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 / Low FPS = Slow game :'(

Author
Message
Guitarussia
14
Years of Service
User Offline
Joined: 16th Nov 2011
Location: NH, USA
Posted: 3rd Feb 2012 06:08
Howdy! 

My problem: 
While recording the progress of my game, I noticed the frame rate drop to around 20 fps and consequently all movement in game became slow.

To expand on it:
My sync rate is set to 60 and that is how many times my screen is set to refresh normally. The game runs like a mustang unless I'm recording it with Fraps. Fraps seems to dislike DBPro so it simply destroys the fps (mind you this is on a computer that can run Crysis maxed and couple windows of HD porn running in the background). What I noticed is that the speed at which my game is running seems proportional to the loss in fps - the game is running at 1/3 the normal fps so all movement is also about 1/3 regular pace. It's like The Matrix all of a sudden.

My goal:
This is a problem I didn't anticipate, but I'd love to get around it. I'm not necessarily asking how to get higher fps, that's not what worries me. I'm worried about the game literally playing slow-mo as frames decrease. My player normally moves 6 units per second. When I start recording and the frames drop by 2/3, he now moves 2 units per second (aka annoying). It normally takes 1 second to equip a weapon, with frames dropping to 20 he's now taking 3 seconds to pull it out. It normally takes 1.5 seconds to jump and land, now he jus--- you see where this is going. 

Oh wait. My Goal:
I need all movement to stay constant, regardless of what the frames per secondary be! I want 6 units per second to stay at 6 units per second whether the game is running at 20 fps or over 9000. Who's got ideas?

Inspired, waiting to be enlightened
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 3rd Feb 2012 09:50
Search the forums for Timer Based Movement

Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 3rd Feb 2012 09:52 Edited at: 3rd Feb 2012 09:54
this isn't particularly difficult to fix, it just requires a different way of thinking

anything and everything relating to doing stuff per loop, needs to be changed to doing stuff according to how much time has passed

Movement is rather easy to fix, all you need to do is store 2 variables and find the difference between them. I.E.



The first line is to set the variables, since if you don't then upon first execution you'll be comparing a very high value to 0, and it'll assume your framerate is 1 per hour or whatever, resulting in the first loop making everything INSANELY fast. So set both to timer and assume 60fps by taking away 16ms from the oldtimer

You must set both variables again, put 1 at the very beginning of the loop, and the other just before the 'sync' command. So that upon the next execution it'll compare the old time (lets assume 100ms) and the new time (116ms), meaning it's taken 16ms to update the screen, which is 60fps.

When actually moving the object, you should specify your intended movement per second (in this case 100.0 units), then divide that by the framerate. So if you have 1fps, the unit should move at 100.0 per loop. If you have 20fps it'll move at 5.0 per loop. Keeping the same overall speed of 100.0 units per second. Make sense?

I'd recommend simplifying/shortening your actual code by writing a function



That should get you started, You need to get your head around that first, then move on to more complicated stuff. Movement is quite easy but you also need to change the speed of
- object animations
since it'll still be playing at 1/3rd normal speed at 20fps)

- projectile calculation
it's all well and good being able to move them faster, but you need to check for collision between those 2 points, and not just where it currently resides, otherwise it might go through walls

- weapon firing speed
low rates of fire are usually not such a big deal, for instance if your weapon shoots 2 times per second, well then you won't notice much difference until it drops below 2fps, but if your fire rate is say 30 rounds per second, then anything below 30fps will be restricting the fire rate. You need to check time elapsed and possibly fire several rounds in a single loop, and get the bullet spacing correct so they aren't all bunched together at the same position

- damage over time
much like above, if you have an effect causing damage every 1/10th of a second then below 10fps will cause the damage effect to be slower than intended. Additionally (this applies to above) if the framerate is not a multiple of 10, it'll be slightly out. 19fps for instance will cause slightly less damage per second, than 20fps
Guitarussia
14
Years of Service
User Offline
Joined: 16th Nov 2011
Location: NH, USA
Posted: 3rd Feb 2012 18:26
Oh snap! Thnx dudes. =PRoF= pointed me in the right direction but Millennium just nannied me through it lmao. Now how I give you m8s good ol fashion forum rep?

Inspired, waiting to be enlightened
Gunslinger
19
Years of Service
User Offline
Joined: 29th May 2007
Location:
Posted: 3rd Feb 2012 19:12
@Millenium7

How am i doing this?

i do all of my stuff like this:

if time > reloadtime
'reload'
reloadtime = time + 123456789
endif

how can i do this with the correct FPS calculation?
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Feb 2012 20:02
WoW just WoW
this was interesting for me nice one guys...
Hopefully I can implement this later this month somehow...

Login to post a reply

Server time is: 2026-07-11 04:43:45
Your offset time is: 2026-07-11 04:43:45