-
Notifications
You must be signed in to change notification settings - Fork 68
/
methods_ecs.py
226 lines (184 loc) · 7.05 KB
/
methods_ecs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import os
from enum import Enum
class SystemType(Enum):
NORMAL = 1
DISPATCHER = 2
TEMPORARY = 3
def is_devel():
return False
def get_version():
return "12"
def generate_system_structs():
"""Generates the structs needed to process the `System`s."""
max_parameters = 30
path = "./systems/system_structs.gen.h"
if os.path.exists(path) and not is_devel():
# If the path exist and is not in development:
with open(path) as f:
firstline = f.readline().rstrip()
if firstline == "/*" + get_version() + "*/":
# This file is already generated, nothing more to do.
print("This file `" + path + "` is already generated.")
return
print("Generate file: `" + path + "`.")
f = open(path, "w")
f.write("/*" + get_version() + "*/\n")
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n\n")
f.write(
"/* This file contains the structure that each system creates with the user defined system arguments. */\n\n"
)
for i in range(max_parameters + 1):
if i == 0:
continue
f.write("template <")
for p in range(i):
f.write("class P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">\n")
f.write("struct SystemExecutionData" + str(i) + " {\n")
for p in range(i):
f.write(" DataFetcher<P" + str(p) + "> p" + str(p) + ";\n")
f.write(" SystemExecutionData" + str(i) + "(World* p_world) :\n")
for p in range(i):
f.write(" p" + str(p) + "(p_world)")
if p < (i - 1):
f.write(",\n")
f.write(" {}\n")
f.write("};\n")
# Generate size_of func
f.write("template <")
for p in range(i):
f.write("class P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">\n")
f.write("uint64_t system_data_size_of() {\n")
f.write(" return sizeof(SystemExecutionData" + str(i) + "<")
for p in range(i):
f.write("P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">);\n")
f.write("}\n")
# Generate new placement func
f.write("template <")
for p in range(i):
f.write("class P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">\n")
f.write("void system_data_new_placement(uint8_t* p_mem, World* p_world) {\n")
f.write(" new (p_mem) SystemExecutionData" + str(i) + "<")
for p in range(i):
f.write("P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">(p_world);\n")
f.write("}\n")
# Generate delete placement func
f.write("template <")
for p in range(i):
f.write("class P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">\n")
f.write("void system_data_delete_placement(uint8_t* p_mem) {\n")
f.write(" ((SystemExecutionData" + str(i) + "<")
for p in range(i):
f.write("P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">*)p_mem)->~SystemExecutionData" + str(i) + "<")
for p in range(i):
f.write("P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">();\n")
f.write("}\n")
# SystemData set world notification active
f.write("template <")
for p in range(i):
f.write("class P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">\n")
f.write("void system_data_set_world_notificatin_active(uint8_t* p_mem, bool p_active) {\n")
f.write(" auto d = ((SystemExecutionData" + str(i) + "<")
for p in range(i):
f.write("P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">*)p_mem);\n")
for p in range(i):
f.write(" d->p" + str(p) + ".set_active(p_active);\n")
f.write("}\n")
f.write("\n")
def internal_generate_system_exe_funcs(system_type, max_parameters, path):
"""Generates the functions needed to process the `System`s."""
if os.path.exists(path) and not is_devel():
# If the path exist and is not in development:
with open(path) as f:
firstline = f.readline().rstrip()
if firstline == "/*" + get_version() + "*/":
# This file is already generated, nothing more to do.
print("This file `" + path + "` is already generated.")
return
print("Generate file: `" + path + "`.")
f = open(path, "w")
f.write("/*" + get_version() + "*/\n")
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
for i in range(max_parameters + 1):
if i == 0:
continue
f.write("template <")
for p in range(i):
f.write("class P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">\n")
if system_type == SystemType.TEMPORARY:
f.write("bool temporary_system_exec_func(uint8_t* p_mem, World *p_world, bool (*p_system)(")
elif system_type == SystemType.DISPATCHER:
f.write("uint32_t system_dispatcher_exec_func(uint8_t* p_mem, World *p_world, uint32_t (*p_system)(")
elif system_type == SystemType.NORMAL:
f.write("void system_exec_func(uint8_t* p_mem, World *p_world, void (*p_system)(")
for p in range(i):
f.write("P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(")) {\n")
f.write(" auto d = ((SystemExecutionData" + str(i) + "<")
for p in range(i):
f.write("P" + str(p))
if p < (i - 1):
f.write(", ")
f.write(">*)p_mem);\n")
for p in range(i):
f.write(" d->p" + str(p) + ".initiate_process(p_world);\n")
if system_type == SystemType.NORMAL:
f.write(" p_system(\n")
else:
f.write(" return p_system(\n")
for p in range(i):
f.write(" d->p" + str(p) + ".inner")
if p < (i - 1):
f.write(",\n")
f.write(");\n")
for p in range(i):
f.write(" d->p" + str(p) + ".conclude_process(p_world);\n")
f.write("}\n")
f.write("\n")
def generate_system_exe_funcs():
"""Generates the functions needed to process the `System`s."""
max_parameters = 30
path = "./systems/system_exe_funcs.gen.h"
internal_generate_system_exe_funcs(SystemType.NORMAL, max_parameters, path)
def generate_system_dispatcher_exe_funcs():
max_parameters = 2
path = "./systems/system_dispatcher_exe_funcs.gen.h"
internal_generate_system_exe_funcs(SystemType.DISPATCHER, max_parameters, path)
def generate_temporary_system_exe_funcs():
max_parameters = 30
path = "./systems/temporary_system_exe_funcs.gen.h"
internal_generate_system_exe_funcs(SystemType.TEMPORARY, max_parameters, path)