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 / Huge List of ways to increase your FPS

Author
Message
Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 11th Dec 2009 18:34 Edited at: 22nd Dec 2009 00:42


Hey, i was helping a person in the newcomers forum and i gave him a list of ways to improve your FPS, then i thought, what if the TGC community got together and made a master list of many possible ways to increase in-game FPS, and ultimately make dbpro games smoother for playing.

This may be the wrong thing todo, but i thought it was appropriate and so if anyone has a tip or idea or even theory (you have an idea to increase FPS but dont know how to code it), then say it here and ill add it to the list. So for example when me or other people goto optimize our code, we can make our games alot smoother to play.

Ill start off my repeating my previous post.
__________________________________________________


Plugins


Scroll to the bottom of this post to see the list of plugins that can improve your FPS.
Also if you use a plugin over your own dbpro code it will be faster.

-.-


Timers

read more


Timer EVERYTHING, well when i say timer everything, some things like variables redefinitions don't matter too much, but put everything into timers, this means it only runs once every X seconds, and therefore not every loop, since it doesn't need to be ran every loop to give the effect that it is ran every loop.

To do a timer do this


That means the code runs 10x every second, which can be much less than it does ATM, but the viewer doesn't see any real change.

-.-


Instance

Similar effect to instancing


Instancing Objects, Instance Object (command) means that you can basically clone objects using same data and greatly increasing FPS when spawning large amounts of objects.

-.-


Object Culling

read more


Object Culling (cull object (obj,0)) this means that all away drawn polygons aren't drawn and so your computer does less work.

-.-



Polys


Lower your polys, don't use high poly models

-.-


Global Variables


If you have a code that uses global variables for everything (and especially global floats), it may cause a minor fps drop.

And since every few FPS do count when its lower than 33, it is better to implement a system where your functions "talk" to each other instead of just ramming the info into a global variable.

Doing this is quite simple:
Example code:


That should return water back to the main code, and therefore removing the need for global functions.

-.-


Billboarding

read more


This is the simple method where objects that are drawn far away are replaced by an image, to give the effect of an object there, however it has gone from a tree with a lot of polys, to a plain with 2 polys.
This effect is very simple and is done via finding out how far the player is from the object, and if the object is an X amount of distance from the player the object is hidden and a plain is shown where this object is and is textured with a tree texture.

This means you can create whole forests of trees but the player is just loading around 5 trees and the rest are just billboards.

-.-


Drawing objects only if they are in a certain range


This is just a more basic version of Billboarding but it means that if the object is at an X distance away, it is hidden, and if it becomes closer again, it is shown, however if you use billboarding you don't need this as much.

example:



-.-


Large Floats


This is a small one, but if you have many large floats (especially if they are global), it may be unneeded processing done by the PC, if a normal variable would have sufficed or do the calculations inside the command that calls the function that uses the float, it may increase your fps slightly.

-.-


Level of Detail (LOD)

read more


Quote: "level of detail involves decreasing the complexity of a 3D object representation as it moves away from the viewer or according other metrics such as object importance, eye-space speed or position."


Billboarding is a form of LOD, however you might want to make up a new system for your LOD, one could be making multiple objects, eg say you have a model which is a house or something, you could make a very similar model but with a lot less polys and by using it like billboarding you will cause there to be a lot less polys drawn but it will keep the realistic effect unlike billboarding (unless its done well)

You also get LOD terrains where the terrain isn't drawn properly until you are near the area so then the polygon count is significantly less, with that said maybe you can come up with your own LOD system?

-.-


Share Vertex Buffers


Personally i haven't tried this but i hear this has a significant effect on FPS.
Using the Set Global Object Creation with the parameter of 1 means that all objects will share vertex buffers where available, you have to call this before any object is made.

-.-


Don't use DBpro particles


I don't know if it is still like this, but they used to be very laggy.

-.-


Be careful with shaders


Shaders effect the pixels printed on the screen, eg if a pixel is black, the shader may change this pixel to a Grey, and maybe implement a pixel offset.
All this calculation (having to be done every time the object/camera changes or you might get bad effects where the pixels go out of place) costs a lot of FPS, so use shaders at your own risk.

-.-


Ray-casting > bullets

read more


