diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp index 2dde5cc..ff1080a 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp @@ -7,22 +7,24 @@ UFFInputBufferComponent::UFFInputBufferComponent() PrimaryComponentTick.bCanEverTick = false; } + void UFFInputBufferComponent::AddInput(const FFFInputState& InputState) { InputBuffer.ForcePush(InputState); } + bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSequence) { int CondIdx = InputSequence.Sequence.Num() - 1; - int FramesSinceValidInput = 0; - for(int InpIdx = 0; InpIdx < InputBuffer.Num() - 1; InpIdx++) + int ElapsedFrames = 0; + for(int InpIdx = InputBuffer.Num() - 1; InpIdx > 1; InpIdx--) { int32 RequiredButtons = InputSequence.Sequence[CondIdx].RequiredButtons; EFFButtonState RequiredButtonState = InputSequence.Sequence[CondIdx].RequiredButtonState; - int32 PrevInput = InputBuffer[InpIdx + 1].Buttons; + int32 PrevInput = InputBuffer[InpIdx - 1].Buttons; int32 CurrInput = InputBuffer[InpIdx].Buttons; - int32 PrevDisable = InputBuffer[InpIdx + 1].DisabledButtons; + int32 PrevDisable = InputBuffer[InpIdx - 1].DisabledButtons; int32 CurrDisable = InputBuffer[InpIdx].DisabledButtons; switch (RequiredButtonState) { @@ -31,7 +33,6 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe CurrInput & RequiredButtons & ~CurrDisable) { CondIdx--; - FramesSinceValidInput = 0; } break; case EFFButtonState::BTNS_Released: @@ -39,7 +40,6 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe !(CurrInput & RequiredButtons | CurrDisable)) { CondIdx--; - FramesSinceValidInput = 0; } break; // TODO: implement button held condition @@ -52,14 +52,14 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe // All conditions were met if(CondIdx == -1) { - // disable inputs that triggered the sequence - InputBuffer[InpIdx].DisabledButtons |= InputBuffer[InpIdx].Buttons; - InputBuffer[InpIdx + 1].DisabledButtons |= InputBuffer[InpIdx + 1].Buttons; + // 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; } - FramesSinceValidInput++; - if(FramesSinceValidInput > InputSequence.Sequence[CondIdx].Lenience) + ElapsedFrames++; + if(ElapsedFrames > InputSequence.MaxDuration) { return false; } diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h index 1363683..4ef704f 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h @@ -48,9 +48,6 @@ struct FFFInputCondition // The button state required for condition to be valid i.e. pressed or released UPROPERTY(EditAnywhere) EFFButtonState RequiredButtonState; - - UPROPERTY(EditAnywhere) - int32 Lenience; }; USTRUCT(BlueprintType) @@ -60,6 +57,9 @@ struct FFFInputSequence UPROPERTY(EditAnywhere) TArray Sequence; + + UPROPERTY(EditAnywhere) + int32 MaxDuration; }; UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) diff --git a/Source/UnrealFightingFramework/Utils/TCircleBuffer.h b/Source/UnrealFightingFramework/Utils/TCircleBuffer.h index 1289eaf..3d82b1a 100644 --- a/Source/UnrealFightingFramework/Utils/TCircleBuffer.h +++ b/Source/UnrealFightingFramework/Utils/TCircleBuffer.h @@ -18,6 +18,7 @@ public: TCircleBuffer() : WriteIdx(0) , ReadIdx(0) + , _Num(0) { } @@ -116,7 +117,7 @@ public: */ T& operator[](SIZE_T Index) { - return Buffer[((SSIZE_T)WriteIdx - (SSIZE_T)Index) < 0 ? L - (Index - WriteIdx) : WriteIdx - Index]; + return Buffer[(ReadIdx + Index) % L]; } FORCEINLINE bool IsEmpty() const