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_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]); } }