Skip to content

Commit f52720d

Browse files
committed
Removed pending registry, opted for serialization instead. Data problems are gone!
1 parent 0857417 commit f52720d

File tree

7 files changed

+64
-202
lines changed

7 files changed

+64
-202
lines changed

reference/async_reference/async_reference.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ ecsact_async_request_id async_reference::connect(const char* connection_string
1111
std::string connect_str(connection_string);
1212

1313
registry_id = ecsact_create_registry("async_reference_impl_reg");
14-
pending_registry_id =
15-
ecsact_create_registry("pending_async_reference_impl_reg");
1614

1715
auto req_id = next_request_id();
1816
// The good and bad strings simulate the outcome of connections
@@ -46,8 +44,7 @@ ecsact_async_request_id async_reference::enqueue_execution_options(
4644
return req_id;
4745
}
4846

49-
auto cpp_options =
50-
util::c_to_cpp_execution_options(options, *pending_registry_id);
47+
auto cpp_options = util::c_to_cpp_execution_options(options);
5148

5249
types::pending_execution_options pending_options{
5350
.request_id = req_id,
@@ -86,11 +83,7 @@ void async_reference::execute_systems() {
8683

8784
if(cpp_options) {
8885
options = std::make_unique<ecsact_execution_options>(
89-
util::cpp_to_c_execution_options(
90-
*cpp_options,
91-
*registry_id,
92-
*pending_registry_id
93-
)
86+
util::cpp_to_c_execution_options(*cpp_options, *registry_id)
9487
);
9588
}
9689

@@ -104,7 +97,6 @@ void async_reference::execute_systems() {
10497

10598
for(auto& entity_request_id : pending_entities) {
10699
auto entity = ecsact_create_entity(*registry_id);
107-
auto pended_entity = ecsact_create_entity(*pending_registry_id);
108100

109101
types::entity created_entity{
110102
.entity_id = entity,

reference/async_reference/async_reference.hh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818
#include "ecsact/runtime/core.hh"
1919
#include "ecsact/runtime/async.h"
2020

21-
// Have one container to hold ALL requests
22-
// Use an std::variant to account for entity and other types
23-
// Separate classes, you are simulating global state by having so much
24-
// functionality that don't involve each other
25-
26-
// Async possibilities:
27-
// Tick manager
28-
// Requests (Async callbacks)
29-
//
30-
3121
class async_reference {
3222
public:
3323
ecsact_async_request_id enqueue_execution_options(
@@ -51,7 +41,6 @@ private:
5141
std::atomic_int32_t _last_request_id = 0;
5242

5343
std::optional<ecsact_registry_id> registry_id;
54-
std::optional<ecsact_registry_id> pending_registry_id;
5544

5645
tick_manager tick_manager;
5746
execution_callbacks exec_callbacks;

reference/async_reference/test/async_ref_test.cc

Lines changed: 13 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -54,99 +54,7 @@ TEST(AsyncRef, Disconnect) {
5454
ecsact_async_disconnect();
5555
}
5656

57-
// TEST(AsyncRef, AddUpdateAndRemove) {
58-
// auto connect_req_id = ecsact_async_connect("good");
59-
60-
// async_test::NeededComponent my_needed_component{};
61-
62-
// ecsact_component needed_component{
63-
// .component_id = async_test::NeededComponent::id,
64-
// .component_data = &my_needed_component,
65-
// };
66-
67-
// async_test::ComponentUpdate my_update_component{};
68-
// auto update_comp_id =
69-
// async_test::ComponentUpdate::id; my_update_component.value_to_update = 1;
70-
// const void* update_component_data = &my_update_component;
71-
72-
// ecsact_component update_component{
73-
// .component_id = update_comp_id,
74-
// .component_data = update_component_data,
75-
// };
76-
77-
// auto entity_request = ecsact_async_create_entity();
78-
79-
// entity_cb_info cb_info{};
80-
81-
// auto entity_cb = //
82-
// [](
83-
// ecsact_entity_id entity_id,
84-
// ecsact_async_request_id request_id,
85-
// void* callback_user_data
86-
// ) {
87-
// entity_cb_info& entity_info =
88-
// *static_cast<entity_cb_info*>(callback_user_data);
89-
// entity_info.wait = true;
90-
// entity_info.entity = entity_id;
91-
// };
92-
93-
// ecsact_async_events_collector async_evc{};
94-
// async_evc.async_entity_callback = entity_cb;
95-
// async_evc.async_entity_error_callback_user_data = &cb_info;
96-
97-
// int check_count = 0;
98-
99-
// while(cb_info.wait != true) {
100-
// ASSERT_LT(++check_count, 10000);
101-
// ecsact_async_flush_events(nullptr, &async_evc);
102-
// }
103-
104-
// std::array<ecsact_component, 2> components{
105-
// needed_component,
106-
// update_component,
107-
// };
108-
// std::array<ecsact_entity_id, 2> components_entities = {
109-
// cb_info.entity,
110-
// cb_info.entity};
111-
112-
// ecsact_execution_options add_options{};
113-
114-
// add_options.add_components_length = components.size();
115-
// add_options.add_components_entities = components_entities.data();
116-
// add_options.add_components = components.data();
117-
118-
// ecsact_async_enqueue_execution_options(add_options);
119-
120-
// ecsact_async_flush_events(nullptr, nullptr);
121-
122-
// my_update_component.value_to_update += 5;
123-
124-
// std::array<ecsact_component, 1> update_components = {update_component};
125-
126-
// ecsact_execution_options update_options{};
127-
// update_options.update_components_length = update_components.size();
128-
// update_options.update_components_entities = components_entities.data();
129-
// update_options.update_components = update_components.data();
130-
131-
// ecsact_async_enqueue_execution_options(update_options);
132-
133-
// ecsact_async_flush_events(nullptr, nullptr);
134-
135-
// std::array<ecsact_component_id, 1> remove_components = {update_comp_id};
136-
137-
// ecsact_execution_options remove_options{};
138-
// remove_options.remove_components_length = 1;
139-
// remove_options.remove_components_entities = components_entities.data();
140-
// remove_options.remove_components = remove_components.data();
141-
142-
// ecsact_async_enqueue_execution_options(remove_options);
143-
144-
// ecsact_async_flush_events(nullptr, nullptr);
145-
146-
// ecsact_async_disconnect();
147-
// }
148-
149-
TEST(AsyncRef, AddUpdateAndRemoveDelayed) {
57+
TEST(AsyncRef, AddUpdateAndRemove) {
15058
using namespace std::chrono_literals;
15159

15260
auto connect_req_id = ecsact_async_connect("good");
@@ -250,10 +158,12 @@ TEST(AsyncRef, TryMergeFailure) {
250158
auto connect_req_id = ecsact_async_connect("good");
251159

252160
async_test::NeededComponent my_needed_component{};
253-
auto needed_comp_id = async_test::NeededComponent::id;
254-
const void* needed_component_data = &my_needed_component;
161+
162+
auto needed_comp_id = async_test::NeededComponent::id;
163+
const void* needed_component_data = &my_needed_component;
255164

256165
async_test::NeededComponent another_my_needed_component{};
166+
257167
auto another_needed_comp_id = async_test::NeededComponent::id;
258168
const void* another_needed_component_data = &my_needed_component;
259169

@@ -300,10 +210,17 @@ TEST(AsyncRef, TryMergeFailure) {
300210
int request_ids_length,
301211
ecsact_async_request_id* request_ids,
302212
void* callback_user_data
303-
) { ASSERT_EQ(async_err, ECSACT_ASYNC_ERR_EXECUTION_MERGE_FAILURE); };
213+
) {
214+
ASSERT_EQ(async_err, ECSACT_ASYNC_ERR_EXECUTION_MERGE_FAILURE);
215+
auto& entity_request =
216+
*reinterpret_cast<ecsact_async_request_id*>(callback_user_data);
217+
auto request_id = request_ids[0];
218+
ASSERT_EQ(entity_request, request_id);
219+
};
304220

305221
ecsact_async_events_collector async_evc{};
306222
async_evc.async_error_callback = async_err_cb;
223+
async_evc.async_error_callback_user_data = &entity_request;
307224

308225
std::array<ecsact_entity_id, 2> entities{cb_info.entity, cb_info.entity};
309226
std::array<ecsact_component, 2> components{

reference/async_reference/test/index.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def ecsact_reference_async_module_test(name = None, srcs = [], deps = [], **kwar
1313
"@ecsact//codegen_plugins:cpp_systems_header",
1414
"@ecsact//codegen_plugins:systems_header",
1515
"@ecsact//codegen_plugins:cpp_systems_source",
16+
"@ecsact_runtime//reference/serialize_reference/codegen",
1617
],
1718
)
1819

@@ -31,6 +32,7 @@ def ecsact_reference_async_module_test(name = None, srcs = [], deps = [], **kwar
3132
"@ecsact_runtime//reference/async_reference:async",
3233
"@com_google_googletest//:gtest",
3334
"@com_google_googletest//:gtest_main",
35+
"@ecsact_runtime//reference/serialize_reference",
3436
],
3537
**kwargs
3638
)

reference/async_reference/util/types.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ struct entity {
2727
};
2828

2929
struct cpp_execution_component {
30-
ecsact_entity_id entity_id;
31-
ecsact_component_id _id;
30+
ecsact_entity_id entity_id;
31+
ecsact_component_id _id;
32+
std::vector<std::byte> data;
3233
};
3334

3435
struct action_info {

0 commit comments

Comments
 (0)