This is one that annoys me because i usually have a hard time getting ray-casting to work properly.
Ray-casting has very speedy calculations as to if an object is along an imaginary ray that is drawn between you and another 3d point.
Where as using objects as bullets means the computer has to process the movement of the bullet each loop, and can cause some errors (eg if the enemy has a thickness of 3, and the bullet moves 4 each step, then the bullet might move THROUGH the enemy and NOT count!).

-.-


Sync Rate


Sync rate is the amount of times the screen is redrawn per second, 60 is 60 timers per second, usually meaning you get a max of 60 FPS.
However this means your computer is processing a lot more per second, and seeing as the eyesight of a human is around 33 FPS, what you can do is lower the sync rate to say 40-50 and therefore decreasing the work load of the PC per second, and increasing your FPS.
This also means don't put multiple Sync commands in the loop. (and if you have to, use fast-sync).

-.-


Full Screen


I'm sure all PC gamers know this, if you play a game in full screen you get a lot smoother gameplay than if it is windowed, in any form.

I'm not 100% sure why this is, i guess it is because windows isn't doing so much work when a full screen application is on, and therefore meaning less work is done by your PC.
But this is a big FPS increaser.

-.-


Object Zones


A good system to make would be making zones of objects, this means that if one object in a zone, or a key object in a zone is not in the camera view, then all the objects are not in the zone.

An object zone is like an object group/collection, so you can have say 20 objects, 10 in Zone/Cluster 1, and 10 in Zone 2.
(you can define their zone in their type when you come to learn types and arrays)
This means every loop you check if one of these objects has left the visible camera view, and if so, you hide the whole group of 10 objects, if done correctly you can increase the FPS and still keep a realistic look.

-.-


Sprites to simulate effects


This may not majorly improve your FPS, however say you wanted to make things get lighter/darker for day and light, you can simply put a black, or grey sprites covering the screen and fade the sprite depending on the time of day, this means at night everything seems dark, and in day everything is bright again.

Another example is for rain, you simply put a plain in front of the player, load a rain texture, and scroll the texture downwards. And then by making the objects visibility low the player will feal like he/she is walking through rain, with only 2 polygons used, and no shaders/rain drops objects/particles.

-.-


Lock Pixels


The command Lock Pixels means it speeds up access for 2d dbpro commands and direct access to the bitmap that you lock.

-.-


Complex Maths Hurts FPS

read more


This one I'm kinda surprised about, every time you call Sin/Cos/Tan and other complex math calculations, you damage the fps by a fair amount, limit the amount of times you use them, or try to prevent using them at all.

-.-


Predefine / Precalculate reused values


This is similar to the Maths problem.
If you are constantly reusing a command (eg RGB(250,250,250)) it can save FPS by simply making a constant variable where this information is stored.

-.-


Dont Hide Sprites


This is an interesting one, don't hide sprites instead delete them, this is because hidden sprites still use CPU, it is better to delete and recreate them.



__________________________________________________


Plugins that fall into the category of:


Timers

read more


N/A - Supported in DBPro

-.-


Instance

Similar effect to instancing


N/A - Supported in DBPro

-.-


Object Culling

read more


Standard Culling is supported in DBpro.

DBPro:
Diggseys Culling DLL

-.-



Polys


N/A.

-.-


Global Variables


N/A

-.-


Billboarding

read more


DBPro:
No Plugins at this date, yet easy to implement.

GDK:
JGC Classes (closed source)

-.-


Drawing objects only if they are in a certain range


No Plugins at this date, yet easy to implement

-.-


Large Floats


N/A

-.-


Level of Detail (LOD)

read more


DBPro + GDK:
Kaedroho's BlitzTerrain Dll
Kaedroho's Object LOD Dll (Open Source)

GDK:
JGC Classes (Closed Source)

-.-


Share Vertex Buffers


Supported in DBPro.
No Plugins at the moment.

-.-


Don't use DBpro particles


Alternatives:
DBPro:
zParticle

-.-


Be careful with shaders


N/A

-.-


Ray-casting > bullets

read more


DBPro + GDK:
Dark Physics
Sparkys

-.-


Sync Rate


N/A

-.-


Full Screen


N/A - Supported in DBPro

-.-


Object Zones


