Jump to content

  • Log In with Google      Sign In   
  • Create Account

how to keep track of game entities


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
6 replies to this topic

#1 lride   Members   -  Reputation: 633

Like
0Likes
Like

Posted 30 September 2012 - 08:04 PM

Let's say I'm making a rpg.
In a rpg game, there are many monsters randomly spawning.
How am I supposed to keep track of these monsters?
Should I store these in an array and iterate through the entire array to update each monster and render them?-This way seems very inefficient.
An invisible text.

Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7500

Like
0Likes
Like

Posted 30 September 2012 - 11:08 PM

This way seems very inefficient

Yes it is for larger amounts of mobs. A very good and easy data structure for holding moving entities is sweep'n'prune.

#3 rdragon1   Crossbones+   -  Reputation: 1200

Like
0Likes
Like

Posted 30 September 2012 - 11:13 PM

Should I store these in an array and iterate through the entire array to update each monster and render them?-This way seems very inefficient.


Do you want to update and render every monster, every frame? If so, an array sounds like a pretty efficient way to be able to iterate over them all. If your 'this seems inefficient' comment isn't based on actually measuring performance, you're just guessing, and that's not science.

A better, more efficient way of transforming a large amount of heterogeneous data is to group the data into homogeneous chunks and update those chunks together.

But I would really hope a discussion about performance contains real data that can be analyzed and commented on precisely.

#4 Krohm   Crossbones+   -  Reputation: 3119

Like
0Likes
Like

Posted 01 October 2012 - 01:01 AM

Should I store these in an array and iterate through the entire array to update each monster and render them?-This way seems very inefficient.

For what purpose?
If your goal is to run physics on them, you have no choice but delegating a physics API (albeit those objects are likely kinematic).
If all the monsters are to be updated each tick, it's possible an array will actually be the faster option. You need to elaborate on your needs.

To give you an answer: I don't keep track of my "monsters". I actually don't keep track of anything in my game(s). I only keep track of a WorldLogic object. This object has responsibility to propagate ticks to all the entities it wants. On top of that, certain entities are live, for example rigid bodies will evolve by themselves and receive asynchronous events every once in a while. Those objects effectively have two ways of ticking.
I have certain entities called ValueGenerators. They are non-positioned entities. I store them in an std::vector, and I'm fine with it, I stop looking at profiler results after hitting 1% of CPU time, they're likely down there.

#5 AticAtac   Members   -  Reputation: 328

Like
0Likes
Like

Posted 01 October 2012 - 06:16 AM

Which of these functions do you need:
- random access monster
- inserting and deleting monsters a lot
- searching monster in the "list" a lot

As you see, depending on what you will do many different types of containers could help:
- vectors/array (good for random access, bad for inserting deleting
- lists (bad for random access, good for inserting, deleting)
- maps (good for searchin)
- ...

Edited by AticAtac, 01 October 2012 - 06:17 AM.


#6 lride   Members   -  Reputation: 633

Like
0Likes
Like

Posted 01 October 2012 - 01:44 PM

I just need to do some AI and rendering on the monsters
So an array seems to be the best option...

Edited by lride, 01 October 2012 - 01:44 PM.

An invisible text.

#7 shadowomf   Members   -  Reputation: 315

Like
0Likes
Like

Posted 05 October 2012 - 12:49 AM

Problaby yes. You might also be interested in data oriented design.

Sometimes it's faster to store your entities in a simple table or array and updating them all. Instead of traversing a scene graph or sorting them and only updating specific items.




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