Fix the way the circle buffer was index and traversed
This commit is contained in:
		
							parent
							
								
									b8fa341503
								
							
						
					
					
						commit
						984fc0ad6a
					
				@ -7,22 +7,24 @@ UFFInputBufferComponent::UFFInputBufferComponent()
 | 
				
			|||||||
	PrimaryComponentTick.bCanEverTick = false;
 | 
						PrimaryComponentTick.bCanEverTick = false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UFFInputBufferComponent::AddInput(const FFFInputState& InputState)
 | 
					void UFFInputBufferComponent::AddInput(const FFFInputState& InputState)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	InputBuffer.ForcePush(InputState);
 | 
						InputBuffer.ForcePush(InputState);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSequence)
 | 
					bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSequence)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int CondIdx = InputSequence.Sequence.Num() - 1;
 | 
					    int CondIdx = InputSequence.Sequence.Num() - 1;
 | 
				
			||||||
    int FramesSinceValidInput = 0;
 | 
					    int ElapsedFrames = 0;
 | 
				
			||||||
    for(int InpIdx = 0; InpIdx < InputBuffer.Num() - 1; InpIdx++)
 | 
					    for(int InpIdx = InputBuffer.Num() - 1; InpIdx > 1; InpIdx--)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int32 RequiredButtons = InputSequence.Sequence[CondIdx].RequiredButtons;
 | 
					        int32 RequiredButtons = InputSequence.Sequence[CondIdx].RequiredButtons;
 | 
				
			||||||
        EFFButtonState RequiredButtonState = InputSequence.Sequence[CondIdx].RequiredButtonState;
 | 
					        EFFButtonState RequiredButtonState = InputSequence.Sequence[CondIdx].RequiredButtonState;
 | 
				
			||||||
        int32 PrevInput = InputBuffer[InpIdx + 1].Buttons;
 | 
					        int32 PrevInput = InputBuffer[InpIdx - 1].Buttons;
 | 
				
			||||||
        int32 CurrInput = InputBuffer[InpIdx].Buttons;
 | 
					        int32 CurrInput = InputBuffer[InpIdx].Buttons;
 | 
				
			||||||
        int32 PrevDisable = InputBuffer[InpIdx + 1].DisabledButtons;
 | 
					        int32 PrevDisable = InputBuffer[InpIdx - 1].DisabledButtons;
 | 
				
			||||||
        int32 CurrDisable = InputBuffer[InpIdx].DisabledButtons;
 | 
					        int32 CurrDisable = InputBuffer[InpIdx].DisabledButtons;
 | 
				
			||||||
        switch (RequiredButtonState)
 | 
					        switch (RequiredButtonState)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@ -31,7 +33,6 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe
 | 
				
			|||||||
                   CurrInput & RequiredButtons & ~CurrDisable)
 | 
					                   CurrInput & RequiredButtons & ~CurrDisable)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    CondIdx--;
 | 
					                    CondIdx--;
 | 
				
			||||||
                    FramesSinceValidInput = 0;
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case EFFButtonState::BTNS_Released:
 | 
					            case EFFButtonState::BTNS_Released:
 | 
				
			||||||
@ -39,7 +40,6 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe
 | 
				
			|||||||
                   !(CurrInput & RequiredButtons | CurrDisable))
 | 
					                   !(CurrInput & RequiredButtons | CurrDisable))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    CondIdx--;
 | 
					                    CondIdx--;
 | 
				
			||||||
                    FramesSinceValidInput = 0;
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            // TODO: implement button held condition
 | 
					            // TODO: implement button held condition
 | 
				
			||||||
@ -52,14 +52,14 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe
 | 
				
			|||||||
        // All conditions were met
 | 
					        // All conditions were met
 | 
				
			||||||
        if(CondIdx == -1)
 | 
					        if(CondIdx == -1)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // disable inputs that triggered the sequence
 | 
					            // disable most recent input
 | 
				
			||||||
            InputBuffer[InpIdx].DisabledButtons |= InputBuffer[InpIdx].Buttons;
 | 
					            InputBuffer[InputBuffer.Num() - 1].DisabledButtons |= InputBuffer[InputBuffer.Num() - 1].Buttons;
 | 
				
			||||||
            InputBuffer[InpIdx + 1].DisabledButtons |= InputBuffer[InpIdx + 1].Buttons;
 | 
					            InputBuffer[InputBuffer.Num() - 2].DisabledButtons |= InputBuffer[InputBuffer.Num() - 2].Buttons;
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        FramesSinceValidInput++;
 | 
					        ElapsedFrames++;
 | 
				
			||||||
        if(FramesSinceValidInput > InputSequence.Sequence[CondIdx].Lenience)
 | 
					        if(ElapsedFrames > InputSequence.MaxDuration)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -48,9 +48,6 @@ struct FFFInputCondition
 | 
				
			|||||||
	// 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)
 | 
						UPROPERTY(EditAnywhere)
 | 
				
			||||||
	EFFButtonState RequiredButtonState;
 | 
						EFFButtonState RequiredButtonState;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    UPROPERTY(EditAnywhere)
 | 
					 | 
				
			||||||
	int32 Lenience;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
USTRUCT(BlueprintType)
 | 
					USTRUCT(BlueprintType)
 | 
				
			||||||
@ -60,6 +57,9 @@ struct FFFInputSequence
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    UPROPERTY(EditAnywhere)
 | 
					    UPROPERTY(EditAnywhere)
 | 
				
			||||||
	TArray<FFFInputCondition> Sequence;
 | 
						TArray<FFFInputCondition> Sequence;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						UPROPERTY(EditAnywhere)
 | 
				
			||||||
 | 
						int32 MaxDuration;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 | 
					UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,7 @@ public:
 | 
				
			|||||||
	TCircleBuffer()
 | 
						TCircleBuffer()
 | 
				
			||||||
	    : WriteIdx(0)
 | 
						    : WriteIdx(0)
 | 
				
			||||||
		, ReadIdx(0)
 | 
							, ReadIdx(0)
 | 
				
			||||||
 | 
					        , _Num(0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -116,7 +117,7 @@ public:
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    T& operator[](SIZE_T Index)
 | 
					    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
 | 
					    FORCEINLINE bool IsEmpty() const
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user