Compare commits

...

2 Commits

7 changed files with 124 additions and 7 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

@ -5,16 +5,41 @@
// FF includes // FF includes
#include "FFInputBufferComponent.h" #include "FFInputBufferComponent.h"
// UE includes
#include "EnhancedInputSubsystems.h"
AFFPlayerController::AFFPlayerController() AFFPlayerController::AFFPlayerController()
{ {
InputBuffer = CreateDefaultSubobject<UFFInputBufferComponent>(TEXT("InputBuffer")); InputBuffer = CreateDefaultSubobject<UFFInputBufferComponent>(TEXT("InputBuffer"));
} }
void AFFPlayerController::SendInputsToRemote() const 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();
if (ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player))
{
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = LocalPlayer->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>())
{
if (!DefaultInputMapping.IsNull())
{
InputSystem->AddMappingContext(DefaultInputMapping.LoadSynchronous(), 0);
}
}
}
} }

View File

@ -2,18 +2,37 @@
#pragma once #pragma once
// FF includes
#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 "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()
@ -23,7 +42,11 @@ public:
/** /**
* Sends all unacknowledged inputs to the remote * Sends all unacknowledged inputs to the remote
*/ */
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;
@ -32,13 +55,22 @@ public:
protected: protected:
/** MappingContext */ /** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true")) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true"))
class UInputMappingContext* DefaultMappingContext; TSoftObjectPtr<UInputMappingContext> DefaultInputMapping;
/** Input Buffer component */ /** Input Buffer component */
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();
};