diff --git a/src/Linker/Game/IW3/ZoneCreatorIW3.cpp b/src/Linker/Game/IW3/ZoneCreatorIW3.cpp index 7266fc52..969380b3 100644 --- a/src/Linker/Game/IW3/ZoneCreatorIW3.cpp +++ b/src/Linker/Game/IW3/ZoneCreatorIW3.cpp @@ -1,71 +1,14 @@ #include "ZoneCreatorIW3.h" -#include "AssetLoading/AssetLoadingContext.h" -#include "Game/IW3/GameAssetPoolIW3.h" -#include "Game/IW3/GameIW3.h" -#include "IObjLoader.h" -#include "ObjLoading.h" -#include "Utils/StringUtils.h" +#include "Game/IW3/IW3.h" using namespace IW3; -std::vector ZoneCreator::CreateGdtList(const ZoneCreationContext& context) -{ - std::vector gdtList; - gdtList.reserve(context.m_gdt_files.size()); - for (const auto& gdt : context.m_gdt_files) - gdtList.push_back(gdt.get()); - - return gdtList; -} - -void ZoneCreator::ApplyIgnoredAssets(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; -} - -void ZoneCreator::CreateZoneAssetPools(Zone* zone) const -{ - zone->m_pools = std::make_unique(zone, zone->m_priority); - - for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) - zone->m_pools->InitPoolDynamic(assetType); -} - GameId ZoneCreator::GetGameId() const { return GameId::IW3; } -std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const -{ - auto zone = std::make_unique(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW3)); - CreateZoneAssetPools(zone.get()); - - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!assetEntry.m_is_reference) - continue; - - context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference); - } - - const auto assetLoadingContext = std::make_unique(*zone, *context.m_asset_search_path, CreateGdtList(context)); - ApplyIgnoredAssets(context, *assetLoadingContext); - - const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::IW3); - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) - return nullptr; - } - - objLoader->FinalizeAssetsForZone(*assetLoadingContext); - - return zone; -} - asset_type_t ZoneCreator::GetImageAssetType() const { return ASSET_TYPE_IMAGE; diff --git a/src/Linker/Game/IW3/ZoneCreatorIW3.h b/src/Linker/Game/IW3/ZoneCreatorIW3.h index 7c756cf7..91cc2a19 100644 --- a/src/Linker/Game/IW3/ZoneCreatorIW3.h +++ b/src/Linker/Game/IW3/ZoneCreatorIW3.h @@ -1,20 +1,13 @@ #pragma once -#include "AssetLoading/AssetLoadingContext.h" -#include "Zone/ZoneTypes.h" #include "ZoneCreation/ZoneCreator.h" namespace IW3 { class ZoneCreator final : public IZoneCreator { - static std::vector CreateGdtList(const ZoneCreationContext& context); - static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); - void CreateZoneAssetPools(Zone* zone) const; - public: [[nodiscard]] GameId GetGameId() const override; - [[nodiscard]] std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const override; [[nodiscard]] asset_type_t GetImageAssetType() const override; }; } // namespace IW3 diff --git a/src/Linker/Game/IW4/ZoneCreatorIW4.cpp b/src/Linker/Game/IW4/ZoneCreatorIW4.cpp index 5a1165bb..2b33cb68 100644 --- a/src/Linker/Game/IW4/ZoneCreatorIW4.cpp +++ b/src/Linker/Game/IW4/ZoneCreatorIW4.cpp @@ -1,70 +1,14 @@ #include "ZoneCreatorIW4.h" -#include "Game/IW4/GameAssetPoolIW4.h" -#include "Game/IW4/GameIW4.h" -#include "IObjLoader.h" -#include "ObjLoading.h" -#include "Utils/StringUtils.h" +#include "Game/IW4/IW4.h" using namespace IW4; -std::vector ZoneCreator::CreateGdtList(const ZoneCreationContext& context) -{ - std::vector gdtList; - gdtList.reserve(context.m_gdt_files.size()); - for (const auto& gdt : context.m_gdt_files) - gdtList.push_back(gdt.get()); - - return gdtList; -} - -void ZoneCreator::ApplyIgnoredAssets(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; -} - -void ZoneCreator::CreateZoneAssetPools(Zone* zone) const -{ - zone->m_pools = std::make_unique(zone, zone->m_priority); - - for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) - zone->m_pools->InitPoolDynamic(assetType); -} - GameId ZoneCreator::GetGameId() const { return GameId::IW4; } -std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const -{ - auto zone = std::make_unique(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW4)); - CreateZoneAssetPools(zone.get()); - - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!assetEntry.m_is_reference) - continue; - - context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference); - } - - const auto assetLoadingContext = std::make_unique(*zone, *context.m_asset_search_path, CreateGdtList(context)); - ApplyIgnoredAssets(context, *assetLoadingContext); - - const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::IW4); - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) - return nullptr; - } - - objLoader->FinalizeAssetsForZone(*assetLoadingContext); - - return zone; -} - asset_type_t ZoneCreator::GetImageAssetType() const { return ASSET_TYPE_IMAGE; diff --git a/src/Linker/Game/IW4/ZoneCreatorIW4.h b/src/Linker/Game/IW4/ZoneCreatorIW4.h index 7523c790..5c439361 100644 --- a/src/Linker/Game/IW4/ZoneCreatorIW4.h +++ b/src/Linker/Game/IW4/ZoneCreatorIW4.h @@ -1,20 +1,13 @@ #pragma once -#include "AssetLoading/AssetLoadingContext.h" -#include "Zone/ZoneTypes.h" #include "ZoneCreation/ZoneCreator.h" namespace IW4 { class ZoneCreator final : public IZoneCreator { - static std::vector CreateGdtList(const ZoneCreationContext& context); - static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); - void CreateZoneAssetPools(Zone* zone) const; - public: [[nodiscard]] GameId GetGameId() const override; - [[nodiscard]] std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const override; [[nodiscard]] asset_type_t GetImageAssetType() const override; }; } // namespace IW4 diff --git a/src/Linker/Game/IW5/ZoneCreatorIW5.cpp b/src/Linker/Game/IW5/ZoneCreatorIW5.cpp index a31841a6..c7700dd4 100644 --- a/src/Linker/Game/IW5/ZoneCreatorIW5.cpp +++ b/src/Linker/Game/IW5/ZoneCreatorIW5.cpp @@ -1,70 +1,14 @@ #include "ZoneCreatorIW5.h" -#include "Game/IW5/GameAssetPoolIW5.h" -#include "Game/IW5/GameIW5.h" -#include "IObjLoader.h" -#include "ObjLoading.h" -#include "Utils/StringUtils.h" +#include "Game/IW5/IW5.h" using namespace IW5; -std::vector ZoneCreator::CreateGdtList(const ZoneCreationContext& context) -{ - std::vector gdtList; - gdtList.reserve(context.m_gdt_files.size()); - for (const auto& gdt : context.m_gdt_files) - gdtList.push_back(gdt.get()); - - return gdtList; -} - -void ZoneCreator::ApplyIgnoredAssets(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; -} - -void ZoneCreator::CreateZoneAssetPools(Zone* zone) const -{ - zone->m_pools = std::make_unique(zone, zone->m_priority); - - for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) - zone->m_pools->InitPoolDynamic(assetType); -} - GameId ZoneCreator::GetGameId() const { return GameId::IW5; } -std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const -{ - auto zone = std::make_unique(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW5)); - CreateZoneAssetPools(zone.get()); - - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!assetEntry.m_is_reference) - continue; - - context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference); - } - - const auto assetLoadingContext = std::make_unique(*zone, *context.m_asset_search_path, CreateGdtList(context)); - ApplyIgnoredAssets(context, *assetLoadingContext); - - const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::IW5); - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) - return nullptr; - } - - objLoader->FinalizeAssetsForZone(*assetLoadingContext); - - return zone; -} - asset_type_t ZoneCreator::GetImageAssetType() const { return ASSET_TYPE_IMAGE; diff --git a/src/Linker/Game/IW5/ZoneCreatorIW5.h b/src/Linker/Game/IW5/ZoneCreatorIW5.h index cee48755..02856166 100644 --- a/src/Linker/Game/IW5/ZoneCreatorIW5.h +++ b/src/Linker/Game/IW5/ZoneCreatorIW5.h @@ -1,19 +1,13 @@ #pragma once -#include "AssetLoading/AssetLoadingContext.h" -#include "Zone/ZoneTypes.h" + #include "ZoneCreation/ZoneCreator.h" namespace IW5 { class ZoneCreator final : public IZoneCreator { - static std::vector CreateGdtList(const ZoneCreationContext& context); - static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); - void CreateZoneAssetPools(Zone* zone) const; - public: [[nodiscard]] GameId GetGameId() const override; - [[nodiscard]] std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const override; [[nodiscard]] asset_type_t GetImageAssetType() const override; }; } // namespace IW5 diff --git a/src/Linker/Game/T5/ZoneCreatorT5.cpp b/src/Linker/Game/T5/ZoneCreatorT5.cpp index ee72e9df..47dc181d 100644 --- a/src/Linker/Game/T5/ZoneCreatorT5.cpp +++ b/src/Linker/Game/T5/ZoneCreatorT5.cpp @@ -1,71 +1,14 @@ #include "ZoneCreatorT5.h" -#include "AssetLoading/AssetLoadingContext.h" -#include "Game/T5/GameAssetPoolT5.h" -#include "Game/T5/GameT5.h" -#include "IObjLoader.h" -#include "ObjLoading.h" -#include "Utils/StringUtils.h" +#include "Game/T5/T5.h" using namespace T5; -std::vector ZoneCreator::CreateGdtList(ZoneCreationContext& context) -{ - std::vector gdtList; - gdtList.reserve(context.m_gdt_files.size()); - for (const auto& gdt : context.m_gdt_files) - gdtList.push_back(gdt.get()); - - return gdtList; -} - -void ZoneCreator::ApplyIgnoredAssets(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; -} - -void ZoneCreator::CreateZoneAssetPools(Zone* zone) const -{ - zone->m_pools = std::make_unique(zone, zone->m_priority); - - for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) - zone->m_pools->InitPoolDynamic(assetType); -} - GameId ZoneCreator::GetGameId() const { return GameId::T5; } -std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const -{ - auto zone = std::make_unique(context.m_definition->m_name, 0, IGame::GetGameById(GameId::T5)); - CreateZoneAssetPools(zone.get()); - - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!assetEntry.m_is_reference) - continue; - - context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference); - } - - const auto assetLoadingContext = std::make_unique(*zone, *context.m_asset_search_path, CreateGdtList(context)); - ApplyIgnoredAssets(context, *assetLoadingContext); - - const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::T5); - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) - return nullptr; - } - - objLoader->FinalizeAssetsForZone(*assetLoadingContext); - - return zone; -} - asset_type_t ZoneCreator::GetImageAssetType() const { return ASSET_TYPE_IMAGE; diff --git a/src/Linker/Game/T5/ZoneCreatorT5.h b/src/Linker/Game/T5/ZoneCreatorT5.h index a7c8e2e6..25e34eb2 100644 --- a/src/Linker/Game/T5/ZoneCreatorT5.h +++ b/src/Linker/Game/T5/ZoneCreatorT5.h @@ -1,19 +1,13 @@ #pragma once -#include "AssetLoading/AssetLoadingContext.h" -#include "Zone/ZoneTypes.h" + #include "ZoneCreation/ZoneCreator.h" namespace T5 { class ZoneCreator final : public IZoneCreator { - static std::vector CreateGdtList(ZoneCreationContext& context); - static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); - void CreateZoneAssetPools(Zone* zone) const; - public: [[nodiscard]] GameId GetGameId() const override; - [[nodiscard]] std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const override; [[nodiscard]] asset_type_t GetImageAssetType() const override; }; } // namespace T5 diff --git a/src/Linker/Game/T6/ZoneCreatorT6.cpp b/src/Linker/Game/T6/ZoneCreatorT6.cpp index 960e258d..7bf7d79d 100644 --- a/src/Linker/Game/T6/ZoneCreatorT6.cpp +++ b/src/Linker/Game/T6/ZoneCreatorT6.cpp @@ -1,42 +1,26 @@ #include "ZoneCreatorT6.h" #include "Game/T6/CommonT6.h" -#include "Game/T6/GameAssetPoolT6.h" -#include "Game/T6/GameT6.h" #include "Game/T6/T6.h" #include "IObjLoader.h" #include "ObjLoading.h" -#include "Utils/StringUtils.h" +#include #include using namespace T6; -std::vector ZoneCreator::CreateGdtList(const ZoneCreationContext& context) +GameId ZoneCreator::GetGameId() const { - std::vector gdtList; - gdtList.reserve(context.m_gdt_files.size()); - for (const auto& gdt : context.m_gdt_files) - gdtList.push_back(gdt.get()); - - return gdtList; + return GameId::T6; } -void ZoneCreator::ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext) +asset_type_t ZoneCreator::GetImageAssetType() const { - for (const auto& ignoreEntry : creationContext.m_ignored_assets.m_entries) - loadingContext.m_ignored_asset_map[ignoreEntry.m_name] = ignoreEntry.m_type; + return ASSET_TYPE_IMAGE; } -void ZoneCreator::CreateZoneAssetPools(Zone* zone) const -{ - zone->m_pools = std::make_unique(zone, zone->m_priority); - - for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) - zone->m_pools->InitPoolDynamic(assetType); -} - -void ZoneCreator::HandleMetadata(Zone* zone, const ZoneCreationContext& context) const +void ZoneCreator::HandleMetadata(Zone& zone, const ZoneCreationContext& context) const { std::vector kvpList; @@ -56,7 +40,7 @@ void ZoneCreator::HandleMetadata(Zone* zone, const ZoneCreationContext& context) if (endPtr != &strValue[strValue.size()]) { - std::cout << "Could not parse metadata key \"" << metaData.first << "\" as hash\n"; + std::cerr << std::format("Could not parse metadata key \"{}\" as hash\n", metaData.first); continue; } } @@ -65,61 +49,21 @@ void ZoneCreator::HandleMetadata(Zone* zone, const ZoneCreationContext& context) keyHash = Common::Com_HashKey(strValue.c_str(), 64); } - KeyValuePair kvp{keyHash, Common::Com_HashKey(zone->m_name.c_str(), 64), zone->GetMemory()->Dup(metaData.second.c_str())}; + KeyValuePair kvp{keyHash, Common::Com_HashKey(zone.m_name.c_str(), 64), zone.GetMemory()->Dup(metaData.second.c_str())}; kvpList.push_back(kvp); } } if (!kvpList.empty()) { - auto* kvps = zone->GetMemory()->Create(); - kvps->name = zone->GetMemory()->Dup(zone->m_name.c_str()); - kvps->numVariables = kvpList.size(); - kvps->keyValuePairs = zone->GetMemory()->Alloc(kvpList.size()); + auto* kvps = zone.GetMemory()->Create(); + kvps->name = zone.GetMemory()->Dup(zone.m_name.c_str()); + kvps->numVariables = static_cast(kvpList.size()); + kvps->keyValuePairs = zone.GetMemory()->Alloc(kvpList.size()); for (auto i = 0u; i < kvpList.size(); i++) kvps->keyValuePairs[i] = kvpList[i]; - zone->m_pools->AddAsset(std::make_unique>(ASSET_TYPE_KEYVALUEPAIRS, zone->m_name, kvps)); + zone.m_pools->AddAsset(std::make_unique>(ASSET_TYPE_KEYVALUEPAIRS, zone.m_name, kvps)); } } - -GameId ZoneCreator::GetGameId() const -{ - return GameId::T6; -} - -std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const -{ - auto zone = std::make_unique(context.m_definition->m_name, 0, IGame::GetGameById(GameId::T6)); - CreateZoneAssetPools(zone.get()); - - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!assetEntry.m_is_reference) - continue; - - context.m_ignored_assets.m_entries.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name, assetEntry.m_is_reference); - } - - const auto assetLoadingContext = std::make_unique(*zone, *context.m_asset_search_path, CreateGdtList(context)); - ApplyIgnoredAssets(context, *assetLoadingContext); - - HandleMetadata(zone.get(), context); - - const auto* objLoader = IObjLoader::GetObjLoaderForGame(GameId::T6); - for (const auto& assetEntry : context.m_definition->m_assets) - { - if (!objLoader->LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) - return nullptr; - } - - objLoader->FinalizeAssetsForZone(*assetLoadingContext); - - return zone; -} - -asset_type_t ZoneCreator::GetImageAssetType() const -{ - return ASSET_TYPE_IMAGE; -} diff --git a/src/Linker/Game/T6/ZoneCreatorT6.h b/src/Linker/Game/T6/ZoneCreatorT6.h index 17e24c78..5ec4a9db 100644 --- a/src/Linker/Game/T6/ZoneCreatorT6.h +++ b/src/Linker/Game/T6/ZoneCreatorT6.h @@ -1,20 +1,16 @@ #pragma once -#include "AssetLoading/AssetLoadingContext.h" -#include "Zone/ZoneTypes.h" + #include "ZoneCreation/ZoneCreator.h" namespace T6 { class ZoneCreator final : public IZoneCreator { - static std::vector CreateGdtList(const ZoneCreationContext& context); - static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); - void CreateZoneAssetPools(Zone* zone) const; - void HandleMetadata(Zone* zone, const ZoneCreationContext& context) const; - public: [[nodiscard]] GameId GetGameId() const override; - [[nodiscard]] std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const override; [[nodiscard]] asset_type_t GetImageAssetType() const override; + + protected: + void HandleMetadata(Zone& zone, const ZoneCreationContext& context) const override; }; } // namespace T6 diff --git a/src/Linker/Linker.cpp b/src/Linker/Linker.cpp index c82a4fda..973eedc8 100644 --- a/src/Linker/Linker.cpp +++ b/src/Linker/Linker.cpp @@ -217,14 +217,14 @@ class LinkerImpl final : public Linker ISearchPath* gdtSearchPath, ISearchPath* sourceSearchPath) const { - const auto context = std::make_unique(&zoneDefinition, assetSearchPath); - if (!ProcessZoneDefinitionIgnores(targetName, *context, sourceSearchPath)) + ZoneCreationContext context(&zoneDefinition, assetSearchPath); + if (!ProcessZoneDefinitionIgnores(targetName, context, sourceSearchPath)) return nullptr; - if (!LoadGdtFilesFromZoneDefinition(context->m_gdt_files, zoneDefinition, gdtSearchPath)) + if (!LoadGdtFilesFromZoneDefinition(context.m_gdt_files, zoneDefinition, gdtSearchPath)) return nullptr; const auto* creator = IZoneCreator::GetCreatorForGame(zoneDefinition.m_game); - return creator->CreateZoneForDefinition(*context); + return creator->CreateZoneForDefinition(context); } bool WriteZoneToFile(const std::string& projectName, Zone* zone) const @@ -334,11 +334,16 @@ class LinkerImpl final : public Linker if (!zoneDefinition) return false; - const auto& gameName = GameId_Names[static_cast(zoneDefinition->m_game)]; - auto assetSearchPaths = m_search_paths.GetAssetSearchPathsForProject(gameName, projectName); - auto gdtSearchPaths = m_search_paths.GetGdtSearchPathsForProject(gameName, projectName); + auto result = true; - auto result = BuildFastFile(projectName, targetName, *zoneDefinition, assetSearchPaths, gdtSearchPaths, sourceSearchPaths); + if (!zoneDefinition->m_assets.empty()) + { + const auto& gameName = GameId_Names[static_cast(zoneDefinition->m_game)]; + auto assetSearchPaths = m_search_paths.GetAssetSearchPathsForProject(gameName, projectName); + auto gdtSearchPaths = m_search_paths.GetGdtSearchPathsForProject(gameName, projectName); + + result = result && BuildFastFile(projectName, targetName, *zoneDefinition, assetSearchPaths, gdtSearchPaths, sourceSearchPaths); + } m_search_paths.UnloadProjectSpecificSearchPaths(); @@ -362,8 +367,8 @@ class LinkerImpl final : public Linker zoneDirectory = fs::current_path(); auto absoluteZoneDirectory = absolute(zoneDirectory).string(); - auto zone = std::unique_ptr(ZoneLoading::LoadZone(zonePath)); - if (zone == nullptr) + auto zone = ZoneLoading::LoadZone(zonePath); + if (!zone) { std::cerr << std::format("Failed to load zone \"{}\".\n", zonePath); return false; diff --git a/src/Linker/ZoneCreation/ZoneCreator.cpp b/src/Linker/ZoneCreation/ZoneCreator.cpp index 9e1f1004..b8cbfadb 100644 --- a/src/Linker/ZoneCreation/ZoneCreator.cpp +++ b/src/Linker/ZoneCreation/ZoneCreator.cpp @@ -6,6 +6,7 @@ #include "Game/IW5/ZoneCreatorIW5.h" #include "Game/T5/ZoneCreatorT5.h" #include "Game/T6/ZoneCreatorT6.h" +#include "IObjLoader.h" #include @@ -18,6 +19,7 @@ const IZoneCreator* IZoneCreator::GetCreatorForGame(GameId game) new T5::ZoneCreator(), new T6::ZoneCreator(), }; + static_assert(std::extent_v == static_cast(GameId::COUNT)); assert(static_cast(game) < static_cast(GameId::COUNT)); const auto* result = zoneCreators[static_cast(game)]; @@ -25,3 +27,71 @@ const IZoneCreator* IZoneCreator::GetCreatorForGame(GameId game) return result; } + +namespace +{ + std::unique_ptr CreateZone(const ZoneCreationContext& context, const GameId gameId) + { + return std::make_unique(context.m_definition->m_name, 0, IGame::GetGameById(gameId)); + } + + void InitializeAssetPools(Zone& zone, const GameId gameId) + { + zone.m_pools = ZoneAssetPools::CreateForGame(gameId, &zone, zone.m_priority); + const auto assetTypeCount = zone.m_pools->GetAssetTypeCount(); + for (auto assetType = 0; assetType < assetTypeCount; assetType++) + zone.m_pools->InitPoolDynamic(assetType); + } + + std::vector CreateGdtList(const ZoneCreationContext& context) + { + std::vector gdtList; + gdtList.reserve(context.m_gdt_files.size()); + for (const auto& gdt : context.m_gdt_files) + gdtList.push_back(gdt.get()); + + return gdtList; + } + + void IgnoreReferencesFromAssets(ZoneCreationContext& context) + { + for (const auto& assetEntry : context.m_definition->m_assets) + { + if (!assetEntry.m_is_reference) + continue; + + 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 IZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const +{ + 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* objLoader = IObjLoader::GetObjLoaderForGame(gameId); + for (const auto& assetEntry : context.m_definition->m_assets) + { + if (!objLoader->LoadAssetForZone(assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) + return nullptr; + } + + objLoader->FinalizeAssetsForZone(assetLoadingContext); + + return zone; +} diff --git a/src/Linker/ZoneCreation/ZoneCreator.h b/src/Linker/ZoneCreation/ZoneCreator.h index 470c595d..05cc729f 100644 --- a/src/Linker/ZoneCreation/ZoneCreator.h +++ b/src/Linker/ZoneCreation/ZoneCreator.h @@ -14,8 +14,12 @@ public: IZoneCreator& operator=(IZoneCreator&& other) noexcept = default; [[nodiscard]] virtual GameId GetGameId() const = 0; - [[nodiscard]] virtual std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const = 0; [[nodiscard]] virtual asset_type_t GetImageAssetType() const = 0; + [[nodiscard]] std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const; + static const IZoneCreator* GetCreatorForGame(GameId game); + +protected: + virtual void HandleMetadata(Zone& zone, const ZoneCreationContext& context) const {} }; diff --git a/src/ZoneCommon/Pool/ZoneAssetPools.cpp b/src/ZoneCommon/Pool/ZoneAssetPools.cpp index 9dc79b9a..56b42abf 100644 --- a/src/ZoneCommon/Pool/ZoneAssetPools.cpp +++ b/src/ZoneCommon/Pool/ZoneAssetPools.cpp @@ -1,5 +1,13 @@ #include "ZoneAssetPools.h" +#include "Game/IW3/GameAssetPoolIW3.h" +#include "Game/IW4/GameAssetPoolIW4.h" +#include "Game/IW5/GameAssetPoolIW5.h" +#include "Game/T5/GameAssetPoolT5.h" +#include "Game/T6/GameAssetPoolT6.h" +#include "Game/T6/ZoneConstantsT6.h" + +#include #include ZoneAssetPools::ZoneAssetPools(Zone* zone) @@ -52,3 +60,23 @@ ZoneAssetPools::iterator ZoneAssetPools::end() const { return m_assets_in_order.end(); } + +std::unique_ptr ZoneAssetPools::CreateForGame(const GameId game, Zone* zone, const zone_priority_t priority) +{ + switch (game) + { + case GameId::IW3: + return std::make_unique(zone, priority); + case GameId::IW4: + return std::make_unique(zone, priority); + case GameId::IW5: + return std::make_unique(zone, priority); + case GameId::T5: + return std::make_unique(zone, priority); + case GameId::T6: + return std::make_unique(zone, priority); + default: + assert(false); + return nullptr; + } +} diff --git a/src/ZoneCommon/Pool/ZoneAssetPools.h b/src/ZoneCommon/Pool/ZoneAssetPools.h index 9f6876e0..5f4b1ecf 100644 --- a/src/ZoneCommon/Pool/ZoneAssetPools.h +++ b/src/ZoneCommon/Pool/ZoneAssetPools.h @@ -52,4 +52,6 @@ public: _NODISCARD iterator begin() const; _NODISCARD iterator end() const; + + static std::unique_ptr CreateForGame(GameId game, Zone* zone, zone_priority_t priority); };