reducing size of gfx state, cleanup
[drnoksnes] / platform / sdl.cpp
index 1558c6a..0cb077e 100644 (file)
@@ -114,9 +114,13 @@ static void pauseGame()
 }
 
 /* This comes nearly straight from snes9x */
+/** Calculates framerate, enables frame skip if to low, sleeps if too high, etc. */
 static void frameSync() {
+       Uint32 now = SDL_GetTicks();
+
        if (Settings.TurboMode)
        {
+               // In Turbo mode, just skip as many frames as desired, but don't sleep.
                if(Settings.SkipFrames == AUTO_FRAMERATE || 
                        ++IPPU.FrameSkip >= Settings.SkipFrames)
                {
@@ -129,10 +133,20 @@ static void frameSync() {
                        ++IPPU.SkippedFrames;
                        IPPU.RenderThisFrame = FALSE;
                }
-               return;
+
+               // Take care of framerate display
+               if (Settings.DisplayFrameRate) {
+                       static Uint32 last = 0;
+                       // Update framecounter every second
+                       if (now > last && (now - last > 1000)) {
+                               IPPU.DisplayedRenderedFrameCount =
+                                       IPPU.RenderedFramesCount;
+                               IPPU.RenderedFramesCount = 0;
+                               last = now;
+                       }
+               }
        } else {
                static Uint32 next1 = 0;
-               Uint32 now = SDL_GetTicks();
 
                // If there is no known "next" frame, initialize it now
                if (next1 == 0) {
@@ -173,6 +187,16 @@ static void frameSync() {
 
                // Calculate the timestamp of the next frame.
                next1 += Settings.FrameTime;
+
+               // Take care of framerate display
+               if (Settings.DisplayFrameRate) {
+                       // Update every theoretical 60 frames
+                       if (IPPU.FrameCount % Memory.ROMFramesPerSecond == 0) {
+                               IPPU.DisplayedRenderedFrameCount =
+                                       IPPU.RenderedFramesCount;
+                               IPPU.RenderedFramesCount = 0;
+                       }
+               }
        }
 }