2022-11-15 12:19:11 +01:00
|
|
|
#pragma once
|
|
|
|
|
#include <concepts>
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
|
|
namespace Seele
|
|
|
|
|
{
|
|
|
|
|
template<typename... Types>
|
|
|
|
|
struct Dependencies;
|
|
|
|
|
template<>
|
|
|
|
|
struct Dependencies<>
|
2023-11-10 19:18:09 +01:00
|
|
|
{
|
|
|
|
|
int x;
|
|
|
|
|
};
|
2022-11-15 12:19:11 +01:00
|
|
|
template<typename This, typename... Rest>
|
|
|
|
|
struct Dependencies<This, Rest...> : public Dependencies<Rest...>
|
|
|
|
|
{
|
|
|
|
|
template<typename... Right>
|
|
|
|
|
Dependencies<This, Rest..., Right...> operator|(const Dependencies<Right...>& other)
|
|
|
|
|
{
|
|
|
|
|
return Dependencies<This, Rest..., Right...>();
|
|
|
|
|
}
|
2023-11-10 19:18:09 +01:00
|
|
|
int x;
|
2022-11-15 12:19:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace Component
|
|
|
|
|
{
|
|
|
|
|
template<typename Comp>
|
|
|
|
|
static int accessComponent(Comp& comp);
|
|
|
|
|
}
|
2023-11-10 19:18:09 +01:00
|
|
|
template<typename Comp>
|
|
|
|
|
concept has_dependencies = requires(Comp) { Comp::dependencies; };
|
2022-11-15 12:19:11 +01:00
|
|
|
|
|
|
|
|
#define REQUIRE_COMPONENT(x) \
|
|
|
|
|
private: \
|
|
|
|
|
x& get##x() { return *tl_##x; } \
|
|
|
|
|
const x& get##x() const { return *tl_##x; }; \
|
|
|
|
|
public: \
|
2023-11-10 19:18:09 +01:00
|
|
|
constexpr static Dependencies<x> dependencies;
|
2022-11-15 12:19:11 +01:00
|
|
|
|
|
|
|
|
#define DECLARE_COMPONENT(x) \
|
|
|
|
|
thread_local extern x* tl_##x; \
|
|
|
|
|
template<> \
|
|
|
|
|
int accessComponent<x>(x& val) { tl_##x = &val; return 0; }
|
|
|
|
|
|
|
|
|
|
#define DEFINE_COMPONENT(x) \
|
|
|
|
|
thread_local x* Seele::Component::tl_##x;
|
|
|
|
|
|
|
|
|
|
} // namespace Seele
|