-fixed issue with optional components in systems

This commit is contained in:
Mergul 2018-09-21 16:44:40 +02:00
parent 8cb5d6ce62
commit 9511e1936e

View file

@ -457,8 +457,7 @@ class EntityManager
ushort[] deltas = (cast(ushort*) alloca(num * ushort.sizeof))[0 .. num]; ushort[] deltas = (cast(ushort*) alloca(num * ushort.sizeof))[0 .. num];
uint delta_id = 0; uint delta_id = 0;
ushort[] cmp_array = system.m_components; foreach (id; system.m_components)
add_deltas: foreach (id; cmp_array)
{ {
deltas[delta_id] = ushort.max; deltas[delta_id] = ushort.max;
foreach (i2, id2; entity.components) foreach (i2, id2; entity.components)
@ -478,11 +477,26 @@ class EntityManager
} }
if (deltas is null) if (deltas is null)
return; return;
if (cmp_array.ptr == system.m_components.ptr)
foreach (id; system.m_optional_components)
{ {
cmp_array = system.m_optional_components; deltas[delta_id] = ushort.max;
goto add_deltas; foreach (i2, id2; entity.components)
{
if (id2 == id)
{
deltas[delta_id] = entity.deltas[id2];
break;
} }
}
/*if (deltas[delta_id] == ushort.max)
{
deltas = null;
break;
}*/
delta_id++;
}
call_data.deltas = Mallocator.instance.makeArray(deltas); //Mallocator.instance.makeArray!ushort(system.m_components.length); call_data.deltas = Mallocator.instance.makeArray(deltas); //Mallocator.instance.makeArray!ushort(system.m_components.length);