Speed Limiting...

BlitzMax Forums/BlitzMax Beginners Area/Speed Limiting...

po(Posted 2007) [#1]
I thought that using Flip 1 would lock the game speed to the hertz I have set, but it only does it on some computers (vSync?).
I need a speed limiting solution for fullscreen 2D games that will work on all computers.

-Thanks


H&K(Posted 2007) [#2]
Set up a timer, which calls (say) your main function every XX Milli, and then run your game code from there. There is a really really good code archive example.

(Or I suppose you could catch the Flip Post, and run you Code from that, Im sure there is a Post Message on Flip command)


Grey Alien(Posted 2007) [#3]
delta timing or fixed rate logic


Ghost Dancer(Posted 2007) [#4]
Just using flip will not work the same on all computers. If you need a constant speed no matter what the game is running on, you do indeed need some sort of speed limiting.

I use for delta timing as it's pretty easy to incorporate into your code and there are plenty of examples, such as here: http://www.blitzbasic.com/codearcs/codearcs.php?code=1698

I don't know much about fixed rate logic - I guess there are pro's & cons to each method so find the one that is best for you.


po(Posted 2007) [#5]
Thanks all.


FlameDuck(Posted 2007) [#6]
(Or I suppose you could catch the Flip Post, and run you Code from that, Im sure there is a Post Message on Flip command)
Not on Windows there isn't.


Gabriel(Posted 2007) [#7]
Set up a timer, which calls (say) your main function every XX Milli, and then run your game code from there.

What happens if the PC it's running on isn't running the game fast enough to run the function every XX milliseconds?


H&K(Posted 2007) [#8]
What happens if the PC it's running on isn't running the game fast enough to run the function every XX milliseconds?
Well then the thread title shouldnt be speed limiting.
Delta Time is obviously a better way to ensure stable graphics over a rangge of faster and slower computers. However the question was, in paraphrase, how can I make sure it doesnt run too fast.
In this case delta time grabs more time to draw tween frames, whereas my sudgestion would be giving the extra time back to the system.

PS. {Anyway to answer What would happen is that you would get a big backlog of posts on the post stack}
Edit: @Flame, yep sorry just looked, you can only add a hook for when Flip is about to occur


Gabriel(Posted 2007) [#9]
Well then the thread title shouldnt be speed limiting.

Uh, yeah, I guess so.