From decf71b169aca37167baeb5e52c62bebf2c60852 Mon Sep 17 00:00:00 2001 From: Kelwan Date: Thu, 30 May 2024 17:12:47 -0700 Subject: [PATCH] feat: Tons of refactoring --- rt_entt_codegen/core/BUILD.bazel | 2 + rt_entt_codegen/core/execute_systems.cc | 73 +-- rt_entt_codegen/core/print_sys_exec.cc | 547 ++++-------------- rt_entt_codegen/core/sys_exec/BUILD.bazel | 1 + rt_entt_codegen/core/sys_exec/sys_exec.cc | 94 +-- rt_entt_codegen/core/sys_exec/sys_exec.hh | 10 +- .../core/system_provider/BUILD.bazel | 17 +- .../association/association.cc | 250 +++++--- .../association/association.hh | 108 ++-- .../core/system_provider/basic/basic.cc | 381 +----------- .../core/system_provider/basic/basic.hh | 137 ++--- .../core/system_provider/lazy/lazy.cc | 7 +- .../core/system_provider/lazy/lazy.hh | 124 ++-- .../core/system_provider/notify/notify.cc | 31 +- .../core/system_provider/notify/notify.hh | 126 ++-- .../system_provider/system_ctx_functions.cc | 416 +++++++++++++ .../system_provider/system_ctx_functions.hh | 53 ++ .../core/system_provider/system_provider.cc | 14 +- .../core/system_provider/system_provider.hh | 154 ++--- rt_entt_codegen/shared/BUILD.bazel | 10 + rt_entt_codegen/shared/parallel.cc | 120 +++- rt_entt_codegen/shared/parallel.hh | 18 +- rt_entt_codegen/shared/system_variant.hh | 39 ++ test/codegen_test.nu | 4 +- 24 files changed, 1268 insertions(+), 1468 deletions(-) create mode 100644 rt_entt_codegen/core/system_provider/system_ctx_functions.cc create mode 100644 rt_entt_codegen/core/system_provider/system_ctx_functions.hh create mode 100644 rt_entt_codegen/shared/system_variant.hh diff --git a/rt_entt_codegen/core/BUILD.bazel b/rt_entt_codegen/core/BUILD.bazel index f32c47d..4691826 100644 --- a/rt_entt_codegen/core/BUILD.bazel +++ b/rt_entt_codegen/core/BUILD.bazel @@ -13,6 +13,7 @@ cc_library( _CORE_CODEGEN_METHODS = { "execute_systems": [ "//rt_entt_codegen/shared:parallel", + "//rt_entt_codegen/shared:system_variant", ], "create_registry": [], "entity_matches": [ @@ -29,6 +30,7 @@ _CORE_CODEGEN_METHODS = { "//rt_entt_codegen/core/system_provider:lazy", "//rt_entt_codegen/core/system_provider:association", "//rt_entt_codegen/core/system_provider:notify", + "//rt_entt_codegen/core/system_provider:basic", "//rt_entt_codegen/core/system_provider", "@entt//:entt", "@ecsact_rt_entt//:lib", diff --git a/rt_entt_codegen/core/execute_systems.cc b/rt_entt_codegen/core/execute_systems.cc index 5b076c6..4e216f0 100644 --- a/rt_entt_codegen/core/execute_systems.cc +++ b/rt_entt_codegen/core/execute_systems.cc @@ -4,6 +4,7 @@ #include "ecsact/lang-support/lang-cc.hh" #include "rt_entt_codegen/shared/util.hh" #include "ecsact/cpp_codegen_plugin_util.hh" +#include "rt_entt_codegen/shared/system_variant.hh" constexpr auto METHOD_BODY_TOP = R"( auto& registry = ecsact::entt::get_registry(registry_id); @@ -77,66 +78,28 @@ auto ecsact::rt_entt_codegen::core::print_execute_systems( // }); }); + std::vector system_like_variants; + + for(const auto sys_like_id : details.top_execution_order) { + if(details.is_system(sys_like_id)) { + system_like_variants.push_back(static_cast(sys_like_id) + ); + } else if(details.is_action(sys_like_id)) { + system_like_variants.push_back(static_cast(sys_like_id) + ); + } + } + auto parallel_system_cluster = ecsact::rt_entt_codegen::parallel::get_parallel_execution_cluster( ctx, - details, - details.top_execution_order + system_like_variants ); - for(const auto& systems_to_parallel : parallel_system_cluster) { - if(systems_to_parallel.size() == 1) { - auto sync_sys_id = systems_to_parallel[0]; - - auto sync_sys_name = - cpp_identifier(ecsact::meta::decl_full_name(sync_sys_id)); - - if(details.is_action(sync_sys_id)) { - ctx.write(std::format( - "ecsact::entt::execute_actions<{}>(registry, {}, " - "actions_map);\n", - sync_sys_name, - "nullptr" - )); - } - if(details.is_system(sync_sys_id)) { - ctx.write(std::format( - "ecsact::entt::execute_system<{}>(registry, {}, " - "actions_map);\n", - sync_sys_name, - "nullptr" - )); - } - continue; - } - - ctx.write("execute_parallel_cluster(registry, nullptr, "); - ctx.write(std::format( - "std::array {{\n", - systems_to_parallel.size() - )); - for(const auto system_like_id : systems_to_parallel) { - auto cpp_decl_name = - cpp_identifier(ecsact::meta::decl_full_name(system_like_id)); - - if(details.is_action(system_like_id)) { - ctx.write( - "\texec_entry_t{&ecsact::entt::execute_actions<", - cpp_decl_name, - ">, actions_map},\n" - ); - } else if(details.is_system(system_like_id)) { - ctx.write( - "\texec_entry_t{&ecsact::entt::execute_system<", - cpp_decl_name, - ">, actions_map},\n" - ); - } else { - ctx.write("// ??? unhandled ??? ", cpp_decl_name, "\n"); - } - } - ctx.write("});\n"); - } + ecsact::rt_entt_codegen::parallel::print_parallel_execution_cluster( + ctx, + parallel_system_cluster + ); ctx.write("\nupdate_all_beforechange_storage(registry_id);\n"); ctx.write("cleanup_system_notifies(registry_id);\n"); diff --git a/rt_entt_codegen/core/print_sys_exec.cc b/rt_entt_codegen/core/print_sys_exec.cc index 8ece7dc..ad2e620 100644 --- a/rt_entt_codegen/core/print_sys_exec.cc +++ b/rt_entt_codegen/core/print_sys_exec.cc @@ -2,7 +2,7 @@ #include #include -#include +#include #include "ecsact/runtime/meta.hh" #include "ecsact/runtime/common.h" #include "ecsact/lang-support/lang-cc.hh" @@ -11,15 +11,14 @@ #include "rt_entt_codegen/shared/ecsact_entt_details.hh" #include "rt_entt_codegen/shared/util.hh" #include "rt_entt_codegen/shared/comps_with_caps.hh" -#include "rt_entt_codegen/shared/sorting.hh" #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 "system_provider/system_provider.hh" #include "rt_entt_codegen/core/system_provider/lazy/lazy.hh" #include "system_provider/lazy/lazy.hh" #include "system_provider/association/association.hh" #include "system_provider/notify/notify.hh" +#include "system_provider/basic/basic.hh" using capability_t = std::unordered_map; @@ -29,12 +28,13 @@ concept system_or_action = std::same_as || std::same_as; using ecsact::rt_entt_codegen::system_comps_with_caps; -using ecsact::rt_entt_codegen::core::provider::system_like_id_variant; +using ecsact::rt_entt_codegen::system_like_id_variant; +using ecsact::rt_entt_codegen::core::provider::system_provider; auto print_sys_exec_ctx_action( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { using ecsact::cc_lang_support::cpp_identifier; using ecsact::meta::decl_full_name; @@ -45,33 +45,16 @@ auto print_sys_exec_ctx_action( .parameter("void*", "out_action_data") .return_type("void final"); - 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<", - action_name, - "*>(out_action_data) = *static_cast(action_data);\n" - ); - } else { - // TODO(Kelwan): Trying to access .action() without a valid action - ctx.write("\n"); + for(const auto& provider : system_providers) { + auto result = provider->context_function_action(ctx, names); } } auto print_sys_exec_ctx_add( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - capability_t sys_caps + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { - 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::util::is_transient_component; using ecsact::rt_entt_codegen::util::method_printer; auto printer = // @@ -80,70 +63,16 @@ auto print_sys_exec_ctx_add( .parameter("const void*", "component_data") .return_type("void final"); - auto adds_comps = std::vector{}; - - for(auto&& [comp_id, sys_cap] : sys_caps) { - if(is_transient_component(ctx.package_id, comp_id)) { - continue; - } - if((ECSACT_SYS_CAP_ADDS & sys_cap) == ECSACT_SYS_CAP_ADDS) { - adds_comps.push_back(comp_id); - } + for(const auto& provider : system_providers) { + auto result = provider->context_function_add(ctx, names); } - - if(adds_comps.empty()) { - // TODO(Kelwan): Handle unexpected behaviour - return; - } else if(adds_comps.size() == 1) { - const auto& comp_id = adds_comps.front(); - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "wrapper::dynamic::context_add<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id),", - "component_data); \n" - ); - return; - } - block( - ctx, - "static const auto add_fns = " - "std::unordered_map", - [&] { - for(int i = 0; i < adds_comps.size(); ++i) { - const auto comp_id = adds_comps[i]; - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "{", - "ecsact_id_cast(", - type_name, - "::id), ", - "&wrapper::dynamic::context_add<::", - type_name, - "> }," - ); - } - } - ); - - ctx.write(";\n"); - - ctx.write("add_fns.at(component_id)(this, component_id, component_data);\n"); } auto print_sys_exec_ctx_remove( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - capability_t sys_caps, - const std::string& view_type_name + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { - 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::util::is_transient_component; using ecsact::rt_entt_codegen::util::method_printer; auto printer = // @@ -151,74 +80,16 @@ auto print_sys_exec_ctx_remove( .parameter("ecsact_component_like_id", "component_id") .return_type("void final"); - auto remove_comps = std::vector{}; - - for(auto&& [comp_id, sys_cap] : sys_caps) { - if(is_transient_component(ctx.package_id, comp_id)) { - continue; - } - if((ECSACT_SYS_CAP_REMOVES & sys_cap) == ECSACT_SYS_CAP_REMOVES) { - remove_comps.push_back(comp_id); - } - } - - ctx.write("// Size: ", remove_comps.size(), "\n"); - - if(remove_comps.size() == 0) { - // TODO(Kelwan): Handle unexpected behaviour - return; + for(const auto& provider : system_providers) { + auto result = provider->context_function_remove(ctx, names); } - if(remove_comps.size() == 1) { - const auto& comp_id = remove_comps.front(); - - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "wrapper::dynamic::context_remove<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id), *view);\n" - ); - return; - } - ctx.write(std::format( - "using remove_fn_t = void (*)(ecsact_system_execution_context*, " - "ecsact_component_like_id, {}_t&);\n", - view_type_name - )); - - ctx.write("static const auto remove_fns = []()\n"); - - block(ctx, "", [&] { - ctx.write( - "auto result = std::unordered_map{};\n" - ); - for(const auto comp_id : details.removable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result[ecsact_id_cast(", - type_name, - "::id)] = &wrapper::dynamic::context_remove<", - type_name, - ">;\n" - ); - } - - ctx.write("return result;\n"); - }); - ctx.write("();\n"); } auto print_sys_exec_ctx_get( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const std::string& view_type_name + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { - 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::util::is_transient_component; using ecsact::rt_entt_codegen::util::method_printer; auto printer = // @@ -227,84 +98,16 @@ auto print_sys_exec_ctx_get( .parameter("void*", "out_component_data") .return_type("void final"); - if(details.readable_comps.size() == 0) { - return; - } - - std::vector get_components; - - for(auto comp_id : details.readable_comps) { - if(is_transient_component(ctx.package_id, comp_id)) { - continue; - } - get_components.insert(get_components.end(), comp_id); - } - - if(get_components.size() == 0) { - return; - } - - // Shortcut - ignore component ID because we only have 1 - if(details.get_comps.size() == 1 && details.readable_comps.size() == 1) { - auto comp_id = *details.get_comps.begin(); - auto cpp_comp_full_name = cpp_identifier(decl_full_name(comp_id)); - - ctx.write( - "assert(ecsact_id_cast(::", - cpp_comp_full_name, - "::id) == component_id);\n" - ); - ctx.write( - "*static_cast<::", - cpp_comp_full_name, - "*>(out_component_data) = view->get<::", - cpp_comp_full_name, - ">(entity);" - ); - return; + for(const auto& provider : system_providers) { + auto result = provider->context_function_get(ctx, names); } - - ctx.write(std::format( - "using get_fn_t = void (*)(ecsact_system_execution_context*, " - "ecsact_component_like_id, void *, {}_t&);\n", - view_type_name - )); - - ctx.write("static const auto get_fns = []()\n"); - - block(ctx, "", [&] { - ctx.write( - "auto result = std::unordered_map{};\n" - ); - for(const auto comp_id : details.readable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result[ecsact_id_cast(", - type_name, - "::id)] = &wrapper::dynamic::context_get<", - type_name, - ">;\n" - ); - } - - ctx.write("return result;\n"); - }); - ctx.write("();\n"); - - ctx.write( - "get_fns.at(component_id)(this, component_id, out_component_data, *view);\n" - ); } auto print_sys_exec_ctx_update( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const std::string& view_type_name + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { - 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::util::method_printer; auto printer = // @@ -313,122 +116,33 @@ auto print_sys_exec_ctx_update( .parameter("const void*", "component_data") .return_type("void final"); - if(details.writable_comps.size() == 0) { - return; - } - - if(details.writable_comps.size() == 1) { - const auto& comp_id = *details.writable_comps.begin(); - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "wrapper::dynamic::context_update<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id),", - "component_data, *view); \n" - ); - return; + for(const auto& provider : system_providers) { + auto result = provider->context_function_update(ctx, names); } - - ctx.write(std::format( - "using update_fn_t = void (*)(ecsact_system_execution_context*, " - "ecsact_component_like_id, const void *, {}_t&);\n", - view_type_name - )); - - ctx.write("static const auto update_fns = []()\n"); - - block(ctx, "", [&] { - ctx.write( - "auto result = std::unordered_map{};\n" - ); - for(const auto comp_id : details.writable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result[ecsact_id_cast(", - type_name, - "::id)] = &wrapper::dynamic::context_update<", - type_name, - ">;\n" - ); - } - - ctx.write("return result;\n"); - }); - ctx.write("();\n"); - - ctx.write( - "update_fns.at(component_id)(this, component_id, component_data, " - "*view);\n" - ); } auto print_sys_exec_ctx_has( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { - 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::util::method_printer; - // use optional_comps - auto printer = // method_printer{ctx, "has"} .parameter("ecsact_component_like_id", "component_id") .return_type("bool final"); - if(details.writable_comps.size() == 0) { - ctx.write("return false;"); - return; - } - - if(details.writable_comps.size() == 1) { - const auto& comp_id = *details.writable_comps.begin(); - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "return wrapper::dynamic::context_has<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id));\n" - ); + for(const auto& provider : system_providers) { + auto result = provider->context_function_has(ctx, names); } - block( - ctx, - "static const auto has_fns = " - "std::unordered_map", - [&] { - for(const auto comp_id : details.readable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "{ecsact_id_cast(", - type_name, - "::id), &wrapper::dynamic::context_has<", - type_name, - "> }," - ); - } - } - ); - ctx.write(";\n"); - - ctx.write("return has_fns.at(component_id)(this, component_id);\n"); } auto print_sys_exec_ctx_generate( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { - 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::ecsact_entt_system_details; - using ecsact::rt_entt_codegen::get_all_sorted_systems; using ecsact::rt_entt_codegen::util::method_printer; auto printer = // @@ -438,56 +152,15 @@ auto print_sys_exec_ctx_generate( .parameter("const void**", "components_data") .return_type("void final"); - if(details.generate_comps.size() == 0) { - // TODO (Kelwan): Handle undefined behaviour - return; + for(const auto& provider : system_providers) { + auto result = provider->context_function_generate(ctx, names); } - block( - ctx, - "static const auto generate_fns = " - "std::unordered_map", - [&] { - for(const auto& component : details.generate_comps) { - for(const auto& [comp_id, requirements] : component) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "{", - type_name, - "::id, &wrapper::dynamic::context_generate_add<", - type_name, - "> }," - ); - } - } - } - ); - ctx.write(";\n"); - - // NOTE(Kelwan): Multiple generates blocks are allowed in Ecsact systems but - // currently the interpreter won't allow this. More testing required after the - // issue is resolved https://github.com/ecsact-dev/ecsact_interpret/issues/185 - ctx.write("auto entity = registry->create();\n"); - - ctx.write( - "registry->template emplace(entity, " - "ecsact_generated_entity);\n" - ); - - block(ctx, "for(int i = 0; i < component_count; ++i)", [&] { - ctx.write("const auto component_id = component_ids[i];\n"); - ctx.write("const void* component_data = components_data[i];\n"); - - ctx.write( - "generate_fns.at(component_id)(this, component_id, " - "component_data, entity);\n" - ); - }); } auto print_sys_exec_ctx_parent( // - ecsact::codegen_plugin_context& ctx + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { using ecsact::rt_entt_codegen::util::method_printer; @@ -495,12 +168,15 @@ auto print_sys_exec_ctx_parent( // method_printer{ctx, "parent"} // .return_type("const ecsact_system_execution_context* final"); - ctx.write("return this->parent_ctx;\n"); + for(const auto& provider : system_providers) { + auto result = provider->context_function_parent(ctx, names); + } } auto print_sys_exec_ctx_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names, + std::vector> system_providers ) -> void { using ecsact::rt_entt_codegen::util::method_printer; @@ -509,20 +185,9 @@ auto print_sys_exec_ctx_other( .parameter("ecsact_entity_id", "entity") .return_type("ecsact_system_execution_context* final"); - if(details.association_details.size() == 0) { - // TODO(Kelwan): Handle undefined behaviour - // Attempt to access other without association - - ctx.write("return nullptr;"); - return; + for(const auto& provider : system_providers) { + auto result = provider->context_function_other(ctx, names); } - - ctx.write( - "if(other_contexts.contains(entity)) {\n", - "return other_contexts.at(entity);\n}\n" - ); - // NOTE(Kelwan): Maybe we handle undefined behaviour here too - ctx.write("return nullptr;"); } template @@ -582,43 +247,53 @@ static auto print_apply_pendings( static auto print_execute_systems( ecsact::codegen_plugin_context& ctx, system_like_id_variant sys_like_id_variant, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& sys_details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names ) -> void { + 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::ecsact_entt_system_details; using ecsact::rt_entt_codegen::core::provider::association; + using ecsact::rt_entt_codegen::core::provider::basic; + using ecsact::rt_entt_codegen::core::provider::handle_exclusive_provide; using ecsact::rt_entt_codegen::core::provider::lazy; using ecsact::rt_entt_codegen::core::provider::notify; using ecsact::rt_entt_codegen::util::method_printer; - auto lazy_provider = lazy{sys_like_id_variant}; + assert(sys_like_id_variant != system_like_id_variant{}); - auto association_provider = association{sys_like_id_variant}; - auto notify_provider = notify{sys_like_id_variant}; + auto system_name = + cpp_identifier(decl_full_name(sys_like_id_variant.get_sys_like_id())); + + auto lazy_provider = std::make_shared(sys_like_id_variant); + auto association_provider = + std::make_shared(sys_like_id_variant); + auto notify_provider = std::make_shared(sys_like_id_variant); + auto basic_provider = std::make_shared(sys_like_id_variant); + + std::vector> system_providers{ + lazy_provider, + association_provider, + notify_provider, + basic_provider + }; + + auto sys_details = ecsact_entt_system_details::from_system_like( + sys_like_id_variant.get_sys_like_id() + ); auto sys_caps = ecsact::meta::system_capabilities(sys_like_id_variant.get_sys_like_id()); auto additional_view_components = std::vector{}; - lazy_provider.before_make_view_or_group( - ctx, - sys_details, - names, - additional_view_components - ); - association_provider.before_make_view_or_group( - ctx, - sys_details, - names, - additional_view_components - ); - notify_provider.before_make_view_or_group( - ctx, - sys_details, - names, - additional_view_components - ); + for(const auto& provider : system_providers) { + provider->initialization(ctx, names); + } + + for(const auto& provider : system_providers) { + provider->before_make_view_or_group(ctx, names, additional_view_components); + } ecsact::rt_entt_codegen::util::make_view( ctx, @@ -630,27 +305,27 @@ static auto print_execute_systems( ctx.write("using view_t = decltype(view);\n"); - lazy_provider.after_make_view_or_group(ctx, sys_details, names); + for(const auto& provider : system_providers) { + provider->after_make_view_or_group(ctx, names); + } block(ctx, "struct : ecsact_system_execution_context ", [&] { ctx.write("view_t* view;\n"); - association_provider.context_function_header(ctx, sys_details, names); - - if(names.action_var_name) { - ctx.write("const void* action_data = nullptr;\n"); + for(const auto& provider : system_providers) { + provider->context_function_header(ctx, names); } ctx.write("\n"); - print_sys_exec_ctx_action(ctx, sys_details, names); - print_sys_exec_ctx_add(ctx, sys_details, sys_caps); - print_sys_exec_ctx_remove(ctx, sys_details, sys_caps, "view"); - print_sys_exec_ctx_get(ctx, sys_details, "view"); - print_sys_exec_ctx_update(ctx, sys_details, "view"); - print_sys_exec_ctx_has(ctx, sys_details); - print_sys_exec_ctx_generate(ctx, sys_details); - print_sys_exec_ctx_parent(ctx); - print_sys_exec_ctx_other(ctx, sys_details); + print_sys_exec_ctx_action(ctx, names, system_providers); + print_sys_exec_ctx_add(ctx, names, system_providers); + print_sys_exec_ctx_remove(ctx, names, system_providers); + print_sys_exec_ctx_get(ctx, names, system_providers); + print_sys_exec_ctx_update(ctx, names, system_providers); + print_sys_exec_ctx_has(ctx, names, system_providers); + print_sys_exec_ctx_generate(ctx, names, system_providers); + print_sys_exec_ctx_parent(ctx, names, system_providers); + print_sys_exec_ctx_other(ctx, names, system_providers); }); ctx.write("context;\n\n"); @@ -661,25 +336,42 @@ static auto print_execute_systems( ctx.write( "context.id = ecsact_id_cast(::", - names.system_name, + system_name, "::id);\n" ); ctx.write("context.parent_ctx = ", names.parent_context_var_name, ";\n"); ctx.write("context.view = &view;\n\n"); - association_provider.pre_entity_iteration(ctx, sys_details, names); + for(const auto& provider : system_providers) { + provider->pre_entity_iteration(ctx, names); + } block(ctx, "for(ecsact::entt::entity_id entity : view)", [&] { ctx.write("context.entity = entity;\n"); - lazy_provider.pre_exec_system_impl(ctx, sys_details, names); - association_provider.pre_exec_system_impl(ctx, sys_details, names); - association_provider.system_impl(ctx, sys_details, names); + ecsact::rt_entt_codegen::core::print_child_systems( + ctx, + names, + sys_like_id_variant + ); + + for(const auto& provider : system_providers) { + provider->pre_exec_system_impl(ctx, names); + } + + for(const auto& provider : system_providers) { + auto handle = provider->system_impl(ctx, names); + if(handle == handle_exclusive_provide::HANDLED) { + break; + } + } ctx.write("\n"); }); - lazy_provider.post_exec_system_impl(ctx, sys_details, names); + for(const auto& provider : system_providers) { + provider->post_exec_system_impl(ctx, names); + } print_apply_pendings( ctx, @@ -753,7 +445,6 @@ static auto print_execute_system_template_specialization( using ecsact::meta::decl_full_name; using ecsact::rt_entt_codegen::ecsact_entt_system_details; using ecsact::rt_entt_codegen::system_util::is_trivial_system; - using ecsact::rt_entt_codegen::util::method_printer; auto sys_details = ecsact_entt_system_details::from_system_like( @@ -789,7 +480,6 @@ static auto print_execute_system_template_specialization( print_execute_systems( ctx, system_id, - sys_details, { .registry_var_name = "registry", .parent_context_var_name = "parent_context", @@ -854,7 +544,6 @@ static auto print_execute_actions_template_specialization( print_execute_systems( ctx, action_id, - sys_details, { .registry_var_name = "registry", .parent_context_var_name = "nullptr", diff --git a/rt_entt_codegen/core/sys_exec/BUILD.bazel b/rt_entt_codegen/core/sys_exec/BUILD.bazel index 8ed692a..b781386 100644 --- a/rt_entt_codegen/core/sys_exec/BUILD.bazel +++ b/rt_entt_codegen/core/sys_exec/BUILD.bazel @@ -10,6 +10,7 @@ cc_library( deps = [ "//rt_entt_codegen/shared:ecsact_entt_details", "//rt_entt_codegen/shared:parallel", + "//rt_entt_codegen/shared:system_variant", "//rt_entt_codegen/shared:util", "@ecsact_lang_cpp//:cpp_codegen_plugin_util", ], diff --git a/rt_entt_codegen/core/sys_exec/sys_exec.cc b/rt_entt_codegen/core/sys_exec/sys_exec.cc index 4526a92..586f20f 100644 --- a/rt_entt_codegen/core/sys_exec/sys_exec.cc +++ b/rt_entt_codegen/core/sys_exec/sys_exec.cc @@ -6,39 +6,26 @@ #include "rt_entt_codegen/shared/parallel.hh" auto ecsact::rt_entt_codegen::core::print_child_systems( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_details& details, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& sys_details, - const ecsact::rt_entt_codegen::core::print_execute_systems_options options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, + const ecsact::rt_entt_codegen::system_like_id_variant& sys_like_id_variant + ) -> void { using ecsact::cc_lang_support::cpp_identifier; 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::system_like_id_variant; - 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{}; - - child_system_like_ids.resize(child_system_ids.size()); - - std::transform( - child_system_ids.begin(), - child_system_ids.end(), - child_system_like_ids.begin(), - [](auto system_id) { - return ecsact_id_cast(system_id); - } - ); + auto child_system_ids = + ecsact::meta::get_child_system_ids(sys_like_id_variant.get_sys_like_id()); if(child_system_ids.size() == 1) { // 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.sys_like_id_variant.get_sys_like_id())) { + get_child_system_ids(sys_like_id_variant.get_sys_like_id())) { auto child_details = ecsact_entt_system_details::from_system_like( ecsact_id_cast(child_sys_id) ); @@ -47,7 +34,7 @@ auto ecsact::rt_entt_codegen::core::print_child_systems( ctx.write( "ecsact::entt::execute_system<::" + child_system_name + ">(", - options.registry_var_name, + names.registry_var_name, ", &context, {});\n" ); } @@ -55,63 +42,16 @@ auto ecsact::rt_entt_codegen::core::print_child_systems( auto parallel_system_cluster = ecsact::rt_entt_codegen::parallel::get_parallel_execution_cluster( ctx, - details, - child_system_like_ids - ); - - for(const auto& systems_to_parallel : parallel_system_cluster) { - if(systems_to_parallel.size() == 1) { - auto sync_sys_id = systems_to_parallel[0]; - - auto sync_sys_name = - cpp_identifier(ecsact::meta::decl_full_name(sync_sys_id)); - - if(details.is_action(sync_sys_id)) { - ctx.write(std::format( - "ecsact::entt::execute_actions<{}>(registry, {}, " - "actions_map);\n", - sync_sys_name, - "parent_context" - )); + std::vector{ + child_system_ids.begin(), + child_system_ids.end() } - if(details.is_system(sync_sys_id)) { - ctx.write(std::format( - "ecsact::entt::execute_system<{}>(registry, {}, " - "actions_map);\n", - sync_sys_name, - "parent_context" - )); - } - continue; - } - - ctx.write("execute_parallel_cluster(registry, parent_context, "); - ctx.write(std::format( - "std::array {{\n", - systems_to_parallel.size() - )); - for(const auto system_like_id : systems_to_parallel) { - auto cpp_decl_name = - cpp_identifier(ecsact::meta::decl_full_name(system_like_id)); + ); - if(details.is_action(system_like_id)) { - ctx.write( - "\texec_entry_t{&ecsact::entt::execute_actions<", - cpp_decl_name, - ">, actions_map},\n" - ); - } else if(details.is_system(system_like_id)) { - ctx.write( - "\texec_entry_t{&ecsact::entt::execute_system<", - cpp_decl_name, - ">, actions_map},\n" - ); - } else { - ctx.write("// ??? unhandled ??? ", cpp_decl_name, "\n"); - } - } - ctx.write("});\n"); - } + ecsact::rt_entt_codegen::parallel::print_parallel_execution_cluster( + ctx, + parallel_system_cluster + ); } ctx.write("\n"); diff --git a/rt_entt_codegen/core/sys_exec/sys_exec.hh b/rt_entt_codegen/core/sys_exec/sys_exec.hh index c031bb2..089fd7b 100644 --- a/rt_entt_codegen/core/sys_exec/sys_exec.hh +++ b/rt_entt_codegen/core/sys_exec/sys_exec.hh @@ -2,9 +2,8 @@ #include #include -#include -#include "rt_entt_codegen/shared/ecsact_entt_details.hh" +#include "rt_entt_codegen/shared/system_variant.hh" #include "ecsact/codegen/plugin.hh" namespace ecsact::rt_entt_codegen::core { @@ -17,9 +16,8 @@ struct print_execute_systems_var_names { }; auto print_child_systems( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_details& details, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& sys_details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, + const system_like_id_variant& sys_like_id_variant ) -> void; } // namespace ecsact::rt_entt_codegen::core diff --git a/rt_entt_codegen/core/system_provider/BUILD.bazel b/rt_entt_codegen/core/system_provider/BUILD.bazel index 9a5379d..daf2852 100644 --- a/rt_entt_codegen/core/system_provider/BUILD.bazel +++ b/rt_entt_codegen/core/system_provider/BUILD.bazel @@ -10,6 +10,7 @@ cc_library( deps = [ "//rt_entt_codegen/core/sys_exec", "//rt_entt_codegen/shared:ecsact_entt_details", + "//rt_entt_codegen/shared:system_variant", ], ) @@ -20,6 +21,7 @@ cc_library( copts = copts, visibility = ["//rt_entt_codegen/core:__pkg__"], deps = [ + ":system_ctx_functions", ":system_provider", "//rt_entt_codegen/core/sys_exec", "//rt_entt_codegen/shared:ecsact_entt_details", @@ -34,6 +36,7 @@ cc_library( copts = copts, visibility = ["//rt_entt_codegen/core:__pkg__"], deps = [ + ":system_ctx_functions", ":system_provider", "//rt_entt_codegen/core/sys_exec", "//rt_entt_codegen/shared:ecsact_entt_details", @@ -50,7 +53,6 @@ cc_library( deps = [ ":system_provider", "//rt_entt_codegen/core/sys_exec", - "//rt_entt_codegen/shared:ecsact_entt_details", "//rt_entt_codegen/shared:system_util", ], ) @@ -68,3 +70,16 @@ cc_library( "//rt_entt_codegen/shared:sorting", ], ) + +cc_library( + name = "system_ctx_functions", + srcs = ["system_ctx_functions.cc"], + hdrs = ["system_ctx_functions.hh"], + copts = copts, + visibility = ["//rt_entt_codegen/core:__pkg__"], + deps = [ + "//rt_entt_codegen/core/sys_exec", + "//rt_entt_codegen/shared:ecsact_entt_details", + "//rt_entt_codegen/shared:system_variant", + ], +) diff --git a/rt_entt_codegen/core/system_provider/association/association.cc b/rt_entt_codegen/core/system_provider/association/association.cc index 857a662..5cc71d3 100644 --- a/rt_entt_codegen/core/system_provider/association/association.cc +++ b/rt_entt_codegen/core/system_provider/association/association.cc @@ -7,64 +7,24 @@ #include "rt_entt_codegen/shared/util.hh" #include "ecsact/runtime/meta.hh" #include "ecsact/cpp_codegen_plugin_util.hh" +#include "rt_entt_codegen/core/system_provider/system_ctx_functions.hh" + +using ecsact::rt_entt_codegen::provider::context_action_impl; +using ecsact::rt_entt_codegen::provider::context_add_impl; +using ecsact::rt_entt_codegen::provider::context_generate_impl; +using ecsact::rt_entt_codegen::provider::context_get_impl; +using ecsact::rt_entt_codegen::provider::context_has_impl; +using ecsact::rt_entt_codegen::provider::context_other_impl; +using ecsact::rt_entt_codegen::provider::context_parent_impl; +using ecsact::rt_entt_codegen::provider::context_remove_impl; +using ecsact::rt_entt_codegen::provider::context_update_impl; using capability_t = std::unordered_map; -auto print_sys_exec_ctx_action( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names names -) -> void; - -auto print_sys_exec_ctx_add( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - capability_t sys_caps -) -> void; - -auto print_sys_exec_ctx_remove( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - capability_t sys_caps, - const std::string& view_type_name -) -> void; - -auto print_sys_exec_ctx_get( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const std::string& view_type_name -) -> void; - -auto print_sys_exec_ctx_update( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const std::string& view_type_name -) -> void; - -auto print_sys_exec_ctx_has( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details -) -> void; - -auto print_sys_exec_ctx_generate( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details -) -> void; - -auto print_sys_exec_ctx_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details -) -> void; - -auto print_sys_exec_ctx_parent( // - ecsact::codegen_plugin_context& ctx -) -> void; - auto ecsact::rt_entt_codegen::core::provider::association:: context_function_header( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { ctx.write( @@ -76,44 +36,29 @@ auto ecsact::rt_entt_codegen::core::provider::association:: auto ecsact::rt_entt_codegen::core::provider::association:: after_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto ecsact::rt_entt_codegen::core::provider::association:: context_function_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - if(details.association_details.size() == 0) { - // TODO(Kelwan): Handle undefined behaviour - // Attempt to access other without association - - ctx.write("return nullptr;"); - return HANDLED; - } - - ctx.write( - "if(other_contexts.contains(entity)) {\n", - "return other_contexts.at(entity);\n}\n" - ); + context_other_impl(ctx, sys_like_id_variant, system_details); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::association::pre_entity_iteration( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { - print_other_contexts(ctx, details, names); + print_other_contexts(ctx, names); } auto ecsact::rt_entt_codegen::core::provider::association::pre_exec_system_impl( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { using ecsact::cc_lang_support::cpp_identifier; @@ -185,7 +130,6 @@ auto ecsact::rt_entt_codegen::core::provider::association::pre_exec_system_impl( auto ecsact::rt_entt_codegen::core::provider::association::system_impl( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { using ecsact::cpp_codegen_plugin_util::block; @@ -208,7 +152,6 @@ auto ecsact::rt_entt_codegen::core::provider::association::system_impl( auto ecsact::rt_entt_codegen::core::provider::association::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_var_names& names ) -> void { using ecsact::cc_lang_support::cpp_identifier; @@ -225,13 +168,13 @@ auto ecsact::rt_entt_codegen::core::provider::association::print_other_contexts( std::map other_views; - for(auto& assoc_detail : details.association_details) { + for(auto& assoc_detail : system_details.association_details) { auto struct_name = create_context_struct_name(assoc_detail.component_id); auto context_name = create_context_var_name(assoc_detail.component_id); auto struct_header = struct_name + " : ecsact_system_execution_context "; - auto view_name = get_unique_view_name(); + auto view_type_name = get_unique_view_name(); other_views.insert( other_views.end(), std::pair( @@ -239,7 +182,7 @@ auto ecsact::rt_entt_codegen::core::provider::association::print_other_contexts( .component_like_id = assoc_detail.component_id, .field_id = assoc_detail.field_id // }, - view_name + view_type_name ) ); @@ -248,44 +191,161 @@ auto ecsact::rt_entt_codegen::core::provider::association::print_other_contexts( ecsact::rt_entt_codegen::util::make_view( ctx, - view_name, + view_type_name, "registry", other_details ); - ctx.write(std::format("using {}_t = decltype({});\n", view_name, view_name) - ); + ctx.write(std::format( + "using {}_t = decltype({});\n", + view_type_name, + view_type_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(std::format("{}_t* view;\n", view_type_name)); ctx.write("\n"); - print_sys_exec_ctx_action(ctx, other_details, names); - 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); + print_other_ctx_action(ctx); + print_other_ctx_add(ctx, other_details); + print_other_ctx_remove(ctx, other_details, view_type_name); + print_other_ctx_get(ctx, other_details, view_type_name); + print_other_ctx_update(ctx, other_details, view_type_name); + print_other_ctx_has(ctx, other_details); + print_other_ctx_generate(ctx, other_details); + print_other_ctx_parent(ctx, sys_like_id_variant); + print_other_ctx_other(ctx, other_details); }); ctx.write(";\n\n"); ctx.write(struct_name, " ", context_name, ";\n\n"); - ctx.write(context_name, ".view = &", view_name, ";\n"); + ctx.write(context_name, ".view = &", view_type_name, ";\n"); ctx.write(context_name, ".parent_ctx = nullptr;\n\n"); ctx.write(context_name, ".registry = &", names.registry_var_name, ";\n"); } other_view_names = other_views; } + +using ecsact::rt_entt_codegen::util::method_printer; + +auto ecsact::rt_entt_codegen::core::provider::association:: + print_other_ctx_action(ecsact::codegen_plugin_context& ctx) -> void { + auto printer = // + method_printer{ctx, "action"} + .parameter("void*", "out_action_data") + .return_type("void final"); + + context_action_impl(ctx, sys_like_id_variant); +} + +auto ecsact::rt_entt_codegen::core::provider::association::print_other_ctx_add( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void { + auto printer = // + method_printer{ctx, "add"} + .parameter("ecsact_component_like_id", "component_id") + .parameter("const void*", "component_data") + .return_type("void final"); + + context_add_impl(ctx, sys_like_id_variant); +} + +auto ecsact::rt_entt_codegen::core::provider::association:: + print_other_ctx_remove( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name + ) -> void { + auto printer = // + method_printer{ctx, "remove"} + .parameter("ecsact_component_like_id", "component_id") + .return_type("void final"); + + context_remove_impl(ctx, sys_like_id_variant, details, view_type_name); +} + +auto ecsact::rt_entt_codegen::core::provider::association::print_other_ctx_get( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name +) -> void { + auto printer = // + method_printer{ctx, "get"} + .parameter("ecsact_component_like_id", "component_id") + .parameter("void*", "out_component_data") + .return_type("void final"); + + context_get_impl(ctx, sys_like_id_variant, details, view_type_name); +} + +auto ecsact::rt_entt_codegen::core::provider::association:: + print_other_ctx_update( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name + ) -> void { + auto printer = // + method_printer{ctx, "update"} + .parameter("ecsact_component_like_id", "component_id") + .parameter("const void*", "component_data") + .return_type("void final"); + + context_update_impl(ctx, sys_like_id_variant, details, view_type_name); +} + +auto ecsact::rt_entt_codegen::core::provider::association::print_other_ctx_has( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void { + auto printer = // + method_printer{ctx, "has"} + .parameter("ecsact_component_like_id", "component_id") + .return_type("bool final"); + + context_has_impl(ctx, sys_like_id_variant, details); +} + +auto ecsact::rt_entt_codegen::core::provider::association:: + print_other_ctx_generate( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ) -> void { + auto printer = // + method_printer{ctx, "generate"} + .parameter("int", "component_count") + .parameter("ecsact_component_id*", "component_ids") + .parameter("const void**", "components_data") + .return_type("void final"); + + context_generate_impl(ctx, sys_like_id_variant, details); +} + +auto ecsact::rt_entt_codegen::core::provider::association:: + print_other_ctx_parent( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::system_like_id_variant& sys_like_id_variant + ) -> void { + auto printer = // + method_printer{ctx, "parent"} // + .return_type("const ecsact_system_execution_context* final"); + + context_parent_impl(ctx, sys_like_id_variant); +} + +auto ecsact::rt_entt_codegen::core::provider::association::print_other_ctx_other( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void { + auto printer = // + method_printer{ctx, "other"} + .parameter("ecsact_entity_id", "entity") + .return_type("ecsact_system_execution_context* final"); + + context_other_impl(ctx, sys_like_id_variant, details); +} diff --git a/rt_entt_codegen/core/system_provider/association/association.hh b/rt_entt_codegen/core/system_provider/association/association.hh index ae6c438..601e565 100644 --- a/rt_entt_codegen/core/system_provider/association/association.hh +++ b/rt_entt_codegen/core/system_provider/association/association.hh @@ -7,21 +7,19 @@ #include "rt_entt_codegen/core/sys_exec/sys_exec.hh" namespace ecsact::rt_entt_codegen::core::provider { -class association : system_provider { +class association : public system_provider { +public: using system_provider::system_provider; -public: auto initialization( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void { } auto before_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options, std::vector& additional_view_components @@ -29,22 +27,19 @@ public: } auto after_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void final; auto context_function_header( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void final; auto context_function_action( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -52,8 +47,7 @@ public: } auto context_function_add( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -61,8 +55,7 @@ public: } auto context_function_remove( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -70,8 +63,7 @@ public: } auto context_function_get( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -79,8 +71,7 @@ public: } auto context_function_update( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -88,8 +79,7 @@ public: } auto context_function_has( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -97,8 +87,7 @@ public: } auto context_function_generate( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -106,8 +95,7 @@ public: } auto context_function_parent( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide { @@ -115,48 +103,41 @@ public: } auto context_function_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide final; auto pre_entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void final; auto entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void { } auto pre_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void final; auto system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> handle_exclusive_provide final; auto post_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void {}; auto post_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void {}; @@ -167,10 +148,53 @@ private: std::map components_with_entity_fields; auto print_other_contexts( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + ecsact::codegen_plugin_context& ctx, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& options ) -> void; + + auto print_other_ctx_action(ecsact::codegen_plugin_context& ctx) -> void; + auto print_other_ctx_add( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ) -> void; + + auto print_other_ctx_remove( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name + ) -> void; + + auto print_other_ctx_get( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name + ) -> void; + + auto print_other_ctx_update( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name + ) -> void; + + auto print_other_ctx_has( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ) -> void; + + auto print_other_ctx_generate( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ) -> void; + + auto print_other_ctx_parent( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant + ) -> void; + + auto print_other_ctx_other( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details + ) -> void; }; } // 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 index cf5ce68..af735f0 100644 --- a/rt_entt_codegen/core/system_provider/basic/basic.cc +++ b/rt_entt_codegen/core/system_provider/basic/basic.cc @@ -4,15 +4,19 @@ #include "ecsact/lang-support/lang-cc.hh" #include "rt_entt_codegen/shared/util.hh" #include "ecsact/cpp_codegen_plugin_util.hh" +#include "rt_entt_codegen/core/system_provider/system_ctx_functions.hh" -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::util::is_transient_component; +using ecsact::rt_entt_codegen::provider::context_action_impl; +using ecsact::rt_entt_codegen::provider::context_add_impl; +using ecsact::rt_entt_codegen::provider::context_generate_impl; +using ecsact::rt_entt_codegen::provider::context_get_impl; +using ecsact::rt_entt_codegen::provider::context_has_impl; +using ecsact::rt_entt_codegen::provider::context_parent_impl; +using ecsact::rt_entt_codegen::provider::context_remove_impl; +using ecsact::rt_entt_codegen::provider::context_update_impl; auto ecsact::rt_entt_codegen::core::provider::basic::initialization( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { sys_caps = @@ -21,409 +25,76 @@ auto ecsact::rt_entt_codegen::core::provider::basic::initialization( view_type_name = "view"; } +auto ecsact::rt_entt_codegen::core::provider::basic::context_function_header( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names +) -> void { + if(names.action_var_name) { + ctx.write("const void* action_data = nullptr;\n"); + } +} + auto ecsact::rt_entt_codegen::core::provider::basic::context_function_action( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - if(sys_like_id_variant.is_action()) { - auto action_name = - cpp_identifier(decl_full_name(sys_like_id_variant.get_sys_like_id())); - - ctx.write( - "*static_cast<", - action_name, - "*>(out_action_data) = *static_cast(action_data);\n" - ); - } else { - // TODO(Kelwan): Trying to access .action() without a valid action - ctx.write("\n"); - } + context_action_impl(ctx, sys_like_id_variant); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::basic::context_function_add( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { auto adds_comps = std::vector{}; - - for(auto&& [comp_id, sys_cap] : sys_caps) { - if(is_transient_component(ctx.package_id, comp_id)) { - continue; - } - if((ECSACT_SYS_CAP_ADDS & sys_cap) == ECSACT_SYS_CAP_ADDS) { - adds_comps.push_back(comp_id); - } - } - - if(adds_comps.empty()) { - // TODO(Kelwan): Handle unexpected behaviour - return HANDLED; - } else if(adds_comps.size() == 1) { - const auto& comp_id = adds_comps.front(); - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "wrapper::dynamic::context_add<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id),", - "component_data); \n" - ); - return HANDLED; - } - block( - ctx, - "static const auto add_fns = " - "std::unordered_map", - [&] { - for(int i = 0; i < adds_comps.size(); ++i) { - const auto comp_id = adds_comps[i]; - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "{", - "ecsact_id_cast(", - type_name, - "::id), ", - "&wrapper::dynamic::context_add<::", - type_name, - "> }," - ); - } - } - ); - - ctx.write(";\n"); - - ctx.write("add_fns.at(component_id)(this, component_id, component_data);\n"); - + context_add_impl(ctx, sys_like_id_variant); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::basic::context_function_remove( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - auto remove_comps = std::vector{}; - - for(auto&& [comp_id, sys_cap] : sys_caps) { - if(is_transient_component(ctx.package_id, comp_id)) { - continue; - } - if((ECSACT_SYS_CAP_REMOVES & sys_cap) == ECSACT_SYS_CAP_REMOVES) { - remove_comps.push_back(comp_id); - } - } - - if(remove_comps.size() == 0) { - // TODO(Kelwan): Handle unexpected behaviour - return HANDLED; - } - if(remove_comps.size() == 1) { - const auto& comp_id = remove_comps.front(); - - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "wrapper::dynamic::context_remove<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id), *view);\n" - ); - return HANDLED; - } - ctx.write(std::format( - "using remove_fn_t = void (*)(ecsact_system_execution_context*, " - "ecsact_component_like_id, {}_t&);\n", - view_type_name - )); - - ctx.write("static const auto remove_fns = []()\n"); - - block(ctx, "", [&] { - ctx.write( - "auto result = std::unordered_map{};\n" - ); - for(const auto comp_id : details.removable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result[ecsact_id_cast(", - type_name, - "::id)] = &wrapper::dynamic::context_remove<", - type_name, - ">;\n" - ); - } - - ctx.write("return result;\n"); - }); - ctx.write("();\n"); + context_remove_impl(ctx, sys_like_id_variant, system_details, view_type_name); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::basic::context_function_get( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - if(details.readable_comps.size() == 0) { - return HANDLED; - } - - std::vector get_components; - - for(auto comp_id : details.readable_comps) { - if(is_transient_component(ctx.package_id, comp_id)) { - continue; - } - get_components.insert(get_components.end(), comp_id); - } - - if(get_components.size() == 0) { - return HANDLED; - } - - // Shortcut - ignore component ID because we only have 1 - if(details.get_comps.size() == 1 && details.readable_comps.size() == 1) { - auto comp_id = *details.get_comps.begin(); - auto cpp_comp_full_name = cpp_identifier(decl_full_name(comp_id)); - - ctx.write( - "assert(ecsact_id_cast(::", - cpp_comp_full_name, - "::id) == component_id);\n" - ); - ctx.write( - "*static_cast<::", - cpp_comp_full_name, - "*>(out_component_data) = view->get<::", - cpp_comp_full_name, - ">(entity);" - ); - return HANDLED; - } - - ctx.write(std::format( - "using get_fn_t = void (*)(ecsact_system_execution_context*, " - "ecsact_component_like_id, void *, {}_t&);\n", - view_type_name - )); - - ctx.write("static const auto get_fns = []()\n"); - - block(ctx, "", [&] { - ctx.write( - "auto result = std::unordered_map{};\n" - ); - for(const auto comp_id : details.readable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result[ecsact_id_cast(", - type_name, - "::id)] = &wrapper::dynamic::context_get<", - type_name, - ">;\n" - ); - } - - ctx.write("return result;\n"); - }); - ctx.write("();\n"); - - ctx.write( - "get_fns.at(component_id)(this, component_id, out_component_data, *view);\n" - ); - + context_get_impl(ctx, sys_like_id_variant, system_details, view_type_name); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::basic::context_function_update( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - if(details.writable_comps.size() == 0) { - return HANDLED; - } - - if(details.writable_comps.size() == 1) { - const auto& comp_id = *details.writable_comps.begin(); - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "wrapper::dynamic::context_update<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id),", - "component_data, *view); \n" - ); - return HANDLED; - } - - ctx.write(std::format( - "using update_fn_t = void (*)(ecsact_system_execution_context*, " - "ecsact_component_like_id, const void *, {}_t&);\n", - view_type_name - )); - - ctx.write("static const auto update_fns = []()\n"); - - block(ctx, "", [&] { - ctx.write( - "auto result = std::unordered_map{};\n" - ); - for(const auto comp_id : details.writable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result[ecsact_id_cast(", - type_name, - "::id)] = &wrapper::dynamic::context_update<", - type_name, - ">;\n" - ); - } - - ctx.write("return result;\n"); - }); - ctx.write("();\n"); - - ctx.write( - "update_fns.at(component_id)(this, component_id, component_data, " - "*view);\n" - ); - + context_update_impl(ctx, sys_like_id_variant, system_details, view_type_name); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::basic::context_function_has( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - if(details.writable_comps.size() == 0) { - ctx.write("return false;"); - return HANDLED; - } - - if(details.writable_comps.size() == 1) { - const auto& comp_id = *details.writable_comps.begin(); - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "return wrapper::dynamic::context_has<::", - type_name, - ">(this, ecsact_id_cast(", - type_name, - "::id));\n" - ); - } - block( - ctx, - "static const auto has_fns = " - "std::unordered_map", - [&] { - for(const auto comp_id : details.readable_comps) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "{ecsact_id_cast(", - type_name, - "::id), &wrapper::dynamic::context_has<", - type_name, - "> }," - ); - } - } - ); - ctx.write(";\n"); - - ctx.write("return has_fns.at(component_id)(this, component_id);\n"); - + context_has_impl(ctx, sys_like_id_variant, system_details); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::basic::context_function_generate( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - if(details.generate_comps.size() == 0) { - // TODO (Kelwan): Handle undefined behaviour - return HANDLED; - } - block( - ctx, - "static const auto generate_fns = " - "std::unordered_map", - [&] { - for(const auto& component : details.generate_comps) { - for(const auto& [comp_id, requirements] : component) { - auto type_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "{", - type_name, - "::id, &wrapper::dynamic::context_generate_add<", - type_name, - "> }," - ); - } - } - } - ); - ctx.write(";\n"); - - // NOTE(Kelwan): Multiple generates blocks are allowed in Ecsact systems but - // currently the interpreter won't allow this. More testing required after the - // issue is resolved https://github.com/ecsact-dev/ecsact_interpret/issues/185 - ctx.write("auto entity = registry->create();\n"); - - ctx.write( - "registry->template emplace(entity, " - "ecsact_generated_entity);\n" - ); - - block(ctx, "for(int i = 0; i < component_count; ++i)", [&] { - ctx.write("const auto component_id = component_ids[i];\n"); - ctx.write("const void* component_data = components_data[i];\n"); - - ctx.write( - "generate_fns.at(component_id)(this, component_id, " - "component_data, entity);\n" - ); - }); - + context_generate_impl(ctx, sys_like_id_variant, system_details); return HANDLED; } auto ecsact::rt_entt_codegen::core::provider::basic::context_function_parent( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { - if(details.association_details.size() == 0) { - // TODO(Kelwan): Handle undefined behaviour - // Attempt to access other without association - - ctx.write("return nullptr;"); - return HANDLED; - } - - ctx.write( - "if(other_contexts.contains(entity)) {\n", - "return other_contexts.at(entity);\n}\n" - ); - // NOTE(Kelwan): Maybe we handle undefined behaviour here too - ctx.write("return nullptr;"); - + context_parent_impl(ctx, sys_like_id_variant); return HANDLED; } diff --git a/rt_entt_codegen/core/system_provider/basic/basic.hh b/rt_entt_codegen/core/system_provider/basic/basic.hh index cdaead6..7540900 100644 --- a/rt_entt_codegen/core/system_provider/basic/basic.hh +++ b/rt_entt_codegen/core/system_provider/basic/basic.hh @@ -8,124 +8,109 @@ namespace ecsact::rt_entt_codegen::core::provider { -class basic : system_provider { +class basic : public system_provider { +public: using system_provider::system_provider; -public: auto initialization( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void final; auto before_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options, + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, std::vector& additional_view_components - ) -> void = 0; + ) -> void { + } auto after_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options - ) -> void = 0; + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names + ) -> void { + } + + auto context_function_header( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names + ) -> void final; auto context_function_action( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_add( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_remove( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_get( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_update( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_has( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_generate( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_parent( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide final; auto context_function_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } + auto pre_entity_iteration( + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names + ) -> void { + } + auto entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options - ) -> void = 0; + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names + ) -> void { + } + auto pre_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options - ) -> void = 0; + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names + ) -> void { + } auto system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto post_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options - ) -> void = 0; + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names + ) -> void { + } + auto post_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options - ) -> void = 0; + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names + ) -> void { + } private: std::unordered_map diff --git a/rt_entt_codegen/core/system_provider/lazy/lazy.cc b/rt_entt_codegen/core/system_provider/lazy/lazy.cc index 965bdb5..bd2a989 100644 --- a/rt_entt_codegen/core/system_provider/lazy/lazy.cc +++ b/rt_entt_codegen/core/system_provider/lazy/lazy.cc @@ -13,7 +13,6 @@ using ecsact::meta::decl_full_name; auto ecsact::rt_entt_codegen::core::provider::lazy::initialization( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { auto system_name = @@ -43,7 +42,6 @@ auto ecsact::rt_entt_codegen::core::provider::lazy::initialization( auto ecsact::rt_entt_codegen::core::provider::lazy::before_make_view_or_group( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, std::vector& additional_view_components ) -> void { @@ -67,7 +65,6 @@ auto ecsact::rt_entt_codegen::core::provider::lazy::before_make_view_or_group( auto ecsact::rt_entt_codegen::core::provider::lazy::after_make_view_or_group( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { if(sys_like_id_variant.is_system()) { @@ -79,7 +76,6 @@ auto ecsact::rt_entt_codegen::core::provider::lazy::after_make_view_or_group( auto ecsact::rt_entt_codegen::core::provider::lazy::pre_exec_system_impl( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { using ecsact::cpp_codegen_plugin_util::block; @@ -101,7 +97,6 @@ auto ecsact::rt_entt_codegen::core::provider::lazy::pre_exec_system_impl( auto ecsact::rt_entt_codegen::core::provider::lazy::post_exec_system_impl( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { using ecsact::cpp_codegen_plugin_util::block; @@ -134,7 +129,7 @@ auto ecsact::rt_entt_codegen::core::provider::lazy::post_exec_system_impl( ctx, "view_no_pending_lazy_", names.registry_var_name, - details + system_details ); ctx.write("auto view_no_pending_lazy_count_ = 0;\n"); diff --git a/rt_entt_codegen/core/system_provider/lazy/lazy.hh b/rt_entt_codegen/core/system_provider/lazy/lazy.hh index 4413e35..c6d254d 100644 --- a/rt_entt_codegen/core/system_provider/lazy/lazy.hh +++ b/rt_entt_codegen/core/system_provider/lazy/lazy.hh @@ -4,178 +4,136 @@ #include #include "rt_entt_codegen/core/sys_exec/sys_exec.hh" +#include "rt_entt_codegen/shared/ecsact_entt_details.hh" #include "rt_entt_codegen/core/system_provider/system_provider.hh" namespace ecsact::rt_entt_codegen::core::provider { -class lazy : system_provider { - using system_provider::system_provider; - +class lazy : public system_provider { public: - lazy(system_like_id_variant sys_like_id_variant); - // Default init to 0 lazy_it_rate + using system_provider::system_provider; auto initialization( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void final; auto before_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options, + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, std::vector& additional_view_components ) -> void final; auto after_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void final; auto context_function_header( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto context_function_action( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_add( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_remove( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_get( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_update( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_has( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_generate( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_parent( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto pre_entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto pre_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void final; auto system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto post_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void final; auto post_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } private: - const system_like_id_variant sys_like_id_variant; - std::string exec_start_label_name; std::string pending_lazy_exec_struct; std::string system_sorting_struct_name; diff --git a/rt_entt_codegen/core/system_provider/notify/notify.cc b/rt_entt_codegen/core/system_provider/notify/notify.cc index cf16188..3bda6d5 100644 --- a/rt_entt_codegen/core/system_provider/notify/notify.cc +++ b/rt_entt_codegen/core/system_provider/notify/notify.cc @@ -7,34 +7,35 @@ #include "rt_entt_codegen/shared/system_util.hh" #include "ecsact/runtime/meta.hh" #include "ecsact/cpp_codegen_plugin_util.hh" -#include "rt_entt_codegen/shared//ecsact_entt_details.hh" auto ecsact::rt_entt_codegen::core::provider::notify::before_make_view_or_group( ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, std::vector& additional_view_components ) -> void { + using ecsact::cc_lang_support::cpp_identifier; + using ecsact::meta::decl_full_name; using ecsact::rt_entt_codegen::system_util::is_notify_system; - if(is_notify_system(options.sys_like_id_variant.get_sys_like_id())) { + auto system_name = + cpp_identifier(decl_full_name(sys_like_id_variant.get_sys_like_id())); + + if(is_notify_system(sys_like_id_variant.get_sys_like_id())) { additional_view_components.push_back( - std::format("ecsact::entt::detail::run_system<{}>", options.system_name) + std::format("ecsact::entt::detail::run_system<{}>", system_name) ); print_system_notify_views( ctx, - details, - options.sys_like_id_variant.get_sys_like_id(), - options.registry_var_name + sys_like_id_variant.get_sys_like_id(), + names.registry_var_name ); } } auto ecsact::rt_entt_codegen::core::provider::notify::print_system_notify_views( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - ecsact_system_like_id system_id, - std::string registry_name + ecsact::codegen_plugin_context& ctx, + ecsact_system_like_id system_id, + std::string registry_name ) -> void { using ecsact::cc_lang_support::c_identifier; using ecsact::cc_lang_support::cpp_identifier; @@ -96,7 +97,7 @@ auto ecsact::rt_entt_codegen::core::provider::notify::print_system_notify_views( ctx, view_name, registry_name, - details, + system_details, std::vector{pending_add_str}, std::vector{run_system_comp} ); @@ -118,7 +119,7 @@ auto ecsact::rt_entt_codegen::core::provider::notify::print_system_notify_views( ctx, view_name, registry_name, - details, + system_details, std::vector{pending_remove_str}, std::vector{run_system_comp} ); @@ -140,7 +141,7 @@ auto ecsact::rt_entt_codegen::core::provider::notify::print_system_notify_views( ctx, view_name, registry_name, - details, + system_details, std::vector{component_updated_str}, std::vector{run_system_comp} ); @@ -164,7 +165,7 @@ auto ecsact::rt_entt_codegen::core::provider::notify::print_system_notify_views( ctx, view_name, registry_name, - details, + system_details, std::vector{exec_itr_onchange_str}, std::vector{run_system_comp} ); diff --git a/rt_entt_codegen/core/system_provider/notify/notify.hh b/rt_entt_codegen/core/system_provider/notify/notify.hh index cb868a5..7018589 100644 --- a/rt_entt_codegen/core/system_provider/notify/notify.hh +++ b/rt_entt_codegen/core/system_provider/notify/notify.hh @@ -2,172 +2,133 @@ #include "rt_entt_codegen/core/system_provider/system_provider.hh" #include "rt_entt_codegen/core/sys_exec/sys_exec.hh" -#include "rt_entt_codegen/shared/ecsact_entt_details.hh" namespace ecsact::rt_entt_codegen::core::provider { -class notify : system_provider { +class notify : public system_provider { +public: using system_provider::system_provider; -public: auto initialization( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto before_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options, + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, std::vector& additional_view_components ) -> void final; auto after_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto context_function_header( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto context_function_action( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_add( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_remove( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_get( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_update( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_has( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_generate( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_parent( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto context_function_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto pre_entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto pre_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide { return NOT_HANDLED; } auto post_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } auto post_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void { } @@ -176,10 +137,9 @@ private: * Prints the specialized views for ecsact_system_notify_settings components */ auto print_system_notify_views( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - ecsact_system_like_id system_id, - std::string registry_name + ecsact::codegen_plugin_context& ctx, + ecsact_system_like_id system_id, + std::string registry_name ) -> void; }; } // namespace ecsact::rt_entt_codegen::core::provider diff --git a/rt_entt_codegen/core/system_provider/system_ctx_functions.cc b/rt_entt_codegen/core/system_provider/system_ctx_functions.cc new file mode 100644 index 0000000..92198e9 --- /dev/null +++ b/rt_entt_codegen/core/system_provider/system_ctx_functions.cc @@ -0,0 +1,416 @@ +#include "system_ctx_functions.hh" + +#include "ecsact/runtime/meta.hh" +#include "ecsact/lang-support/lang-cc.hh" +#include "ecsact/cpp_codegen_plugin_util.hh" +#include "rt_entt_codegen/shared/util.hh" + +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::util::is_transient_component; + +auto ecsact::rt_entt_codegen::provider::context_action_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant +) -> void { + if(sys_like_id_variant.is_action()) { + auto action_name = + cpp_identifier(decl_full_name(sys_like_id_variant.get_sys_like_id())); + + ctx.write( + "*static_cast<", + action_name, + "*>(out_action_data) = *static_cast(action_data);\n" + ); + } else { + // TODO(Kelwan): Trying to access .action() without a valid action + ctx.write("\n"); + } +} + +auto ecsact::rt_entt_codegen::provider::context_add_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant +) -> void { + auto adds_comps = std::vector{}; + + auto sys_caps = + ecsact::meta::system_capabilities(sys_like_id_variant.get_sys_like_id()); + + for(auto&& [comp_id, sys_cap] : sys_caps) { + if(is_transient_component(ctx.package_id, comp_id)) { + continue; + } + if((ECSACT_SYS_CAP_ADDS & sys_cap) == ECSACT_SYS_CAP_ADDS) { + adds_comps.push_back(comp_id); + } + } + + if(adds_comps.empty()) { + // TODO(Kelwan): Handle unexpected behaviour + return; + } else if(adds_comps.size() == 1) { + const auto& comp_id = adds_comps.front(); + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "wrapper::dynamic::context_add<::", + type_name, + ">(this, ecsact_id_cast(", + type_name, + "::id),", + "component_data); \n" + ); + return; + } + block( + ctx, + "static const auto add_fns = " + "std::unordered_map", + [&] { + for(int i = 0; i < adds_comps.size(); ++i) { + const auto comp_id = adds_comps[i]; + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "{", + "ecsact_id_cast(", + type_name, + "::id), ", + "&wrapper::dynamic::context_add<::", + type_name, + "> }," + ); + } + } + ); + + ctx.write(";\n"); + + ctx.write("add_fns.at(component_id)(this, component_id, component_data);\n"); +} + +auto ecsact::rt_entt_codegen::provider::context_remove_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name +) -> void { + auto remove_comps = std::vector{}; + + auto sys_caps = + ecsact::meta::system_capabilities(sys_like_id_variant.get_sys_like_id()); + + for(auto&& [comp_id, sys_cap] : sys_caps) { + if(is_transient_component(ctx.package_id, comp_id)) { + continue; + } + if((ECSACT_SYS_CAP_REMOVES & sys_cap) == ECSACT_SYS_CAP_REMOVES) { + remove_comps.push_back(comp_id); + } + } + + if(remove_comps.size() == 0) { + // TODO(Kelwan): Handle unexpected behaviour + return; + } + if(remove_comps.size() == 1) { + const auto& comp_id = remove_comps.front(); + + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "wrapper::dynamic::context_remove<::", + type_name, + ">(this, ecsact_id_cast(", + type_name, + "::id), *view);\n" + ); + return; + } + ctx.write(std::format( + "using remove_fn_t = void (*)(ecsact_system_execution_context*, " + "ecsact_component_like_id, {}_t&);\n", + view_type_name + )); + + ctx.write("static const auto remove_fns = []()\n"); + + block(ctx, "", [&] { + ctx.write( + "auto result = std::unordered_map{};\n" + ); + for(const auto comp_id : details.removable_comps) { + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "result[ecsact_id_cast(", + type_name, + "::id)] = &wrapper::dynamic::context_remove<", + type_name, + ">;\n" + ); + } + + ctx.write("return result;\n"); + }); + ctx.write("();\n"); +} + +auto ecsact::rt_entt_codegen::provider::context_get_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name +) -> void { + if(details.readable_comps.size() == 0) { + return; + } + + std::vector get_components; + + for(auto comp_id : details.readable_comps) { + if(is_transient_component(ctx.package_id, comp_id)) { + continue; + } + get_components.insert(get_components.end(), comp_id); + } + + if(get_components.size() == 0) { + return; + } + + // Shortcut - ignore component ID because we only have 1 + if(details.get_comps.size() == 1 && details.readable_comps.size() == 1) { + auto comp_id = *details.get_comps.begin(); + auto cpp_comp_full_name = cpp_identifier(decl_full_name(comp_id)); + + ctx.write( + "assert(ecsact_id_cast(::", + cpp_comp_full_name, + "::id) == component_id);\n" + ); + ctx.write( + "*static_cast<::", + cpp_comp_full_name, + "*>(out_component_data) = view->get<::", + cpp_comp_full_name, + ">(entity);" + ); + return; + } + + ctx.write(std::format( + "using get_fn_t = void (*)(ecsact_system_execution_context*, " + "ecsact_component_like_id, void *, {}_t&);\n", + view_type_name + )); + + ctx.write("static const auto get_fns = []()\n"); + + block(ctx, "", [&] { + ctx.write( + "auto result = std::unordered_map{};\n" + ); + for(const auto comp_id : details.readable_comps) { + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "result[ecsact_id_cast(", + type_name, + "::id)] = &wrapper::dynamic::context_get<", + type_name, + ">;\n" + ); + } + + ctx.write("return result;\n"); + }); + ctx.write("();\n"); + + ctx.write( + "get_fns.at(component_id)(this, component_id, out_component_data, *view);\n" + ); +} + +auto ecsact::rt_entt_codegen::provider::context_update_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name +) -> void { + if(details.writable_comps.size() == 0) { + return; + } + + if(details.writable_comps.size() == 1) { + const auto& comp_id = *details.writable_comps.begin(); + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "wrapper::dynamic::context_update<::", + type_name, + ">(this, ecsact_id_cast(", + type_name, + "::id),", + "component_data, *view); \n" + ); + return; + } + + ctx.write(std::format( + "using update_fn_t = void (*)(ecsact_system_execution_context*, " + "ecsact_component_like_id, const void *, {}_t&);\n", + view_type_name + )); + + ctx.write("static const auto update_fns = []()\n"); + + block(ctx, "", [&] { + ctx.write( + "auto result = std::unordered_map{};\n" + ); + for(const auto comp_id : details.writable_comps) { + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "result[ecsact_id_cast(", + type_name, + "::id)] = &wrapper::dynamic::context_update<", + type_name, + ">;\n" + ); + } + + ctx.write("return result;\n"); + }); + ctx.write("();\n"); + + ctx.write( + "update_fns.at(component_id)(this, component_id, component_data, " + "*view);\n" + ); +} + +auto ecsact::rt_entt_codegen::provider::context_has_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void { + if(details.writable_comps.size() == 0) { + ctx.write("return false;"); + return; + } + + if(details.writable_comps.size() == 1) { + const auto& comp_id = *details.writable_comps.begin(); + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "return wrapper::dynamic::context_has<::", + type_name, + ">(this, ecsact_id_cast(", + type_name, + "::id));\n" + ); + } + block( + ctx, + "static const auto has_fns = " + "std::unordered_map", + [&] { + for(const auto comp_id : details.readable_comps) { + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "{ecsact_id_cast(", + type_name, + "::id), &wrapper::dynamic::context_has<", + type_name, + "> }," + ); + } + } + ); + ctx.write(";\n"); + + ctx.write("return has_fns.at(component_id)(this, component_id);\n"); +} + +auto ecsact::rt_entt_codegen::provider::context_generate_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void { + if(details.generate_comps.size() == 0) { + // TODO (Kelwan): Handle undefined behaviour + return; + } + block( + ctx, + "static const auto generate_fns = " + "std::unordered_map", + [&] { + for(const auto& component : details.generate_comps) { + for(const auto& [comp_id, requirements] : component) { + auto type_name = cpp_identifier(decl_full_name(comp_id)); + ctx.write( + "{", + type_name, + "::id, &wrapper::dynamic::context_generate_add<", + type_name, + "> }," + ); + } + } + } + ); + ctx.write(";\n"); + + // NOTE(Kelwan): Multiple generates blocks are allowed in Ecsact systems but + // currently the interpreter won't allow this. More testing required after the + // issue is resolved https://github.com/ecsact-dev/ecsact_interpret/issues/185 + ctx.write("auto entity = registry->create();\n"); + + ctx.write( + "registry->template emplace(entity, " + "ecsact_generated_entity);\n" + ); + + block(ctx, "for(int i = 0; i < component_count; ++i)", [&] { + ctx.write("const auto component_id = component_ids[i];\n"); + ctx.write("const void* component_data = components_data[i];\n"); + + ctx.write( + "generate_fns.at(component_id)(this, component_id, " + "component_data, entity);\n" + ); + }); +} + +auto ecsact::rt_entt_codegen::provider::context_parent_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant +) -> void { + ctx.write("return this->parent_ctx;\n"); +} + +auto ecsact::rt_entt_codegen::provider::context_other_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void { + if(details.association_details.size() == 0) { + // TODO(Kelwan): Handle undefined behaviour + // Attempt to access other without association + + ctx.write("return nullptr;"); + return; + } + + ctx.write( + "if(other_contexts.contains(entity)) {\n", + "return other_contexts.at(entity);\n}\n" + ); +} diff --git a/rt_entt_codegen/core/system_provider/system_ctx_functions.hh b/rt_entt_codegen/core/system_provider/system_ctx_functions.hh new file mode 100644 index 0000000..a8d833d --- /dev/null +++ b/rt_entt_codegen/core/system_provider/system_ctx_functions.hh @@ -0,0 +1,53 @@ +#pragma once + +#include "rt_entt_codegen/core/sys_exec/sys_exec.hh" +#include "rt_entt_codegen/shared/ecsact_entt_details.hh" +#include "rt_entt_codegen/shared/system_variant.hh" + +namespace ecsact::rt_entt_codegen::provider { +auto context_action_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant +) -> void; +auto context_add_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant +) -> void; +auto context_remove_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name +) -> void; +auto context_get_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name +) -> void; +auto context_update_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, + const std::string& view_type_name +) -> void; +auto context_has_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void; +auto context_generate_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void; +auto context_parent_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant +) -> void; +auto context_other_impl( + ecsact::codegen_plugin_context& ctx, + const system_like_id_variant& sys_like_id_variant, + const ecsact::rt_entt_codegen::ecsact_entt_system_details& details +) -> void; +} // namespace ecsact::rt_entt_codegen::provider diff --git a/rt_entt_codegen/core/system_provider/system_provider.cc b/rt_entt_codegen/core/system_provider/system_provider.cc index 768fb9e..2106e9a 100644 --- a/rt_entt_codegen/core/system_provider/system_provider.cc +++ b/rt_entt_codegen/core/system_provider/system_provider.cc @@ -1,7 +1,15 @@ #include "system_provider.hh" ecsact::rt_entt_codegen::core::provider::system_provider::system_provider( - system_like_id_variant sys_like_id_variant -) { - sys_like_id_variant = sys_like_id_variant; + system_like_id_variant id +) + : sys_like_id_variant(id) { + system_details = ecsact_entt_system_details::from_system_like( + sys_like_id_variant.get_sys_like_id() + ); + + assert(sys_like_id_variant != system_like_id_variant{}); } + +ecsact::rt_entt_codegen::core::provider::system_provider::~system_provider() = + default; diff --git a/rt_entt_codegen/core/system_provider/system_provider.hh b/rt_entt_codegen/core/system_provider/system_provider.hh index 7b4d126..cdb93a8 100644 --- a/rt_entt_codegen/core/system_provider/system_provider.hh +++ b/rt_entt_codegen/core/system_provider/system_provider.hh @@ -4,8 +4,9 @@ #include #include -#include "rt_entt_codegen/shared/ecsact_entt_details.hh" #include "rt_entt_codegen/core/sys_exec/sys_exec.hh" +#include "rt_entt_codegen/shared/system_variant.hh" +#include "rt_entt_codegen/shared/ecsact_entt_details.hh" namespace ecsact::rt_entt_codegen::core::provider { enum handle_exclusive_provide { @@ -13,160 +14,95 @@ enum handle_exclusive_provide { NOT_HANDLED = 1, }; -struct system_like_id_variant - : std::variant { - using variant::variant; - - auto as_system() const -> ecsact_system_id { - return std::get(*this); - } - - auto as_action() const -> ecsact_action_id { - return std::get(*this); - } - - auto is_system() const -> bool { - return std::holds_alternative(*this); - } - - auto is_action() const -> bool { - return std::holds_alternative(*this); - } - - auto get_sys_like_id() const -> ecsact_system_like_id { - return std::visit( - [](auto&& arg) { return static_cast(arg); }, - *this - ); - } -}; - class system_provider { public: system_provider(system_like_id_variant sys_like_id_variant); + virtual ~system_provider(); -protected: - system_like_id_variant sys_like_id_variant; - -private: virtual auto initialization( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; virtual auto before_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options, + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names, std::vector& additional_view_components ) -> void = 0; virtual auto after_make_view_or_group( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; virtual auto context_function_header( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; virtual auto context_function_action( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_add( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_remove( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_get( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_update( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_has( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_generate( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_parent( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto context_function_other( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto pre_entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; virtual auto entity_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; virtual auto pre_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; virtual auto system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> handle_exclusive_provide = 0; virtual auto post_exec_system_impl( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; virtual auto post_iteration( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_system_details& details, - const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& - options + ecsact::codegen_plugin_context& ctx, + const ecsact::rt_entt_codegen::core::print_execute_systems_var_names& names ) -> void = 0; + +protected: + system_like_id_variant sys_like_id_variant; + ecsact_entt_system_details system_details; }; } // namespace ecsact::rt_entt_codegen::core::provider diff --git a/rt_entt_codegen/shared/BUILD.bazel b/rt_entt_codegen/shared/BUILD.bazel index 40dc655..0147e6b 100644 --- a/rt_entt_codegen/shared/BUILD.bazel +++ b/rt_entt_codegen/shared/BUILD.bazel @@ -77,6 +77,16 @@ cc_library( copts = copts, deps = [ ":ecsact_entt_details", + "//rt_entt_codegen/shared:system_variant", "@ecsact_lang_cpp//:cpp_codegen_plugin_util", ], ) + +cc_library( + name = "system_variant", + hdrs = ["system_variant.hh"], + copts = copts, + deps = [ + "@ecsact_runtime//:common", + ], +) diff --git a/rt_entt_codegen/shared/parallel.cc b/rt_entt_codegen/shared/parallel.cc index 627a3c9..d45c36d 100644 --- a/rt_entt_codegen/shared/parallel.cc +++ b/rt_entt_codegen/shared/parallel.cc @@ -6,24 +6,24 @@ #include "ecsact/lang-support/lang-cc.hh" #include "ecsact/cpp_codegen_plugin_util.hh" +#include "rt_entt_codegen/shared/system_variant.hh" +#include "system_variant.hh" + +using ecsact::rt_entt_codegen::system_like_id_variant; static auto loop_iterator( - const std::vector& system_list, - const std::vector::iterator begin, - std::vector>& parallel_system_cluster + const std::vector& system_list, + const std::vector::iterator begin, + std::vector>& parallel_system_cluster ) -> void; auto ecsact::rt_entt_codegen::parallel::get_parallel_execution_cluster( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_details& details, - std::vector system_list, - std::string parent_context -) -> std::vector> { - using ecsact::cc_lang_support::cpp_identifier; - using ecsact::cpp_codegen_plugin_util::block; - + ecsact::codegen_plugin_context& ctx, + std::vector system_list, + std::string parent_context +) -> std::vector> { auto parallel_system_cluster = - std::vector>{}; + std::vector>{}; loop_iterator(system_list, system_list.begin(), parallel_system_cluster); @@ -39,20 +39,23 @@ static auto is_capability_safe(ecsact_system_capability capability) -> bool { } static auto loop_iterator( - const std::vector& system_list, - const std::vector::iterator begin, - std::vector>& parallel_system_cluster + const std::vector& system_list, + const std::vector::iterator begin, + std::vector>& parallel_system_cluster ) -> void { - std::vector parallel_system_list; + std::vector parallel_system_list; auto unsafe_comps = std::set{}; using ecsact::meta::decl_full_name; for(auto iterator = begin; iterator != system_list.end(); iterator++) { - auto sys_like_id = *iterator; - auto capabilities = ecsact::meta::system_capabilities(sys_like_id); + auto sys_like_id_variant = *iterator; + auto capabilities = + ecsact::meta::system_capabilities(sys_like_id_variant.get_sys_like_id()); - auto generate_ids = ecsact::meta::get_system_generates_ids(sys_like_id); + auto generate_ids = ecsact::meta::get_system_generates_ids( + sys_like_id_variant.get_sys_like_id() + ); if(!generate_ids.empty()) { if(!parallel_system_list.empty()) { @@ -60,7 +63,7 @@ static auto loop_iterator( } parallel_system_cluster.push_back( - std::vector{sys_like_id} + std::vector{sys_like_id_variant} ); loop_iterator( system_list, @@ -72,7 +75,8 @@ static auto loop_iterator( std::set child_unsafe_comps{}; - auto child_systems = ecsact::meta::get_child_system_ids(sys_like_id); + auto child_systems = + ecsact::meta::get_child_system_ids(sys_like_id_variant.get_sys_like_id()); for(auto child_sys_id : child_systems) { auto cpp_system_name = decl_full_name(child_sys_id); @@ -121,12 +125,14 @@ static auto loop_iterator( } } - auto other_fields = - ecsact::meta::system_association_fields(sys_like_id, comp_id); + auto other_fields = ecsact::meta::system_association_fields( + sys_like_id_variant.get_sys_like_id(), + comp_id + ); for(auto field_id : other_fields) { auto other_capabilities = ecsact::meta::system_association_capabilities( - sys_like_id, + sys_like_id_variant.get_sys_like_id(), comp_id, field_id ); @@ -152,7 +158,71 @@ static auto loop_iterator( } } - parallel_system_list.push_back(sys_like_id); + parallel_system_list.push_back(sys_like_id_variant); } parallel_system_cluster.push_back(parallel_system_list); } + +auto ecsact::rt_entt_codegen::parallel::print_parallel_execution_cluster( + ecsact::codegen_plugin_context& ctx, + const std::vector>& + parallel_system_cluster +) -> void { + using ecsact::cc_lang_support::cpp_identifier; + + for(const auto& systems_to_parallel : parallel_system_cluster) { + if(systems_to_parallel.size() == 1) { + auto single_system_like_variant = systems_to_parallel.begin(); + + auto sync_sys_name = cpp_identifier(ecsact::meta::decl_full_name( + single_system_like_variant->get_sys_like_id() + )); + + if(single_system_like_variant->is_action()) { + ctx.write(std::format( + "ecsact::entt::execute_actions<{}>(registry, {}, " + "actions_map);\n", + sync_sys_name, + "nullptr" + )); + } + if(single_system_like_variant->is_system()) { + ctx.write(std::format( + "ecsact::entt::execute_system<{}>(registry, {}, " + "actions_map);\n", + sync_sys_name, + "nullptr" + )); + } + continue; + } + + ctx.write("execute_parallel_cluster(registry, nullptr, "); + ctx.write(std::format( + "std::array {{\n", + systems_to_parallel.size() + )); + for(const auto system_like_id_variant : systems_to_parallel) { + auto cpp_decl_name = cpp_identifier( + ecsact::meta::decl_full_name(system_like_id_variant.get_sys_like_id()) + ); + + if(system_like_id_variant.is_action()) { + ctx.write( + "\texec_entry_t{&ecsact::entt::execute_actions<", + cpp_decl_name, + ">, actions_map},\n" + ); + } else if(system_like_id_variant.is_system()) { + ctx.write( + "\texec_entry_t{&ecsact::entt::execute_system<", + cpp_decl_name, + ">, actions_map},\n" + ); + } else { + ctx.write("// ??? unhandled ??? ", cpp_decl_name, "\n"); + } + } + ctx.write("});\n"); + } +} diff --git a/rt_entt_codegen/shared/parallel.hh b/rt_entt_codegen/shared/parallel.hh index 13d39f8..e50d8e4 100644 --- a/rt_entt_codegen/shared/parallel.hh +++ b/rt_entt_codegen/shared/parallel.hh @@ -2,12 +2,18 @@ #include "ecsact/codegen/plugin.hh" #include "rt_entt_codegen/shared/ecsact_entt_details.hh" +#include "system_variant.hh" namespace ecsact::rt_entt_codegen::parallel { auto get_parallel_execution_cluster( - ecsact::codegen_plugin_context& ctx, - const ecsact::rt_entt_codegen::ecsact_entt_details& details, - std::vector system_list, - std::string parent_context = "nullptr" -) -> std::vector>; -} + ecsact::codegen_plugin_context& ctx, + std::vector system_list, + std::string parent_context = "nullptr" +) -> std::vector>; + +auto print_parallel_execution_cluster( + ecsact::codegen_plugin_context& ctx, + const std::vector>& + parallel_system_cluster +) -> void; +} // namespace ecsact::rt_entt_codegen::parallel diff --git a/rt_entt_codegen/shared/system_variant.hh b/rt_entt_codegen/shared/system_variant.hh new file mode 100644 index 0000000..f6082d0 --- /dev/null +++ b/rt_entt_codegen/shared/system_variant.hh @@ -0,0 +1,39 @@ +#pragma once + +#include + +#include "ecsact/runtime/common.h" + +namespace ecsact::rt_entt_codegen { +struct system_like_id_variant + : std::variant { + using variant::variant; + + // operator ecsact_system_like_id() const { + // return get_sys_like_id(); + // } + + auto as_system() const -> ecsact_system_id { + return std::get(*this); + } + + auto as_action() const -> ecsact_action_id { + return std::get(*this); + } + + auto is_system() const -> bool { + return std::holds_alternative(*this); + } + + auto is_action() const -> bool { + return std::holds_alternative(*this); + } + + auto get_sys_like_id() const -> ecsact_system_like_id { + return std::visit( + [](auto&& arg) { return ecsact_id_cast(arg); }, + *this + ); + } +}; +} // namespace ecsact::rt_entt_codegen diff --git a/test/codegen_test.nu b/test/codegen_test.nu index 3c1eff3..987ab46 100644 --- a/test/codegen_test.nu +++ b/test/codegen_test.nu @@ -7,5 +7,5 @@ let ecsact_cli = (bazel cquery @ecsact_cli --output=files | lines | get 0); let ecsact_files = (ls *.ecsact | each {|it| $it.name}); let plugin = $dir | path join (bazel cquery @ecsact_rt_entt//rt_entt_codegen --output=files | lines | get 0); -^$ecsact_cli codegen ...$ecsact_files -p $plugin -o $outdir; -# dbg launch $ecsact_cli codegen ...$ecsact_files -p $plugin -o $outdir; +# ^$ecsact_cli codegen ...$ecsact_files -p $plugin -o $outdir; +dbg launch $ecsact_cli codegen ...$ecsact_files -p $plugin -o $outdir;