From 5db5f88f5d855651fa798178b1881a447862561b Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 26 Jan 2023 19:10:08 -0800 Subject: [PATCH 1/6] C++ execution options view --- ecsact/runtime/core.hh | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index c1f6d71f..275a1b5c 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -1,10 +1,86 @@ #pragma once #include +#include +#if __has_include() +# include +#endif #include "ecsact/runtime/core.h" namespace ecsact::core { +class execution_options_view { + ecsact_execution_options& _c_exec_opts; + +public: + inline execution_options_view(ecsact_execution_options& options) + : _c_exec_opts(options) { + } + + inline auto add_components() -> std::span { + return std::span( + _c_exec_opts.add_components, + static_cast(_c_exec_opts.add_components_length) + ); + } + + inline auto add_components_entities() -> std::span { + return std::span( + _c_exec_opts.add_components_entities, + static_cast(_c_exec_opts.add_components_length) + ); + } + + inline auto update_components() -> std::span { + return std::span( + _c_exec_opts.update_components, + static_cast(_c_exec_opts.update_components_length) + ); + } + + inline auto update_components_entities() -> std::span { + return std::span( + _c_exec_opts.update_components_entities, + static_cast(_c_exec_opts.update_components_length) + ); + } + + inline auto remove_components() -> std::span { + return std::span( + _c_exec_opts.remove_components, + static_cast(_c_exec_opts.remove_components_length) + ); + } + + inline auto remove_components_entities() -> std::span { + return std::span( + _c_exec_opts.remove_components_entities, + static_cast(_c_exec_opts.remove_components_length) + ); + } + + inline auto actions() -> std::span { + return std::span( + _c_exec_opts.actions, + static_cast(_c_exec_opts.actions_length) + ); + } + +#ifdef __cpp_lib_ranges_zip + inline auto add_components_zip() { + return std::views::zip(add_components_entities(), add_components()); + } + + inline auto update_components_zip() { + return std::views::zip(update_components_entities(), update_components()); + } + + inline auto remove_components_zip() { + return std::views::zip(remove_components_entities(), remove_components()); + } +#endif +}; + class registry { ecsact_registry_id _id; bool _owned = false; From 96bf3d9e627a0273ad95888099345268607e63ff Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 26 Jan 2023 19:11:06 -0800 Subject: [PATCH 2/6] documentation --- ecsact/runtime/core.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index 275a1b5c..98806f73 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -9,6 +9,9 @@ namespace ecsact::core { +/** + * Lightweight view of a `ecsact_execution_options` struct. + */ class execution_options_view { ecsact_execution_options& _c_exec_opts; From 63e83449e22201882246f54a2935b1d6a149892b Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 26 Jan 2023 19:14:22 -0800 Subject: [PATCH 3/6] Added empty util fn --- ecsact/runtime/core.hh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index 98806f73..4aa2f3ce 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -69,6 +69,17 @@ public: ); } + /** + * @returns `true` when all lengths are `0` + */ + inline auto empty() const noexcept -> bool { + return // + _c_exec_opts.actions_length == 0 && + _c_exec_opts.add_components_length == 0 && + _c_exec_opts.update_components_length == 0 && + _c_exec_opts.remove_components_length == 0; + } + #ifdef __cpp_lib_ranges_zip inline auto add_components_zip() { return std::views::zip(add_components_entities(), add_components()); From a2ea9c5a0ea7dd681bc6adf87973f669338e37e9 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Mon, 6 Feb 2023 12:22:45 -0800 Subject: [PATCH 4/6] added pair methods --- ecsact/runtime/core.hh | 83 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index 4aa2f3ce..8c4f7382 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -2,6 +2,8 @@ #include #include +#include +#include #if __has_include() # include #endif @@ -13,62 +15,104 @@ namespace ecsact::core { * Lightweight view of a `ecsact_execution_options` struct. */ class execution_options_view { - ecsact_execution_options& _c_exec_opts; + const ecsact_execution_options& _c_exec_opts; public: - inline execution_options_view(ecsact_execution_options& options) + inline execution_options_view(const ecsact_execution_options& options) : _c_exec_opts(options) { } - inline auto add_components() -> std::span { + inline auto add_components() const -> std::span { return std::span( _c_exec_opts.add_components, static_cast(_c_exec_opts.add_components_length) ); } - inline auto add_components_entities() -> std::span { + inline auto add_components_entities() const -> std::span { return std::span( _c_exec_opts.add_components_entities, static_cast(_c_exec_opts.add_components_length) ); } - inline auto update_components() -> std::span { + inline auto update_components() const -> std::span { return std::span( _c_exec_opts.update_components, static_cast(_c_exec_opts.update_components_length) ); } - inline auto update_components_entities() -> std::span { + inline auto update_components_entities() const + -> std::span { return std::span( _c_exec_opts.update_components_entities, static_cast(_c_exec_opts.update_components_length) ); } - inline auto remove_components() -> std::span { + inline auto remove_components() const -> std::span { return std::span( _c_exec_opts.remove_components, static_cast(_c_exec_opts.remove_components_length) ); } - inline auto remove_components_entities() -> std::span { + inline auto remove_components_entities() const + -> std::span { return std::span( _c_exec_opts.remove_components_entities, static_cast(_c_exec_opts.remove_components_length) ); } - inline auto actions() -> std::span { + inline auto actions() const -> std::span { return std::span( _c_exec_opts.actions, static_cast(_c_exec_opts.actions_length) ); } + inline auto add_components_pairs() const + -> std::vector> { + auto result = std::vector>{}; + result.reserve(_c_exec_opts.add_components_length); + for(int i = 0; _c_exec_opts.add_components_length > i; ++i) { + auto entity = _c_exec_opts.add_components_entities[i]; + auto comp = _c_exec_opts.add_components[i]; + result.push_back({entity, comp}); + } + + return result; + } + + inline auto update_components_pairs() const + -> std::vector> { + auto result = std::vector>{}; + result.reserve(_c_exec_opts.update_components_length); + for(int i = 0; _c_exec_opts.update_components_length > i; ++i) { + auto entity = _c_exec_opts.update_components_entities[i]; + auto comp = _c_exec_opts.update_components[i]; + result.push_back({entity, comp}); + } + + return result; + } + + inline auto remove_components_pairs() const + -> std::vector> { + auto result = + std::vector>{}; + result.reserve(_c_exec_opts.remove_components_length); + for(int i = 0; _c_exec_opts.remove_components_length > i; ++i) { + auto entity = _c_exec_opts.remove_components_entities[i]; + auto comp = _c_exec_opts.remove_components[i]; + result.push_back({entity, comp}); + } + + return result; + } + /** * @returns `true` when all lengths are `0` */ @@ -95,6 +139,27 @@ public: #endif }; +template +class execution_options_view_span { + std::span _span; + +public: + using size_type = std::size_t; + + constexpr execution_options_view_span() noexcept { + } + + template + constexpr execution_options_view_span(It first, size_type count) + : _span(std::forward(first), count) { + } + + template + constexpr execution_options_view_span(It first, End last) + : _span(std::forward(first), std::forward(last)) { + } +}; + class registry { ecsact_registry_id _id; bool _owned = false; From b53de7757667e7e0b46736435ad8980164ce5e96 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Mon, 6 Feb 2023 12:27:44 -0800 Subject: [PATCH 5/6] remove span idea --- ecsact/runtime/core.hh | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index 8c4f7382..f1ad3f9b 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -139,27 +139,6 @@ public: #endif }; -template -class execution_options_view_span { - std::span _span; - -public: - using size_type = std::size_t; - - constexpr execution_options_view_span() noexcept { - } - - template - constexpr execution_options_view_span(It first, size_type count) - : _span(std::forward(first), count) { - } - - template - constexpr execution_options_view_span(It first, End last) - : _span(std::forward(first), std::forward(last)) { - } -}; - class registry { ecsact_registry_id _id; bool _owned = false; From 7ce89a91004779d7f01fa3a294a7f28a8f6c77b7 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Tue, 14 Feb 2023 07:55:59 -0800 Subject: [PATCH 6/6] wip --- ecsact/runtime/core.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index f1ad3f9b..d02be524 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -223,6 +223,20 @@ public: ) { return ecsact_update_component(_id, entity_id, Component::id, &component); } + + inline void execute_systems(int32_t execution_count = 1) { + ecsact_execute_systems(_id, execution_count, nullptr, nullptr); + } + + template + inline void execute_systems(ExecutionOptionsRange&& execution_options_range) { + ecsact_execution_options* options = std::data(execution_options_range); + + auto execution_count = + static_cast(std::size(execution_options_range)); + + ecsact_execute_systems(_id, execution_count, options, nullptr); + } }; } // namespace ecsact::core