Use std::invocable<T&...>
This commit is contained in:
parent
006d9fc95e
commit
3aaa4557c6
2 changed files with 12 additions and 11 deletions
|
@ -139,7 +139,7 @@ TEST_CASE("Addresses of removed components should be reused")
|
||||||
* Gotta reverse it because now we reuse ids in LIFO order
|
* Gotta reverse it because now we reuse ids in LIFO order
|
||||||
*/
|
*/
|
||||||
std::reverse(addr.begin(), addr.end());
|
std::reverse(addr.begin(), addr.end());
|
||||||
|
|
||||||
for(int j = 0; j < N; ++j)
|
for(int j = 0; j < N; ++j)
|
||||||
{
|
{
|
||||||
REQUIRE(&w.get<ChoosenOne>(entities[j]) == addr[j]);
|
REQUIRE(&w.get<ChoosenOne>(entities[j]) == addr[j]);
|
||||||
|
|
21
zecsy.hpp
21
zecsy.hpp
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <concepts>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
@ -8,9 +9,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <variant>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <concepts>
|
|
||||||
|
|
||||||
namespace zecsy
|
namespace zecsy
|
||||||
{
|
{
|
||||||
|
@ -22,14 +21,14 @@ namespace zecsy
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
concept Component = []
|
concept Component = []
|
||||||
{
|
{
|
||||||
static_assert((std::is_default_constructible_v<T> && ...),
|
static_assert((std::is_default_constructible_v<T> && ...),
|
||||||
"Should have a default constructor");
|
"Should have a default constructor");
|
||||||
static_assert((std::is_trivially_copyable_v<T> && ...),
|
static_assert((std::is_trivially_copyable_v<T> && ...),
|
||||||
"Should be trivially copyable");
|
"Should be trivially copyable");
|
||||||
static_assert((std::is_trivially_destructible_v<T> && ...),
|
static_assert((std::is_trivially_destructible_v<T> && ...),
|
||||||
"Should be trivially destructible");
|
"Should be trivially destructible");
|
||||||
static_assert((std::is_standard_layout_v<T> && ...),
|
static_assert((std::is_standard_layout_v<T> && ...),
|
||||||
"Should have standard layout");
|
"Should have standard layout");
|
||||||
return true;
|
return true;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
@ -213,6 +212,7 @@ namespace zecsy
|
||||||
void add_system(int freq, auto&& func);
|
void add_system(int freq, auto&& func);
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct system_handler
|
struct system_handler
|
||||||
{
|
{
|
||||||
|
@ -273,7 +273,8 @@ namespace zecsy
|
||||||
void remove(entity_id e);
|
void remove(entity_id e);
|
||||||
|
|
||||||
template<Component... T>
|
template<Component... T>
|
||||||
void query(auto&& system);
|
void query(std::invocable<T&...> auto&& system);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
entities_set alive_entities;
|
entities_set alive_entities;
|
||||||
entity_id entity_counter = 0;
|
entity_id entity_counter = 0;
|
||||||
|
@ -328,7 +329,7 @@ namespace zecsy
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Component... T>
|
template<Component... T>
|
||||||
inline void world::query(auto&& system)
|
inline void world::query(std::invocable<T&...> auto&& system)
|
||||||
{
|
{
|
||||||
for(auto e: alive_entities)
|
for(auto e: alive_entities)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue