Skip to content

Commit 5ca90a5

Browse files
authored
feat: new async stream api (#27)
1 parent 5b2a286 commit 5ca90a5

File tree

8 files changed

+120
-19
lines changed

8 files changed

+120
-19
lines changed

MODULE.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ module(
55
)
66

77
bazel_dep(name = "rules_cc", version = "0.0.9")
8-
bazel_dep(name = "ecsact_runtime", version = "0.6.9")
9-
bazel_dep(name = "ecsact_codegen", version = "0.4.2")
10-
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.8")
11-
bazel_dep(name = "rules_ecsact", version = "0.5.8")
12-
bazel_dep(name = "ecsact_cli", version = "0.3.17")
8+
bazel_dep(name = "ecsact_runtime", version = "0.7.0")
9+
bazel_dep(name = "ecsact_codegen", version = "0.4.3")
10+
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.9")
11+
bazel_dep(name = "rules_ecsact", version = "0.5.7")
12+
bazel_dep(name = "ecsact_cli", version = "0.3.18")
1313
bazel_dep(name = "bazel_skylib", version = "1.4.2")
1414
bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")
1515
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")

async_reference/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ ecsact_build_recipe(
1717
"ecsact_serialize_action_size",
1818
"ecsact_serialize_component",
1919
"ecsact_serialize_component_size",
20+
"ecsact_stream",
2021
],
2122
exports = [
2223
"ecsact_async_connect",
2324
"ecsact_async_disconnect",
2425
"ecsact_async_enqueue_execution_options",
2526
"ecsact_async_flush_events",
2627
"ecsact_async_get_current_tick",
28+
"ecsact_async_stream",
2729
],
2830
)
2931

async_reference/async.cc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <optional>
2-
2+
#include <stdarg.h>
3+
#include <span>
34
#include "ecsact/runtime/async.h"
45
#include "async_reference/async_reference.hh"
56
#include "async_reference/callbacks/async_callbacks.hh"
@@ -60,3 +61,37 @@ int32_t ecsact_async_get_current_tick() {
6061
}
6162
return 0;
6263
}
64+
65+
ecsact_async_request_id ecsact_async_stream(
66+
ecsact_entity_id entity,
67+
ecsact_component_id component_id,
68+
const void* component_data,
69+
const void* indexed_fields
70+
) {
71+
auto req_id = request_id_factory.next_id();
72+
// TODO: indexed fields
73+
if(indexed_fields != nullptr) {
74+
async_callbacks.add(detail::types::async_error{
75+
.error = ECSACT_ASYNC_ERR_INTERNAL,
76+
.request_ids = {req_id},
77+
});
78+
return req_id;
79+
}
80+
81+
if(!reference) {
82+
async_callbacks.add(detail::types::async_error{
83+
.error = ECSACT_ASYNC_ERR_NOT_CONNECTED,
84+
.request_ids = {req_id},
85+
});
86+
return req_id;
87+
}
88+
89+
reference->stream( //
90+
req_id,
91+
entity,
92+
component_id,
93+
component_data,
94+
indexed_fields
95+
);
96+
return req_id;
97+
}

async_reference/async_reference.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <chrono>
22
#include <map>
3-
43
#include "ecsact/runtime/core.h"
54
#include "async_reference/async_reference.hh"
65
#include "async_reference/util/util.hh"
6+
#include "async_reference/util/types.hh"
77

88
using namespace ecsact::async_reference::detail;
99

@@ -199,6 +199,28 @@ void async_reference::execute_systems() {
199199
});
200200
}
201201

202+
void async_reference::stream(
203+
ecsact_async_request_id req_id,
204+
ecsact_entity_id entity,
205+
ecsact_component_id component_id,
206+
const void* component_data,
207+
const void* indexed_fields
208+
) {
209+
if(registry_id) {
210+
auto stream_error = ecsact_stream(
211+
registry_id.value(),
212+
entity,
213+
component_id,
214+
component_data,
215+
indexed_fields
216+
);
217+
218+
async_callbacks.add(types::async_request_complete{{req_id}});
219+
} else {
220+
async_callbacks.add(types::async_request_complete{{req_id}});
221+
}
222+
}
223+
202224
void async_reference::invoke_execution_events(
203225
const ecsact_execution_events_collector* execution_evc
204226
) {

async_reference/async_reference.hh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <thread>
55
#include <atomic>
66
#include <optional>
7-
7+
#include <span>
88
#include "tick_manager/tick_manager.hh"
99
#include "callbacks/execution_callbacks.hh"
1010
#include "callbacks/async_callbacks.hh"
@@ -24,6 +24,14 @@ public:
2424
const ecsact_execution_options& options
2525
);
2626

