Hello, I’m having some problems with a a little project I’m working on. The problem is that my animations are oscillating slightly. I’m using a timer (implemented in win32 by QueryPerformanceCounter), that returns a float value, representing the time slice for the frame in seconds. When I replace the time with a fixed value for the timeslice, the animation runs perfect.
The returned value is sent to the “update” methods as an argument. I have a wintimer set up, sending WM_PAINT messages to the window every 1/85th second.
How can I improve this? Should I use a lower-precision timer, lower the forced framerate, or apply a simple filter on the output from my timer?
Such irregularities may be related to vsync on or off, try to toggle it. I would say ‘on’ is better, specially if you have a high framerate.
Maybe return a double, to get more precision ?
For vsync, you can try to set it through the driver control panel, or use wglSwapInterval(1)
EDIT: well, if using a constant value smoothes the animation, then vsync is not the issue. Try to log what values are returned, both as original integer and after transformation to double.
Thanks for your replies. I’ll try logging the output of the timer as suggested, and study it. The obvious solution, as pointed out, would be to use a double instead, but I’ll do some peeking around first as to acertain wether it really is the issue or not.
The reason that I perform game update with WM_PAINT messages are really comes from a framework we were handed by the course admin, where they implemented it this way. It has it’s advantages, as game updates are done during this message, so it doesn’t eat up all CPU. I’ll probably change it to the way you suggested, now that I have a pause function halts the game whenever the window loses focus anyway.
Thanks again guys, I’ll post any findings or progress I make.
Martin