Skip to content

chore: removed a bunch of deprecated ctx.write calls #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions rt_entt_codegen/core/check_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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(
Expand All @@ -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}
Expand All @@ -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(
Expand All @@ -111,24 +111,24 @@ 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}
.parameter("ecsact::entt::registry_t&", "registry")
.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(
Expand Down
24 changes: 11 additions & 13 deletions rt_entt_codegen/core/events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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"
);
Expand Down Expand Up @@ -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"
);
Expand All @@ -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
);
}
}
65 changes: 31 additions & 34 deletions rt_entt_codegen/core/execution_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ecsact_component_like_id>(",
type_name,
"::id), ",
"&ecsact::entt::wrapper::core::add_component_exec_options",
"<::",
type_name,
"> },\n"
ctx.writef(
"{"
"ecsact_id_cast<ecsact_component_like_id>({0}::id), "
"&ecsact::entt::wrapper::core::add_component_exec_options<::{0}>"
"},\n",
type_name
);
}
}
);
ctx.write(";\n");
ctx.writef(";\n");

block(
ctx,
Expand Down Expand Up @@ -62,7 +59,7 @@ inline auto print_static_maps(
}
}
);
ctx.write(";\n");
ctx.writef(";\n");

block(
ctx,
Expand All @@ -85,7 +82,7 @@ inline auto print_static_maps(
}
}
);
ctx.write(";\n");
ctx.writef(";\n");

block(
ctx,
Expand All @@ -109,7 +106,7 @@ inline auto print_static_maps(
}
);

ctx.write(";\n");
ctx.writef(";\n");
}

auto ecsact::rt_entt_codegen::core::print_execution_options(
Expand All @@ -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<ecsact::entt::detail::created_entity>(entity, "
"options.create_entities[i]);\n"
);
Expand All @@ -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<ecsact_component_like_id>("
"component.component_id))(registry_id, "
"entity, "
Expand All @@ -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<ecsact_component_like_id>("
"component.component_id))(registry_id, "
"ecsact::entt::entity_id(entity), "
Expand All @@ -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<ecsact_component_like_id>("
"component.component_id))(registry_id, "
"ecsact::entt::entity_id(entity), "
Expand All @@ -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<ecsact_component_like_id>("
"component_id))(registry_id, "
"ecsact::entt::entity_id(entity), "
Expand All @@ -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::detail::destroyed_entity>(ecsact::entt::entity_id("
"entity));\n"
);
});

ctx.write("return ECSACT_EXEC_SYS_OK;\n");
ctx.writef("return ECSACT_EXEC_SYS_OK;\n");
}
10 changes: 5 additions & 5 deletions rt_entt_codegen/core/init_registry_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ecsact::entt::detail::destroyed_entity>();\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
));
);
}
}
Loading
Loading