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.

Newcomers DBPro Corner / dynamically changing speed.

Author
Message
pollywog
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location:
Posted: 30th Jan 2009 22:14
I'm sure others have run into this.
what steps has anyone done to correct it.

you build your app on your sweet state of the art brand spanking new computer.

or (more if your like me) you program on your old commodore 64 with a tad less processing power.

anyway when you distribute your game to others the speed in which stuff moves is either way too fast, or slow because of the processor speed.

so has anyone done any kind of correction in their main game loop?
like when you increment the positions of your object you take into consideration the processor speed?

so like instead of
inc z#, .01 : position object 1, x#,y#,z#

you have something like
inc z#, GetIncrementValue(ProcessorSpeed) : position object 1, x#,y#,z#

or I suppose another solution would be to simply berate any one with a worse/better computer than yourself
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 30th Jan 2009 22:28 Edited at: 30th Jan 2009 22:29
Typically people use timer-based movement, which basically into account the amount of time it takes to go through a single loop and does everything accordingly. For instance:



(obviously you'll have to ElapsedTime declared as a global var somewhere else, and you'll have to set it to the amount of time one loop takes.

This way your game will never slow down/speed up on any computer, everything will always move as if your game was running at 60FPS.

An example:

If a loop takes 16 ms (approx 60 FPS) then GetTimerBasedVal( 1.0 ) will return 1.0. However if it takes twice as long--32ms (approx 30 FPS) then GetTimerBasedVal( 1.0 ) will return 2.0, so everything will move twice as fast, which, because your game is running at half regular speed, will make everything move at an appropriate speed.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jan 2009 23:05
... what he said, except I prefer to convert the milliseconds into fractions of a second (MS = timer() / 1000.0), use a convention of 1 directx unit = 1 metre, and then use metre per second speeds (or scale up if necessary) - I find it makes everything nice and predictable, but your mileage may vary

In addition, you can also have timed events, as in a 5 second delay before a grenade explodes. You simply add the time passed to a variable, and when that variable reaches or exceeds a certain value, bang!

lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 31st Jan 2009 06:02
isnt that what the sync does, which is it updating at and when you ask it to e.g

if i use

it would keep the frames running at or close to 60 fps

but if i changed sync rate to 120 it would make it update faster and the sprites would move across the screen faster...

Please explain what difference there is between the code you use and what i just posted

Please Note i am still new at this and dont have a very big understanding of all the commands......
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 1st Feb 2009 06:31
The SYNC RATE command does not make the program sync at the rate you specify, it only stops it from syncing any faster than that rate. So if you specify a sync rate of 60, and the computer is only capable of syncing 30 times a second, it will only sync 30 times a second. This is why your best bet is to set your sync rate at whatever speed works best on your machine, calibrate all of your speeds and whatnot to this sync rate, then set the sync rate to 0 to allow the program to sync as fast as it can, and implement timer-based movement to ensure all of your speeds are changing to stay consistent with the speed you set at 60 fps.

Login to post a reply

Server time is: 2024-09-28 02:25:46
Your offset time is: 2024-09-28 02:25:46