GASATHON/Project/Source/Gasa/Game/GasaPlayerController.h
Ed_ ad41867dc5 WIP: Boostrapping NetSlime
- Just a old name for a set of changes to make the game framework hardened for multiplayer as well as some ease of use functionality.
2024-04-23 01:10:02 -04:00

113 lines
3.4 KiB
C++

#pragma once
#include "GasaCommon.h"
#include "Engine/Engine.h"
#include "GameFramework/PlayerController.h"
#include "Networking/GasaNetLibrary.h"
#include "GasaPlayerController.generated.h"
UCLASS(Blueprintable)
class GASA_API AGasaPlayerController : public APlayerController
{
GENERATED_BODY()
public:
#pragma region Camera
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;
void Move(FInputActionValue const& ActionValue);
#pragma endregion Input
AGasaPlayerController();
inline AGasaPlayerState* GetPlayerState();
#pragma region NetSlime
// NetSlime interface is generated by GasaGen/GasaGen_NetSlime.cpp
FORCEINLINE ENetworkMode GetNetworkMode() const { return Gasa::GetNetworkMode( this ); }
FORCEINLINE bool IsClient() const { return Gasa::IsClient( this ); }
FORCEINLINE bool IsListenServer() const { return Gasa::IsListenServer( this ); }
FORCEINLINE bool IsNetOwner() const { return Gasa::IsNetOwner( this ); }
FORCEINLINE bool IsServer() const { return Gasa::IsServer( this ); }
FORCEINLINE bool IsSimulatedProxy() const { return Gasa::IsSimulatedProxy( this ); }
FORCEINLINE void NetLog(
FString Message,
EGasaVerbosity Verbosity = EGasaVerbosity::Log,
FLogCategoryBase& Category = LogGasaNet,
bool DumpStack = false,
int32 Line = __builtin_LINE(),
ANSICHAR const* File = __builtin_FILE(),
ANSICHAR const* Func = __builtin_FUNCTION()
)
{
Gasa::NetLog( this, Message, Verbosity, Category, DumpStack, Line, File, Func );
}
#pragma endregion NetSlime
#pragma region PlayerController
void SpawnDefaultHUD() override;
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());
}
}