Skip to content

Commit 75627d8

Browse files
committed
chore: wip
1 parent 27b375e commit 75627d8

File tree

5 files changed

+81
-77
lines changed

5 files changed

+81
-77
lines changed

ecsact/entt/detail/apply_pending.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ auto apply_pending_add(ecsact::entt::registry_t& registry) -> void {
1111
if constexpr(std::is_empty_v<C>) {
1212
registry.view<pending_add<C>>().each([&](auto entity) {
1313
C& comp = registry.emplace<C>(entity);
14-
lifecycle_on_add<C>(registry, entity, comp);
14+
// lifecycle_on_add<C>(registry, entity, comp);
1515
});
1616
} else {
1717
registry.view<pending_add<C>>().each( //
1818
[&](auto entity, const pending_add<C>& comp) {
19-
C& comp = registry.emplace<C>(entity, comp.value);
19+
registry.emplace<C>(entity, comp.value);
2020
registry
2121
.emplace<exec_beforechange_storage<C>>(entity, comp.value, false);
2222
add_system_markers_if_needed<C>(registry, entity);
23-
lifecycle_on_add<C>(registry, entity, comp);
23+
// lifecycle_on_add<C>(registry, entity, comp.value);
2424
}
2525
);
2626
}

ecsact/entt/detail/internal_lifecycle.hh

Lines changed: 0 additions & 53 deletions
This file was deleted.

rt_entt_codegen/core/system_provider/association/association.cc

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,29 @@ auto provider::association::initialization(
2828
) -> void {
2929
auto assoc_ids = ecsact::meta::system_assoc_ids(sys_like_id);
3030
for(auto assoc_id : assoc_ids) {
31+
auto assoc_comp_id =
32+
ecsact::meta::system_assoc_component_id(sys_like_id, assoc_id);
33+
auto assoc_field_ids =
34+
ecsact::meta::system_assoc_fields(sys_like_id, assoc_id);
3135
assoc_view_names.insert({assoc_id, get_unique_view_name()});
36+
37+
for(auto field_id : assoc_field_ids) {
38+
auto field_type = ecsact::meta::get_field_type(assoc_comp_id, field_id);
39+
if(field_type.kind == ECSACT_TYPE_KIND_BUILTIN &&
40+
field_type.type.builtin == ECSACT_ENTITY_TYPE) {
41+
auto compo_id = ecsact_id_cast<ecsact_composite_id>(assoc_comp_id);
42+
assoc_fields[compo_id].push_back(field_id);
43+
assoc_composites[assoc_id].insert(compo_id);
44+
} else if(field_type.kind == ECSACT_TYPE_KIND_FIELD_INDEX) {
45+
auto compo_id = field_type.type.field_index.composite_id;
46+
assoc_fields[compo_id].push_back(field_id);
47+
assoc_composites[assoc_id].insert(compo_id);
48+
} else {
49+
// Should never get here. Association fields may only be an indexed
50+
// field or entity field.
51+
assert(false);
52+
}
53+
}
3254
}
3355
}
3456

@@ -84,35 +106,45 @@ auto provider::association::entity_iteration(
84106
make_view_opts.view_var_name = assoc_view_names.at(assoc_id);
85107
make_view_opts.registry_var_name = names.registry_var_name;
86108

109+
for(auto compo_id : assoc_composites.at(assoc_id)) {
110+
}
111+
87112
util::make_view(ctx, make_view_opts);
88113
}
89114

115+
for(auto&& [assoc_id, compo_ids] : assoc_composites) {
116+
for(auto compo_id : compo_ids) {
117+
auto field_ids = assoc_fields.at(compo_id);
118+
auto compo_cpp_ident = cpp_identifier(decl_full_name(compo_id));
119+
120+
ctx.write(std::format(
121+
"{0}.storage({3}.storage<{1}>(static_cast<::entt::id_type>(::ecsact::"
122+
"entt::detail::"
123+
"hash_vals({1}::"
124+
"id, {2}))));\n",
125+
assoc_view_names.at(assoc_id),
126+
compo_cpp_ident,
127+
util::comma_delim(
128+
field_ids |
129+
std::views::transform([&](auto field_id) -> std::string {
130+
return std::format(
131+
"view.get<{}>(entity).{}",
132+
compo_cpp_ident,
133+
ecsact::meta::field_name(compo_id, field_id)
134+
);
135+
})
136+
),
137+
names.registry_var_name
138+
));
139+
}
140+
}
141+
90142
for(auto assoc_id : ecsact::meta::system_assoc_ids(sys_like_id)) {
91143
auto assoc_comp_id =
92144
ecsact::meta::system_assoc_component_id(sys_like_id, assoc_id);
93145
auto assoc_field_ids =
94146
ecsact::meta::system_assoc_fields(sys_like_id, assoc_id);
95147
auto assoc_comp_cpp_ident = cpp_identifier(decl_full_name(assoc_comp_id));
96-
97-
ctx.write(std::format(
98-
"{0}.storage({3}.storage<{1}>(static_cast<::entt::id_type>(::ecsact::"
99-
"entt::detail::"
100-
"hash_vals({1}::"
101-
"id, {2}))));\n",
102-
assoc_view_names.at(assoc_id),
103-
assoc_comp_cpp_ident,
104-
util::comma_delim(
105-
assoc_field_ids |
106-
std::views::transform([&](auto field_id) -> std::string {
107-
return std::format(
108-
"view.get<{}>(entity).{}",
109-
assoc_comp_cpp_ident,
110-
ecsact::meta::field_name(assoc_comp_id, field_id)
111-
);
112-
})
113-
),
114-
names.registry_var_name
115-
));
116148
}
117149

118150
for(auto assoc_id : ecsact::meta::system_assoc_ids(sys_like_id)) {

rt_entt_codegen/core/system_provider/association/association.hh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <string>
44
#include <map>
5+
#include <set>
56
#include "rt_entt_codegen/core/system_provider/system_provider.hh"
67
#include "rt_entt_codegen/core/sys_exec/sys_exec.hh"
78
#include "rt_entt_codegen/core/system_provider/system_ctx_functions.hh"
@@ -53,7 +54,13 @@ public:
5354
) -> handle_exclusive_provide final;
5455

5556
private:
56-
std::map<ecsact_system_assoc_id, std::string> assoc_view_names;
57+
std::map<ecsact_system_assoc_id, std::string> assoc_view_names;
58+
std::map<ecsact_composite_id, std::vector<ecsact_field_id>> assoc_fields;
59+
60+
// List of composites the association needs to read from in their view/group
61+
// due to indexed fields.
62+
std::map<ecsact_system_assoc_id, std::set<ecsact_composite_id>>
63+
assoc_composites;
5764

5865
auto print_other_contexts(
5966
ecsact::codegen_plugin_context& ctx,

runtime/hash.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ auto ecsact::entt::detail::bytes_hash( //
55
std::byte* data,
66
int data_length
77
) -> std::uint64_t {
8+
if(data_length == sizeof(std::uint64_t)) {
9+
auto bytes_as_u64 = std::uint64_t{};
10+
std::memcpy(&bytes_as_u64, data, sizeof(std::uint64_t));
11+
return bytes_as_u64;
12+
} else if(data_length == sizeof(std::uint32_t)) {
13+
auto bytes_as_u32 = std::uint32_t{};
14+
std::memcpy(&bytes_as_u32, data, sizeof(std::uint32_t));
15+
return bytes_as_u32;
16+
} else if(data_length == sizeof(std::uint16_t)) {
17+
auto bytes_as_u16 = std::uint16_t{};
18+
std::memcpy(&bytes_as_u16, data, sizeof(std::uint16_t));
19+
return bytes_as_u16;
20+
} else if(data_length == 1) {
21+
return static_cast<std::uint64_t>(data[0]);
22+
} else if(data_length == 0) {
23+
return 0;
24+
}
25+
826
XXH64_hash_t hash = XXH3_64bits(data, data_length);
927
return hash;
1028
}

0 commit comments

Comments
 (0)