-error information about adding system with non existing component (prints name of system and component) -fill components in template with default values
37 lines
653 B
D
37 lines
653 B
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)()
|
|
{
|
|
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
|
EntityManager.EntityInfo* info = block.type_data;
|
|
return cast(T*)(cast(void*)&this + info.deltas[T.component_id]);
|
|
}
|
|
}
|
|
|
|
struct EntityTemplate
|
|
{
|
|
ubyte[] entity_data;
|
|
EntityManager.EntityInfo* info;
|
|
|
|
T* getComponent(T)()
|
|
{
|
|
return cast(T*)(entity_data.ptr + info.deltas[T.component_id]);
|
|
}
|
|
}
|