GASATHON/Project/Source/Gasa/Game/GasaGameState.h

124 lines
3.6 KiB
C
Raw Permalink Normal View History

#pragma once
2024-04-12 19:05:09 -07:00
#include "GameFramework/GameState.h"
2024-04-12 19:05:09 -07:00
#include "GasaCommon.h"
#include "Engine/Engine.h"
#include "Networking/GasaNetLibrary.h"
2024-04-12 19:05:09 -07:00
#include "GasaGameState.generated.h"
UCLASS( Blueprintable )
2024-04-12 19:05:09 -07:00
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;
2024-04-12 19:05:09 -07:00
#if ENABLE_COG
2024-04-12 19:37:31 -07:00
TObjectPtr<UCogWindowManager> CogWindowManager;
#endif
// ENABLE_COG
2024-04-12 19:05:09 -07:00
#pragma endregion Cog
AGasaGameState();
#pragma region GameFramework
UPROPERTY(BlueprintAssignable)
FOnPawnReadySig Event_OnPlayerPawnReady;
UFUNCTION()
void OnGameFrameworkInitialized();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, meta=(DisplayName = "Game Framework Initialized"))
void BP_OnGameFrameworkInitialized();
UFUNCTION()
void NotifyPlayerPawnReady(APawn* Pawn)
{
if (Event_OnPlayerPawnReady.IsBound())
Event_OnPlayerPawnReady.Broadcast(Pawn);
}
#pragma endregion GameFramework
#pragma region Networking
UPROPERTY(Replicated, BlueprintReadOnly)
AGasaPlayerState* ListenServerHost;
UPROPERTY(ReplicatedUsing = "Client_OnRep_OnlinePlayers", BlueprintReadOnly)
TArray<AGasaPlayerState*> OnlinePlayers;
UFUNCTION()
void Client_OnRep_OnlinePlayers();
#pragma endregion Networking
#pragma region Seamless Travel
UPROPERTY(BlueprintAssignable)
FOnTravelSig Event_OnSeamlessTravelStart;
UPROPERTY(BlueprintAssignable, meta=(DisplayName="Event: On Seamless Travel End"))
FOnTravelSig BP_Event_OnSeamlessTravelEnd;
FOnTravelDelegate Event_OnSeamlessTravelEnd;
UFUNCTION(NetMulticast, Reliable)
void Multicast_R_NotifySeamlessTravelEnd();
#pragma endregion Seamless Travel
#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
2024-04-12 19:05:09 -07:00
#pragma region GameState
void HandleBeginPlay() override;
#pragma endregion GameState
#pragma region GameStateBase
void SeamlessTravelTransitionCheckpoint(bool bToTransitionMap) override;
#pragma endregion GameStateBase
#pragma region Actor
2024-04-12 19:05:09 -07:00
void BeginPlay() override;
void PostInitializeComponents() override;
void Tick( float DeltaSeconds ) override;
#pragma endregion Actor
2024-04-12 19:05:09 -07:00
#pragma region UObject
void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
#pragma endregion UObject
};
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() );
}
}