// Copyright Epic Games, Inc. All Rights Reserved. #include "LyraGameState.h" #include "AbilitySystem/LyraAbilitySystemComponent.h" #include "AbilitySystemComponent.h" #include "Containers/Array.h" #include "Engine/EngineBaseTypes.h" #include "GameFramework/GameplayMessageSubsystem.h" #include "GameModes/LyraExperienceManagerComponent.h" #include "HAL/Platform.h" #include "Misc/AssertionMacros.h" #include "Net/UnrealNetwork.h" class APlayerState; class FLifetimeProperty; extern ENGINE_API float GAverageFPS; ALyraGameState::ALyraGameState(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bStartWithTickEnabled = true; AbilitySystemComponent = ObjectInitializer.CreateDefaultSubobject(this, TEXT("AbilitySystemComponent")); AbilitySystemComponent->SetIsReplicated(true); AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed); ExperienceManagerComponent = CreateDefaultSubobject(TEXT("ExperienceManagerComponent")); ServerFPS = 0.0f; } void ALyraGameState::PreInitializeComponents() { Super::PreInitializeComponents(); } void ALyraGameState::PostInitializeComponents() { Super::PostInitializeComponents(); check(AbilitySystemComponent); AbilitySystemComponent->InitAbilityActorInfo(/*Owner=*/ this, /*Avatar=*/ this); } UAbilitySystemComponent* ALyraGameState::GetAbilitySystemComponent() const { return AbilitySystemComponent; } void ALyraGameState::EndPlay(const EEndPlayReason::Type EndPlayReason) { Super::EndPlay(EndPlayReason); } void ALyraGameState::AddPlayerState(APlayerState* PlayerState) { Super::AddPlayerState(PlayerState); } void ALyraGameState::RemovePlayerState(APlayerState* PlayerState) { //@TODO: This isn't getting called right now (only the 'rich' AGameMode uses it, not AGameModeBase) // Need to at least comment the engine code, and possibly move things around Super::RemovePlayerState(PlayerState); } void ALyraGameState::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(ThisClass, ServerFPS); } void ALyraGameState::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); if (GetLocalRole() == ROLE_Authority) { ServerFPS = GAverageFPS; } } void ALyraGameState::MulticastMessageToClients_Implementation(const FLyraVerbMessage Message) { if (GetNetMode() == NM_Client) { UGameplayMessageSubsystem::Get(this).BroadcastMessage(Message.Verb, Message); } } void ALyraGameState::MulticastReliableMessageToClients_Implementation(const FLyraVerbMessage Message) { MulticastMessageToClients_Implementation(Message); }