Skip to main content
gamedev.net
🔒 Locked

Game SPEED help !

Started by Gf11speed Nov 23, 2001 at 1:43 PM 0 replies 200+ views
Original Post
Gf11speed
Gf11speed
I wrote a game, and on 1 of my test systems ( the faster one) the game runs too fast, and on another system (the slower one), it runs just right. However, when I add StartClock(), WaitClock() commands to slow it down ONLY if necessary, it runs ok on my faster system but too slow on the slower... so what can I do about this? Also, when I add any kind of Wait command, my animations are not smooth at all (like when I slide a bitmap across the screen). How could I fix all this ?? Thanks! *==================* www.syntasoft.com *==================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
Cyberium
Cyberium
Here''s how I solved the timing problem for my own prototype/test games (real simple, but it works) - First declare some kind of variable for the specific animation or entire game screen frame, that needs a timer controlled progression. Let''s declare this variable as Time1:LongWord; for now (Pascal code, Delphi 5 compliant. LongWord is unsigned 32-bit, in case you need to know...). Next, you need to write the timer code so that it encapsules the animation code. Let''s assume that the function GetTickCount returns how long your computer''s been on (in milliseconds). Here''s some pseudo-code (Pascal):

if GetTickCount - Time1 > 70 then begin
...Animation code and other instructions goes here...
Time1 := GetTickCount;
end;

What is done in the code above, is that it checks if the difference between GetTickCount and Time1 is larger than 70. If it is, then it first executes any instructions that needs that specific timing, then it assigns the current time to Time1. This will produce a seemingly smooth timing. As you can see, if the test system running your program is too slow to produce minimal results, the timer code will execute as many times as it possible can, because the if...then difference check comes out larger than 70 continously. It is required that there''s a main timer executing the game main loop, for this to work.

More pseudo-code (simple game loop example, where the game loop and everything is coded or called from the timer event procedure):

var Time1: LongWord; //This is a global variable (faster)

procedure TimerTimoutEvent;
begin
Timer.Enabled:=False;
...Game input, sound output and world calculation...
if GetTickCount - Time1 > 70 then begin
...Game animation index calculation and screen output...
Time1 := GetTickCount;
end;
Timer.Enabled:=True;
end;


Hope this works,
good luck!

-cyberium

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.