Compare commits
2 Commits
e38379586c
...
ec6daa06fb
Author | SHA1 | Date | |
---|---|---|---|
ec6daa06fb | |||
f31f0437e9 |
@ -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;
|
||||
};
|
||||
|
@ -5,16 +5,41 @@
|
||||
// FF includes
|
||||
#include "FFInputBufferComponent.h"
|
||||
|
||||
// UE includes
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
|
||||
AFFPlayerController::AFFPlayerController()
|
||||
{
|
||||
InputBuffer = CreateDefaultSubobject<UFFInputBufferComponent>(TEXT("InputBuffer"));
|
||||
}
|
||||
|
||||
|
||||
void AFFPlayerController::SendInputsToRemote() const
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AFFPlayerController::FixedTick(float OneFrame)
|
||||
{
|
||||
UnacknowledgedInputs.Add(CurrInput);
|
||||
InputBuffer->AddInput(CurrInput);
|
||||
|
||||
SendInputsToRemote();
|
||||
}
|
||||
|
||||
|
||||
void AFFPlayerController::SetupInputComponent()
|
||||
{
|
||||
Super::SetupInputComponent();
|
||||
|
||||
if (ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player))
|
||||
{
|
||||
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = LocalPlayer->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>())
|
||||
{
|
||||
if (!DefaultInputMapping.IsNull())
|
||||
{
|
||||
InputSystem->AddMappingContext(DefaultInputMapping.LoadSynchronous(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,37 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// 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()
|
||||
|
||||
@ -23,7 +42,11 @@ public:
|
||||
/**
|
||||
* 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
|
||||
virtual void SetupInputComponent() override;
|
||||
@ -32,13 +55,22 @@ public:
|
||||
protected:
|
||||
/** MappingContext */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UFF|Input", meta = (AllowPrivateAccess = "true"))
|
||||
class UInputMappingContext* DefaultMappingContext;
|
||||
TSoftObjectPtr<UInputMappingContext> DefaultInputMapping;
|
||||
|
||||
/** Input Buffer component */
|
||||
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