From d7920802cf54724dda1ffc47940a59e5e05b8544 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Mon, 20 Nov 2023 22:17:55 -0500 Subject: [PATCH] Keep track of tick on landed was called --- .../State/FFStateMachineComponent.cpp | 3 +++ .../State/FFStateMachineComponent.h | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp index 120c8cf..04bc928 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp @@ -117,6 +117,7 @@ void UFFStateMachineComponent::GoToState(UFFState* NewState, EFFStateFinishReaso CurrentState->Exit(GetCurrentStateContext(), StateFinishReason); TicksInState = 0; + OnLandedTick = 0; TickStateWasEntered = GetWorld()->GetGameState()->GetCurrentTick(); CurrentSubStateLabel = NAME_None; NewState->Enter(GetCurrentStateContext()); @@ -161,6 +162,8 @@ void UFFStateMachineComponent::Landed(const FHitResult& Hit) { check(CurrentState) + OnLandedTick = GetWorld()->GetGameState()->GetCurrentTick(); + CurrentState->Landed(Hit, GetCurrentStateContext()); } diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.h b/Source/UnrealFightingFramework/State/FFStateMachineComponent.h index 2c0c84d..a379c63 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.h +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.h @@ -104,6 +104,14 @@ public: UFUNCTION(BlueprintPure) FORCEINLINE int64 GetTickStateWasEntered() const { return TickStateWasEntered; } + /** + * Returns the tick number which corresponds to when the On Landed event fired + * + * The tick number represents the ticks that have elapsed since the game began. + */ + UFUNCTION(BlueprintPure) + FORCEINLINE int64 GetOnLandedTick() const { return OnLandedTick; } + UFUNCTION(BlueprintPure) const UFFState* GetCurrentState() const { return const_cast(CurrentState); } @@ -158,12 +166,19 @@ protected: int64 TicksInState; /** - * The tick number which corresponds to when this state was entered into. + * The tick number which corresponds to when the current state was entered. * * The tick number represents the ticks that have elapsed since the game began. */ int64 TickStateWasEntered; + /** + * The tick number which corresponds to when the On Landed event was called for the current tick. + * + * The tick number represents the ticks that have elapsed since the game began. + */ + int64 OnLandedTick; + /** Current active state for this state machine */ UPROPERTY() UFFState* CurrentState; @@ -171,6 +186,7 @@ protected: /** Current SubState label or NAME_None if there is no SubState label set for the current state*/ FName CurrentSubStateLabel; + // TODO: should be a TMap // States that have been added UPROPERTY() TArray States;