From e90a0510b951c4e08d94d7ca4643eec6add3437c Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Mon, 22 Feb 2010 16:22:28 +0000 Subject: some changes to fps limiter, dependency to old UTime stuff removed git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2139 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UMain.pas | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/base/UMain.pas') diff --git a/src/base/UMain.pas b/src/base/UMain.pas index f05470c1..473a78a9 100644 --- a/src/base/UMain.pas +++ b/src/base/UMain.pas @@ -41,6 +41,7 @@ uses var Done: boolean; Restart: boolean; + TicksBeforeFrame: Cardinal; procedure Main; procedure MainLoop; @@ -337,6 +338,7 @@ end; procedure MainLoop; var Delay: integer; + TicksCurrent: Cardinal; const MAX_FPS = 100; begin @@ -345,6 +347,8 @@ begin CountSkipTime(); // JB - for some reason this seems to be needed when we use the SDL Timer functions. while not Done do begin + TicksBeforeFrame := SDL_GetTicks; + // joypad if (Ini.Joypad = 1) or (Params.Joypad) then Joy.Update; @@ -356,10 +360,9 @@ begin Done := not Display.Draw; SwapBuffers; - // delay - CountMidTime; - - Delay := Floor(1000 / MAX_FPS - 1000 * TimeMid); + // FPS limiter + TicksCurrent := SDL_GetTicks; + Delay := 1000 div MAX_FPS - (TicksCurrent - TicksBeforeFrame); if Delay >= 1 then SDL_Delay(Delay); // dynamic, maximum is 100 fps -- cgit v1.2.3