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 Professional Discussion / Consistant game speed?

Author
Message
Jaidex
22
Years of Service
User Offline
Joined: 28th Jan 2003
Location:
Posted: 18th Feb 2003 18:16
I asked this question once before, but I didn't really get an answer - I'll try rewording it.

On some games (like race games, flight sims, etc), a player on a slow machine will cover the same amount of distance as a player on a fast machine, they just won't have as fast a frame rate. How is this accomplished? How can I make the speed of the machine show up in frame rate, but NOT in game play?

I know this is an effect of the main game loop, but I can't figure out how to accomplish it.

Any help would be appreciated.

Thanks!

Jai
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Feb 2003 19:23
There are various ways to do it. I wrote something once an one way : http://www.matrix1.demon.co.uk/DBPro/WhatFrameRate.html
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Feb 2003 19:52
there is a post a page or two over called "Framerate Doubler" or something ... it has a good few techniques for achieve this

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 18th Feb 2003 20:34
yes, ian's got the right idea, just monitor the framerate and move your objects faster or slower depending on how many frames you lose
mimesis
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 18th Feb 2003 20:56
@Ian
Dont use screen fps(), use timer() instead.
What I mean is, you need to time the MainLoop and than
use that to calculate your RateAdjust#
mimesis
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 18th Feb 2003 20:59
Why? becouse screen fps() is not accurate (very surpraising)
I'm not sure but screen fps() seems to return an "averaged" fps.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Feb 2003 22:25
Know that I wrote that some time back.

I wouldn't use timer() either though - its resolution is too low. I've put a high resolution timer into my utility dll so I can have a decent timing mechanism (try getting an accurate 30fps using a 1000tick/sec timer).

Darned good it is too - http://www.matrix1.demon.co.uk/DBPro
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 19th Feb 2003 02:06
timer resolution is fine for me...

time as float = timer()
1000.0000 = 1/1000th Second

atleast in professional this is quite high, and therein comes the beauty of the way i do it because it runs each time based op as part of a per Nth ammount of time passed (^_^) then you calculated the other times as seperate instances + the loop time for time equasions.

solves alot of time and effort making sure that the entire loop is time synced rather than per operation

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
mimesis
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 19th Feb 2003 02:25
Yeah I'm doing it this way also and I'm happy with Timer()

@Ian
You're plug is great, but for most cases timer() works fine.
I've tryed your plugin in my FPS game but the extra precision is not detecteable so i'm sticking to dbp timer().
However it's good to know u can get the extra precision if
needed
OrcishBlue
22
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Canada
Posted: 19th Feb 2003 05:54
This is what i use, pseudo code from memory:

sync on : sync 0
FrameBudget as float
FrameStart as float
FrameBudget = 1000/75; change 75 to whatever fits your game

main()
{
FrameStart = GetTickCount();
rem main game loop, move objects..etc
rem process keys...
sync
repeat
rem process messages or use this time for ai ..etc
rem or just let it be
until (GetTickCount()-framestart) >= framebudget;
}

now you have a game that can run at whatever fps without limiting your vsynch, ensures super smooth gameplay.

I hope this helps.

OrcishBlue.
OrcishBlue
22
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Canada
Posted: 19th Feb 2003 05:57
How can i edit my messages here ?

i just noticed that i keep putting ; at the end of my code..etc, my 'C' background is showing it's ugly colors
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 19th Feb 2003 06:18
well seeing as the entire code it layn out as more C than Basic ...

be more like



more DBpro friendly code

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
OrcishBlue
22
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Canada
Posted: 19th Feb 2003 06:33
thanks for the convert Raven
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 19th Feb 2003 06:41
i have a niggling feeling that it looks wrong, and won't do what your after ... but that might just be me

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Jaidex
22
Years of Service
User Offline
Joined: 28th Jan 2003
Location:
Posted: 19th Feb 2003 22:42
Raven, several messages back (in this thread) you said:

time as float = timer()
1000.0000 = 1/1000th Second

Could I possibly get you to show me how to use the method you're referring to in a real (even if very simple) game loop?

I thought I finally had my answer with the stuff that Ian posted at the beginning (Thanks Ian!), but then everyone is telling me that I should use timer() intead, and I think I'm missing something somewhere. A concrete example would really be appreciated!

Thanks!

Jai

Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 20th Feb 2003 00:54
well my example isn't too difficult really



perhaps its not as compact or glamourous as other timers, but its quite versitile

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
The Big Babou
22
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 20th Feb 2003 01:59
raven posted a code snippet in Dark Basic code above. in the example the frame.budget is 1000/75. if i understand it right, the main loop will be run through one time in 75/1000 of a second?
what happens when, on very slow machines, running through the main loop takes longer than 75/1000 of a second? wouldn't the gamespeed be slower on that machine than on a fast machine?
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 20th Feb 2003 08:04
well you have to look at this at more of a technical veiwpoint rather than a darkbasic rendering veiwpoint.

pentium based machines run (at slowers i.e. P60 - P2 366) on 66Mhz bus's - which maynot seem important here, however this is the adverage refresh rate of your system or rather
Ram <-> CPU | Ram <-> AGP | CPU <-> AGP | CPU <-> PCI | Ram <-> PCI

now this translates into a 1.66ms (0.000166) delay between loops ... and the loop timer - for DarkBasic standard you first need to calibrate this timer to make sure its correct, however for Professional its running in pure machine code - this means you can consider it is running at machine level and therefore assume this is right.

So what you're doing is 166/1000 = your standard loop on the lowest speed machine, anything under that and your running the program slower than the system ... and if you set this value to 60/1000 this means that you're using close to 60 loops / second e.g. VSync (^_^)

