Fleshed out the module's base helper definitions
This commit is contained in:
8
Project/Source/Gasa/Game/GasaGameInstance.cpp
Normal file
8
Project/Source/Gasa/Game/GasaGameInstance.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "GasaGameInstance.h"
|
||||
|
||||
void UGasaGameInstance::Init()
|
||||
{
|
||||
Super::Init();
|
||||
|
||||
DevOptionsCache.CachedDevOptions();
|
||||
}
|
35
Project/Source/Gasa/Game/GasaGameInstance.h
Normal file
35
Project/Source/Gasa/Game/GasaGameInstance.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "GasaCommon.h"
|
||||
#include "GasaDevOptionsCache.h"
|
||||
|
||||
#include "GasaGameInstance.generated.h"
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class GASA_API UGasaGameInstance : public UGameInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
|
||||
UPROPERTY(VisibleAnywhere, Category="Dev Cache")
|
||||
FGasaDevOptionsCache DevOptionsCache;
|
||||
|
||||
#pragma region GameInstance
|
||||
void Init() override;
|
||||
#pragma endregion GameInstance
|
||||
};
|
||||
|
||||
namespace Gasa
|
||||
{
|
||||
inline
|
||||
UGasaGameInstance* GetGameInstance(UObject* Context)
|
||||
{
|
||||
UWorld* World = GEngine->GetWorldFromContextObject(Context, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{
|
||||
Log("World is null... are you running in a proper context?", ELogV::Error);
|
||||
return nullptr;
|
||||
}
|
||||
return Cast<UGasaGameInstance>(World->GetGameInstance());
|
||||
}
|
||||
}
|
2
Project/Source/Gasa/Game/GasaGameMode.cpp
Normal file
2
Project/Source/Gasa/Game/GasaGameMode.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "GasaGameMode.h"
|
||||
|
28
Project/Source/Gasa/Game/GasaGameMode.h
Normal file
28
Project/Source/Gasa/Game/GasaGameMode.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include "GameFramework/GameMode.h"
|
||||
|
||||
#include "GasaCommon.h"
|
||||
|
||||
#include "GasaGameMode.generated.h"
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class GASA_API AGasaGameMode : public AGameMode
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
};
|
||||
|
||||
namespace Gasa
|
||||
{
|
||||
inline
|
||||
AGasaGameMode* GetGameMode(UObject* Context)
|
||||
{
|
||||
UWorld* World = GEngine->GetWorldFromContextObject(Context, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{
|
||||
Log("World is null... are you running in a proper context?", ELogV::Error);
|
||||
return nullptr;
|
||||
}
|
||||
return Cast<AGasaGameMode>(World->GetAuthGameMode());
|
||||
}
|
||||
}
|
34
Project/Source/Gasa/Game/GasaGameState.cpp
Normal file
34
Project/Source/Gasa/Game/GasaGameState.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "GasaGameState.h"
|
||||
|
||||
#include "CogAll.h"
|
||||
#include "CogWindowManager.h"
|
||||
|
||||
AGasaGameState::AGasaGameState()
|
||||
{
|
||||
// Enable ticking
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
PrimaryActorTick.SetTickFunctionEnable(true);
|
||||
PrimaryActorTick.bStartWithTickEnabled = true;
|
||||
}
|
||||
|
||||
#pragma region GameState
|
||||
void AGasaGameState::BeginPlay()
|
||||
{
|
||||
#if ENABLE_COG
|
||||
CogWindowManager = NewObject<UCogWindowManager>(this);
|
||||
CogWindowManagerRef = CogWindowManager;
|
||||
|
||||
// Add all the built-in windows
|
||||
Cog::AddAllWindows(*CogWindowManager);
|
||||
#endif //ENABLE_COG
|
||||
}
|
||||
|
||||
void AGasaGameState::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
|
||||
#if ENABLE_COG
|
||||
CogWindowManager->Tick(DeltaSeconds);
|
||||
#endif //ENABLE_COG
|
||||
}
|
||||
#pragma endregion GameState
|
46
Project/Source/Gasa/Game/GasaGameState.h
Normal file
46
Project/Source/Gasa/Game/GasaGameState.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/GameState.h"
|
||||
|
||||
#include "GasaCommon.h"
|
||||
|
||||
#include "GasaGameState.generated.h"
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class GASA_API AGasaGameState : public AGameState
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
#pragma region Cog
|
||||
// To make sure it doesn't get garbage collected.
|
||||
UPROPERTY()
|
||||
TObjectPtr<UObject> CogWindowManagerRef;
|
||||
|
||||
#if ENABLE_COG
|
||||
TObjectPtr<UCogWindowManager> CogWindowManager;
|
||||
#endif // ENABLE_COG
|
||||
#pragma endregion Cog
|
||||
|
||||
AGasaGameState();
|
||||
|
||||
#pragma region GameState
|
||||
void BeginPlay() override;
|
||||
|
||||
void Tick(float DeltaSeconds) override;
|
||||
#pragma endregion GameState
|
||||
};
|
||||
|
||||
namespace Gasa
|
||||
{
|
||||
inline
|
||||
AGasaGameState* GetGameState(UObject* Context)
|
||||
{
|
||||
UWorld* World = GEngine->GetWorldFromContextObject(Context, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{
|
||||
Log("World is null... are you running in a proper context?", ELogV::Error);
|
||||
return nullptr;
|
||||
}
|
||||
return Cast<AGasaGameState>(World->GetGameState());
|
||||
}
|
||||
}
|
2
Project/Source/Gasa/Game/GasaGameplayTags.cpp
Normal file
2
Project/Source/Gasa/Game/GasaGameplayTags.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "GasaGameplayTags.h"
|
||||
|
3
Project/Source/Gasa/Game/GasaGameplayTags.h
Normal file
3
Project/Source/Gasa/Game/GasaGameplayTags.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "NativeGameplayTags.h"
|
24
Project/Source/Gasa/Game/GasaLevelScriptActor.cpp
Normal file
24
Project/Source/Gasa/Game/GasaLevelScriptActor.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "GasaLevelScriptActor.h"
|
||||
|
||||
#include "GasaDevOptions.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
void AGasaLevelScriptActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
using namespace Gasa;
|
||||
|
||||
TArray<AActor*> TaggedActors;
|
||||
UGameplayStatics::GetAllActorsWithTag(GetWorld(), GetDevOptions()->Tag_GlobalPPV, TaggedActors);
|
||||
for (AActor* Actor : TaggedActors)
|
||||
{
|
||||
GlobalPPV = Cast<APostProcessVolume>(Actor);
|
||||
|
||||
APostProcessVolume* PPV = GetLevelActor(this)->GlobalPPV;
|
||||
UMaterialInstance* Blendable = Cast<UMaterialInstance>(PPV->Settings.WeightedBlendables.Array[0].Object);
|
||||
UMaterialInstanceDynamic* MID = UMaterialInstanceDynamic::Create(Blendable, this);
|
||||
PPV->Settings.WeightedBlendables.Array[0].Object = MID;
|
||||
break;
|
||||
}
|
||||
}
|
34
Project/Source/Gasa/Game/GasaLevelScriptActor.h
Normal file
34
Project/Source/Gasa/Game/GasaLevelScriptActor.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "Engine/LevelScriptActor.h"
|
||||
|
||||
#include "GasaCommon.h"
|
||||
|
||||
#include "GasaLevelScriptActor.generated.h"
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class GASA_API AGasaLevelScriptActor : public ALevelScriptActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Post Process")
|
||||
TObjectPtr<APostProcessVolume> GlobalPPV;
|
||||
|
||||
#pragma region Actor
|
||||
void BeginPlay() override;
|
||||
#pragma region endActor
|
||||
};
|
||||
|
||||
namespace Gasa
|
||||
{
|
||||
inline
|
||||
AGasaLevelScriptActor* GetLevelActor(UObject* Context, ULevel* OwnerLevel = nullptr) {
|
||||
UWorld* World = GEngine->GetWorldFromContextObject(Context, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{
|
||||
Log("World is null... are you running in a proper context?", ELogV::Error);
|
||||
return nullptr;
|
||||
}
|
||||
return Cast<AGasaLevelScriptActor>(World->GetLevelScriptActor(OwnerLevel));
|
||||
}
|
||||
}
|
184
Project/Source/Gasa/Game/GasaPlayerController.cpp
Normal file
184
Project/Source/Gasa/Game/GasaPlayerController.cpp
Normal file
@ -0,0 +1,184 @@
|
||||
#include "GasaPlayerController.h"
|
||||
|
||||
#include "Engine/LocalPlayer.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "Actors/CameraMount.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Characters/GasaCharacter.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
|
||||
AGasaPlayerController::AGasaPlayerController()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
bAutoManageActiveCameraTarget = false;
|
||||
|
||||
// Replication
|
||||
bReplicates = true;
|
||||
}
|
||||
|
||||
void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
|
||||
{
|
||||
APawn* pawn = GetPawn<APawn>();
|
||||
if (pawn == nullptr )
|
||||
return;
|
||||
|
||||
// Note(Ed): I did the follow optimization for practice, they are completely unnecessary for this context.
|
||||
#if 0
|
||||
FVector2D AxisV = ActionValue.Get<FVector2D>();
|
||||
FRotator ControlRot = GetControlRotation();
|
||||
FRotator YawRot = FRotator(0.f, ControlRot.Yaw, 0.f);
|
||||
|
||||
FVector FwdDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::X);
|
||||
FVector RightDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::Y);
|
||||
|
||||
PPawn->AddMovementInput(FwdDir, AxisV.Y);
|
||||
PPawn->AddMovementInput(RightDir, AxisV.X);
|
||||
#else
|
||||
FVector2f AxisV = FVector2f(ActionValue.Get<FVector2D>());
|
||||
|
||||
FQuat4f // FQuat isomorphic to FRotor (Hypothetical Def)
|
||||
ControlRotor = FQuat4f(GetControlRotation().Quaternion());
|
||||
// ControlRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
||||
|
||||
FVector3f HorizontalForward = ControlRotor.RotateVector(FVector3f::ForwardVector);
|
||||
// HorizontalForward.Normalize();
|
||||
|
||||
// TODO(Ed): Profile which is faster just to know... (atan2 vs FindBetweenVectors)
|
||||
// HorizontalForward.Z = 0;
|
||||
// FQuat4f
|
||||
// YawRotor = FQuat4f::FindBetweenVectors(FVector3f::ForwardVector, HorizontalForward);
|
||||
// YawRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
||||
|
||||
// Need only one axis of rotation so this might be a possible optimization
|
||||
float YawAngle = FMath::Atan2(HorizontalForward.Y, HorizontalForward.X);
|
||||
FQuat4f YawRotor = FQuat4f(FVector3f::UpVector, YawAngle);
|
||||
|
||||
// Rotate the combined input by the yaw rotor to get the movement direction
|
||||
FVector MoveDir = (FVector) YawRotor.RotateVector( FVector3f(AxisV.Y, AxisV.X, 0.f));
|
||||
pawn->AddMovementInput( MoveDir );
|
||||
#endif
|
||||
}
|
||||
|
||||
void AGasaPlayerController::OnPossess(APawn* InPawn)
|
||||
{
|
||||
Super::OnPossess(InPawn);
|
||||
|
||||
Cam->AttachToActor(InPawn, FAttachmentTransformRules::KeepRelativeTransform);
|
||||
}
|
||||
|
||||
void AGasaPlayerController::OnUnPossess()
|
||||
{
|
||||
Super::OnUnPossess();
|
||||
}
|
||||
|
||||
#pragma region PlayerController
|
||||
void AGasaPlayerController::PlayerTick(float DeltaTime)
|
||||
{
|
||||
Super::PlayerTick(DeltaTime);
|
||||
|
||||
// Cursor Trace
|
||||
for (int32 do_once = 0; do_once != 1; ++ do_once)
|
||||
{
|
||||
FHitResult CursorHit;
|
||||
GetHitResultUnderCursor(ECC_Pawn, false, CursorHit);
|
||||
if (! CursorHit.bBlockingHit)
|
||||
break;
|
||||
|
||||
HoverPrev = HoverCurr;
|
||||
HoverCurr = Cast<AGasaCharacter>(CursorHit.GetActor());
|
||||
if (HoverPrev == nullptr)
|
||||
{
|
||||
// We didn't have a prev to de-highlight so we just need to highlight newly detected character.
|
||||
if (HoverCurr)
|
||||
HoverCurr->Highlight();
|
||||
|
||||
// No matter what we need to not go to the next case as there is no previous.
|
||||
break;
|
||||
}
|
||||
//else Previous is valid...
|
||||
|
||||
// We are no longer hovering the previous with no new character, we just need to de-highlight previous.
|
||||
if ( HoverCurr == nullptr )
|
||||
HoverPrev->Dehighlight();
|
||||
|
||||
// We had a prev and curr change between frames. They both don't match; we need to switch highlighting.
|
||||
else if ( HoverPrev != HoverCurr )
|
||||
{
|
||||
HoverPrev->Dehighlight();
|
||||
HoverCurr->Highlight();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AGasaPlayerController::SetupInputComponent()
|
||||
{
|
||||
Super::SetupInputComponent();
|
||||
|
||||
UEnhancedInputComponent*
|
||||
EIC = CastChecked<UEnhancedInputComponent>(InputComponent);
|
||||
{
|
||||
EIC->BindAction(IA_Move, ETriggerEvent::Triggered, this, &ThisClass::Move);
|
||||
}
|
||||
}
|
||||
#pragma endregion PlayerController
|
||||
|
||||
#pragma region Actor
|
||||
void AGasaPlayerController::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
check(IMC);
|
||||
|
||||
UEnhancedInputLocalPlayerSubsystem*
|
||||
EILP_Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
||||
check(EILP_Subsystem);
|
||||
EILP_Subsystem->AddMappingContext(IMC, 0);
|
||||
{
|
||||
bShowMouseCursor = true;
|
||||
DefaultMouseCursor = EMouseCursor::Default;
|
||||
FInputModeGameAndUI MouseMode;
|
||||
MouseMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
|
||||
MouseMode.SetHideCursorDuringCapture(false);
|
||||
SetInputMode(MouseMode);
|
||||
}
|
||||
}
|
||||
|
||||
void AGasaPlayerController::PostInitializeComponents()
|
||||
{
|
||||
Super::PostInitializeComponents();
|
||||
|
||||
Cam = GetWorld()->SpawnActor<ACameraMount>(CamClass, FActorSpawnParameters() );
|
||||
SetViewTarget(Cam);
|
||||
}
|
||||
|
||||
void AGasaPlayerController::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
|
||||
#if 0
|
||||
switch (HighlightState)
|
||||
{
|
||||
case EHighlight::Disabled:
|
||||
break;
|
||||
case EHighlight::Enabled:
|
||||
{
|
||||
UCapsuleComponent* Capsule = GetCapsuleComponent();
|
||||
|
||||
UKismetSystemLibrary::DrawDebugCapsule(this
|
||||
, Capsule->GetComponentLocation()
|
||||
, Capsule->GetScaledCapsuleHalfHeight()
|
||||
, Capsule->GetScaledCapsuleRadius()
|
||||
, Capsule->GetComponentRotation()
|
||||
, HighlightColor
|
||||
, 0.f
|
||||
, 1.f
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#pragma endregion Actor
|
89
Project/Source/Gasa/Game/GasaPlayerController.h
Normal file
89
Project/Source/Gasa/Game/GasaPlayerController.h
Normal file
@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include "GasaCommon.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
|
||||
#include "GasaPlayerController.generated.h"
|
||||
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class GASA_API AGasaPlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
#pragma region Camera
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TSubclassOf<ACameraMount> CamClass;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<ACameraMount> Cam;
|
||||
#pragma endregion Camera
|
||||
|
||||
// This will be implemented in the base until it needs to be lifted into an abstraction.
|
||||
#if 0
|
||||
#pragma region Highlighting
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Highlighting")
|
||||
EHighlight HighlightState;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Highlighting")
|
||||
void SetHighlight( EHighlight Desired );
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Highlighting")
|
||||
FORCEINLINE void Highlight() { SetHighlight(EHighlight::Enabled); };
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Highlighting")
|
||||
FORCEINLINE void Dehighlight() { SetHighlight(EHighlight::Disabled); };
|
||||
#pragma endregion Highlighting
|
||||
#endif
|
||||
|
||||
#pragma region Input
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
TObjectPtr<AGasaCharacter> HoverPrev;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
TObjectPtr<AGasaCharacter> HoverCurr;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Input")
|
||||
TObjectPtr<UInputMappingContext> IMC;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Input")
|
||||
TObjectPtr<UInputAction> IA_Move;
|
||||
#pragma endregion Input
|
||||
|
||||
AGasaPlayerController();
|
||||
|
||||
void Move(FInputActionValue const& ActionValue);
|
||||
|
||||
#pragma region PlayerController
|
||||
void OnPossess(APawn* InPawn) override;
|
||||
|
||||
void OnUnPossess() override;
|
||||
|
||||
void PlayerTick(float DeltaTime) override;
|
||||
|
||||
void SetupInputComponent() override;
|
||||
#pragma endregion PlayerController
|
||||
|
||||
#pragma region Actor
|
||||
void BeginPlay() override;
|
||||
|
||||
void PostInitializeComponents() override;
|
||||
|
||||
void Tick(float DeltaSeconds) override;
|
||||
#pragma endregion Actor
|
||||
};
|
||||
|
||||
namespace Gasa
|
||||
{
|
||||
inline
|
||||
AGasaPlayerController* GetPrimaryPlayerController(UObject* Context)
|
||||
{
|
||||
UWorld* World = GEngine->GetWorldFromContextObject(Context, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{
|
||||
Log("World is null... are you running in a proper context?", ELogV::Error);
|
||||
return nullptr;
|
||||
}
|
||||
return Cast<AGasaPlayerController>(World->GetFirstPlayerController());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user