RealtimeStyleTransferRuntime/Source/LyraGame/GameFeatures/LyraGameFeaturePolicy.cpp

167 lines
5.6 KiB
C++
Raw Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "GameFeatures/LyraGameFeaturePolicy.h"
2022-09-13 07:18:28 +00:00
2022-05-23 18:41:30 +00:00
#include "AbilitySystem/LyraGameplayCueManager.h"
2022-09-13 07:18:28 +00:00
#include "GameFeatureAction.h"
#include "GameFeatureData.h"
#include "GameFeaturesSubsystem.h"
2022-05-23 18:41:30 +00:00
#include "GameplayCueSet.h"
2022-09-13 07:18:28 +00:00
#include "HAL/Platform.h"
#include "Misc/AssertionMacros.h"
#include "Misc/CoreMisc.h"
#include "OnlineHotfixManager.h"
#include "ProfilingDebugging/CpuProfilerTrace.h"
#include "Templates/Casts.h"
#include "UObject/SoftObjectPath.h"
2022-05-23 18:41:30 +00:00
ULyraGameFeaturePolicy::ULyraGameFeaturePolicy(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
ULyraGameFeaturePolicy& ULyraGameFeaturePolicy::Get()
{
return UGameFeaturesSubsystem::Get().GetPolicy<ULyraGameFeaturePolicy>();
}
void ULyraGameFeaturePolicy::InitGameFeatureManager()
{
Observers.Add(NewObject<ULyraGameFeature_HotfixManager>());
Observers.Add(NewObject<ULyraGameFeature_AddGameplayCuePaths>());
UGameFeaturesSubsystem& Subsystem = UGameFeaturesSubsystem::Get();
for (UObject* Observer : Observers)
{
Subsystem.AddObserver(Observer);
}
Super::InitGameFeatureManager();
}
void ULyraGameFeaturePolicy::ShutdownGameFeatureManager()
{
Super::ShutdownGameFeatureManager();
UGameFeaturesSubsystem& Subsystem = UGameFeaturesSubsystem::Get();
for (UObject* Observer : Observers)
{
Subsystem.RemoveObserver(Observer);
}
Observers.Empty();
}
2022-09-13 07:18:28 +00:00
TArray<FPrimaryAssetId> ULyraGameFeaturePolicy::GetPreloadAssetListForGameFeature(const UGameFeatureData* GameFeatureToLoad, bool bIncludeLoadedAssets) const
{
return Super::GetPreloadAssetListForGameFeature(GameFeatureToLoad, bIncludeLoadedAssets);
}
2022-05-23 18:41:30 +00:00
const TArray<FName> ULyraGameFeaturePolicy::GetPreloadBundleStateForGameFeature() const
{
return Super::GetPreloadBundleStateForGameFeature();
}
void ULyraGameFeaturePolicy::GetGameFeatureLoadingMode(bool& bLoadClientData, bool& bLoadServerData) const
{
// Editor will load both, this can cause hitching as the bundles are set to not preload in editor
bLoadClientData = !IsRunningDedicatedServer();
bLoadServerData = !IsRunningClientOnly();
}
bool ULyraGameFeaturePolicy::IsPluginAllowed(const FString& PluginURL) const
{
return Super::IsPluginAllowed(PluginURL);
}
//////////////////////////////////////////////////////////////////////
//
#include "Hotfix/LyraHotfixManager.h"
void ULyraGameFeature_HotfixManager::OnGameFeatureLoading(const UGameFeatureData* GameFeatureData, const FString& PluginURL)
{
if (ULyraHotfixManager* HotfixManager = Cast<ULyraHotfixManager>(UOnlineHotfixManager::Get(nullptr)))
{
HotfixManager->RequestPatchAssetsFromIniFiles();
}
}
//////////////////////////////////////////////////////////////////////
//
2022-09-13 07:18:28 +00:00
#include "AbilitySystemGlobals.h"
2022-05-23 18:41:30 +00:00
#include "GameFeatureAction_AddGameplayCuePath.h"
#include "GameplayCueManager.h"
2022-09-13 07:18:28 +00:00
class FName;
struct FPrimaryAssetId;
2022-05-23 18:41:30 +00:00
void ULyraGameFeature_AddGameplayCuePaths::OnGameFeatureRegistering(const UGameFeatureData* GameFeatureData, const FString& PluginName, const FString& PluginURL)
{
TRACE_CPUPROFILER_EVENT_SCOPE(ULyraGameFeature_AddGameplayCuePaths::OnGameFeatureRegistering);
const FString PluginRootPath = TEXT("/") + PluginName;
for (const UGameFeatureAction* Action : GameFeatureData->GetActions())
{
if (const UGameFeatureAction_AddGameplayCuePath* AddGameplayCueGFA = Cast<UGameFeatureAction_AddGameplayCuePath>(Action))
{
const TArray<FDirectoryPath>& DirsToAdd = AddGameplayCueGFA->GetDirectoryPathsToAdd();
if (ULyraGameplayCueManager* GCM = ULyraGameplayCueManager::Get())
{
UGameplayCueSet* RuntimeGameplayCueSet = GCM->GetRuntimeCueSet();
const int32 PreInitializeNumCues = RuntimeGameplayCueSet ? RuntimeGameplayCueSet->GameplayCueData.Num() : 0;
for (const FDirectoryPath& Directory : DirsToAdd)
{
FString MutablePath = Directory.Path;
UGameFeaturesSubsystem::FixPluginPackagePath(MutablePath, PluginRootPath, false);
GCM->AddGameplayCueNotifyPath(MutablePath, /** bShouldRescanCueAssets = */ false);
}
// Rebuild the runtime library with these new paths
if (!DirsToAdd.IsEmpty())
{
GCM->InitializeRuntimeObjectLibrary();
}
const int32 PostInitializeNumCues = RuntimeGameplayCueSet ? RuntimeGameplayCueSet->GameplayCueData.Num() : 0;
if (PreInitializeNumCues != PostInitializeNumCues)
{
GCM->RefreshGameplayCuePrimaryAsset();
}
}
}
}
}
void ULyraGameFeature_AddGameplayCuePaths::OnGameFeatureUnregistering(const UGameFeatureData* GameFeatureData, const FString& PluginName, const FString& PluginURL)
{
const FString PluginRootPath = TEXT("/") + PluginName;
for (const UGameFeatureAction* Action : GameFeatureData->GetActions())
{
if (const UGameFeatureAction_AddGameplayCuePath* AddGameplayCueGFA = Cast<UGameFeatureAction_AddGameplayCuePath>(GameFeatureData))
{
const TArray<FDirectoryPath>& DirsToAdd = AddGameplayCueGFA->GetDirectoryPathsToAdd();
if (UGameplayCueManager* GCM = UAbilitySystemGlobals::Get().GetGameplayCueManager())
{
int32 NumRemoved = 0;
for (const FDirectoryPath& Directory : DirsToAdd)
{
FString MutablePath = Directory.Path;
UGameFeaturesSubsystem::FixPluginPackagePath(MutablePath, PluginRootPath, false);
NumRemoved += GCM->RemoveGameplayCueNotifyPath(MutablePath, /** bShouldRescanCueAssets = */ false);
}
ensure(NumRemoved == DirsToAdd.Num());
// Rebuild the runtime library only if there is a need to
if (NumRemoved > 0)
{
GCM->InitializeRuntimeObjectLibrary();
}
}
}
}
}