1
1
#include " EcsactAsyncRunner.h"
2
2
#include " Ecsact.h"
3
+ #include < span>
3
4
#include " EcsactUnrealExecutionOptions.h"
4
5
#include " EcsactUnrealEventsCollector.h"
5
6
#include " ecsact/runtime/async.h"
6
7
#include " ecsact/runtime/common.h"
7
8
9
+ UEcsactAsyncRunner::UEcsactAsyncRunner () {
10
+ async_evc.async_error_callback = ThisClass::OnAsyncErrorRaw;
11
+ async_evc.system_error_callback = ThisClass::OnExecuteSysErrorRaw;
12
+ async_evc.async_request_done_callback = ThisClass::OnAsyncRequestDoneRaw;
13
+
14
+ async_evc.async_error_callback_user_data = this ;
15
+ async_evc.system_error_callback_user_data = this ;
16
+ async_evc.async_request_done_callback_user_data = this ;
17
+ }
18
+
19
+ auto UEcsactAsyncRunner::OnAsyncErrorRaw (
20
+ ecsact_async_error async_err,
21
+ int request_ids_length,
22
+ ecsact_async_request_id* request_ids_data,
23
+ void * callback_user_data
24
+ ) -> void {
25
+ auto self = static_cast <ThisClass*>(callback_user_data);
26
+ auto request_ids =
27
+ std::span{request_ids_data, static_cast <size_t >(request_ids_length)};
28
+
29
+ for (auto req_id : request_ids) {
30
+ auto cbs = self->RequestErrorCallbacks .Find (req_id);
31
+ if (cbs) {
32
+ for (auto & cb : *cbs) {
33
+ cb.ExecuteIfBound (async_err);
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ auto UEcsactAsyncRunner::OnExecuteSysErrorRaw (
40
+ ecsact_execute_systems_error execute_err,
41
+ void * callback_user_data
42
+ ) -> void {
43
+ auto self = static_cast <ThisClass*>(callback_user_data);
44
+ }
45
+
46
+ auto UEcsactAsyncRunner::OnAsyncRequestDoneRaw (
47
+ int request_ids_length,
48
+ ecsact_async_request_id* request_ids_data,
49
+ void * callback_user_data
50
+ ) -> void {
51
+ auto self = static_cast <ThisClass*>(callback_user_data);
52
+ auto request_ids =
53
+ std::span{request_ids_data, static_cast <size_t >(request_ids_length)};
54
+
55
+ for (auto req_id : request_ids) {
56
+ auto cbs = self->RequestDoneCallbacks .Find (req_id);
57
+ if (cbs) {
58
+ for (auto & cb : *cbs) {
59
+ cb.ExecuteIfBound ();
60
+ }
61
+
62
+ cbs->Empty ();
63
+ }
64
+ }
65
+ }
66
+
8
67
auto UEcsactAsyncRunner::Tick (float DeltaTime) -> void {
9
68
EnqueueExecutionOptions ();
10
69
@@ -15,7 +74,7 @@ auto UEcsactAsyncRunner::Tick(float DeltaTime) -> void {
15
74
if (EventsCollector != nullptr ) {
16
75
evc_c = EventsCollector->GetCEVC ();
17
76
}
18
- ecsact_async_flush_events (evc_c, nullptr );
77
+ ecsact_async_flush_events (evc_c, &async_evc );
19
78
}
20
79
}
21
80
@@ -44,3 +103,21 @@ auto UEcsactAsyncRunner::GetStatId() const -> TStatId {
44
103
STATGROUP_Tickables
45
104
);
46
105
}
106
+
107
+ auto UEcsactAsyncRunner::OnRequestDone (
108
+ ecsact_async_request_id RequestId,
109
+ FAsyncRequestDoneCallback Callback
110
+ ) -> void {
111
+ check (RequestId != ECSACT_INVALID_ID (async_request));
112
+
113
+ RequestDoneCallbacks.FindOrAdd (RequestId).Add (Callback);
114
+ }
115
+
116
+ auto UEcsactAsyncRunner::OnRequestError (
117
+ ecsact_async_request_id RequestId,
118
+ FAsyncRequestErrorCallback Callback
119
+ ) -> void {
120
+ check (RequestId != ECSACT_INVALID_ID (async_request));
121
+
122
+ RequestErrorCallbacks.FindOrAdd (RequestId).Add (Callback);
123
+ }
0 commit comments