From ecd8b1ca3c26a0163e80bb799dd52fa9bccb3231 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Mon, 5 Jun 2023 17:02:11 -0400 Subject: [PATCH] Start of input buffer and player controller --- .../UnrealFightingEngine/IFESystemInterface.h | 4 +- .../Input/FEInputBufferComponent.cpp | 8 ++++ .../Input/FEInputBufferComponent.h | 18 +++++++++ .../Input/FEPlayerController.cpp | 20 ++++++++++ .../Input/FEPlayerController.h | 40 +++++++++++++++++++ Source/UnrealFightingEngine/State/FEState.cpp | 13 +++--- Source/UnrealFightingEngine/State/FEState.h | 4 +- .../State/FEStateMachineComponent.cpp | 2 +- .../State/FEStateMachineComponent.h | 6 +-- 9 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 Source/UnrealFightingEngine/Input/FEInputBufferComponent.cpp create mode 100644 Source/UnrealFightingEngine/Input/FEInputBufferComponent.h create mode 100644 Source/UnrealFightingEngine/Input/FEPlayerController.cpp create mode 100644 Source/UnrealFightingEngine/Input/FEPlayerController.h diff --git a/Source/UnrealFightingEngine/IFESystemInterface.h b/Source/UnrealFightingEngine/IFESystemInterface.h index f40dbc9..c0153c7 100644 --- a/Source/UnrealFightingEngine/IFESystemInterface.h +++ b/Source/UnrealFightingEngine/IFESystemInterface.h @@ -9,7 +9,7 @@ // This class does not need to be modified. UINTERFACE(MinimalAPI) -class UIFESystemInterface : public UInterface +class UFESystemInterface : public UInterface { GENERATED_BODY() }; @@ -20,7 +20,7 @@ class UIFESystemInterface : public UInterface * This ensures all gameplay effecting objects can be assumed to have certain properties that enable serialization, networking and * some form of determinism. */ -class UNREALFIGHTINGENGINE_API IIFESystemInterface +class UNREALFIGHTINGENGINE_API IFESystemInterface { GENERATED_BODY() diff --git a/Source/UnrealFightingEngine/Input/FEInputBufferComponent.cpp b/Source/UnrealFightingEngine/Input/FEInputBufferComponent.cpp new file mode 100644 index 0000000..bc28f2d --- /dev/null +++ b/Source/UnrealFightingEngine/Input/FEInputBufferComponent.cpp @@ -0,0 +1,8 @@ +// Unreal Fighting Engine by Kevin Poretti + +#include "FEInputBufferComponent.h" + +UFEInputBufferComponent::UFEInputBufferComponent() +{ + PrimaryComponentTick.bCanEverTick = false; +} diff --git a/Source/UnrealFightingEngine/Input/FEInputBufferComponent.h b/Source/UnrealFightingEngine/Input/FEInputBufferComponent.h new file mode 100644 index 0000000..30e925a --- /dev/null +++ b/Source/UnrealFightingEngine/Input/FEInputBufferComponent.h @@ -0,0 +1,18 @@ +// Unreal Fighting Engine by Kevin Poretti + +#pragma once + +// UE includes +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" + +#include "FEInputBufferComponent.generated.h" + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class UNREALFIGHTINGENGINE_API UFEInputBufferComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + UFEInputBufferComponent(); +}; diff --git a/Source/UnrealFightingEngine/Input/FEPlayerController.cpp b/Source/UnrealFightingEngine/Input/FEPlayerController.cpp new file mode 100644 index 0000000..ea1dba5 --- /dev/null +++ b/Source/UnrealFightingEngine/Input/FEPlayerController.cpp @@ -0,0 +1,20 @@ +// Unreal Fighting Engine by Kevin Poretti + +#include "FEPlayerController.h" + +// FE includes +#include "FEInputBufferComponent.h" + +AFEPlayerController::AFEPlayerController() +{ + InputBuffer = CreateDefaultSubobject(TEXT("InputBuffer")); +} + +void AFEPlayerController::SendInputsToRemote() const +{ +} + +void AFEPlayerController::SetupInputComponent() +{ + Super::SetupInputComponent(); +} diff --git a/Source/UnrealFightingEngine/Input/FEPlayerController.h b/Source/UnrealFightingEngine/Input/FEPlayerController.h new file mode 100644 index 0000000..ee6d711 --- /dev/null +++ b/Source/UnrealFightingEngine/Input/FEPlayerController.h @@ -0,0 +1,40 @@ +// Unreal Fighting Engine by Kevin Poretti + +#pragma once + +// UE includes +#include "CoreMinimal.h" +#include "GameFramework/PlayerController.h" + +#include "FEPlayerController.generated.h" + +/** + * 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 UNREALFIGHTINGENGINE_API AFEPlayerController : public APlayerController +{ + GENERATED_BODY() + +public: + AFEPlayerController(); + + /** + * Sends all unacknowledged inputs to the remote + */ + void SendInputsToRemote() const; + + // APlayerController interface + virtual void SetupInputComponent() override; + // End of APlayerController interface + +protected: + /** Input Buffer component */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "UFE|Input", meta = (AllowPrivateAccess = "true")) + UFEInputBufferComponent* InputBuffer; + + int32 Inputs; + + TArray UnacknowledgedInputs; +}; diff --git a/Source/UnrealFightingEngine/State/FEState.cpp b/Source/UnrealFightingEngine/State/FEState.cpp index dc4f4f9..f52c68f 100644 --- a/Source/UnrealFightingEngine/State/FEState.cpp +++ b/Source/UnrealFightingEngine/State/FEState.cpp @@ -5,13 +5,13 @@ // FE includes #include "FEStateMachineComponent.h" - void UFEState::InitActorInfo(AActor* InOwner, AActor* InAvatar) { Owner = InOwner; Avatar = InAvatar; } + void UFEState::Enter() { TicksInState = 0; @@ -19,16 +19,18 @@ void UFEState::Enter() OnEnter(); } + void UFEState::Exit() { OnExit(); } -void UFEState::FixedTick(float OneFrame) + +void UFEState::Update(float OneFrame) { TicksInState++; - OnFixedTick(OneFrame); + OnUpdate(OneFrame); } @@ -42,10 +44,11 @@ void UFEState::OnExit_Implementation() } -void UFEState::OnFixedTick_Implementation(float OneFrame) +void UFEState::OnUpdate_Implementation(float OneFrame) { } + UWorld* UFEState::GetWorld() const { UFEStateMachineComponent* SMC = Cast(GetOuter()); @@ -55,4 +58,4 @@ UWorld* UFEState::GetWorld() const } return nullptr; -} +} \ No newline at end of file diff --git a/Source/UnrealFightingEngine/State/FEState.h b/Source/UnrealFightingEngine/State/FEState.h index 29b003b..2db6c2e 100644 --- a/Source/UnrealFightingEngine/State/FEState.h +++ b/Source/UnrealFightingEngine/State/FEState.h @@ -61,7 +61,7 @@ public: * * @param OneFrame the time that elapses during one fixed tick */ - void FixedTick(float OneFrame); + void Update(float OneFrame); /** * Blueprint hook that is called whenever this state is transitioned into @@ -81,7 +81,7 @@ public: * @param OneFrame the time that elapses during one fixed tick */ UFUNCTION(BlueprintNativeEvent, Category="UFE|State|Events") - void OnFixedTick(float OneFrame); + void OnUpdate(float OneFrame); // UObject interface virtual UWorld* GetWorld() const override; diff --git a/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp b/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp index 8cac64a..93fae14 100644 --- a/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp +++ b/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp @@ -128,7 +128,7 @@ void UFEStateMachineComponent::FixedTick(float OneFrame) check(CurrentState); // Tick current state - CurrentState->FixedTick(OneFrame); + CurrentState->Update(OneFrame); // Debug } diff --git a/Source/UnrealFightingEngine/State/FEStateMachineComponent.h b/Source/UnrealFightingEngine/State/FEStateMachineComponent.h index 5cb2428..8ca6ab4 100644 --- a/Source/UnrealFightingEngine/State/FEStateMachineComponent.h +++ b/Source/UnrealFightingEngine/State/FEStateMachineComponent.h @@ -18,7 +18,7 @@ * This component also calls the appropriate state logic when a state is changed or the component ticks. */ UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) -class UNREALFIGHTINGENGINE_API UFEStateMachineComponent : public UActorComponent, public IIFESystemInterface +class UNREALFIGHTINGENGINE_API UFEStateMachineComponent : public UActorComponent, public IFESystemInterface { GENERATED_BODY() @@ -74,9 +74,9 @@ public: UFUNCTION(BlueprintPure) FName GetCurrentStateName() const; - // IIFESystemInterface interface + // IFESystemInterface interface virtual void FixedTick(float OneFrame) override; - // End of IIFESystemInterface interface + // End of IFESystemInterface interface protected: /**