Archived

This topic is now archived and is closed to further replies.

Same speed on every system

This topic is 6016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What makes a game run smooter, on fast or old cpus: 1-Make it runs at the same fixed FPS on all systems (let''s say 30, for example) 2-Extract the max FPS possible and work by lag as measure for sprites actions, timers, etc. The 2 is much more hard to do, and i think is the best way. What is the right way to implement it on a game engine?

Share this post


Link to post
Share on other sites
The best way is to determine the time between each frame and multiply this time with all movements. For example:

timekey := timegettime - oldtime;
oldtime := timekey;

ship.x := ship.x + 10*timekey;

Now the object moves on every computer at every framerate the same way in the same time.

Look at the tutorials (high performance timers) at www.neobrothers.de

Neo

Share this post


Link to post
Share on other sites
There was a big discussion on this topic in a flipCode forum thread a while back.

In my current project, I was all for having a variable frame rate but have since been converted to using a fixed rate of 30fps.

Neo, your code shown will not work properly. Try this...

timekey := timegettime - oldtime;
oldtime := oldtime + timekey;

What I do with a time delta such as this is to convert it to a floating point value that represents the fractional part of a second. To do this, divide timekey by the number of ticks per seconds.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The DXTimer OnTimer event gives you the elapsed time since the last call (LagCount). Use LagCount as parameter for you move events and then calc the movements in pixels per sec (FDX/FDY):
newX := X + FDX*(MoveCount/1000);
newY := Y + FDY*(MoveCount/1000);

Share this post


Link to post
Share on other sites
Well for very perfect movements try this code:

var
Frequency, Current_Time, Last_Time: Int64;
Time_Elapsed , Time_Scale: Double;
Counter_Available: Boolean;

in your init procedure:

Counter_Available := false;
if QueryPerformanceFrequency(frequency) = false then
begin
Last_Time := timeGetTime;
Time_Scale := 0.001;
end
else
begin
Counter_Available := true;
Time_Scale := 1.0 / frequency;
QueryPerformanceCounter(Last_Time);
end;


call this function every frame:

function GetTimeKey: Double;
begin
if Counter_Available then
QueryPerformanceCounter(Current_Time)
else
Current_Time := timeGetTime;

Time_Elapsed := (Current_Time - Last_Time) * Time_Scale;
last_time := current_time;
result := time_elapsed;
end;

Now your result is a number, which you can use to multiplay with your movements and everything works fine.

Neo

Share this post


Link to post
Share on other sites