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 / Optimizing the game

Author
Message
Escaped Ape
19
Years of Service
User Offline
Joined: 25th Jul 2006
Location: Germany
Posted: 4th Nov 2006 14:30 Edited at: 4th Nov 2006 15:13
I have some problems with my game performance and I hope you can give me some tips about structuring the game.
The game has a few enemys who are shooting on you, my question is now: how do I store the bullet-objects and sounds?
Is it better to store a default amount of sounds when loading the game (sounds(100)) and then loop through the array and ask if the sound sound(x).nr is still playing?
Or is it better to clone these sounds directy when they are needed and then delete them?
The same question with the bullet and particle objects which are temporary needed (burning stuff etc.).
Right now my game slows down with 10 enemys, shooting on me and playing sounds.
I always check for a free object number and then clone a new bullet-object when they shoot.

Any other tips maybe?
I've read this thread:http://forum.thegamecreators.com/?m=forum_view&t=32948&b=10
but there is nothing mentioned about this point I'm afraid..

Greets,
ape.
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 4th Nov 2006 15:13
I made a few functions that used the cloning method. That seemed to work well and not be too bad on performance. I basically loaded in all my sounds from 100 upwards, and then used the 1-100 range for sound playback. Then you can impose your own sound limit and tweak it for performance reasons. I think I generally stuck with about 20-30 simultaneous sounds, although I don't think that many were ever played back at the same time.

With regard to objects, don't ever delete them during the main game loop. Deleting objects causes and update of the vertex buffers which can be very slow. Some very complex games with lots of complex objects experience up to a second of delay when an object is deleted. With all your objects, you need to come up with a pooling system. For example, give yourself a particle cap of maybe 100 objects. Either make them in advance, or make them in real-time, but don't delete them. Just EXCLUDE them when you dont need them anymore and re-use them again when you need them back. This is the best approach for all your enemy models, guns, bullets, particles etc. You can then delete objects at the end of the level, or during another paused period ready for the next session.


Escaped Ape
19
Years of Service
User Offline
Joined: 25th Jul 2006
Location: Germany
Posted: 4th Nov 2006 15:25 Edited at: 4th Nov 2006 15:26
I'm not quiet sure how you realize your sound-functions.
What I am using right now is a function to load all sounds before they are used:


This method works very slow...or do you mean something else?
When i create new objects or sounds i use this kind of method to get a free number:


and then use them inside of the game:

this is what i use to get a free object number(same for the sound)
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 4th Nov 2006 17:34
Here's some code from Claymore Island ..

Firstly, I load in all the sound files I'm going to use (so each WAV, just once).

Here's a function I use for playing back a sound:


I dont use 3D sounds in Claymore Island, as I have this simple function which sets the volume and pan instead for stereo only.



For sound slots I would use something like this:


It also checks for the sound playing and if its not playing, it deletes it, otherwise you'll be leaving a lot of unnecessary sound data in memory. If you're cloning a new sound every time someone fires a bullet without deleting the old sound data, then you'll eat up memory quite fast.


Escaped Ape
19
Years of Service
User Offline
Joined: 25th Jul 2006
Location: Germany
Posted: 7th Nov 2006 22:06
hm the only problem left now is playing sounds..
Here what i use for sound output:


This code works very very slow.
Maybe the freeSound() function eats too much performance if i have many shots at one time?
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 7th Nov 2006 23:10
That looks pretty efficient. My only guess is the 3D sounds are perhaps slow. How about trying it without 3D sounds just to test performance and see if that's where the slow down is?


Escaped Ape
19
Years of Service
User Offline
Joined: 25th Jul 2006
Location: Germany
Posted: 8th Nov 2006 16:32
Using normal sounds makes it a bit fast but not fast enough..
I just can't find the reason for that..
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 8th Nov 2006 16:39
Hmmm. How about removing sound completely? Just to try and narrow down if its a sound problem or not.

It's possible that if you're using onboard mobo sound you have a cheap chip that can't mix many voices. If you actually have 50 simultaneous sounds and your hardware doesnt support that, that'll take a fair bit of CPU mixing. Maybe drop the 500-550 range to 500-520 and see if that helps.

Also, try making your sounds as short as possible. If for example you're playing a new sound for every shot from a machine gun (say 5 shots per second), then you want the bullet sound to be about 1/5th of a second long, so that on average only 1 sound will be playing at any one time per gun. If you're using a bigger old 1 second long sound on a gun that fires 10 shots per second, then you're playing 10 sounds simultaneously which is a lot of voices for one gun and a lot of mixing drain.


Escaped Ape
19
Years of Service
User Offline
Joined: 25th Jul 2006
Location: Germany
Posted: 9th Nov 2006 15:00
without the sounds the game is working fine, that's why i opened this topic
The reason for the low of performance realy seems to be my soundcard - on another guys pc its running smooth.
Thanks for help m8

Login to post a reply

Server time is: 2026-06-11 14:46:00
Your offset time is: 2026-06-11 14:46:00