hopefully this all make sence

the brilliant thing is though, most latter Pentium2 Machines are 100Mhz Bus's - Pentium3 Machine are standardly 133Mhz and the current Pentium4's are 400Mhz Bus's

... this means that if you use a DLL to detect the processor/bus value you can adjust your timer to run multiple loops prior to syncing to allow for greater speed because its all being run at the same time

and its also good to time for latency from the start of a loop to the end to find abnormailities (^_^)

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 20th Feb 2003 08:12
oh and incase your wondering how i got 66Mhz into 1.66ms - thats a pretty simple one

( Mhz / 3 ) * ( Mhz / 100 )

i mean the original multiplication of 3, isn't quite right because its suppose to be (Mhz/2/100) so its more like 3.3 but its gives you the idea

and its by 100, because a milisecond is a 1/1000th of a second ... and set to the nearest 100th

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Karlos
22
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United Kingdom
Posted: 20th Feb 2003 14:02
Ok,
Here's how I handle the problem...

Similar to the above but I just calculate how far an object should move in a second and correct th movement in each frame:-


If it ain't broke - try harder.
W2K Pro - Geforce2 MX400 64MB - Athlon 900
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Feb 2003 14:28
Loads of ways of doing it. It depends on what you are aiming for.

I guess if I was doing this now, I would use a more complex system of determining where I wanted objects to be in a known amount of time, then use a system similar to Karlos's to get me there.
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 20th Feb 2003 14:34
yeah there are many ways and each to thier own really...
i preferably use the method i do simply because i can accept time as a constant throughout the functions that need to be time based, suchas controls and physics - and so limits the time they're actually run, and it actually skips it on the loops that they're not needed to be run - can lay up a considerable amount of speed

(^_^) i feel more confortable worring about the code more than if the timing is correct per model, kinda like when i do vectors in db standard ... i work to all three axis on the same calculation utilising dot products and such to truely calculate positions similtaneously.
but then thats not for everyone either hehee

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Jaidex
22
Years of Service
User Offline
Joined: 28th Jan 2003
Location:
Posted: 20th Feb 2003 17:32
I THINK this all makes sense, but there's one thing I don't understand. The numbers you calculated through end up giving you passes per second through the main loop on a slow machine. Does that equate to 60 fps on those machines? I've run through loops a LOT slower than that on faster machines! Or is number of times through the loop not the same as fps?

On looking more at the code, I think I have it. Things like moving the player, moving enemies, etc should go in the <<Time based ops go here>> section and will be updated by the number of ticks you've determined to use. Operations that were not time dependent would go in the <<Other ops go here>> section. The sync will take place each time through the loop, but on faster machines, this will NOT include updates to some (time dependant) things. Is this correct? What kind of ops would NOT be based on time? That is, what types of things should be time based and what types of things shouldn't?

Thanks for all of the help!

Jai

Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 20th Feb 2003 18:02
yeah basically... the reason you base on the timer rather than the FPS is a simple reason really.

the Timer is a Constant based on your system speed which is a constant as well
the FPS is based on the loops ability to syncronise the data rendered with the data within the program, and the actual sync oftenly causes the some pretty major slowdowns.

thanks to FastSync you can actually eliviate most of this pressure of the actual rendering.

really placing the Sync outside of the IF...ENDIF statement slightly defeats the point - because you don't really want to sycnronise everything each loop, but for now its best not to worry too much into what the sync itself does cause that'll cause worse headaches

things that don't belong within time loops are thinks like object updates, memory writing and reading, Ai routines, thinks that won't require a set basis to work properly.

however usually i run Ai scripts about 5times per second, the reason being that they are very very processor heavy to have anything to complex and as reaction times of people arn't too great a tiney latency can be forgiven for faster gameplay.

netscript is another i have working outside of the sync - because this is extreme in its processor needs... especially on software modem systems (e.g. DSL, Internal Dialup, USB) - so you'd set them aside to run happily on thier own you only check the actual sync times with a ping timer

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Jaidex
22
Years of Service
User Offline
Joined: 28th Jan 2003
Location:
Posted: 20th Feb 2003 22:36
I have an idea for a method that I'm tempted to try out, I want to see what everyone thinks before I spend too much time on it.

How about an OO system with each object keeping track of the time it was last moved and when it's turn to move comes around, it can move itself based on how much time has passed. Does this sound reasonable? Of course it would also have to take other types of timing into account, not just object MOVEMENT (animation as well, etc). Is there a negative to this method?

Thanks for any input!

Jai

Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 20th Feb 2003 22:52
i would think a more valueable system would not so much be an OO system for time based movement, but rather a physics engine (similar to math engine) based on the time routines

i mean by all means an OO system timer would be cool, if you incorporate that into a physics engine that'd be dynomite in a fireworks factory... plus i'd love to be able to create Black&White more easily within Pro

if you would like to see the MathEngine (karma) gimma a shout cause its only like 10mb and i can email it, well as long as you promise not to use it commercially just to like create a clone (I can't afford the $50,000 second product licence and its already being used in Zoids & Space Hulk)

Karma is probably one of the better physics engines about, especially as you'll notice its trademark effects from stuff like Black&White, Unreal2, Grand Theft Auto3 (^_^) certainly does have a very very nice background ... and i know the DBS is already planning a similar system, but i'd certainly be happy to pay for such a system within Pro

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?

Login to post a reply

Server time is: 2025-05-18 04:38:35
Your offset time is: 2025-05-18 04:38:35