chore: adjust asset creation process to use separated AssetCreators

This commit is contained in:
Jan
2024-12-13 23:28:28 +00:00
parent 63046f5681
commit 4f0a405bdc
46 changed files with 638 additions and 278 deletions

View File

@ -1,34 +1,11 @@
#include "ZoneCreator.h"
#include "AssetLoading/AssetLoadingContext.h"
#include "Game/IW3/ZoneCreatorIW3.h"
#include "Game/IW4/ZoneCreatorIW4.h"
#include "Game/IW5/ZoneCreatorIW5.h"
#include "Game/T5/ZoneCreatorT5.h"
#include "Game/T6/ZoneCreatorT6.h"
#include "IObjCompiler.h"
#include "IObjLoader.h"
#include <cassert>
const IZoneCreator* IZoneCreator::GetCreatorForGame(GameId game)
{
static const IZoneCreator* zoneCreators[static_cast<unsigned>(GameId::COUNT)]{
new IW3::ZoneCreator(),
new IW4::ZoneCreator(),
new IW5::ZoneCreator(),
new T5::ZoneCreator(),
new T6::ZoneCreator(),
};
static_assert(std::extent_v<decltype(zoneCreators)> == static_cast<unsigned>(GameId::COUNT));
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
const auto* result = zoneCreators[static_cast<unsigned>(game)];
assert(result);
return result;
}
namespace
{
std::unique_ptr<Zone> CreateZone(const ZoneCreationContext& context, const GameId gameId)
@ -64,43 +41,37 @@ namespace
context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference);
}
}
void ApplyIgnoredAssetsToLoadingContext(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext)
{
for (const auto& ignoreEntry : creationContext.m_ignored_assets.m_entries)
loadingContext.m_ignored_asset_map[ignoreEntry.m_name] = ignoreEntry.m_type;
}
} // namespace
std::unique_ptr<Zone> IZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
namespace zone_creator
{
const auto gameId = GetGameId();
auto zone = CreateZone(context, gameId);
InitializeAssetPools(*zone, gameId);
AssetLoadingContext assetLoadingContext(*zone, *context.m_asset_search_path, CreateGdtList(context));
IgnoreReferencesFromAssets(context);
ApplyIgnoredAssetsToLoadingContext(context, assetLoadingContext);
HandleMetadata(*zone, context);
const auto* objCompiler = IObjCompiler::GetObjCompilerForGame(gameId);
const auto* objLoader = IObjLoader::GetObjLoaderForGame(gameId);
for (const auto& assetEntry : context.m_definition->m_assets)
std::unique_ptr<Zone> CreateZoneForDefinition(GameId gameId, ZoneCreationContext& context)
{
const auto compilerResult = objCompiler->CompileAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name);
if (compilerResult == ObjCompilerResult::FAILURE)
return nullptr;
auto zone = CreateZone(context, gameId);
InitializeAssetPools(*zone, gameId);
if (compilerResult == ObjCompilerResult::NO_COMPILATION_DONE)
IgnoreReferencesFromAssets(context);
IgnoredAssetLookup ignoredAssetLookup(context.m_ignored_assets);
const auto* objCompiler = IObjCompiler::GetObjCompilerForGame(gameId);
const auto* objLoader = IObjLoader::GetObjLoaderForGame(gameId);
AssetCreatorCollection creatorCollection(*zone);
objCompiler->ConfigureCreatorCollection(creatorCollection, *zone, *context.m_definition);
objLoader->ConfigureCreatorCollection(creatorCollection);
AssetCreationContext creationContext(zone.get(), &creatorCollection, &ignoredAssetLookup);
for (const auto& assetEntry : context.m_definition->m_assets)
{
if (!objLoader->LoadAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name))
const auto* createdAsset = creationContext.LoadDependencyGeneric(assetEntry.m_asset_type, assetEntry.m_asset_name);
if (!createdAsset)
return nullptr;
}
creatorCollection.FinalizeZone(creationContext);
return zone;
}
objLoader->FinalizeAssetsForZone(assetLoadingContext);
return zone;
}
} // namespace zone_creator