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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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<FFFInputCondition> Sequence;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
int32 MaxDuration;
|
||||
};
|
||||
|
||||
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user