In an Entity/Component system, can component data be implemented as a simple array of key-value pairs? [on hold]
- by 010110110101
I'm trying to wrap my head around how to organize components in an Entity Component Systems once everything in the current scene/level is loaded in memory. (I'm a hobbyist BTW)
Some people seem to implement the Entity as an object that contains a list of of "Component" objects. Components contain data organized as an array of key-value pairs. Where the value is serialized "somehow".
(pseudocode is loosely in C# for brevity)
class Entity {
Guid _id;
List<Component> _components;
}
class Component {
List<ComponentAttributeValue> _attributes;
}
class ComponentAttributeValue {
string AttributeName;
object AttributeValue;
}
Others describe Components as an in-memory "table". An entity acquires the component by having its key placed in a table. The attributes of the component-entity instance are like the columns in a table
class Renderable_Component {
List<RenderableComponentAttributeValue> _entities;
}
class RenderableComponentAttributeValue {
Guid entityId;
matrix4 transformation;
// other stuff for rendering
// everything is strongly typed
}
Others describe this actually as a table. (and such tables sound like an EAV database schema BTW) (and the value is serialized "somehow")
Render_Component_Table
----------------
Entity Id
Attribute Name
Attribute Value
and when brought into running code:
class Entity {
Guid _id;
Dictionary<string, object> _attributes;
}
My specific question is: Given various components, (Renderable, Positionable, Explodeable, Hideable, etc) and given that each component has an attribute with a particular name, (TRANSLATION_MATRIX, PARTICLE_EMISSION_VELOCITY, CAN_HIDE, FAVORITE_COLOR, etc) should:
an entity contain a list of components where each component, in turn, has their own array of named attributes with values serialized somehow
or
should components exist as in-memory tables of entity references and associated with each "row" there are "columns" representing the attribute with values that are specific to each entity instance and are strongly typed
or
all attributes be stored in an entity as a singular array of named attributes with values serialized somehow (could have name collisions)
or
something else???