Only disable most recent input if transition into state is successful

This commit is contained in:
Kevin Poretti 2023-08-26 16:03:01 -04:00
parent bd195c7ee8
commit 6c06611901
6 changed files with 30 additions and 3 deletions

View File

@ -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;
}

View File

@ -94,6 +94,8 @@ public:
bool CheckInputSequence(const FFFInputSequence& InputSequence);
void DisableMostRecentInput();
protected:
/** The underlying buffer data structure for holding past input states */
TCircleBuffer<FFFInputState, 120> InputBuffer;

View File

@ -56,6 +56,11 @@ bool AFFPlayerController::CheckInputSequences(const TArray<FFFInputSequence>& In
return false;
}
void AFFPlayerController::DisableMostRecentInput()
{
InputBuffer->DisableMostRecentInput();
}
void AFFPlayerController::SetupInputComponent()
{

View File

@ -55,6 +55,8 @@ public:
virtual bool CheckInputSequence(const FFFInputSequence& InInputSequence) override;
virtual bool CheckInputSequences(const TArray<FFFInputSequence>& InputSequences) override;
virtual void DisableMostRecentInput() override;
// End of IFFStateOwnerInterface
// APlayerController interface

View File

@ -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<IFFStateOwnerInterface>(Owner);
if(PC)
{
PC->DisableMostRecentInput();
}
}
CurrentState->Exit(GetCurrentStateContext());
CurrentState = NewState;
CurrentState->Enter(GetCurrentStateContext());

View File

@ -24,4 +24,6 @@ public:
virtual bool CheckInputSequence(const FFFInputSequence& InInputSequence) = 0;
virtual bool CheckInputSequences(const TArray<FFFInputSequence>& InInputSequences) = 0;
virtual void DisableMostRecentInput() = 0;
};