-fixed EntityTemplate.getComponent()

-fxied issue with components string in systems HashMap
This commit is contained in:
Mergul 2018-09-27 22:45:23 +02:00
parent c915b1a8c7
commit c0ac19b6f9
2 changed files with 22 additions and 5 deletions

View file

@ -44,9 +44,17 @@ export struct EntityTemplate
EntityManager.EntityInfo* info; EntityManager.EntityInfo* info;
T* getComponent(T)() T* getComponent(T)()
{
version(LinearLayout)
{ {
if(T.component_id >= info.tmpl_deltas.length)return null; if(T.component_id >= info.tmpl_deltas.length)return null;
version(LinearLayout)return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]); return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]);
else return cast(T*)(entity_data.ptr + info.deltas[T.component_id]); }
else
{
if(T.component_id >= info.deltas.length)return null;
return cast(T*)(entity_data.ptr + info.deltas[T.component_id]);
}
} }
} }

View file

@ -329,12 +329,19 @@ class EntityManager
if (sys_id < systems.length) if (sys_id < systems.length)
{ {
system.enable(); system.enable();
/*if (systems[sys_id].m_destroy)
systems[sys_id].m_destroy(systems[sys_id].m_system_pointer);*/
if (system.m_create)
system.m_create(system.m_system_pointer);
systems[sys_id] = system; systems[sys_id] = system;
Sys.system_id = sys_id; Sys.system_id = sys_id;
} }
else else
{ {
systems_map.add(Sys.stringof, cast(ushort) systems.length); string name = Mallocator.instance.makeArray(Sys.stringof);
systems_map.add(name, cast(ushort) systems.length);
systems.add(system); systems.add(system);
@ -394,12 +401,14 @@ class EntityManager
if (comp_id < components.length) if (comp_id < components.length)
{ {
Comp.component_id = comp_id; Comp.component_id = comp_id;
components[comp_id] = info;
} }
else else
{ {
components.add(info); components.add(info);
Comp.component_id = cast(ushort)(components.length - 1); Comp.component_id = cast(ushort)(components.length - 1);
components_map.add(Comp.stringof, cast(ushort)(components.length - 1)); string name = Mallocator.instance.makeArray(Comp.stringof);
components_map.add(name, cast(ushort)(components.length - 1));
} }
} }