Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to store the objects in my world


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 ic0de   Members   -  Reputation: 909

Like
1Likes
Like

Posted 02 November 2012 - 01:25 PM

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?

you know you program too much when you start ending sentences with semicolons;


Sponsor:

#2 zacaj   Members   -  Reputation: 643

Like
0Likes
Like

Posted 02 November 2012 - 01:43 PM

Most likely it just uses a std::vector, or maybe its own custom version of a vector.

#3 nox_pp   Members   -  Reputation: 490

Like
1Likes
Like

Posted 02 November 2012 - 02:24 PM

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


#4 zacaj   Members   -  Reputation: 643

Like
0Likes
Like

Posted 02 November 2012 - 02:25 PM

Using a map seems like a bad idea (assuming string key?)

#5 Lauris Kaplinski   Members   -  Reputation: 841

Like
1Likes
Like

Posted 02 November 2012 - 02:27 PM

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/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS