Test multiple components at once
This commit is contained in:
parent
6737ffb2eb
commit
672d27a6a3
2 changed files with 39 additions and 12 deletions
|
@ -1,10 +1,8 @@
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_all.hpp>
|
||||||
|
|
||||||
//#define MAX_ZECSY_ENTITIES 4
|
|
||||||
#include "../zecsy.hpp"
|
#include "../zecsy.hpp"
|
||||||
|
|
||||||
using namespace zecsy;
|
using namespace zecsy;
|
||||||
|
@ -168,3 +166,20 @@ TEST_CASE("Addresses of removed components should be reused")
|
||||||
entities.clear();
|
entities.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Attach multiple components to an entity and verify all are correctly stored and retrievable")
|
||||||
|
{
|
||||||
|
world w;
|
||||||
|
|
||||||
|
auto e = w.make_entity();
|
||||||
|
e.set(ChoosenOne{});
|
||||||
|
e.set(Name{"zecsy"});
|
||||||
|
|
||||||
|
REQUIRE(e.has<ChoosenOne, Name>());
|
||||||
|
REQUIRE(w.has<ChoosenOne, Name>(e));
|
||||||
|
|
||||||
|
e.remove<ChoosenOne>();
|
||||||
|
|
||||||
|
REQUIRE_FALSE(e.has<ChoosenOne, Name>());
|
||||||
|
REQUIRE_FALSE(w.has<ChoosenOne, Name>(e));
|
||||||
|
}
|
||||||
|
|
32
zecsy.hpp
32
zecsy.hpp
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <catch2/internal/catch_console_colour.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
@ -30,7 +31,7 @@ namespace zecsy
|
||||||
|
|
||||||
bool is_alive() const;
|
bool is_alive() const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename... T>
|
||||||
bool has() const;
|
bool has() const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -54,6 +55,10 @@ namespace zecsy
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool has(entity_id e) const;
|
bool has(entity_id e) const;
|
||||||
|
|
||||||
|
template<typename First, typename Second, typename... Rest>
|
||||||
|
requires(sizeof...(Rest) >= 0)
|
||||||
|
bool has(entity_id e) const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& get(entity_id e);
|
T& get(entity_id e);
|
||||||
|
|
||||||
|
@ -95,7 +100,7 @@ namespace zecsy
|
||||||
void destroy_entity(entity_id e);
|
void destroy_entity(entity_id e);
|
||||||
bool is_alive(entity_id e) const;
|
bool is_alive(entity_id e) const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename... T>
|
||||||
bool has(entity_id e) const;
|
bool has(entity_id e) const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -151,12 +156,6 @@ namespace zecsy
|
||||||
return entities_bitset.test(e);
|
return entities_bitset.test(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline bool world::has(entity_id e) const
|
|
||||||
{
|
|
||||||
return storage.has<T>(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool component_storage::has(entity_id e) const
|
inline bool component_storage::has(entity_id e) const
|
||||||
{
|
{
|
||||||
|
@ -184,10 +183,10 @@ namespace zecsy
|
||||||
return *ptr;
|
return *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename... T>
|
||||||
inline bool entity::has() const
|
inline bool entity::has() const
|
||||||
{
|
{
|
||||||
return w->has<T>(id);
|
return w->has<T...>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -269,4 +268,17 @@ namespace zecsy
|
||||||
{
|
{
|
||||||
w->remove<T>(id);
|
w->remove<T>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename... T>
|
||||||
|
inline bool world::has(entity_id e) const
|
||||||
|
{
|
||||||
|
return storage.has<T...>(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename First, typename Second, typename... Rest>
|
||||||
|
requires(sizeof...(Rest) >= 0)
|
||||||
|
inline bool component_storage::has(entity_id e) const
|
||||||
|
{
|
||||||
|
return has<First>(e) && has<Second>(e) && (has<Rest>(e) && ...);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue