diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index c1f6d71f..d02be524 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -1,10 +1,144 @@ #pragma once #include +#include +#include +#include +#if __has_include() +# include +#endif #include "ecsact/runtime/core.h" namespace ecsact::core { +/** + * Lightweight view of a `ecsact_execution_options` struct. + */ +class execution_options_view { + const ecsact_execution_options& _c_exec_opts; + +public: + inline execution_options_view(const ecsact_execution_options& options) + : _c_exec_opts(options) { + } + + 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() const -> std::span { + return std::span( + _c_exec_opts.add_components_entities, + static_cast(_c_exec_opts.add_components_length) + ); + } + + 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() const + -> std::span { + return std::span( + _c_exec_opts.update_components_entities, + static_cast(_c_exec_opts.update_components_length) + ); + } + + 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() const + -> std::span { + return std::span( + _c_exec_opts.remove_components_entities, + static_cast(_c_exec_opts.remove_components_length) + ); + } + + 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` + */ + 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()); + } + + 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; @@ -89,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