OLS/Source/ols/Private/Systems/OLSAssetManagerStartupJob.cpp

47 lines
1.5 KiB
C++

// © 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 "Systems/OLSAssetManagerStartupJob.h"
TSharedPtr<FStreamableHandle> FOLSAssetManagerStartupJob::DoJob() const
{
const double jobStartTime = FPlatformTime::Seconds();
TSharedPtr<FStreamableHandle> handle;
// @Todo replace this with our custom log.
// UE_LOG(LogLyra, Display, TEXT("Startup job \"%s\" starting"), *JobName);
JobFunc(*this, handle);
if (handle.IsValid())
{
handle->BindUpdateDelegate(FStreamableUpdateDelegate::CreateRaw(this, &FOLSAssetManagerStartupJob::UpdateSubstepProgressFromStreamable));
handle->WaitUntilComplete(0.0f, false);
handle->BindUpdateDelegate(FStreamableUpdateDelegate());
}
// @Todo replace this with our custom log.
// UE_LOG(LogLyra, Display, TEXT("Startup job \"%s\" took %.2f seconds to complete"), *JobName, FPlatformTime::Seconds() - jobStartTime);
return handle;
}
void FOLSAssetManagerStartupJob::UpdateSubstepProgress(float newProgress) const
{
SubstepProgressDelegate.ExecuteIfBound(newProgress);
}
void FOLSAssetManagerStartupJob::UpdateSubstepProgressFromStreamable(
TSharedRef<FStreamableHandle> 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;
}
}
}