Jump to content
  • Advertisement

Archived

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

dacredens

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

This topic is 5416 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

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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!