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.

Newcomers DBPro Corner / squeezing out system resources

Author
Message
SanBa Games
14
Years of Service
User Offline
Joined: 28th Nov 2009
Location: Silicon Valley
Posted: 11th Dec 2009 07:43
Hey, everybody...

As I'm learning DBP, I have been remaking classic games to try to get adjusted to the language and make sure I can replicate the game I have chosen. My first was 3d Space Invaders, which I released a couple weeks ago. I have since been working on an asteroids clone. It's not going nearly as smooth, but it's getting there. I have a couple problems, but I'm trying to solve them without help.

The main thing I'm here asking for right now is memory allocation, which is something I'm sure I can't learn on my own. There's no way I can play Dragon Age at full blast and have it be completely lossless but my little asteroids application is going slow as if it were really an Atari 2600 trying to run it.

So, are there any tricks or methods someone would be willing to share to help me squeeze some more juice out of my program? I can share my code, if you like. It's around 500 lines right now and has full base function except ship/asteroid collisions.



Sanba Games: Because We Can
Outscape
16
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 11th Dec 2009 08:43 Edited at: 11th Dec 2009 15:46
I have not read your code but..

If any of these are too complex for you, maybe learn a bit more then come back to this thread at a later date and try and do them.

Timers

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.

More on Timers

Instance

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.

heres a tutorial in the newsletter on something similar to instancing


Object Culling

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


ill add more when i return from my A+ exam...
back.. and i passed xD



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

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.

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)

http://en.wikipedia.org/wiki/Level_of_detail

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

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


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.

Read more on Trig and FPS


if u want more i can add more..

(if you are a lazy ass like me you'll never be bothered to do any of this though)



SanBa Games
14
Years of Service
User Offline
Joined: 28th Nov 2009
Location: Silicon Valley
Posted: 11th Dec 2009 09:57
Thanks for that, I hadn't thought of reducing the number of times per second my attributes are checked. It must be a strain to do collision detection so many times per second, and to update object position x,y, and z of every asteroid even though it isn't used that often.

I'll try implementing that, but it includes another question I've been wondering about: why use timer when you can DEC a variable every game time unit? Is it because you can get exact time with TIMER()? And if exact time isn't necessary (for example, the number of times I check for a certain variable to be within a certain range) is timer or checking the value of a DEC'ed variable faster?

Sanba Games: Because We Can
Outscape
16
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 11th Dec 2009 14:08 Edited at: 11th Dec 2009 14:39
timer is the internal computers timer
what happens is

timer is a large number (like 15+ digits)

and so you define a variable to the number of timer, eg,
if timer is 5000
h = timer()
makes h = 5000

now every milisecond the timer increases by 1, (so 1 second is 1000)

so if u do if timer()>h+1000 (if the timer has gone past another 1000 milliseconds)

then inside this if statement you have to define h as the new timer number (which would be 6000) or itll keep repeating the if statement.

every computers timer is the same, so if u play ur game at 10fps on my laptop itll be same as 60 on my pc.

the reason you use timer is because the more FPS u have the faster the unit will dec and therefore it wont work the same on different FPS, you gota think of Joe Bloggs in his basement with 16mb of RAM.


i added some more stuff to the second post



SanBa Games
14
Years of Service
User Offline
Joined: 28th Nov 2009
Location: Silicon Valley
Posted: 12th Dec 2009 04:53
Hmm, thanks for all the help so far, and congratulations on your test.

I've implemented a few of these already, and it seems to be going fine so far, although I'm still surprised how much of a resource-guzzler my little asteroids game is. One of my problems may be that I'm using DB particles for my explosions, but I am too lazy to try to come up with a unique particle system for such a simple game.

Do you think the game would run faster if I used Dark GDK instead of DBPro? And is it hard to learn if I've only ever used BASIC-based programming languages? I mean, I'm no schmuck, and I'm a pretty advanced BASIC programmer, but I've never used C++, and when I did it seemed ridiculous (even the print-to-screen command was outrageous, if I remember correctly). If I want to make nice-looking games, (I actually want to make a series of games similar to the old Nocturne game by Terminal Reality) will it be necessary to switch to Dark GDK?

Sanba Games: Because We Can

Login to post a reply

Server time is: 2024-11-16 09:20:45
Your offset time is: 2024-11-16 09:20:45