DbPro:
No Plugins at the moment.

GDK:
JGC Classes (closed source)

-.-


Sprites to simulate effects


No Plugins at the moment, that i know of.

-.-


Lock Pixels


N/A - Supported in DBPro.

-.-


Complex Maths Hurts FPS

read more


No Plugins (that i know of) does maths calculations.

-.-


Predefine / Precalculate reused values


N/A.

-.-


Dont Hide Sprites


DBPro:
AdvancedSPRITES



-.-


Plugin Collections (1 plugin collection, many features)

IanMs Utility Plugin


__________________________________________________


Good Habits Section


This is the Good Habits Section Where basically, it lists good habits for a programmer todo (eg neat code, easily readable, which ultimately can lead to FPS increasement due to your code being laid out and basically programmed in a better way.

to be added


Attachments

Login to view attachments
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2009 19:26
You missed one of the more obvious ones - use plug-ins.

Generally, plug-ins will do the job faster than you can do it yourself (always benchmark though - prove that the plug-in is faster, don't assume).

Yes, write the code yourself if you want to learn how to do something, but if there's a plug-in available and it does the job faster, dump your code once you are done.

kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 11th Dec 2009 19:46 Edited at: 11th Dec 2009 19:46
Heres a plugin which allows you to easily add LOD into your games:
http://forum.thegamecreators.com/?m=forum_view&t=159658&b=5

It works well with multiple cameras too, meaning you can have many cameras all over your map and the objects will have different detail levels for each one! And its open source.

Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 11th Dec 2009 19:49 Edited at: 11th Dec 2009 20:10
@ Santa's Little Programmer
You raise a good point however plugins don't increase fps on their own .
Ofc i understand what you are saying but you need to know these methods if you are planning to find a plugin that provides the method, or if you were to create one yourself.
Ill add it to the list however, might add a list of plugins that increase FPS, but for now i wont. (unless people start listing them for me).

[edit]

@Kaedroho
Looks like I'm adding plugins to the list =)

[edit 2]
Does anyone know how i can make it so i can make it when you press the link itll take u to the part of the thread that lists the plugins

www.tgc.com/thisthread#Plugins%20that%20fall%20into%20the%20category%20of

or cant you with these forums?

[edit 3] to reduce my workload im going to edit this after a few replys from now on, so i dont need to keep editing. So dont expect your comment to be implemented straight away



=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 11th Dec 2009 20:07
I find precalculating cos and sin values into an array saves time and fps, rather than calling the commands every time.

Also use constants for any value which you work out a lot e.g. Screen width()/2, rgb(255,255,255) etc.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2009 20:40
Quote: "plugins don't increase fps on their own"

You missed the point - I wasn't saying that plug-ins will magically speed up your program. What I was saying was that if you have a choice between your own code doing a job, and a plug-in doing the same job, generally the plug-in will be faster - that WILL speed up your processing and contribute to greater FPS.

For example, sorting an array - you can write a quicksort routine to sort your array, but I'd bet that no matter how hard you tried, you couldn't make it run faster than the equivalent sort in one of my plug-ins.

An even simpler example - perform a single search and replace on a string. I'd bet my routine would be faster there too.

Finding a free object? Faster in my plug-ins.

I could go on for ages, but I'll stop there and simply say that there are two reasons that I add commands to my plug-in set. Firstly that they do something that DBPro doesn't already do, and secondly that they do a job that can be done in DBPro, but faster. If one of those isn't true for a connand, I don't add it.

kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 11th Dec 2009 20:55
AdvancedSPRITES is a lot faster at drawing sprites than DBPro is.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Dec 2009 21:21
I made a culling plugin a while back which culls off-screen objects:

http://forum.thegamecreators.com/?m=forum_view&t=122321&b=5

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th Dec 2009 21:48
If you are using standard DBPro sprites, don't just hide them and leave them hanging around - delete them. Hidden sprites eat up performance, delete them and recreate them instead.


Health, Ammo, and bacon and eggs!
Tom0001
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location:
Posted: 11th Dec 2009 22:00
Quote: "Drawing objects only if they are in a certain range

This is just a more basic version of Billboarding but it means that if the object is at an X distance away, it is hidden, and if it becomes closer again, it is shown, however if you use billboarding you don't need this as much.

example:

+ Code Snippet

distancex = dbObjectPositionX(obj1)-dbObjectPositionX(obj2)
distancey = dbObjectPositionY(obj1)-dbObjectPositionY(obj2)
distancez = dbObjectPositionZ(obj1)-dbObjectPositionZ(obj2)
distance = dbSQRT((distancex*distancex)+(distancey*distancey)+(distancez*distancez))

if distance > 100
hide object obj2
else
show object obj2
endif"


Doesn't the SET CAMERA RANGE command kind of...make that obsolete?
Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 11th Dec 2009 22:16 Edited at: 17th Dec 2009 16:31
Quote: "Doesn't the SET CAMERA RANGE command kind of...make that obsolete?"


Not if you want other objects drawn.

Eg say you had grass or something around you, you simply make sure that ones not near u arnt drawn, but other objects on the horizon are drawn

MSon
19
Years of Service
User Offline
Joined: 13th Jul 2004
Location: Earth, (I Think).
Posted: 11th Dec 2009 22:41
This was a good read.

Quote: "Object Zones

A good system to make would be making zones of objects, this means that if one object in a zone, or a key object in a zone is not in the camera view, then all the objects are not in the zone.

An object zone is like an object group/collection, so you can have say 20 objects, 10 in Zone/Cluster 1, and 10 in Zone 2.
(you can define their zone in their type when you come to learn types and arrays)
This means every loop you check if one of these objects has left the visible camera view, and if so, you hide the whole group of 10 objects, if done correctly you can increase the FPS and still keep a realistic look."


I assume this is using Object In Screen, i use this, but i check it against almost Every Object, i've never checked FPS Increase rate, but i assume even with checking every object, it will still allow an increase in FPS Rate.

Also

PICK OBJECT, Only call this once per loop.and store the Value, as running this in a for\next loop will majorley impact FPS Rate.

Everyone Be Cool, You, Be Cool.
Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 11th Dec 2009 23:09 Edited at: 11th Dec 2009 23:09
Quote: "This was a good read."


I got the idea from JGC Classes in which im hoping to buy within the next few days (JGC Classes is by Jason P Sage).





kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 11th Dec 2009 23:23 Edited at: 11th Dec 2009 23:26
Quote: "+ Code Snippet

distancex = dbObjectPositionX(obj1)-dbObjectPositionX(obj2)
distancey = dbObjectPositionY(obj1)-dbObjectPositionY(obj2)
distancez = dbObjectPositionZ(obj1)-dbObjectPositionZ(obj2)
distance = dbSQRT((distancex*distancex)+(distancey*distancey)+(distancez*distancez))

if distance > 100
hide object obj2
else
show object obj2
endif""


This code is faster



Pythragoras is: A^2=B^2+C^2
If your just comparing the 2 sides, you don't have to square the right hand side.

Because if A=sqrt(B^2+C^2) then A^2=B^2+C^2
Squareing is more faster than Square rooting.

Randomness 128
17
Years of Service
User Offline
Joined: 13th Feb 2007
Location:
Posted: 12th Dec 2009 02:09
Quote: "Sync rate is the amount of times the screen is redrawn per second, 60 is 60 timers per second, usually meaning you get a max of 60 FPS.
However this means your computer is processing a lot more per second, and seeing as the eyesight of a human is around 33 FPS, what you can do is lower the sync rate to say 40-50 and therefore decreasing the work load of the PC per second, and increasing your FPS."

Lowering the frame rate will increase the frame rate?

All anti aliasing and no anisotropic filtering makes Jack a dull texture.
Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 12th Dec 2009 02:14
Lowering the frame rate cap will increase the frame rate?



Randomness 128
17
Years of Service
User Offline
Joined: 13th Feb 2007
Location:
Posted: 12th Dec 2009 02:43 Edited at: 12th Dec 2009 02:43
I just tested that with an old unfinished project. Tried it with sync rate set to 250, 500, 1000, and 2000. Got a steady 238 fps with all 3 of them. I don't see how a higher frame rate cap would make the computer work harder if the cap is already higher than the frame rate.

Anyone have any tests that show this working?

All anti aliasing and no anisotropic filtering makes Jack a dull texture.
Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 12th Dec 2009 16:17 Edited at: 12th Dec 2009 16:28
in my old app Archer FPS, with 60 sync rate i was getting 20-30FPS, but when i changed the sync rate to 40 it was 30-40FPS, it might depend on you having alot of work running each loop.

i think it was because, it ran 60 times per second, but it may not have been able to run the code that much, and that amount of repetition is unneeded.

but when i made it 40x per second it might have been able to do it with time to spare but there was no visual change for me.

im not sure how it helped, it just did =S



General Jackson
User Banned
Posted: 12th Dec 2009 16:19
Oh man this is so helpful,
thanks man

Randomness 128
17
Years of Service
User Offline
Joined: 13th Feb 2007
Location:
Posted: 12th Dec 2009 16:58
Quote: "i think it was because, it ran 60 times per second, but it may not have been able to run the code that much, and that amount of repetition is unneeded."

Capping the frame rate doesn't force it to run at that frame rate even if it can't, though, that doesn't make sense. With the frame rate capped at 60, it won't actually be running the code 60 times per second unless it's able to achieve 60 fps. If it did work that way, timer based movement would end up being done automatically, and uncapping the frame rate would have to make it infinitely slow.

Quote: "im not sure how it helped, it just did =S"

I'm not sure either, but it must have been some other reason. =S

All anti aliasing and no anisotropic filtering makes Jack a dull texture.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Dec 2009 16:58
You should always run with sync rate set to 0 and control things with timer based movement. Setting the framerate cap lower actually adds a delay into your code with is counter-productive to increasing framerates.

My signature is NOT a moderator plaything! Stop changing it!
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 12th Dec 2009 17:04
Wow very usefull info.

Also use Inc/Dec it's faster than a=a+1
PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 12th Dec 2009 17:50
WOW this thread is awesome, i am bookmarking it

dont hate people who rip you off,cheat and get away with it, learn from them
Duke E
15
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 13th Dec 2009 01:52
"Sync Rate" is obsolete, use the "Set Display Mode" command and just add a "Sync On" after that. The "Set Display mode" sync parameters either fixes the sync to your current screen frame refresh or lets it loose for you to use your own timers and it is accurate, "Sync Rate" is not.

Regards
Daniel wright 2311
User Banned
Posted: 13th Dec 2009 03:51
this is also a note i have tested myself that might help people with frame rates.

with in the loop, keep all your coad lines real close to each other, this way the loop dont take as long to loop.so if you have lines of code that are spaced pretty far from each other move them up a line down from the line abouve, i know it sounds crazy but i did it and I see a little of a difrence.every little thing you can do you should do it. becouse if its spaced then the programe has to do a line jump, every line jump takes up time.

hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 13th Dec 2009 04:56
Quote: "i know it sounds crazy but i did it and I see a little of a difrence.every little thing you can do you should do it. becouse if its spaced then the programe has to do a line jump, every line jump takes up time."


??? Isn't whitespace ignored by the compiler?

CodeSurge
Version 2 coming soon!
Daniel wright 2311
User Banned
Posted: 13th Dec 2009 05:58
If there is a numbered line it still jumps from line to line, it cant inore lines, if it did then it would not read any line at all. it has to count how many lines to jump, imagine counting in your mind over and over and over intill you reached that next line of coad, well if there are less lines then less counting, less pc usage.

hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 13th Dec 2009 06:09
Hmmm, there is actually something to what you say. It may be the compiler trying to remember what the line numbers are in case of a runtime error or something. I just created a very simple spinning cube demo with over 30,000 blank lines. It took a fair amount longer to compile, and it seems to run about 20 fps slower than when I condensed it down to 8 lines.

CodeSurge
Version 2 coming soon!
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th Dec 2009 06:15
Quote: "If there is a numbered line it still jumps from line to line"


You don't 'jump' from lines to lines, you just read a list of instructions. I can't be bothered to check the actual disassembly, but the output .dbm makes no mention of extra data being written based on line count, but if blank lines result in extra data being written then wow, that's really stupid.

hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 13th Dec 2009 06:34
Quote: "but if blank lines result in extra data being written then wow, that's really stupid."


That's basically what I was thinking. However, my little test did drop about 20 fps by having around 30k lines between statements in the loop. I couldn't see any noticeable increase in exe size, though.

CodeSurge
Version 2 coming soon!
Daniel wright 2311
User Banned
Posted: 13th Dec 2009 06:39 Edited at: 13th Dec 2009 06:46
it does jump from line to line, i know for a fact, all programs do.the extra lines are based on all lines being writen, i know that did not sound right but how most programers right there code is line to line with no spaces. now i know this has no effect in programes like c++ or even dark basic pro but i would cram as many lines together as you can to save pc usage.it will defintly speed things up.

edit, of corse this really only matters if your making a huge game
with tons of code. im shure with small games and programs it really woulod not matter but if your trying to get as much fps as you can this is one of them, just adding to the list,lol.

Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 13th Dec 2009 06:56 Edited at: 11th Aug 2010 23:43
Quote: "it does jump from line to line, i know for a fact"


That sounds a lot like a one those BASIC myths from 80's to me.

Daniel wright 2311
User Banned
Posted: 13th Dec 2009 07:12
That sounds a lot like a one those BASIC myths from 80's to me.

lol, that was funny

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 13th Dec 2009 07:20
Quote: "That sounds a lot like a one those BASIC myths from 80's to me.

lol, that was funny"


He was being serious.
Daniel wright 2311
User Banned
Posted: 13th Dec 2009 07:47 Edited at: 13th Dec 2009 07:49
ohh, well, then i guess i need to specify a little better. we read with a clear understanding, a pc reads as its told to. it can only do what it is told. it can not think by its self or read at that. so if i say ok, go read only thease lines the pc will not understand, so i have to code this, well if i code a pc to not read every line then the program will not run. but if i tell the pc to read every line the program will run. my point is when dark basic pro was writen, it was written to read every single line. how do i know this? because the dark basic pro team or who ever wrote it did not know what lines you would use to build your program. so it has to read every line.does it skip to the next line of code, no, it does not,it jumps from line to line.if you have no code in between 10 lines of code it is still going to read every single line even if its blank. this is what will slow down your program. and this is all i meant from it.this is why it will speed your program up a little bit if you cram your code together.

Hockeykid
DBPro Tool Maker
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 13th Dec 2009 08:14
Quote: "ohh, well, then i guess i need to specify a little better. we read with a clear understanding, a pc reads as its told to. it can only do what it is told. it can not think by its self or read at that. so if i say ok, go read only thease lines the pc will not understand, so i have to code this, well if i code a pc to not read every line then the program will not run. but if i tell the pc to read every line the program will run. my point is when dark basic pro was writen, it was written to read every single line. how do i know this? because the dark basic pro team or who ever wrote it did not know what lines you would use to build your program. so it has to read every line.does it skip to the next line of code, no, it does not,it jumps from line to line.if you have no code in between 10 lines of code it is still going to read every single line even if its blank. this is what will slow down your program. and this is all i meant from it.this is why it will speed your program up a little bit if you cram your code together."


So why didn't Lee or whoever have the compiler remove empty lines during compiling of your code?

Daniel wright 2311
User Banned
Posted: 13th Dec 2009 08:26
well, i dont know but i do know this, i tested it and i got better frame rates with less lines,

also doing this right here speed my game up by at least 20 percent. i guess its becouse the pc uses less memory to play the game.

do this to all your code and it will spped things up. this is my whole menu in a couple lines of code with brakets



hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 13th Dec 2009 13:20 Edited at: 13th Dec 2009 13:45
The only thing I can truly confirm is that lots of whitespace appears to slow down compiling. I don't know why I got a slightly lower FPS last night when I was trying this (maybe my computer was running some other background process at the time?) but right now, I can't see any difference, and the size of the .exe is exactly the same.

The file called "silly 142k.exe" has about 20,000 blank lines between each command for a total of 142,941 lines. Silly.exe is only 8 lines long.

I can't believe Lee wouldn't know how to have the compiler remove blank lines. I know almost nothing about x86 assembler, so someone can correct me if I'm wrong on this, but doesn't the processor just jump from one address to another in memory, which means it wouldn't matter at all how much whitespace was in there?

CodeSurge
Version 2 coming soon!

Attachments

Login to view attachments
Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 13th Dec 2009 13:30
im pretty sure dark basic would remove white spaces and remmed code, when compiling.



Daniel wright 2311
User Banned
Posted: 13th Dec 2009 13:45 Edited at: 14th Dec 2009 02:17
i guess miss my point here, this is my point, less lines = more time the pc has to function, ill show you what i meen.

my old code

i edit this out for the sake that no one thinks im right on this, mabey im not so im removing the code.

hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 13th Dec 2009 13:47
Sorry, but you still don't get it. The only difference is in the time it takes to compile it. The compiler knows how to skip over blank lines and comments, and the resulting machine code is exactly the same.

CodeSurge
Version 2 coming soon!
Phjon
18
Years of Service
User Offline
Joined: 28th Nov 2005
Location:
Posted: 13th Dec 2009 13:50
Interesting thread.

I know this is a bit of a "plug", but if anyone wants to analyse code performance/speed more efficiently, then I have some programs on the WIP board that'll do the job - a system called PerfAnDBPro.

Does anyone think it would be useful for me (or someone) to run PerfAnDBPro on some sets of code that have been optimised with some of the suggestions above, and perhaps post some of the results to this thread?
Daniel wright 2311
User Banned
Posted: 13th Dec 2009 13:51
then why has my fps gone up then, when all i did was this?

hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 13th Dec 2009 13:59 Edited at: 13th Dec 2009 13:59
Quote: "then why has my fps gone up then, when all i did was this?"

I can't say for sure. It could be a number of different things. Last night, my test with lots of blank lines was running a few FPS slower than the condensed code, but right now, I can see no difference.
Edit: And the size of the two .exes are exactly the same down to the last byte.

Sorry for taking this thread off topic.

CodeSurge
Version 2 coming soon!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Dec 2009 14:04
Wow. Just ... wow! Myth it IS.

If you have one of the very-early 80's BASIC interpreters, then yes the lines were reinterpreted each time they ran, and if the interpreter you were using was able to hold blank lines then that could take a little time to skip over.

This is the 21st century though, and DBPro just does not work like that.

Quote: "then why has my fps gone up then, when all i did was this?"

Maybe you should let your system settle after carrying out a compile (ie don't run it from the IDE), shut down your music player, web browser and AV, then take the timings on a relatively quiet system.

sladeiw
14
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 13th Dec 2009 21:11
Phew! Sanity prevails... I started writing a response when I saw this thread earlier, then I realized it was just going to be a "for God's sake, pull yourselves together!" type rant and abandoned it.
Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 13th Dec 2009 23:14 Edited at: 17th Dec 2009 16:27
can we get back on topic?
Its starting to trail off it.



KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 14th Dec 2009 17:14
It's worth noting, if only because it took me a while to figure it out, that SYNC doesn't just control frame rate, but also controls how many times per second your main loop runs.

I know it sounds silly now, but I initially thought that the main loop just ran flat out as fast as it could, and sync just made sure it refreshed the screen at whatever rate you set it to.

If you set SYNC 10, then your main loop only runs 10 times a second. So it's important to understand that when figuring out timings.

So to explain why Outscape got a more consistent FPS when he set the SYNC RATE lower is the main loop was taking more than 1/60th of a second to execute, and so it slowed the frame rate. When he set it to 40 it gave the main loop more time to finish, and so gave a more consistent rate.

Hope that helps.

Outscape
15
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 15th Dec 2009 21:51
if anyone knows any more ways on how to increase ingame FPS to add to this list it will be great for me and including the rest of the TGC Dark Basic community.



TuPP3
17
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 20th Dec 2009 20:06 Edited at: 20th Dec 2009 20:10
I can't get that timer code to work the way it should...
This returns something 80000000 every loop.


I'm using lots of timers so this would be sweet FPS increase because I really need timer like once in a second for bigger timing.

Btw. If Sin/Cos/Tan commands are so heavy for the FPS, how should I make seamless movement back and forth, like gun breathing movement(is it faster if I use animation?)

Or when you run and you need to simulate the camera movement like you would shake head in real life, how I seamlesly shake it without sin/cos/tan?

Login to post a reply

Server time is: 2024-04-25 02:52:01
Your offset time is: 2024-04-25 02:52:01