11#include " EcsactUnreal/Blueprint/EcsactAsyncConnectBlueprintAction.h"
2- #include " EcsactUnreal/EcsactExecution.h"
32#include " EcsactUnreal/EcsactAsyncRunnerEvents.h"
3+ #include " EcsactUnreal/EcsactExecution.h"
4+ #include " EcsactUnreal/EcsactAsyncRunner.h"
45#include " ecsact/runtime/async.h"
56#include " EcsactUnreal/Ecsact.h"
67
@@ -21,57 +22,30 @@ auto UEcsactAsyncConnectBlueprintAction::ConnectRequest(
2122) -> void {
2223 UE_LOG (Ecsact, Warning, TEXT (" AsyncConnectActivate()" ));
2324 auto runner = EcsactUnrealExecution::Runner (GetWorld ());
24- auto async_events = Cast<IEcsactAsyncRunnerEvents >(runner);
25- if (!async_events ) {
25+ auto async_runner = Cast<UEcsactAsyncRunner >(runner);
26+ if (!async_runner ) {
2627 UE_LOG (
2728 Ecsact,
2829 Error,
2930 TEXT (" Cannot use Ecsact async blueprint api with runner that does not "
30- " implement IEcsactAsyncRunnerEvents " )
31+ " inherit UEcsactAsyncRunner " )
3132 );
32- OnError.Broadcast (EAsyncConnectError::AsyncRunnerEventsUnavailable);
33- OnDone.Broadcast ({});
34- return ;
35- }
36-
37- auto req_id = ecsact_async_connect (ConnectionString.c_str ());
38- UE_LOG (Ecsact, Warning, TEXT (" async connect request id=%i" ), req_id);
39-
40- if (req_id == ECSACT_INVALID_ID (async_request)) {
41- UE_LOG (Ecsact, Error, TEXT (" Invalid Request ID" ));
42- OnError.Broadcast (EAsyncConnectError::InvalidRequestId);
33+ OnError.Broadcast (EAsyncConnectError::AsyncRunnerUnavailable);
4334 OnDone.Broadcast ({});
4435 return ;
4536 }
4637
47- async_events->OnRequestDone (
48- req_id,
49- IEcsactAsyncRunnerEvents::FAsyncRequestDoneCallback::CreateUObject (
50- this ,
51- &ThisClass::OnRequestDone
52- )
38+ SessionEventHandle = async_runner->AsyncSessionEvent .AddUObject (
39+ this ,
40+ &ThisClass::OnAsyncSessionEvent
5341 );
5442
55- async_events->OnRequestError (
56- req_id,
57- IEcsactAsyncRunnerEvents::FAsyncRequestErrorCallback::CreateUObject (
58- this ,
59- &ThisClass::OnRequestError
60- )
43+ async_runner->AsyncSessionStart (
44+ ConnectionString.c_str (),
45+ static_cast <int32_t >(ConnectionString.size ())
6146 );
6247}
6348
64- auto UEcsactAsyncConnectBlueprintAction::OnRequestDone () -> void {
65- auto runner = EcsactUnrealExecution::Runner (GetWorld ());
66- auto async_events = Cast<IEcsactAsyncRunnerEvents>(runner);
67- UE_LOG (Ecsact, Error, TEXT (" OnRequestDone??" ));
68- if (!bConnectFailed) {
69- async_events->TriggerGenericConnectCallbacks ();
70- OnSuccess.Broadcast ({});
71- }
72- OnDone.Broadcast ({});
73- }
74-
7549auto UEcsactAsyncConnectBlueprintAction::OnRequestError ( //
7650 ecsact_async_error Error
7751) -> void {
@@ -84,6 +58,28 @@ auto UEcsactAsyncConnectBlueprintAction::OnRequestError( //
8458 OnError.Broadcast (EAsyncConnectError::InvalidConnectionString);
8559 break ;
8660 }
61+ }
8762
88- bConnectFailed = true ;
63+ auto UEcsactAsyncConnectBlueprintAction::OnAsyncSessionEvent ( //
64+ int32 SessionId,
65+ EEcsactAsyncSessionEvent Event
66+ ) -> void {
67+ auto runner = EcsactUnrealExecution::Runner (GetWorld ());
68+ auto async_runner = Cast<UEcsactAsyncRunner>(runner);
69+
70+ if (async_runner) {
71+ switch (Event) {
72+ case EEcsactAsyncSessionEvent::Stopped:
73+ async_runner->AsyncSessionEvent .Remove (SessionEventHandle);
74+ OnDone.Broadcast ({});
75+ break ;
76+ case EEcsactAsyncSessionEvent::Started:
77+ async_runner->AsyncSessionEvent .Remove (SessionEventHandle);
78+ OnSuccess.Broadcast ({});
79+ OnDone.Broadcast ({});
80+ break ;
81+ default :
82+ break ;
83+ }
84+ }
8985}
0 commit comments