• Advertisement

Archived

This topic is now archived and is closed to further replies.

How to use std::list ... good for mass amounts of bullets ?

This topic is 5151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi , just wondering how to use the std::list command to help with handeling a dynamic number of bullets etc . Thanks

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You use push_back to put the bullets in the list and erase them as they hit enemies or walls. Really, what do you want to know? std::list is not a command, it''s a class.. You need to grasp that concept pretty well if you want to do anything.

Though using std::vector is probably a better choice. As long as you''ve used reserve() to allocate enough memory, push_back in vector is very fast, iterating it will also be probably be a bit faster and it''s more intact in memory (good for cache). Removing a bullet from vector can be done fast by swapping the eraseable bullet with the last bullet in the vector and then shrinking the vector''s size by 1. That won''t preserve the order of bullets in the list, but often that''s not useful.

Share this post


Link to post
Share on other sites

  • Advertisement