Projectile system

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SanderVocke
Posts: 40
Joined: Mon Oct 31, 2005 1:19 pm
Location: Netherlands

Projectile system

Post by SanderVocke »

Almost every game has some kind of projectile(s) that can be shot from a player-represented model. Mine(a space game) has laser beams that can be shot from the guns of every ship in play. What is the best method to keep track of all the projectiles that are in play? My method is very unefficient. I have an array of 40 "beam" instances for every ship. this sucks up a lot of memory, and now that I also have to check for every single one of them (that is 40 beams x 8 ships = 320 beams) in a while loop whether they exist and do collision detection on them, my framerate drops from 100 to 10. Could someone give me an example of how it should be done?
"The shortest distance between two points is always under construction."
- Noelie Alite
Cancel
Posts: 4
Joined: Fri Nov 11, 2005 1:03 pm

Post by Cancel »

I don't know exactly HOW you game works but I guess that you could simply hold ALL beams in one dynamic list. Since it maybe important to know which beam belongs to which ship, simply add a int (or even char) to the beam object that keeps the number of the "owning" ship. For the list I'd use good 'ol vector class since it always worked fine for me.

http://www.msoe.edu/eecs/ce/courseinfo/stl/vector.htm
SanderVocke
Posts: 40
Joined: Mon Oct 31, 2005 1:19 pm
Location: Netherlands

Post by SanderVocke »

Is there any difference between the vector list and Irrlicht's array<> method? I'm using regular c++ [] arrays now, which are of course inefficient in that the number of items is constant. I didn't even think about using different kinds of arrays.
"The shortest distance between two points is always under construction."
- Noelie Alite
Cancel
Posts: 4
Joined: Fri Nov 11, 2005 1:03 pm

Post by Cancel »

Actually, I didn't even know about Irrlicht's own array^^(pretty new to irrlicht). But since the Irrlicht documentation explicitly says

"rr::core::array< T > Class Template Reference
Self reallocating template array (like stl vector) with additional features"

it seems as it would be wise to use the Irrlicht array :D
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

possibly the best way to do it would be to look at the particle system scene node and use something that draws all the lasers as a single mesh.
To be honest though, I'm being lazy and use a bullet scene node class. When the player or an enemy creates a bullet, it checks for ground collision, sets the bullet's deletion time and sets a flag that decides if, where and when to create a decal. In the bullet's OnPostRender, I check for collision with moving objects that are not the owner of the bullet, and delete it if the current time is more than the deletion time, creating a decal if it collided with the ground, and then add a deletion animator on to the decal.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply