Timing

BlitzMax Forums/BlitzMax Beginners Area/Timing

RetroRusty(Posted 2005) [#1]
What is the best way to do timing in BlitzMax so my game will run at the same speed on all PC's?

In Blitz3D i used a replacement function instead of using flip. The function is

Const framerate=60

Function do_flip()

framecounter=framecounter+1

Flip

While Abs (MilliSecs()-timer) < (1000/FRAMERATE)

Wend

timer=MilliSecs()

End Function

I have tried this in BlitzMax and it does work but is there a better/easier way to do this?

Thanks


Dreamora(Posted 2005) [#2]
1. Precalculate the 1000/framerate and use a local variable instead. Saves quite some calculation time :-)

2. There is the way of FPS Modifier which means that you modify all movement,speed etc values with a factor that depends on your actual fps (normally 1.0/fps)
If you do so, you can modify your above code that only flip depends on the time passed since so you can replace the while wend with a if then endif. This way your calculation power runs at its max while the fps is still on the wished point.

I sometimes even used it to fill the rest of the frame with a delay which is needed in B3D to prevent "full cpu usage"


Gabriel(Posted 2005) [#3]
I thought BlitzMax did all the timing stuff for you internally if you set the hertz to 0 when you call Graphics. Has this changed?


Dreamora(Posted 2005) [#4]
This timing has nothing to do with "make it the same speed on every system", this timing is only for graphics part not the mathematic calculation stuff.


ImaginaryHuman(Posted 2005) [#5]
You'll only get it to run the same speed on all PC's if all PC's are fast enough to run your game within its capacity. If your game needs more juice than is available it will run slower no matter what you do. In that case, you then enter into the different area of how to adjust the place that you are at in the various animations and movements to relate to the timing of when the frame will be ready to be viewed.


RetroRusty(Posted 2005) [#6]
My game will run on most PC's. It's a platform game with some nice effects in it. If my do_flip function will work then I will use that.

Thanks


The r0nin(Posted 2005) [#7]
Are you worried that the game might be too fast on some machines, or that it will be too fast on some and too slow on other machines? The first is solvable by several methods (including tweening, which Mark Sibly did a good tutorial for on the message boards, or something else like a frame-rate limiter). The second requires both a tweening-type solution as well as "throttling" of your graphics or calculations (i.e. on slower machinces you would have to use simpler graphics routines or AI calculations, etc., leading to the possibility of a different game experience on different hardware, even though you have the same game speeds), which is much harder to do.


RetroRusty(Posted 2005) [#8]
What I want is for my game to run smooth no matter what people's monitor rate is. I have some code that get's the users monitor rate and matches the games speed to that, but this doesn't work in BlitzMax.

I want my game to have smooth scrolling. I'm not going to achieve this unless I can match my game to the users monitor rate. If I set my game to run at 75fps and someone is playing it on a monitor that is set to 60fps, it's going to look nasty.

Thanks


Dreamora(Posted 2005) [#9]
Why do you want to match the monitor refresh?
this means that it will run faster for people with faster refresh rates ...

syncronize the movement to a fixed value which is scaled to the actual main loop time needed and set the refresh to -1 ...

then it does not mather how fast the monitor is, it will run at the same speed for every use.


RetroRusty(Posted 2005) [#10]
Do you have any code that show's how to do this?

Thanks


Dreamora(Posted 2005) [#11]
Sure sure, no problem :-)