From 27cf20fac3baaef34d3fdb79464cb938db9ea948 Mon Sep 17 00:00:00 2001 From: NukeBird Date: Thu, 20 Feb 2025 00:17:11 +0300 Subject: [PATCH] Queries also provide entity_id --- system_scheduler.hpp | 2 +- tests/zecsy.cpp | 12 ++++-------- zecsy.hpp | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/system_scheduler.hpp b/system_scheduler.hpp index 7644142..1bd8a11 100644 --- a/system_scheduler.hpp +++ b/system_scheduler.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include namespace zecsy { diff --git a/tests/zecsy.cpp b/tests/zecsy.cpp index e3d3bea..4bbe582 100644 --- a/tests/zecsy.cpp +++ b/tests/zecsy.cpp @@ -2,8 +2,8 @@ #define CATCH_CONFIG_MAIN #include -#include "../zecsy.hpp" #include "../system_scheduler.hpp" +#include "../zecsy.hpp" using namespace zecsy; @@ -193,7 +193,7 @@ TEST_CASE("Create a simple system that processes entities with a specific " * Really wanna deduce it to w.query([](Component&){}), * but I have some troubles with it */ - w.query([](Component& c) { c.value++; }); + w.query([](entity_id e, Component& c) { c.value++; }); REQUIRE(w.get(e0).value == 1); REQUIRE(w.get(e1).value == 21); @@ -223,20 +223,16 @@ TEST_CASE("Test a systems ability to query and process only entities with a " auto e2 = w.make_entity(); w.set(e2, C1{}); - int count = 0; - REQUIRE(w.get(e0).value == 0); REQUIRE(w.get(e0).value == 10); - w.query([&count](C0& c0, C1& c1) + w.query([e0](entity_id e, C0& c0, C1& c1) { + REQUIRE(e == e0); c0.value++; c1.value++; - count++; }); - REQUIRE(count == 1); - REQUIRE(w.get(e0).value == 1); REQUIRE(w.get(e0).value == 11); diff --git a/zecsy.hpp b/zecsy.hpp index 82b616e..9f583e0 100644 --- a/zecsy.hpp +++ b/zecsy.hpp @@ -63,7 +63,7 @@ namespace zecsy void remove(entity_id e); template - void query(std::invocable auto&& system); + void query(std::invocable auto&& system); private: using comp_id = size_t; @@ -228,13 +228,13 @@ namespace zecsy } template - inline void world::query(std::invocable auto&& system) + inline void world::query(std::invocable auto&& system) { for(auto e: alive_entities) { if((has(e))) { - system(get(e)...); + system(e, get(e)...); } } }