From 1aa1fbf36bc17c3f8cf72de377e4c057ca6cf7da Mon Sep 17 00:00:00 2001 From: Mergul Date: Thu, 13 Sep 2018 22:04:43 +0200 Subject: [PATCH] -support for system priority -fixed callers system pointer update -fixed HashMap issue --- source/ecs/manager.d | 11 +++++++++-- source/ecs/vector.d | 3 ++- tests/tests.d | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/source/ecs/manager.d b/source/ecs/manager.d index d75b0f3..d4bf7b3 100644 --- a/source/ecs/manager.d +++ b/source/ecs/manager.d @@ -115,6 +115,7 @@ class EntityManager } system.m_system_pointer = cast(void*) Mallocator.instance.make!Sys; + system.m_priority = priority; system.m_components = Mallocator.instance.makeArray!uint(types.length - 1); mixin(genCompList()); @@ -268,7 +269,7 @@ class EntityManager { foreach(entity;&entities_infos.byValue) { - foreach(caller;entity.callers) + foreach(ref caller;entity.callers) { caller.system = &systems[caller.system_id]; } @@ -302,7 +303,13 @@ class EntityManager { call_data.deltas = Mallocator.instance.makeArray(deltas); //Mallocator.instance.makeArray!ushort(system.m_components.length); - entity.callers.add(call_data); + uint index = 0; + for(;index= call_data.system.priority)break; + } + entity.callers.add(call_data,index); } } diff --git a/source/ecs/vector.d b/source/ecs/vector.d index fa5963f..e0b6f2d 100644 --- a/source/ecs/vector.d +++ b/source/ecs/vector.d @@ -148,7 +148,8 @@ public: extend(array.length * 2); } foreach_reverse (size_t i; pos .. used) { - swap(array[i + 1], array[i]); + //swap(array[i + 1], array[i]); + array[i+1] = array[i]; } emplace(&array[pos], t); used++; diff --git a/tests/tests.d b/tests/tests.d index 15b6075..5f5f259 100644 --- a/tests/tests.d +++ b/tests/tests.d @@ -101,6 +101,28 @@ int main() test2.b += 2; test2.a = 8; //writeln("Jakis tekst! ",test2.b); + writeln("Low priority tekst! "); + } + + void handleEvent(Event event, ref TestComp comp) + { + + } + } + + struct TestSystemWithHighPriority + { + + void initialize(ref Entity entity, ref TestComp comp) + { + + } + + void update(ref Entity entity, ref TestComp test) //ref TestComp comp) + { + assert(cast(size_t)&test % TestComp.alignof == 0); + + writeln("High priority tekst! "); } void handleEvent(Event event, ref TestComp comp) @@ -158,7 +180,9 @@ int main() time = MonoTime.currTime; + gEM.registerSystem!TestSystemWithHighPriority(100); gEM.registerSystem!TestSystem(0); + //gEM.registerSystem!TestSystemWithHighPriority(100); //gEM.registerSystem!TestSystem2(0); dur = (MonoTime.currTime - time).total!"usecs";