Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Newbie question: timing and the game loop

Author
Message
EddieRay
22
Years of Service
User Offline
Joined: 28th Feb 2003
Location: USA
Posted: 6th Mar 2003 09:17
In most programming environments I've worked with, one of the best ways to deal with motion of objects in the game is to have a master loop which does something like the following:

do forever:

compute the elapsed time since last update occured(T)

update all objects based on the value of T

obj1_velocity_x = obj1_velocity_x + obj1_accel_x * T
obj1_x = obj1_x + obj1_velocity_x * T
...

update the screen

The thing I'm not getting is how the above approach will work with a specified SYNC RATE? What does DB do if we have surpassed the SYNC RATE... sleep?

Also, does the SYNC command wait for a vertical sync on the video card?

Thanks,

Ed
arras
22
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 6th Mar 2003 09:49
You have to handle your sync on your own instead of using sync rates:

sync on

do

compute the elapsed time since last update occured(T)

update all objects based on the value of T

obj1_velocity_x = obj1_velocity_x + obj1_accel_x * T
obj1_x = obj1_x + obj1_velocity_x * T

sync
loop

QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 6th Mar 2003 15:03
The only thing the sync does is set the maximum framerate your game can achieve; sync rate 60 will give you a max of 60 fps. If you say sync rate 0 it will go as fast as the processor allows, though most monitors have a limit of 200 fps. you should use the timer() and screen fps() commands to do the calculations you want.

Darken the skies, we are god

Login to post a reply

Server time is: 2025-08-08 20:40:10
Your offset time is: 2025-08-08 20:40:10