diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp index 604ffbe..e4e7c97 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp @@ -6,3 +6,17 @@ UFFInputBufferComponent::UFFInputBufferComponent() { PrimaryComponentTick.bCanEverTick = false; } + +void UFFInputBufferComponent::Initialize(int32 BufferSize) +{ + Buffer.Reserve(BufferSize); +} + +void UFFInputBufferComponent::AddInput(const FFFInputState& InputState) +{ +} + +bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSequence) +{ + return true; +} diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h index 05ca9d5..b425dbd 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.h @@ -5,9 +5,19 @@ // UE includes #include "CoreMinimal.h" #include "Components/ActorComponent.h" +#include "Containers/RingBuffer.h" #include "FFInputBufferComponent.generated.h" +struct FFFInputState; + +USTRUCT() +struct FFFInputSequence +{ + GENERATED_BODY() + +}; + UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) class UNREALFIGHTINGFRAMEWORK_API UFFInputBufferComponent : public UActorComponent { @@ -15,4 +25,14 @@ class UNREALFIGHTINGFRAMEWORK_API UFFInputBufferComponent : public UActorCompone public: UFFInputBufferComponent(); + + void Initialize(int32 BufferSize = 120); + + void AddInput(const FFFInputState& InputState); + + bool CheckInputSequence(const FFFInputSequence& InputSequence); + +protected: + /** The underlying buffer data structure for holding past input states */ + TRingBuffer Buffer; }; diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp index a1a75e7..d55b53e 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.cpp +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.cpp @@ -19,6 +19,15 @@ void AFFPlayerController::SendInputsToRemote() const } +void AFFPlayerController::FixedTick(float OneFrame) +{ + UnacknowledgedInputs.Add(CurrInput); + InputBuffer->AddInput(CurrInput); + + SendInputsToRemote(); +} + + void AFFPlayerController::SetupInputComponent() { Super::SetupInputComponent(); diff --git a/Source/UnrealFightingFramework/Input/FFPlayerController.h b/Source/UnrealFightingFramework/Input/FFPlayerController.h index 0c4bba3..bf74650 100644 --- a/Source/UnrealFightingFramework/Input/FFPlayerController.h +++ b/Source/UnrealFightingFramework/Input/FFPlayerController.h @@ -4,20 +4,35 @@ // FF includes #include "FFInputBufferComponent.h" +#include "UnrealFightingFramework/IFFSystemInterface.h" // UE includes #include "CoreMinimal.h" #include "GameFramework/PlayerController.h" #include "InputMappingContext.h" +#include "Containers/RingBuffer.h" #include "FFPlayerController.generated.h" +/** + * Struct representing the state of a player's inputs for one frame + */ +USTRUCT() +struct FFFInputState +{ + GENERATED_BODY() + + FVector2D MoveAxes; + FVector2D LookAxes; + int32 Buttons; +}; + /** * A class that collects player inputs, stores them in an input buffer, and sends a rolling window of * unacknowledged inputs to a remote client or server for processing. */ UCLASS() -class UNREALFIGHTINGFRAMEWORK_API AFFPlayerController : public APlayerController +class UNREALFIGHTINGFRAMEWORK_API AFFPlayerController : public APlayerController, public IFFSystemInterface { GENERATED_BODY() @@ -29,6 +44,10 @@ public: */ virtual void SendInputsToRemote() const; + // IFFSystemInterface interface + virtual void FixedTick(float OneFrame) override; + // End of IFFSystemInterface + // APlayerController interface virtual void SetupInputComponent() override; // End of APlayerController interface @@ -42,7 +61,16 @@ protected: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true")) UFFInputBufferComponent* InputBuffer; - int32 Inputs; + /** Current state of the player's inputs */ + FFFInputState CurrInput; - TArray UnacknowledgedInputs; + /** + * Rolling window of the player's past inputs that have yet to be + * acknowledged and simulated by the remote machine + * + * This ring buffer should be initialized to be the size of the past X frames + * you want the remote machine to re-simulate, where X is the oldest input you want to + * allow to be re-simulated. + */ + TRingBuffer UnacknowledgedInputs; }; diff --git a/Source/UnrealFightingFramework/UnrealFightingFramework.Build.cs b/Source/UnrealFightingFramework/UnrealFightingFramework.Build.cs index 92e65a6..a2e4e2d 100644 --- a/Source/UnrealFightingFramework/UnrealFightingFramework.Build.cs +++ b/Source/UnrealFightingFramework/UnrealFightingFramework.Build.cs @@ -10,14 +10,14 @@ public class UnrealFightingFramework : ModuleRules PublicIncludePaths.AddRange( new string[] { - // ... add public include paths required here ... + "UnrealFightingFramework" } ); PrivateIncludePaths.AddRange( new string[] { - // ... add other private include paths required here ... + "UnrealFightingFramework" } ); diff --git a/Source/UnrealFightingFramework/Utils/TCircleBuffer.cpp b/Source/UnrealFightingFramework/Utils/TCircleBuffer.cpp new file mode 100644 index 0000000..c6e0643 --- /dev/null +++ b/Source/UnrealFightingFramework/Utils/TCircleBuffer.cpp @@ -0,0 +1,11 @@ +// Unreal Fighting Framework by Kevin Poretti + +#include "Utils/TCircleBuffer.h" + +TCircleBuffer::TCircleBuffer() +{ +} + +TCircleBuffer::~TCircleBuffer() +{ +} diff --git a/Source/UnrealFightingFramework/Utils/TCircleBuffer.h b/Source/UnrealFightingFramework/Utils/TCircleBuffer.h new file mode 100644 index 0000000..a1debaa --- /dev/null +++ b/Source/UnrealFightingFramework/Utils/TCircleBuffer.h @@ -0,0 +1,15 @@ +// Unreal Fighting Framework by Kevin Poretti + +#pragma once + +#include "CoreMinimal.h" + +/** + * + */ +class UNREALFIGHTINGFRAMEWORK_API TCircleBuffer +{ +public: + TCircleBuffer(); + ~TCircleBuffer(); +};