Skip to content

Commit 63f129c

Browse files
authored
feat: lazy execution values in meta codegen (#133)
1 parent e2ce8de commit 63f129c

File tree

6 files changed

+85
-2
lines changed

6 files changed

+85
-2
lines changed

cpp_meta_header_codegen/cpp_meta_header_codegen.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,23 @@ static void write_fields_info_constexpr(
436436
ctx.write("\n}\n");
437437
}
438438

439+
static inline auto write_lazy_system_iteration_rate( //
440+
ecsact::codegen_plugin_context& ctx,
441+
ecsact_system_id id
442+
) -> void {
443+
using ecsact::cc_lang_support::cpp_identifier;
444+
445+
auto lazy_iteration_rate = ecsact_meta_get_lazy_iteration_rate(id);
446+
447+
ctx.write(
448+
"template<> struct ecsact::system_lazy_execution_iteration_rate<",
449+
cpp_identifier(get_sys_full_name(ctx.package_id, id)),
450+
"> : std::integral_constant<int32_t, ",
451+
lazy_iteration_rate,
452+
"> {};"
453+
);
454+
}
455+
439456
void ecsact_codegen_plugin(
440457
ecsact_package_id package_id,
441458
ecsact_codegen_write_fn_t write_fn
@@ -594,4 +611,8 @@ void ecsact_codegen_plugin(
594611
for(auto& act_id : ecsact::meta::get_action_ids(ctx.package_id)) {
595612
write_system_capabilities_info_struct(ctx, act_id);
596613
}
614+
615+
for(auto& sys_id : ecsact::meta::get_system_ids(ctx.package_id)) {
616+
write_lazy_system_iteration_rate(ctx, sys_id);
617+
}
597618
}

ecsact/cpp/type_info.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ template<typename SystemT>
3131
struct system_lazy_execution_iteration_rate;
3232

3333
template<typename SystemT>
34-
using system_lazy_execution_iteration_rate_v =
35-
typename system_lazy_execution_iteration_rate<SystemT>::value;
34+
constexpr auto system_lazy_execution_iteration_rate_v =
35+
system_lazy_execution_iteration_rate<SystemT>::value;
3636

3737
template<typename SystemLikeT>
3838
struct system_capabilities_info {

test/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ cc_library(
8080
],
8181
)
8282

83+
cc_library(
84+
name = "meta_check",
85+
copts = copts,
86+
srcs = ["meta_check.cc"],
87+
deps = [
88+
"//:ecsact_cc",
89+
"@ecsact_lang_cpp//:type_info",
90+
"@ecsact_runtime//:lib",
91+
],
92+
)
93+
8394
cc_binary(
8495
name = "example_system_impls",
8596
copts = copts,

test/example.ecsact

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ system ExampleSystemFromImports {
88
readwrite pkg.b.ExampleB;
99
}
1010

11+
system ExampleLazy(lazy) {
12+
readwrite pkg.a.ExampleA;
13+
}
14+
15+
system LazyLeap(lazy: 24) {
16+
readwrite pkg.b.ExampleB;
17+
}
18+
19+
system ExplicitlyNoLazy(lazy: false) {
20+
readwrite pkg.b.ExampleB;
21+
}
22+
23+
system ExplicitlyNoLazyZero(lazy: 0) {
24+
readwrite pkg.b.ExampleB;
25+
}
26+

test/meta_check.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "example.ecsact.meta.hh"
2+
3+
static_assert(
4+
ecsact::system_lazy_execution_iteration_rate_v<
5+
example::ExampleSystemFromImports> == 0
6+
);
7+
8+
static_assert(
9+
ecsact::system_lazy_execution_iteration_rate_v<example::ExampleLazy> == 1
10+
);
11+
12+
static_assert(
13+
ecsact::system_lazy_execution_iteration_rate_v<example::LazyLeap> == 24
14+
);
15+
16+
static_assert(
17+
ecsact::system_lazy_execution_iteration_rate_v<example::ExplicitlyNoLazy> == 0
18+
);
19+
20+
static_assert(
21+
ecsact::system_lazy_execution_iteration_rate_v<
22+
example::ExplicitlyNoLazyZero> == 0
23+
);

test/system_impls.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ void example::ExampleSystemFromImports::impl(context& ctx) {
1010
ctx.update(a);
1111
ctx.update(b);
1212
}
13+
14+
void example::ExampleLazy::impl(context&) {
15+
}
16+
17+
void example::LazyLeap::impl(context&) {
18+
}
19+
20+
void example::ExplicitlyNoLazy::impl(context&) {
21+
}
22+
23+
void example::ExplicitlyNoLazyZero::impl(context&) {
24+
}

0 commit comments

Comments
 (0)