diff --git a/meson.build b/meson.build index b26bdcc..3317d5c 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,7 @@ project('DECS', 'd') src = [ + 'source/ecs/atomic.d', 'source/ecs/attributes.d', 'source/ecs/block_allocator.d', 'source/ecs/core.d', @@ -9,14 +10,12 @@ src = [ 'source/ecs/hash_map.d', 'source/ecs/id_manager.d', 'source/ecs/manager.d', - 'source/ecs/simple_vector.d', + 'source/ecs/package.d', 'source/ecs/simple_vector.d', 'source/ecs/std.d', - 'source/ecs/atomic.d', 'source/ecs/system.d', 'source/ecs/traits.d', - 'source/ecs/vector.d', - 'source/ecs/package.d' + 'source/ecs/vector.d' ] tests_src = [ diff --git a/source/ecs/manager.d b/source/ecs/manager.d index f3c5db8..853cf14 100644 --- a/source/ecs/manager.d +++ b/source/ecs/manager.d @@ -164,14 +164,16 @@ export struct EntityManager foreach (ref system; systems) { - if (system.m_empty == true) + if (system.m_empty) { - addSystemCaller(system.id); + if (system.m_update) + addSystemCaller(system.id); continue; } if (system.m_update is null) { - if (system.m_add_entity || system.m_remove_entity || system.m_change_entity) + if (system.m_add_entity || system.m_remove_entity + || system.m_change_entity || system.m_event_callers.length) { foreach (info; &entities_infos.byValue) { @@ -181,7 +183,7 @@ export struct EntityManager continue; } - bool added = false; + /*bool added = false; foreach (i, caller; passes[system.m_pass].system_callers) { if (systems[caller.system_id].priority > system.priority) @@ -202,7 +204,8 @@ export struct EntityManager sys_caller.job_group.caller = sys_caller; system.m_any_system_caller = sys_caller; passes[system.m_pass].system_callers.add(sys_caller); - } + }*/ + addSystemCaller(system.id); foreach (info; &entities_infos.byValue) { @@ -739,6 +742,9 @@ export struct EntityManager enum OnUpdateOverloadNum = -1; //enum HasOnUpdate = (hasMember!(Sys, "onUpdate") && checkOnUpdateParams()); + static if (components_info.req.length == 0 && components_info.optional.length == 0) + system.m_empty = true; + static if (OnUpdateOverloadNum != -1) { static if (components_info.req.length != 0 || components_info.optional.length != 0) @@ -819,8 +825,6 @@ export struct EntityManager (cast(typeof(&__traits(getOverloads, s, "onUpdate")[OnUpdateOverloadNum])) data.update_delegate)(input_data); } - - system.m_empty = true; } system.m_update = &callUpdate; @@ -1454,9 +1458,12 @@ export struct EntityManager foreach (i, ref system; systems) { + if (system.m_empty) + continue; if (system.m_update is null) { - if (system.m_add_entity || system.m_remove_entity || system.m_change_entity) + if (system.m_add_entity || system.m_remove_entity + || system.m_change_entity || system.m_event_callers.length) connectListenerToEntityInfo(*info, cast(uint) i); continue; } diff --git a/tests/tests.d b/tests/tests.d index d75eb47..33ce587 100644 --- a/tests/tests.d +++ b/tests/tests.d @@ -412,6 +412,55 @@ struct Sys3 } } +struct EmptyEventSystem +{ + mixin ECS.System; + + bool handled = false; + + struct EntitiesData + { + uint thread_id; + } + + void handleEvent(Entity* entity, TestEvent event) + { + if(!handled) + { + printf("EmptyEventSystem.handleEvent() called!\n"); + handled = true; + } + assert(0,"this shouldn't be called!"); + } +} + +struct EventSystem +{ + mixin ECS.System; + + bool handled = false; + + struct EntitiesData + { + uint thread_id; + TestComp[] comp; + } + + void handleEvent(Entity* entity, TestEvent event) + { + if(!handled) + { + printf("EventSystem.handleEvent() called!\n"); + handled = true; + } + } + + /*void onUpdate(EntitiesData) + { + + }*/ +} + struct EmptySystem { mixin ECS.System; @@ -458,7 +507,7 @@ struct TestSystem2 //TestComp* tt; } - void handleEvent(Entity* entity, ref TestEvent event) + void handleEvent(Entity* entity, TestEvent event) { TestComp3* test = entity.getComponent!TestComp3; test.bg = event.a; @@ -467,7 +516,7 @@ struct TestSystem2 gEM.sendEvent(entity.id, event2); } - void handleEvent(Entity* entity, ref TestEvent2 event) + void handleEvent(Entity* entity, TestEvent2 event) { TestComp3* test = entity.getComponent!TestComp3; test.gg = cast(uint) event.a; @@ -618,6 +667,8 @@ else: gEM.registerSystem!Sys2(-100); gEM.registerSystem!Sys3(-2); gEM.registerSystem!EmptySystem(2); + gEM.registerSystem!EmptyEventSystem(2); + gEM.registerSystem!EventSystem(2); //gEM.registerSystem!TestSystemWithHighPriority(100); //gEM.registerSystem!TestSystem2(0); gEM.endRegister();