Skip to content

Commit b94cfcb

Browse files
authored
feat: lazy systems (#94)
1 parent e6befa7 commit b94cfcb

22 files changed

+582
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ user.bazelrc
33
compile_commands.json
44
external
55
.cache
6+
/test/codegen_test

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ bazel_dep(name = "rules_cc", version = "0.0.9")
88
bazel_dep(name = "bazel_skylib", version = "1.5.0")
99
bazel_dep(name = "rules_ecsact", version = "0.5.0")
1010
bazel_dep(name = "ecsact_runtime", version = "0.6.1")
11-
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.0")
11+
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.1")
1212
bazel_dep(name = "boost.mp11", version = "1.83.0.bzl.1")
1313
bazel_dep(name = "entt", version = "3.12.2")
1414
bazel_dep(name = "ecsact_codegen", version = "0.2.0")
1515
bazel_dep(name = "ecsact_cli", version = "0.3.4")
16+
bazel_dep(name = "xxhash", version = "0.8.2")
1617

1718
bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
1819
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
19-
2020
git_override(
2121
module_name = "hedron_compile_commands",
2222
commit = "204aa593e002cbd177d30f11f54cff3559110bb9",

MODULE.bazel.lock

Lines changed: 37 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecsact/entt/detail/bytes.hh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#pragma once
2+
3+
#include <concepts>
4+
#include <array>
5+
#include <bit>
6+
#include <type_traits>
7+
#include <cstddef>
8+
9+
namespace ecsact::entt::detail {
10+
11+
template<typename T>
12+
requires(std::integral<T> || std::floating_point<T>)
13+
constexpr auto bytes_sizeof() -> int {
14+
using value_type = std::remove_cvref_t<T>;
15+
16+
if constexpr(std::is_same_v<value_type, bool>) {
17+
return 1;
18+
} else {
19+
return sizeof(value_type);
20+
}
21+
}
22+
23+
template<typename T>
24+
struct unsigned_bit_size_equivalent;
25+
26+
template<typename T>
27+
requires(bytes_sizeof<T>() == 1)
28+
struct unsigned_bit_size_equivalent<T> : std::type_identity<uint8_t> {};
29+
30+
template<typename T>
31+
requires(bytes_sizeof<T>() == 2)
32+
struct unsigned_bit_size_equivalent<T> : std::type_identity<uint16_t> {};
33+
34+
template<typename T>
35+
requires(bytes_sizeof<T>() == 4)
36+
struct unsigned_bit_size_equivalent<T> : std::type_identity<uint32_t> {};
37+
38+
template<typename T>
39+
requires(bytes_sizeof<T>() == 8)
40+
struct unsigned_bit_size_equivalent<T> : std::type_identity<uint64_t> {};
41+
42+
template<typename T>
43+
using unsigned_bit_size_equivalent_t = unsigned_bit_size_equivalent<T>::type;
44+
45+
template<typename T>
46+
requires(std::integral<T> || std::floating_point<T>)
47+
auto bytes_copy_into( //
48+
T v,
49+
auto& out_bytes,
50+
auto& out_bytes_offset = 0
51+
) -> void {
52+
using value_type = std::remove_cvref_t<T>;
53+
constexpr auto value_size = bytes_sizeof<T>();
54+
55+
auto v_bits = std::bit_cast<unsigned_bit_size_equivalent_t<T>>(v);
56+
57+
if constexpr(std::is_same_v<value_type, bool>) {
58+
out_bytes[out_bytes_offset++] = static_cast<std::byte>(v_bits ? 1 : 0);
59+
} else if constexpr(value_size == 1) {
60+
out_bytes[out_bytes_offset++] = static_cast<std::byte>(v_bits);
61+
} else if constexpr(value_size == 2) {
62+
out_bytes[out_bytes_offset++] =
63+
static_cast<std::byte>((v_bits >> 8) & 0xFF);
64+
out_bytes[out_bytes_offset++] = static_cast<std::byte>(v_bits & 0xFF);
65+
} else if constexpr(value_size == 4) {
66+
out_bytes[out_bytes_offset++] =
67+
static_cast<std::byte>((v_bits >> 24) & 0xFF);
68+
out_bytes[out_bytes_offset++] =
69+
static_cast<std::byte>((v_bits >> 16) & 0xFF);
70+
out_bytes[out_bytes_offset++] =
71+
static_cast<std::byte>((v_bits >> 8) & 0xFF);
72+
out_bytes[out_bytes_offset++] = static_cast<std::byte>(v_bits & 0xFF);
73+
} else if constexpr(value_size == 8) {
74+
out_bytes[out_bytes_offset++] =
75+
static_cast<std::byte>((v_bits >> 56) & 0xFF);
76+
out_bytes[out_bytes_offset++] =
77+
static_cast<std::byte>((v_bits >> 48) & 0xFF);
78+
out_bytes[out_bytes_offset++] =
79+
static_cast<std::byte>((v_bits >> 40) & 0xFF);
80+
out_bytes[out_bytes_offset++] =
81+
static_cast<std::byte>((v_bits >> 32) & 0xFF);
82+
out_bytes[out_bytes_offset++] =
83+
static_cast<std::byte>((v_bits >> 24) & 0xFF);
84+
out_bytes[out_bytes_offset++] =
85+
static_cast<std::byte>((v_bits >> 16) & 0xFF);
86+
out_bytes[out_bytes_offset++] =
87+
static_cast<std::byte>((v_bits >> 8) & 0xFF);
88+
out_bytes[out_bytes_offset++] = static_cast<std::byte>(v_bits & 0xFF);
89+
}
90+
91+
static_assert(value_size <= 8);
92+
}
93+
94+
template<typename... T>
95+
auto bytes_copy( //
96+
T... values
97+
) -> std::array<std::byte, (0 + ... + bytes_sizeof<T>())> {
98+
auto result = std::array<std::byte, (0 + ... + bytes_sizeof<T>())>{};
99+
auto offset = 0;
100+
(bytes_copy_into(values, result, offset), ...);
101+
return result;
102+
}
103+
104+
} // namespace ecsact::entt::detail

ecsact/entt/detail/hash.hh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <cstddef>
5+
6+
namespace ecsact::entt::detail {
7+
/**
8+
* Opaque hash algorithm used by the Ecsact EnTT Runtime
9+
*
10+
* @param data bytes to hash
11+
* @param data_length length of @p data
12+
* @returns hash value
13+
*/
14+
auto bytes_hash( //
15+
std::byte* data,
16+
int data_length
17+
) -> std::uint64_t;
18+
} // namespace ecsact::entt::detail

ecsact/entt/detail/internal_markers.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ struct created_entity {
6262

6363
struct destroyed_entity {};
6464

65+
template<typename S>
66+
struct system_sorted;
67+
68+
template<typename S>
69+
struct pending_lazy_execution {};
70+
6571
} // namespace ecsact::entt::detail

rt_entt_codegen/core/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ _CORE_CODEGEN_METHODS = {
2222
],
2323
"check_error_template_specializations": [],
2424
"execution_options": [],
25+
"sorting_components": [],
2526
}
2627

2728
[cc_library(

rt_entt_codegen/core/core.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ auto print_cleanup_ecsact_component_events( //
5151
const ecsact_entt_details& details
5252
) -> void;
5353

54+
auto print_entity_sorting_components( //
55+
codegen_plugin_context& ctx,
56+
const ecsact_entt_details& details
57+
) -> void;
58+
5459
} // namespace ecsact::rt_entt_codegen::core

rt_entt_codegen/core/create_registry.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ auto ecsact::rt_entt_codegen::core::print_create_registry( //
1616
.return_type("ecsact_registry_id");
1717

1818
ctx.write("auto&& [registry_id, reg] = ecsact::entt::create_registry();\n\n");
19-
20-
if(!details.group_systems.empty()) {
21-
ctx.write(
22-
"// These groups were automatically selected based on the input ecsact "
23-
"files\n"
24-
);
25-
for(auto sys_id : details.group_systems) {
26-
auto decl_name = ecsact::meta::decl_full_name(sys_id);
27-
}
28-
}
29-
3019
ctx.write("ecsact_init_registry_storage(registry_id);\n");
31-
3220
ctx.write("\nreturn registry_id;");
3321
}

0 commit comments

Comments
 (0)