mirror of
				https://github.com/Laupetin/OpenAssetTools.git
				synced 2025-10-31 10:36:58 +00:00 
			
		
		
		
	refactor: use asset_type_t for ZoneDefinition
This commit is contained in:
		| @@ -6,23 +6,8 @@ | ||||
| #include "ObjLoading.h" | ||||
| #include "Utils/StringUtils.h" | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace IW3; | ||||
|  | ||||
| ZoneCreator::ZoneCreator() | ||||
| { | ||||
|     for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) | ||||
|     { | ||||
|         AddAssetTypeName(assetType, GameAssetPoolIW3::AssetTypeNameByType(assetType)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void ZoneCreator::AddAssetTypeName(asset_type_t assetType, std::string name) | ||||
| { | ||||
|     m_asset_types_by_name.emplace(std::make_pair(std::move(name), assetType)); | ||||
| } | ||||
|  | ||||
| std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
| { | ||||
|     std::vector<Gdt*> gdtList; | ||||
| @@ -33,21 +18,10 @@ std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
|     return gdtList; | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const | ||||
| void ZoneCreator::ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext) | ||||
| { | ||||
|     for (const auto& ignoreEntry : context.m_ignored_assets.m_entries) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(ignoreEntry.m_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << ignoreEntry.m_type << "\" for ignore \"" << ignoreEntry.m_name << "\"\n"; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         ignoredAssetMap[ignoreEntry.m_name] = foundAssetTypeEntry->second; | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|     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 | ||||
| @@ -58,12 +32,9 @@ void ZoneCreator::CreateZoneAssetPools(Zone* zone) const | ||||
|         zone->m_pools->InitPoolDynamic(assetType); | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::SupportsGame(const std::string& gameName) const | ||||
| GameId ZoneCreator::GetGameId() const | ||||
| { | ||||
|     auto shortName = g_GameIW3.GetShortName(); | ||||
|     utils::MakeStringLowerCase(shortName); | ||||
|  | ||||
|     return gameName == shortName; | ||||
|     return GameId::IW3; | ||||
| } | ||||
|  | ||||
| std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const | ||||
| @@ -80,19 +51,11 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|     } | ||||
|  | ||||
|     const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context)); | ||||
|     if (!CreateIgnoredAssetMap(context, assetLoadingContext->m_ignored_asset_map)) | ||||
|         return nullptr; | ||||
|     ApplyIgnoredAssets(context, *assetLoadingContext); | ||||
|  | ||||
|     for (const auto& assetEntry : context.m_definition->m_assets) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << assetEntry.m_asset_type << "\"\n"; | ||||
|             return nullptr; | ||||
|         } | ||||
|  | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, foundAssetTypeEntry->second, assetEntry.m_asset_name)) | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) | ||||
|             return nullptr; | ||||
|     } | ||||
|  | ||||
| @@ -100,3 +63,8 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|  | ||||
|     return zone; | ||||
| } | ||||
|  | ||||
| asset_type_t ZoneCreator::GetImageAssetType() const | ||||
| { | ||||
|     return ASSET_TYPE_IMAGE; | ||||
| } | ||||
|   | ||||
| @@ -1,25 +1,20 @@ | ||||
| #pragma once | ||||
| #include "Zone/ZoneTypes.h" | ||||
| #include "ZoneCreation/IZoneCreator.h" | ||||
|  | ||||
| #include <string> | ||||
| #include <unordered_map> | ||||
| #include "AssetLoading/AssetLoadingContext.h" | ||||
| #include "Zone/ZoneTypes.h" | ||||
| #include "ZoneCreation/ZoneCreator.h" | ||||
|  | ||||
| namespace IW3 | ||||
| { | ||||
|     class ZoneCreator final : public IZoneCreator | ||||
|     { | ||||
|         std::unordered_map<std::string, asset_type_t> m_asset_types_by_name; | ||||
|  | ||||
|         void AddAssetTypeName(asset_type_t assetType, std::string name); | ||||
|         static std::vector<Gdt*> CreateGdtList(const ZoneCreationContext& context); | ||||
|         bool CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const; | ||||
|         static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); | ||||
|         void CreateZoneAssetPools(Zone* zone) const; | ||||
|  | ||||
|     public: | ||||
|         ZoneCreator(); | ||||
|  | ||||
|         _NODISCARD bool SupportsGame(const std::string& gameName) const override; | ||||
|         _NODISCARD std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] GameId GetGameId() const override; | ||||
|         [[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] asset_type_t GetImageAssetType() const override; | ||||
|     }; | ||||
| } // namespace IW3 | ||||
|   | ||||
| @@ -5,23 +5,8 @@ | ||||
| #include "ObjLoading.h" | ||||
| #include "Utils/StringUtils.h" | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace IW4; | ||||
|  | ||||
| ZoneCreator::ZoneCreator() | ||||
| { | ||||
|     for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) | ||||
|     { | ||||
|         AddAssetTypeName(assetType, GameAssetPoolIW4::AssetTypeNameByType(assetType)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void ZoneCreator::AddAssetTypeName(asset_type_t assetType, std::string name) | ||||
| { | ||||
|     m_asset_types_by_name.emplace(std::make_pair(std::move(name), assetType)); | ||||
| } | ||||
|  | ||||
| std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
| { | ||||
|     std::vector<Gdt*> gdtList; | ||||
| @@ -32,21 +17,10 @@ std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
|     return gdtList; | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const | ||||
| void ZoneCreator::ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext) | ||||
| { | ||||
|     for (const auto& ignoreEntry : context.m_ignored_assets.m_entries) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(ignoreEntry.m_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << ignoreEntry.m_type << "\" for ignore \"" << ignoreEntry.m_name << "\"\n"; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         ignoredAssetMap[ignoreEntry.m_name] = foundAssetTypeEntry->second; | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|     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 | ||||
| @@ -57,12 +31,9 @@ void ZoneCreator::CreateZoneAssetPools(Zone* zone) const | ||||
|         zone->m_pools->InitPoolDynamic(assetType); | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::SupportsGame(const std::string& gameName) const | ||||
| GameId ZoneCreator::GetGameId() const | ||||
| { | ||||
|     auto shortName = g_GameIW4.GetShortName(); | ||||
|     utils::MakeStringLowerCase(shortName); | ||||
|  | ||||
|     return gameName == shortName; | ||||
|     return GameId::IW4; | ||||
| } | ||||
|  | ||||
| std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const | ||||
| @@ -79,19 +50,11 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|     } | ||||
|  | ||||
|     const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context)); | ||||
|     if (!CreateIgnoredAssetMap(context, assetLoadingContext->m_ignored_asset_map)) | ||||
|         return nullptr; | ||||
|     ApplyIgnoredAssets(context, *assetLoadingContext); | ||||
|  | ||||
|     for (const auto& assetEntry : context.m_definition->m_assets) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << assetEntry.m_asset_type << "\"\n"; | ||||
|             return nullptr; | ||||
|         } | ||||
|  | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, foundAssetTypeEntry->second, assetEntry.m_asset_name)) | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) | ||||
|             return nullptr; | ||||
|     } | ||||
|  | ||||
| @@ -99,3 +62,8 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|  | ||||
|     return zone; | ||||
| } | ||||
|  | ||||
| asset_type_t ZoneCreator::GetImageAssetType() const | ||||
| { | ||||
|     return ASSET_TYPE_IMAGE; | ||||
| } | ||||
|   | ||||
| @@ -1,25 +1,20 @@ | ||||
| #pragma once | ||||
| #include "Zone/ZoneTypes.h" | ||||
| #include "ZoneCreation/IZoneCreator.h" | ||||
|  | ||||
| #include <string> | ||||
| #include <unordered_map> | ||||
| #include "AssetLoading/AssetLoadingContext.h" | ||||
| #include "Zone/ZoneTypes.h" | ||||
| #include "ZoneCreation/ZoneCreator.h" | ||||
|  | ||||
| namespace IW4 | ||||
| { | ||||
|     class ZoneCreator final : public IZoneCreator | ||||
|     { | ||||
|         std::unordered_map<std::string, asset_type_t> m_asset_types_by_name; | ||||
|  | ||||
|         void AddAssetTypeName(asset_type_t assetType, std::string name); | ||||
|         static std::vector<Gdt*> CreateGdtList(const ZoneCreationContext& context); | ||||
|         bool CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const; | ||||
|         static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); | ||||
|         void CreateZoneAssetPools(Zone* zone) const; | ||||
|  | ||||
|     public: | ||||
|         ZoneCreator(); | ||||
|  | ||||
|         _NODISCARD bool SupportsGame(const std::string& gameName) const override; | ||||
|         _NODISCARD std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] GameId GetGameId() const override; | ||||
|         [[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] asset_type_t GetImageAssetType() const override; | ||||
|     }; | ||||
| } // namespace IW4 | ||||
|   | ||||
| @@ -5,23 +5,8 @@ | ||||
| #include "ObjLoading.h" | ||||
| #include "Utils/StringUtils.h" | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace IW5; | ||||
|  | ||||
| ZoneCreator::ZoneCreator() | ||||
| { | ||||
|     for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) | ||||
|     { | ||||
|         AddAssetTypeName(assetType, GameAssetPoolIW5::AssetTypeNameByType(assetType)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void ZoneCreator::AddAssetTypeName(asset_type_t assetType, std::string name) | ||||
| { | ||||
|     m_asset_types_by_name.emplace(std::make_pair(std::move(name), assetType)); | ||||
| } | ||||
|  | ||||
| std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
| { | ||||
|     std::vector<Gdt*> gdtList; | ||||
| @@ -32,21 +17,10 @@ std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
|     return gdtList; | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const | ||||
| void ZoneCreator::ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext) | ||||
| { | ||||
|     for (const auto& ignoreEntry : context.m_ignored_assets.m_entries) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(ignoreEntry.m_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << ignoreEntry.m_type << "\" for ignore \"" << ignoreEntry.m_name << "\"\n"; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         ignoredAssetMap[ignoreEntry.m_name] = foundAssetTypeEntry->second; | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|     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 | ||||
| @@ -57,12 +31,9 @@ void ZoneCreator::CreateZoneAssetPools(Zone* zone) const | ||||
|         zone->m_pools->InitPoolDynamic(assetType); | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::SupportsGame(const std::string& gameName) const | ||||
| GameId ZoneCreator::GetGameId() const | ||||
| { | ||||
|     auto shortName = g_GameIW5.GetShortName(); | ||||
|     utils::MakeStringLowerCase(shortName); | ||||
|  | ||||
|     return gameName == shortName; | ||||
|     return GameId::IW5; | ||||
| } | ||||
|  | ||||
| std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const | ||||
| @@ -79,19 +50,11 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|     } | ||||
|  | ||||
|     const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context)); | ||||
|     if (!CreateIgnoredAssetMap(context, assetLoadingContext->m_ignored_asset_map)) | ||||
|         return nullptr; | ||||
|     ApplyIgnoredAssets(context, *assetLoadingContext); | ||||
|  | ||||
|     for (const auto& assetEntry : context.m_definition->m_assets) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << assetEntry.m_asset_type << "\"\n"; | ||||
|             return nullptr; | ||||
|         } | ||||
|  | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, foundAssetTypeEntry->second, assetEntry.m_asset_name)) | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) | ||||
|             return nullptr; | ||||
|     } | ||||
|  | ||||
| @@ -99,3 +62,8 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|  | ||||
|     return zone; | ||||
| } | ||||
|  | ||||
| asset_type_t ZoneCreator::GetImageAssetType() const | ||||
| { | ||||
|     return ASSET_TYPE_IMAGE; | ||||
| } | ||||
|   | ||||
| @@ -1,25 +1,19 @@ | ||||
| #pragma once | ||||
| #include "AssetLoading/AssetLoadingContext.h" | ||||
| #include "Zone/ZoneTypes.h" | ||||
| #include "ZoneCreation/IZoneCreator.h" | ||||
|  | ||||
| #include <string> | ||||
| #include <unordered_map> | ||||
| #include "ZoneCreation/ZoneCreator.h" | ||||
|  | ||||
| namespace IW5 | ||||
| { | ||||
|     class ZoneCreator final : public IZoneCreator | ||||
|     { | ||||
|         std::unordered_map<std::string, asset_type_t> m_asset_types_by_name; | ||||
|  | ||||
|         void AddAssetTypeName(asset_type_t assetType, std::string name); | ||||
|         static std::vector<Gdt*> CreateGdtList(const ZoneCreationContext& context); | ||||
|         bool CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const; | ||||
|         static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); | ||||
|         void CreateZoneAssetPools(Zone* zone) const; | ||||
|  | ||||
|     public: | ||||
|         ZoneCreator(); | ||||
|  | ||||
|         _NODISCARD bool SupportsGame(const std::string& gameName) const override; | ||||
|         _NODISCARD std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] GameId GetGameId() const override; | ||||
|         [[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] asset_type_t GetImageAssetType() const override; | ||||
|     }; | ||||
| } // namespace IW5 | ||||
|   | ||||
| @@ -6,23 +6,8 @@ | ||||
| #include "ObjLoading.h" | ||||
| #include "Utils/StringUtils.h" | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace T5; | ||||
|  | ||||
| ZoneCreator::ZoneCreator() | ||||
| { | ||||
|     for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) | ||||
|     { | ||||
|         AddAssetTypeName(assetType, GameAssetPoolT5::AssetTypeNameByType(assetType)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void ZoneCreator::AddAssetTypeName(asset_type_t assetType, std::string name) | ||||
| { | ||||
|     m_asset_types_by_name.emplace(std::make_pair(std::move(name), assetType)); | ||||
| } | ||||
|  | ||||
| std::vector<Gdt*> ZoneCreator::CreateGdtList(ZoneCreationContext& context) | ||||
| { | ||||
|     std::vector<Gdt*> gdtList; | ||||
| @@ -33,21 +18,10 @@ std::vector<Gdt*> ZoneCreator::CreateGdtList(ZoneCreationContext& context) | ||||
|     return gdtList; | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const | ||||
| void ZoneCreator::ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext) | ||||
| { | ||||
|     for (const auto& ignoreEntry : context.m_ignored_assets.m_entries) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(ignoreEntry.m_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << ignoreEntry.m_type << "\" for ignore \"" << ignoreEntry.m_name << "\"\n"; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         ignoredAssetMap[ignoreEntry.m_name] = foundAssetTypeEntry->second; | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|     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 | ||||
| @@ -58,12 +32,9 @@ void ZoneCreator::CreateZoneAssetPools(Zone* zone) const | ||||
|         zone->m_pools->InitPoolDynamic(assetType); | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::SupportsGame(const std::string& gameName) const | ||||
| GameId ZoneCreator::GetGameId() const | ||||
| { | ||||
|     auto shortName = g_GameT5.GetShortName(); | ||||
|     utils::MakeStringLowerCase(shortName); | ||||
|  | ||||
|     return gameName == shortName; | ||||
|     return GameId::T5; | ||||
| } | ||||
|  | ||||
| std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const | ||||
| @@ -80,19 +51,11 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|     } | ||||
|  | ||||
|     const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context)); | ||||
|     if (!CreateIgnoredAssetMap(context, assetLoadingContext->m_ignored_asset_map)) | ||||
|         return nullptr; | ||||
|     ApplyIgnoredAssets(context, *assetLoadingContext); | ||||
|  | ||||
|     for (const auto& assetEntry : context.m_definition->m_assets) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << assetEntry.m_asset_type << "\"\n"; | ||||
|             return nullptr; | ||||
|         } | ||||
|  | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, foundAssetTypeEntry->second, assetEntry.m_asset_name)) | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) | ||||
|             return nullptr; | ||||
|     } | ||||
|  | ||||
| @@ -100,3 +63,8 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|  | ||||
|     return zone; | ||||
| } | ||||
|  | ||||
| asset_type_t ZoneCreator::GetImageAssetType() const | ||||
| { | ||||
|     return ASSET_TYPE_IMAGE; | ||||
| } | ||||
|   | ||||
| @@ -1,25 +1,19 @@ | ||||
| #pragma once | ||||
| #include "AssetLoading/AssetLoadingContext.h" | ||||
| #include "Zone/ZoneTypes.h" | ||||
| #include "ZoneCreation/IZoneCreator.h" | ||||
|  | ||||
| #include <string> | ||||
| #include <unordered_map> | ||||
| #include "ZoneCreation/ZoneCreator.h" | ||||
|  | ||||
| namespace T5 | ||||
| { | ||||
|     class ZoneCreator final : public IZoneCreator | ||||
|     { | ||||
|         std::unordered_map<std::string, asset_type_t> m_asset_types_by_name; | ||||
|  | ||||
|         void AddAssetTypeName(asset_type_t assetType, std::string name); | ||||
|         static std::vector<Gdt*> CreateGdtList(ZoneCreationContext& context); | ||||
|         bool CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const; | ||||
|         static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); | ||||
|         void CreateZoneAssetPools(Zone* zone) const; | ||||
|  | ||||
|     public: | ||||
|         ZoneCreator(); | ||||
|  | ||||
|         _NODISCARD bool SupportsGame(const std::string& gameName) const override; | ||||
|         _NODISCARD std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] GameId GetGameId() const override; | ||||
|         [[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] asset_type_t GetImageAssetType() const override; | ||||
|     }; | ||||
| } // namespace T5 | ||||
|   | ||||
| @@ -11,19 +11,6 @@ | ||||
|  | ||||
| using namespace T6; | ||||
|  | ||||
| ZoneCreator::ZoneCreator() | ||||
| { | ||||
|     for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) | ||||
|     { | ||||
|         AddAssetTypeName(assetType, GameAssetPoolT6::AssetTypeNameByType(assetType)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void ZoneCreator::AddAssetTypeName(asset_type_t assetType, std::string name) | ||||
| { | ||||
|     m_asset_types_by_name.emplace(std::make_pair(std::move(name), assetType)); | ||||
| } | ||||
|  | ||||
| std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
| { | ||||
|     std::vector<Gdt*> gdtList; | ||||
| @@ -34,21 +21,10 @@ std::vector<Gdt*> ZoneCreator::CreateGdtList(const ZoneCreationContext& context) | ||||
|     return gdtList; | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const | ||||
| void ZoneCreator::ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext) | ||||
| { | ||||
|     for (const auto& ignoreEntry : context.m_ignored_assets.m_entries) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(ignoreEntry.m_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << ignoreEntry.m_type << "\" for ignore \"" << ignoreEntry.m_name << "\"\n"; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         ignoredAssetMap[ignoreEntry.m_name] = foundAssetTypeEntry->second; | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|     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 | ||||
| @@ -63,11 +39,11 @@ void ZoneCreator::HandleMetadata(Zone* zone, const ZoneCreationContext& context) | ||||
| { | ||||
|     std::vector<KeyValuePair> kvpList; | ||||
|  | ||||
|     for (const auto& metaData : context.m_definition->m_metadata) | ||||
|     for (const auto& metaData : context.m_definition->m_properties.m_properties) | ||||
|     { | ||||
|         if (metaData->m_key.rfind("level.", 0) == 0) | ||||
|         if (metaData.first.rfind("level.", 0) == 0) | ||||
|         { | ||||
|             const std::string strValue = metaData->m_key.substr(std::char_traits<char>::length("level.")); | ||||
|             const std::string strValue = metaData.first.substr(std::char_traits<char>::length("level.")); | ||||
|             if (strValue.empty()) | ||||
|                 continue; | ||||
|  | ||||
| @@ -79,7 +55,7 @@ void ZoneCreator::HandleMetadata(Zone* zone, const ZoneCreationContext& context) | ||||
|  | ||||
|                 if (endPtr != &strValue[strValue.size()]) | ||||
|                 { | ||||
|                     std::cout << "Could not parse metadata key \"" << metaData->m_key << "\" as hash\n"; | ||||
|                     std::cout << "Could not parse metadata key \"" << metaData.first << "\" as hash\n"; | ||||
|                     continue; | ||||
|                 } | ||||
|             } | ||||
| @@ -88,7 +64,7 @@ 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->m_value.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); | ||||
|         } | ||||
|     } | ||||
| @@ -107,12 +83,9 @@ void ZoneCreator::HandleMetadata(Zone* zone, const ZoneCreationContext& context) | ||||
|     } | ||||
| } | ||||
|  | ||||
| bool ZoneCreator::SupportsGame(const std::string& gameName) const | ||||
| GameId ZoneCreator::GetGameId() const | ||||
| { | ||||
|     auto shortName = g_GameT6.GetShortName(); | ||||
|     utils::MakeStringLowerCase(shortName); | ||||
|  | ||||
|     return gameName == shortName; | ||||
|     return GameId::T6; | ||||
| } | ||||
|  | ||||
| std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const | ||||
| @@ -129,21 +102,13 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|     } | ||||
|  | ||||
|     const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(*zone, *context.m_asset_search_path, CreateGdtList(context)); | ||||
|     if (!CreateIgnoredAssetMap(context, assetLoadingContext->m_ignored_asset_map)) | ||||
|         return nullptr; | ||||
|     ApplyIgnoredAssets(context, *assetLoadingContext); | ||||
|  | ||||
|     HandleMetadata(zone.get(), context); | ||||
|  | ||||
|     for (const auto& assetEntry : context.m_definition->m_assets) | ||||
|     { | ||||
|         const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type); | ||||
|         if (foundAssetTypeEntry == m_asset_types_by_name.end()) | ||||
|         { | ||||
|             std::cout << "Unknown asset type \"" << assetEntry.m_asset_type << "\"\n"; | ||||
|             return nullptr; | ||||
|         } | ||||
|  | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, foundAssetTypeEntry->second, assetEntry.m_asset_name)) | ||||
|         if (!ObjLoading::LoadAssetForZone(*assetLoadingContext, assetEntry.m_asset_type, assetEntry.m_asset_name)) | ||||
|             return nullptr; | ||||
|     } | ||||
|  | ||||
| @@ -151,3 +116,8 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& | ||||
|  | ||||
|     return zone; | ||||
| } | ||||
|  | ||||
| asset_type_t ZoneCreator::GetImageAssetType() const | ||||
| { | ||||
|     return ASSET_TYPE_IMAGE; | ||||
| } | ||||
|   | ||||
| @@ -1,26 +1,20 @@ | ||||
| #pragma once | ||||
| #include "AssetLoading/AssetLoadingContext.h" | ||||
| #include "Zone/ZoneTypes.h" | ||||
| #include "ZoneCreation/IZoneCreator.h" | ||||
|  | ||||
| #include <string> | ||||
| #include <unordered_map> | ||||
| #include "ZoneCreation/ZoneCreator.h" | ||||
|  | ||||
| namespace T6 | ||||
| { | ||||
|     class ZoneCreator final : public IZoneCreator | ||||
|     { | ||||
|         std::unordered_map<std::string, asset_type_t> m_asset_types_by_name; | ||||
|  | ||||
|         void AddAssetTypeName(asset_type_t assetType, std::string name); | ||||
|         static std::vector<Gdt*> CreateGdtList(const ZoneCreationContext& context); | ||||
|         bool CreateIgnoredAssetMap(const ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const; | ||||
|         static void ApplyIgnoredAssets(const ZoneCreationContext& creationContext, AssetLoadingContext& loadingContext); | ||||
|         void CreateZoneAssetPools(Zone* zone) const; | ||||
|         void HandleMetadata(Zone* zone, const ZoneCreationContext& context) const; | ||||
|  | ||||
|     public: | ||||
|         ZoneCreator(); | ||||
|  | ||||
|         _NODISCARD bool SupportsGame(const std::string& gameName) const override; | ||||
|         _NODISCARD std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] GameId GetGameId() const override; | ||||
|         [[nodiscard]] std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const override; | ||||
|         [[nodiscard]] asset_type_t GetImageAssetType() const override; | ||||
|     }; | ||||
| } // namespace T6 | ||||
|   | ||||
| @@ -1,10 +1,5 @@ | ||||
| #include "Linker.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 "LinkerArgs.h" | ||||
| #include "LinkerSearchPaths.h" | ||||
| #include "ObjContainer/IPak/IPakWriter.h" | ||||
| @@ -13,15 +8,12 @@ | ||||
| #include "ObjLoading.h" | ||||
| #include "ObjWriting.h" | ||||
| #include "SearchPath/SearchPaths.h" | ||||
| #include "Utils/Arguments/ArgumentParser.h" | ||||
| #include "Utils/ClassUtils.h" | ||||
| #include "Utils/ObjFileStream.h" | ||||
| #include "Utils/StringUtils.h" | ||||
| #include "Zone/AssetList/AssetList.h" | ||||
| #include "Zone/AssetList/AssetListStream.h" | ||||
| #include "Zone/Definition/ZoneDefinitionStream.h" | ||||
| #include "ZoneCreation/IZoneCreator.h" | ||||
| #include "ZoneCreation/ZoneCreationContext.h" | ||||
| #include "ZoneCreation/ZoneCreator.h" | ||||
| #include "ZoneLoading.h" | ||||
| #include "ZoneWriting.h" | ||||
|  | ||||
| @@ -29,41 +21,12 @@ | ||||
| #include <filesystem> | ||||
| #include <format> | ||||
| #include <fstream> | ||||
| #include <regex> | ||||
| #include <set> | ||||
|  | ||||
| namespace fs = std::filesystem; | ||||
|  | ||||
| const IZoneCreator* const ZONE_CREATORS[]{ | ||||
|     new IW3::ZoneCreator(), | ||||
|     new IW4::ZoneCreator(), | ||||
|     new IW5::ZoneCreator(), | ||||
|     new T5::ZoneCreator(), | ||||
|     new T6::ZoneCreator(), | ||||
| }; | ||||
|  | ||||
| enum class ProjectType | ||||
| { | ||||
|     NONE, | ||||
|     FASTFILE, | ||||
|     IPAK, | ||||
|  | ||||
|     MAX | ||||
| }; | ||||
|  | ||||
| constexpr const char* PROJECT_TYPE_NAMES[static_cast<unsigned>(ProjectType::MAX)]{ | ||||
|     "none", | ||||
|     "fastfile", | ||||
|     "ipak", | ||||
| }; | ||||
|  | ||||
| class LinkerImpl final : public Linker | ||||
| { | ||||
|     static constexpr auto METADATA_GAME = "game"; | ||||
|     static constexpr auto METADATA_GDT = "gdt"; | ||||
|     static constexpr auto METADATA_NAME = "name"; | ||||
|     static constexpr auto METADATA_TYPE = "type"; | ||||
|  | ||||
|     LinkerArgs m_args; | ||||
|     LinkerSearchPaths m_search_paths; | ||||
|     std::vector<std::unique_ptr<Zone>> m_loaded_zones; | ||||
| @@ -117,7 +80,7 @@ class LinkerImpl final : public Linker | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     bool ReadAssetList(const std::string& zoneName, AssetList& assetList, ISearchPath* sourceSearchPath) const | ||||
|     bool ReadAssetList(const std::string& zoneName, const GameId game, AssetList& assetList, ISearchPath* sourceSearchPath) const | ||||
|     { | ||||
|         { | ||||
|             const auto assetListFileName = std::format("assetlist/{}.csv", zoneName); | ||||
| @@ -125,14 +88,16 @@ class LinkerImpl final : public Linker | ||||
|  | ||||
|             if (assetListStream.IsOpen()) | ||||
|             { | ||||
|                 const AssetListInputStream stream(*assetListStream.m_stream); | ||||
|                 const AssetListInputStream stream(*assetListStream.m_stream, game); | ||||
|                 AssetListEntry entry; | ||||
|  | ||||
|                 while (stream.NextEntry(entry)) | ||||
|                 bool failure; | ||||
|                 while (stream.NextEntry(entry, &failure)) | ||||
|                 { | ||||
|                     assetList.m_entries.emplace_back(std::move(entry)); | ||||
|                 } | ||||
|                 return true; | ||||
|  | ||||
|                 return !failure; | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -157,7 +122,7 @@ class LinkerImpl final : public Linker | ||||
|         for (const auto& assetListName : zoneDefinition.m_asset_lists) | ||||
|         { | ||||
|             AssetList assetList; | ||||
|             if (!ReadAssetList(assetListName, assetList, sourceSearchPath)) | ||||
|             if (!ReadAssetList(assetListName, zoneDefinition.m_game, assetList, sourceSearchPath)) | ||||
|             { | ||||
|                 std::cerr << std::format("Failed to read asset list \"{}\"\n", assetListName); | ||||
|                 return false; | ||||
| @@ -169,33 +134,6 @@ class LinkerImpl final : public Linker | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     static bool GetNameFromZoneDefinition(std::string& name, const std::string& targetName, const ZoneDefinition& zoneDefinition) | ||||
|     { | ||||
|         auto firstNameEntry = true; | ||||
|         const auto [rangeBegin, rangeEnd] = zoneDefinition.m_metadata_lookup.equal_range(METADATA_NAME); | ||||
|         for (auto i = rangeBegin; i != rangeEnd; ++i) | ||||
|         { | ||||
|             if (firstNameEntry) | ||||
|             { | ||||
|                 name = i->second->m_value; | ||||
|                 firstNameEntry = false; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (name != i->second->m_value) | ||||
|                 { | ||||
|                     std::cerr << std::format("Conflicting names in target \"{}\": {} != {}\n", targetName, name, i->second->m_value); | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (firstNameEntry) | ||||
|             name = targetName; | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     std::unique_ptr<ZoneDefinition> ReadZoneDefinition(const std::string& targetName, ISearchPath* sourceSearchPath) const | ||||
|     { | ||||
|         std::unique_ptr<ZoneDefinition> zoneDefinition; | ||||
| @@ -218,9 +156,6 @@ class LinkerImpl final : public Linker | ||||
|             return nullptr; | ||||
|         } | ||||
|  | ||||
|         if (!GetNameFromZoneDefinition(zoneDefinition->m_name, targetName, *zoneDefinition)) | ||||
|             return nullptr; | ||||
|  | ||||
|         if (!IncludeAdditionalZoneDefinitions(targetName, *zoneDefinition, sourceSearchPath)) | ||||
|             return nullptr; | ||||
|  | ||||
| @@ -235,19 +170,13 @@ class LinkerImpl final : public Linker | ||||
|         if (context.m_definition->m_ignores.empty()) | ||||
|             return true; | ||||
|  | ||||
|         std::map<std::string, std::reference_wrapper<ZoneDefinitionEntry>> zoneDefinitionAssetsByName; | ||||
|         for (auto& entry : context.m_definition->m_assets) | ||||
|         { | ||||
|             zoneDefinitionAssetsByName.try_emplace(entry.m_asset_name, entry); | ||||
|         } | ||||
|  | ||||
|         for (const auto& ignore : context.m_definition->m_ignores) | ||||
|         { | ||||
|             if (ignore == targetName) | ||||
|                 continue; | ||||
|  | ||||
|             std::vector<AssetListEntry> assetList; | ||||
|             if (!ReadAssetList(ignore, context.m_ignored_assets, sourceSearchPath)) | ||||
|             if (!ReadAssetList(ignore, context.m_definition->m_game, context.m_ignored_assets, sourceSearchPath)) | ||||
|             { | ||||
|                 std::cerr << std::format("Failed to read asset listing for ignoring assets of project \"{}\".\n", ignore); | ||||
|                 return false; | ||||
| @@ -256,101 +185,14 @@ class LinkerImpl final : public Linker | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     static bool ProjectTypeByName(ProjectType& projectType, const std::string& projectTypeName) | ||||
|     { | ||||
|         for (auto i = 0u; i < static_cast<unsigned>(ProjectType::MAX); i++) | ||||
|         { | ||||
|             if (projectTypeName == PROJECT_TYPE_NAMES[i]) | ||||
|             { | ||||
|                 projectType = static_cast<ProjectType>(i); | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     static bool GetProjectTypeFromZoneDefinition(ProjectType& projectType, const std::string& targetName, const ZoneDefinition& zoneDefinition) | ||||
|     { | ||||
|         auto firstTypeEntry = true; | ||||
|         const auto [rangeBegin, rangeEnd] = zoneDefinition.m_metadata_lookup.equal_range(METADATA_TYPE); | ||||
|         for (auto i = rangeBegin; i != rangeEnd; ++i) | ||||
|         { | ||||
|             ProjectType parsedProjectType; | ||||
|             if (!ProjectTypeByName(parsedProjectType, i->second->m_value)) | ||||
|             { | ||||
|                 std::cerr << std::format("Not a valid project type: \"{}\"\n", i->second->m_value); | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             if (firstTypeEntry) | ||||
|             { | ||||
|                 projectType = parsedProjectType; | ||||
|                 firstTypeEntry = false; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (projectType != parsedProjectType) | ||||
|                 { | ||||
|                     std::cerr << std::format("Conflicting types in target \"{}\": {} != {}\n", | ||||
|                                              targetName, | ||||
|                                              PROJECT_TYPE_NAMES[static_cast<unsigned>(projectType)], | ||||
|                                              PROJECT_TYPE_NAMES[static_cast<unsigned>(parsedProjectType)]); | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (firstTypeEntry) | ||||
|         { | ||||
|             if (zoneDefinition.m_assets.empty()) | ||||
|                 projectType = ProjectType::NONE; | ||||
|             else | ||||
|                 projectType = ProjectType::FASTFILE; | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     static bool GetGameNameFromZoneDefinition(std::string& gameName, const std::string& targetName, const ZoneDefinition& zoneDefinition) | ||||
|     { | ||||
|         auto firstGameEntry = true; | ||||
|         const auto [rangeBegin, rangeEnd] = zoneDefinition.m_metadata_lookup.equal_range(METADATA_GAME); | ||||
|         for (auto i = rangeBegin; i != rangeEnd; ++i) | ||||
|         { | ||||
|             if (firstGameEntry) | ||||
|             { | ||||
|                 gameName = i->second->m_value; | ||||
|                 firstGameEntry = false; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (gameName != i->second->m_value) | ||||
|                 { | ||||
|                     std::cerr << std::format("Conflicting game names in target \"{}\": {} != {}\n", targetName, gameName, i->second->m_value); | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (firstGameEntry) | ||||
|         { | ||||
|             std::cerr << std::format("No game name was specified for target \"{}\"\n", targetName); | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     static bool LoadGdtFilesFromZoneDefinition(std::vector<std::unique_ptr<Gdt>>& gdtList, const ZoneDefinition& zoneDefinition, ISearchPath* gdtSearchPath) | ||||
|     { | ||||
|         const auto [rangeBegin, rangeEnd] = zoneDefinition.m_metadata_lookup.equal_range(METADATA_GDT); | ||||
|         for (auto i = rangeBegin; i != rangeEnd; ++i) | ||||
|         for (const auto& gdtName : zoneDefinition.m_gdts) | ||||
|         { | ||||
|             const auto gdtFile = gdtSearchPath->Open(i->second->m_value + ".gdt"); | ||||
|             const auto gdtFile = gdtSearchPath->Open(std::format("{}.gdt", gdtName)); | ||||
|             if (!gdtFile.IsOpen()) | ||||
|             { | ||||
|                 std::cerr << std::format("Failed to open file for gdt \"{}\"\n", i->second->m_value); | ||||
|                 std::cerr << std::format("Failed to open file for gdt \"{}\"\n", gdtName); | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
| @@ -358,7 +200,7 @@ class LinkerImpl final : public Linker | ||||
|             auto gdt = std::make_unique<Gdt>(); | ||||
|             if (!gdtReader.Read(*gdt)) | ||||
|             { | ||||
|                 std::cerr << std::format("Failed to read gdt file \"{}\"\n", i->second->m_value); | ||||
|                 std::cerr << std::format("Failed to read gdt file \"{}\"\n", gdtName); | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
| @@ -374,23 +216,14 @@ class LinkerImpl final : public Linker | ||||
|                                                   ISearchPath* gdtSearchPath, | ||||
|                                                   ISearchPath* sourceSearchPath) const | ||||
|     { | ||||
|         const auto context = std::make_unique<ZoneCreationContext>(assetSearchPath, &zoneDefinition); | ||||
|         const auto context = std::make_unique<ZoneCreationContext>(&zoneDefinition, assetSearchPath); | ||||
|         if (!ProcessZoneDefinitionIgnores(targetName, *context, sourceSearchPath)) | ||||
|             return nullptr; | ||||
|         if (!GetGameNameFromZoneDefinition(context->m_game_name, targetName, zoneDefinition)) | ||||
|             return nullptr; | ||||
|         utils::MakeStringLowerCase(context->m_game_name); | ||||
|         if (!LoadGdtFilesFromZoneDefinition(context->m_gdt_files, zoneDefinition, gdtSearchPath)) | ||||
|             return nullptr; | ||||
|  | ||||
|         for (const auto* zoneCreator : ZONE_CREATORS) | ||||
|         { | ||||
|             if (zoneCreator->SupportsGame(context->m_game_name)) | ||||
|                 return zoneCreator->CreateZoneForDefinition(*context); | ||||
|         } | ||||
|  | ||||
|         std::cerr << std::format("Unsupported game: {}\n", context->m_game_name); | ||||
|         return nullptr; | ||||
|         const auto* creator = IZoneCreator::GetCreatorForGame(zoneDefinition.m_game); | ||||
|         return creator->CreateZoneForDefinition(*context); | ||||
|     } | ||||
|  | ||||
|     bool WriteZoneToFile(const std::string& projectName, Zone* zone) const | ||||
| @@ -444,7 +277,7 @@ class LinkerImpl final : public Linker | ||||
|     { | ||||
|         const fs::path ipakFolderPath(m_args.GetOutputFolderPathForProject(projectName)); | ||||
|         auto ipakFilePath(ipakFolderPath); | ||||
|         ipakFilePath.append(zoneDefinition.m_name + ".ipak"); | ||||
|         ipakFilePath.append(std::format("{}.ipak", zoneDefinition.m_name)); | ||||
|  | ||||
|         fs::create_directories(ipakFolderPath); | ||||
|  | ||||
| @@ -453,12 +286,13 @@ class LinkerImpl final : public Linker | ||||
|             return false; | ||||
|  | ||||
|         const auto ipakWriter = IPakWriter::Create(stream, &assetSearchPaths); | ||||
|         const auto imageAssetType = IZoneCreator::GetCreatorForGame(zoneDefinition.m_game)->GetImageAssetType(); | ||||
|         for (const auto& assetEntry : zoneDefinition.m_assets) | ||||
|         { | ||||
|             if (assetEntry.m_is_reference) | ||||
|                 continue; | ||||
|  | ||||
|             if (assetEntry.m_asset_type == "image") | ||||
|             if (assetEntry.m_asset_type == imageAssetType) | ||||
|                 ipakWriter->AddImage(assetEntry.m_asset_name); | ||||
|         } | ||||
|  | ||||
| @@ -499,22 +333,14 @@ class LinkerImpl final : public Linker | ||||
|         if (!zoneDefinition) | ||||
|             return false; | ||||
|  | ||||
|         ProjectType projectType; | ||||
|         if (!GetProjectTypeFromZoneDefinition(projectType, targetName, *zoneDefinition)) | ||||
|             return false; | ||||
|  | ||||
|         auto result = true; | ||||
|         if (projectType != ProjectType::NONE) | ||||
|         if (zoneDefinition->m_type != ProjectType::NONE) | ||||
|         { | ||||
|             std::string gameName; | ||||
|             if (!GetGameNameFromZoneDefinition(gameName, targetName, *zoneDefinition)) | ||||
|                 return false; | ||||
|             utils::MakeStringLowerCase(gameName); | ||||
|  | ||||
|             const auto& gameName = GameId_Names[static_cast<unsigned>(zoneDefinition->m_game)]; | ||||
|             auto assetSearchPaths = m_search_paths.GetAssetSearchPathsForProject(gameName, projectName); | ||||
|             auto gdtSearchPaths = m_search_paths.GetGdtSearchPathsForProject(gameName, projectName); | ||||
|  | ||||
|             switch (projectType) | ||||
|             switch (zoneDefinition->m_type) | ||||
|             { | ||||
|             case ProjectType::FASTFILE: | ||||
|                 result = BuildFastFile(projectName, targetName, *zoneDefinition, assetSearchPaths, gdtSearchPaths, sourceSearchPaths); | ||||
|   | ||||
| @@ -1,13 +1,13 @@ | ||||
| #include "ZoneCreationContext.h" | ||||
|  | ||||
| ZoneCreationContext::ZoneCreationContext() | ||||
|     : m_asset_search_path(nullptr), | ||||
|       m_definition(nullptr) | ||||
|     : m_definition(nullptr), | ||||
|       m_asset_search_path(nullptr) | ||||
| { | ||||
| } | ||||
|  | ||||
| ZoneCreationContext::ZoneCreationContext(ISearchPath* assetSearchPath, ZoneDefinition* definition) | ||||
|     : m_asset_search_path(assetSearchPath), | ||||
|       m_definition(definition) | ||||
| ZoneCreationContext::ZoneCreationContext(ZoneDefinition* definition, ISearchPath* assetSearchPath) | ||||
|     : m_definition(definition), | ||||
|       m_asset_search_path(assetSearchPath) | ||||
| { | ||||
| } | ||||
|   | ||||
| @@ -5,18 +5,16 @@ | ||||
| #include "Zone/Definition/ZoneDefinition.h" | ||||
|  | ||||
| #include <memory> | ||||
| #include <string> | ||||
| #include <vector> | ||||
|  | ||||
| class ZoneCreationContext | ||||
| { | ||||
| public: | ||||
|     std::string m_game_name; | ||||
|     ISearchPath* m_asset_search_path; | ||||
|     ZoneDefinition* m_definition; | ||||
|     ISearchPath* m_asset_search_path; | ||||
|     std::vector<std::unique_ptr<Gdt>> m_gdt_files; | ||||
|     AssetList m_ignored_assets; | ||||
|  | ||||
|     ZoneCreationContext(); | ||||
|     ZoneCreationContext(ISearchPath* assetSearchPath, ZoneDefinition* definition); | ||||
|     ZoneCreationContext(ZoneDefinition* definition, ISearchPath* assetSearchPath); | ||||
| }; | ||||
|   | ||||
							
								
								
									
										26
									
								
								src/Linker/ZoneCreation/ZoneCreator.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/Linker/ZoneCreation/ZoneCreator.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| #include "ZoneCreator.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 <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(), | ||||
|     }; | ||||
|  | ||||
|     assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT)); | ||||
|     const auto* result = zoneCreators[static_cast<unsigned>(game)]; | ||||
|     assert(result); | ||||
|  | ||||
|     return result; | ||||
| } | ||||
| @@ -1,10 +1,8 @@ | ||||
| #pragma once | ||||
| #include "Utils/ClassUtils.h" | ||||
| 
 | ||||
| #include "Zone/Zone.h" | ||||
| #include "ZoneCreationContext.h" | ||||
| 
 | ||||
| #include <string> | ||||
| 
 | ||||
| class IZoneCreator | ||||
| { | ||||
| public: | ||||
| @@ -15,6 +13,9 @@ public: | ||||
|     IZoneCreator& operator=(const IZoneCreator& other) = default; | ||||
|     IZoneCreator& operator=(IZoneCreator&& other) noexcept = default; | ||||
| 
 | ||||
|     _NODISCARD virtual bool SupportsGame(const std::string& gameName) const = 0; | ||||
|     _NODISCARD virtual std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const = 0; | ||||
|     [[nodiscard]] virtual GameId GetGameId() const = 0; | ||||
|     [[nodiscard]] virtual std::unique_ptr<Zone> CreateZoneForDefinition(ZoneCreationContext& context) const = 0; | ||||
|     [[nodiscard]] virtual asset_type_t GetImageAssetType() const = 0; | ||||
| 
 | ||||
|     static const IZoneCreator* GetCreatorForGame(GameId game); | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user