Implement separate timeout durations for each input condition

This commit is contained in:
Kevin Poretti 2023-11-25 19:21:31 -05:00
parent afc6781f5c
commit ee8dff88ea
2 changed files with 28 additions and 11 deletions

View File

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

View File

@ -17,6 +17,7 @@ enum class EFFButtonState : uint8
BTNS_Pressed UMETA(DisplayName="Pressed"),
BTNS_Released UMETA(DisplayName="Released"),
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)
{
}
};
@ -73,11 +82,7 @@ struct FFFInputSequence
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FFFInputCondition> Sequence;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 MaxDuration;
FFFInputSequence()
: MaxDuration(0)
{
}
};