- if (pthissec != tval.tv_sec)\r
- {\r
- if (PsndOut == 0 && currentConfig.Frameskip >= 0) {\r
- pframes_done = pframes_shown = 0;\r
- } else {\r
- // it is quite common for this implementation to leave 1 fame unfinished\r
- // when second changes, but we don't want buffer to starve.\r
- if(PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {\r
- updateKeys();\r
- SkipFrame(1); pframes_done++;\r
- }\r
-\r
- pframes_done -= target_fps; if (pframes_done < 0) pframes_done = 0;\r
- pframes_shown -= target_fps; if (pframes_shown < 0) pframes_shown = 0;\r
- if (pframes_shown > pframes_done) pframes_shown = pframes_done;\r
- }\r
- pthissec = tval.tv_sec;\r
- }\r
-\r
- lim_time = (pframes_done+1) * target_frametime + vsync_offset;\r
- if (currentConfig.Frameskip >= 0) // frameskip enabled\r
- {\r
- for(i = 0; i < currentConfig.Frameskip; i++) {\r
- updateKeys();\r
- SkipFrame(1); pframes_done++; frames_done++;\r
- if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
- gettimeofday(&tval, 0);\r
- if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r
- if (tval.tv_usec < lim_time) { // we are too fast\r
- simpleWait(pthissec, lim_time);\r
- }\r
- }\r
- lim_time += target_frametime;\r
- }\r
- }\r
- else if (tval.tv_usec > lim_time) // auto frameskip\r
- {\r
- // no time left for this frame - skip\r
- if (tval.tv_usec - lim_time >= 300000) {\r
- /* something caused a slowdown for us (disk access? cache flush?)\r
- * try to recover by resetting timing... */\r
- reset_timing = 1;\r
- continue;\r
- }\r
- updateKeys();\r
- SkipFrame(tval.tv_usec < lim_time+target_frametime*2); pframes_done++; frames_done++;\r
- continue;\r
- }\r
-\r
- updateKeys();\r
- PicoFrame();\r
-\r
- // check time\r
- gettimeofday(&tval, 0);\r
- if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r