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; int32 RequiredButtons = InputSequence.Sequence[CondIdx].RequiredButtons;
EFFButtonState RequiredButtonState = InputSequence.Sequence[CondIdx].RequiredButtonState; EFFButtonState RequiredButtonState = InputSequence.Sequence[CondIdx].RequiredButtonState;
int32 TimeoutDuration = InputSequence.Sequence[CondIdx].TimeoutDuration;
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;
bool bCondFoundThisIteration = false;
switch (RequiredButtonState) switch (RequiredButtonState)
{ {
// TODO: should it be (PrevInput & RequiredButtons) == RequiredButtons or what we have now? // 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) CurrInput & RequiredButtons & ~CurrDisable)
{ {
CondIdx--; CondIdx--;
ElapsedFrames = 0;
bCondFoundThisIteration = true;
} }
break; break;
case EFFButtonState::BTNS_Released: case EFFButtonState::BTNS_Released:
@ -52,12 +56,16 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe
!(CurrInput & RequiredButtons | CurrDisable)) !(CurrInput & RequiredButtons | CurrDisable))
{ {
CondIdx--; CondIdx--;
ElapsedFrames = 0;
bCondFoundThisIteration = true;
} }
break; break;
case EFFButtonState::BTNS_Down: case EFFButtonState::BTNS_Down:
if(CurrInput & RequiredButtons & ~CurrDisable) if(CurrInput & RequiredButtons & ~CurrDisable)
{ {
CondIdx--; CondIdx--;
ElapsedFrames = 0;
bCondFoundThisIteration = true;
} }
break; break;
// TODO: implement button held condition // TODO: implement button held condition
@ -73,10 +81,14 @@ bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSe
return true; return true;
} }
ElapsedFrames++; // No condition found this iteration, so increment elapse frames and see if current condition timed out
if(ElapsedFrames > InputSequence.MaxDuration) if(!bCondFoundThisIteration)
{ {
return false; ElapsedFrames++;
if(ElapsedFrames > TimeoutDuration)
{
return false;
}
} }
} }

View File

@ -16,7 +16,8 @@ enum class EFFButtonState : uint8
{ {
BTNS_Pressed UMETA(DisplayName="Pressed"), BTNS_Pressed UMETA(DisplayName="Pressed"),
BTNS_Released UMETA(DisplayName="Released"), 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_Held UMETA(DisplayName="Held"),
BTNS_MAX UMETA(Hidden) BTNS_MAX UMETA(Hidden)
}; };
@ -50,17 +51,25 @@ struct FFFInputCondition
{ {
GENERATED_BODY() GENERATED_BODY()
// Buttons required for this specific condition to be valid /** Buttons required for this specific condition to be valid */
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 RequiredButtons; 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) UPROPERTY(EditAnywhere, BlueprintReadWrite)
EFFButtonState RequiredButtonState; 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() FFFInputCondition()
: RequiredButtons(0) : RequiredButtons(0)
, RequiredButtonState(EFFButtonState::BTNS_Pressed) , RequiredButtonState(EFFButtonState::BTNS_Pressed)
, TimeoutDuration(0)
{ {
} }
}; };
@ -72,12 +81,8 @@ struct FFFInputSequence
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FFFInputCondition> Sequence; TArray<FFFInputCondition> Sequence;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 MaxDuration;
FFFInputSequence() FFFInputSequence()
: MaxDuration(0)
{ {
} }
}; };