Entity¶
Entity Format¶
Each entity consists of several components.
Each component can communicate with adjacent component through entity. Each component belongs to one system and stores state of the entity for that system.
For example, for render system:
"render": {
"root": {
"position": "0,0,0",
"rotation": "1,0,-1,0",
"scale": "1,1,1",
"children": [{
"type": "model",
"mesh": "castle.mesh",
"name": "castle",
"castShadows": true
}]
}
}
The component stores information about nodes: "root"
is always root node of the component.
It has "position"
, "rotation"
and other props, typical for render system.
"children"
here can store the list of various visual children:
models.
billboards.
particle systems.
and others.
There are different kinds of systems. Script component data can look like this:
"script":
{
"setupScript": "@File:characters/scripts/ninja.lua",
"behavior": "dumbMonster"
}
The engine is highly extensible, so it’s easy to add any new kind of system. Each system is installed in the engine with the unique string id. The same id is used to match the system where the entity should be created.
That way, engine will find system by the name "script"
and will create new component there using
parameters, which are defined for it in the entity description.
For example for the script component type it will call
Gsage::Engine::createComponent()
with type = "script"
and dict:
{
"setupScript": "@File:characters/scripts/ninja.lua",
"behavior": "dumbMonster"
}
Then it will add the pointer to the created component to the entity object.
Lifecycle¶
On each update, each component state can be updated. Engine iterates and updates all the systems and each system iterates and updates each component it owns.
Each component can be altered during engine operation. For example, render component can update it’s position or change model. Movement can change speed.
Entity Add Flow¶
Gsage::Engine
createsGsage::Entity
in the pool of entities. All entities are stored in theGsage::Engine
.Engine iterates through the list of keys of
Gsage::Entity
, finds appropriate system by stringid
and allocates a component there.Each system allocates the component in the pool and configures created component with
Gsage::DataProxy
that came fromGsage::Engine
.
Entity Remove Flow¶
Gsage::Engine
findsGsage::Entity
by id and iterates through all it’s components.Gsage::Engine
removes each component by pointer it got fromGsage::Entity
.Gsage::ComponentStorage
deallocates component.Gsage::Engine
removes entity from pool when all components are deleted.