3 Replies - 180 Views - Last Post: 18 April 2014 - 02:48 PM Rate Topic: -----

#1 Mr_Fraggs  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 85
  • Joined: 17-June 12

Storing Dynamic Objects

Posted 16 April 2014 - 08:48 PM

Hey everyone, long time no see! Been crazy busy lately, with trying to get back into school, work, and making games!

I come to you not really for help, but more for opinions / advice. It's not a code problem, just an organization thing I can't get out of my head!

So, for my project, i'm using a Component / Entity system, with messaging and listeners in each system. I've been doing my best to get all logic in systems aside from stuff like raw rendering code and all that fun stuff. Components only hold data, and events handle triggering interactions in each system for handling those events.

Now, for my objects ( entities ) in my game world, I'll create a class called GameWorld or Item, and all it does is hold it's entity ID, and some basic logic specific for that entity. ( For example, Items and it's base class have their own Use() function, since each item might be crazy specific in how it's used. )

Now, when storing these game objects, which is basically just the entity GUID wrapped in a class, possibly with minimal outside ( non-system ) functions for logic, would it make more sense to store them all in one big list, say, all Items in a vector of items in ItemSystem, or would I give the item class object to it's appropriate owner? ( By owner, I mean GameWorld or Inventory ).And, it doesn't always have to be one big list. Maybe, CharacterSystem might hold three lists, one list for FriendlyNPCs, one list for EnemyNPCs, and one more for NeutralNPCs.

Currently, i'm trying to keep them all in the one big list in each system, so I can keep as much data/logic related to that area ( Item logic in ItemSystem ) so that I can keep it as modulated as possible. Is this the wrong way to go about it? Is it more common to see objects held by their owners, instead of one long list?

Thanks for any advice ahead of time, as I tend to read forum replys on my phone on the go, and I NEVER type forum posts on a touch screen xD

This post has been edited by Mr_Fraggs: 16 April 2014 - 08:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Storing Dynamic Objects

#2 yothsoggoth  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 47
  • Joined: 19-June 12

Re: Storing Dynamic Objects

Posted 18 April 2014 - 05:09 AM

This is really something quite dependant on the rest of your architecture and usage.

For example, if you never need to access only friendly NPCs, why would you bother to store them separately?

There's no one best way to do this.

One approach would be to store all entities in one container of entities, which makes entity messaging simpler as you don't have to find which container the entity belongs in every time you need to find it.
Then, if you need to store a certain type of entity separately, store a list of UIDs that can be used to access those entities from the global list. The reason to store UIDs rather than pointers is so you're safe if the entity gets removed.

Also, you didn't mention hash maps at all, so I thought I would add that you almost definitely want to be using a hash map to store your entities, mapped by their UIDs.
Was This Post Helpful? 0
  • +
  • -

#3 Mr_Fraggs  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 85
  • Joined: 17-June 12

Re: Storing Dynamic Objects

Posted 18 April 2014 - 01:54 PM

I think I might have worded that poorly. I do have one big map that holds each entities' GUID, and the components tied to it. What i'm looking for, is more of the objects that hold the entity ID.

For example, my Item class might just only have an int entityID, along with a few helper functions and whatnot. I'm more looking for what makes sense the most when it comes to holding the object that holds the entity basically. So, I would have a list of 10 Item Class Objects, that each have their own entity ID. Now, the entity for the Item is held in a Map in my EntityManager class. So that's all set.

But, then i'll have an ItemSystem to handle all of the item logic in the game. ( Picking up, putting down, using, etc ). So, if it wasn't clear, ( which is always possible with the way stuff pours out of my mind! ), i'm looking for advice for storing the class objects that HOLD the entity ID. Basically the object the entity represents. So, would it be more common to see that list of ten items held in one single list in Item System, or would it be more common to see those items held by their actual owners, like the Player's Inventory, Game World, etc.

Sorry if I misunderstood your answer, and i'm correcting something that isn't wrong. I hope this hammers my point across! :P Thanks for the help though!
Was This Post Helpful? 0
  • +
  • -

#4 yothsoggoth  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 47
  • Joined: 19-June 12

Re: Storing Dynamic Objects

Posted 18 April 2014 - 02:48 PM

View PostMr_Fraggs, on 18 April 2014 - 01:54 PM, said:

But, then i'll have an ItemSystem to handle all of the item logic in the game. ( Picking up, putting down, using, etc ). So, if it wasn't clear, ( which is always possible with the way stuff pours out of my mind! ), i'm looking for advice for storing the class objects that HOLD the entity ID. Basically the object the entity represents. So, would it be more common to see that list of ten items held in one single list in Item System, or would it be more common to see those items held by their actual owners, like the Player's Inventory, Game World, etc.


I see, in that case I misunderstood your question a little. I think I understand a little better now...

I would say that it depends purely on the usage that you need from the "items". For example, if the ItemSystem needs to do something for which it needs every single item (e.g. loop through and update them or something) then the ItemSystem would need to store the list. If not, and the only thing that ever uses the items is their actual owners (e.g. Inventory, GameWorld, based on your examples) then only the actual owners need to store them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1