From ee8dff88eae02bf466d74236711396101950293d Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sat, 25 Nov 2023 19:21:31 -0500 Subject: [PATCH] Implement separate timeout durations for each input condition --- .../Input/FFInputBufferComponent.cpp | 18 +++++++++++++--- .../Input/FFInputBufferComponent.h | 21 ++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp index 52f0d0e..8c2072f 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp @@ -29,10 +29,12 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe { int32 RequiredButtons = InputSequence.Sequence[CondIdx].RequiredButtons; EFFButtonState RequiredButtonState = InputSequence.Sequence[CondIdx].RequiredButtonState; + int32 TimeoutDuration = InputSequence.Sequence[CondIdx].TimeoutDuration; int32 PrevInput = InputBuffer[InpIdx - 1].Buttons; int32 CurrInput = InputBuffer[InpIdx].Buttons; int32 PrevDisable = InputBuffer[InpIdx - 1].DisabledButtons; int32 CurrDisable = InputBuffer[InpIdx].DisabledButtons; + bool bCondFoundThisIteration = false; switch (RequiredButtonState) { // TODO: should it be (PrevInput & RequiredButtons) == RequiredButtons or what we have now? @@ -45,6 +47,8 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe CurrInput & RequiredButtons & ~CurrDisable) { CondIdx--; + ElapsedFrames = 0; + bCondFoundThisIteration = true; } break; case EFFButtonState::BTNS_Released: @@ -52,12 +56,16 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe !(CurrInput & RequiredButtons | CurrDisable)) { CondIdx--; + ElapsedFrames = 0; + bCondFoundThisIteration = true; } break; case EFFButtonState::BTNS_Down: if(CurrInput & RequiredButtons & ~CurrDisable) { CondIdx--; + ElapsedFrames = 0; + bCondFoundThisIteration = true; } break; // TODO: implement button held condition @@ -73,10 +81,14 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe return true; } - ElapsedFrames++; - if(ElapsedFrames > InputSequence.MaxDuration) + // No condition found this iteration, so increment elapse frames and see if current condition timed out + if(!bCondFoundThisIteration) { - return false; + ElapsedFrames++; + if(ElapsedFrames > TimeoutDuration) + { + return false; + } } } diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h index be9d3c3..264d5dc 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h @@ -16,7 +16,8 @@ enum class EFFButtonState : uint8 { BTNS_Pressed UMETA(DisplayName="Pressed"), BTNS_Released UMETA(DisplayName="Released"), - BTNS_Down UMETA(DisplayName="Down"), + BTNS_Down UMETA(DisplayName="Down"), + //BTNS_Up UMETA(DisplayName="Up), //BTNS_Held UMETA(DisplayName="Held"), BTNS_MAX UMETA(Hidden) }; @@ -50,17 +51,25 @@ struct FFFInputCondition { GENERATED_BODY() - // Buttons required for this specific condition to be valid + /** Buttons required for this specific condition to be valid */ UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 RequiredButtons; - // The button state required for condition to be valid i.e. pressed or released + /** The button state required for condition to be valid i.e. pressed or released */ UPROPERTY(EditAnywhere, BlueprintReadWrite) EFFButtonState RequiredButtonState; + /* + * How many ticks that can be checked since the last valid input condition was found before + * this condition is considered not valid/found in the input buffer + */ + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 TimeoutDuration; + FFFInputCondition() : RequiredButtons(0) , RequiredButtonState(EFFButtonState::BTNS_Pressed) + , TimeoutDuration(0) { } }; @@ -72,12 +81,8 @@ struct FFFInputSequence UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray Sequence; - - UPROPERTY(EditAnywhere, BlueprintReadWrite) - int32 MaxDuration; - + FFFInputSequence() - : MaxDuration(0) { } };