Define functions and members for integrating player controller with input buffer
This commit is contained in:
parent
f31f0437e9
commit
ec6daa06fb
@ -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;
|
||||
}
|
||||
|
@ -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<FFFInputState> Buffer;
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -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<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;
|
||||
};
|
||||
|
@ -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"
|
||||
}
|
||||
);
|
||||
|
||||
|
11
Source/UnrealFightingFramework/Utils/TCircleBuffer.cpp
Normal file
11
Source/UnrealFightingFramework/Utils/TCircleBuffer.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
// Unreal Fighting Framework by Kevin Poretti
|
||||
|
||||
#include "Utils/TCircleBuffer.h"
|
||||
|
||||
TCircleBuffer::TCircleBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
TCircleBuffer::~TCircleBuffer()
|
||||
{
|
||||
}
|
15
Source/UnrealFightingFramework/Utils/TCircleBuffer.h
Normal file
15
Source/UnrealFightingFramework/Utils/TCircleBuffer.h
Normal file
@ -0,0 +1,15 @@
|
||||
// Unreal Fighting Framework by Kevin Poretti
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class UNREALFIGHTINGFRAMEWORK_API TCircleBuffer
|
||||
{
|
||||
public:
|
||||
TCircleBuffer();
|
||||
~TCircleBuffer();
|
||||
};
|
Loading…
Reference in New Issue
Block a user