-fixed critical bug with adding components
-some fixes -minor optimization -added debug assert test
This commit is contained in:
parent
913cf1aef8
commit
19687b9f88
2 changed files with 29 additions and 19 deletions
|
|
@ -45,7 +45,7 @@ static struct ECS
|
|||
*/
|
||||
mixin template System(uint jobs_count = 32)
|
||||
{
|
||||
__gshared ushort system_id;
|
||||
__gshared ushort system_id = ushort.max;
|
||||
uint __ecs_jobs_count = jobs_count;
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ static struct ECS
|
|||
*/
|
||||
mixin template Component()
|
||||
{
|
||||
__gshared ushort component_id;
|
||||
__gshared ushort component_id = ushort.max;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
|
|
@ -62,7 +62,7 @@ static struct ECS
|
|||
*/
|
||||
mixin template Event()
|
||||
{
|
||||
__gshared ushort event_id;
|
||||
__gshared ushort event_id = ushort.max;
|
||||
EntityID entity_id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -770,13 +770,15 @@ export struct EntityManager
|
|||
else
|
||||
enum OnUpdateOverloadNum = -1;
|
||||
//enum HasOnUpdate = (hasMember!(Sys, "onUpdate") && checkOnUpdateParams());
|
||||
enum IsEmpty = components_info.req.length == 0 && components_info.optional.length == 0
|
||||
&& components_info.excluded.length == 0 && components_info.entites_array.length == 0;
|
||||
|
||||
static if (components_info.req.length == 0 && components_info.optional.length == 0)
|
||||
static if (IsEmpty)
|
||||
system.m_empty = true;
|
||||
|
||||
static if (OnUpdateOverloadNum != -1)
|
||||
{
|
||||
static if (components_info.req.length != 0 || components_info.optional.length != 0)
|
||||
static if (!IsEmpty)
|
||||
{
|
||||
static void callUpdate(ref CallData data)
|
||||
{
|
||||
|
|
@ -972,6 +974,8 @@ export struct EntityManager
|
|||
*/
|
||||
export System* getSystem(ushort id) nothrow @nogc
|
||||
{
|
||||
if (id >= systems.length)
|
||||
return null;
|
||||
return &systems[id];
|
||||
}
|
||||
|
||||
|
|
@ -980,6 +984,8 @@ export struct EntityManager
|
|||
*/
|
||||
Sys* getSystem(Sys)() nothrow @nogc
|
||||
{
|
||||
if (Sys.system_id >= systems.length)
|
||||
return null;
|
||||
return cast(Sys*) systems[Sys.system_id].m_system_pointer;
|
||||
}
|
||||
|
||||
|
|
@ -1404,6 +1410,7 @@ export struct EntityManager
|
|||
uint j = 1;
|
||||
foreach (i; 1 .. ids.length)
|
||||
{
|
||||
assert(ids[i] != ushort.max);
|
||||
if (ids[i] != ids[j - 1])
|
||||
{
|
||||
ids[j] = ids[i];
|
||||
|
|
@ -1500,9 +1507,10 @@ export struct EntityManager
|
|||
}
|
||||
|
||||
info.comp_add_info = Mallocator.makeArray!(EntityInfo*)(instance.components.length);
|
||||
info.comp_rem_info = Mallocator.makeArray!(EntityInfo*)(instance.components.length, info);
|
||||
info.comp_rem_info = Mallocator.makeArray!(EntityInfo*)(instance.components.length,
|
||||
info);
|
||||
|
||||
foreach(comp; info.components)
|
||||
foreach (comp; info.components)
|
||||
{
|
||||
info.comp_add_info[comp] = info;
|
||||
info.comp_rem_info[comp] = null;
|
||||
|
|
@ -1772,17 +1780,18 @@ export struct EntityManager
|
|||
EntityInfo* info = block.type_info;
|
||||
|
||||
//remove non-existing components
|
||||
uint num = cast(uint)del_ids.length;
|
||||
foreach_reverse(i; 0 .. num)
|
||||
uint num = cast(uint) del_ids.length;
|
||||
foreach_reverse (i; 0 .. num)
|
||||
{
|
||||
if(info.deltas.length <= del_ids[i] || info.deltas[del_ids[i]] == 0)
|
||||
if (info.deltas.length <= del_ids[i] || info.deltas[del_ids[i]] == 0)
|
||||
{
|
||||
num--;
|
||||
del_ids[i] = del_ids[num];
|
||||
}
|
||||
}
|
||||
|
||||
if(num == 0)return;
|
||||
if (num == 0)
|
||||
return;
|
||||
del_ids = del_ids[0 .. num];
|
||||
|
||||
//sort components
|
||||
|
|
@ -1883,16 +1892,17 @@ export struct EntityManager
|
|||
EntitiesBlock* block = getMetaData(entity);
|
||||
EntityInfo* info = block.type_info;
|
||||
|
||||
foreach_reverse(i; 0 .. num)
|
||||
foreach_reverse (i; 0 .. num)
|
||||
{
|
||||
if(info.deltas.length > new_ids[i] && info.deltas[new_ids[i]] != 0)
|
||||
if (info.deltas.length > new_ids[i] && info.deltas[new_ids[i]] != 0)
|
||||
{
|
||||
num--;
|
||||
new_ids[i] = new_ids[num];
|
||||
}
|
||||
}
|
||||
|
||||
if(num == 0)return;
|
||||
if (num == 0)
|
||||
return;
|
||||
new_ids = new_ids[0 .. num];
|
||||
|
||||
foreach (int i; 0 .. num)
|
||||
|
|
@ -2834,7 +2844,7 @@ export struct EntityManager
|
|||
|
||||
assert(len == components.length + 1);
|
||||
|
||||
EntityInfo* new_info = instance.getEntityInfo(ids);//[0 .. len]);
|
||||
EntityInfo* new_info = instance.getEntityInfo(ids);
|
||||
|
||||
comp_add_info[id] = new_info;
|
||||
return new_info;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue