How to store the objects in my world

Started by
3 comments, last by lauris71 11 years, 5 months ago
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:


dynamicsWorld->addRigidBody(body);


How would something like that work? I never defined a specific size. Does it use a container class from STL?
Advertisement
Most likely it just uses a std::vector, or maybe its own custom version of a vector.
If you're using C++, and not 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 potentially faster lookup.

Between Scylla and Charybdis: First Look <-- The game I'm working on

Object-Oriented Programming Sucks <-- The kind of thing I say

Using a map seems like a bad idea (assuming string key?)
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.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

This topic is closed to new replies.

Advertisement