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 / How to increase the FPS rate ?? FOR PROFESSIONAL

Author
Message
maicl
19
Years of Service
User Offline
Joined: 19th Jun 2007
Location:
Posted: 17th May 2010 09:12
Hi guys .
My question is , how to increase the fps rate in my game , when I create more than 300 plane , I notice that the fps rate goes down .
So , I ask professional people and who has a long Experience with darkbasic to help me
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th May 2010 10:05
Professional only, that rules out most the people on this forum..

But if anyone can help, then things to reduce frame rates would be fewer objects on screen, lower poly counts, lower screen resolutions, fewer maths calculations (I.E. pre-calculate as much as you can), smaller, modular efficient code (As opposed to many loops and unnecessary function calls.

My signature is NOT a moderator plaything! Stop changing it!
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 17th May 2010 15:10 Edited at: 17th May 2010 15:11
If we could see your code, we could be a little more specific helping you.

With something a simple as displaying 300 planes, I get around 4500 fps with my aging pc.

>Edit<
Assuming you mean plane as in make object plane 1,20. and not some detailed model of an airplane...

maicl
19
Years of Service
User Offline
Joined: 19th Jun 2007
Location:
Posted: 17th May 2010 16:39 Edited at: 17th May 2010 17:01
OK ..
here is my code :

I Have not finished it yet , the Shooting system needs further dditions .




I know that I have to delete bullet objects , but also I want to know why is the fps rate goes down after 300 plane ??

And thank you mobiius for replaying .
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th May 2010 17:00
Built in collision like that will not be hugely fast, ever, you need to optimize things a bit I think. Probably best to start by looking at Sparky's collision DLL - it's free, fast, and absolutely brilliant and line intersection collision which is good for bullets.

I think that would give a chunk of performance back, but there are other issues there.

It's a bad idea to create objects in your main loop unless you absolutely have to. For instance, I would pre-create all those bullets and hide them, then only show them when they get used - maybe even using their visibility state to decide if they should move or not.

A matrix is not very optimized either, although you are only making a 10x10 grid matrix, you might want to expand on that in future, in which case you might see the performance drop again. Often it's best to just use an object, or even advanced terrain as that has visibility culling to improve performance.

2D operations like lines, circles, and text all cost performance - only have them display when debugging, don't show them all the time - or swap to a text plugin; D3D for instance has tons of useful features. In the old days we would store the frame rate (or whatever) and only show it when pressing a key, so that the rate could be measured without the drawback of drawing the actual FPS values . I think that using sprites for your aim reticule and stuff would be faster, and prettier, and give you much more control over how it looks.

With DBPro it can quickly slow down if you let it, but limiting those time consuming operations to a bare minimum can really help. And then there's other optimizations too, like if you made a 2D array and stores distance and angle data in there. I checked how much faster it is to read from an array, as opposed to SQRT - and an array is about 2.5 times faster. For a little pre-calculation it's possible to save a lot of frames, especially if you are using collision checks a lot. A range check might help as well - only check collision if the enemy is within X range of the bullet.


Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th May 2010 18:08
As Van B says, repeatedly creating an deleting objects in your main loop will eventually slow your game down to a crawl. Don't do it. Follow Van B's advice and create the objects before the main loop. Then show/hide them as necessary in the main loop.
maicl
19
Years of Service
User Offline
Joined: 19th Jun 2007
Location:
Posted: 17th May 2010 22:10
VAN B .. Words are not enough to thank you
I did like you told me to do , and now , my frame rate rose to more than 200 fps ..

Thank you ..
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 17th May 2010 22:44 Edited at: 17th May 2010 22:46
I never understood why Text makes things so slow.. Is this a DBpro specific thing? We have all kinds of DirectX games that have Text all over the place, is why I ask. But they don't seem to have a problem with it - and it just seems to me if DBPro is using DirectX/D3D as well, that it seems weird that simple things like drawing some text to the screen, would slow things down so much.

I'd really be interested in why this is, if someone could explain it. Is this something to do with the performance difference of printing text, vs something like using Bitmap fonts (which I'm guessing is what a lot of the texts in most games as made up from) ?

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 18th May 2010 00:49
It is definitely a dbpro specific thing, though im not sure what the cause is. If text slow down is a problem, try using cloggy's dll/d3dfunc. It has really fast lines and text stuff, by making calls directly to directX functions.


Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th May 2010 15:54 Edited at: 18th May 2010 15:54
And get rid of the..
Quote: "sync sleep 1 : FastSync"

combo and replace it with just plain old..
Quote: "sync"

Doing that increased my framerate from 51FPS (After shooting) to 79 (After shooting).

Again, don't use the default text commands or the collision commands and precalculate everything! (if you can)

My signature is NOT a moderator plaything! Stop changing it!
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 18th May 2010 20:32
Well, I just got rid of the sleep stuff and just used normal sync. Frame rate leapt from 31 to 1200+! Way too fast. Then just added ,1 at the end of your set display mode command to limit it to the monitor. Hey Presto! 60fps smooth as silk. Until you shoot a lot. but it seems you have that covered.
I agree with Mobiius that you should never slow your game loop on purpose by adding in a sleep command. Unless it is an app where you may be using other programs, then you may want to limit the programs use of the cpu.

http://s6.bitefight.org/c.php?uid=103081
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th May 2010 20:51
Timer based movement FTW!

My signature is NOT a moderator plaything! Stop changing it!
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 19th May 2010 18:07 Edited at: 19th May 2010 18:09
Just a little side question related to an application I'm making as a side project...

Quote: "As Van B says, repeatedly creating an deleting objects in your main loop will eventually slow your game down to a crawl. Don't do it. Follow Van B's advice and create the objects before the main loop. Then show/hide them as necessary in the main loop. "


Does this include after changing the display mode? My application works perfectly except for...

The window is frameless so I have my own button to minimise the window to smaller window (not true minimised). So you can flick between a larger window and smaller one. Now in order to do this correctly it has to basically change the display mode and reload everything. After min-max 6 times the frame rate drops from 60 to 5fps. Theres no frame drop until the 6th. Yes this could easily be a bug in my code, but I was wondering if there was a bug deeper than that in changing displays, loading objects, images and bitmaps?

Thanks
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th May 2010 18:48
My last game had to be more system friendly so it would re-load all the image media when restored - but no 3D media. I think it's the 3D media that would be causing the issue, I've had issues with deleting and reloading objects. Maybe it can't quite delete the 3D media when minimizing, it gets deleted but not neatly enough.

Might be an idea to track the memory available and see how it's affected with minimize and restore. Maybe there's a way to flush out everything, as that's the case anyway with a display mode change.


Health, Ammo, and bacon and eggs!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th May 2010 19:07
Quote: "The window is frameless so I have my own button to minimise the window to smaller window (not true minimised). So you can flick between a larger window and smaller one. Now in order to do this correctly it has to basically change the display mode and reload everything."


I'm not sure I understand what the problem is exactly. The following code seems to work without having to reload anything.

NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 19th May 2010 21:12
Thanks, the changing of the window size isn't the problem, the problem is created by the fact it doesn't change the resolution. Changing it clears everything except variables. When the window size is changed, it has to reload objects, images and bitmaps, reinitialise D3D, create new lights etc. It only seems to liek to do it a few times. I've disabled this for now as it's not 100% required, but it had it's uses for lowering memory useage when required.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th May 2010 23:41 Edited at: 20th May 2010 00:36
Quote: "the problem is created by the fact it doesn't change the resolution"


I missed that part of what you were doing.

Quote: "It only seems to liek to do it a few times."


Sounds like a bug somewhere.

Edit

Out of curiousity I tried to reproduce your problem - but all I get is a crash. Perhaps I did something silly? Here's the code I used. It should change the display mode every 60 frames. It crashes when it changes the display mode.



Edit2 Oops! The above code works fine for me. I'll spare you all the one which fails till I've checked it again.
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 20th May 2010 01:41 Edited at: 20th May 2010 01:47
Increasing Frame Rate

1. Don't use square root commands. Always cheat with range check.
A^2 = B^2 + C^2
ie. Keep player distance squared and compare with other squared distances.

2. Don't Load/Delete all the time. Most stuff is okay if rarely done. If it's always or multiple times per frame. Manage your resources better. Hide things. Maybe setup some object management.

3. Use Exclude Object.

4. Use Fog. Exclude things behind unless it shows badly on screen. (Like silhouettes against a Sky)

5. Exclude everything you can that isn't on Screen. "Object In Screen()"

6. Use Portals. If camera is in one part of a level, setup a method for identifying that area, and Exclude everything that is in other designated areas you know the camera cant see from that area. It's not formal. But it works if two rooms are close by, in camera view, and within your fog range.

7. Use FastSync(), Timer Based Movement. This will reduce any remaining problems with fps from being noticeable. And you can still control your program properly.

8. Don't use built-in 2d text and drawing commands.

9. Don't load sounds over and over, manage them and only load them if needed (if too many to load all at once). Pre-Load them if there's just a few in total.

10. Don't use built-in collision.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th May 2010 02:02 Edited at: 20th May 2010 02:03
Quote: "5. Exclude everything you can that isn't on Screen. "Object In Screen()""


Hmm... Mage, your not drunk right. 'Object In Screen()' doesn't work correctly at all.

Another one to add would be to make some the game classes update independent of loop fps. Basically, if a game updates at 60 fps, there's no need to update certain game classes at the same speed. Some only need to be updated at half that or even less.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 20th May 2010 02:58 Edited at: 20th May 2010 03:00
Absolutely Sasuke.

11. FPS Independant Events. I usually call this a "Heartbeat" since it will trigger once every second, or a half beat 1/2 second, or a five beat every five frames. This is good for things like standing in lava, damaging the "Player" in bursts so things like hit-scans, and calcs happen much less often.

"'Object In Screen()' doesn't work correctly..."
'Object In Screen()' I noticed that this has problems if XYZ of an object is off screen but if the object extends into view, sometimes the object will list as off-screen incorrectly. I listed it as a method since in my experience it doesn't occur often enough to be a problem. Results may vary.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 20th May 2010 09:38
Quote: "Object In Screen()' I noticed that this has problems if XYZ of an object is off screen but if the object extends into view"

Or if it's behind the camera, but within view. (If the camera pointed backwards?)

My signature is NOT a moderator plaything! Stop changing it!
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 20th May 2010 14:05
Quote: "Sounds like a bug somewhere."


Quite possibly. After about 12-14 switches it complains about not being able to load a bitmap that worked fine all the other times. If I decide to put this back in I'll see if I can fix this.

Quote: "Out of curiousity I tried to reproduce your problem - but all I get is a crash"


Hehe yes it took me a while to make it work in all the situations Windows can throw at it. Its very easy to make it crash, and without the Matrix plugin almost impossible.

Login to post a reply

Server time is: 2026-07-25 14:17:33
Your offset time is: 2026-07-25 14:17:33