Compare commits
No commits in common. "93d6d14e70997ac1ac6ba4a0ad18f2285c3773c7" and "3ad8fc6d2130bb05d43485e96defe35028f314af" have entirely different histories.
93d6d14e70
...
3ad8fc6d21
2 changed files with 13 additions and 25 deletions
|
@ -207,7 +207,6 @@ TEST_CASE("Create a simple system that processes entities with a specific "
|
||||||
*/
|
*/
|
||||||
w.query<Component>([](entity_id e, Component& c) { c.value++; });
|
w.query<Component>([](entity_id e, Component& c) { c.value++; });
|
||||||
|
|
||||||
REQUIRE(w.filter<Component>().size() == 2);
|
|
||||||
REQUIRE(w.get<Component>(e0).value == 1);
|
REQUIRE(w.get<Component>(e0).value == 1);
|
||||||
REQUIRE(w.get<Component>(e1).value == 21);
|
REQUIRE(w.get<Component>(e1).value == 21);
|
||||||
}
|
}
|
||||||
|
@ -248,9 +247,6 @@ TEST_CASE("Test a systems ability to query and process only entities with a "
|
||||||
c1.value++;
|
c1.value++;
|
||||||
});
|
});
|
||||||
|
|
||||||
REQUIRE(w.filter<C0, C1>().size() == 1);
|
|
||||||
REQUIRE(w.filter<C0, C1>()[0] == e0);
|
|
||||||
|
|
||||||
REQUIRE(w.get<C0>(e0).value == 1);
|
REQUIRE(w.get<C0>(e0).value == 1);
|
||||||
REQUIRE(w.get<C1>(e0).value == 11);
|
REQUIRE(w.get<C1>(e0).value == 11);
|
||||||
|
|
||||||
|
|
34
zecsy.hpp
34
zecsy.hpp
|
@ -78,9 +78,6 @@ namespace zecsy
|
||||||
template<Component First, Component Second, Component... Rest>
|
template<Component First, Component Second, Component... Rest>
|
||||||
void remove(entity_id e);
|
void remove(entity_id e);
|
||||||
|
|
||||||
template<Component... T>
|
|
||||||
std::vector<entity_id> filter();
|
|
||||||
|
|
||||||
template<Component... T>
|
template<Component... T>
|
||||||
void query(std::invocable<entity_id, T&...> auto&& system);
|
void query(std::invocable<entity_id, T&...> auto&& system);
|
||||||
|
|
||||||
|
@ -89,10 +86,9 @@ namespace zecsy
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using comp_id = size_t;
|
using comp_id = size_t;
|
||||||
using entity_group = std::set<entity_id>;
|
using zecsy_bits = std::bitset<ZECSY_MAX_COMPONENTS>;
|
||||||
using archetype_signature = std::bitset<ZECSY_MAX_COMPONENTS>;
|
|
||||||
|
|
||||||
std::unordered_map<entity_id, archetype_signature> entity_to_comps;
|
std::unordered_map<entity_id, zecsy_bits> entity_to_comps;
|
||||||
entity_id entity_counter = 0;
|
entity_id entity_counter = 0;
|
||||||
|
|
||||||
size_t query_archetypes_checked = 0;
|
size_t query_archetypes_checked = 0;
|
||||||
|
@ -106,6 +102,10 @@ namespace zecsy
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unordered_map<comp_id, component_pool> pools;
|
std::unordered_map<comp_id, component_pool> pools;
|
||||||
|
|
||||||
|
using archetype_signature = zecsy_bits;
|
||||||
|
using entity_group = std::set<entity_id>;
|
||||||
|
|
||||||
std::unordered_map<archetype_signature, entity_group> archetypes;
|
std::unordered_map<archetype_signature, entity_group> archetypes;
|
||||||
|
|
||||||
template<Component T>
|
template<Component T>
|
||||||
|
@ -349,8 +349,10 @@ namespace zecsy
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Component... T>
|
template<Component... T>
|
||||||
inline std::vector<entity_id> world::filter()
|
inline void world::query(std::invocable<entity_id, T&...> auto&& system)
|
||||||
{
|
{
|
||||||
|
/*std::vector<comp_id> required = {get_component_id<T>()...};*/
|
||||||
|
|
||||||
archetype_signature required;
|
archetype_signature required;
|
||||||
|
|
||||||
(required.set(get_component_id<T>()), ...);
|
(required.set(get_component_id<T>()), ...);
|
||||||
|
@ -358,8 +360,6 @@ namespace zecsy
|
||||||
query_archetypes_checked = 0;
|
query_archetypes_checked = 0;
|
||||||
query_entities_processed = 0;
|
query_entities_processed = 0;
|
||||||
|
|
||||||
std::vector<entity_id> result;
|
|
||||||
|
|
||||||
for(const auto& [archetype_key, entities]: archetypes)
|
for(const auto& [archetype_key, entities]: archetypes)
|
||||||
{
|
{
|
||||||
query_archetypes_checked++;
|
query_archetypes_checked++;
|
||||||
|
@ -367,19 +367,11 @@ namespace zecsy
|
||||||
if((archetype_key & required) == required)
|
if((archetype_key & required) == required)
|
||||||
{
|
{
|
||||||
query_entities_processed += entities.size();
|
query_entities_processed += entities.size();
|
||||||
result.insert(result.end(), entities.begin(), entities.end());
|
for(entity_id e: entities)
|
||||||
|
{
|
||||||
|
system(e, get<T>(e)...);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Component... T>
|
|
||||||
inline void world::query(std::invocable<entity_id, T&...> auto&& system)
|
|
||||||
{
|
|
||||||
for(auto e: filter<T...>())
|
|
||||||
{
|
|
||||||
system(e, get<T>(e)...);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}; // namespace zecsy
|
}; // namespace zecsy
|
||||||
|
|
Loading…
Reference in a new issue