From d869d0105f68fed56fab6fa862fbb7e9cb2c02ec Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sat, 3 Jun 2023 18:38:35 -0400 Subject: [PATCH] Start implementing states --- .../IFESystemInterface.cpp | 7 +- .../UnrealFightingEngine/IFESystemInterface.h | 4 +- Source/UnrealFightingEngine/State/FEState.cpp | 55 +++++++++++- Source/UnrealFightingEngine/State/FEState.h | 90 ++++++++++++++++++- .../State/FEStateMachineComponent.cpp | 3 +- .../State/FEStateMachineComponent.h | 2 +- 6 files changed, 145 insertions(+), 16 deletions(-) diff --git a/Source/UnrealFightingEngine/IFESystemInterface.cpp b/Source/UnrealFightingEngine/IFESystemInterface.cpp index c715879..41c7cb9 100644 --- a/Source/UnrealFightingEngine/IFESystemInterface.cpp +++ b/Source/UnrealFightingEngine/IFESystemInterface.cpp @@ -1,9 +1,4 @@ -// Project Sword & Gun Copyright Kevin Poretti +// Unreal Fighting Engine by Kevin Poretti #include "IFESystemInterface.h" - -// Add default functionality here for any IIFESystemInterface functions that are not pure virtual. -void IIFESystemInterface::FixedTick(float OneFrame) -{ -} diff --git a/Source/UnrealFightingEngine/IFESystemInterface.h b/Source/UnrealFightingEngine/IFESystemInterface.h index 78573e7..0ad0f96 100644 --- a/Source/UnrealFightingEngine/IFESystemInterface.h +++ b/Source/UnrealFightingEngine/IFESystemInterface.h @@ -1,4 +1,4 @@ -// Project Sword & Gun Copyright Kevin Poretti +// Unreal Fighting Engine by Kevin Poretti #pragma once @@ -29,5 +29,5 @@ public: * * @param OneFrame the time that elapses during one fixed tick */ - virtual void FixedTick(float OneFrame); + virtual void FixedTick(float OneFrame) = 0; }; diff --git a/Source/UnrealFightingEngine/State/FEState.cpp b/Source/UnrealFightingEngine/State/FEState.cpp index 7e49f67..e70c55c 100644 --- a/Source/UnrealFightingEngine/State/FEState.cpp +++ b/Source/UnrealFightingEngine/State/FEState.cpp @@ -1,5 +1,56 @@ -// Project Sword & Gun Copyright Kevin Poretti - +// Unreal Fighting Engine by Kevin Poretti #include "FEState.h" +#include "FEStateMachineComponent.h" + +void UFEState::InitActorInfo(AActor* InOwner, AActor* InAvatar) +{ + Owner = InOwner; + Avatar = InAvatar; +} + +void UFEState::Enter() +{ + TicksInState = 0; + + OnEnter(); +} + +void UFEState::Exit() +{ + OnExit(); +} + +void UFEState::FixedTick(float OneFrame) +{ + TicksInState++; + + OnFixedTick(OneFrame); +} + + +void UFEState::OnEnter_Implementation() +{ +} + + +void UFEState::OnExit_Implementation() +{ +} + + +void UFEState::OnFixedTick_Implementation(float OneFrame) +{ +} + +UWorld* UFEState::GetWorld() const +{ + UFEStateMachineComponent* SMC = Cast(GetOuter()); + if(SMC) + { + return SMC->GetWorld(); + } + + return nullptr; +} diff --git a/Source/UnrealFightingEngine/State/FEState.h b/Source/UnrealFightingEngine/State/FEState.h index 8fd888f..395c143 100644 --- a/Source/UnrealFightingEngine/State/FEState.h +++ b/Source/UnrealFightingEngine/State/FEState.h @@ -1,4 +1,4 @@ -// Project Sword & Gun Copyright Kevin Poretti +// Unreal Fighting Engine by Kevin Poretti #pragma once @@ -7,11 +7,95 @@ #include "FEState.generated.h" /** - * + * A state is an object that provides rules and conditions for when a state can be transitioned into + * and logic to run when the state is entered, exited, and active. */ UCLASS() class UNREALFIGHTINGENGINE_API UFEState : public UObject { GENERATED_BODY() - + +public: + + /** + * Initializes pointers to what owns this state and what avatar this state represents. + */ + virtual void InitActorInfo(AActor* InOwner, AActor* InAvatar); + + /** Name of this state */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="UFE|State") + FName Name; + + /** Conditions that need to be met in order for this state to be transitioned into */ + UPROPERTY(EditAnywhere) + TArray EntryConditions; + + /** What is this state's category. Used for determining what types of state can prematurely cancel this one. */ + UPROPERTY(EditAnywhere) + uint8 StateType; + + /** How many ticks have elapsed since this state was entered */ + UPROPERTY(BlueprintReadOnly, Category="UFE|State") + int32 TicksInState; + + /** + * Called whenever this state is transitioned into. + * + * Resets TicksInState and calls appropriate Blueprint hooks + */ + void Enter(); + + /** + * Called whenever this state is transitioned out of into a new state. + */ + void Exit(); + + /** + * Called whenever this state is active and the game logic ticks. + * + * Increments TicksInState and calls appropriate Blueprint hooks. + * + * @param OneFrame the time that elapses during one fixed tick + */ + void FixedTick(float OneFrame); + + /** + * Blueprint hook that is called whenever this state is transitioned into + */ + UFUNCTION(BlueprintNativeEvent, Category="UFE|State|Events") + void OnEnter(); + + /** + * Blueprint hook that is called whenever this state is transitioned out of into a new state + */ + UFUNCTION(BlueprintNativeEvent, Category="UFE|State|Events") + void OnExit(); + + /** + * Blueprint hook that is called whenever this state is active and the game logic ticks + * + * @param OneFrame the time that elapses during one fixed tick + */ + UFUNCTION(BlueprintNativeEvent, Category="UFE|State|Events") + void OnFixedTick(float OneFrame); + + // UObject interface + virtual UWorld* GetWorld() const override; + // End of UObject interface + +protected: + + /** + * Actor that owns this state. + * This will typically be a player controller that possesses the avatar. + */ + UPROPERTY(BlueprintReadOnly) + AActor* Owner; + + /** + * The avatar is an actor that this state represents. + * This will typically be a pawn or character. + */ + UPROPERTY(BlueprintReadOnly) + AActor* Avatar; }; diff --git a/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp b/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp index 85bec85..7a8b740 100644 --- a/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp +++ b/Source/UnrealFightingEngine/State/FEStateMachineComponent.cpp @@ -1,5 +1,4 @@ -// Project Sword & Gun Copyright Kevin Poretti - +// Unreal Fighting Engine by Kevin Poretti #include "FEStateMachineComponent.h" diff --git a/Source/UnrealFightingEngine/State/FEStateMachineComponent.h b/Source/UnrealFightingEngine/State/FEStateMachineComponent.h index d017375..2077de8 100644 --- a/Source/UnrealFightingEngine/State/FEStateMachineComponent.h +++ b/Source/UnrealFightingEngine/State/FEStateMachineComponent.h @@ -1,4 +1,4 @@ -// Project Sword & Gun Copyright Kevin Poretti +// Unreal Fighting Engine by Kevin Poretti #pragma once