-add ecsID template function (get Component/System/Event ID, passes tests)

-removed some ECS mixins code
This commit is contained in:
Mergul 2020-09-29 18:41:31 +02:00
parent 13c82acad4
commit a926b79223
9 changed files with 138 additions and 123 deletions

View file

@ -8,6 +8,7 @@ module bubel.ecs.entity;
import bubel.ecs.system;
import bubel.ecs.manager;
import bubel.ecs.traits : ecsID;
/************************************************************************************************************************
Entity ID structure. Used as reference to Entity. Pointer to entity should be ever used to store entity reference!
@ -40,7 +41,7 @@ struct Entity
return null;
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + block.entityIndex(&this) * T.sizeof);*/
return cast(T*)getComponent(T.component_id);
return cast(T*)getComponent(ecsID!T);
}
void* getComponent(ushort component_id) const
@ -81,7 +82,7 @@ struct EntityMeta
if (T.component_id >= info.deltas.length || info.deltas[T.component_id] == 0)
return null;
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + index * T.sizeof);*/
return cast(T*)getComponent(T.component_id);
return cast(T*)getComponent(ecsID!T);
}
void* getComponent(ushort component_id) const
@ -125,8 +126,8 @@ export struct EntityTemplate
*/
T* getComponent(T)() nothrow @nogc
{
if(T.component_id >= info.tmpl_deltas.length || info.tmpl_deltas[T.component_id] == ushort.max)return null;
return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]);
if(ecsID!T >= info.tmpl_deltas.length || info.tmpl_deltas[ecsID!T] == ushort.max)return null;
return cast(T*)(entity_data.ptr + info.tmpl_deltas[ecsID!T]);
}
}