bubel-ecs/source/ecs/entity.d
Mergul d5780a6252 -working update() with EntitiesData structure input
-added support for 'const' components input (read only, future usage)
2018-09-30 23:12:20 +02:00

45 lines
1.1 KiB
D

module ecs.entity;
import ecs.manager;
struct EntityID
{
uint id;
uint counter;
}
struct Entity
{
EntityID id;
void updateID()
{
EntityManager.instance.id_manager.update(this);
}
T* getComponent(T)() const
{
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
EntityManager.EntityInfo* info = block.type_info;
if (T.component_id >= info.deltas.length || info.deltas[T.component_id] == 0)
return null;
static if (EntityID.sizeof == 8)
uint ind = cast(uint)((cast(void*)&this - block.dataBegin()) >> 3);
else
uint ind = cast(uint)((cast(void*)&this - block.dataBegin()) / EntityID.sizeof());
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + ind * T.sizeof);
}
}
export struct EntityTemplate
{
ubyte[] entity_data;
EntityManager.EntityInfo* info;
T* getComponent(T)()
{
if(T.component_id >= info.tmpl_deltas.length)return null;
return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]);
}
}