167 lines
5.6 KiB
C++
167 lines
5.6 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "GameFeatures/LyraGameFeaturePolicy.h"
|
|
|
|
#include "AbilitySystem/LyraGameplayCueManager.h"
|
|
#include "GameFeatureAction.h"
|
|
#include "GameFeatureData.h"
|
|
#include "GameFeaturesSubsystem.h"
|
|
#include "GameplayCueSet.h"
|
|
#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"
|
|
|
|
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();
|
|
}
|
|
|
|
TArray<FPrimaryAssetId> ULyraGameFeaturePolicy::GetPreloadAssetListForGameFeature(const UGameFeatureData* GameFeatureToLoad, bool bIncludeLoadedAssets) const
|
|
{
|
|
return Super::GetPreloadAssetListForGameFeature(GameFeatureToLoad, bIncludeLoadedAssets);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//
|
|
|
|
#include "AbilitySystemGlobals.h"
|
|
#include "GameFeatureAction_AddGameplayCuePath.h"
|
|
#include "GameplayCueManager.h"
|
|
|
|
class FName;
|
|
struct FPrimaryAssetId;
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |