From 3c525b9f46c8b865689134a263f6526e46a62bd9 Mon Sep 17 00:00:00 2001 From: gecko_reverse Date: Sun, 21 Sep 2008 08:06:31 +0000 Subject: [PATCH] timing switched to use NSDate instead of Microseconds (cleaner), fixed regression in auto frame skip menu item --- desmume/src/cocoa/main_window.m | 1 + desmume/src/cocoa/nds_control.mm | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/desmume/src/cocoa/main_window.m b/desmume/src/cocoa/main_window.m index f800cbfdb..418e8486d 100644 --- a/desmume/src/cocoa/main_window.m +++ b/desmume/src/cocoa/main_window.m @@ -1134,6 +1134,7 @@ NSMenuItem *screenshot_to_file_item = nil; [pause_item setState:NSOffState]; } + [frame_skip_auto_item setTarget:self]; for(i = 0; i < MAX_FRAME_SKIP; i++)[frame_skip_item[i] setTarget:self]; [self setFrameSkip:[self frameSkip]]; //set the menu checkmarks correctly diff --git a/desmume/src/cocoa/nds_control.mm b/desmume/src/cocoa/nds_control.mm index e7db7c21e..217ee2fd4 100644 --- a/desmume/src/cocoa/nds_control.mm +++ b/desmume/src/cocoa/nds_control.mm @@ -1255,8 +1255,8 @@ bool opengl_init() u32 cycles = 0; - NSDate *frame_end_date; - unsigned long long frame_start_time, frame_end_time; + NSDate *frame_start_date, *frame_end_date, *ideal_frame_end_date; + int frames_to_skip = 0; //program main loop @@ -1271,9 +1271,9 @@ bool opengl_init() paused = false; int speed_limit_this_frame = speed_limit; //dont let speed limit change midframe - if(speed_limit_this_frame)frame_end_date = [[NSDate alloc] initWithTimeIntervalSinceNow: DS_SECONDS_PER_FRAME / ((float)speed_limit_this_frame / 100.0)]; + if(speed_limit_this_frame)ideal_frame_end_date = [NSDate dateWithTimeIntervalSinceNow: DS_SECONDS_PER_FRAME / ((float)speed_limit_this_frame / 100.0)]; - Microseconds((struct UnsignedWide*)&frame_start_time); + frame_start_date = [NSDate dateWithTimeIntervalSinceNow:0]; [execution_lock lock]; @@ -1287,14 +1287,11 @@ bool opengl_init() [execution_lock unlock]; - Microseconds((struct UnsignedWide*)&frame_end_time); - + frame_end_date = [NSDate dateWithTimeIntervalSinceNow:0]; + //speed limit if(speed_limit_this_frame) - { - [NSThread sleepUntilDate:frame_end_date]; - [frame_end_date release]; - } + [NSThread sleepUntilDate:ideal_frame_end_date]; if(frames_to_skip > 0) frames_to_skip--; @@ -1304,10 +1301,9 @@ bool opengl_init() if(frame_skip < 0) { //automatic - //i don't know if theres a standard strategy, but here we calculate - //how much longer the frame took than it should have, then set it to skip - //that many frames. - frames_to_skip = ((double)(frame_end_time - frame_start_time)) / ((double)DS_MICROSECONDS_PER_FRAME); + //i don't know if theres a standard strategy, but here we calculate how much + //longer the frame took than it should have, then set it to skip that many frames. + frames_to_skip = [frame_end_date timeIntervalSinceDate:frame_start_date] / (float)DS_SECONDS_PER_FRAME; if(frames_to_skip > 10)frames_to_skip = 10; } else