From 586f7b224ec5adb66821501e3505fdce8fcf10c0 Mon Sep 17 00:00:00 2001 From: NukeBird Date: Sat, 15 Feb 2025 18:24:18 +0300 Subject: [PATCH] std::set might work better for systems (?) --- tests/zecsy.cpp | 17 +++++++++++++++++ zecsy.hpp | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/zecsy.cpp b/tests/zecsy.cpp index a5c8c92..ac863bd 100644 --- a/tests/zecsy.cpp +++ b/tests/zecsy.cpp @@ -186,3 +186,20 @@ TEST_CASE("Attach multiple components to an entity and verify all are correctly REQUIRE_FALSE(e.has()); REQUIRE_FALSE(e.has()); } + +TEST_CASE("Create a simple system that processes entities with a specific component and verify it executes correctly") +{ + struct Component + { + int value = 0; + }; + + world w; + auto e0 = w.make_entity(), e1 = w.make_entity(); + + e0.set(); //or e0.set(Component{}) + e1.set(Component{20}); + + REQUIRE(e0.get().value == 0); + REQUIRE(e1.get().value == 20); +} diff --git a/zecsy.hpp b/zecsy.hpp index 8f534ee..4f28b08 100644 --- a/zecsy.hpp +++ b/zecsy.hpp @@ -7,11 +7,19 @@ #include #include #include +#include namespace zecsy { using entity_id = uint64_t; - using entities_set = std::unordered_set; + + /* + * unordered_set is also an option. But probably sorting ids may be + * beneficial for queries, because it might increase the chance of reusing + * cpu cache (aka "required components were close to each other"). Definitely + * should play around with it + */ + using entities_set = std::set; class entity final {