Bullet management

I’m trying to figure out the best way to manage many simple moving objects (bulltes, lasers, etc). There are several ways I can think of doing this and each way is inefficient in some major way. I’m hoping someone could give me some advice:

  1. Store each bullet in its own node in a linked list, complete with its own geometry and transformation matrix.

Good: fast adding/removing and translating/rotating of bullets

Bad: slow to traverse the large linked list for rendering, and to push, multiply, and pop the transformation matrix for each bullet


  1. Use a large pre-allocated memory block as an interleaved vertex array

Good: Fast rendering

Bad: slow to translate each bullet in its own direction (i’d have to loop through each vertex and add the bullet’s velocity).
Limited number of bullets.
Slow to remove a bullet from the middle of the array (would require copying all subsequent data into the memory location)


  1. Linked list, but without matrix push/pops

Good: fast adding/removing bullets. Less speed hit than #1 when rendering

Bad: Slow to translate/rotate bullets (would require looping through each vertex and adding velocity as in #2)

I’m really at a loss here, since none of these seems like a very good solution. Maybe someone has a different way or maybe I’m overestimating the speed costs here?

Hi !

If you have lot’s of objects and they are all very simple, then I guess it would be good to try to live without a transformation for each object, instead keeping the object transformed (if it’s just a few vertices), but if we are talking about “bullets” in a game for example I guess there would never be that many objects active at one time ?, unless we are talking Gatling minguns with 7000 rounds per minute or so ;o)

Mikael

Well its a space arcade game, so if there’s a big battle with 20 or so ships and each one is shooting then there could be 100 or more shots on screen at a time.

I think the third one is the most promising so I’m gonna try that.

Currently Im working on a first person 3D shooter and for my ‘bullets’ (actually more like plasma balls or something) i use an array of around 40 elements for the bullets, each array member is a structure for the bullet holding position, velocity, damage, stuff like that. An array of 40 elements shouldnt take up alot of memory and you dont need larger because im never going to have more than 40 active bullets, and it is alot faster than traversing a list.
I then build a display list for the bullet and traslate the matrix for each bullet…

I use bullets like normal objects in node, so theoreticaly there is no upper limit of their number (except RAM . The framerate of course goes down, but it is because they act as dynamic lights. But having around 50 bullets is still playable. And I dont store their rotation matrices, because I dont need them (I draw them with a kind of billboarding technique).