diff --git a/src/Linker/AssetLoading/IAssetLoader.h b/src/Linker/AssetLoading/IAssetLoader.h deleted file mode 100644 index de984911..00000000 --- a/src/Linker/AssetLoading/IAssetLoader.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include - -#include "Utils/ClassUtils.h" -#include "AssetLoadingContext.h" -#include "Zone/Zone.h" - -class IAssetLoader -{ -public: - IAssetLoader() = default; - virtual ~IAssetLoader() = default; - IAssetLoader(const IAssetLoader& other) = default; - IAssetLoader(IAssetLoader&& other) noexcept = default; - IAssetLoader& operator=(const IAssetLoader& other) = default; - IAssetLoader& operator=(IAssetLoader&& other) noexcept = default; - - _NODISCARD virtual bool SupportsGame(const std::string& gameName) const = 0; - _NODISCARD virtual std::unique_ptr CreateZoneForDefinition(AssetLoadingContext& context) const = 0; -}; diff --git a/src/Linker/Game/IW4/AssetLoaderIW4.cpp b/src/Linker/Game/IW4/ZoneCreatorIW4.cpp similarity index 70% rename from src/Linker/Game/IW4/AssetLoaderIW4.cpp rename to src/Linker/Game/IW4/ZoneCreatorIW4.cpp index caa62088..c5a74e95 100644 --- a/src/Linker/Game/IW4/AssetLoaderIW4.cpp +++ b/src/Linker/Game/IW4/ZoneCreatorIW4.cpp @@ -1,16 +1,16 @@ -#include "AssetLoaderIW4.h" +#include "ZoneCreatorIW4.h" #include "Game/IW4/GameIW4.h" #include "Game/IW4/GameAssetPoolIW4.h" using namespace IW4; -bool AssetLoader::SupportsGame(const std::string& gameName) const +bool ZoneCreator::SupportsGame(const std::string& gameName) const { return gameName == g_GameIW4.GetShortName(); } -std::unique_ptr AssetLoader::CreateZoneForDefinition(AssetLoadingContext& context) const +std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const { auto zone = std::make_unique(context.m_zone_name, 0, &g_GameIW4); zone->m_pools = std::make_unique(zone.get(), zone->m_priority); diff --git a/src/Linker/Game/IW4/AssetLoaderIW4.h b/src/Linker/Game/IW4/ZoneCreatorIW4.h similarity index 59% rename from src/Linker/Game/IW4/AssetLoaderIW4.h rename to src/Linker/Game/IW4/ZoneCreatorIW4.h index 580a453e..7bab80a1 100644 --- a/src/Linker/Game/IW4/AssetLoaderIW4.h +++ b/src/Linker/Game/IW4/ZoneCreatorIW4.h @@ -1,12 +1,12 @@ #pragma once -#include "AssetLoading/IAssetLoader.h" +#include "ZoneCreation/IZoneCreator.h" namespace IW4 { - class AssetLoader final : public IAssetLoader + class ZoneCreator final : public IZoneCreator { public: _NODISCARD bool SupportsGame(const std::string& gameName) const override; - _NODISCARD std::unique_ptr CreateZoneForDefinition(AssetLoadingContext& context) const override; + _NODISCARD std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const override; }; } diff --git a/src/Linker/Game/T6/AssetLoaderT6.cpp b/src/Linker/Game/T6/AssetLoaderT6.cpp deleted file mode 100644 index 1f6769ac..00000000 --- a/src/Linker/Game/T6/AssetLoaderT6.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "AssetLoaderT6.h" - -#include "Game/T6/T6.h" -#include "Game/T6/GameT6.h" -#include "Game/T6/GameAssetPoolT6.h" - -using namespace T6; - -bool AssetLoader::SupportsGame(const std::string& gameName) const -{ - return gameName == g_GameT6.GetShortName(); -} - -std::unique_ptr AssetLoader::CreateZoneForDefinition(AssetLoadingContext& context) const -{ - auto zone = std::make_unique(context.m_zone_name, 0, &g_GameT6); - zone->m_pools = std::make_unique(zone.get(), zone->m_priority); - - for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) - zone->m_pools->InitPoolDynamic(assetType); - - return zone; -} diff --git a/src/Linker/Game/T6/ZoneCreatorT6.cpp b/src/Linker/Game/T6/ZoneCreatorT6.cpp new file mode 100644 index 00000000..b38f1949 --- /dev/null +++ b/src/Linker/Game/T6/ZoneCreatorT6.cpp @@ -0,0 +1,58 @@ +#include "ZoneCreatorT6.h" + +#include "Game/T6/T6.h" +#include "Game/T6/GameT6.h" +#include "Game/T6/GameAssetPoolT6.h" + +using namespace T6; + +namespace T6 +{ + class SpecifiedAsset + { + public: + XAssetType m_type; + std::string m_name; + bool m_reference; + }; + + class AssetLoaderImpl + { + ZoneCreationContext& m_context; + + void 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); + } + + public: + explicit AssetLoaderImpl(ZoneCreationContext& context) + : m_context(context) + { + } + + std::unique_ptr CreateZoneForDefinition() + { + auto zone = std::make_unique(m_context.m_zone_name, 0, &g_GameT6); + CreateZoneAssetPools(zone.get()); + + std::vector specifiedAssets; + + return zone; + } + }; +} + +bool ZoneCreator::SupportsGame(const std::string& gameName) const +{ + return gameName == g_GameT6.GetShortName(); +} + +std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const +{ + AssetLoaderImpl impl(context); + return impl.CreateZoneForDefinition(); +} diff --git a/src/Linker/Game/T6/AssetLoaderT6.h b/src/Linker/Game/T6/ZoneCreatorT6.h similarity index 59% rename from src/Linker/Game/T6/AssetLoaderT6.h rename to src/Linker/Game/T6/ZoneCreatorT6.h index 2d45343a..ea890f82 100644 --- a/src/Linker/Game/T6/AssetLoaderT6.h +++ b/src/Linker/Game/T6/ZoneCreatorT6.h @@ -1,12 +1,12 @@ #pragma once -#include "AssetLoading/IAssetLoader.h" +#include "ZoneCreation/IZoneCreator.h" namespace T6 { - class AssetLoader final : public IAssetLoader + class ZoneCreator final : public IZoneCreator { public: _NODISCARD bool SupportsGame(const std::string& gameName) const override; - _NODISCARD std::unique_ptr CreateZoneForDefinition(AssetLoadingContext& context) const override; + _NODISCARD std::unique_ptr CreateZoneForDefinition(ZoneCreationContext& context) const override; }; } diff --git a/src/Linker/Linker.cpp b/src/Linker/Linker.cpp index 03513fb6..c2810445 100644 --- a/src/Linker/Linker.cpp +++ b/src/Linker/Linker.cpp @@ -15,10 +15,10 @@ #include "SearchPath/SearchPathFilesystem.h" #include "ObjContainer/IWD/IWD.h" #include "LinkerArgs.h" -#include "AssetLoading/AssetLoadingContext.h" -#include "AssetLoading/IAssetLoader.h" -#include "Game/IW4/AssetLoaderIW4.h" -#include "Game/T6/AssetLoaderT6.h" +#include "ZoneCreation/ZoneCreationContext.h" +#include "ZoneCreation/IZoneCreator.h" +#include "Game/IW4/ZoneCreatorIW4.h" +#include "Game/T6/ZoneCreatorT6.h" #include "Utils/ObjFileStream.h" #include "Zone/AssetList/AssetList.h" @@ -27,10 +27,10 @@ namespace fs = std::filesystem; -const IAssetLoader* const ASSET_LOADERS[] +const IZoneCreator* const ZONE_CREATORS[] { - new IW4::AssetLoader(), - new T6::AssetLoader() + new IW4::ZoneCreator(), + new T6::ZoneCreator() }; class Linker::Impl @@ -427,13 +427,13 @@ class Linker::Impl std::unique_ptr CreateZoneForDefinition(const std::string& zoneName, ZoneDefinition& zoneDefinition, ISearchPath* assetSearchPath, ISearchPath* gdtSearchPath) const { - auto context = std::make_unique(zoneName, assetSearchPath); + auto context = std::make_unique(zoneName, assetSearchPath); if (!GetGameNameFromZoneDefinition(context->m_game_name, zoneName, zoneDefinition)) return nullptr; if (!LoadGdtFilesFromZoneDefinition(context->m_gdt_files, zoneName, zoneDefinition, gdtSearchPath)) return nullptr; - for(const auto* assetLoader : ASSET_LOADERS) + for(const auto* assetLoader : ZONE_CREATORS) { if(assetLoader->SupportsGame(context->m_game_name)) return assetLoader->CreateZoneForDefinition(*context); diff --git a/src/Linker/ZoneCreation/IZoneCreator.h b/src/Linker/ZoneCreation/IZoneCreator.h new file mode 100644 index 00000000..52e2d200 --- /dev/null +++ b/src/Linker/ZoneCreation/IZoneCreator.h @@ -0,0 +1,20 @@ +#pragma once +#include + +#include "Utils/ClassUtils.h" +#include "ZoneCreationContext.h" +#include "Zone/Zone.h" + +class IZoneCreator +{ +public: + IZoneCreator() = default; + virtual ~IZoneCreator() = default; + IZoneCreator(const IZoneCreator& other) = default; + IZoneCreator(IZoneCreator&& other) noexcept = default; + 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 CreateZoneForDefinition(ZoneCreationContext& context) const = 0; +}; diff --git a/src/Linker/AssetLoading/AssetLoadingContext.cpp b/src/Linker/ZoneCreation/ZoneCreationContext.cpp similarity index 52% rename from src/Linker/AssetLoading/AssetLoadingContext.cpp rename to src/Linker/ZoneCreation/ZoneCreationContext.cpp index 048a2f2b..9a6e6675 100644 --- a/src/Linker/AssetLoading/AssetLoadingContext.cpp +++ b/src/Linker/ZoneCreation/ZoneCreationContext.cpp @@ -1,11 +1,11 @@ -#include "AssetLoadingContext.h" +#include "ZoneCreationContext.h" -AssetLoadingContext::AssetLoadingContext() +ZoneCreationContext::ZoneCreationContext() : m_asset_search_path(nullptr) { } -AssetLoadingContext::AssetLoadingContext(std::string zoneName, ISearchPath* assetSearchPath) +ZoneCreationContext::ZoneCreationContext(std::string zoneName, ISearchPath* assetSearchPath) : m_asset_search_path(assetSearchPath), m_zone_name(std::move(zoneName)) { diff --git a/src/Linker/AssetLoading/AssetLoadingContext.h b/src/Linker/ZoneCreation/ZoneCreationContext.h similarity index 72% rename from src/Linker/AssetLoading/AssetLoadingContext.h rename to src/Linker/ZoneCreation/ZoneCreationContext.h index 4517d0c7..2173c6be 100644 --- a/src/Linker/AssetLoading/AssetLoadingContext.h +++ b/src/Linker/ZoneCreation/ZoneCreationContext.h @@ -6,7 +6,7 @@ #include "SearchPath/ISearchPath.h" #include "Obj/Gdt/Gdt.h" -class AssetLoadingContext +class ZoneCreationContext { public: ISearchPath* m_asset_search_path; @@ -14,6 +14,6 @@ public: std::string m_game_name; std::vector> m_gdt_files; - AssetLoadingContext(); - AssetLoadingContext(std::string zoneName, ISearchPath* assetSearchPath); + ZoneCreationContext(); + ZoneCreationContext(std::string zoneName, ISearchPath* assetSearchPath); };