|
| 1 | +#include "core.hh" |
| 2 | + |
| 3 | +#include "ecsact/lang-support/lang-cc.hh" |
| 4 | +#include "ecsact/cpp_codegen_plugin_util.hh" |
| 5 | +#include "rt_entt_codegen/shared/util.hh" |
| 6 | + |
| 7 | +auto ecsact::rt_entt_codegen::core::print_copy_components( |
| 8 | + ecsact::codegen_plugin_context& ctx, |
| 9 | + const ecsact::rt_entt_codegen::ecsact_entt_details& details |
| 10 | +) -> void { |
| 11 | + using ecsact::cc_lang_support::cpp_identifier; |
| 12 | + using ecsact::cpp_codegen_plugin_util::block; |
| 13 | + using ecsact::meta::decl_full_name; |
| 14 | + using ecsact::rt_entt_codegen::util::method_printer; |
| 15 | + |
| 16 | + auto printer = // |
| 17 | + method_printer{ctx, "ecsact::entt::copy_components"} |
| 18 | + .parameter("const ::entt::registry&", "src") |
| 19 | + .parameter("::entt::registry&", "dst") |
| 20 | + .return_type("void"); |
| 21 | + |
| 22 | + for(auto comp_id : details.all_components) { |
| 23 | + const auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); |
| 24 | + const auto is_tag = ecsact::meta::get_field_ids(comp_id).empty(); |
| 25 | + |
| 26 | + if(is_tag) { |
| 27 | + block( |
| 28 | + ctx, |
| 29 | + std::format("for(auto entity : src.view<{}>())", cpp_comp_name), |
| 30 | + [&] { ctx.writef("dst.emplace<{}>(entity);\n", cpp_comp_name); } |
| 31 | + ); |
| 32 | + } else { |
| 33 | + block( |
| 34 | + ctx, |
| 35 | + std::format( |
| 36 | + "for(auto&& [entity, comp] : src.view<{}>().each())", |
| 37 | + cpp_comp_name |
| 38 | + ), |
| 39 | + [&] { ctx.writef("dst.emplace<{}>(entity, comp);\n", cpp_comp_name); } |
| 40 | + ); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + for(auto sys_id : details.all_systems) { |
| 45 | + const auto system_name = cpp_identifier(decl_full_name(sys_id)); |
| 46 | + const auto pending_lazy_exec_struct = std::format( |
| 47 | + "::ecsact::entt::detail::pending_lazy_execution<::{}>", |
| 48 | + system_name |
| 49 | + ); |
| 50 | + block( |
| 51 | + ctx, |
| 52 | + std::format( |
| 53 | + "for(auto entity : src.view<{}>())", |
| 54 | + pending_lazy_exec_struct |
| 55 | + ), |
| 56 | + [&] { |
| 57 | + ctx.writef("dst.emplace<{}>(entity);\n", pending_lazy_exec_struct); |
| 58 | + } |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments