Fixed system reregistration issue and added funtion to allocate EntityTEmplate as copy of different teamplte

This commit is contained in:
Mergul 2020-05-13 15:31:26 +02:00
parent 9580ee9af9
commit dd491302af

View file

@ -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_);