Hi Marg,
I did it this way with the game I'm working on in BlitzPlus. It's quick 'n' crude, but works out pretty well on the machies I've tried it on so far.
------------------------------------------------------------
gamespeed=9 ;Number of milliseconds each update should take
.gameloop
starttime=millisecs()
cls
---blah blah all the rendering to be done
flip false
---blah blah all the collision checking to be done
---blah blah blah the UDP network stuff
---blah blah read mouse/joystick/keyboard, update movement variables
timeleft=gamespeed-(millisecs()-starttime)
if timeleft>0 delay timeleft
goto gameloop
--------------------------------------------------
Provided the loop is done within the number of millisecs I specify in the gamespeed variable (which for my actual application, it was easily. Damn, B+ is fast!), the game will always update every 9 milliseconds (or whatever gamespeed is set to).
-It takes a reading of the system timer at the start of the loop (starttime)
-runs through all the loop gubbins (rendering, collision, movement etc)
-and at the end works out the remaining time needed to delay (timeleft) by subtracting the time it took to do the loop (millisecs()-starttime) and subtracting it from the time you want the loop to take in total (gamespeed-(millisecs()-starttime)).
-the loop will then delay for the remaining milliseconds (timeleft) (it needs to check that it's greater than zero, as in the event that it does ever go below 1, it will delay forever).
Also, the loop uses Flip False. Flip on it's own will always delay the loop until the next vertical retrace, so the refresh rate of the monitor will impact the game speed (producing the problem you cited), whereas Flip False will just flip the buffer immediately, thus becoming monitor refresh independent.
Good luck! :D
I did it this way with the game I'm working on in BlitzPlus. It's quick 'n' crude, but works out pretty well on the machies I've tried it on so far.
------------------------------------------------------------
gamespeed=9 ;Number of milliseconds each update should take
.gameloop
starttime=millisecs()
cls
---blah blah all the rendering to be done
flip false
---blah blah all the collision checking to be done
---blah blah blah the UDP network stuff
---blah blah read mouse/joystick/keyboard, update movement variables
timeleft=gamespeed-(millisecs()-starttime)
if timeleft>0 delay timeleft
goto gameloop
--------------------------------------------------
Provided the loop is done within the number of millisecs I specify in the gamespeed variable (which for my actual application, it was easily. Damn, B+ is fast!), the game will always update every 9 milliseconds (or whatever gamespeed is set to).
-It takes a reading of the system timer at the start of the loop (starttime)
-runs through all the loop gubbins (rendering, collision, movement etc)
-and at the end works out the remaining time needed to delay (timeleft) by subtracting the time it took to do the loop (millisecs()-starttime) and subtracting it from the time you want the loop to take in total (gamespeed-(millisecs()-starttime)).
-the loop will then delay for the remaining milliseconds (timeleft) (it needs to check that it's greater than zero, as in the event that it does ever go below 1, it will delay forever).
Also, the loop uses Flip False. Flip on it's own will always delay the loop until the next vertical retrace, so the refresh rate of the monitor will impact the game speed (producing the problem you cited), whereas Flip False will just flip the buffer immediately, thus becoming monitor refresh independent.
Good luck! :D