Skip to content

Commit

Permalink
refactor: make RUN_LATENT_EXECUTION() wrap the co_await
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonetfal committed Jan 13, 2024
1 parent 71b9db7 commit 3853cbe
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ UE5FSM_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_StateMachine_Label_Default);

#define TO_STR(x) #x
#define RUN_LATENT_EXECUTION(FUNCTION, ...) \
RunLatentExecutionExt(LIFT(FUNCTION), *FString::Printf(TEXT("Caller function [%s] Line [%d] Latent function [%s]"), \
co_await RunLatentExecutionExt(LIFT(FUNCTION), *FString::Printf( \
TEXT("Caller function [%s] Line [%d] Latent function [%s]"), \
*FString(__FUNCTION__), __LINE__, *FString(TO_STR(FUNCTION))), ## __VA_ARGS__)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

TCoroutine<> UMachineState_ExternalPushPopTest::Label_Default()
{
co_await RUN_LATENT_EXECUTION(Latent::Seconds, 0.5);
RUN_LATENT_EXECUTION(Latent::Seconds, 0.5);
BROADCAST_TEST_MESSAGE("Post default label", true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ TCoroutine<> UMachineState_ExternalPushTest::Label_Default()
while (true)
{
BROADCAST_TEST_MESSAGE("Hello", true);
co_await RUN_LATENT_EXECUTION(Latent::Seconds, 0.4f);
RUN_LATENT_EXECUTION(Latent::Seconds, 0.4f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TCoroutine<> UMachineState_GotoStateTest1::Label_Default()
BROADCAST_TEST_MESSAGE("Goto test 2 fail", true);

// Wait one tick to due to the reason described above
co_await RUN_LATENT_EXECUTION(Latent::NextTick);
RUN_LATENT_EXECUTION(Latent::NextTick);

BROADCAST_TEST_MESSAGE("Pre goto test 2", true);
GOTO_STATE(UMachineState_GotoStateTest2);
Expand All @@ -21,7 +21,7 @@ TCoroutine<> UMachineState_GotoStateTest1::Label_Default()

TCoroutine<> UMachineState_GotoStateTest2::Label_Default()
{
co_await RUN_LATENT_EXECUTION(Latent::Seconds, 1.0);
RUN_LATENT_EXECUTION(Latent::Seconds, 1.0);
BROADCAST_TEST_MESSAGE("End test", true);
co_return;
}
Expand All @@ -32,7 +32,7 @@ TCoroutine<> UMachineState_LatentExecutionTest1::Label_Default()
GetTimerManager().SetTimer(TimerHandle, this, &ThisClass::PushLatentExecutionTest2, 1.f, false);

BROADCAST_TEST_MESSAGE("Pre sleep", true);
co_await RUN_LATENT_EXECUTION(Latent::Seconds, 2.0);
RUN_LATENT_EXECUTION(Latent::Seconds, 2.0);
BROADCAST_TEST_MESSAGE("Post sleep", true);
BROADCAST_TEST_MESSAGE("End test", true);
}
Expand All @@ -47,7 +47,7 @@ void UMachineState_LatentExecutionTest1::PushLatentExecutionTest2()
TCoroutine<> UMachineState_LatentExecutionTest2::Label_Default()
{
BROADCAST_TEST_MESSAGE("Pre sleep", true);
co_await RUN_LATENT_EXECUTION(Latent::Seconds, 3.5);
RUN_LATENT_EXECUTION(Latent::Seconds, 3.5);
BROADCAST_TEST_MESSAGE("Post sleep", true);
BROADCAST_TEST_MESSAGE("Pre pop", true);
POP_STATE();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TCoroutine<> UMachineState_PushPopTest::Label_Default()
BROADCAST_TEST_MESSAGE("Before test label activation", true);

// Should be cancelled by the test label
co_await RUN_LATENT_EXECUTION(Latent::Seconds, 120.0);
RUN_LATENT_EXECUTION(Latent::Seconds, 120.0);
BROADCAST_TEST_MESSAGE("Latent execution has been cancelled", true);
}
}
Expand All @@ -46,10 +46,10 @@ TCoroutine<> UMachineState_PushPopTest::Label_Test()

if (IsValid(LatentPushState))
{
co_await RUN_LATENT_EXECUTION(Latent::Seconds, 1.0);
co_await PUSH_STATE_CLASS(LatentPushState);
RUN_LATENT_EXECUTION(Latent::Seconds, 1.0);
PUSH_STATE_CLASS(LatentPushState);
}

co_await RUN_LATENT_EXECUTION(Latent::Seconds, 1.0);
RUN_LATENT_EXECUTION(Latent::Seconds, 1.0);
POP_STATE();
}

0 comments on commit 3853cbe

Please sign in to comment.