1
1
#include " core.hh"
2
2
3
- #include < set>
4
-
3
+ #include " rt_entt_codegen/shared/parallel.hh"
5
4
#include " ecsact/lang-support/lang-cc.hh"
6
5
#include " rt_entt_codegen/shared/util.hh"
7
6
#include " ecsact/cpp_codegen_plugin_util.hh"
8
7
9
8
#include < iostream>
10
9
11
10
constexpr auto METHOD_BODY_TOP = R"(
12
- auto& reg = ecsact::entt::get_registry(registry_id);
13
- auto actions = ecsact::entt::actions_map{};
11
+ auto& registry = ecsact::entt::get_registry(registry_id);
12
+ auto actions_map = ecsact::entt::actions_map{};
14
13
)" ;
15
14
16
- auto is_capability_safe (ecsact_system_capability capability) -> bool {
17
- // List of components capabilities that can't be executed in parallel
18
- if (capability == ECSACT_SYS_CAP_ADDS ||
19
- capability == ECSACT_SYS_CAP_REMOVES ||
20
- capability == ECSACT_SYS_CAP_READWRITE ||
21
- capability == ECSACT_SYS_CAP_WRITEONLY ||
22
- capability == ECSACT_SYS_CAP_OPTIONAL_WRITEONLY ||
23
- capability == ECSACT_SYS_CAP_OPTIONAL_READWRITE) {
24
- return false ;
25
- }
26
- return true ;
27
- }
28
-
29
- auto manage_component_safety (
30
- const ecsact_component_id unsafe_comp_id,
31
- std::set<ecsact_component_id>& unsafe_comps
32
- ) -> void {
33
- if (!unsafe_comps.contains (unsafe_comp_id)) {
34
- unsafe_comps.insert (unsafe_comp_id);
35
- return ;
36
- }
37
- }
38
-
39
- auto loop_iterator (
40
- std::vector<ecsact_system_like_id>& system_list,
41
- const std::vector<ecsact_system_like_id>::iterator begin,
42
- std::vector<std::vector<ecsact_system_like_id>>& parallel_system_cluster
43
- ) -> void {
44
- std::cout << " loop iterator run" << std::endl;
45
- std::vector<ecsact_system_like_id> parallel_system_list;
46
- auto unsafe_comps = std::set<ecsact_component_like_id>{};
47
-
48
- for (auto iterator = begin; iterator != system_list.end (); iterator++) {
49
- auto sys_like_id = *iterator;
50
- auto capabilities = ecsact::meta::system_capabilities (sys_like_id);
51
-
52
- for (const auto [comp_id, capability] : capabilities) {
53
- if (!is_capability_safe (capability)) {
54
- if (!unsafe_comps.contains (comp_id)) {
55
- std::cout << " Unsafe comp inserted" << std::endl;
56
- unsafe_comps.insert (comp_id);
57
- } else {
58
- // We already have it. Uh-oh!
59
- std::cout << " Conflict found" << std::endl;
60
- parallel_system_cluster.push_back (parallel_system_list);
61
- parallel_system_list.clear ();
62
- unsafe_comps.clear ();
63
- loop_iterator (system_list, iterator, parallel_system_cluster);
64
- }
65
- }
66
- }
67
-
68
- // Okay it's all good, check has passed. Now let's check the child systems
69
- auto child_systems = ecsact::meta::get_child_system_ids (sys_like_id);
70
-
71
- for (const auto child_sys_id : child_systems) {
72
- auto child_capabilities = ecsact::meta::system_capabilities (child_sys_id);
73
- for (const auto [child_comp_id, child_capability] : child_capabilities) {
74
- if (!is_capability_safe (child_capability)) {
75
- if (!unsafe_comps.contains (child_comp_id)) {
76
- std::cout << " Unsafe comp inserted in child" << std::endl;
77
- unsafe_comps.insert (child_comp_id);
78
- } else {
79
- // We already have it. Uh-oh!
80
- std::cout << " Conflict found in child" << std::endl;
81
- parallel_system_cluster.push_back (parallel_system_list);
82
- parallel_system_list.clear ();
83
- unsafe_comps.clear ();
84
- loop_iterator (system_list, iterator, parallel_system_cluster);
85
- }
86
- }
87
- }
88
- }
89
-
90
- std::cout << " System added to list" << std::endl;
91
- parallel_system_list.push_back (sys_like_id);
92
- }
93
- parallel_system_cluster.push_back (parallel_system_list);
94
- }
95
-
96
- auto print_parallel_execution (
97
- ecsact::codegen_plugin_context& ctx,
98
- const ecsact::rt_entt_codegen::ecsact_entt_details& details
15
+ auto ecsact::rt_entt_codegen::core::print_parallel_system_execute (
16
+ codegen_plugin_context& ctx,
17
+ const ecsact_entt_details& details
99
18
) -> void {
19
+ using ecsact::cc_lang_support::cpp_identifier;
100
20
using ecsact::cpp_codegen_plugin_util::block;
21
+ using ecsact::rt_entt_codegen::util::method_printer;
101
22
102
- auto parallel_system_cluster =
103
- std::vector<std::vector<ecsact_system_like_id>>{};
104
-
105
- auto top_systems_copy = std::vector<ecsact_system_like_id>{
106
- details.top_execution_order .begin (),
107
- details.top_execution_order .end ()
108
- };
109
-
110
- loop_iterator (
111
- top_systems_copy,
112
- top_systems_copy.begin (),
113
- parallel_system_cluster
23
+ auto printer = //
24
+ method_printer{ctx, " ecsact_execute_parallel_cluster" } //
25
+ .parameter (" ::entt::registry&" , " registry" )
26
+ .parameter (" ecsact_system_execution_context*" , " parent_context" )
27
+ .parameter (" auto" , " system_arr" )
28
+ .return_type (" void" );
29
+
30
+ ctx.write (
31
+ " std::for_each(std::execution::par_unseq\n , system_arr.begin()\n , "
32
+ " system_arr.end()\n , "
114
33
);
115
-
116
- std::cout << " post loop iterator" << std::endl;
117
-
118
- for (const auto & systems_to_parallel : parallel_system_cluster) {
119
- std::cout << " Parallel system cluster" << std::endl;
120
- using ecsact::cc_lang_support::cpp_identifier;
121
- block (ctx, " " , [&] {
122
- block (ctx, " auto system_bank = std::array\n " , [&] {
123
- for (const auto system_like_id : systems_to_parallel) {
124
- std::cout << " Systems to parallel" << std::endl;
125
- auto cpp_decl_name =
126
- cpp_identifier (ecsact::meta::decl_full_name (system_like_id));
127
-
128
- if (details.is_action (system_like_id)) {
129
- ctx.write (
130
- " std::pair{&ecsact::entt::execute_actions<" ,
131
- cpp_decl_name,
132
- " >, actions},\n "
133
- );
134
- } else if (details.is_system (system_like_id)) {
135
- ctx.write (
136
- " std::pair{&ecsact::entt::execute_system<" ,
137
- cpp_decl_name,
138
- " >, actions},\n "
139
- );
140
- } else {
141
- ctx.write (" // ??? unhandled ??? " , cpp_decl_name, " \n " );
142
- }
143
- }
144
- });
145
- ctx.write (" ;\n " );
146
-
147
- ctx.write (
148
- " std::for_each(std::execution::par_unseq\n , system_bank.begin()\n , "
149
- " system_bank.end()\n , "
150
- );
151
- block (ctx, " [&](auto pair)" , [&]() {
152
- ctx.write (" auto fn_ptr = pair.first;\n " );
153
- ctx.write (" auto actions_map = pair.second;\n " );
154
- ctx.write (" fn_ptr(reg, actions_map);" );
155
- });
156
- ctx.write (" );\n " );
157
- });
158
- }
34
+ block (ctx, " [&](auto pair)" , [&]() {
35
+ ctx.write (" auto fn_ptr = pair.first;\n " );
36
+ ctx.write (" auto actions_map = pair.second;\n " );
37
+ ctx.write (" fn_ptr(registry, nullptr, actions_map);" );
38
+ });
39
+ ctx.write (" );\n " );
159
40
}
160
41
161
42
auto ecsact::rt_entt_codegen::core::print_execute_systems ( //
@@ -182,7 +63,8 @@ auto ecsact::rt_entt_codegen::core::print_execute_systems( //
182
63
ctx.indentation += 1 ;
183
64
ctx.write (" \n " );
184
65
185
- ctx.write (" actions.collect(i, execution_count, execution_options_list);\n " );
66
+ ctx.write (" actions_map.collect(i, execution_count, execution_options_list);\n "
67
+ );
186
68
187
69
block (ctx, " if(execution_options_list != nullptr)" , [&] {
188
70
ctx.write (
@@ -194,7 +76,11 @@ auto ecsact::rt_entt_codegen::core::print_execute_systems( //
194
76
});
195
77
});
196
78
197
- print_parallel_execution (ctx, details);
79
+ ecsact::rt_entt_codegen::parallel::print_parallel_system_executions (
80
+ ctx,
81
+ details,
82
+ details.top_execution_order
83
+ );
198
84
199
85
ctx.write (" \n update_all_beforechange_storage(registry_id);\n " );
200
86
ctx.write (" cleanup_system_notifies(registry_id);\n " );
0 commit comments