// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Containers/UnrealString.h" #include "Delegates/Delegate.h" #include "Engine/StreamableManager.h" #include "HAL/PlatformTime.h" #include "Templates/Function.h" #include "Templates/SharedPointer.h" DECLARE_DELEGATE_OneParam(FLyraAssetManagerStartupJobSubstepProgress, float /*NewProgress*/); /** Handles reporting progress from streamable handles */ struct FLyraAssetManagerStartupJob { FLyraAssetManagerStartupJobSubstepProgress SubstepProgressDelegate; TFunction&)> JobFunc; FString JobName; float JobWeight; mutable double LastUpdate = 0; /** Simple job that is all synchronous */ FLyraAssetManagerStartupJob(const FString& InJobName, const TFunction&)>& InJobFunc, float InJobWeight) : JobFunc(InJobFunc) , JobName(InJobName) , JobWeight(InJobWeight) {} /** Perform actual loading, will return a handle if it created one */ TSharedPtr DoJob() const; void UpdateSubstepProgress(float NewProgress) const { SubstepProgressDelegate.ExecuteIfBound(NewProgress); } void UpdateSubstepProgressFromStreamable(TSharedRef StreamableHandle) const { if (SubstepProgressDelegate.IsBound()) { // StreamableHandle::GetProgress traverses() a large graph and is quite expensive double Now = FPlatformTime::Seconds(); if (LastUpdate - Now > 1.0 / 60) { SubstepProgressDelegate.Execute(StreamableHandle->GetProgress()); LastUpdate = Now; } } } };