diff --git a/src/ObjCommon/Techset/TechsetCommon.cpp b/src/ObjCommon/Techset/TechsetCommon.cpp index f8e75ea5..f21097bd 100644 --- a/src/ObjCommon/Techset/TechsetCommon.cpp +++ b/src/ObjCommon/Techset/TechsetCommon.cpp @@ -4,6 +4,11 @@ namespace techset { + std::string GetFileNameForStateMapName(const std::string& stateMapName) + { + return std::format("statemaps/{}.sm", stateMapName); + } + std::string GetFileNameForTechniqueName(const std::string& assetName) { return std::format("techniques/{}.tech", assetName); diff --git a/src/ObjCommon/Techset/TechsetCommon.h b/src/ObjCommon/Techset/TechsetCommon.h index 510b9122..ad65b5df 100644 --- a/src/ObjCommon/Techset/TechsetCommon.h +++ b/src/ObjCommon/Techset/TechsetCommon.h @@ -4,6 +4,7 @@ namespace techset { + std::string GetFileNameForStateMapName(const std::string& stateMapName); std::string GetFileNameForTechniqueName(const std::string& assetName); std::string GetFileNameForTechsetName(const std::string& assetName); } // namespace techset diff --git a/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp b/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp index 02e34655..29ea2ee1 100644 --- a/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp +++ b/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp @@ -25,8 +25,8 @@ namespace { auto& memory = zone.Memory(); - if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) - collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); + if (image::IwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) + collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); } } // namespace diff --git a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp index 7b54ceaa..0fc61324 100644 --- a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp @@ -14,6 +14,7 @@ #include "StateMap/StateMapHandler.h" #include "Techset/TechniqueFileReader.h" #include "Techset/TechniqueStateMapCache.h" +#include "Techset/TechsetCommon.h" #include "Techset/TechsetDefinitionCache.h" #include @@ -45,9 +46,9 @@ namespace m_search_path(searchPath), m_context(context), m_registration(registration), - m_state_map_cache(context.GetZoneAssetCreationState()), + m_state_map_cache(context.GetZoneAssetCreationState<::techset::TechniqueStateMapCache>()), m_base_state_bits{}, - m_techset_creator(CreateTechsetLoader(memory, searchPath)) + m_techset_creator(IW4::techset::CreateLoader(memory, searchPath)) { } @@ -793,7 +794,7 @@ namespace m_registration.AddDependency(techset); m_material.techniqueSet = techset->Asset(); - auto& definitionCache = m_context.GetZoneAssetCreationState(); + auto& definitionCache = m_context.GetZoneAssetCreationState<::techset::TechsetDefinitionCache>(); bool failure = false; const auto* techsetDefinition = m_techset_creator->LoadTechsetDefinition(techsetName, m_context, failure); @@ -806,7 +807,7 @@ namespace SetTechniqueSetCameraRegion(techsetDefinition); } - void SetTechniqueSetStateBits(const techset::TechsetDefinition* techsetDefinition) + void SetTechniqueSetStateBits(const ::techset::TechsetDefinition* techsetDefinition) { for (auto i = 0; i < TECHNIQUE_COUNT; i++) { @@ -854,19 +855,19 @@ namespace return stateBits; } - _NODISCARD const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const + [[nodiscard]] const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const { const auto* preloadedStateMap = m_state_map_cache.GetStateMapForTechnique(techniqueName); if (preloadedStateMap) return preloadedStateMap; - const auto techniqueFileName = GetTechniqueFileName(techniqueName); + const auto techniqueFileName = ::techset::GetFileNameForTechniqueName(techniqueName); const auto file = m_search_path.Open(techniqueFileName); if (!file.IsOpen()) return nullptr; state_map::StateMapFromTechniqueExtractor extractor; - const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor); + const ::techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor); if (!reader.ReadTechniqueDefinition()) { m_state_map_cache.SetTechniqueUsesStateMap(techniqueName, nullptr); @@ -890,7 +891,7 @@ namespace return outBits; } - void SetTechniqueSetCameraRegion(const techset::TechsetDefinition* techsetDefinition) const + void SetTechniqueSetCameraRegion(const ::techset::TechsetDefinition* techsetDefinition) const { std::string tempName; if (techsetDefinition->GetTechniqueByIndex(TECHNIQUE_LIT, tempName)) @@ -1316,7 +1317,7 @@ namespace AssetCreationContext& m_context; AssetRegistration& m_registration; - techset::TechniqueStateMapCache& m_state_map_cache; + ::techset::TechniqueStateMapCache& m_state_map_cache; std::unordered_map m_state_bits_per_state_map; GfxStateBits m_base_state_bits; @@ -1324,7 +1325,7 @@ namespace std::vector m_textures; std::vector m_constants; - std::unique_ptr m_techset_creator; + std::unique_ptr<::IW4::techset::ICreator> m_techset_creator; }; class MaterialLoader final : public AssetCreator @@ -1374,10 +1375,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::material { - std::unique_ptr> CreateMaterialCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt) + std::unique_ptr> CreateCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt) { return std::make_unique(memory, searchPath, gdt); } -} // namespace IW4 +} // namespace IW4::material diff --git a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.h b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.h index 52c7d3dd..3258e1b5 100644 --- a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.h +++ b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.h @@ -6,7 +6,7 @@ #include "SearchPath/ISearchPath.h" #include "Utils/MemoryManager.h" -namespace IW4 +namespace IW4::material { - std::unique_ptr> CreateMaterialCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt); -} // namespace IW4 + std::unique_ptr> CreateCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt); +} // namespace IW4::material diff --git a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp index f33dd566..8ad32e9d 100644 --- a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp +++ b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp @@ -17,10 +17,10 @@ namespace auto& memory = zone.Memory(); #ifdef EXPERIMENTAL_MATERIAL_COMPILATION - collection.AddAssetCreator(CreateMaterialCompiler(memory, searchPath, gdt)); - collection.AddAssetCreator(CreateTechsetLoader(memory, searchPath)); + collection.AddAssetCreator(material::CreateCompiler(memory, searchPath, gdt)); + collection.AddAssetCreator(IW4::techset::CreateLoader(memory, searchPath)); #endif - collection.AddAssetCreator(CreateVertexDeclLoader(memory)); + collection.AddAssetCreator(vertex_decl::CreateLoader(memory)); } void ConfigurePostProcessors(AssetCreatorCollection& collection, @@ -32,8 +32,8 @@ namespace { auto& memory = zone.Memory(); - if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) - collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); + if (image::IwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) + collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); } } // namespace diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp index 321d3297..dd336d7e 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp @@ -9,6 +9,7 @@ #include "StateMap/StateMapReader.h" #include "Techset/TechniqueFileReader.h" #include "Techset/TechniqueStateMapCache.h" +#include "Techset/TechsetCommon.h" #include "Techset/TechsetDefinitionCache.h" #include "Techset/TechsetFileReader.h" #include "Utils/Alignment.h" @@ -25,6 +26,7 @@ #include using namespace IW4; +using namespace ::techset; using namespace std::string_literals; namespace @@ -62,7 +64,7 @@ namespace .first->second.get(); } - literal_t GetAllocatedLiteral(MemoryManager& memory, techset::ShaderArgumentLiteralSource source) + literal_t GetAllocatedLiteral(MemoryManager& memory, ShaderArgumentLiteralSource source) { const auto& existingEntry = m_allocated_literals.find(source); @@ -81,7 +83,7 @@ namespace private: std::unordered_map> m_loaded_techniques; - std::map m_allocated_literals; + std::map m_allocated_literals; }; class ShaderInfoFromFileSystemCacheState final : public IZoneAssetCreationState @@ -121,7 +123,7 @@ namespace std::unordered_map> m_cached_shader_info; }; - class TechniqueCreator final : public techset::ITechniqueDefinitionAcceptor + class TechniqueCreator final : public ITechniqueDefinitionAcceptor { public: class PassShaderArgument @@ -197,14 +199,17 @@ namespace std::vector m_arguments; }; - TechniqueCreator( - const std::string& techniqueName, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, ITechsetCreator* techsetCreator) + TechniqueCreator(const std::string& techniqueName, + ISearchPath& searchPath, + MemoryManager& memory, + AssetCreationContext& context, + IW4::techset::ICreator* techsetCreator) : m_technique_name(techniqueName), m_search_path(searchPath), m_memory(memory), m_context(context), m_zone_state(context.GetZoneAssetCreationState()), - m_state_map_cache(context.GetZoneAssetCreationState()), + m_state_map_cache(context.GetZoneAssetCreationState()), m_shader_info_cache(context.GetZoneAssetCreationState()), m_techset_creator(techsetCreator) { @@ -230,7 +235,7 @@ namespace || constant.m_type == d3d9::ParameterType::SAMPLER_CUBE; } - bool AutoCreateShaderArgument(const techset::ShaderSelector shaderType, + bool AutoCreateShaderArgument(const ShaderSelector shaderType, const d3d9::ShaderConstant& shaderArgument, const size_t elementOffset, const size_t registerOffset) @@ -239,7 +244,7 @@ namespace auto& pass = m_passes.at(m_passes.size() - 1); const auto isSamplerArgument = IsSamplerArgument(shaderArgument); - if (shaderType == techset::ShaderSelector::VERTEX_SHADER && isSamplerArgument) + if (shaderType == ShaderSelector::VERTEX_SHADER && isSamplerArgument) return false; MaterialShaderArgument argument; @@ -270,7 +275,7 @@ namespace if (!constantSource) return false; - argument.type = shaderType == techset::ShaderSelector::VERTEX_SHADER ? MTL_ARG_CODE_VERTEX_CONST : MTL_ARG_CODE_PIXEL_CONST; + argument.type = shaderType == ShaderSelector::VERTEX_SHADER ? MTL_ARG_CODE_VERTEX_CONST : MTL_ARG_CODE_PIXEL_CONST; argument.u.codeConst.index = static_cast(constantSource->source + elementOffset); argument.u.codeConst.firstRow = 0u; argument.u.codeConst.rowCount = static_cast(shaderArgument.m_type_rows); @@ -301,7 +306,7 @@ namespace { if (!pass.m_handled_vertex_shader_arguments[argumentHandledIndex + elementIndex]) { - if (!AutoCreateShaderArgument(techset::ShaderSelector::VERTEX_SHADER, argument, elementIndex, registerIndex)) + if (!AutoCreateShaderArgument(ShaderSelector::VERTEX_SHADER, argument, elementIndex, registerIndex)) { std::string elementIndexStr; if (argument.m_type_elements > 1) @@ -336,7 +341,7 @@ namespace { if (!pass.m_handled_pixel_shader_arguments[argumentHandledIndex + elementIndex]) { - if (!AutoCreateShaderArgument(techset::ShaderSelector::PIXEL_SHADER, argument, elementIndex, registerIndex)) + if (!AutoCreateShaderArgument(ShaderSelector::PIXEL_SHADER, argument, elementIndex, registerIndex)) { std::ostringstream ss; ss << "Unassigned pixel shader \"" << pass.m_pixel_shader->m_name << "\" arg: " << argument.m_name; @@ -572,11 +577,8 @@ namespace return foundSource; } - static bool FindShaderArgument(const d3d9::ShaderInfo& shaderInfo, - const techset::ShaderArgument& argument, - size_t& constantIndex, - size_t& registerOffset, - std::string& errorMessage) + static bool FindShaderArgument( + const d3d9::ShaderInfo& shaderInfo, const ShaderArgument& argument, size_t& constantIndex, size_t& registerOffset, std::string& errorMessage) { const auto matchingShaderConstant = std::ranges::find_if(shaderInfo.m_constants, [argument](const d3d9::ShaderConstant& constant) @@ -622,7 +624,7 @@ namespace } static bool SetArgumentCodeConst(MaterialShaderArgument& argument, - const techset::ShaderArgumentCodeSource& source, + const ShaderArgumentCodeSource& source, const d3d9::ShaderConstant& shaderConstant, const unsigned sourceIndex, const unsigned arrayCount, @@ -660,7 +662,7 @@ namespace } static bool SetArgumentCodeSampler(MaterialShaderArgument& argument, - const techset::ShaderArgumentCodeSource& source, + const ShaderArgumentCodeSource& source, const d3d9::ShaderConstant& shaderConstant, const unsigned sourceIndex, const unsigned arrayCount, @@ -695,9 +697,7 @@ namespace return true; } - bool AcceptVertexShaderConstantArgument(const techset::ShaderArgument& shaderArgument, - const techset::ShaderArgumentCodeSource& source, - std::string& errorMessage) + bool AcceptVertexShaderConstantArgument(const ShaderArgument& shaderArgument, const ShaderArgumentCodeSource& source, std::string& errorMessage) { assert(!m_passes.empty()); auto& pass = m_passes.at(m_passes.size() - 1); @@ -745,8 +745,8 @@ namespace return true; } - bool AcceptPixelShaderCodeArgument(const techset::ShaderArgument& shaderArgument, - const techset::ShaderArgumentCodeSource& source, + bool AcceptPixelShaderCodeArgument(const ShaderArgument& shaderArgument, + const ShaderArgumentCodeSource& source, std::string& errorMessage, const bool isSampler) { @@ -826,36 +826,36 @@ namespace return true; } - bool AcceptShaderConstantArgument(const techset::ShaderSelector shader, - const techset::ShaderArgument shaderArgument, - const techset::ShaderArgumentCodeSource source, + bool AcceptShaderConstantArgument(const ShaderSelector shader, + const ShaderArgument shaderArgument, + const ShaderArgumentCodeSource source, std::string& errorMessage) override { - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) return AcceptVertexShaderConstantArgument(shaderArgument, source, errorMessage); - assert(shader == techset::ShaderSelector::PIXEL_SHADER); + assert(shader == ShaderSelector::PIXEL_SHADER); return AcceptPixelShaderCodeArgument(shaderArgument, source, errorMessage, false); } - bool AcceptShaderSamplerArgument(const techset::ShaderSelector shader, - const techset::ShaderArgument shaderArgument, - const techset::ShaderArgumentCodeSource source, + bool AcceptShaderSamplerArgument(const ShaderSelector shader, + const ShaderArgument shaderArgument, + const ShaderArgumentCodeSource source, std::string& errorMessage) override { - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) { errorMessage = "Vertex sampler are unsupported"; return false; } - assert(shader == techset::ShaderSelector::PIXEL_SHADER); + assert(shader == ShaderSelector::PIXEL_SHADER); return AcceptPixelShaderCodeArgument(shaderArgument, source, errorMessage, true); } - bool AcceptShaderLiteralArgument(const techset::ShaderSelector shader, - const techset::ShaderArgument shaderArgument, - const techset::ShaderArgumentLiteralSource source, + bool AcceptShaderLiteralArgument(const ShaderSelector shader, + const ShaderArgument shaderArgument, + const ShaderArgumentLiteralSource source, std::string& errorMessage) override { assert(!m_passes.empty()); @@ -864,14 +864,14 @@ namespace MaterialShaderArgument argument; const d3d9::ShaderInfo* shaderInfo; - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) { argument.type = MTL_ARG_LITERAL_VERTEX_CONST; shaderInfo = pass.m_vertex_shader_info; } else { - assert(shader == techset::ShaderSelector::PIXEL_SHADER); + assert(shader == ShaderSelector::PIXEL_SHADER); argument.type = MTL_ARG_LITERAL_PIXEL_CONST; shaderInfo = pass.m_pixel_shader_info; } @@ -892,7 +892,7 @@ namespace const auto argumentIsSampler = IsSamplerArgument(shaderConstant); if (argumentIsSampler) { - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) errorMessage = "Vertex shader argument expects sampler but got constant"; else errorMessage = "Pixel shader argument expects sampler but got constant"; @@ -904,7 +904,7 @@ namespace argument.u.literalConst = m_zone_state.GetAllocatedLiteral(m_memory, source); pass.m_arguments.emplace_back(argument); - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) pass.m_handled_vertex_shader_arguments[pass.m_vertex_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true; else pass.m_handled_pixel_shader_arguments[pass.m_pixel_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true; @@ -912,9 +912,9 @@ namespace return true; } - bool AcceptShaderMaterialArgument(const techset::ShaderSelector shader, - const techset::ShaderArgument shaderArgument, - const techset::ShaderArgumentMaterialSource source, + bool AcceptShaderMaterialArgument(const ShaderSelector shader, + const ShaderArgument shaderArgument, + const ShaderArgumentMaterialSource source, std::string& errorMessage) override { assert(!m_passes.empty()); @@ -923,13 +923,13 @@ namespace MaterialShaderArgument argument; const d3d9::ShaderInfo* shaderInfo; - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) { shaderInfo = pass.m_vertex_shader_info; } else { - assert(shader == techset::ShaderSelector::PIXEL_SHADER); + assert(shader == ShaderSelector::PIXEL_SHADER); shaderInfo = pass.m_pixel_shader_info; } @@ -947,7 +947,7 @@ namespace const auto elementOffset = shaderArgument.m_argument_index_specified ? shaderArgument.m_argument_index : 0u; const auto& shaderConstant = shaderInfo->m_constants[shaderConstantIndex]; const auto argumentIsSampler = IsSamplerArgument(shaderConstant); - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) { if (argumentIsSampler) { @@ -958,7 +958,7 @@ namespace } else { - assert(shader == techset::ShaderSelector::PIXEL_SHADER); + assert(shader == ShaderSelector::PIXEL_SHADER); argument.type = !argumentIsSampler ? MTL_ARG_MATERIAL_PIXEL_CONST : MTL_ARG_MATERIAL_PIXEL_SAMPLER; } @@ -970,7 +970,7 @@ namespace argument.dest = static_cast(shaderConstant.m_register_index + registerOffset); pass.m_arguments.emplace_back(argument); - if (shader == techset::ShaderSelector::VERTEX_SHADER) + if (shader == ShaderSelector::VERTEX_SHADER) pass.m_handled_vertex_shader_arguments[pass.m_vertex_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true; else pass.m_handled_pixel_shader_arguments[pass.m_pixel_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true; @@ -1024,15 +1024,15 @@ namespace MemoryManager& m_memory; AssetCreationContext& m_context; TechniqueZoneLoadingState& m_zone_state; - techset::TechniqueStateMapCache& m_state_map_cache; + TechniqueStateMapCache& m_state_map_cache; ShaderInfoFromFileSystemCacheState& m_shader_info_cache; - ITechsetCreator* m_techset_creator; + IW4::techset::ICreator* m_techset_creator; }; class TechniqueLoader { public: - TechniqueLoader(ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, ITechsetCreator* techsetCreator) + TechniqueLoader(ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, IW4::techset::ICreator* techsetCreator) : m_search_path(searchPath), m_memory(memory), m_context(context), @@ -1243,13 +1243,13 @@ namespace MaterialTechnique* LoadTechniqueFromRaw(const std::string& techniqueName, std::vector& dependencies) const { - const auto techniqueFileName = GetTechniqueFileName(techniqueName); + const auto techniqueFileName = GetFileNameForTechniqueName(techniqueName); const auto file = m_search_path.Open(techniqueFileName); if (!file.IsOpen()) return nullptr; TechniqueCreator creator(techniqueName, m_search_path, m_memory, m_context, m_techset_creator); - const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &creator); + const TechniqueFileReader reader(*file.m_stream, techniqueFileName, &creator); if (!reader.ReadTechniqueDefinition()) return nullptr; @@ -1260,10 +1260,10 @@ namespace MemoryManager& m_memory; AssetCreationContext& m_context; TechniqueZoneLoadingState& m_zone_state; - ITechsetCreator* m_techset_creator; + IW4::techset::ICreator* m_techset_creator; }; - class TechsetLoader final : public ITechsetCreator + class TechsetLoader final : public IW4::techset::ICreator { public: TechsetLoader(MemoryManager& memory, ISearchPath& searchPath) @@ -1283,8 +1283,7 @@ namespace } private: - AssetCreationResult - CreateTechsetFromDefinition(const std::string& assetName, const techset::TechsetDefinition& definition, AssetCreationContext& context) + AssetCreationResult CreateTechsetFromDefinition(const std::string& assetName, const TechsetDefinition& definition, AssetCreationContext& context) { auto* techset = m_memory.Alloc(); techset->name = m_memory.Dup(assetName.c_str()); @@ -1312,20 +1311,20 @@ namespace return AssetCreationResult::Success(context.AddAsset(std::move(registration))); } - techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context, bool& failure) override + TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context, bool& failure) override { failure = false; - auto& definitionCache = context.GetZoneAssetCreationState(); + auto& definitionCache = context.GetZoneAssetCreationState(); auto* cachedTechsetDefinition = definitionCache.GetCachedTechsetDefinition(assetName); if (cachedTechsetDefinition) return cachedTechsetDefinition; - const auto techsetFileName = GetTechsetFileName(assetName); + const auto techsetFileName = GetFileNameForTechsetName(assetName); const auto file = m_search_path.Open(techsetFileName); if (!file.IsOpen()) return nullptr; - const techset::TechsetFileReader reader(*file.m_stream, techsetFileName, techniqueTypeNames, std::extent_v); + const TechsetFileReader reader(*file.m_stream, techsetFileName, techniqueTypeNames, std::extent_v); auto techsetDefinition = reader.ReadTechsetDefinition(); if (!techsetDefinition) { @@ -1342,12 +1341,12 @@ namespace const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) override { - auto& stateMapCache = context.GetZoneAssetCreationState(); + auto& stateMapCache = context.GetZoneAssetCreationState(); auto* cachedStateMap = stateMapCache.GetCachedStateMap(stateMapName); if (cachedStateMap) return cachedStateMap; - const auto stateMapFileName = GetStateMapFileName(stateMapName); + const auto stateMapFileName = GetFileNameForStateMapName(stateMapName); const auto file = m_search_path.Open(stateMapFileName); if (!file.IsOpen()) return nullptr; @@ -1370,25 +1369,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::techset { - std::string GetTechsetFileName(const std::string& techsetAssetName) - { - return std::format("techsets/{}.techset", techsetAssetName); - } - - std::string GetTechniqueFileName(const std::string& techniqueName) - { - return std::format("techniques/{}.tech", techniqueName); - } - - std::string GetStateMapFileName(const std::string& stateMapName) - { - return std::format("statemaps/{}.sm", stateMapName); - } - - std::unique_ptr CreateTechsetLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::techset diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.h b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.h index 2f246031..0187b329 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.h +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.h @@ -10,21 +10,17 @@ #include #include -namespace IW4 +namespace IW4::techset { - [[nodiscard]] std::string GetTechsetFileName(const std::string& techsetAssetName); - [[nodiscard]] std::string GetTechniqueFileName(const std::string& techniqueName); - [[nodiscard]] std::string GetStateMapFileName(const std::string& stateMapName); - - class ITechsetCreator : public AssetCreator + class ICreator : public AssetCreator { public: - ITechsetCreator() = default; - virtual ~ITechsetCreator() = default; + ICreator() = default; + virtual ~ICreator() = default; - virtual techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context, bool& failure) = 0; + virtual ::techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context, bool& failure) = 0; virtual const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) = 0; }; - std::unique_ptr CreateTechsetLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::techset diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp index 391975ee..feaa64bf 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp @@ -92,10 +92,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::vertex_decl { - std::unique_ptr> CreateVertexDeclLoader(MemoryManager& memory) + std::unique_ptr> CreateLoader(MemoryManager& memory) { return std::make_unique(memory); } -} // namespace IW4 +} // namespace IW4::vertex_decl diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h index d4bd1b68..3153e5a0 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::vertex_decl { - std::unique_ptr> CreateVertexDeclLoader(MemoryManager& memory); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory); +} // namespace IW4::vertex_decl diff --git a/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp b/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp index fe02ead8..5f9e9bf9 100644 --- a/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp +++ b/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp @@ -25,8 +25,8 @@ namespace { auto& memory = zone.Memory(); - if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) - collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); + if (image::IwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) + collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); } } // namespace diff --git a/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp b/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp index 3ca4d416..0442c1e8 100644 --- a/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp +++ b/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp @@ -25,8 +25,8 @@ namespace { auto& memory = zone.Memory(); - if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) - collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); + if (image::IwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) + collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); } } // namespace diff --git a/src/ObjCompiling/Game/T6/Image/ImageCompilerT6.cpp b/src/ObjCompiling/Game/T6/Image/ImageCompilerT6.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjCompiling/Game/T6/Image/ImageCompilerT6.h b/src/ObjCompiling/Game/T6/Image/ImageCompilerT6.h deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.cpp b/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.cpp index 22da77ce..92d3cd0d 100644 --- a/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.cpp @@ -18,7 +18,7 @@ namespace : m_memory(memory), m_zone(zone), m_zone_definition(zoneDefinition), - m_kvp_creator(zoneStates.GetZoneAssetCreationState()) + m_kvp_creator(zoneStates.GetZoneAssetCreationState<::key_value_pairs::Creator>()) { } @@ -67,15 +67,15 @@ namespace MemoryManager& m_memory; const Zone& m_zone; const ZoneDefinition& m_zone_definition; - KeyValuePairsCreator& m_kvp_creator; + ::key_value_pairs::Creator m_kvp_creator; }; } // namespace -namespace T6 +namespace T6::key_value_pairs { std::unique_ptr - CreateKeyValuePairsCompiler(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates) + CreateCompiler(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates) { return std::make_unique(memory, zone, zoneDefinition, zoneStates); } -} // namespace T6 +} // namespace T6::key_value_pairs diff --git a/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.h b/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.h index c68c06b5..a3dadb8c 100644 --- a/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.h +++ b/src/ObjCompiling/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.h @@ -9,8 +9,8 @@ #include -namespace T6 +namespace T6::key_value_pairs { std::unique_ptr - CreateKeyValuePairsCompiler(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates); -} // namespace T6 + CreateCompiler(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates); +} // namespace T6::key_value_pairs diff --git a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp index eae90387..d25f2dee 100644 --- a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp @@ -19,7 +19,7 @@ namespace { auto& memory = zone.Memory(); - collection.AddAssetCreator(CreateKeyValuePairsCompiler(memory, zone, zoneDefinition.m_zone_definition, zoneStates)); + collection.AddAssetCreator(T6::key_value_pairs::CreateCompiler(memory, zone, zoneDefinition.m_zone_definition, zoneStates)); } void ConfigurePostProcessors(AssetCreatorCollection& collection, @@ -31,11 +31,11 @@ namespace { auto& memory = zone.Memory(); - if (ImageIPakPostProcessor::AppliesToZoneDefinition(zoneDefinition)) - collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); + if (image::IPakPostProcessor::AppliesToZoneDefinition(zoneDefinition)) + collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); - if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) - collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); + if (image::IwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) + collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); } } // namespace diff --git a/src/ObjCompiling/Image/IPak/IPakCreator.cpp b/src/ObjCompiling/Image/IPak/IPakCreator.cpp index 64134b2b..1f3fd36a 100644 --- a/src/ObjCompiling/Image/IPak/IPakCreator.cpp +++ b/src/ObjCompiling/Image/IPak/IPakCreator.cpp @@ -371,68 +371,71 @@ namespace }; } // namespace -IPakToCreate::IPakToCreate(std::string name) - : m_name(std::move(name)) +namespace image { -} - -void IPakToCreate::AddImage(std::string imageName) -{ - m_image_names.emplace_back(std::move(imageName)); -} - -void IPakToCreate::Build(ISearchPath& searchPath, IOutputPath& outPath) -{ - const auto file = outPath.Open(std::format("{}.ipak", m_name)); - if (!file) + IPakToCreate::IPakToCreate(std::string name) + : m_name(std::move(name)) { - std::cerr << std::format("Failed to open file for ipak {}\n", m_name); - return; } - IPakWriter writer(*file, searchPath, m_image_names); - writer.Write(); + void IPakToCreate::AddImage(std::string imageName) + { + m_image_names.emplace_back(std::move(imageName)); + } - std::cout << std::format("Created ipak {} with {} entries\n", m_name, m_image_names.size()); -} + void IPakToCreate::Build(ISearchPath& searchPath, IOutputPath& outPath) + { + const auto file = outPath.Open(std::format("{}.ipak", m_name)); + if (!file) + { + std::cerr << std::format("Failed to open file for ipak {}\n", m_name); + return; + } -const std::vector& IPakToCreate::GetImageNames() const -{ - return m_image_names; -} + IPakWriter writer(*file, searchPath, m_image_names); + writer.Write(); -IPakCreator::IPakCreator() - : m_kvp_creator(nullptr) -{ -} + std::cout << std::format("Created ipak {} with {} entries\n", m_name, m_image_names.size()); + } -void IPakCreator::Inject(ZoneAssetCreationInjection& inject) -{ - m_kvp_creator = &inject.m_zone_states.GetZoneAssetCreationState(); -} + const std::vector& IPakToCreate::GetImageNames() const + { + return m_image_names; + } -IPakToCreate* IPakCreator::GetOrAddIPak(const std::string& ipakName) -{ - const auto existingIPak = m_ipak_lookup.find(ipakName); - if (existingIPak != m_ipak_lookup.end()) - return existingIPak->second; + IPakCreator::IPakCreator() + : m_kvp_creator(nullptr) + { + } - auto newIPak = std::make_unique(ipakName); - auto* result = newIPak.get(); - m_ipak_lookup.emplace(ipakName, result); - m_ipaks.emplace_back(std::move(newIPak)); + void IPakCreator::Inject(ZoneAssetCreationInjection& inject) + { + m_kvp_creator = &inject.m_zone_states.GetZoneAssetCreationState(); + } - assert(m_kvp_creator); - m_kvp_creator->AddKeyValuePair(CommonKeyValuePair("ipak_read", ipakName)); + IPakToCreate* IPakCreator::GetOrAddIPak(const std::string& ipakName) + { + const auto existingIPak = m_ipak_lookup.find(ipakName); + if (existingIPak != m_ipak_lookup.end()) + return existingIPak->second; - return result; -} + auto newIPak = std::make_unique(ipakName); + auto* result = newIPak.get(); + m_ipak_lookup.emplace(ipakName, result); + m_ipaks.emplace_back(std::move(newIPak)); -void IPakCreator::Finalize(ISearchPath& searchPath, IOutputPath& outPath) -{ - for (const auto& ipakToCreate : m_ipaks) - ipakToCreate->Build(searchPath, outPath); + assert(m_kvp_creator); + m_kvp_creator->AddKeyValuePair(key_value_pairs::CommonKeyValuePair("ipak_read", ipakName)); - m_ipaks.clear(); - m_ipak_lookup.clear(); -} + return result; + } + + void IPakCreator::Finalize(ISearchPath& searchPath, IOutputPath& outPath) + { + for (const auto& ipakToCreate : m_ipaks) + ipakToCreate->Build(searchPath, outPath); + + m_ipaks.clear(); + m_ipak_lookup.clear(); + } +} // namespace image diff --git a/src/ObjCompiling/Image/IPak/IPakCreator.h b/src/ObjCompiling/Image/IPak/IPakCreator.h index 31eed0b2..b7891fbf 100644 --- a/src/ObjCompiling/Image/IPak/IPakCreator.h +++ b/src/ObjCompiling/Image/IPak/IPakCreator.h @@ -9,32 +9,35 @@ #include #include -class IPakToCreate +namespace image { -public: - explicit IPakToCreate(std::string name); + class IPakToCreate + { + public: + explicit IPakToCreate(std::string name); - void AddImage(std::string imageName); - void Build(ISearchPath& searchPath, IOutputPath& outPath); - [[nodiscard]] const std::vector& GetImageNames() const; + void AddImage(std::string imageName); + void Build(ISearchPath& searchPath, IOutputPath& outPath); + [[nodiscard]] const std::vector& GetImageNames() const; -private: - std::string m_name; - std::vector m_image_names; -}; + private: + std::string m_name; + std::vector m_image_names; + }; -class IPakCreator final : public IZoneAssetCreationState -{ -public: - IPakCreator(); + class IPakCreator final : public IZoneAssetCreationState + { + public: + IPakCreator(); - void Inject(ZoneAssetCreationInjection& inject) override; + void Inject(ZoneAssetCreationInjection& inject) override; - IPakToCreate* GetOrAddIPak(const std::string& ipakName); - void Finalize(ISearchPath& searchPath, IOutputPath& outPath); + IPakToCreate* GetOrAddIPak(const std::string& ipakName); + void Finalize(ISearchPath& searchPath, IOutputPath& outPath); -private: - KeyValuePairsCreator* m_kvp_creator; - std::unordered_map m_ipak_lookup; - std::vector> m_ipaks; -}; + private: + key_value_pairs::Creator* m_kvp_creator; + std::unordered_map m_ipak_lookup; + std::vector> m_ipaks; + }; +} // namespace image diff --git a/src/ObjCompiling/Image/ImageIPakPostProcessor.cpp b/src/ObjCompiling/Image/ImageIPakPostProcessor.cpp index 24c0ace2..2c05d22b 100644 --- a/src/ObjCompiling/Image/ImageIPakPostProcessor.cpp +++ b/src/ObjCompiling/Image/ImageIPakPostProcessor.cpp @@ -4,63 +4,66 @@ #include -AbstractImageIPakPostProcessor::AbstractImageIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition, - ISearchPath& searchPath, - ZoneAssetCreationStateContainer& zoneStates, - IOutputPath& outDir) - : m_zone_definition(zoneDefinition), - m_search_path(searchPath), - m_ipak_creator(zoneStates.GetZoneAssetCreationState()), - m_out_dir(outDir), - m_obj_container_index(0u), - m_current_ipak(nullptr), - m_current_ipak_start_index(0u), - m_current_ipak_end_index(0u) +namespace image { - FindNextObjContainer(); -} - -bool AbstractImageIPakPostProcessor::AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition) -{ - return std::ranges::any_of(zoneDefinition.m_zone_definition.m_obj_containers, - [](const ZoneDefinitionObjContainer& objContainer) - { - return objContainer.m_type == ZoneDefinitionObjContainerType::IPAK; - }); -} - -void AbstractImageIPakPostProcessor::FindNextObjContainer() -{ - const auto objContainerCount = m_zone_definition.m_zone_definition.m_obj_containers.size(); - while (m_obj_container_index < objContainerCount) + AbstractIPakPostProcessor::AbstractIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition, + ISearchPath& searchPath, + ZoneAssetCreationStateContainer& zoneStates, + IOutputPath& outDir) + : m_zone_definition(zoneDefinition), + m_search_path(searchPath), + m_ipak_creator(zoneStates.GetZoneAssetCreationState()), + m_out_dir(outDir), + m_obj_container_index(0u), + m_current_ipak(nullptr), + m_current_ipak_start_index(0u), + m_current_ipak_end_index(0u) { - const auto& objContainer = m_zone_definition.m_zone_definition.m_obj_containers[m_obj_container_index++]; - - if (objContainer.m_type != ZoneDefinitionObjContainerType::IPAK) - continue; - - m_current_ipak = m_ipak_creator.GetOrAddIPak(objContainer.m_name); - m_current_ipak_start_index = objContainer.m_asset_start; - m_current_ipak_end_index = objContainer.m_asset_end; - return; + FindNextObjContainer(); } - m_current_ipak = nullptr; -} + bool AbstractIPakPostProcessor::AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition) + { + return std::ranges::any_of(zoneDefinition.m_zone_definition.m_obj_containers, + [](const ZoneDefinitionObjContainer& objContainer) + { + return objContainer.m_type == ZoneDefinitionObjContainerType::IPAK; + }); + } -void AbstractImageIPakPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) -{ - if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',') - return; + void AbstractIPakPostProcessor::FindNextObjContainer() + { + const auto objContainerCount = m_zone_definition.m_zone_definition.m_obj_containers.size(); + while (m_obj_container_index < objContainerCount) + { + const auto& objContainer = m_zone_definition.m_zone_definition.m_obj_containers[m_obj_container_index++]; - while (m_current_ipak && m_zone_definition.m_asset_index_in_definition >= m_current_ipak_end_index) - FindNextObjContainer(); + if (objContainer.m_type != ZoneDefinitionObjContainerType::IPAK) + continue; - if (m_current_ipak && m_zone_definition.m_asset_index_in_definition >= m_current_ipak_start_index) - m_current_ipak->AddImage(assetInfo.m_name); -} + m_current_ipak = m_ipak_creator.GetOrAddIPak(objContainer.m_name); + m_current_ipak_start_index = objContainer.m_asset_start; + m_current_ipak_end_index = objContainer.m_asset_end; + return; + } -void AbstractImageIPakPostProcessor::FinalizeZone(AssetCreationContext& context) -{ - m_ipak_creator.Finalize(m_search_path, m_out_dir); -} + m_current_ipak = nullptr; + } + + void AbstractIPakPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) + { + if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',') + return; + + while (m_current_ipak && m_zone_definition.m_asset_index_in_definition >= m_current_ipak_end_index) + FindNextObjContainer(); + + if (m_current_ipak && m_zone_definition.m_asset_index_in_definition >= m_current_ipak_start_index) + m_current_ipak->AddImage(assetInfo.m_name); + } + + void AbstractIPakPostProcessor::FinalizeZone(AssetCreationContext& context) + { + m_ipak_creator.Finalize(m_search_path, m_out_dir); + } +} // namespace image diff --git a/src/ObjCompiling/Image/ImageIPakPostProcessor.h b/src/ObjCompiling/Image/ImageIPakPostProcessor.h index 675b79cf..b6a6ec2d 100644 --- a/src/ObjCompiling/Image/ImageIPakPostProcessor.h +++ b/src/ObjCompiling/Image/ImageIPakPostProcessor.h @@ -5,48 +5,51 @@ #include "Image/IPak/IPakCreator.h" #include "SearchPath/IOutputPath.h" -class AbstractImageIPakPostProcessor : public IAssetPostProcessor +namespace image { -public: - AbstractImageIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition, - ISearchPath& searchPath, - ZoneAssetCreationStateContainer& zoneStates, - IOutputPath& outDir); - - static bool AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition); - - void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override; - void FinalizeZone(AssetCreationContext& context) override; - -private: - void FindNextObjContainer(); - - const ZoneDefinitionContext& m_zone_definition; - ISearchPath& m_search_path; - IPakCreator& m_ipak_creator; - IOutputPath& m_out_dir; - - unsigned m_obj_container_index; - IPakToCreate* m_current_ipak; - unsigned m_current_ipak_start_index; - unsigned m_current_ipak_end_index; -}; - -template class ImageIPakPostProcessor final : public AbstractImageIPakPostProcessor -{ -public: - static_assert(std::is_base_of_v); - - ImageIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition, - ISearchPath& searchPath, - ZoneAssetCreationStateContainer& zoneStates, - IOutputPath& outDir) - : AbstractImageIPakPostProcessor(zoneDefinition, searchPath, zoneStates, outDir) + class AbstractIPakPostProcessor : public IAssetPostProcessor { - } + public: + AbstractIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition, + ISearchPath& searchPath, + ZoneAssetCreationStateContainer& zoneStates, + IOutputPath& outDir); - [[nodiscard]] asset_type_t GetHandlingAssetType() const override + static bool AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition); + + void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override; + void FinalizeZone(AssetCreationContext& context) override; + + private: + void FindNextObjContainer(); + + const ZoneDefinitionContext& m_zone_definition; + ISearchPath& m_search_path; + IPakCreator& m_ipak_creator; + IOutputPath& m_out_dir; + + unsigned m_obj_container_index; + IPakToCreate* m_current_ipak; + unsigned m_current_ipak_start_index; + unsigned m_current_ipak_end_index; + }; + + template class IPakPostProcessor final : public AbstractIPakPostProcessor { - return AssetType::EnumEntry; - } -}; + public: + static_assert(std::is_base_of_v); + + IPakPostProcessor(const ZoneDefinitionContext& zoneDefinition, + ISearchPath& searchPath, + ZoneAssetCreationStateContainer& zoneStates, + IOutputPath& outDir) + : AbstractIPakPostProcessor(zoneDefinition, searchPath, zoneStates, outDir) + { + } + + [[nodiscard]] asset_type_t GetHandlingAssetType() const override + { + return AssetType::EnumEntry; + } + }; +} // namespace image diff --git a/src/ObjCompiling/Image/ImageIwdPostProcessor.cpp b/src/ObjCompiling/Image/ImageIwdPostProcessor.cpp index b329546c..3163ea81 100644 --- a/src/ObjCompiling/Image/ImageIwdPostProcessor.cpp +++ b/src/ObjCompiling/Image/ImageIwdPostProcessor.cpp @@ -1,67 +1,71 @@ #include "ImageIwdPostProcessor.h" +#include "Image/ImageCommon.h" #include "Iwd/IwdCreator.h" #include #include -AbstractImageIwdPostProcessor::AbstractImageIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition, - ISearchPath& searchPath, - ZoneAssetCreationStateContainer& zoneStates, - IOutputPath& outDir) - : m_zone_definition(zoneDefinition), - m_search_path(searchPath), - m_iwd_creator(zoneStates.GetZoneAssetCreationState()), - m_out_dir(outDir), - m_obj_container_index(0u), - m_current_iwd(nullptr), - m_current_iwd_start_index(0u), - m_current_iwd_end_index(0u) +namespace image { - FindNextObjContainer(); -} - -bool AbstractImageIwdPostProcessor::AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition) -{ - return std::ranges::any_of(zoneDefinition.m_zone_definition.m_obj_containers, - [](const ZoneDefinitionObjContainer& objContainer) - { - return objContainer.m_type == ZoneDefinitionObjContainerType::IWD; - }); -} - -void AbstractImageIwdPostProcessor::FindNextObjContainer() -{ - const auto objContainerCount = m_zone_definition.m_zone_definition.m_obj_containers.size(); - while (m_obj_container_index < objContainerCount) + AbstractIwdPostProcessor::AbstractIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition, + ISearchPath& searchPath, + ZoneAssetCreationStateContainer& zoneStates, + IOutputPath& outDir) + : m_zone_definition(zoneDefinition), + m_search_path(searchPath), + m_iwd_creator(zoneStates.GetZoneAssetCreationState()), + m_out_dir(outDir), + m_obj_container_index(0u), + m_current_iwd(nullptr), + m_current_iwd_start_index(0u), + m_current_iwd_end_index(0u) { - const auto& objContainer = m_zone_definition.m_zone_definition.m_obj_containers[m_obj_container_index++]; - - if (objContainer.m_type != ZoneDefinitionObjContainerType::IWD) - continue; - - m_current_iwd = m_iwd_creator.GetOrAddIwd(objContainer.m_name); - m_current_iwd_start_index = objContainer.m_asset_start; - m_current_iwd_end_index = objContainer.m_asset_end; - return; + FindNextObjContainer(); } - m_current_iwd = nullptr; -} + bool AbstractIwdPostProcessor::AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition) + { + return std::ranges::any_of(zoneDefinition.m_zone_definition.m_obj_containers, + [](const ZoneDefinitionObjContainer& objContainer) + { + return objContainer.m_type == ZoneDefinitionObjContainerType::IWD; + }); + } -void AbstractImageIwdPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) -{ - if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',') - return; + void AbstractIwdPostProcessor::FindNextObjContainer() + { + const auto objContainerCount = m_zone_definition.m_zone_definition.m_obj_containers.size(); + while (m_obj_container_index < objContainerCount) + { + const auto& objContainer = m_zone_definition.m_zone_definition.m_obj_containers[m_obj_container_index++]; - while (m_current_iwd && m_zone_definition.m_asset_index_in_definition >= m_current_iwd_end_index) - FindNextObjContainer(); + if (objContainer.m_type != ZoneDefinitionObjContainerType::IWD) + continue; - if (m_current_iwd && m_zone_definition.m_asset_index_in_definition >= m_current_iwd_start_index) - m_current_iwd->AddFile(std::format("images/{}.iwi", assetInfo.m_name)); -} + m_current_iwd = m_iwd_creator.GetOrAddIwd(objContainer.m_name); + m_current_iwd_start_index = objContainer.m_asset_start; + m_current_iwd_end_index = objContainer.m_asset_end; + return; + } -void AbstractImageIwdPostProcessor::FinalizeZone(AssetCreationContext& context) -{ - m_iwd_creator.Finalize(m_search_path, m_out_dir); -} + m_current_iwd = nullptr; + } + + void AbstractIwdPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) + { + if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',') + return; + + while (m_current_iwd && m_zone_definition.m_asset_index_in_definition >= m_current_iwd_end_index) + FindNextObjContainer(); + + if (m_current_iwd && m_zone_definition.m_asset_index_in_definition >= m_current_iwd_start_index) + m_current_iwd->AddFile(GetFileNameForAsset(assetInfo.m_name, ".iwi")); + } + + void AbstractIwdPostProcessor::FinalizeZone(AssetCreationContext& context) + { + m_iwd_creator.Finalize(m_search_path, m_out_dir); + } +} // namespace image diff --git a/src/ObjCompiling/Image/ImageIwdPostProcessor.h b/src/ObjCompiling/Image/ImageIwdPostProcessor.h index 8225c29f..a7bf657b 100644 --- a/src/ObjCompiling/Image/ImageIwdPostProcessor.h +++ b/src/ObjCompiling/Image/ImageIwdPostProcessor.h @@ -5,48 +5,48 @@ #include "Iwd/IwdCreator.h" #include "SearchPath/IOutputPath.h" -class AbstractImageIwdPostProcessor : public IAssetPostProcessor +namespace image { -public: - AbstractImageIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition, - ISearchPath& searchPath, - ZoneAssetCreationStateContainer& zoneStates, - IOutputPath& outDir); - - static bool AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition); - - void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override; - void FinalizeZone(AssetCreationContext& context) override; - -private: - void FindNextObjContainer(); - - const ZoneDefinitionContext& m_zone_definition; - ISearchPath& m_search_path; - IwdCreator& m_iwd_creator; - IOutputPath& m_out_dir; - - unsigned m_obj_container_index; - IwdToCreate* m_current_iwd; - unsigned m_current_iwd_start_index; - unsigned m_current_iwd_end_index; -}; - -template class ImageIwdPostProcessor final : public AbstractImageIwdPostProcessor -{ -public: - static_assert(std::is_base_of_v); - - ImageIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition, - ISearchPath& searchPath, - ZoneAssetCreationStateContainer& zoneStates, - IOutputPath& outDir) - : AbstractImageIwdPostProcessor(zoneDefinition, searchPath, zoneStates, outDir) + class AbstractIwdPostProcessor : public IAssetPostProcessor { - } + public: + AbstractIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition, + ISearchPath& searchPath, + ZoneAssetCreationStateContainer& zoneStates, + IOutputPath& outDir); - [[nodiscard]] asset_type_t GetHandlingAssetType() const override + static bool AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition); + + void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override; + void FinalizeZone(AssetCreationContext& context) override; + + private: + void FindNextObjContainer(); + + const ZoneDefinitionContext& m_zone_definition; + ISearchPath& m_search_path; + IwdCreator& m_iwd_creator; + IOutputPath& m_out_dir; + + unsigned m_obj_container_index; + IwdToCreate* m_current_iwd; + unsigned m_current_iwd_start_index; + unsigned m_current_iwd_end_index; + }; + + template class IwdPostProcessor final : public AbstractIwdPostProcessor { - return AssetType::EnumEntry; - } -}; + public: + static_assert(std::is_base_of_v); + + IwdPostProcessor(const ZoneDefinitionContext& zoneDefinition, ISearchPath& searchPath, ZoneAssetCreationStateContainer& zoneStates, IOutputPath& outDir) + : AbstractIwdPostProcessor(zoneDefinition, searchPath, zoneStates, outDir) + { + } + + [[nodiscard]] asset_type_t GetHandlingAssetType() const override + { + return AssetType::EnumEntry; + } + }; +} // namespace image diff --git a/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.cpp b/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.cpp index 348a6177..ec9b2cc8 100644 --- a/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.cpp +++ b/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.cpp @@ -5,72 +5,75 @@ #include #include -CommonKeyValuePair::CommonKeyValuePair(std::string keyStr, std::string value) - : m_key_str(std::move(keyStr)), - m_value(std::move(value)) +namespace key_value_pairs { -} - -CommonKeyValuePair::CommonKeyValuePair(const unsigned keyHash, std::string value) - : m_key_hash(keyHash), - m_value(std::move(value)) -{ -} - -void KeyValuePairsCreator::AddKeyValuePair(CommonKeyValuePair keyValuePair) -{ - m_key_value_pairs.emplace_back(std::move(keyValuePair)); -} - -void KeyValuePairsCreator::Finalize(const ZoneDefinition& zoneDefinition) -{ - for (const auto& metaData : zoneDefinition.m_properties.m_properties) + CommonKeyValuePair::CommonKeyValuePair(std::string keyStr, std::string value) + : m_key_str(std::move(keyStr)), + m_value(std::move(value)) { - if (metaData.first.rfind("level.", 0) == 0) - { - std::string strValue = metaData.first.substr(std::char_traits::length("level.")); - if (strValue.empty()) - continue; - - if (strValue[0] == '@') - { - char* endPtr; - const unsigned keyHash = strtoul(&strValue[1], &endPtr, 16); - - if (endPtr != &strValue[strValue.size()]) - { - std::cerr << std::format("Could not parse metadata key \"{}\" as hash\n", metaData.first); - continue; - } - - m_key_value_pairs.emplace_back(keyHash, metaData.second); - } - else - { - m_key_value_pairs.emplace_back(std::move(strValue), metaData.second); - } - } } - std::ranges::sort(m_key_value_pairs, - [](const CommonKeyValuePair& v0, const CommonKeyValuePair& v1) - { - if (v0.m_key_str.has_value()) + CommonKeyValuePair::CommonKeyValuePair(const unsigned keyHash, std::string value) + : m_key_hash(keyHash), + m_value(std::move(value)) + { + } + + void Creator::AddKeyValuePair(CommonKeyValuePair keyValuePair) + { + m_key_value_pairs.emplace_back(std::move(keyValuePair)); + } + + void Creator::Finalize(const ZoneDefinition& zoneDefinition) + { + for (const auto& metaData : zoneDefinition.m_properties.m_properties) + { + if (metaData.first.rfind("level.", 0) == 0) + { + std::string strValue = metaData.first.substr(std::char_traits::length("level.")); + if (strValue.empty()) + continue; + + if (strValue[0] == '@') + { + char* endPtr; + const unsigned keyHash = strtoul(&strValue[1], &endPtr, 16); + + if (endPtr != &strValue[strValue.size()]) + { + std::cerr << std::format("Could not parse metadata key \"{}\" as hash\n", metaData.first); + continue; + } + + m_key_value_pairs.emplace_back(keyHash, metaData.second); + } + else + { + m_key_value_pairs.emplace_back(std::move(strValue), metaData.second); + } + } + } + + std::ranges::sort(m_key_value_pairs, + [](const CommonKeyValuePair& v0, const CommonKeyValuePair& v1) { - if (!v1.m_key_str.has_value()) - return true; + if (v0.m_key_str.has_value()) + { + if (!v1.m_key_str.has_value()) + return true; - return *v0.m_key_str < *v1.m_key_str; - } + return *v0.m_key_str < *v1.m_key_str; + } - if (!v1.m_key_hash.has_value()) - return false; + if (!v1.m_key_hash.has_value()) + return false; - return *v0.m_key_hash < *v1.m_key_hash; - }); -} + return *v0.m_key_hash < *v1.m_key_hash; + }); + } -std::vector KeyValuePairsCreator::GetFinalKeyValuePairs() -{ - return std::move(m_key_value_pairs); -} + std::vector Creator::GetFinalKeyValuePairs() + { + return std::move(m_key_value_pairs); + } +} // namespace key_value_pairs diff --git a/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.h b/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.h index eb91d33f..dd35d260 100644 --- a/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.h +++ b/src/ObjCompiling/KeyValuePairs/KeyValuePairsCreator.h @@ -7,24 +7,27 @@ #include #include -class CommonKeyValuePair +namespace key_value_pairs { -public: - CommonKeyValuePair(std::string keyStr, std::string value); - CommonKeyValuePair(unsigned keyHash, std::string value); + class CommonKeyValuePair + { + public: + CommonKeyValuePair(std::string keyStr, std::string value); + CommonKeyValuePair(unsigned keyHash, std::string value); - std::optional m_key_str; - std::optional m_key_hash; - std::string m_value; -}; + std::optional m_key_str; + std::optional m_key_hash; + std::string m_value; + }; -class KeyValuePairsCreator final : public IZoneAssetCreationState -{ -public: - void AddKeyValuePair(CommonKeyValuePair keyValuePair); - void Finalize(const ZoneDefinition& zoneDefinition); - std::vector GetFinalKeyValuePairs(); + class Creator final : public IZoneAssetCreationState + { + public: + void AddKeyValuePair(CommonKeyValuePair keyValuePair); + void Finalize(const ZoneDefinition& zoneDefinition); + std::vector GetFinalKeyValuePairs(); -private: - std::vector m_key_value_pairs; -}; + private: + std::vector m_key_value_pairs; + }; +} // namespace key_value_pairs diff --git a/src/ObjLoading/Techset/TechniqueFileReader.h b/src/ObjLoading/Techset/TechniqueFileReader.h index fe85f9a8..2090304b 100644 --- a/src/ObjLoading/Techset/TechniqueFileReader.h +++ b/src/ObjLoading/Techset/TechniqueFileReader.h @@ -11,14 +11,15 @@ namespace techset { class TechniqueFileReader { + public: + TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor); + + [[nodiscard]] bool ReadTechniqueDefinition() const; + + private: std::string m_file_name; ITechniqueDefinitionAcceptor* m_acceptor; std::unique_ptr m_base_stream; std::unique_ptr m_comment_proxy; - - public: - TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor); - - _NODISCARD bool ReadTechniqueDefinition() const; }; } // namespace techset diff --git a/test/ObjCompilingTests/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6Test.cpp b/test/ObjCompilingTests/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6Test.cpp index b25715b9..dc771218 100644 --- a/test/ObjCompilingTests/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6Test.cpp +++ b/test/ObjCompilingTests/Game/T6/KeyValuePairs/KeyValuePairsCompilerT6Test.cpp @@ -26,13 +26,13 @@ namespace m_creators(m_zone), m_ignored_assets(), m_context(m_zone, &m_creators, &m_ignored_assets), - m_kvp_creator(m_zone_states.GetZoneAssetCreationState()) + m_kvp_creator(m_zone_states.GetZoneAssetCreationState<::key_value_pairs::Creator>()) { } std::unique_ptr CreateSut() { - return CreateKeyValuePairsCompiler(m_memory, m_zone, m_zone_definition, m_zone_states); + return T6::key_value_pairs::CreateCompiler(m_memory, m_zone, m_zone_definition, m_zone_states); } TestMemoryManager m_memory; @@ -43,7 +43,7 @@ namespace IgnoredAssetLookup m_ignored_assets; AssetCreationContext m_context; - KeyValuePairsCreator& m_kvp_creator; + ::key_value_pairs::Creator& m_kvp_creator; }; } // namespace @@ -81,7 +81,7 @@ namespace test::game::t6::keyvaluepairs TestContext testContext; const auto sut = testContext.CreateSut(); - testContext.m_kvp_creator.AddKeyValuePair(CommonKeyValuePair("ipak_read", "test_ipak")); + testContext.m_kvp_creator.AddKeyValuePair(::key_value_pairs::CommonKeyValuePair("ipak_read", "test_ipak")); sut->FinalizeZone(testContext.m_context); @@ -107,7 +107,7 @@ namespace test::game::t6::keyvaluepairs TestContext testContext; const auto sut = testContext.CreateSut(); - testContext.m_kvp_creator.AddKeyValuePair(CommonKeyValuePair(0xDDEEFFAA, "hello_there")); + testContext.m_kvp_creator.AddKeyValuePair(::key_value_pairs::CommonKeyValuePair(0xDDEEFFAA, "hello_there")); sut->FinalizeZone(testContext.m_context); diff --git a/test/ObjCompilingTests/Image/IPak/IPakCreatorTest.cpp b/test/ObjCompilingTests/Image/IPak/IPakCreatorTest.cpp index bd49745f..4b4fcd9f 100644 --- a/test/ObjCompilingTests/Image/IPak/IPakCreatorTest.cpp +++ b/test/ObjCompilingTests/Image/IPak/IPakCreatorTest.cpp @@ -26,9 +26,9 @@ namespace { } - IPakCreator& CreateSut() + image::IPakCreator& CreateSut() { - return m_zone_states.GetZoneAssetCreationState(); + return m_zone_states.GetZoneAssetCreationState(); } Zone m_zone; diff --git a/test/ObjCompilingTests/Image/ImageIPakPostProcessorTest.cpp b/test/ObjCompilingTests/Image/ImageIPakPostProcessorTest.cpp index 29dd627f..3955146d 100644 --- a/test/ObjCompilingTests/Image/ImageIPakPostProcessorTest.cpp +++ b/test/ObjCompilingTests/Image/ImageIPakPostProcessorTest.cpp @@ -28,13 +28,13 @@ namespace m_ignored_assets(), m_out_dir(), m_context(m_zone, &m_creators, &m_ignored_assets), - m_ipak_creator(m_zone_states.GetZoneAssetCreationState()) + m_ipak_creator(m_zone_states.GetZoneAssetCreationState()) { } std::unique_ptr CreateSut() { - return std::make_unique>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir); + return std::make_unique>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir); } Zone m_zone; @@ -47,7 +47,7 @@ namespace MockOutputPath m_out_dir; AssetCreationContext m_context; - IPakCreator& m_ipak_creator; + image::IPakCreator& m_ipak_creator; }; } // namespace diff --git a/test/ObjCompilingTests/Image/ImageIwdPostProcessorTest.cpp b/test/ObjCompilingTests/Image/ImageIwdPostProcessorTest.cpp index 8e971524..a357e550 100644 --- a/test/ObjCompilingTests/Image/ImageIwdPostProcessorTest.cpp +++ b/test/ObjCompilingTests/Image/ImageIwdPostProcessorTest.cpp @@ -33,7 +33,7 @@ namespace std::unique_ptr CreateSut() { - return std::make_unique>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir); + return std::make_unique>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir); } Zone m_zone; diff --git a/test/ObjCompilingTests/KeyValuePairs/KeyValuePairsCreatorTest.cpp b/test/ObjCompilingTests/KeyValuePairs/KeyValuePairsCreatorTest.cpp index 48bffd61..42c21fb1 100644 --- a/test/ObjCompilingTests/KeyValuePairs/KeyValuePairsCreatorTest.cpp +++ b/test/ObjCompilingTests/KeyValuePairs/KeyValuePairsCreatorTest.cpp @@ -13,7 +13,7 @@ namespace test::keyvaluepairs { TEST_CASE("KeyValuePairsCreator: ZoneDefinition with no properties produces no KeyValuePairs", "[keyvaluepairs]") { - KeyValuePairsCreator sut; + key_value_pairs::Creator sut; ZoneDefinition zoneDefinition; sut.Finalize(zoneDefinition); @@ -25,7 +25,7 @@ namespace test::keyvaluepairs TEST_CASE("KeyValuePairsCreator: ZoneDefinition with unrelated properties produce no KeyValuePairs", "[keyvaluepairs]") { - KeyValuePairsCreator sut; + key_value_pairs::Creator sut; ZoneDefinition zoneDefinition; zoneDefinition.m_properties.AddProperty("linker.test", "yes"); @@ -38,7 +38,7 @@ namespace test::keyvaluepairs TEST_CASE("KeyValuePairsCreator: ZoneDefinition with level properties produce KeyValuePairs", "[keyvaluepairs]") { - KeyValuePairsCreator sut; + key_value_pairs::Creator sut; ZoneDefinition zoneDefinition; zoneDefinition.m_properties.AddProperty("linker.test", "yes"); @@ -56,7 +56,7 @@ namespace test::keyvaluepairs TEST_CASE("KeyValuePairsCreator: ZoneDefinition can have level properties with hash", "[keyvaluepairs]") { - KeyValuePairsCreator sut; + key_value_pairs::Creator sut; ZoneDefinition zoneDefinition; zoneDefinition.m_properties.AddProperty("level.@D34DB33F", "yes"); @@ -77,7 +77,7 @@ namespace test::keyvaluepairs TEST_CASE("KeyValuePairsCreator: ZoneDefinition can have level properties with name and/or hash", "[keyvaluepairs]") { - KeyValuePairsCreator sut; + key_value_pairs::Creator sut; ZoneDefinition zoneDefinition; zoneDefinition.m_properties.AddProperty("level.ipak_read", "asdf");