Define functions and members for integrating player controller with input buffer

This commit is contained in:
Kevin Poretti 2023-06-11 17:45:58 -04:00
parent f31f0437e9
commit ec6daa06fb
7 changed files with 102 additions and 5 deletions

View File

@ -6,3 +6,17 @@ UFFInputBufferComponent::UFFInputBufferComponent()
{ {
PrimaryComponentTick.bCanEverTick = false; 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;
}

View File

@ -5,9 +5,19 @@
// UE includes // UE includes
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Components/ActorComponent.h" #include "Components/ActorComponent.h"
#include "Containers/RingBuffer.h"
#include "FFInputBufferComponent.generated.h" #include "FFInputBufferComponent.generated.h"
struct FFFInputState;
USTRUCT()
struct FFFInputSequence
{
GENERATED_BODY()
};
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class UNREALFIGHTINGFRAMEWORK_API UFFInputBufferComponent : public UActorComponent class UNREALFIGHTINGFRAMEWORK_API UFFInputBufferComponent : public UActorComponent
{ {
@ -15,4 +25,14 @@ class UNREALFIGHTINGFRAMEWORK_API UFFInputBufferComponent : public UActorCompone
public: public:
UFFInputBufferComponent(); 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<FFFInputState> Buffer;
}; };

View File

@ -19,6 +19,15 @@ void AFFPlayerController::SendInputsToRemote() const
} }
void AFFPlayerController::FixedTick(float OneFrame)
{
UnacknowledgedInputs.Add(CurrInput);
InputBuffer->AddInput(CurrInput);
SendInputsToRemote();
}
void AFFPlayerController::SetupInputComponent() void AFFPlayerController::SetupInputComponent()
{ {
Super::SetupInputComponent(); Super::SetupInputComponent();

View File

@ -4,20 +4,35 @@
// FF includes // FF includes
#include "FFInputBufferComponent.h" #include "FFInputBufferComponent.h"
#include "UnrealFightingFramework/IFFSystemInterface.h"
// UE includes // UE includes
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "GameFramework/PlayerController.h" #include "GameFramework/PlayerController.h"
#include "InputMappingContext.h" #include "InputMappingContext.h"
#include "Containers/RingBuffer.h"
#include "FFPlayerController.generated.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 * 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. * unacknowledged inputs to a remote client or server for processing.
*/ */
UCLASS() UCLASS()
class UNREALFIGHTINGFRAMEWORK_API AFFPlayerController : public APlayerController class UNREALFIGHTINGFRAMEWORK_API AFFPlayerController : public APlayerController, public IFFSystemInterface
{ {
GENERATED_BODY() GENERATED_BODY()
@ -29,6 +44,10 @@ public:
*/ */
virtual void SendInputsToRemote() const; virtual void SendInputsToRemote() const;
// IFFSystemInterface interface
virtual void FixedTick(float OneFrame) override;
// End of IFFSystemInterface
// APlayerController interface // APlayerController interface
virtual void SetupInputComponent() override; virtual void SetupInputComponent() override;
// End of APlayerController interface // End of APlayerController interface
@ -42,7 +61,16 @@ protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true"))
UFFInputBufferComponent* InputBuffer; UFFInputBufferComponent* InputBuffer;
int32 Inputs; /** Current state of the player's inputs */
FFFInputState CurrInput;
TArray<int32> 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<FFFInputState> UnacknowledgedInputs;
}; };

View File

@ -10,14 +10,14 @@ public class UnrealFightingFramework : ModuleRules
PublicIncludePaths.AddRange( PublicIncludePaths.AddRange(
new string[] { new string[] {
// ... add public include paths required here ... "UnrealFightingFramework"
} }
); );
PrivateIncludePaths.AddRange( PrivateIncludePaths.AddRange(
new string[] { new string[] {
// ... add other private include paths required here ... "UnrealFightingFramework"
} }
); );

View File

@ -0,0 +1,11 @@
// Unreal Fighting Framework by Kevin Poretti
#include "Utils/TCircleBuffer.h"
TCircleBuffer::TCircleBuffer()
{
}
TCircleBuffer::~TCircleBuffer()
{
}

View File

@ -0,0 +1,15 @@
// Unreal Fighting Framework by Kevin Poretti
#pragma once
#include "CoreMinimal.h"
/**
*
*/
class UNREALFIGHTINGFRAMEWORK_API TCircleBuffer
{
public:
TCircleBuffer();
~TCircleBuffer();
};