Skip to main content
GameDev.net gamedev.net
🔒 Locked

Frane-Based / Time-based modeling

Started by n0p3x Aug 28, 2000 at 8:47 AM 3 replies 750+ views
Original Post
n0p3x
n0p3x
Hi, I just rearanged my program so the sprite moves at the same amount of pixels per second no matter how fast/slow the computer is. The only problem is that the frame rate seems very fluctuant. Therefore one minuite the sprite will move nice and smoothly, next it jumps. Is this normal? What''s a good way to get around it? Should I calculate the average frame rate every second rather than that seconds frame rate to keep the figure ''smoother''? Any ideas on this or extra information on the subject of time based modeling would be a great help. Regards, David Stubbs
Regards,Dave
Knarkles
Knarkles
Exactly how are you doing this? I time it with QueryPerformanceCounter() and do like this, every frame:

    Time = Timer.DeltaTime();
Position = Velocity * Time;


Timer.DeltaTime() calculates the time elapsed since the last call to the same function. This is a very simple example, but you get the idea.

-Jussi
n0p3x
n0p3x
Im using GetTickCount(). I''ve never heard of QueryPerformanceCounter before.

Regards,
David Stubbs
Regards,Dave
Knarkles
Knarkles
QueryPerformanceCounter is the most accurate timer there is. On my mainboard (or is it on the processor?), its frequency is over 1MHz, which should be enough for any FPS freak.

Look in your compiler''s help for QueryPerformanceCounter() and QueryPerformanceFrequency(). (Or something like that)

-Jussi
Belandrew
Belandrew
The reason you''re having a problem is because GetTickCount()''s timer is only updated when Windows feels like it (ie, has nothing better to do for a time slice). This can result in very inaccurate timing results. It was never intended for high-resolution timing.
As everyone else has already mentioned, QueryPerformanceCounter() is a better way to go. It has much better accuracy.

Topic Locked

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

Sign in to reply to this topic.