diff --git a/rt_entt_codegen/core/check_error.cc b/rt_entt_codegen/core/check_error.cc index 5b89137..5dc7ec1 100644 --- a/rt_entt_codegen/core/check_error.cc +++ b/rt_entt_codegen/core/check_error.cc @@ -45,7 +45,7 @@ static auto print_check_add_component_error_template_specialization( const auto method_name = "ecsact::entt::check_add_component_error<" + cpp_component_ident + ">"; - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = // method_printer{ctx, method_name} @@ -57,11 +57,11 @@ static auto print_check_add_component_error_template_specialization( for_each_entity_field(component_id, [&](auto field_name) { auto field_var = "ecsact::entt::entity_id{component." + field_name + "}"; block(ctx, "if(!registry.valid(" + field_var + "))", [&] { - ctx.write("return ECSACT_ADD_ERR_ENTITY_INVALID;\n"); + ctx.writef("return ECSACT_ADD_ERR_ENTITY_INVALID;\n"); }); }); - ctx.write("return ECSACT_ADD_OK;"); + ctx.writef("return ECSACT_ADD_OK;"); } static auto print_check_update_component_error_template_specialization( @@ -78,7 +78,7 @@ static auto print_check_update_component_error_template_specialization( const auto method_name = "ecsact::entt::check_update_component_error<" + cpp_component_ident + ">"; - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = // method_printer{ctx, method_name} @@ -90,11 +90,11 @@ static auto print_check_update_component_error_template_specialization( for_each_entity_field(component_id, [&](auto field_name) { auto field_var = "ecsact::entt::entity_id{component." + field_name + "}"; block(ctx, "if(!registry.valid(" + field_var + "))", [&] { - ctx.write("return ECSACT_UPDATE_ERR_ENTITY_INVALID;\n"); + ctx.writef("return ECSACT_UPDATE_ERR_ENTITY_INVALID;\n"); }); }); - ctx.write("return ECSACT_UPDATE_OK;"); + ctx.writef("return ECSACT_UPDATE_OK;"); } static auto print_check_action_error_template_specialization( @@ -111,7 +111,7 @@ static auto print_check_action_error_template_specialization( const auto method_name = "ecsact::entt::check_action_error<" + cpp_action_ident + ">"; - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = // method_printer{ctx, method_name} @@ -119,16 +119,16 @@ static auto print_check_action_error_template_specialization( .parameter(cpp_action_ident + " const&", "action") .return_type("ecsact_execute_systems_error"); - ctx.write("auto err = ECSACT_EXEC_SYS_OK;\n"); + ctx.writef("auto err = ECSACT_EXEC_SYS_OK;\n"); for_each_entity_field(action_id, [&](auto field_name) { auto field_var = "ecsact::entt::entity_id{action." + field_name + "}"; block(ctx, "if(!registry.valid(" + field_var + "))", [&] { - ctx.write("return ECSACT_EXEC_SYS_ERR_ACTION_ENTITY_INVALID;\n"); + ctx.writef("return ECSACT_EXEC_SYS_ERR_ACTION_ENTITY_INVALID;\n"); }); }); - ctx.write("return err;\n"); + ctx.writef("return err;\n"); } auto ecsact::rt_entt_codegen::core::print_check_error_template_specializations( diff --git a/rt_entt_codegen/core/events.cc b/rt_entt_codegen/core/events.cc index 01e1e18..77f8afb 100644 --- a/rt_entt_codegen/core/events.cc +++ b/rt_entt_codegen/core/events.cc @@ -12,12 +12,11 @@ static auto print_trigger_event_fn_call( std::string event_name, std::string component_name ) { - ctx.write( - "::ecsact::entt::wrapper::core::_trigger_", + ctx.writef( + "::ecsact::entt::wrapper::core::_trigger_{}" + "_component_event<::{}>(registry_id, events_collector);\n", event_name, - "_component_event<::", - component_name, - ">(registry_id, events_collector);\n" + component_name ); } @@ -53,12 +52,12 @@ auto ecsact::rt_entt_codegen::core::print_trigger_ecsact_events_minimal( // print_trigger_event_fn_call(ctx, "remove", type_name); } - ctx.write( + ctx.writef( "ecsact::entt::wrapper::core::_trigger_create_entity_events(registry_id, " "events_collector);\n" ); - ctx.write( + ctx.writef( "ecsact::entt::wrapper::core::_trigger_destroy_entity_events(registry_id, " "events_collector);\n" ); @@ -101,12 +100,12 @@ auto ecsact::rt_entt_codegen::core::print_trigger_ecsact_events_all( // print_trigger_event_fn_call(ctx, "remove", type_name); } - ctx.write( + ctx.writef( "ecsact::entt::wrapper::core::_trigger_create_entity_events(registry_id, " "events_collector);\n" ); - ctx.write( + ctx.writef( "ecsact::entt::wrapper::core::_trigger_destroy_entity_events(registry_id, " "events_collector);\n" ); @@ -128,11 +127,10 @@ auto ecsact::rt_entt_codegen::core::print_cleanup_ecsact_component_events( // for(auto component_id : details.all_components) { auto type_name = cpp_identifier(decl_full_name(component_id)); - ctx.write( + ctx.writef( "ecsact::entt::wrapper::core::clear_component", - "<::", - type_name, - ">(registry_id);\n" + "<::{}>(registry_id);\n", + type_name ); } } diff --git a/rt_entt_codegen/core/execution_options.cc b/rt_entt_codegen/core/execution_options.cc index 5a16d1c..386264b 100644 --- a/rt_entt_codegen/core/execution_options.cc +++ b/rt_entt_codegen/core/execution_options.cc @@ -20,20 +20,17 @@ inline auto print_static_maps( [&] { for(auto component_id : details.all_components) { auto type_name = cpp_identifier(decl_full_name(component_id)); - ctx.write( - "{", - "ecsact_id_cast(", - type_name, - "::id), ", - "&ecsact::entt::wrapper::core::add_component_exec_options", - "<::", - type_name, - "> },\n" + ctx.writef( + "{" + "ecsact_id_cast({0}::id), " + "&ecsact::entt::wrapper::core::add_component_exec_options<::{0}>" + "},\n", + type_name ); } } ); - ctx.write(";\n"); + ctx.writef(";\n"); block( ctx, @@ -62,7 +59,7 @@ inline auto print_static_maps( } } ); - ctx.write(";\n"); + ctx.writef(";\n"); block( ctx, @@ -85,7 +82,7 @@ inline auto print_static_maps( } } ); - ctx.write(";\n"); + ctx.writef(";\n"); block( ctx, @@ -109,7 +106,7 @@ inline auto print_static_maps( } ); - ctx.write(";\n"); + ctx.writef(";\n"); } auto ecsact::rt_entt_codegen::core::print_execution_options( @@ -128,22 +125,22 @@ auto ecsact::rt_entt_codegen::core::print_execution_options( .return_type("ecsact_execute_systems_error"); print_static_maps(ctx, details); - ctx.write("auto& reg = ecsact::entt::get_registry(registry_id);\n"); + ctx.writef("auto& reg = ecsact::entt::get_registry(registry_id);\n"); block(ctx, "for(int i = 0; i < options.actions_length; i++)", [&] { - ctx.write("auto action = options.actions[i];\n"); - ctx.write( + ctx.writef("auto action = options.actions[i];\n"); + ctx.writef( "auto err = action_error_fns.at(action.action_id)(registry_id, " "action.action_data);\n" ); block(ctx, "if(err != ECSACT_EXEC_SYS_OK)", [&] { - ctx.write("return err;\n"); + ctx.writef("return err;\n"); }); }); block(ctx, "for(int i = 0; i < options.create_entities_length; i++)", [&] { - ctx.write("auto entity = ecsact::entt::entity_id(reg.create());\n"); - ctx.write( + ctx.writef("auto entity = ecsact::entt::entity_id(reg.create());\n"); + ctx.writef( "reg.template emplace(entity, " "options.create_entities[i]);\n" ); @@ -152,10 +149,10 @@ auto ecsact::rt_entt_codegen::core::print_execution_options( "for(int j = 0; j < options.create_entities_components_length[i]; " "j++)", [&] { - ctx.write( + ctx.writef( "auto& component = options.create_entities_components[i][j];\n" ); - ctx.write( + ctx.writef( "execution_add_fns.at(ecsact_id_cast(" "component.component_id))(registry_id, " "entity, " @@ -166,10 +163,10 @@ auto ecsact::rt_entt_codegen::core::print_execution_options( }); block(ctx, "for(int i = 0; i < options.add_components_length; i++)", [&] { - ctx.write("auto& component = options.add_components[i];\n"); - ctx.write("auto entity = options.add_components_entities[i];\n\n"); + ctx.writef("auto& component = options.add_components[i];\n"); + ctx.writef("auto entity = options.add_components_entities[i];\n\n"); - ctx.write( + ctx.writef( "execution_add_fns.at(ecsact_id_cast(" "component.component_id))(registry_id, " "ecsact::entt::entity_id(entity), " @@ -178,10 +175,10 @@ auto ecsact::rt_entt_codegen::core::print_execution_options( }); block(ctx, "for(int i = 0; i < options.update_components_length; i++)", [&] { - ctx.write("auto& component = options.update_components[i];\n"); - ctx.write("auto entity = options.update_components_entities[i];\n\n"); + ctx.writef("auto& component = options.update_components[i];\n"); + ctx.writef("auto entity = options.update_components_entities[i];\n\n"); - ctx.write( + ctx.writef( "execution_update_fns.at(ecsact_id_cast(" "component.component_id))(registry_id, " "ecsact::entt::entity_id(entity), " @@ -190,10 +187,10 @@ auto ecsact::rt_entt_codegen::core::print_execution_options( }); block(ctx, "for(int i = 0; i < options.remove_components_length; i++)", [&] { - ctx.write("auto& component_id = options.remove_components[i];\n"); - ctx.write("auto entity = options.remove_components_entities[i];\n\n"); + ctx.writef("auto& component_id = options.remove_components[i];\n"); + ctx.writef("auto entity = options.remove_components_entities[i];\n\n"); - ctx.write( + ctx.writef( "execution_remove_fns.at(ecsact_id_cast(" "component_id))(registry_id, " "ecsact::entt::entity_id(entity), " @@ -202,14 +199,14 @@ auto ecsact::rt_entt_codegen::core::print_execution_options( }); block(ctx, "for(int i = 0; i < options.destroy_entities_length; i++)", [&] { - ctx.write("auto entity = options.destroy_entities[i];\n"); - ctx.write("reg.destroy(ecsact::entt::entity_id(entity));\n"); - ctx.write( + ctx.writef("auto entity = options.destroy_entities[i];\n"); + ctx.writef("reg.destroy(ecsact::entt::entity_id(entity));\n"); + ctx.writef( "reg.template " "emplace(ecsact::entt::entity_id(" "entity));\n" ); }); - ctx.write("return ECSACT_EXEC_SYS_OK;\n"); + ctx.writef("return ECSACT_EXEC_SYS_OK;\n"); } diff --git a/rt_entt_codegen/core/init_registry_storage.cc b/rt_entt_codegen/core/init_registry_storage.cc index b0dda9a..ec4b70d 100644 --- a/rt_entt_codegen/core/init_registry_storage.cc +++ b/rt_entt_codegen/core/init_registry_storage.cc @@ -16,25 +16,25 @@ auto ecsact::rt_entt_codegen::core::print_init_registry_storage( .parameter("::entt::registry&", "registry") .return_type("void"); - ctx.write( + ctx.writef( "registry.template storage();\n\n" ); for(auto comp_id : details.all_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write(std::format( + ctx.writef( "ecsact::entt::wrapper::core::prepare_component<{}>(registry);\n", cpp_comp_name - )); + ); } for(auto system_id : details.all_systems) { auto cpp_sys_name = cpp_identifier(decl_full_name(system_id)); - ctx.write(std::format( + ctx.writef( "ecsact::entt::wrapper::core::prepare_system<{}>(registry);\n", cpp_sys_name - )); + ); } } diff --git a/rt_entt_codegen/core/print_sys_exec.cc b/rt_entt_codegen/core/print_sys_exec.cc index 8bc6c23..0a4aa21 100644 --- a/rt_entt_codegen/core/print_sys_exec.cc +++ b/rt_entt_codegen/core/print_sys_exec.cc @@ -324,13 +324,13 @@ static auto print_system_execution_context( ); block(ctx, struct_header, [&] { - ctx.write("view_t* view;\n"); + ctx.writef("view_t* view;\n"); for(const auto& provider : system_providers) { provider->context_function_header(ctx, names); } - ctx.write("\n"); + ctx.writef("\n"); 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); @@ -342,13 +342,14 @@ static auto print_system_execution_context( print_sys_exec_ctx_other(ctx, names, system_providers); print_sys_exec_ctx_stream_toggle(ctx, names, system_providers); }); - ctx.write(";\n\n"); + ctx.writef(";\n\n"); return context_type_name; } -static auto setup_system_providers(system_like_id_variant sys_like_id) - -> system_provider_t { +static auto setup_system_providers( // + system_like_id_variant sys_like_id +) -> system_provider_t { using ecsact::rt_entt_codegen::core::provider::association; using ecsact::rt_entt_codegen::core::provider::basic; using ecsact::rt_entt_codegen::core::provider::lazy; @@ -456,7 +457,7 @@ static auto print_execute_systems( additional_view_components ); - ctx.write("using view_t = decltype(view);\n"); + ctx.writef("using view_t = decltype(view);\n"); auto context_type_name = print_system_execution_context(ctx, sys_like_id, names, system_providers); @@ -510,7 +511,7 @@ static auto print_execute_systems( provider->post_exec_system_impl(ctx, names); } - ctx.write("\n"); + ctx.writef("\n"); }); if(result == handle_exclusive_provide::HANDLED) { break; @@ -545,7 +546,7 @@ static auto print_trivial_system_like( auto system_name = cpp_identifier(decl_full_name(system_like_id)); auto sys_capabilities = system_capabilities(system_like_id); - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = // method_printer{ctx, "ecsact::entt::execute_system<::" + system_name + ">"} .parameter("ecsact::entt::registry_t&", "registry") @@ -585,7 +586,7 @@ static auto print_trivial_system_like( } } }); - ctx.write("\n"); + ctx.writef("\n"); print_apply_pendings(ctx, details, system_like_id, "registry"); } @@ -608,7 +609,7 @@ static auto print_execute_system_template_specialization( } auto system_name = cpp_identifier(decl_full_name(system_id)); - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = // method_printer{ctx, "ecsact::entt::execute_system<::" + system_name + ">"} .parameter("ecsact::entt::registry_t&", "registry") @@ -624,8 +625,8 @@ static auto print_execute_system_template_specialization( auto child_ids = ecsact::meta::get_child_system_ids(system_id); if(child_ids.empty()) { - block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); }); - ctx.write("\n"); + block(ctx, "if(system_impl == nullptr)", [&] { ctx.writef("return;"); }); + ctx.writef("\n"); } ctx.write( @@ -670,7 +671,7 @@ static auto print_execute_actions_template_specialization( const auto method_name = "ecsact::entt::execute_actions<::" + cpp_system_name + ">"; - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = // method_printer{ctx, method_name} .parameter("ecsact::entt::registry_t&", "registry") @@ -686,8 +687,8 @@ static auto print_execute_actions_template_specialization( auto child_ids = ecsact::meta::get_child_system_ids(action_id); if(child_ids.empty()) { - block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); }); - ctx.write("\n"); + block(ctx, "if(system_impl == nullptr)", [&] { ctx.writef("return;"); }); + ctx.writef("\n"); } ctx.write( diff --git a/rt_entt_codegen/core/sorting_components.cc b/rt_entt_codegen/core/sorting_components.cc index 3cba878..f2641a7 100644 --- a/rt_entt_codegen/core/sorting_components.cc +++ b/rt_entt_codegen/core/sorting_components.cc @@ -32,7 +32,7 @@ static auto print_system_entity_sorting_component_struct( auto system_sorting_struct_name = std::format("::ecsact::entt::detail::system_sorted<{}>", system_cpp_name); - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = method_printer{ctx, "_recalc_sorting_hash<" + system_cpp_name + ">"} .parameter("ecsact::entt::registry_t&", "reg") @@ -53,10 +53,9 @@ static auto print_system_entity_sorting_component_struct( ); block(ctx, "for(auto entity : view)", [&] { - ctx.write( - "auto& sorted = view.get<", - system_sorting_struct_name, - ">(entity);\n" + ctx.writef( + "auto& sorted = view.get<{}>(entity);\n", + system_sorting_struct_name ); for(auto&& [comp_id, caps] : caps_map) { @@ -67,17 +66,14 @@ static auto print_system_entity_sorting_component_struct( auto comp_cpp_name = decl_cpp_ident(comp_id); auto comp_var = gen_comp_var_name(comp_id); - ctx.write( - "const auto& ", + ctx.writef( + "const auto& {} = view.get<{}>(entity);\n", comp_var, - " = ", - "view.get<", - comp_cpp_name, - ">(entity);\n" + comp_cpp_name ); } - ctx.write("auto bytes = ::ecsact::entt::detail::bytes_copy("); + ctx.writef("auto bytes = ::ecsact::entt::detail::bytes_copy("); ctx.indentation += 1; auto prefix = std::string{"\n"}; @@ -92,15 +88,15 @@ static auto print_system_entity_sorting_component_struct( field_id )}; - ctx.write(prefix, comp_var, ".", field_name); + ctx.writef("{}{}.{}", prefix, comp_var, ".", field_name); prefix = ",\n"; } } ctx.indentation -= 1; - ctx.write("\n);\n"); + ctx.writef("\n);\n"); - ctx.write( + ctx.writef( "sorted.hash = ::ecsact::entt::detail::bytes_hash(bytes.data(), " "bytes.size());" ); @@ -111,7 +107,7 @@ auto ecsact::rt_entt_codegen::core::print_entity_sorting_components( codegen_plugin_context& ctx, const ecsact_entt_details& details ) -> void { - ctx.write(RECALC_COMPONENTS_HASH_DECL); + ctx.writef("{}", RECALC_COMPONENTS_HASH_DECL); for(auto sys_id : details.all_systems) { auto sys_like_id = ecsact_id_cast(sys_id); diff --git a/rt_entt_codegen/core/system_markers.cc b/rt_entt_codegen/core/system_markers.cc index b6280ab..2c8af63 100644 --- a/rt_entt_codegen/core/system_markers.cc +++ b/rt_entt_codegen/core/system_markers.cc @@ -22,7 +22,7 @@ auto ecsact::rt_entt_codegen::core::print_system_marker_add_fn( auto comp_cpp_ident = cc_lang_support::cpp_identifier(comp_name); auto sorting_structs_covered = std::set{}; - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = method_printer{ ctx, @@ -54,10 +54,9 @@ auto ecsact::rt_entt_codegen::core::print_system_marker_add_fn( auto system_sorting_struct_name = std::format("system_sorted<{}>", system_cpp_ident); - ctx.write( - "reg.emplace_or_replace<", - system_sorting_struct_name, - ">(entity);" + ctx.writef( + "reg.emplace_or_replace<{}>(entity);", + system_sorting_struct_name ); } } @@ -73,7 +72,7 @@ auto ecsact::rt_entt_codegen::core::print_system_marker_remove_fn( auto comp_cpp_ident = cc_lang_support::cpp_identifier(comp_name); auto sorting_structs_covered = std::set{}; - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = method_printer{ ctx, @@ -84,7 +83,7 @@ auto ecsact::rt_entt_codegen::core::print_system_marker_remove_fn( .parameter("ecsact::entt::entity_id", "entity") .return_type("void"); - ctx.write("//TODO\n"); + ctx.writef("//TODO\n"); } } @@ -100,7 +99,7 @@ auto ecsact::rt_entt_codegen::core::print_add_sys_beforestorage_fn( for(auto comp_id : details.all_components) { auto comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write("template<>\n"); + ctx.writef("template<>\n"); auto printer = method_printer{ ctx, @@ -123,10 +122,10 @@ auto ecsact::rt_entt_codegen::core::print_add_sys_beforestorage_fn( break; } already_printed_.insert(comp_id); - ctx.write(std::format( // + ctx.writef( // "reg.emplace>(entity);\n", comp_name - )); + ); break; } } diff --git a/rt_entt_codegen/core/system_notify.cc b/rt_entt_codegen/core/system_notify.cc index 782a89d..50f13fa 100644 --- a/rt_entt_codegen/core/system_notify.cc +++ b/rt_entt_codegen/core/system_notify.cc @@ -27,10 +27,9 @@ auto ecsact::rt_entt_codegen::core::print_cleanup_system_notifies( auto system_name = cpp_identifier(decl_full_name(system_id)); - ctx.write( - "ecsact::entt::wrapper::core::clear_notify_component<", - system_name, - ">(registry_id);\n" + ctx.writef( + "ecsact::entt::wrapper::core::clear_notify_component<{}>(registry_id);\n", + system_name ); } } diff --git a/rt_entt_codegen/core/system_provider/basic/basic.cc b/rt_entt_codegen/core/system_provider/basic/basic.cc index bdb9461..ccf072b 100644 --- a/rt_entt_codegen/core/system_provider/basic/basic.cc +++ b/rt_entt_codegen/core/system_provider/basic/basic.cc @@ -22,7 +22,7 @@ auto provider::basic::context_function_header( const common_vars& names ) -> void { if(names.action_var_name) { - ctx.write("const void* action_data = nullptr;\n"); + ctx.writef("const void* action_data = nullptr;\n"); } } @@ -98,7 +98,7 @@ auto provider::basic::context_function_other( ecsact::codegen_plugin_context& ctx, const common_vars& names ) -> handle_exclusive_provide { - ctx.write("return nullptr;"); + ctx.writef("return nullptr;"); return HANDLED; } @@ -114,7 +114,7 @@ auto provider::basic::system_impl( ecsact::codegen_plugin_context& ctx, const common_vars& names ) -> handle_exclusive_provide { - ctx.write("system_impl(&context);\n"); + ctx.writef("system_impl(&context);\n"); return HANDLED; } @@ -136,7 +136,7 @@ auto provider::basic::provide_context_init( const ecsact::rt_entt_codegen::core::common_vars& names, std::string_view context_type_name ) -> handle_exclusive_provide { - ctx.write(std::format("{} context;\n\n", context_type_name)); + ctx.writef("{} context;\n\n", context_type_name); auto system_name = cc_lang_support::cpp_identifier(meta::decl_full_name(sys_like_id)); @@ -152,7 +152,7 @@ auto provider::basic::provide_context_init( "::id);\n" ); ctx.write("context.parent_ctx = ", names.parent_context_var_name, ";\n"); - ctx.write("context.view = &view;\n\n"); + ctx.writef("context.view = &view;\n\n"); return HANDLED; } @@ -161,5 +161,5 @@ auto provider::basic::pre_exec_system_impl_context_init( const ecsact::rt_entt_codegen::core::common_vars& names, std::string_view context_type_name ) -> void { - ctx.write("context.entity = entity;\n"); + ctx.writef("context.entity = entity;\n"); } diff --git a/rt_entt_codegen/core/system_provider/lazy/lazy.cc b/rt_entt_codegen/core/system_provider/lazy/lazy.cc index e5e9c89..381ba5f 100644 --- a/rt_entt_codegen/core/system_provider/lazy/lazy.cc +++ b/rt_entt_codegen/core/system_provider/lazy/lazy.cc @@ -43,13 +43,12 @@ auto provider::lazy::before_make_view_or_group( const common_vars& names, std::vector& additional_view_components ) -> void { - ctx.write( - "constexpr auto lazy_iteration_rate_ = ", - lazy_iteration_rate, - ";\n\n" + ctx.writef( + "constexpr auto lazy_iteration_rate_ = {};\n\n", + lazy_iteration_rate ); - ctx.write("auto iteration_count_ = 0;\n\n"); - ctx.write(exec_start_label_name, ":\n"); + ctx.writef("auto iteration_count_ = 0;\n\n"); + ctx.writef("{}:\n", exec_start_label_name); additional_view_components.push_back(pending_lazy_exec_struct); if(sys_like_id.is_system()) { @@ -65,7 +64,7 @@ auto provider::lazy::after_make_view_or_group( ) -> void { if(sys_like_id.is_system()) { if(system_needs_sorted_entities(sys_like_id.as_system())) { - ctx.write("view.use<", system_sorting_struct_name, ">();\n"); + ctx.writef("view.use<{}>();\n", system_sorting_struct_name); } } } @@ -77,15 +76,14 @@ auto provider::lazy::pre_exec_system_impl( using ecsact::cpp_codegen_plugin_util::block; block(ctx, "if(iteration_count_ == lazy_iteration_rate_)", [&] { - ctx.write("break;\n"); + ctx.writef("break;\n"); }); - ctx.write("++iteration_count_;\n"); - ctx.write( + ctx.writef("++iteration_count_;\n"); + ctx.writef( + "{}.erase<{}>(entity);\n", names.registry_var_name, - ".erase<", - pending_lazy_exec_struct, - ">(entity);\n" + pending_lazy_exec_struct ); } @@ -97,11 +95,11 @@ auto provider::lazy::post_iteration( auto system_name = cpp_identifier(decl_full_name(sys_like_id)); - ctx.write( + ctx.writef( "// If this assertion triggers that's a ecsact_rt_entt codegen " "failure\n" ); - ctx.write("assert(iteration_count_ <= lazy_iteration_rate_);\n"); + ctx.writef("assert(iteration_count_ <= lazy_iteration_rate_);\n"); block(ctx, "if(iteration_count_ < lazy_iteration_rate_)", [&] { ctx.write( "_recalc_sorting_hash<", @@ -124,13 +122,13 @@ auto provider::lazy::post_iteration( system_details ); - ctx.write("auto view_no_pending_lazy_count_ = 0;\n"); + ctx.writef("auto view_no_pending_lazy_count_ = 0;\n"); block( ctx, "for(ecsact::entt::entity_id entity : view_no_pending_lazy_)", [&] { - ctx.write( + ctx.writef( "// If this assertion triggers this is an indicator of a codegen " "failure.\n" "// Please report to " @@ -143,7 +141,7 @@ auto provider::lazy::post_iteration( system_sorting_struct_name, ">(entity));\n" ); - ctx.write("view_no_pending_lazy_count_ += 1;\n"); + ctx.writef("view_no_pending_lazy_count_ += 1;\n"); ctx.write( names.registry_var_name, ".emplace<", @@ -154,7 +152,7 @@ auto provider::lazy::post_iteration( ); block(ctx, "if(view_no_pending_lazy_count_ >= lazy_iteration_rate_)", [&] { - ctx.write("goto ", exec_start_label_name, ";\n"); + ctx.writef("goto {};\n", exec_start_label_name); }); }); } diff --git a/rt_entt_codegen/core/system_provider/notify/notify.cc b/rt_entt_codegen/core/system_provider/notify/notify.cc index 7df8358..363e0c7 100644 --- a/rt_entt_codegen/core/system_provider/notify/notify.cc +++ b/rt_entt_codegen/core/system_provider/notify/notify.cc @@ -122,9 +122,7 @@ auto provider::notify::print_system_notify_views( ); block(ctx, std::format("for(auto entity: {})", view_name), [&]() { - ctx.write( - std::format("registry.emplace<{}>(entity);\n", run_system_comp) - ); + ctx.writef("registry.emplace<{}>(entity);\n", run_system_comp); }); } @@ -141,9 +139,7 @@ auto provider::notify::print_system_notify_views( ); block(ctx, std::format("for(auto entity: {})", view_name), [&]() { - ctx.write( - std::format("registry.emplace<{}>(entity);\n", run_system_comp) - ); + ctx.writef("registry.emplace<{}>(entity);\n", run_system_comp); }); } @@ -172,12 +168,10 @@ auto provider::notify::print_system_notify_views( " registry))", cpp_comp_name ), - [&] { ctx.write("continue;\n"); } + [&] { ctx.writef("continue;\n"); } ); - ctx.write( - std::format("registry.emplace<{}>(entity);\n", run_system_comp) - ); + ctx.writef("registry.emplace<{}>(entity);\n", run_system_comp); }); } } diff --git a/rt_entt_codegen/core/system_provider/parallel/parallel.cc b/rt_entt_codegen/core/system_provider/parallel/parallel.cc index a4da93e..9b32063 100644 --- a/rt_entt_codegen/core/system_provider/parallel/parallel.cc +++ b/rt_entt_codegen/core/system_provider/parallel/parallel.cc @@ -19,7 +19,7 @@ auto provider::parallel::entity_iteration( "view.end(), [&](auto entity)", [&] { iter_func(); } ); - ctx.write(");\n"); + ctx.writef(");\n"); return HANDLED; } @@ -36,22 +36,21 @@ auto provider::parallel::pre_exec_system_impl_context_init( const ecsact::rt_entt_codegen::core::common_vars& names, std::string_view context_type_name ) -> void { - ctx.write(std::format("{} context;\n\n", context_type_name)); + ctx.writef("{} context;\n\n", context_type_name); auto system_name = cc_lang_support::cpp_identifier(meta::decl_full_name(sys_like_id)); - ctx.write("context.registry = &", names.registry_var_name, ";\n"); + ctx.writef("context.registry = &{};\n", names.registry_var_name); if(names.action_var_name) { - ctx.write("context.action_data = ", *names.action_var_name, ";\n\n"); + ctx.writef("context.action_data = {};\n\n", *names.action_var_name); } - ctx.write( - "context.id = ecsact_id_cast(::", - system_name, - "::id);\n" + ctx.writef( + "context.id = ecsact_id_cast(::{}::id);\n", + system_name ); - ctx.write("context.parent_ctx = ", names.parent_context_var_name, ";\n"); - ctx.write("context.view = &view;\n\n"); - ctx.write("context.entity = entity;\n"); + ctx.writef("context.parent_ctx = {};\n", names.parent_context_var_name); + ctx.writef("context.view = &view;\n\n"); + ctx.writef("context.entity = entity;\n"); } diff --git a/rt_entt_codegen/core/system_provider/system_ctx_functions.cc b/rt_entt_codegen/core/system_provider/system_ctx_functions.cc index 8715a25..96fe40b 100644 --- a/rt_entt_codegen/core/system_provider/system_ctx_functions.cc +++ b/rt_entt_codegen/core/system_provider/system_ctx_functions.cc @@ -16,12 +16,12 @@ auto ecsact::rt_entt_codegen::core::provider::context_action_impl( ) -> void { if(sys_like_id.is_action()) { auto action_name = cpp_identifier(decl_full_name(sys_like_id)); - ctx.write( - "\t#ifdef TRACY_ENABLE\n", - "ZoneScopedNC(\"context_action ", - action_name, - "\", tracy::Color::Blue);\n", - "#endif\n" + ctx.writef( + "\t#ifdef TRACY_ENABLE\n" + "ZoneScopedNC(\"context_action {}", + "\", tracy::Color::Blue);\n" + "#endif\n", + action_name ); ctx.write( @@ -33,7 +33,7 @@ auto ecsact::rt_entt_codegen::core::provider::context_action_impl( ); } else { // TODO(Kelwan): Trying to access .action() without a valid action - ctx.write("\n"); + ctx.writef("\n"); } } @@ -93,9 +93,9 @@ auto ecsact::rt_entt_codegen::core::provider::context_add_impl( } ); - ctx.write(";\n"); + ctx.writef(";\n"); - ctx.write("add_fns.at(component_id)(this, component_id, component_data);\n"); + ctx.writef("add_fns.at(component_id)(this, component_id, component_data);\n"); } auto ecsact::rt_entt_codegen::core::provider::context_remove_impl( @@ -133,16 +133,16 @@ auto ecsact::rt_entt_codegen::core::provider::context_remove_impl( ); return; } - ctx.write(std::format( + ctx.writef( "using remove_fn_t = void (*)(ecsact_system_execution_context*, " "ecsact_component_like_id, const void*, {}_t&);\n", view_type_name - )); + ); - ctx.write("static const auto remove_fns = []()\n"); + ctx.writef("static const auto remove_fns = []()\n"); block(ctx, "", [&] { - ctx.write( + ctx.writef( "auto result = std::unordered_map{};\n" ); @@ -157,10 +157,11 @@ auto ecsact::rt_entt_codegen::core::provider::context_remove_impl( ); } - ctx.write("return result;\n"); + ctx.writef("return result;\n"); }); - ctx.write("();\n"); - ctx.write("remove_fns.at(component_id)(this, component_id, nullptr, *view);\n" + ctx.writef("();\n"); + ctx.writef( + "remove_fns.at(component_id)(this, component_id, nullptr, *view);\n" ); } @@ -216,18 +217,18 @@ auto ecsact::rt_entt_codegen::core::provider::context_get_impl( return; } - ctx.write(std::format( + ctx.writef( "using get_fn_t = void (*)(ecsact_system_execution_context*, " "ecsact_component_like_id, void *, const void*, {}_t&);\n", view_type_name - )); + ); - ctx.write("static const auto get_fns = []()\n"); + ctx.writef("static const auto get_fns = []()\n"); block(ctx, "", [&] { - ctx.write( + ctx.writef( "auto result = std::unordered_map{};\n" + "get_fn_t>{{}};\n" ); for(const auto comp_id : details.readable_comps) { auto type_name = cpp_identifier(decl_full_name(comp_id)); @@ -240,11 +241,11 @@ auto ecsact::rt_entt_codegen::core::provider::context_get_impl( ); } - ctx.write("return result;\n"); + ctx.writef("return result;\n"); }); - ctx.write("();\n"); + ctx.writef("();\n"); - ctx.write( + ctx.writef( "get_fns.at(" "component_id)(this, component_id, out_component_data, nullptr, *view" ");\n" @@ -286,18 +287,18 @@ auto ecsact::rt_entt_codegen::core::provider::context_update_impl( return; } - ctx.write(std::format( + ctx.writef( "using update_fn_t = void (*)(ecsact_system_execution_context*, " "ecsact_component_like_id, const void *, const void*, {}_t&);\n", view_type_name - )); + ); - ctx.write("static const auto update_fns = []()\n"); + ctx.writef("static const auto update_fns = []()\n"); - block(ctx, "", [&] { - ctx.write( + block(ctx, [&] { + ctx.writef( "auto result = std::unordered_map{};\n" + "update_fn_t>{{}};\n" ); for(const auto comp_id : details.writable_comps) { auto type_name = cpp_identifier(decl_full_name(comp_id)); @@ -310,11 +311,11 @@ auto ecsact::rt_entt_codegen::core::provider::context_update_impl( ); } - ctx.write("return result;\n"); + ctx.writef("return result;\n"); }); - ctx.write("();\n"); + ctx.writef("();\n"); - ctx.write( + ctx.writef( "update_fns.at(component_id)(this, component_id, component_data, nullptr, " "*view);\n" ); @@ -326,7 +327,7 @@ auto ecsact::rt_entt_codegen::core::provider::context_has_impl( const ecsact::rt_entt_codegen::ecsact_entt_system_details& details ) -> void { if(details.writable_comps.size() == 0) { - ctx.write("return false;"); + ctx.writef("return false;"); return; } @@ -370,9 +371,9 @@ auto ecsact::rt_entt_codegen::core::provider::context_has_impl( } } ); - ctx.write(";\n"); + ctx.writef(";\n"); - ctx.write("return has_fns.at(component_id)(this, component_id, nullptr);\n"); + ctx.writef("return has_fns.at(component_id)(this, component_id, nullptr);\n"); } auto ecsact::rt_entt_codegen::core::provider::context_generate_impl( @@ -417,23 +418,23 @@ auto ecsact::rt_entt_codegen::core::provider::context_generate_impl( } } ); - ctx.write(";\n"); + ctx.writef(";\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.writef("auto entity = registry->create();\n"); - ctx.write( + ctx.writef( "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.writef("const auto component_id = component_ids[i];\n"); + ctx.writef("const void* component_data = components_data[i];\n"); - ctx.write( + ctx.writef( "generate_fns.at(component_id)(this, component_id, " "component_data, nullptr, entity);\n" ); @@ -506,7 +507,7 @@ auto ecsact::rt_entt_codegen::core::provider::context_parent_impl( ecsact::codegen_plugin_context& ctx, const system_like_id_variant& sys_like_id ) -> void { - ctx.write("return this->parent_ctx;\n"); + ctx.writef("return this->parent_ctx;\n"); } auto ecsact::rt_entt_codegen::core::provider::context_other_impl( diff --git a/rt_entt_codegen/core/update_beforechange.cc b/rt_entt_codegen/core/update_beforechange.cc index 8dc1f97..30822f4 100644 --- a/rt_entt_codegen/core/update_beforechange.cc +++ b/rt_entt_codegen/core/update_beforechange.cc @@ -22,7 +22,7 @@ auto ecsact::rt_entt_codegen::core::print_update_all_beforechange_storage( .parameter("ecsact_registry_id", "registry_id") .return_type("void"); - ctx.write("auto& reg = ecsact::entt::get_registry(registry_id);\n\n"); + ctx.writef("auto& reg = ecsact::entt::get_registry(registry_id);\n\n"); for(auto comp_id : details.all_components) { if(ecsact::meta::get_field_ids(comp_id).empty()) { @@ -39,16 +39,14 @@ auto ecsact::rt_entt_codegen::core::print_update_all_beforechange_storage( auto view_name = std::format("{}_view", comp_name); auto comp_list = std::format("{}, {}", cpp_comp_name, comp_change_name); - ctx.write( // - std::format("auto {} = reg.view<{}>();\n", view_name, comp_list) - ); + ctx.writef("auto {} = reg.view<{}>();\n", view_name, comp_list); block(ctx, std::format("for(auto entity: {})", view_name), [&]() { - ctx.write(std::format( + ctx.writef( "ecsact::entt::wrapper::core::update_exec_itr_beforechange<{}>(entity, " "reg);\n", cpp_comp_name - )); + ); }); } } diff --git a/rt_entt_codegen/rt_entt_codegen.cc b/rt_entt_codegen/rt_entt_codegen.cc index 0ef3881..1ac7ec0 100644 --- a/rt_entt_codegen/rt_entt_codegen.cc +++ b/rt_entt_codegen/rt_entt_codegen.cc @@ -112,10 +112,10 @@ void ecsact_codegen_plugin( ecsact::codegen_plugin_context ctx{package_id, 0, write_fn, report_fn}; - ctx.write(GENERATED_FILE_DISCLAIMER); + ctx.writef("{}", GENERATED_FILE_DISCLAIMER); if(ecsact_meta_main_package() != package_id) { - ctx.write(MAIN_PACKAGE_ONLY_DISCLAIMER); + ctx.writef("{}", MAIN_PACKAGE_ONLY_DISCLAIMER); return; } @@ -138,18 +138,18 @@ void ecsact_codegen_plugin( inc_header(ctx, "ecsact/entt/wrapper/core.hh"); inc_header(ctx, "ecsact/entt/wrapper/dynamic.hh"); inc_header(ctx, "ecsact/entt/error_check.hh"); - ctx.write("#include \n"); + ctx.writef("#include \n"); - ctx.write("\n"); + ctx.writef("\n"); inc_package_header(ctx, package_id); for(auto dep : ecsact::meta::get_dependencies(package_id)) { assert(package_id != dep); inc_package_header(ctx, dep); } - ctx.write("\n"); + ctx.writef("\n"); - ctx.write("// test1234\n"); - ctx.write( + ctx.writef("// test1234\n"); + ctx.writef( "using exec_entry_t = std::pair;\n\n" ); @@ -163,11 +163,11 @@ void ecsact_codegen_plugin( return; } - ctx.write("result.reserve(", details.all_components.size(), ");\n"); + ctx.writef("result.reserve({});\n", details.all_components.size()); for(auto comp_id : details.all_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write("result.insert(", cpp_comp_name, "::id);\n"); + ctx.writef("result.insert({}::id);\n", cpp_comp_name); } }); @@ -176,17 +176,14 @@ void ecsact_codegen_plugin( return; } - ctx.write("result.reserve(", details.all_components.size(), ");\n"); + ctx.writef("result.reserve({});\n", details.all_components.size()); for(auto comp_id : details.all_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result.insert({::", - cpp_comp_name, - "::id, ", - "&ecsact::entt::wrapper::core::add_component<::", - cpp_comp_name, - ">});\n" + ctx.writef( + "result.insert({{::{0}::id, " + "&ecsact::entt::wrapper::core::add_component<::{0}>}});\n", + cpp_comp_name ); } }); @@ -196,21 +193,17 @@ void ecsact_codegen_plugin( return; } - ctx.write( - "result.reserve(", - std::ranges::distance(details.all_components), - ");\n" + ctx.writef( + "result.reserve({});\n", + std::ranges::distance(details.all_components) ); for(auto comp_id : details.all_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result.insert({::", - cpp_comp_name, - "::id, ", - "&ecsact::entt::wrapper::core::get_component<::", - cpp_comp_name, - ">});\n" + ctx.writef( + "result.insert({{::{0}::id, " + "&ecsact::entt::wrapper::core::get_component<::{0}>}});\n", + cpp_comp_name ); } }); @@ -226,21 +219,17 @@ void ecsact_codegen_plugin( return !ecsact::meta::get_field_ids(comp_id).empty(); }); - ctx.write( - "result.reserve(", - std::ranges::distance(non_tag_component_ids), - ");\n" + ctx.writef( + "result.reserve({});\n", + std::ranges::distance(non_tag_component_ids) ); for(auto comp_id : non_tag_component_ids) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result.insert({::", - cpp_comp_name, - "::id, ", - "&ecsact::entt::wrapper::core::update_component<::", - cpp_comp_name, - ">});\n" + ctx.writef( + "result.insert({{::{0}::id, " + "&ecsact::entt::wrapper::core::update_component<::{0]>}});\n", + cpp_comp_name ); } }); @@ -250,17 +239,14 @@ void ecsact_codegen_plugin( return; } - ctx.write("result.reserve(", details.all_components.size(), ");\n"); + ctx.writef("result.reserve({});\n", details.all_components.size()); for(auto comp_id : details.all_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result.insert({::", - cpp_comp_name, - "::id, ", - "&ecsact::entt::wrapper::core::remove_component<::", - cpp_comp_name, - ">});\n" + ctx.writef( + "result.insert({{::{0}::id, " + "&ecsact::entt::wrapper::core::remove_component<::{0}>}});\n", + cpp_comp_name ); } }); @@ -270,17 +256,14 @@ void ecsact_codegen_plugin( return; } - ctx.write("result.reserve(", details.all_components.size(), ");\n"); + ctx.writef("result.reserve({});\n", details.all_components.size()); for(auto comp_id : details.all_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result.insert({::", - cpp_comp_name, - "::id, ", - "&ecsact::entt::wrapper::core::has_component<::", - cpp_comp_name, - ">});\n" + ctx.writef( + "result.insert({{::{0}::id, " + "&ecsact::entt::wrapper::core::has_component<::{0}>}});\n", + cpp_comp_name ); } }); @@ -303,22 +286,19 @@ void ecsact_codegen_plugin( } } - ctx.write("result.reserve(", stream_components.size(), ");\n"); + ctx.writef("result.reserve({});\n", stream_components.size()); for(auto comp_id : stream_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); - ctx.write( - "result.insert({::", - cpp_comp_name, - "::id, ", - "&ecsact::entt::wrapper::core::ecsact_stream<::", - cpp_comp_name, - ">});\n" + ctx.writef( + "result.insert({{::{0}::id, " + "&ecsact::entt::wrapper::core::ecsact_stream<::{0}>}});\n", + cpp_comp_name ); } }); - ctx.write("\n"); + ctx.writef("\n"); for(auto comp_id : details.all_components) { auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id)); @@ -329,13 +309,14 @@ void ecsact_codegen_plugin( cpp_comp_name ), [&] { - ctx.write("using type = ::", cpp_comp_name, ";\n"); - ctx.write("static constexpr bool in_place_delete = true;\n"); - ctx.write("static constexpr std::size_t page_size = ENTT_PACKED_PAGE;\n" + ctx.writef("using type = ::{};\n", cpp_comp_name); + ctx.writef("static constexpr bool in_place_delete = true;\n"); + ctx.writef( + "static constexpr std::size_t page_size = ENTT_PACKED_PAGE;\n" ); } ); - ctx.write(";\n"); + ctx.writef(";\n"); } { // Print core Ecsact API methods diff --git a/rt_entt_codegen/shared/parallel.cc b/rt_entt_codegen/shared/parallel.cc index cdadd35..075c572 100644 --- a/rt_entt_codegen/shared/parallel.cc +++ b/rt_entt_codegen/shared/parallel.cc @@ -55,52 +55,48 @@ auto ecsact::rt_entt_codegen::parallel::print_parallel_execution_cluster( )); if(single_system_like_variant->is_action()) { - ctx.write(std::format( + ctx.writef( "ecsact::entt::execute_actions<{}>(registry, {}, " "actions_map);\n", sync_sys_name, "nullptr" - )); + ); } if(single_system_like_variant->is_system()) { - ctx.write(std::format( + ctx.writef( "ecsact::entt::execute_system<{}>(registry, {}, " "actions_map);\n", sync_sys_name, "nullptr" - )); + ); } continue; } if(systems_to_parallel.size() == 0) { } - ctx.write("execute_parallel_cluster(registry, nullptr, "); - ctx.write(std::format( - "std::array {{\n", - systems_to_parallel.size() - )); + ctx.writef("execute_parallel_cluster(registry, nullptr, "); + ctx.writef("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)); if(system_like_id_variant.is_action()) { - ctx.write( - "\texec_entry_t{&ecsact::entt::execute_actions<", - cpp_decl_name, - ">, actions_map},\n" + ctx.writef( + "\texec_entry_t{{&ecsact::entt::execute_actions<{}>, " + "actions_map}},\n", + cpp_decl_name ); } else if(system_like_id_variant.is_system()) { - ctx.write( - "\texec_entry_t{&ecsact::entt::execute_system<", - cpp_decl_name, - ">, actions_map},\n" + ctx.writef( + "\texec_entry_t{{&ecsact::entt::execute_system<{}>, actions_map}},\n", + cpp_decl_name ); } else { - ctx.write("// ??? unhandled ??? ", cpp_decl_name, "\n"); + ctx.writef("// ??? unhandled ??? ", cpp_decl_name, "\n"); } } - ctx.write("});\n"); + ctx.writef("}});\n"); } } diff --git a/rt_entt_codegen/shared/util.hh b/rt_entt_codegen/shared/util.hh index 02f22fe..f915e3e 100644 --- a/rt_entt_codegen/shared/util.hh +++ b/rt_entt_codegen/shared/util.hh @@ -37,7 +37,7 @@ public: ")> {" ); ctx.indentation += 1; - ctx.write("\n"); + ctx.writef("\n"); ctx.write( "auto result = " "std::remove_cvref_t void { - ctx.write("#include \"", header_path, "\"\n"); + ctx.writef("#include \"", header_path, "\"\n"); } inline auto inc_package_header( // @@ -182,23 +182,23 @@ class method_printer { } if(!parameters->empty()) { - ctx.write("\n"); + ctx.writef("\n"); } for(auto i = 0; parameters->size() > i; ++i) { auto&& [param_type, param_name] = parameters->at(i); - ctx.write("\t", param_type, " ", param_name); + ctx.writef("\t{} {}", param_type, param_name); if(i + 1 < parameters->size()) { - ctx.write(","); + ctx.writef(","); } - ctx.write("\n"); + ctx.writef("\n"); } parameters = std::nullopt; - ctx.write(") -> ", type, " {"); + ctx.writef(") -> {} {{", type); ctx.indentation += 1; - ctx.write("\n"); + ctx.writef("\n"); } public: @@ -208,7 +208,7 @@ public: ) : ctx(ctx) { parameters.emplace(); - ctx.write("auto ", method_name, "("); + ctx.writef("auto {}(", method_name); } method_printer(method_printer&& other) : ctx(other.ctx) { @@ -253,7 +253,7 @@ public: } disposed = true; ctx.indentation -= 1; - ctx.write("\n}\n\n"); + ctx.writef("\n}}\n\n"); } }; @@ -284,11 +284,14 @@ auto make_view( // using ecsact::rt_entt_codegen::util::decl_cpp_ident; using std::views::transform; - ctx.write("auto ", view_var_name, " = ", registry_var_name, ".view<"); + ctx.writef("auto {} = {} .view<", view_var_name, registry_var_name); - ctx.write(comma_delim( - details.get_comps | transform(decl_cpp_ident) - )); + ctx.writef( + "{}", + comma_delim( + details.get_comps | transform(decl_cpp_ident) + ) + ); for(auto comp_id : details.writable_comps) { auto comp_name = decl_cpp_ident(comp_id); @@ -300,11 +303,10 @@ auto make_view( // } if(!additional_components.empty()) { - ctx.write(", "); - ctx.write(comma_delim(additional_components)); + ctx.writef(", {}", comma_delim(additional_components)); } - ctx.write(">("); + ctx.writef(">("); auto exclude_comps = details.exclude_comps | transform(decl_cpp_ident); @@ -316,14 +318,13 @@ auto make_view( // ); if(!additional_exclude_components.empty()) { - ctx.write( - "::entt::exclude<", - comma_delim(additional_exclude_components), - ">" + ctx.writef( + "::entt::exclude<{}>", + comma_delim(additional_exclude_components) ); } - ctx.write(");\n"); + ctx.writef(");\n"); } } // namespace ecsact::rt_entt_codegen::util