Weapon system / Bullets problem

Blitz3D Forums/Blitz3D Programming/Weapon system / Bullets problem

Mortiis(Posted 2009) [#1]
I'm having some problems with my weapon system. I have a chaingun which fires textured quads, and needless to say that it fires pretty fast so there is a lot of particles in the scene.

Each bullet is a new "tBullet" type which has it's own entity and pivot. I use CopyMesh from a placeholder bullet mesh(blitz3d made quad).

There is no problem at creating the bullets and firing them. It doesn't cause any serious slowdown at all.

The problem is the getting rid of the bullets. I want to delete them based on their distance. Like if they are 250 units away from the player, they will get deleted. And for this purpose I free the entity and pivot then delete the individual type upon checking the EntityDistance. But strangely, while it doesn't cause any frame drop, it slows down the game while deleting/freeing stuff.

I tried not to delete them but hide them via HideEntity, but as the bullets pile up in the scene (which are hidden) it still cause an unacceptable amount of frame drop. Like 1000 fps to 30-40 in 2 minutes of shooting.

So is there a logical solution to this issue? If so, I will really appreciate it, if you guys tell me.


Warner(Posted 2009) [#2]
No logical solution here, but maybe you can recylcle unused bullets instead of freeing and recreating them?
As I understood, a single mesh solution is faster, so if you can attach each sprite to the same surface there might be a chance that it is faster.


Mortiis(Posted 2009) [#3]
I added a "maxBullets" variable and right now, I'm adding a delay between each bullet that is fired, if those doesn't fix the overloading issue, I'll try your suggestiongs Warner. Thanks.


Warner(Posted 2009) [#4]
Here, I wrote a single surface example:



Nate the Great(Posted 2009) [#5]
Recycling the bullets is the way to go because I have noticed small memory leaks when deleting many meshes and types that most shooting games cannot afford. Recycling always fixes that for me. So have an active variable for each type and when the bullet is too far away turn the active variable off. You can use a single surface system to help with orientation and rendering speed problems of bullets as well.


Zethrax(Posted 2009) [#6]
As stated above, try to cache and reuse the dead bullets, and try to minimize the number of surfaces displayed onscreen at once. Bear in mind, though, if you merge them into the one mesh you won't get the advantage of frustum culling with the offscreen bullets, so try to find a good balance.

Rather than deleting the bullets based on distance, you would probably be better off deleting them based on a timeout, as the math is less computationally expensive. If the bullets are moving at a constant speed, this will end up destroying them at a certain distance from the point they were fired at anyway.


Ross C(Posted 2009) [#7]
Another vote for recycling bullets. Simple create an "alive" field. When generating a new bullet, look through this list for bullets that are dead. Even quickier would be to have an array, with the type objects handles that are dead.