• Advertisement
Sign in to follow this  

How to store the objects in my world

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

Right now in my game engine I store my objects in an array whose size is defined at load time. This is all well and good but what do I do when an object is added during runtime like using some kind of spawner, the array would have to expand and this is slow. Ideally I would have something similar to Bullet Physics where I can do:

[CODE]
dynamicsWorld->addRigidBody(body);
[/CODE]

How would something like that work? I never defined a specific size. Does it use a container class from STL?

Share this post


Link to post
Share on other sites
Advertisement
Most likely it just uses a std::vector, or maybe its own custom version of a vector.

Share this post


Link to post
Share on other sites
If you're using C++, and [i]not[/i] using the STL, you're doing something wrong. Yes yes, there are exceptions to this rule, but if you're in a position to ask a question like this, you are not the
exception.


Anyway, as zacaj said, use an std::vector. Or, perhaps an std::map if you want more convenient and [i]potentially[/i] faster lookup.

Share this post


Link to post
Share on other sites
Why do you think that resizing array is slow?
Use std::vector and forget the resizing. I cannot imagine a scenario where this could become bottleneck unless you are doing something very weird. And in the latter case you should fix that weirdness, not worry about vector resizing speed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement