From dd491302afa388e86e7ad5b2a4a5af502a28431b Mon Sep 17 00:00:00 2001 From: Mergul Date: Wed, 13 May 2020 15:31:26 +0200 Subject: [PATCH] Fixed system reregistration issue and added funtion to allocate EntityTEmplate as copy of different teamplte --- source/bubel/ecs/manager.d | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/source/bubel/ecs/manager.d b/source/bubel/ecs/manager.d index 15d1f6e..c6b02a1 100644 --- a/source/bubel/ecs/manager.d +++ b/source/bubel/ecs/manager.d @@ -1150,17 +1150,22 @@ export struct EntityManager ushort sys_id = systems_map.get(cast(char[]) Sys.stringof, ushort.max); if (sys_id < systems.length) { - system.enable(); + systems[sys_id].disable(); + if(systems[sys_id].m_destroy)(cast(void function(void*)) systems[sys_id].m_destroy)(systems[sys_id].m_system_pointer); if (system.m_create) (cast(void function(void*)) system.m_create)(system.m_system_pointer); + system.enable(); + system.m_id = sys_id; + system.m_name = systems[sys_id].m_name; systems[sys_id] = system; } else { system.m_name = Mallocator.makeArray(cast(char[]) Sys.stringof); + systems_map.add(system.m_name, cast(ushort) systems.length); system.m_id = cast(ushort)(systems.length); @@ -1723,6 +1728,20 @@ export struct EntityManager return temp; } + /************************************************************************************************************************ + Allocate EntityTemplate copy. + + Params: + copy_tmpl = template which should be copied + */ + export EntityTemplate* allocateTemplate(EntityTemplate* copy_tmpl) + { + EntityTemplate* tmpl = Mallocator.make!EntityTemplate; + tmpl.info = copy_tmpl.info; + tmpl.entity_data = Mallocator.makeArray(copy_tmpl.entity_data); + return tmpl; + } + /************************************************************************************************************************ Returns entity type info. @@ -2344,7 +2363,7 @@ export struct EntityManager Params: template_ = pointer entity template allocated by EntityManager. */ - export void freeTemplate(EntityTemplate* template_) + export void freeTemplate(EntityTemplate* template_) @nogc nothrow { Mallocator.dispose(template_.entity_data); Mallocator.dispose(template_);