From c0ac19b6f9ad6da61a8e8cf8bffde69f2d932799 Mon Sep 17 00:00:00 2001 From: Mergul Date: Thu, 27 Sep 2018 22:45:23 +0200 Subject: [PATCH] -fixed EntityTemplate.getComponent() -fxied issue with components string in systems HashMap --- source/ecs/entity.d | 14 +++++++++++--- source/ecs/manager.d | 13 +++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/source/ecs/entity.d b/source/ecs/entity.d index e880a64..6a34e51 100644 --- a/source/ecs/entity.d +++ b/source/ecs/entity.d @@ -45,8 +45,16 @@ export struct EntityTemplate T* getComponent(T)() { - if(T.component_id >= info.tmpl_deltas.length)return null; - version(LinearLayout)return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]); - else return cast(T*)(entity_data.ptr + info.deltas[T.component_id]); + + version(LinearLayout) + { + if(T.component_id >= info.tmpl_deltas.length)return null; + return cast(T*)(entity_data.ptr + info.tmpl_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]); + } } } diff --git a/source/ecs/manager.d b/source/ecs/manager.d index 41776e3..31334b3 100644 --- a/source/ecs/manager.d +++ b/source/ecs/manager.d @@ -329,12 +329,19 @@ class EntityManager if (sys_id < systems.length) { 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; Sys.system_id = sys_id; } 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); @@ -394,12 +401,14 @@ class EntityManager if (comp_id < components.length) { Comp.component_id = comp_id; + components[comp_id] = info; } else { components.add(info); 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)); } }