diff --git a/Source/ols/Private/AbilitySystem/OLSAbilitySystemComponent.cpp b/Source/ols/Private/AbilitySystem/OLSAbilitySystemComponent.cpp index f81f926..aaab0f1 100644 --- a/Source/ols/Private/AbilitySystem/OLSAbilitySystemComponent.cpp +++ b/Source/ols/Private/AbilitySystem/OLSAbilitySystemComponent.cpp @@ -5,10 +5,12 @@ #include "AbilitySystemGlobals.h" #include "GameplayCueManager.h" +#include "OLSLog.h" #include "AbilitySystem/OLSBatchGameplayAbilityInterface.h" #include "AbilitySystem/OLSGlobaAbilitySubsystem.h" #include "AnimInstances/OLSBaseLayerAnimInstance.h" +DEFINE_LOG_CATEGORY(LogOLSAbilitySystemComponent); // Sets default values for this component's properties UOLSAbilitySystemComponent::UOLSAbilitySystemComponent() @@ -179,10 +181,9 @@ FActiveGameplayEffectHandle UOLSAbilitySystemComponent::ApplyGameplayEffectClass if (specHandle.IsValid()) { handle = ApplyGameplayEffectSpecToSelf(*specHandle.Data.Get()); - - //@Todo: replace this with our custom log. - UE_LOG(LogAbilitySystemComponent, Verbose, TEXT("[%s] Effect '%s' granted at level %f."), - *GetNameSafe(GetAvatarActor()), *GetNameSafe(effectClass), level); + + OLS_LOG(LogOLSAbilitySystemComponent, Verbose, TEXT("[%s] Effect '%s' granted at level %f."), + GET_UOBJECT_NAME(GetAvatarActor()), GET_UOBJECT_NAME(effectClass), level); } } @@ -201,9 +202,8 @@ FGameplayAbilitySpecHandle UOLSAbilitySystemComponent::GiveAbilityFromClass( const FGameplayAbilitySpec newAbilitySpec(FGameplayAbilitySpec(abilityClass, level, input, GetOwner())); handle = GiveAbility(newAbilitySpec); - //@Todo: replace this with our custom log. - UE_LOG(LogAbilitySystemComponent, Log, TEXT("[%s] Ability '%s' %s at level %d."), - *GetNameSafe(GetAvatarActor()), *GetNameSafe(abilityClass), + OLS_LOG(LogOLSAbilitySystemComponent, Log, TEXT("[%s] Ability '%s' %s at level %d."), + GET_UOBJECT_NAME(GetAvatarActor()), GET_UOBJECT_NAME(abilityClass), handle.IsValid() ? TEXT("successfully granted") : TEXT("failed to be granted"), level); } @@ -217,8 +217,7 @@ bool UOLSAbilitySystemComponent::TryBatchActivateAbility( bool isAbilityActivated = false; if (abilityHandle.IsValid()) { - //@Todo: replace this with our custom log. - // GAS_LOG(Warning, "Ability handle is invalid!"); + OLS_LOG(LogAbilitySystemComponent, Warning, TEXT("Ability handle is invalid!")); return isAbilityActivated; } @@ -237,9 +236,8 @@ bool UOLSAbilitySystemComponent::TryBatchActivateAbility( } else { - // @Todo: replace this with our custom log. - // const FString Message = IsValid(Ability) ? FString::Printf(TEXT("%s does not implement Batch Gameplay Ability Interface"), *GetNameSafe(Ability)) : "is invalid"; - // GAS_LOG_ARGS(Error, "Ability %s!", *Message); + OLS_LOG(LogAbilitySystemComponent, Error, + TEXT("%s does not implement Batch Gameplay Ability Interface"), GET_UOBJECT_NAME(ability)); } } } diff --git a/Source/ols/Private/DataAssets/OLSAbilitySetPrimaryDataAsset.cpp b/Source/ols/Private/DataAssets/OLSAbilitySetDataAsset.cpp similarity index 82% rename from Source/ols/Private/DataAssets/OLSAbilitySetPrimaryDataAsset.cpp rename to Source/ols/Private/DataAssets/OLSAbilitySetDataAsset.cpp index 2d150d0..a32c6d4 100644 --- a/Source/ols/Private/DataAssets/OLSAbilitySetPrimaryDataAsset.cpp +++ b/Source/ols/Private/DataAssets/OLSAbilitySetDataAsset.cpp @@ -1,14 +1,17 @@ // © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action. -#include "DataAssets/OLSAbilitySetPrimaryDataAsset.h" +#include "DataAssets/OLSAbilitySetDataAsset.h" #include "ActiveGameplayEffectHandle.h" #include "GameplayAbilitySpecHandle.h" +#include "OLSLog.h" #include "AbilitySystem/OLSAbilitySystemComponent.h" #include "AbilitySystem/Abilities/OLSGameplayAbility.h" #include "AbilitySystem/Attributes/OLSAttributeSetBase.h" +DEFINE_LOG_CATEGORY(LogOLSAbilitySetDataAsset); + void FOLSAbilitySet_GrantedHandles::AddAbilitySpecHandle(const FGameplayAbilitySpecHandle& handle) { if (handle.IsValid()) @@ -66,11 +69,11 @@ void FOLSAbilitySet_GrantedHandles::TakeFromAbilitySystem(UOLSAbilitySystemCompo GrantedAttributeSets.Reset(); } -UOLSAbilitySetPrimaryDataAsset::UOLSAbilitySetPrimaryDataAsset(const FObjectInitializer& objectInitializer) : Super(objectInitializer) +UOLSAbilitySetDataAsset::UOLSAbilitySetDataAsset(const FObjectInitializer& objectInitializer) : Super(objectInitializer) { } -void UOLSAbilitySetPrimaryDataAsset::GiveToAbilitySystem( +void UOLSAbilitySetDataAsset::GiveToAbilitySystem( UOLSAbilitySystemComponent* olsASC, FOLSAbilitySet_GrantedHandles* outGrantedHandlePtrs, UObject* sourceObject) const @@ -90,11 +93,11 @@ void UOLSAbilitySetPrimaryDataAsset::GiveToAbilitySystem( if (!IsValid(setToGrant.AttributeSet)) { - //@Todo: Replace this with custom log. - // UE_LOG(LogLyraAbilitySystem, Error, TEXT("GrantedAttributes[%d] on ability set [%s] is not valid"), SetIndex, *GetNameSafe(this)); + OLS_LOG(LogOLSAbilitySetDataAsset, Error, TEXT("GrantedAttributes[%d] on ability set [%s] is not valid"), + setIndex, GET_UOBJECT_NAME(this)); continue; } - + UAttributeSet* newSet = NewObject(olsASC->GetOwner(), setToGrant.AttributeSet); olsASC->AddAttributeSetSubobject(newSet); @@ -111,8 +114,8 @@ void UOLSAbilitySetPrimaryDataAsset::GiveToAbilitySystem( if (!IsValid(AbilityToGrant.Ability)) { - //@Todo: Replace this with custom log. - // UE_LOG(LogLyraAbilitySystem, Error, TEXT("GrantedGameplayAbilities[%d] on ability set [%s] is not valid."), AbilityIndex, *GetNameSafe(this)); + OLS_LOG(LogOLSAbilitySetDataAsset, Error, TEXT("GrantedGameplayAbilities[%d] on ability set [%s] is not valid"), + abilityIndex, GET_UOBJECT_NAME(this)); continue; } @@ -137,8 +140,8 @@ void UOLSAbilitySetPrimaryDataAsset::GiveToAbilitySystem( if (!IsValid(EffectToGrant.GameplayEffect)) { - //@Todo: Replace this with custom log. - // UE_LOG(LogLyraAbilitySystem, Error, TEXT("GrantedGameplayEffects[%d] on ability set [%s] is not valid"), EffectIndex, *GetNameSafe(this)); + OLS_LOG(LogOLSAbilitySetDataAsset, Error, TEXT("GrantedGameplayEffects[%d] on ability set [%s] is not valid"), + effectIndex, GET_UOBJECT_NAME(this)); continue; } diff --git a/Source/ols/Private/Player/OLSPlayerState.cpp b/Source/ols/Private/Player/OLSPlayerState.cpp index 28080c2..b739de2 100644 --- a/Source/ols/Private/Player/OLSPlayerState.cpp +++ b/Source/ols/Private/Player/OLSPlayerState.cpp @@ -7,7 +7,7 @@ #include "AbilitySystem/Attributes/OLSCombatAttributeSet.h" #include "AbilitySystem/Attributes/OLSHealthAttributeSet.h" #include "Components/GameFrameworkComponentManager.h" -#include "DataAssets/OLSAbilitySetPrimaryDataAsset.h" +#include "DataAssets/OLSAbilitySetDataAsset.h" #include "GameModes/OLSExperienceManagerComponent.h" #include "GameModes/OLSGameMode.h" #include "Net/UnrealNetwork.h" @@ -51,7 +51,7 @@ void AOLSPlayerState::SetPawnData(const UOLSPawnDataAsset* pawnData) MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, PawnData, this); - for (const UOLSAbilitySetPrimaryDataAsset* abilityDataAsset : PawnData->AbilitySets) + for (const UOLSAbilitySetDataAsset* abilityDataAsset : PawnData->AbilitySets) { if (abilityDataAsset) { diff --git a/Source/ols/Private/Systems/OLSAssetManager.cpp b/Source/ols/Private/Systems/OLSAssetManager.cpp index a1219ca..ee6996e 100644 --- a/Source/ols/Private/Systems/OLSAssetManager.cpp +++ b/Source/ols/Private/Systems/OLSAssetManager.cpp @@ -3,6 +3,7 @@ #include "Systems/OLSAssetManager.h" +#include "OLSLog.h" #include "DataAssets/OLSGameDataAsset.h" #include "Misc/App.h" #include "Stats/StatsMisc.h" @@ -13,6 +14,8 @@ #include UE_INLINE_GENERATED_CPP_BY_NAME(OLSAssetManager) +DEFINE_LOG_CATEGORY(LogOLSAssetManager); + const FName FOLSBundles::Equipped("Equipped"); ////////////////////////////////////////////////////////////////////// @@ -44,8 +47,7 @@ UOLSAssetManager& UOLSAssetManager::Get() return *Singleton; } - // @Todo replace this our custom log. - // UE_LOG(LogLyra, Fatal, TEXT("Invalid AssetManagerClassName in DefaultEngine.ini. It must be set to LyraAssetManager!")); + OLS_LOG_NO_WORLD(LogOLSAssetManager, Fatal, TEXT("Invalid AssetManagerClassName in DefaultEngine.ini. It must be set to LyraAssetManager!")); // Fatal error above prevents this from being called. return *NewObject(); @@ -53,6 +55,15 @@ UOLSAssetManager& UOLSAssetManager::Get() void UOLSAssetManager::DumpLoadedAssets() { + OLS_LOG_NO_WORLD(LogOLSAssetManager, Log, TEXT("========== Start Dumping Loaded Assets ==========")); + + for (const UObject* loadedAsset : Get().LoadedAssets) + { + OLS_LOG_NO_WORLD(LogOLSAssetManager, Log, TEXT(" %s"), GET_UOBJECT_NAME(loadedAsset)); + } + + OLS_LOG_NO_WORLD(LogOLSAssetManager, Log, TEXT("... %d assets in loaded pool"), Get().LoadedAssets.Num()); + OLS_LOG_NO_WORLD(LogOLSAssetManager, Log, TEXT("========== Finish Dumping Loaded Assets ==========")); } const UOLSGameDataAsset& UOLSAssetManager::GetGameData() @@ -129,8 +140,7 @@ void UOLSAssetManager::StartInitialLoading() { // Load base game data asset - // @Todo uncomment this after implementing GetGameData(). - // STARTUP_JOB_WEIGHTED(GetGameData(), 25.f); + STARTUP_JOB_WEIGHTED(GetGameData(), 25.f); } // Run all the queued up startup jobs @@ -148,8 +158,7 @@ void UOLSAssetManager::PreBeginPIE(bool shouldStartSimulate) const bool shouldAllowInPIE = true; slowTask.MakeDialog(shouldShowCancelButton, shouldAllowInPIE); - // @Todo unlock this comment. - // const ULyraGameData& LocalGameDataCommon = GetGameData(); + const UOLSGameDataAsset& LocalGameDataCommon = GetGameData(); // Intentionally after GetGameData to avoid counting GameData time in this timer SCOPE_LOG_TIME_IN_SECONDS(TEXT("PreBeginPIE asset preloading complete"), nullptr); @@ -176,8 +185,8 @@ UPrimaryDataAsset* UOLSAssetManager::LoadGameDataOfClass( const bool shouldAllowInPIE = true; slowTask.MakeDialog(shouldShowCancelButton, shouldAllowInPIE); #endif - // @Todo replace this log with our custom. - // UE_LOG(LogLyra, Log, TEXT("Loading GameData: %s ..."), *dataClassPath.ToString()); + + OLS_LOG(LogOLSAssetManager, Log, TEXT("Loading GameData: %%s ..."), *dataClassPath.ToString()); SCOPE_LOG_TIME_IN_SECONDS(TEXT(" ... GameData loaded!"), nullptr); // This can be called recursively in the editor because it is called on demand from PostLoad so force a sync load for primary asset and async load the rest in that case @@ -206,8 +215,10 @@ UPrimaryDataAsset* UOLSAssetManager::LoadGameDataOfClass( else { // It is not acceptable to fail to load any GameData asset. It will result in soft failures that are hard to diagnose. - // @Todo replace this log with our custom. - // UE_LOG(LogLyra, Fatal, TEXT("Failed to load GameData asset at %s. Type %s. This is not recoverable and likely means you do not have the correct data to run %s."), *dataClassPath.ToString(), *primaryAssetType.ToString(), FApp::GetProjectName()); + OLS_LOG(LogOLSAssetManager, Fatal, + TEXT( + "Failed to load GameData asset at %s. Type %s. This is not recoverable and likely means you do not have the correct data to run %s." + ), *dataClassPath.ToString(), *primaryAssetType.ToString(), FApp::GetProjectName()); } return asset; @@ -215,64 +226,65 @@ UPrimaryDataAsset* UOLSAssetManager::LoadGameDataOfClass( void UOLSAssetManager::DoAllStartupJobs() { - SCOPED_BOOT_TIMING("ULyraAssetManager::DoAllStartupJobs"); - const double AllStartupJobsStartTime = FPlatformTime::Seconds(); + SCOPED_BOOT_TIMING("UOLSAssetManager::DoAllStartupJobs"); + const double allStartupJobsStartTime = FPlatformTime::Seconds(); - // if (IsRunningDedicatedServer()) - // { - // // No need for periodic progress updates, just run the jobs - // for (const FLyraAssetManagerStartupJob& StartupJob : StartupJobs) - // { - // StartupJob.DoJob(); - // } - // } - // else - // { - // if (StartupJobs.Num() > 0) - // { - // float TotalJobValue = 0.0f; - // for (const FLyraAssetManagerStartupJob& StartupJob : StartupJobs) - // { - // TotalJobValue += StartupJob.JobWeight; - // } - // - // float AccumulatedJobValue = 0.0f; - // for (FLyraAssetManagerStartupJob& StartupJob : StartupJobs) - // { - // const float JobValue = StartupJob.JobWeight; - // StartupJob.SubstepProgressDelegate.BindLambda([This = this, AccumulatedJobValue, JobValue, TotalJobValue](float NewProgress) - // { - // const float SubstepAdjustment = FMath::Clamp(NewProgress, 0.0f, 1.0f) * JobValue; - // const float OverallPercentWithSubstep = (AccumulatedJobValue + SubstepAdjustment) / TotalJobValue; - // - // This->UpdateInitialGameContentLoadPercent(OverallPercentWithSubstep); - // }); - // - // StartupJob.DoJob(); - // - // StartupJob.SubstepProgressDelegate.Unbind(); - // - // AccumulatedJobValue += JobValue; - // - // UpdateInitialGameContentLoadPercent(AccumulatedJobValue / TotalJobValue); - // } - // } - // else - // { - // UpdateInitialGameContentLoadPercent(1.0f); - // } - // } - // - // StartupJobs.Empty(); + if (IsRunningDedicatedServer()) + { + // No need for periodic progress updates, just run the jobs + for (const FOLSAssetManagerStartupJob& startupJob : StartupJobs) + { + startupJob.DoJob(); + } + } + else + { + if (StartupJobs.Num() > 0) + { + float totalJobValue = 0.0f; + for (const FOLSAssetManagerStartupJob& startupJob : StartupJobs) + { + totalJobValue += startupJob.JobWeight; + } + + float accumulatedJobValue = 0.0f; + for (FOLSAssetManagerStartupJob& startupJob : StartupJobs) + { + const float jobValue = startupJob.JobWeight; + startupJob.SubstepProgressDelegate.BindLambda([This = this, accumulatedJobValue, jobValue, totalJobValue](float NewProgress) + { + const float SubstepAdjustment = FMath::Clamp(NewProgress, 0.0f, 1.0f) * jobValue; + const float OverallPercentWithSubstep = (accumulatedJobValue + SubstepAdjustment) / totalJobValue; + + This->UpdateInitialGameContentLoadPercent(OverallPercentWithSubstep); + }); + + startupJob.DoJob(); + + startupJob.SubstepProgressDelegate.Unbind(); + + accumulatedJobValue += jobValue; + + UpdateInitialGameContentLoadPercent(accumulatedJobValue / totalJobValue); + } + } + else + { + UpdateInitialGameContentLoadPercent(1.0f); + } + } + + StartupJobs.Empty(); - // @Todo replace this with our custom log. - // UE_LOG(LogLyra, Display, TEXT("All startup jobs took %.2f seconds to complete"), FPlatformTime::Seconds() - AllStartupJobsStartTime); + OLS_LOG(LogOLSAssetManager, Display, TEXT("All startup jobs took %.2f seconds to complete"), + FPlatformTime::Seconds() - allStartupJobsStartTime); } void UOLSAssetManager::InitializeGameplayCueManager() { SCOPED_BOOT_TIMING("UOLSAssetManager::InitializeGameplayCueManager"); + // @TODO: Implement this after implementing ULyraGameplayCueManager. // ULyraGameplayCueManager* GCM = ULyraGameplayCueManager::Get(); // check(GCM); // GCM->LoadAlwaysLoadedCues(); @@ -280,5 +292,6 @@ void UOLSAssetManager::InitializeGameplayCueManager() void UOLSAssetManager::UpdateInitialGameContentLoadPercent(float gameContentPercent) { + // @TODO: Implement this function. // Could route this to the early startup loading screen } diff --git a/Source/ols/Public/AbilitySystem/OLSAbilitySystemComponent.h b/Source/ols/Public/AbilitySystem/OLSAbilitySystemComponent.h index 1cf70c9..befffea 100644 --- a/Source/ols/Public/AbilitySystem/OLSAbilitySystemComponent.h +++ b/Source/ols/Public/AbilitySystem/OLSAbilitySystemComponent.h @@ -6,6 +6,8 @@ #include "AbilitySystemComponent.h" #include "OLSAbilitySystemComponent.generated.h" +DECLARE_LOG_CATEGORY_EXTERN(LogOLSAbilitySystemComponent, Verbose, All); + /** * CVAR to control the "Play Montage" flow. * Example: OLS.EnableDefaultPlayMontage true diff --git a/Source/ols/Public/DataAssets/OLSAbilitySetPrimaryDataAsset.h b/Source/ols/Public/DataAssets/OLSAbilitySetDataAsset.h similarity index 89% rename from Source/ols/Public/DataAssets/OLSAbilitySetPrimaryDataAsset.h rename to Source/ols/Public/DataAssets/OLSAbilitySetDataAsset.h index 64e9da6..799bdbf 100644 --- a/Source/ols/Public/DataAssets/OLSAbilitySetPrimaryDataAsset.h +++ b/Source/ols/Public/DataAssets/OLSAbilitySetDataAsset.h @@ -5,7 +5,10 @@ #include "CoreMinimal.h" #include "GameplayTagContainer.h" #include "OLSPawnDataAsset.h" -#include "OLSAbilitySetPrimaryDataAsset.generated.h" +#include "OLSAbilitySetDataAsset.generated.h" + +DECLARE_LOG_CATEGORY_EXTERN(LogOLSAbilitySetDataAsset, Verbose, All); + /** * FOLSAbilitySet_GameplayAbility * @@ -102,15 +105,20 @@ protected: TArray> GrantedAttributeSets; }; -UCLASS() -class OLS_API UOLSAbilitySetPrimaryDataAsset : public UOLSPawnDataAsset +/** + * UOLSAbilitySetDataAsset + * + * Non-mutable data asset used to grant gameplay abilities and gameplay effects. + */ +UCLASS(BlueprintType, Const) +class OLS_API UOLSAbilitySetDataAsset : public UOLSPawnDataAsset { GENERATED_BODY() public: - UOLSAbilitySetPrimaryDataAsset(const FObjectInitializer& objectInitializer); + UOLSAbilitySetDataAsset(const FObjectInitializer& objectInitializer); // Grants the ability set to the specified ability system component. // The returned handles can be used later to take away anything that was granted. diff --git a/Source/ols/Public/DataAssets/OLSPawnDataAsset.h b/Source/ols/Public/DataAssets/OLSPawnDataAsset.h index d47fdae..5e3d3c7 100644 --- a/Source/ols/Public/DataAssets/OLSPawnDataAsset.h +++ b/Source/ols/Public/DataAssets/OLSPawnDataAsset.h @@ -33,7 +33,7 @@ public: // Ability sets to grant to this pawn's ability system. UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "OLS|Abilities") - TArray> AbilitySets; + TArray> AbilitySets; // What mapping of ability tags to use for actions taking by this pawn UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "OLS|Abilities") diff --git a/Source/ols/Public/OLSLog.h b/Source/ols/Public/OLSLog.h index 000867f..d190723 100644 --- a/Source/ols/Public/OLSLog.h +++ b/Source/ols/Public/OLSLog.h @@ -29,6 +29,12 @@ */ #define GET_UOBJECT_NAME(obj) obj ? *obj->GetName() : TEXT("NULL") +/* +* Helper Macro which returns the string from GetNameSafe on the UObject it's passed +* (Returns NULL if the pointer is null) +*/ +#define GET_UOBJECT_NAME_SAFE(obj) obj ? *obj->GetNameSafe() : TEXT("NULL") + /* * Helper Macro which returns the string from GetFullName on the UObject it's passed * (Returns NULL if the pointer is null) diff --git a/Source/ols/Public/Systems/OLSAssetManager.h b/Source/ols/Public/Systems/OLSAssetManager.h index 3a8571a..6e8be4f 100644 --- a/Source/ols/Public/Systems/OLSAssetManager.h +++ b/Source/ols/Public/Systems/OLSAssetManager.h @@ -6,6 +6,7 @@ #include "Engine/AssetManager.h" #include "OLSAssetManager.generated.h" +DECLARE_LOG_CATEGORY_EXTERN(LogOLSAssetManager, Verbose, All); struct FOLSBundles {