on Game Development
See other posts from Game Development
or by miguel.martin
Published on 2013-07-01T00:59:52Z Indexed on 2013/07/01 4:29 UTC
Read the original article Hit count: 159
I'm quite unsure how I should allocate/resemble my entities within my entity system. I have various options, but most of them seem to have cons associated with them. In all cases entities are resembled by an ID (integer), and possibly has a wrapper class associated with it. This wrapper class has methods to add/remove components to/from the entity.
Before I mention the options, here is the basic structure of my entity system:
- An object that describes an object within the game
- Used to store data for the entity
- Contains entities with specific components
- Used to update entities with specific components
- Contains entities and systems for the entity system
- Can create/destroy entites and have systems added/removed from/to it
Here are my options, that I have thought of:
Do not store the Entity wrapper classes, and just store the next ID/deleted IDs. In other words, entities will be returned by value, like so:
Entity entity = world.createEntity();
This is much like entityx, except I see some flaws in this design.
- There can be duplicate entity wrapper classes (as the copy-ctor has to be implemented, and systems need to contain entities)
- If an Entity is destroyed, the duplicate entity wrapper classes will not have an updated value
Store the entity wrapper classes within an object pool. i.e. Entities will be return by pointer/reference, like so:
Entity& e = world.createEntity();
- If there is duplicate entities, then when an entity is destroyed, the same entity object may be re-used to allocate another entity.
Use raw IDs, and forget about the wrapper entity classes. The downfall to this, I think, is the syntax that will be required for it. I'm thinking about doing thisas it seems the most simple & easy to implement it. I'm quite unsure about it, because of the syntax.
i.e. To add a component with this design, it would look like:
Entity e = world.createEntity(); world.addComponent<Position>(e, 0, 3);
As apposed to this:
Entity e = world.createEntity(); e.addComponent<Position>(0, 3);
- Duplicate IDs
© Game Development or respective owner