🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Game Timing - Rely on vsync?

Started by
9 comments, last by SikCiv 24 years, 7 months ago
Bunch of questions, bunch of answers.

Your sprite animation in Windows games should rely on a high resolution timer (several in Windows, use QueryPerformance Counter if you can get it) to figure out which frame to display. Movement should be measured and stored NOT in pixels per frame but pixels per second, and then multiplied by the time delta (change in time since the last frame) to figure out the correct position for this frame. This will cause animations to miss frames, but such is life - the animations should be keeping up with time.

This is a global change that should be used for every and all things that previously used "per frame" measurements.

You can set the refresh rate of the monitor with the SetDisplayMode() command of the DirectDraw interface. You must be prepared, however, for it to return an error in which case that refresh rate is not valid. You could also enumerate the display modes and find one that you like.

This should help alot, games will run at constant speed (but not constant fps) on different systems.

- Splat

Advertisement
yep, that's exactly right.

Check out this post from yesterday which has example code for doing just that...
http://www.gamedev.net/community/forums/ubb/Forum7/HTML/000179.html

I see, but is my current setup virtually the same, or should I calculate it using queryperformancetimer?

What I have now is a mmtimer function that updates all the sprite positions every 10 milliseconds, with each sprite having a frame length variable that controls the frame change, i.e..

TimerUpdate() //updated every 10 milsec
{
//update each sprite pos if frame len //counter is overdue

for(i=0;i {
Sprite.counter+=10;
if(Sprite.counter>Sprite.FrameLen)
{
Sprite.counter = 0; //reset counter
UpdateSpriteFrame();//next frame..
}
}

}


Each frame is updated as fast as the vsync is running (60fps), so if the FPS is at 75FPS, the blit positions will be where I want them, but im worried because animation may not be smooth when the FPS change due to more blitting etc..

Would I get a better result if I calculated from the Frame speed instead? (using the code from yesterdays post)

  Downloads:  ZeroOne Realm

Yes, you would do yourself a great deed to use the millisecond time delta to calculate the new positions. You main error lies in the comment "//updated every 10 milsec" You DON'T know that, you are hoping that. Hoping is a bad thing in programming.

- Splat

I have modified my code to be more efficient in frame updates, and recompiled it, now the blit animations are much smoother (-: But the only problem is when the FPS drop below 60FPS, the animations lose a frame here and there, but its not that bad.

I was wandering if this is the same with the other technique, i.e calculating blit positions with the FPS instead of pixels?

The mmtimer (not the standard timer) I am using is very accurate as I have tested it in a multimedia app I made. Isnt QueryPerformanceTimer using the same timer as a multimedia timer?

I was wandering if there is any C/C++ source code available for a windows platform/shoot'em up game so I can get an idea of how it should be done (prefferably a commercial or good shareware game). Any ideas?

  Downloads:  ZeroOne Realm

Is there an equivelent function to QueryPerformanceCounter() for Unix and SGI machines???

I've got my game to work fine on a Win32 platform, however I need to get it running on Irix (6.3).

Is this function OS or architecture specific?

Arthur

QueryPerformanceCounter is a hardware routine that is not necessarily supported by every hardware setup. I'd suggest testing to see whether it is supported and dropping back to timeGetTime if it is not (better than nothing).
Umm, first off, use QueryPerformanceCounter if you have it EVERY single time. It has tremendous resolution (it varies on each computer, but mine is like 5200000 ticks a seconds res, which means milliseconds are going to be perfect). timeGetTime is a good backup, but returns millisecond res values, which means they can and will be off by a bit. On newer MS OS's, you need to use timeBeginPeriod() and timeEndPeriod() to set the res at 1 millisecond.

However, all are Platform SDK API functions and therefore not supported by OS's other than Windows 95/98/NT/2000. For unix, you need to use completely different functions for high-resolutions timing services.

- Splat


I think QueryPerformanceCounter just calls the Intel assembly
opcode RDTSC (read direct from time stamp counter) for Pentium
and above machines? They both give the same results.

The count that QueryPerformanceCounter returns is basically useless
in terms of absolute time if you don't use the function QueryPerformanceFrequency
with it as well. For example, if you want to figure out fps, you
need the frequency to convert counts to seconds.

Reaver

My platform game is controlled by a mmtimer to maintain the speed of the background and sprites, BUT since the screen syncs from 30 to 75 FPS (depending on the system) the blits appear to be out of time, sometimes missing some frames. This is because the mmtimer isnt in sync with the screen flips.

Is there a way to set the DDraw Fullscreen video frequency to say 60Hz on every system so my blits are in sync?

How does everyone control the timing?

Also, if I use the vsync to control the screen animation speed, my game will slow down on slower machines! How do I overcome this problem?

(I remember in DOS 320x200 the vsync was always constant on all systems, so controlling animation was easy)


hhheeelllpppp )-;

Machine.. P2/35064MB, i740 8MB, @ 640x480x16bit

  Downloads:  ZeroOne Realm

This topic is closed to new replies.

Advertisement