mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-12 11:41:50 +00:00
chore: adjust asset data when taking from global asset pools
This commit is contained in:
43
src/ObjLoading/Asset/GlobalAssetPoolsLoader.cpp
Normal file
43
src/ObjLoading/Asset/GlobalAssetPoolsLoader.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "GlobalAssetPoolsLoader.h"
|
||||
|
||||
GlobalAssetPoolsAssetStealer::GlobalAssetPoolsAssetStealer(GenericAssetRegistration& registration, Zone& zone, Zone& foreignZone, AssetCreationContext& context)
|
||||
: m_registration(registration),
|
||||
m_zone(zone),
|
||||
m_foreign_zone(foreignZone),
|
||||
m_context(context),
|
||||
m_failure(false)
|
||||
{
|
||||
}
|
||||
|
||||
std::optional<XAssetInfoGeneric*> GlobalAssetPoolsAssetStealer::Visit_Dependency(const asset_type_t assetType, const char* assetName)
|
||||
{
|
||||
auto assetNameToLoad = assetName;
|
||||
if (assetNameToLoad && assetNameToLoad[0] == ',')
|
||||
assetNameToLoad = &assetNameToLoad[1];
|
||||
|
||||
auto* newDependency = m_context.LoadDependencyGeneric(assetType, assetNameToLoad);
|
||||
if (!newDependency)
|
||||
{
|
||||
m_failure = true;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(newDependency);
|
||||
return newDependency;
|
||||
}
|
||||
|
||||
std::optional<scr_string_t> GlobalAssetPoolsAssetStealer::Visit_ScriptString(scr_string_t scriptString)
|
||||
{
|
||||
// Make sure any used script string is available in the created zone
|
||||
return m_zone.m_script_strings.AddOrGetScriptString(m_foreign_zone.m_script_strings.CValue(scriptString));
|
||||
}
|
||||
|
||||
void GlobalAssetPoolsAssetStealer::Visit_IndirectAssetRef(const asset_type_t assetType, const char* assetName)
|
||||
{
|
||||
m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReferenceGeneric(assetType, assetName));
|
||||
}
|
||||
|
||||
bool GlobalAssetPoolsAssetStealer::Failed() const
|
||||
{
|
||||
return m_failure;
|
||||
}
|
||||
@@ -1,7 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Marking/AssetVisitor.h"
|
||||
#include "Marking/BaseAssetMarker.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
class GlobalAssetPoolsAssetStealer : public AssetVisitor
|
||||
{
|
||||
public:
|
||||
GlobalAssetPoolsAssetStealer(GenericAssetRegistration& registration, Zone& zone, Zone& foreignZone, AssetCreationContext& context);
|
||||
|
||||
std::optional<XAssetInfoGeneric*> Visit_Dependency(asset_type_t assetType, const char* assetName) override;
|
||||
std::optional<scr_string_t> Visit_ScriptString(scr_string_t scriptString) override;
|
||||
void Visit_IndirectAssetRef(asset_type_t assetType, const char* assetName) override;
|
||||
|
||||
[[nodiscard]] bool Failed() const;
|
||||
|
||||
private:
|
||||
GenericAssetRegistration& m_registration;
|
||||
Zone& m_zone;
|
||||
Zone& m_foreign_zone;
|
||||
AssetCreationContext& m_context;
|
||||
|
||||
bool m_failure;
|
||||
};
|
||||
|
||||
template<typename AssetType> class GlobalAssetPoolsLoader : public AssetCreator<AssetType>
|
||||
{
|
||||
public:
|
||||
@@ -21,28 +44,12 @@ public:
|
||||
|
||||
AssetRegistration<AssetType> registration(assetName, existingAsset->Asset());
|
||||
|
||||
for (const auto* dependency : existingAsset->m_dependencies)
|
||||
{
|
||||
auto* newDependency = context.LoadDependencyGeneric(dependency->m_type, dependency->m_name);
|
||||
if (newDependency)
|
||||
registration.AddDependency(newDependency);
|
||||
else
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
for (const auto& indirectAssetReference : existingAsset->m_indirect_asset_references)
|
||||
registration.AddIndirectAssetReference(context.LoadIndirectAssetReferenceGeneric(indirectAssetReference.m_type, indirectAssetReference.m_name));
|
||||
|
||||
// Make sure any used script string is available in the created zone
|
||||
// The replacement of the scr_string_t values will be done upon writing
|
||||
for (const auto scrString : existingAsset->m_used_script_strings)
|
||||
m_zone.m_script_strings.AddOrGetScriptString(existingAsset->m_zone->m_script_strings.CValue(scrString));
|
||||
GlobalAssetPoolsAssetStealer stealer(registration, m_zone, *existingAsset->m_zone, context);
|
||||
AssetMarker<AssetType> marker(stealer);
|
||||
marker.Mark(existingAsset->Asset());
|
||||
|
||||
auto* newAsset = context.AddAsset(std::move(registration));
|
||||
|
||||
// Make sure we remember this asset came from another zone
|
||||
newAsset->m_zone = existingAsset->m_zone;
|
||||
|
||||
return AssetCreationResult::Success(newAsset);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ObjLoaderIW3.h"
|
||||
|
||||
#include "Asset/GlobalAssetPoolsLoader.h"
|
||||
#include "Game/IW3/AssetMarkerIW3.h"
|
||||
#include "Game/IW3/GameIW3.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Game/IW3/XModel/LoaderXModelIW3.h"
|
||||
@@ -65,7 +66,7 @@ namespace
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSound>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundCurve>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetLoadedSound>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMap>>(zone));
|
||||
// collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMap>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMapPvs>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetComWorld>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGameWorldSp>>(zone));
|
||||
@@ -78,7 +79,7 @@ namespace
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetMenu>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetLocalize>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetWeapon>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundDriverGlobals>>(zone));
|
||||
// collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundDriverGlobals>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetFx>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetImpactFx>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetRawFile>>(zone));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ObjLoaderIW4.h"
|
||||
|
||||
#include "Asset/GlobalAssetPoolsLoader.h"
|
||||
#include "Game/IW4/AssetMarkerIW4.h"
|
||||
#include "Game/IW4/GameIW4.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW4/XModel/LoaderXModelIW4.h"
|
||||
@@ -79,7 +80,7 @@ namespace
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetPhysPreset>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetPhysCollMap>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetXAnim>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetXModelSurfs>>(zone));
|
||||
// collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetXModelSurfs>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetXModel>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetMaterial>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetPixelShader>>(zone));
|
||||
@@ -90,7 +91,7 @@ namespace
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSound>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundCurve>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetLoadedSound>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMapSp>>(zone));
|
||||
// collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMapSp>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMapMp>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetComWorld>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGameWorldSp>>(zone));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ObjLoaderIW5.h"
|
||||
|
||||
#include "Asset/GlobalAssetPoolsLoader.h"
|
||||
#include "Game/IW5/AssetMarkerIW5.h"
|
||||
#include "Game/IW5/GameIW5.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW5/XModel/LoaderXModelIW5.h"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ObjLoaderT5.h"
|
||||
|
||||
#include "Asset/GlobalAssetPoolsLoader.h"
|
||||
#include "Game/T5/AssetMarkerT5.h"
|
||||
#include "Game/T5/GameT5.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Game/T5/XModel/LoaderXModelT5.h"
|
||||
@@ -71,7 +72,7 @@ namespace
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetImage>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundBank>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundPatch>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMap>>(zone));
|
||||
// collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMap>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMapPvs>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetComWorld>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGameWorldSp>>(zone));
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Asset/GlobalAssetPoolsLoader.h"
|
||||
#include "FontIcon/CsvLoaderFontIconT6.h"
|
||||
#include "FontIcon/JsonLoaderFontIconT6.h"
|
||||
#include "Game/T6/AssetMarkerT6.h"
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
#include "Game/T6/GameT6.h"
|
||||
@@ -340,7 +341,7 @@ namespace T6
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetImage>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundBank>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundPatch>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMap>>(zone));
|
||||
// collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMap>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMapPvs>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetComWorld>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGameWorldSp>>(zone));
|
||||
|
||||
Reference in New Issue
Block a user