From 61b4548a94b9d3f6cc97d19c2f9f5e3bea83c24b Mon Sep 17 00:00:00 2001 From: Kelwan Date: Wed, 29 May 2024 07:36:38 -0700 Subject: [PATCH] feat: Provider base class, folder structure and lazy done --- rt_entt_codegen/core/BUILD.bazel | 1 + rt_entt_codegen/core/print_sys_exec.cc | 149 +++++------------ rt_entt_codegen/core/sys_exec/sys_exec.cc | 8 +- rt_entt_codegen/core/sys_exec/sys_exec.hh | 32 ++-- .../core/system_provider/BUILD.bazel | 54 ++++++ .../association/association.cc | 96 +++++++++++ .../association/association.hh | 38 +++++ .../core/system_provider/basic/basic.cc | 0 .../core/system_provider/basic/basic.hh | 8 + .../core/system_provider/lazy/lazy.cc | 156 ++++++++++++++++++ .../core/system_provider/lazy/lazy.hh | 73 ++++++++ .../core/system_provider/notify/notify.cc | 0 .../core/system_provider/notify/notify.hh | 0 .../core/system_provider/system_provider.hh | 30 ++++ 14 files changed, 516 insertions(+), 129 deletions(-) create mode 100644 rt_entt_codegen/core/system_provider/BUILD.bazel create mode 100644 rt_entt_codegen/core/system_provider/association/association.cc create mode 100644 rt_entt_codegen/core/system_provider/association/association.hh create mode 100644 rt_entt_codegen/core/system_provider/basic/basic.cc create mode 100644 rt_entt_codegen/core/system_provider/basic/basic.hh create mode 100644 rt_entt_codegen/core/system_provider/lazy/lazy.cc create mode 100644 rt_entt_codegen/core/system_provider/lazy/lazy.hh create mode 100644 rt_entt_codegen/core/system_provider/notify/notify.cc create mode 100644 rt_entt_codegen/core/system_provider/notify/notify.hh create mode 100644 rt_entt_codegen/core/system_provider/system_provider.hh diff --git a/rt_entt_codegen/core/BUILD.bazel b/rt_entt_codegen/core/BUILD.bazel index e8d9c8d..9c51e96 100644 --- a/rt_entt_codegen/core/BUILD.bazel +++ b/rt_entt_codegen/core/BUILD.bazel @@ -26,6 +26,7 @@ _CORE_CODEGEN_METHODS = { "//rt_entt_codegen/shared:system_util", "//rt_entt_codegen/shared:parallel", "//rt_entt_codegen/core/sys_exec", + "//rt_entt_codegen/core/system_provider:lazy", "@entt//:entt", "@ecsact_rt_entt//:lib", ], diff --git a/rt_entt_codegen/core/print_sys_exec.cc b/rt_entt_codegen/core/print_sys_exec.cc index db0ec30..c1dae08 100644 --- a/rt_entt_codegen/core/print_sys_exec.cc +++ b/rt_entt_codegen/core/print_sys_exec.cc @@ -20,6 +20,9 @@ #include "rt_entt_codegen/shared/system_util.hh" #include "rt_entt_codegen/shared/parallel.hh" #include "rt_entt_codegen/core/sys_exec/sys_exec.hh" +#include "rt_entt_codegen/core/system_provider/lazy/lazy.hh" +#include "system_provider/lazy/lazy.hh" +#include "system_provider/system_provider.hh" using capability_t = std::unordered_map; @@ -45,9 +48,10 @@ static auto print_sys_exec_ctx_action( .parameter("void*", "out_action_data") .return_type("void final"); - if(options.is_action()) { - auto action_name = - cpp_identifier(decl_full_name(options.get_sys_like_id())); + if(options.sys_like_id_variant.is_action()) { + auto action_name = cpp_identifier( + decl_full_name(options.sys_like_id_variant.get_sys_like_id()) + ); ctx.write( "*static_cast<", @@ -673,17 +677,29 @@ static auto print_execute_systems( using ecsact::cpp_codegen_plugin_util::block; using ecsact::meta::decl_full_name; using ecsact::rt_entt_codegen::ecsact_entt_system_details; + using ecsact::rt_entt_codegen::core::provider::lazy; using ecsact::rt_entt_codegen::system_util::create_context_struct_name; using ecsact::rt_entt_codegen::system_util::create_context_var_name; using ecsact::rt_entt_codegen::system_util::is_notify_system; using ecsact::rt_entt_codegen::system_util::print_system_notify_views; using ecsact::rt_entt_codegen::util::method_printer; - auto sys_caps = ecsact::meta::system_capabilities(options.get_sys_like_id()); + auto lazy_provider = lazy{ + ctx, + sys_details, + options.sys_like_id_variant, + options.registry_var_name + }; + + auto sys_caps = ecsact::meta::system_capabilities( + options.sys_like_id_variant.get_sys_like_id() + ); auto lazy_iteration_rate = 0; - auto exec_start_label_name = - std::format("exec_start_{}_", static_cast(options.get_sys_like_id())); + auto exec_start_label_name = std::format( + "exec_start_{}_", + static_cast(options.sys_like_id_variant.get_sys_like_id()) + ); auto pending_lazy_exec_struct = std::format( "::ecsact::entt::detail::pending_lazy_execution<::{}>", @@ -697,37 +713,23 @@ static auto print_execute_systems( auto additional_view_components = std::vector{}; - if(options.is_system()) { - lazy_iteration_rate = ecsact_meta_get_lazy_iteration_rate( - static_cast(options.get_sys_like_id()) - ); - } - - if(lazy_iteration_rate > 0) { - ctx.write( - "constexpr auto lazy_iteration_rate_ = ", - lazy_iteration_rate, - ";\n\n" - ); - ctx.write("auto iteration_count_ = 0;\n\n"); - ctx.write(exec_start_label_name, ":\n"); - additional_view_components.push_back(pending_lazy_exec_struct); + if(options.sys_like_id_variant.is_system()) { + lazy_iteration_rate = + ecsact_meta_get_lazy_iteration_rate(static_cast( + options.sys_like_id_variant.get_sys_like_id() + )); } - if(options.is_system()) { - if(system_needs_sorted_entities(options.as_system())) { - additional_view_components.push_back(system_sorting_struct_name); - } - } + lazy_provider.before_make_view_or_group(additional_view_components); - if(is_notify_system(options.get_sys_like_id())) { + if(is_notify_system(options.sys_like_id_variant.get_sys_like_id())) { additional_view_components.push_back( std::format("ecsact::entt::detail::run_system<{}>", options.system_name) ); print_system_notify_views( ctx, sys_details, - options.get_sys_like_id(), + options.sys_like_id_variant.get_sys_like_id(), options.registry_var_name ); } @@ -742,8 +744,8 @@ static auto print_execute_systems( ctx.write("using view_t = decltype(view);\n"); - if(options.is_system()) { - if(system_needs_sorted_entities(options.as_system())) { + if(options.sys_like_id_variant.is_system()) { + if(system_needs_sorted_entities(options.sys_like_id_variant.as_system())) { ctx.write("view.use<", system_sorting_struct_name, ">();\n"); } } @@ -790,19 +792,7 @@ static auto print_execute_systems( auto other_view_names = print_other_contexts(ctx, sys_details, options); block(ctx, "for(ecsact::entt::entity_id entity : view)", [&] { - if(lazy_iteration_rate > 0) { - block(ctx, "if(iteration_count_ == lazy_iteration_rate_)", [&] { - ctx.write("break;\n"); - }); - - ctx.write("++iteration_count_;\n"); - ctx.write( - options.registry_var_name, - ".erase<", - pending_lazy_exec_struct, - ">(entity);\n" - ); - } + lazy_provider.pre_exec_system_impl(); // value = comp var name auto components_with_entity_fields = @@ -894,75 +884,12 @@ static auto print_execute_systems( ctx.write("\n"); }); - if(lazy_iteration_rate > 0) { - ctx.write( - "// If this assertion triggers that's a ecsact_rt_entt codegen " - "failure\n" - ); - ctx.write("assert(iteration_count_ <= lazy_iteration_rate_);\n"); - block(ctx, "if(iteration_count_ < lazy_iteration_rate_)", [&] { - ctx.write( - "_recalc_sorting_hash<", - options.system_name, - ">(", - options.registry_var_name, - ");\n" - ); - ctx.write( - options.registry_var_name, - ".sort<", - system_sorting_struct_name, - ">([](const auto& a, const auto& b) { return a.hash < b.hash; });\n" - ); - - ecsact::rt_entt_codegen::util::make_view( - ctx, - "view_no_pending_lazy_", - options.registry_var_name, - sys_details - ); - - ctx.write("auto view_no_pending_lazy_count_ = 0;\n"); - - block( - ctx, - "for(ecsact::entt::entity_id entity : view_no_pending_lazy_)", - [&] { - ctx.write( - "// If this assertion triggers this is an indicator of a codegen " - "failure.\n" - "// Please report to " - "https://github.com/ecsact-dev/ecsact_rt_entt\n" - ); - ctx.write( - "assert(", - options.registry_var_name, - ".all_of<", - system_sorting_struct_name, - ">(entity));\n" - ); - ctx.write("view_no_pending_lazy_count_ += 1;\n"); - ctx.write( - options.registry_var_name, - ".emplace<", - pending_lazy_exec_struct, - ">(entity);\n" - ); - } - ); - - block( - ctx, - "if(view_no_pending_lazy_count_ >= lazy_iteration_rate_)", - [&] { ctx.write("goto ", exec_start_label_name, ";\n"); } - ); - }); - } + lazy_provider.post_exec_system_impl(); print_apply_pendings( ctx, sys_details, - options.get_sys_like_id(), + options.sys_like_id_variant.get_sys_like_id(), options.registry_var_name ); } @@ -1030,7 +957,7 @@ static auto print_execute_system_template_specialization( using ecsact::cc_lang_support::cpp_identifier; using ecsact::cpp_codegen_plugin_util::block; using ecsact::meta::decl_full_name; - using ecsact::rt_entt_codegen::core::system_like_id_variant_t; + using ecsact::rt_entt_codegen::core::system_like_id_variant; using ecsact::rt_entt_codegen::system_util::is_trivial_system; using ecsact::rt_entt_codegen::util::method_printer; @@ -1066,7 +993,7 @@ static auto print_execute_system_template_specialization( details, sys_details, { - .sys_like_id = system_id, + .sys_like_id_variant = system_id, .system_name = system_name, .registry_var_name = "registry", .parent_context_var_name = "parent_context", @@ -1129,7 +1056,7 @@ static auto print_execute_actions_template_specialization( details, sys_details, { - .sys_like_id = action_id, + .sys_like_id_variant = action_id, .system_name = cpp_system_name, .registry_var_name = "registry", .parent_context_var_name = "nullptr", diff --git a/rt_entt_codegen/core/sys_exec/sys_exec.cc b/rt_entt_codegen/core/sys_exec/sys_exec.cc index 116fc47..5bac9dc 100644 --- a/rt_entt_codegen/core/sys_exec/sys_exec.cc +++ b/rt_entt_codegen/core/sys_exec/sys_exec.cc @@ -14,8 +14,9 @@ auto ecsact::rt_entt_codegen::core::print_child_systems( using ecsact::meta::get_child_system_ids; using ecsact::rt_entt_codegen::ecsact_entt_system_details; - auto child_system_ids = - ecsact::meta::get_child_system_ids(options.get_sys_like_id()); + auto child_system_ids = ecsact::meta::get_child_system_ids( + options.sys_like_id_variant.get_sys_like_id() + ); std::vector child_system_like_ids{}; @@ -34,7 +35,8 @@ auto ecsact::rt_entt_codegen::core::print_child_systems( // TODO(Kelwan): Make use case system agnostic when we support // nested Action systems // Issue: https://github.com/ecsact-dev/ecsact_parse/issues/154 - for(auto child_sys_id : get_child_system_ids(options.get_sys_like_id())) { + for(auto child_sys_id : + get_child_system_ids(options.sys_like_id_variant.get_sys_like_id())) { auto child_details = ecsact_entt_system_details::from_system_like( ecsact_id_cast(child_sys_id) ); diff --git a/rt_entt_codegen/core/sys_exec/sys_exec.hh b/rt_entt_codegen/core/sys_exec/sys_exec.hh index e1cd738..e37a40a 100644 --- a/rt_entt_codegen/core/sys_exec/sys_exec.hh +++ b/rt_entt_codegen/core/sys_exec/sys_exec.hh @@ -14,41 +14,43 @@ namespace ecsact::rt_entt_codegen::core { -using system_like_id_variant_t = - std::variant; - -struct print_execute_systems_options { - system_like_id_variant_t sys_like_id; - std::string system_name; - std::string registry_var_name; - std::string parent_context_var_name; - /// only set if system is an action - std::optional action_var_name; +struct system_like_id_variant + : std::variant { + using variant::variant; auto as_system() const -> ecsact_system_id { - return std::get(sys_like_id); + return std::get(*this); } auto as_action() const -> ecsact_action_id { - return std::get(sys_like_id); + return std::get(*this); } auto is_system() const -> bool { - return std::holds_alternative(sys_like_id); + return std::holds_alternative(*this); } auto is_action() const -> bool { - return std::holds_alternative(sys_like_id); + return std::holds_alternative(*this); } auto get_sys_like_id() const -> ecsact_system_like_id { return std::visit( [](auto&& arg) { return static_cast(arg); }, - sys_like_id + *this ); } }; +struct print_execute_systems_options { + system_like_id_variant sys_like_id_variant; + std::string system_name; + std::string registry_var_name; + std::string parent_context_var_name; + /// only set if system is an action + std::optional action_var_name; +}; + auto print_child_systems( ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::ecsact_entt_details& details, diff --git a/rt_entt_codegen/core/system_provider/BUILD.bazel b/rt_entt_codegen/core/system_provider/BUILD.bazel new file mode 100644 index 0000000..3da4fbe --- /dev/null +++ b/rt_entt_codegen/core/system_provider/BUILD.bazel @@ -0,0 +1,54 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("//bazel:copts.bzl", "copts") + +cc_library( + name = "system_provider", + hdrs = ["system_provider.hh"], + copts = copts, + deps = [ + "//rt_entt_codegen/shared:ecsact_entt_details", + ], +) + +cc_library( + name = "association", + srcs = ["association/association.cc"], + hdrs = ["association/association.hh"], + copts = copts, + deps = [ + ":system_provider", + "//rt_entt_codegen/core/sys_exec", + "//rt_entt_codegen/shared:ecsact_entt_details", + "//rt_entt_codegen/shared:system_util", + ], +) + +cc_library( + name = "basic", + hdrs = ["basic/basic.hh"], + copts = copts, +) + +cc_library( + name = "notify", + hdrs = ["notify/notify.hh"], + copts = copts, + deps = [ + ":system_provider", + "//rt_entt_codegen/shared:ecsact_entt_details", + ], +) + +cc_library( + name = "lazy", + srcs = ["lazy/lazy.cc"], + hdrs = ["lazy/lazy.hh"], + copts = copts, + visibility = ["//rt_entt_codegen/core:__pkg__"], + deps = [ + ":system_provider", + "//rt_entt_codegen/core/sys_exec", + "//rt_entt_codegen/shared:ecsact_entt_details", + "//rt_entt_codegen/shared:sorting", + ], +) diff --git a/rt_entt_codegen/core/system_provider/association/association.cc b/rt_entt_codegen/core/system_provider/association/association.cc new file mode 100644 index 0000000..8534f49 --- /dev/null +++ b/rt_entt_codegen/core/system_provider/association/association.cc @@ -0,0 +1,96 @@ +#include "association.hh" + +#include + +#include "ecsact/lang-support/lang-cc.hh" +#include "rt_entt_codegen/shared/system_util.hh" +#include "rt_entt_codegen/shared/util.hh" +#include "ecsact/runtime/meta.hh" + +ecsact::rt_entt_codegen::core::provider::association::association() { +} + +static auto print_other_contexts( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const ecsact::rt_entt_codegen::core::print_execute_systems_options options +) -> std::map { + using ecsact::cc_lang_support::cpp_identifier; + using ecsact::cpp_codegen_plugin_util::block; + using ecsact::meta::component_name; + using ecsact::meta::decl_full_name; + using ecsact::meta::get_child_system_ids; + using ecsact::rt_entt_codegen::ecsact_entt_system_details; + using ecsact::rt_entt_codegen::other_key; + using ecsact::rt_entt_codegen::system_util::create_context_struct_name; + using ecsact::rt_entt_codegen::system_util::create_context_var_name; + using ecsact::rt_entt_codegen::system_util::get_unique_view_name; + using ecsact::rt_entt_codegen::util::method_printer; + + std::map other_views; + + for(auto& assoc_detail : details.association_details) { + auto struct_name = create_context_struct_name(assoc_detail.component_id); + auto struct_header = struct_name + " : ecsact_system_execution_context "; + + auto view_name = get_unique_view_name(); + other_views.insert( + other_views.end(), + std::pair( + other_key{ + .component_like_id = assoc_detail.component_id, + .field_id = assoc_detail.field_id // + }, + view_name + ) + ); + + auto other_details = + ecsact_entt_system_details::from_capabilities(assoc_detail.capabilities); + + ecsact::rt_entt_codegen::util::make_view( + ctx, + view_name, + "registry", + other_details + ); + + ctx.write(std::format("using {}_t = decltype({});\n", view_name, view_name) + ); + + block(ctx, "struct " + struct_header, [&] { + using namespace std::string_literals; + using ecsact::rt_entt_codegen::util::decl_cpp_ident; + using std::views::transform; + + ctx.write(std::format("{}_t* view;\n", view_name)); + ctx.write("\n"); + print_sys_exec_ctx_action(ctx, other_details, options); + print_sys_exec_ctx_add(ctx, other_details, assoc_detail.capabilities); + print_sys_exec_ctx_remove( + ctx, + other_details, + assoc_detail.capabilities, + view_name + ); + print_sys_exec_ctx_get(ctx, other_details, view_name); + print_sys_exec_ctx_update(ctx, other_details, view_name); + print_sys_exec_ctx_has(ctx, other_details); + print_sys_exec_ctx_generate(ctx, other_details); + print_sys_exec_ctx_parent(ctx); + print_sys_exec_ctx_other(ctx, other_details); + }); + ctx.write(";\n\n"); + + auto type_name = cpp_identifier(decl_full_name(assoc_detail.component_id)); + auto context_name = create_context_var_name(assoc_detail.component_id); + + ctx.write(struct_name, " ", context_name, ";\n\n"); + + ctx.write(context_name, ".view = &", view_name, ";\n"); + ctx.write(context_name, ".parent_ctx = nullptr;\n\n"); + ctx.write(context_name, ".registry = &", options.registry_var_name, ";\n"); + } + + return other_views; +} diff --git a/rt_entt_codegen/core/system_provider/association/association.hh b/rt_entt_codegen/core/system_provider/association/association.hh new file mode 100644 index 0000000..889ffbf --- /dev/null +++ b/rt_entt_codegen/core/system_provider/association/association.hh @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +#include "rt_entt_codegen/core/sys_exec/sys_exec.hh" +#include "rt_entt_codegen/core/system_provider/system_provider.hh" + +namespace ecsact::rt_entt_codegen::core::provider { +class association : system_provider { +public: + association(); + + auto initialization() -> void = 0; + + auto before_make_view_or_group( + std::vector& additional_view_components + ) -> void = 0; + + auto after_make_view_or_gorup() -> void = 0; + + auto context_function_add() -> void = 0; + auto context_function_remove() -> void = 0; + auto context_function_get() -> void = 0; + auto context_function_update() -> void = 0; + auto context_function_has() -> void = 0; + + auto entity_iteration() -> void = 0; + auto pre_exec_system_impl() -> void = 0; + auto system_impl() -> void = 0; + auto post_exec_system_impl() -> void = 0; + auto post_iteration() -> void = 0; + +private: + std::map other_views; +}; +} // namespace ecsact::rt_entt_codegen::core::provider diff --git a/rt_entt_codegen/core/system_provider/basic/basic.cc b/rt_entt_codegen/core/system_provider/basic/basic.cc new file mode 100644 index 0000000..e69de29 diff --git a/rt_entt_codegen/core/system_provider/basic/basic.hh b/rt_entt_codegen/core/system_provider/basic/basic.hh new file mode 100644 index 0000000..18f4f58 --- /dev/null +++ b/rt_entt_codegen/core/system_provider/basic/basic.hh @@ -0,0 +1,8 @@ +#pragma once + +#include "rt_entt_codegen/core/system_provider/system_provider.hh" + +namespace rt_entt_codegen::core::provider { + +class basic : system_provider {} +} // namespace rt_entt_codegen::core::provider diff --git a/rt_entt_codegen/core/system_provider/lazy/lazy.cc b/rt_entt_codegen/core/system_provider/lazy/lazy.cc new file mode 100644 index 0000000..d3692ad --- /dev/null +++ b/rt_entt_codegen/core/system_provider/lazy/lazy.cc @@ -0,0 +1,156 @@ +#include "lazy.hh" + +#include + +#include "ecsact/lang-support/lang-cc.hh" +#include "rt_entt_codegen/shared/sorting.hh" +#include "rt_entt_codegen/shared/util.hh" +#include "ecsact/runtime/meta.hh" + +ecsact::rt_entt_codegen::core::provider::lazy::lazy( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& sys_details, + const ecsact::rt_entt_codegen::core::system_like_id_variant& system_like_id_v, + const std::string& registry_name +) + : ctx(ctx) + , system_details(sys_details) + , system_like_id_variant(system_like_id_v) + , registry_name(registry_name) { + using ecsact::cc_lang_support::cpp_identifier; + using ecsact::meta::decl_full_name; + + system_name = + cpp_identifier(decl_full_name(system_like_id_variant.get_sys_like_id())); + + lazy_iteration_rate = 0; + + if(system_like_id_variant.is_system()) { + lazy_iteration_rate = ecsact_meta_get_lazy_iteration_rate( + static_cast(system_like_id_variant.get_sys_like_id()) + ); + } + + exec_start_label_name = std::format( + "exec_start_{}_", + static_cast(system_like_id_v.get_sys_like_id()) + ); + + pending_lazy_exec_struct = std::format( + "::ecsact::entt::detail::pending_lazy_execution<::{}>", + system_name + ); + + system_sorting_struct_name = + std::format("::ecsact::entt::detail::system_sorted<{}>", system_name); +} + +auto ecsact::rt_entt_codegen::core::provider::lazy::before_make_view_or_group( + std::vector& additional_view_components +) -> void { + if(lazy_iteration_rate > 0) { + ctx.write( + "constexpr auto lazy_iteration_rate_ = ", + lazy_iteration_rate, + ";\n\n" + ); + ctx.write("auto iteration_count_ = 0;\n\n"); + ctx.write(exec_start_label_name, ":\n"); + additional_view_components.push_back(pending_lazy_exec_struct); + } + + if(system_like_id_variant.is_system()) { + if(system_needs_sorted_entities(system_like_id_variant.as_system())) { + additional_view_components.push_back(system_sorting_struct_name); + } + } +} + +auto ecsact::rt_entt_codegen::core::provider::lazy::pre_exec_system_impl() + -> void { + using ecsact::cpp_codegen_plugin_util::block; + + if(lazy_iteration_rate > 0) { + block(ctx, "if(iteration_count_ == lazy_iteration_rate_)", [&] { + ctx.write("break;\n"); + }); + + ctx.write("++iteration_count_;\n"); + ctx.write( + registry_name, + ".erase<", + pending_lazy_exec_struct, + ">(entity);\n" + ); + } +} + +auto ecsact::rt_entt_codegen::core::provider::lazy::post_exec_system_impl() + -> void { + using ecsact::cpp_codegen_plugin_util::block; + + if(lazy_iteration_rate > 0) { + ctx.write( + "// If this assertion triggers that's a ecsact_rt_entt codegen " + "failure\n" + ); + ctx.write("assert(iteration_count_ <= lazy_iteration_rate_);\n"); + block(ctx, "if(iteration_count_ < lazy_iteration_rate_)", [&] { + ctx.write( + "_recalc_sorting_hash<", + system_name, + ">(", + registry_name, + ");\n" + ); + ctx.write( + registry_name, + ".sort<", + system_sorting_struct_name, + ">([](const auto& a, const auto& b) { return a.hash < b.hash; });\n" + ); + + ecsact::rt_entt_codegen::util::make_view( + ctx, + "view_no_pending_lazy_", + registry_name, + system_details + ); + + ctx.write("auto view_no_pending_lazy_count_ = 0;\n"); + + block( + ctx, + "for(ecsact::entt::entity_id entity : view_no_pending_lazy_)", + [&] { + ctx.write( + "// If this assertion triggers this is an indicator of a codegen " + "failure.\n" + "// Please report to " + "https://github.com/ecsact-dev/ecsact_rt_entt\n" + ); + ctx.write( + "assert(", + registry_name, + ".all_of<", + system_sorting_struct_name, + ">(entity));\n" + ); + ctx.write("view_no_pending_lazy_count_ += 1;\n"); + ctx.write( + registry_name, + ".emplace<", + pending_lazy_exec_struct, + ">(entity);\n" + ); + } + ); + + block( + ctx, + "if(view_no_pending_lazy_count_ >= lazy_iteration_rate_)", + [&] { ctx.write("goto ", exec_start_label_name, ";\n"); } + ); + }); + } +} diff --git a/rt_entt_codegen/core/system_provider/lazy/lazy.hh b/rt_entt_codegen/core/system_provider/lazy/lazy.hh new file mode 100644 index 0000000..2db3ad9 --- /dev/null +++ b/rt_entt_codegen/core/system_provider/lazy/lazy.hh @@ -0,0 +1,73 @@ +#pragma once + +#include +#include + +#include "rt_entt_codegen/core/sys_exec/sys_exec.hh" +#include "rt_entt_codegen/core/system_provider/system_provider.hh" + +namespace ecsact::rt_entt_codegen::core::provider { + +class lazy : system_provider { +public: + // Default init to 0 lazy_it_rate + lazy( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& sys_details, + const system_like_id_variant& system_like_id_v, + const std::string& registry_name + ); + + auto initialization() -> void { + } + + auto before_make_view_or_group( + std::vector& additional_view_components + ) -> void final; + + auto after_make_view_or_gorup() -> void { + } + + auto context_function_add() -> void { + } + + auto context_function_remove() -> void { + } + + auto context_function_get() -> void { + } + + auto context_function_update() -> void { + } + + auto context_function_has() -> void { + } + + auto entity_iteration() -> void { + } + + auto pre_exec_system_impl() -> void final; + + auto system_impl() -> void { + } + + auto post_exec_system_impl() -> void final; + + auto post_iteration() -> void { + } + +private: + ecsact::codegen_plugin_context& ctx; + const ecsact::rt_entt_codegen::ecsact_entt_system_details& system_details; + const std::string& registry_name; + const system_like_id_variant& system_like_id_variant; + + std::string system_name; + + std::string exec_start_label_name; + std::string pending_lazy_exec_struct; + std::string system_sorting_struct_name; + + int32_t lazy_iteration_rate; +}; +} // namespace ecsact::rt_entt_codegen::core::provider diff --git a/rt_entt_codegen/core/system_provider/notify/notify.cc b/rt_entt_codegen/core/system_provider/notify/notify.cc new file mode 100644 index 0000000..e69de29 diff --git a/rt_entt_codegen/core/system_provider/notify/notify.hh b/rt_entt_codegen/core/system_provider/notify/notify.hh new file mode 100644 index 0000000..e69de29 diff --git a/rt_entt_codegen/core/system_provider/system_provider.hh b/rt_entt_codegen/core/system_provider/system_provider.hh new file mode 100644 index 0000000..8d722e8 --- /dev/null +++ b/rt_entt_codegen/core/system_provider/system_provider.hh @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include "ecsact/codegen/plugin.hh" + +namespace ecsact::rt_entt_codegen::core::provider { +class system_provider { + virtual auto initialization() -> void = 0; + + virtual auto before_make_view_or_group( + std::vector& additional_view_components + ) -> void = 0; + + virtual auto after_make_view_or_gorup() -> void = 0; + + virtual auto context_function_add() -> void = 0; + virtual auto context_function_remove() -> void = 0; + virtual auto context_function_get() -> void = 0; + virtual auto context_function_update() -> void = 0; + virtual auto context_function_has() -> void = 0; + + virtual auto entity_iteration() -> void = 0; + virtual auto pre_exec_system_impl() -> void = 0; + virtual auto system_impl() -> void = 0; + virtual auto post_exec_system_impl() -> void = 0; + virtual auto post_iteration() -> void = 0; +}; +} // namespace ecsact::rt_entt_codegen::core::provider