Skip to content

Commit

Permalink
optimize impl
Browse files Browse the repository at this point in the history
  • Loading branch information
hxhb committed Sep 24, 2022
1 parent ff96aa2 commit 2bb26dc
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ int32 UHotSingleCookerCommandlet::Main(const FString& Params)
THotPatcherTemplateHelper::TSerializeStructAsJsonString(*ExportSingleCookerSetting,FinalConfig);
}

if(IsRunningCommandlet() && ExportSingleCookerSetting->bPackageTracker && ExportSingleCookerSetting->bCookPackageTrackerAssets)
{
SCOPED_NAMED_EVENT_TEXT("SearchAllAssets",FColor::Red);
// load asset registry
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
AssetRegistryModule.Get().SearchAllAssets(true);
}
// if(IsRunningCommandlet() && ExportSingleCookerSetting->bPackageTracker && ExportSingleCookerSetting->bCookPackageTrackerAssets)
// {
// SCOPED_NAMED_EVENT_TEXT("SearchAllAssets",FColor::Red);
// // load asset registry
// FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
// AssetRegistryModule.Get().SearchAllAssets(true);
// }

UE_LOG(LogHotSingleCookerCommandlet, Display, TEXT("Cooker %s Id %d,Assets Num %d"), *ExportSingleCookerSetting->MissionName,ExportSingleCookerSetting->MissionID,ExportSingleCookerSetting->CookAssets.Num());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ FString UFlibHotCookerHelper::GetCookerProcFailedResultPath(const FString& BaseD

FString UFlibHotCookerHelper::GetProfilingCmd()
{
return FString::Printf(TEXT("-trace=cpu,memory,loadtime -statnamedevents implies -llm"));
return FString::Printf(TEXT("-tracehost=127.0.0.1 -trace=cpu,memory,loadtime -statnamedevents implies -llm"));
}

TSharedPtr<FCookShaderCollectionProxy> UFlibHotCookerHelper::CreateCookShaderCollectionProxyByPlatform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,26 @@ FCookCluster USingleCookerProxy::GetPackageTrackerAsCluster()

PackageTrackerCluster.CookActionCallback.OnAssetCooked = GetOnPackageSavedCallback();
PackageTrackerCluster.CookActionCallback.OnCookBegin = GetOnCookAssetBeginCallback();

if(PackageTracker && GetSettingObject()->bCookPackageTrackerAssets)
{
PackageTrackerCluster.AssetDetails.Empty();
for(FName PackagePath:PackageTracker->GetPendingPackageSet())
{
FAssetDetail AssetDetail = UFlibAssetManageHelper::GetAssetDetailByPackageName(PackagePath.ToString());
if(AssetDetail.IsValid())
// make asset data to asset registry
FSoftObjectPath ObjectPath(PackagePath);
FAssetData AssetData;
if(UAssetManager::Get().GetAssetDataForPath(ObjectPath,AssetData))
{
PackageTrackerCluster.AssetDetails.Emplace(AssetDetail);
FAssetDetail AssetDetail;
if(UFlibAssetManageHelper::ConvFAssetDataToFAssetDetail(AssetData,AssetDetail))
{
PackageTrackerCluster.AssetDetails.Emplace(AssetDetail);
}
}
else
{
UE_LOG(LogHotPatcher,Warning,TEXT("[GetPackageTrackerAsCluster] Get %s AssetData Failed!"),*PackagePath.ToString());
}
}
}
Expand Down Expand Up @@ -708,19 +718,32 @@ void USingleCookerProxy::OnAssetCookedHandle(const FSoftObjectPath& PackagePath,
{
FScopeLock Lock(&SynchronizationObject);
SCOPED_NAMED_EVENT_TEXT("OnAssetCookedHandle",FColor::Red);


FString PlatformName = THotPatcherTemplateHelper::GetEnumNameByValue(Platform);
FString SavePackageResultStr = UFlibHotPatcherCoreHelper::GetSavePackageResultStr(Result);
FName AssetPathName = PackagePath.GetAssetPathName();
GetPaendingCookAssetsSet().Remove(AssetPathName);
FString AssetPath = PackagePath.GetAssetPathString();

if(Result == ESavePackageResult::Success)
{
GetPlatformCookAssetOrders(Platform).Add(AssetPathName);
}
else
GetPaendingCookAssetsSet().Remove(AssetPathName);

switch(Result)
{
SCOPED_NAMED_EVENT_TEXT("USingleCookerProxy::OnCookAssetFailed",FColor::Red);
UE_LOG(LogHotPatcher,Warning,TEXT("Cook %s for %d Failed (%s)!"),*PackagePath.GetAssetPathString(),(int32)Platform, *UFlibHotPatcherCoreHelper::GetSavePackageResultStr(Result));
GetCookFailedAssetsCollection().CookFailedAssets.FindOrAdd(Platform).PackagePaths.Add(AssetPathName);
case ESavePackageResult::Success:
{
GetPlatformCookAssetOrders(Platform).Add(AssetPathName);
break;
}
case ESavePackageResult::Error:
case ESavePackageResult::MissingFile:
{
UE_LOG(LogHotPatcher,Error,TEXT("CookError %s for %s (%s)!"),*AssetPath,*PlatformName,*SavePackageResultStr);
GetCookFailedAssetsCollection().CookFailedAssets.FindOrAdd(Platform).PackagePaths.Add(AssetPathName);
break;
}
default:
{
UE_LOG(LogHotPatcher,Warning,TEXT("CookWarning %s for %s Failed (%s)!"),*AssetPath,*PlatformName, *SavePackageResultStr);
}
}
}

Expand Down Expand Up @@ -775,22 +798,7 @@ TSet<FName> USingleCookerProxy::GetAdditionalAssets()
return TSet<FName>{};
}

TArray<UClass*> GetClassesByNames(const TArray<FName>& ClassesNames)
{
TArray<UClass*> result;
for(const auto& ClassesName:ClassesNames)
{
for (TObjectIterator<UClass> Itt; Itt; ++Itt)
{
if((*Itt)->GetName().Equals(ClassesName.ToString()))
{
result.Add(*Itt);
break;
}
}
}
return result;
}

// pre cache asset type order
TArray<UClass*> USingleCookerProxy::GetPreCacheClasses() const
{
Expand All @@ -802,10 +810,10 @@ TArray<UClass*> USingleCookerProxy::GetPreCacheClasses() const
TEXT("Texture"),
TEXT("PaperSprite"),
// material
TEXT("MaterialExpression"),
TEXT("MaterialParameterCollection"),
TEXT("MaterialFunctionInterface"),
TEXT("MaterialInterface"),
// TEXT("MaterialExpression"),
// TEXT("MaterialParameterCollection"),
// TEXT("MaterialFunctionInterface"),
// TEXT("MaterialInterface"),
// other
TEXT("PhysicsAsset"),
TEXT("PhysicalMaterial"),
Expand All @@ -832,13 +840,13 @@ TArray<UClass*> USingleCookerProxy::GetPreCacheClasses() const
// large ref asset
TEXT("ActorSequence"),
TEXT("LevelSequence"),
TEXT("World")
TEXT("World")
};

for(auto& ParentClass:GetClassesByNames(ParentClassesName))
for(auto& ParentClass:UFlibHotPatcherCoreHelper::GetClassesByNames(ParentClassesName))
{
Classes.Append(UFlibHotPatcherCoreHelper::GetDerivedClasses(ParentClass,true,true));
}

Classes.Append(UFlibHotPatcherCoreHelper::GetAllMaterialClasses());
return Classes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,7 @@ void UFlibHotPatcherCoreHelper::CacheForCookedPlatformData(
for(auto Package:Packages)
{
FString LongPackageName = UFlibAssetManageHelper::LongPackageNameToPackagePath(Package->GetPathName());
FExecTimeRecoder PreGeneratePlatformDataTimer(FString::Printf(TEXT("PreGeneratePlatformData %s"),*LongPackageName));
// FExecTimeRecoder PreGeneratePlatformDataTimer(FString::Printf(TEXT("PreGeneratePlatformData %s"),*LongPackageName));
FString FakePackageName = FString(TEXT("Package ")) + LongPackageName;

#if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 25
Expand Down Expand Up @@ -2249,7 +2249,7 @@ void UFlibHotPatcherCoreHelper::WaitObjectsCachePlatformDataComplete(TSet<UObjec
TArray<ITargetPlatform*> TargetPlatforms)
{
SCOPED_NAMED_EVENT_TEXT("WaitObjectsCachePlatformDataComplete",FColor::Red);
FExecTimeRecoder WaitObjectsCachePlatformDataCompleteTimer(TEXT("WaitObjectsCachePlatformDataComplete"));
// FExecTimeRecoder WaitObjectsCachePlatformDataCompleteTimer(TEXT("WaitObjectsCachePlatformDataComplete"));
if (GShaderCompilingManager)
{
// Wait for all shaders to finish compiling
Expand Down Expand Up @@ -2294,7 +2294,8 @@ void UFlibHotPatcherCoreHelper::WaitObjectsCachePlatformDataComplete(TSet<UObjec

if(!!PendingCachePlatformDataObjects.Num())
{
FPlatformProcess::Sleep(0.001f);
FPlatformProcess::Sleep(0.1f);
GLog->Flush();
}
}
}
Expand Down Expand Up @@ -2494,4 +2495,48 @@ TempSandboxFile.Get()
);
#endif
return bresult;
}
}
TArray<UClass*> UFlibHotPatcherCoreHelper::GetClassesByNames(const TArray<FName>& ClassesNames)
{
TArray<UClass*> result;
for(const auto& ClassesName:ClassesNames)
{
for (TObjectIterator<UClass> Itt; Itt; ++Itt)
{
if((*Itt)->GetName().Equals(ClassesName.ToString()))
{
result.Add(*Itt);
break;
}
}
}
return result;
}

TArray<UClass*> UFlibHotPatcherCoreHelper::GetAllMaterialClasses()
{
TArray<UClass*> Classes;
TArray<FName> ParentClassesName = {
// materials
TEXT("MaterialExpression"),
TEXT("MaterialParameterCollection"),
TEXT("MaterialFunctionInterface"),
TEXT("Material"),
TEXT("MaterialInterface"),
};
for(auto& ParentClass:GetClassesByNames(ParentClassesName))
{
Classes.Append(UFlibHotPatcherCoreHelper::GetDerivedClasses(ParentClass,true,true));
}
return Classes;
}

TSet<FName> UFlibHotPatcherCoreHelper::GetAllMaterialClassesNames()
{
TSet<FName> result;
for(const auto& Class:GetAllMaterialClasses())
{
result.Add(Class->GetFName());
}
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ void UFlibShaderCodeLibraryHelper::WaitShaderCompilingComplete()
// LastRemainingJob = CurrentNumRemaingingJobs;
// }
FPlatformProcess::Sleep(0.5f);
GLog->Flush();
}

// One last process to get the shaders that were compiled at the very end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct HOTPATCHERCORE_API FSingleCookerSettings:public FHotPatcherCookerSettingB
UPROPERTY(EditAnywhere,BlueprintReadWrite)
int32 MissionID = -1;
UPROPERTY(EditAnywhere,BlueprintReadWrite)
bool bShaderCooker = false;
UPROPERTY(EditAnywhere,BlueprintReadWrite)
FString ShaderLibName;

UPROPERTY(EditAnywhere,BlueprintReadWrite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,7 @@ class HOTPATCHERCORE_API UFlibHotPatcherCoreHelper : public UBlueprintFunctionLi
// need add UNREALED_API to FAssetRegistryGenerator
// all chunksinfo.csv / pakchunklist.txt / assetregistry.bin
static bool SerializeChunksManifests(ITargetPlatform* TargetPlatform, const TSet<FName>&, const TSet<FName>&, bool bGenerateStreamingInstallManifest = true);
static TArray<UClass*> GetClassesByNames(const TArray<FName>& ClassesNames);
static TArray<UClass*> GetAllMaterialClasses();
static TSet<FName> GetAllMaterialClassesNames();
};
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ bool UFlibAssetManageHelper::ConvFAssetDataToFAssetDetail(const FAssetData& InAs
#endif

OutAssetDetail = AssetDetail;
return !OutAssetDetail.AssetType.IsNone() && !OutAssetDetail.AssetType.IsNone() && !OutAssetDetail.AssetType.IsNone();
return OutAssetDetail.IsValid();
}

bool UFlibAssetManageHelper::GetSpecifyAssetDetail(const FString& InLongPackageName, FAssetDetail& OutAssetDetail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1636,9 +1636,11 @@ FString UFlibPatchParserHelper::ReplaceMark(const FString& Src)
result = result.Replace(*Key,*FPaths::ConvertRelativePathToFull(*MarkMap.Find(Key)));
}
}

FPaths::NormalizeFilename(result);
FPaths::CollapseRelativeDirectories(result);
return result;
}

FString UFlibPatchParserHelper::ReplaceMarkPath(const FString& Src)
{
FString result = UFlibPatchParserHelper::ReplaceMark(Src);
Expand Down
2 changes: 1 addition & 1 deletion Mods/HotMultiCooker

0 comments on commit 2bb26dc

Please sign in to comment.