19 virtual void run() = 0;
24 virtual auto name() const ->
std::string_view = 0;
58class system_argument_state_trait;
63template<
typename... Args>
67 using system_state_tuple = std::tuple<typename system_argument_state_trait<Args>::state_type...>;
74 _state(typename system_argument_state_trait<Args>::state_type(
registry, user_context)...){};
79 [[nodiscard]] system_state_tuple& get() noexcept {
86 auto access_pattern() const -> access_pattern_t {
87 access_pattern_t pattern;
88 if constexpr (0 < std::tuple_size_v<system_state_tuple>) {
89 pattern &= std::apply([](
auto&&... args) {
return (args.access_pattern() & ...); }, _state);
95 system_state_tuple _state;
102struct system_state_trait;
107template<
typename... Ts>
108struct system_state_trait<
std::tuple<Ts...>> {
109 using type = system_state<Ts...>;
116class system_executor :
public system_executor_interface {
119 using system_arguments =
typename detail::function_traits<F>::arguments_tuple_type;
125 explicit system_executor(registry& registry,
void* user_context, F func, std::string_view name = {}) :
126 _func(
std::move(func)), _state(registry, user_context), _name(name) {
130 void run()
override {
131 std::apply([
this](
auto&&... args) { _func(args.get()...); }, _state.get());
137 auto name() const ->
std::string_view
override {
144 auto type_name() const ->
std::string_view
override {
145 return co_ecs::type_name<F>();
151 auto access_pattern() const -> access_pattern_t
override {
152 return _state.access_pattern();
157 typename system_state_trait<system_arguments>::type _state;
158 std::string_view _name;
165class system :
public system_interface {
170 explicit system(F func) : _func(
std::move(func)) {
178 std::unique_ptr<system_executor_interface> create_executor(registry& registry,
void* user_context)
override {
179 return std::make_unique<system_executor<F>>(registry, user_context, _func);
188class system_registry_state {
194 explicit system_registry_state(registry& registry,
void* user_context) noexcept : _registry(registry) {
200 [[nodiscard]] registry& get() noexcept {
207 auto access_pattern() const -> access_pattern_t {
208 return access_pattern_t(access_type::write);
217class system_argument_state_trait<registry&> {
220 using state_type = system_registry_state;
225class system_const_registry_state {
231 explicit system_const_registry_state(registry& registry,
void* user_context) noexcept : _registry(registry) {
237 [[nodiscard]]
const registry& get() noexcept {
244 auto access_pattern() const -> access_pattern_t {
245 return access_pattern_t(access_type::read);
249 const registry& _registry;
254class system_argument_state_trait<const registry&> {
257 using state_type = system_registry_state;
262class system_command_writer_state {
268 explicit system_command_writer_state(registry& registry,
void* user_context) noexcept : _registry(registry) {
274 [[nodiscard]] command_writer get() noexcept {
275 return command_writer(_registry);
281 auto access_pattern() const -> access_pattern_t {
282 return access_pattern_t{};
291class system_argument_state_trait<command_writer> {
294 using state_type = system_command_writer_state;
300template<
typename view_t>
301class system_view_state {
307 explicit system_view_state(registry& registry,
void* user_context) noexcept : _view(registry) {
313 [[nodiscard]] view_t& get() noexcept {
319 struct access_pattern_helper {};
321 template<component_reference... Args>
322 struct access_pattern_helper<view<Args...>> {
323 static auto access_pattern() -> access_pattern_t {
324 return (access_pattern_t(
325 std::is_const_v<std::remove_reference_t<Args>> ? access_type::read :
access_type::
write,
335 auto access_pattern() const -> access_pattern_t {
336 return access_pattern_helper<view_t>::access_pattern();
346template<component_reference... Args>
347class system_argument_state_trait<view<Args...>> {
350 using state_type = system_view_state<view<Args...>>;
Class representing an access pattern for components.
Definition access.hpp:19
Registry is a container for all our entities and components. Components are stored in continuously in...
Definition registry.hpp:13
System executor interface, a system is a type that implements run() method.
Definition system.hpp:13
virtual auto name() const -> std::string_view=0
Get the name of the entity.
virtual auto type_name() const -> std::string_view=0
Get the type name of the entity.
virtual void run()=0
Execute system logic.
virtual ~system_executor_interface()=default
Destroy the system executor interface object.
virtual auto access_pattern() const -> access_pattern_t=0
Get the access pattern of the entity.
System interface.
Definition system.hpp:38
virtual ~system_interface()=default
Destroy the system interface object.
virtual std::unique_ptr< system_executor_interface > create_executor(registry ®istry, void *user_context)=0
Create a system executor object.
Definition archetype.hpp:11
std::decay_t< T > decay_component_t
Decay component; converts component_reference to component by removing cv-qualifiers and reference.
Definition component.hpp:100
access_type
Enumeration representing the type of access.
Definition access.hpp:10
@ write
Write access.
Definition access.hpp:13