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
//how long does the timer last?
secondstimerlasts = 100
//set the timer variable
hi = timer()
//loop
do
//if timer has gone past another 100 miliseconds
if timer() - hi > secondstimerlasts
//redefine hi
hi = timer()
endif
sync
loop
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:
water = 50
do
water = hello(water)
sync
loop
function hello(water)
water = water - 1
endfunction water
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:
distancex = ObjectPositionX(obj1)-ObjectPositionX(obj2)
distancey = ObjectPositionY(obj1)-ObjectPositionY(obj2)
distancez = ObjectPositionZ(obj1)-ObjectPositionZ(obj2)
distance = SQRT((distancex*distancex)+(distancey*distancey)+(distancez*distancez))
if distance > 100
hide object obj2
else
show object obj2
endif
-.-
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