Start implementing states

This commit is contained in:
Kevin Poretti 2023-06-03 18:38:35 -04:00
parent fef1217877
commit d869d0105f
6 changed files with 145 additions and 16 deletions

View File

@ -1,9 +1,4 @@
// Project Sword & Gun Copyright Kevin Poretti // Unreal Fighting Engine by Kevin Poretti
#include "IFESystemInterface.h" #include "IFESystemInterface.h"
// Add default functionality here for any IIFESystemInterface functions that are not pure virtual.
void IIFESystemInterface::FixedTick(float OneFrame)
{
}

View File

@ -1,4 +1,4 @@
// Project Sword & Gun Copyright Kevin Poretti // Unreal Fighting Engine by Kevin Poretti
#pragma once #pragma once
@ -29,5 +29,5 @@ public:
* *
* @param OneFrame the time that elapses during one fixed tick * @param OneFrame the time that elapses during one fixed tick
*/ */
virtual void FixedTick(float OneFrame); virtual void FixedTick(float OneFrame) = 0;
}; };

View File

@ -1,5 +1,56 @@
// Project Sword & Gun Copyright Kevin Poretti // Unreal Fighting Engine by Kevin Poretti
#include "FEState.h" #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<UFEStateMachineComponent>(GetOuter());
if(SMC)
{
return SMC->GetWorld();
}
return nullptr;
}

View File

@ -1,4 +1,4 @@
// Project Sword & Gun Copyright Kevin Poretti // Unreal Fighting Engine by Kevin Poretti
#pragma once #pragma once
@ -7,11 +7,95 @@
#include "FEState.generated.h" #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() UCLASS()
class UNREALFIGHTINGENGINE_API UFEState : public UObject class UNREALFIGHTINGENGINE_API UFEState : public UObject
{ {
GENERATED_BODY() 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<uint8> 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;
}; };

View File

@ -1,5 +1,4 @@
// Project Sword & Gun Copyright Kevin Poretti // Unreal Fighting Engine by Kevin Poretti
#include "FEStateMachineComponent.h" #include "FEStateMachineComponent.h"

View File

@ -1,4 +1,4 @@
// Project Sword & Gun Copyright Kevin Poretti // Unreal Fighting Engine by Kevin Poretti
#pragma once #pragma once