Quote: "But specifically, I'm moving a camera. With no delays, sync rate 0, and steps of .01, the camera moves pretty good on my fast machine. On my slow machine, it crawls along. If I bump the step size up to 1.0, then the slow machine moves well, but on the fast one the camera is out of control.
That's fine, they are different computers. But what's a good way to trap this? Should I run some sort of benchmark when my program starts? Maybe a huge FOR/NEXT loop, and compare the timer before and after?"
YES! Timer based movement!
Lets say your program is running at 30 frames per second, and you want your object to move 1 unit per frame. OK. That's 30 units per second. Now, if you move your object 1 unit per frame at 60 frames per second, your object is moving at 60 units per second.
So, instead of having distance per frame constant, have distance per second constant.
of course the function "screen fps()" isn't the best measure of framerate, so each frame, you want to use the "timer()" or "perftimer()" function, to get the number of millisecond elapsed since the last frame. Divide that by 1000 and you get the number of seconds it took for the frame to pass.
So... What I usually do is:
do
...code...
Duration#=(timer()-time_last_frame)*.001
move object n, speed_per_second*Duration#
time_last_frame=timer()
sync
loop
If you do that, then object n will move at the same speed per second, regardless of what computer you're on!
The important thing is that I'm updating time_last_frame at the end of the loop, so that there is
*minimal time elapsed between the time you calculate "duration" and the time you update time_last_frame*
This is because... Well, if you update time_last_frame right before you calculate duration, you'll get a number that's pretty much equal, because timer_last_frame~=timer(), and timer()-timer()=0.