From 6c06611901756b19903d0a4fb15e45abd1be4f13 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sat, 26 Aug 2023 16:03:01 -0400 Subject: [PATCH] Only disable most recent input if transition into state is successful --- .../Input/FFInputBufferComponent.cpp | 9 ++++++--- .../Input/FFInputBufferComponent.h | 2 ++ .../Input/FFPlayerController.cpp | 5 +++++ .../Input/FFPlayerController.h | 2 ++ .../State/FFStateMachineComponent.cpp | 13 +++++++++++++ .../State/IFFStateOwnerInterface.h | 2 ++ 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp index 375bd0e..a15e594 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp @@ -59,9 +59,6 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe // All conditions were met if(CondIdx == -1) { - // disable most recent input - InputBuffer[InputBuffer.Num() - 1].DisabledButtons |= InputBuffer[InputBuffer.Num() - 1].Buttons; - InputBuffer[InputBuffer.Num() - 2].DisabledButtons |= InputBuffer[InputBuffer.Num() - 2].Buttons; return true; } @@ -74,3 +71,9 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe return false; } + +void UFFInputBufferComponent::DisableMostRecentInput() +{ + InputBuffer[InputBuffer.Num() - 1].DisabledButtons |= InputBuffer[InputBuffer.Num() - 1].Buttons; + InputBuffer[InputBuffer.Num() - 2].DisabledButtons |= InputBuffer[InputBuffer.Num() - 2].Buttons; +} diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h index 35184d3..698e603 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h @@ -94,6 +94,8 @@ public: bool CheckInputSequence(const FFFInputSequence& InputSequence); + void DisableMostRecentInput(); + protected: /** The underlying buffer data structure for holding past input states */ TCircleBuffer InputBuffer; diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp index 9744321..c8fea47 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp @@ -56,6 +56,11 @@ bool AFFPlayerController::CheckInputSequences(const TArray& In return false; } +void AFFPlayerController::DisableMostRecentInput() +{ + InputBuffer->DisableMostRecentInput(); +} + void AFFPlayerController::SetupInputComponent() { diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.h b/Source/UnrealFightingFramework/Input/FFPlayerController.h index acf648b..bcc485b 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.h +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.h @@ -55,6 +55,8 @@ public: virtual bool CheckInputSequence(const FFFInputSequence& InInputSequence) override; virtual bool CheckInputSequences(const TArray& InputSequences) override; + + virtual void DisableMostRecentInput() override; // End of IFFStateOwnerInterface // APlayerController interface diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp index 54bf8cd..16a0993 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp @@ -4,6 +4,7 @@ // FF includes #include "FFState.h" +#include "Input/FFPlayerController.h" #if !UE_BUILD_SHIPPING static int32 StateMachineDebug = 0; @@ -100,6 +101,18 @@ void UFFStateMachineComponent::GoToState(UFFState* NewState) check(CurrentState); check(NewState); + // if state being transitioned into requires an input sequence we need to disable the most + // recent input in the player controller input buffer to prevent unwanted "double firing" of + // actions that have short durations but very lenient required input sequences + if(NewState->InputSequences.Num() > 0) + { + IFFStateOwnerInterface* PC = Cast(Owner); + if(PC) + { + PC->DisableMostRecentInput(); + } + } + CurrentState->Exit(GetCurrentStateContext()); CurrentState = NewState; CurrentState->Enter(GetCurrentStateContext()); diff --git a/Source/UnrealFightingFramework/State/IFFStateOwnerInterface.h b/Source/UnrealFightingFramework/State/IFFStateOwnerInterface.h index d6de2c3..75631aa 100644 --- a/Source/UnrealFightingFramework/State/IFFStateOwnerInterface.h +++ b/Source/UnrealFightingFramework/State/IFFStateOwnerInterface.h @@ -24,4 +24,6 @@ public: virtual bool CheckInputSequence(const FFFInputSequence& InInputSequence) = 0; virtual bool CheckInputSequences(const TArray& InInputSequences) = 0; + + virtual void DisableMostRecentInput() = 0; };