Skip to content

Commit e6574ec

Browse files
committed
chore: wip
1 parent 36844fd commit e6574ec

12 files changed

+460
-58
lines changed

ecsact/entt/detail/system_execution_context.hh

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,44 @@ struct ecsact_system_execution_context {
3434

3535
ecsact::entt::entity_id entity;
3636

37-
// This is set by the system_execution_context::other method. `0` means
38-
// no association.
39-
ecsact::entt::assoc_index association_index = {};
37+
virtual ~ecsact_system_execution_context() = default;
38+
39+
virtual auto action( //
40+
void* out_action_data
41+
) -> void = 0;
42+
43+
virtual auto add( //
44+
ecsact_component_like_id component_id,
45+
const void* component_data
46+
) -> void = 0;
47+
48+
virtual auto remove( //
49+
ecsact_component_like_id component_id
50+
) -> void = 0;
51+
52+
virtual auto get( //
53+
ecsact_component_like_id component_id,
54+
void* out_component_data
55+
) -> void = 0;
56+
57+
virtual auto update( //
58+
ecsact_component_like_id component_id,
59+
const void* component_data
60+
) -> void = 0;
61+
62+
virtual auto has( //
63+
ecsact_component_like_id component_id
64+
) -> bool = 0;
65+
66+
virtual auto generate( //
67+
int component_count,
68+
ecsact_component_id* component_ids,
69+
const void** components_data
70+
) -> void = 0;
71+
72+
virtual auto parent() -> const ecsact_system_execution_context* = 0;
73+
74+
virtual auto other( //
75+
ecsact_entity_id entity
76+
) -> ecsact_system_execution_context* = 0;
4077
};

ecsact/entt/entity.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class entity_id {
1414
std::int32_t _id;
1515

1616
public:
17+
inline entity_id() {
18+
}
19+
1720
inline entity_id(::entt::entity entt_entity)
1821
: _id(reinterpret_cast<std::int32_t&>(entt_entity)) {
1922
}

ecsact/entt/execution.hh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <type_traits>
88
#include "ecsact/runtime/common.h"
99
#include "entt/entity/registry.hpp"
10+
#include "ecsact/entt/detail/globals.hh"
1011

1112
namespace ecsact::entt::detail {
1213
template<typename>
@@ -15,6 +16,20 @@ constexpr bool unimplemented_by_codegen = false;
1516

1617
namespace ecsact::entt {
1718

19+
template<typename S>
20+
auto get_system_impl() -> ecsact_system_execution_impl {
21+
using ecsact::entt::detail::globals::system_impls;
22+
23+
const auto sys_like_id = ecsact_id_cast<ecsact_system_like_id>(S::id);
24+
25+
auto sys_impl_itr = system_impls.find(sys_like_id);
26+
if(sys_impl_itr != system_impls.end()) {
27+
return sys_impl_itr->second;
28+
} else {
29+
return nullptr;
30+
}
31+
}
32+
1833
struct actions_map {
1934
using raw_value_t =
2035
std::unordered_map<ecsact_action_id, std::vector<const void*>>;

rt_entt_codegen/core/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ _CORE_CODEGEN_METHODS = {
1414
"execute_systems": [],
1515
"create_registry": [],
1616
"execute_system_like_template_specializations": [],
17+
"check_error_template_specializations": [],
1718
}
1819

1920
[cc_library(
@@ -27,6 +28,7 @@ _CORE_CODEGEN_METHODS = {
2728
"@ecsact_runtime//:meta",
2829
"@ecsact_runtime//:codegen_plugin_cc",
2930
"@ecsact_lang_cpp//:support",
31+
"@ecsact_lang_cpp//:cpp_codegen_plugin_util",
3032
],
3133
) for method in _CORE_CODEGEN_METHODS]
3234

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "core.hh"
2+
3+
#include <ranges>
4+
#include "ecsact/lang-support/lang-cc.hh"
5+
#include "ecsact/cpp_codegen_plugin_util.hh"
6+
#include "rt_entt_codegen/shared/util.hh"
7+
8+
static auto print_check_add_component_error_template_specialization(
9+
ecsact::codegen_plugin_context& ctx,
10+
const ecsact::rt_entt_codegen::ecsact_entt_details& details,
11+
ecsact_component_id component_id
12+
) -> void {
13+
using ecsact::cpp_codegen_plugin_util::method_printer;
14+
using ecsact::rt_entt_codegen::util::decl_cpp_ident;
15+
16+
auto cpp_component_ident = decl_cpp_ident(component_id);
17+
18+
const auto method_name =
19+
"ecsact::entt::check_add_component_error<" + cpp_component_ident + ">";
20+
21+
ctx.write("template<>\n");
22+
23+
auto printer = //
24+
method_printer{ctx, method_name}
25+
.parameter("::entt::registry&", "registry")
26+
.parameter("::ecsact::entt::entity_id", "entity")
27+
.parameter(cpp_component_ident + " const&", "component")
28+
.return_type("ecsact_add_error");
29+
30+
ctx.write("return ECSACT_ADD_OK;");
31+
}
32+
33+
static auto print_check_update_component_error_template_specialization(
34+
ecsact::codegen_plugin_context& ctx,
35+
const ecsact::rt_entt_codegen::ecsact_entt_details& details,
36+
ecsact_component_id component_id
37+
) -> void {
38+
using ecsact::cpp_codegen_plugin_util::method_printer;
39+
using ecsact::rt_entt_codegen::util::decl_cpp_ident;
40+
41+
auto cpp_component_ident = decl_cpp_ident(component_id);
42+
43+
const auto method_name =
44+
"ecsact::entt::check_update_component_error<" + cpp_component_ident + ">";
45+
46+
ctx.write("template<>\n");
47+
48+
auto printer = //
49+
method_printer{ctx, method_name}
50+
.parameter("::entt::registry&", "registry")
51+
.parameter("::ecsact::entt::entity_id", "entity")
52+
.parameter(cpp_component_ident + " const&", "component")
53+
.return_type("ecsact_update_error");
54+
55+
ctx.write("return ECSACT_UPDATE_OK;");
56+
}
57+
58+
auto ecsact::rt_entt_codegen::core::print_check_error_template_specializations(
59+
codegen_plugin_context& ctx,
60+
const ecsact_entt_details& details
61+
) -> void {
62+
for(auto comp_id : details.all_components) {
63+
print_check_add_component_error_template_specialization(
64+
ctx,
65+
details,
66+
comp_id
67+
);
68+
}
69+
70+
for(auto comp_id : details.all_components) {
71+
print_check_update_component_error_template_specialization(
72+
ctx,
73+
details,
74+
comp_id
75+
);
76+
}
77+
}

rt_entt_codegen/core/core.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ auto print_execute_system_like_template_specializations( //
2121
const ecsact_entt_details& details
2222
) -> void;
2323

24+
auto print_check_error_template_specializations( //
25+
codegen_plugin_context& ctx,
26+
const ecsact_entt_details& details
27+
) -> void;
28+
2429
} // namespace ecsact::rt_entt_codegen::core

0 commit comments

Comments
 (0)