From 3aaa4557c6528ea2da6040f7178143900443ead8 Mon Sep 17 00:00:00 2001 From: NukeBird Date: Tue, 18 Feb 2025 22:44:21 +0300 Subject: [PATCH] Use std::invocable --- tests/zecsy.cpp | 2 +- zecsy.hpp | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/zecsy.cpp b/tests/zecsy.cpp index 497b145..a0fbc67 100644 --- a/tests/zecsy.cpp +++ b/tests/zecsy.cpp @@ -139,7 +139,7 @@ TEST_CASE("Addresses of removed components should be reused") * Gotta reverse it because now we reuse ids in LIFO order */ std::reverse(addr.begin(), addr.end()); - + for(int j = 0; j < N; ++j) { REQUIRE(&w.get(entities[j]) == addr[j]); diff --git a/zecsy.hpp b/zecsy.hpp index 4d4a467..b637b58 100644 --- a/zecsy.hpp +++ b/zecsy.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include #include @@ -8,9 +9,7 @@ #include #include #include -#include #include -#include namespace zecsy { @@ -22,14 +21,14 @@ namespace zecsy template concept Component = [] { - static_assert((std::is_default_constructible_v && ...), - "Should have a default constructor"); + static_assert((std::is_default_constructible_v && ...), + "Should have a default constructor"); static_assert((std::is_trivially_copyable_v && ...), - "Should be trivially copyable"); + "Should be trivially copyable"); static_assert((std::is_trivially_destructible_v && ...), - "Should be trivially destructible"); - static_assert((std::is_standard_layout_v && ...), - "Should have standard layout"); + "Should be trivially destructible"); + static_assert((std::is_standard_layout_v && ...), + "Should have standard layout"); return true; }(); @@ -213,6 +212,7 @@ namespace zecsy void add_system(int freq, auto&& func); void update(float dt); + private: struct system_handler { @@ -273,7 +273,8 @@ namespace zecsy void remove(entity_id e); template - void query(auto&& system); + void query(std::invocable auto&& system); + private: entities_set alive_entities; entity_id entity_counter = 0; @@ -328,7 +329,7 @@ namespace zecsy } template - inline void world::query(auto&& system) + inline void world::query(std::invocable auto&& system) { for(auto e: alive_entities) {