27+
void stream(
28+
ecsact_async_request_id req_id,
29+
ecsact_entity_id entity,
30+
ecsact_component_id component_id,
31+
const void* component_data,
32+
const void* indexed_fields
33+
);
34+
2735
void execute_systems();
2836

2937
void invoke_execution_events(

async_reference/callbacks/execution_callbacks.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ void execution_callbacks::invoke(
9090
const void* component_data = ecsact_get_component(
9191
registry_id,
9292
component_info.entity_id,
93-
component_info.component_id
93+
component_info.component_id,
94+
nullptr // TODO: indeded fields
9495
);
9596

9697
execution_events->init_callback(
@@ -108,7 +109,8 @@ void execution_callbacks::invoke(
108109
const void* component_data = ecsact_get_component(
109110
registry_id,
110111
component_info.entity_id,
111-
component_info.component_id
112+
component_info.component_id,
113+
nullptr // TODO: indeded fields
112114
);
113115

114116
execution_events->update_callback(

serialize_reference/serialize_reference.cc

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,21 @@ ecsact_restore_error ecsact_restore_entities(
350350
auto component_data =
351351
ecsact::deserialize(component_id, serialized_component_data);
352352

353-
if(ecsact_has_component(registry_id, entity_id, component_id)) {
353+
if(ecsact_has_component(
354+
registry_id,
355+
entity_id,
356+
component_id,
357+
// TODO: indexed fields
358+
nullptr
359+
)) {
354360
if(component_size != 0) {
355361
ecsact_update_component(
356362
registry_id,
357363
entity_id,
358364
component_id,
359-
component_data.data()
365+
component_data.data(),
366+
// TODO: indexed fields
367+
nullptr
360368
);
361369
}
362370
updated_components.push_back({entity_id, component_id});
@@ -396,7 +404,13 @@ ecsact_restore_error ecsact_restore_entities(
396404
ECSACT_EVENT_INIT_COMPONENT,
397405
entity,
398406
comp_id,
399-
ecsact_get_component(registry_id, entity, comp_id),
407+
ecsact_get_component(
408+
registry_id,
409+
entity,
410+
comp_id,
411+
// TODO: indexed fields
412+
nullptr
413+
),
400414
events_collector->init_callback_user_data
401415
);
402416
}
@@ -408,7 +422,13 @@ ecsact_restore_error ecsact_restore_entities(
408422
ECSACT_EVENT_UPDATE_COMPONENT,
409423
entity,
410424
comp_id,
411-
ecsact_get_component(registry_id, entity, comp_id),
425+
ecsact_get_component(
426+
registry_id,
427+
entity,
428+
comp_id,
429+
// TODO: indexed fields
430+
nullptr
431+
),
412432
events_collector->update_callback_user_data
413433
);
414434
}
@@ -420,11 +440,23 @@ ecsact_restore_error ecsact_restore_entities(
420440
ECSACT_EVENT_REMOVE_COMPONENT,
421441
entity,
422442
comp_id,
423-
ecsact_get_component(registry_id, entity, comp_id),
443+
ecsact_get_component(
444+
registry_id,
445+
entity,
446+
comp_id,
447+
// TODO: indexed fields
448+
nullptr
449+
),
424450
events_collector->remove_callback_user_data
425451
);
426452

427-
ecsact_remove_component(registry_id, entity, comp_id);
453+
ecsact_remove_component(
454+
registry_id,
455+
entity,
456+
comp_id,
457+
// TODO: indexed fields
458+
nullptr
459+
);
428460
}
429461
}
430462

test/MODULE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module(name = "ecsact_rt_reference_test")
33
bazel_dep(name = "rules_cc", version = "0.0.9")
44
bazel_dep(name = "bazel_skylib", version = "1.6.1")
55
bazel_dep(name = "googletest", version = "1.14.0")
6-
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.6")
7-
bazel_dep(name = "ecsact_runtime", version = "0.6.7")
6+
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.9")
7+
bazel_dep(name = "ecsact_runtime", version = "0.7.0")
88
bazel_dep(name = "rules_ecsact", version = "0.5.6")
9-
bazel_dep(name = "ecsact_cli", version = "0.3.16")
9+
bazel_dep(name = "ecsact_cli", version = "0.3.18")
1010
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")
1111
bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")
1212
bazel_dep(name = "ecsact_rt_reference")

0 commit comments

Comments
 (0)