std::set might work better for systems (?)
This commit is contained in:
parent
11ff925149
commit
586f7b224e
2 changed files with 26 additions and 1 deletions
|
@ -186,3 +186,20 @@ TEST_CASE("Attach multiple components to an entity and verify all are correctly
|
|||
REQUIRE_FALSE(e.has<ChoosenOne>());
|
||||
REQUIRE_FALSE(e.has<Name>());
|
||||
}
|
||||
|
||||
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<Component>(); //or e0.set(Component{})
|
||||
e1.set(Component{20});
|
||||
|
||||
REQUIRE(e0.get<Component>().value == 0);
|
||||
REQUIRE(e1.get<Component>().value == 20);
|
||||
}
|
||||
|
|
10
zecsy.hpp
10
zecsy.hpp
|
@ -7,11 +7,19 @@
|
|||
#include <typeindex>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <set>
|
||||
|
||||
namespace zecsy
|
||||
{
|
||||
using entity_id = uint64_t;
|
||||
using entities_set = std::unordered_set<entity_id>;
|
||||
|
||||
/*
|
||||
* 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<entity_id>;
|
||||
|
||||
class entity final
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue