Advertisement

bullet object storage advice needed

Started by April 16, 2001 09:32 PM
0 comments, last by wooord 23 years, 9 months ago
I have a c++ class that represents a bullet. Each newly fired bullet is a separate instantiation. What is the best way to store the active bullets? array, linked list, vector, etc??
i use linked lists arranged so that new bullets are pushed on the head of the list. why? it is more than likely the first fired bullet will hit something (and thus need to be removed from the list) before the latest fired, and every bullet in between. since this is the case i find it easier this way so the second to last bullet can just be made to point ant NULL and the last one deleted. this is a bit nicer, less pointers to work with. it is possible that the third bullet (for example) will hit before the first bullet, so you''ll need to handle this too.

another alternative would be a circular doubly linked list. this way it doesn''t matter where the new bullet is created (either the start or end), and this also (somewhat) simplifies the removal of any arbitrary bullet. if you''ve paid attention in class too it shouldn''t be tough to implement.

any way you do it i believe it should be based upon a linked list structure. they are very handy in most situations and i think something like this just screams for them.

hope that helps


<(o)>
<(o)>

This topic is closed to new replies.

Advertisement