From 5cefce1cf0272dd88707e99c5fd21f406d51d43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Sperber?= Date: Thu, 19 Sep 2013 13:51:39 +0200 Subject: [PATCH] Respect frameRate when scheduling timer in CPAnimation. Treat a frameRate of 0 as "really fast" instead of CPTimer default (10 fps). --- AppKit/CPAnimation.j | 4 ++- Tests/AppKit/CPAnimationTest.j | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Tests/AppKit/CPAnimationTest.j diff --git a/AppKit/CPAnimation.j b/AppKit/CPAnimation.j index c79f1e2bb..67b4ae7fb 100644 --- a/AppKit/CPAnimation.j +++ b/AppKit/CPAnimation.j @@ -236,7 +236,9 @@ ACTUAL_FRAME_RATE = 0; ACTUAL_FRAME_RATE = 0; _lastTime = new Date(); - _timer = [CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(animationTimerDidFire:) userInfo:nil repeats:YES]; + var timerInterval = _frameRate <= 0.0 ? 0.0001 : 1.0/_frameRate; + + _timer = [CPTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selector(animationTimerDidFire:) userInfo:nil repeats:YES]; } /* diff --git a/Tests/AppKit/CPAnimationTest.j b/Tests/AppKit/CPAnimationTest.j new file mode 100644 index 000000000..d151d82bc --- /dev/null +++ b/Tests/AppKit/CPAnimationTest.j @@ -0,0 +1,47 @@ +@import +@import + +[CPApplication sharedApplication]; + +@implementation CPAnimation (TestMethods) +{ +} + +- (CPTimer)timer +{ + return _timer; +} + +@end + +@implementation CPAnimationTest : OJTestCase +{ +} + +- (void)testScheduleTimerWithIntervalBasedOnDefaultFrameRate +{ + var animation = [[CPAnimation alloc] initWithDuration:0.1 animationCurve:CPAnimationLinear]; + [animation startAnimation]; + + [self assert:1.0/60.0 equals:[[animation timer] timeInterval]]; +} + +- (void)testScheduleTimerWithIntervalBasedOnCustomFrameRate +{ + var animation = [[CPAnimation alloc] initWithDuration:0.1 animationCurve:CPAnimationLinear]; + [animation setFrameRate:30]; + [animation startAnimation]; + + [self assert:1.0/30.0 equals:[[animation timer] timeInterval]]; +} + +- (void)testScheduleTimerWithIntervalBasedOnAsFastAsPossibleFrameRate +{ + var animation = [[CPAnimation alloc] initWithDuration:0.1 animationCurve:CPAnimationLinear]; + [animation setFrameRate:0]; + [animation startAnimation]; + + [self assert:0.0001 equals:[[animation timer] timeInterval]]; +} + +@end