From a85a9a7005456647dc135bc1bc33ff1dae5d74c5 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Fri, 30 Jun 2023 14:13:26 -0400 Subject: [PATCH] Interface for modifying raw inputs --- .../Input/FFInputBufferComponent.cpp | 2 +- .../Input/FFInputBufferComponent.h | 15 ++++++++++---- .../Input/FFPlayerController.cpp | 10 ++++++++-- .../Input/FFPlayerController.h | 20 +++++++++++++++++-- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp index f7d1aa4..a1f9b9c 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp @@ -12,7 +12,7 @@ void UFFInputBufferComponent::AddInput(const FFFInputState& InputState) InputBuffer.ForcePush(InputState); } -bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSequence) +bool UFFInputBufferComponent::CheckInputSequence(const FFFInputCondition& InputCondition) { for(int InpIdx = 0; InpIdx < InputBuffer.Num(); InpIdx++) { diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h index a2992f4..c4c5109 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h @@ -21,14 +21,21 @@ struct FFFInputState FVector2D MoveAxes; FVector2D LookAxes; + + UPROPERTY(EditAnywhere, Meta = (Bitmask)) int32 Buttons; }; -USTRUCT() -struct FFFInputSequence +USTRUCT(BlueprintType) +struct FFFInputCondition { GENERATED_BODY() - + + UPROPERTY(EditAnywhere) + TArray Sequence; + + UPROPERTY(EditAnywhere) + int32 Lenience; }; UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) @@ -41,7 +48,7 @@ public: void AddInput(const FFFInputState& InputState); - bool CheckInputSequence(const FFFInputSequence& InputSequence); + bool CheckInputSequence(const FFFInputCondition& InputCondition); protected: /** The underlying buffer data structure for holding past input states */ diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp index 1c6a615..57c5b7d 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp @@ -19,10 +19,16 @@ void AFFPlayerController::SendInputsToRemote() const } +void AFFPlayerController::ModifyRawInput() +{ + ModifiedInput = RawInput; +} + + void AFFPlayerController::FixedTick(float OneFrame) { - //UnacknowledgedInputs.Push(CurrInput); - InputBuffer->AddInput(CurrInput); + //UnacknowledgedInputs.Push(RawInput); + InputBuffer->AddInput(ModifiedInput); //SendInputsToRemote(); } diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.h b/Source/UnrealFightingFramework/Input/FFPlayerController.h index be413ba..ded1695 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.h +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.h @@ -31,7 +31,20 @@ public: */ virtual void SendInputsToRemote() const; - virtual FFFInputState GetCurrInput() { return CurrInput; }; + /** + * @brief Gets the current input after cleaning/modifying the raw input state + * @return the current input + */ + virtual FFFInputState GetModifiedInput() const { return ModifiedInput; }; + + /** + * @brief Function called before inputs are passed to the game logic to update the game state. + * This is a chance for the application to mutate inputs before the game uses them to update game state. + * Examples would include treating opposite directional inputs being held cancelling each other out or setting + * a "neutral input" flag when no directional inputs are being held. + * For stick/axis values this can be clamping those values or normalizing the Move and Look direction vectors. + */ + virtual void ModifyRawInput(); // IFFSystemInterface interface virtual void FixedTick(float OneFrame) override; @@ -51,7 +64,10 @@ protected: UFFInputBufferComponent* InputBuffer; /** Current state of the player's inputs */ - FFFInputState CurrInput; + FFFInputState RawInput; + + /** Current state of the player's inputs after performing cleaning and modifications */ + FFFInputState ModifiedInput; /** * Rolling window of the player's past inputs that have yet to be