2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-01 06:27:26 +00:00

refactor: streamline obj compiling asset loading

This commit is contained in:
Jan Laupetin
2025-08-05 18:51:56 +02:00
parent 95a6a028ab
commit 33c09dfe61
31 changed files with 505 additions and 495 deletions

View File

@@ -4,6 +4,11 @@
namespace techset namespace techset
{ {
std::string GetFileNameForStateMapName(const std::string& stateMapName)
{
return std::format("statemaps/{}.sm", stateMapName);
}
std::string GetFileNameForTechniqueName(const std::string& assetName) std::string GetFileNameForTechniqueName(const std::string& assetName)
{ {
return std::format("techniques/{}.tech", assetName); return std::format("techniques/{}.tech", assetName);

View File

@@ -4,6 +4,7 @@
namespace techset namespace techset
{ {
std::string GetFileNameForStateMapName(const std::string& stateMapName);
std::string GetFileNameForTechniqueName(const std::string& assetName); std::string GetFileNameForTechniqueName(const std::string& assetName);
std::string GetFileNameForTechsetName(const std::string& assetName); std::string GetFileNameForTechsetName(const std::string& assetName);
} // namespace techset } // namespace techset

View File

@@ -25,8 +25,8 @@ namespace
{ {
auto& memory = zone.Memory(); auto& memory = zone.Memory();
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition)) if (image::IwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir)); collection.AddAssetPostProcessor(std::make_unique<image::IwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
} }
} // namespace } // namespace

View File

@@ -14,6 +14,7 @@
#include "StateMap/StateMapHandler.h" #include "StateMap/StateMapHandler.h"
#include "Techset/TechniqueFileReader.h" #include "Techset/TechniqueFileReader.h"
#include "Techset/TechniqueStateMapCache.h" #include "Techset/TechniqueStateMapCache.h"
#include "Techset/TechsetCommon.h"
#include "Techset/TechsetDefinitionCache.h" #include "Techset/TechsetDefinitionCache.h"
#include <cmath> #include <cmath>
@@ -45,9 +46,9 @@ namespace
m_search_path(searchPath), m_search_path(searchPath),
m_context(context), m_context(context),
m_registration(registration), m_registration(registration),
m_state_map_cache(context.GetZoneAssetCreationState<techset::TechniqueStateMapCache>()), m_state_map_cache(context.GetZoneAssetCreationState<::techset::TechniqueStateMapCache>()),
m_base_state_bits{}, 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_registration.AddDependency(techset);
m_material.techniqueSet = techset->Asset(); m_material.techniqueSet = techset->Asset();
auto& definitionCache = m_context.GetZoneAssetCreationState<techset::TechsetDefinitionCache>(); auto& definitionCache = m_context.GetZoneAssetCreationState<::techset::TechsetDefinitionCache>();
bool failure = false; bool failure = false;
const auto* techsetDefinition = m_techset_creator->LoadTechsetDefinition(techsetName, m_context, failure); const auto* techsetDefinition = m_techset_creator->LoadTechsetDefinition(techsetName, m_context, failure);
@@ -806,7 +807,7 @@ namespace
SetTechniqueSetCameraRegion(techsetDefinition); SetTechniqueSetCameraRegion(techsetDefinition);
} }
void SetTechniqueSetStateBits(const techset::TechsetDefinition* techsetDefinition) void SetTechniqueSetStateBits(const ::techset::TechsetDefinition* techsetDefinition)
{ {
for (auto i = 0; i < TECHNIQUE_COUNT; i++) for (auto i = 0; i < TECHNIQUE_COUNT; i++)
{ {
@@ -854,19 +855,19 @@ namespace
return stateBits; 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); const auto* preloadedStateMap = m_state_map_cache.GetStateMapForTechnique(techniqueName);
if (preloadedStateMap) if (preloadedStateMap)
return preloadedStateMap; return preloadedStateMap;
const auto techniqueFileName = GetTechniqueFileName(techniqueName); const auto techniqueFileName = ::techset::GetFileNameForTechniqueName(techniqueName);
const auto file = m_search_path.Open(techniqueFileName); const auto file = m_search_path.Open(techniqueFileName);
if (!file.IsOpen()) if (!file.IsOpen())
return nullptr; return nullptr;
state_map::StateMapFromTechniqueExtractor extractor; 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()) if (!reader.ReadTechniqueDefinition())
{ {
m_state_map_cache.SetTechniqueUsesStateMap(techniqueName, nullptr); m_state_map_cache.SetTechniqueUsesStateMap(techniqueName, nullptr);
@@ -890,7 +891,7 @@ namespace
return outBits; return outBits;
} }
void SetTechniqueSetCameraRegion(const techset::TechsetDefinition* techsetDefinition) const void SetTechniqueSetCameraRegion(const ::techset::TechsetDefinition* techsetDefinition) const
{ {
std::string tempName; std::string tempName;
if (techsetDefinition->GetTechniqueByIndex(TECHNIQUE_LIT, tempName)) if (techsetDefinition->GetTechniqueByIndex(TECHNIQUE_LIT, tempName))
@@ -1316,7 +1317,7 @@ namespace
AssetCreationContext& m_context; AssetCreationContext& m_context;
AssetRegistration<AssetMaterial>& m_registration; AssetRegistration<AssetMaterial>& m_registration;
techset::TechniqueStateMapCache& m_state_map_cache; ::techset::TechniqueStateMapCache& m_state_map_cache;
std::unordered_map<const state_map::StateMapDefinition*, GfxStateBits> m_state_bits_per_state_map; std::unordered_map<const state_map::StateMapDefinition*, GfxStateBits> m_state_bits_per_state_map;
GfxStateBits m_base_state_bits; GfxStateBits m_base_state_bits;
@@ -1324,7 +1325,7 @@ namespace
std::vector<MaterialTextureDef> m_textures; std::vector<MaterialTextureDef> m_textures;
std::vector<MaterialConstantDef> m_constants; std::vector<MaterialConstantDef> m_constants;
std::unique_ptr<ITechsetCreator> m_techset_creator; std::unique_ptr<::IW4::techset::ICreator> m_techset_creator;
}; };
class MaterialLoader final : public AssetCreator<AssetMaterial> class MaterialLoader final : public AssetCreator<AssetMaterial>
@@ -1374,10 +1375,10 @@ namespace
}; };
} // namespace } // namespace
namespace IW4 namespace IW4::material
{ {
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt) std::unique_ptr<AssetCreator<AssetMaterial>> CreateCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt)
{ {
return std::make_unique<MaterialLoader>(memory, searchPath, gdt); return std::make_unique<MaterialLoader>(memory, searchPath, gdt);
} }
} // namespace IW4 } // namespace IW4::material

View File

@@ -6,7 +6,7 @@
#include "SearchPath/ISearchPath.h" #include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h" #include "Utils/MemoryManager.h"
namespace IW4 namespace IW4::material
{ {
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt); std::unique_ptr<AssetCreator<AssetMaterial>> CreateCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt);
} // namespace IW4 } // namespace IW4::material

View File

@@ -17,10 +17,10 @@ namespace
auto& memory = zone.Memory(); auto& memory = zone.Memory();
#ifdef EXPERIMENTAL_MATERIAL_COMPILATION #ifdef EXPERIMENTAL_MATERIAL_COMPILATION
collection.AddAssetCreator(CreateMaterialCompiler(memory, searchPath, gdt)); collection.AddAssetCreator(material::CreateCompiler(memory, searchPath, gdt));
collection.AddAssetCreator(CreateTechsetLoader(memory, searchPath)); collection.AddAssetCreator(IW4::techset::CreateLoader(memory, searchPath));
#endif #endif
collection.AddAssetCreator(CreateVertexDeclLoader(memory)); collection.AddAssetCreator(vertex_decl::CreateLoader(memory));
} }
void ConfigurePostProcessors(AssetCreatorCollection& collection, void ConfigurePostProcessors(AssetCreatorCollection& collection,
@@ -32,8 +32,8 @@ namespace
{ {
auto& memory = zone.Memory(); auto& memory = zone.Memory();
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition)) if (image::IwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir)); collection.AddAssetPostProcessor(std::make_unique<image::IwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
} }
} // namespace } // namespace

View File

@@ -9,6 +9,7 @@
#include "StateMap/StateMapReader.h" #include "StateMap/StateMapReader.h"
#include "Techset/TechniqueFileReader.h" #include "Techset/TechniqueFileReader.h"
#include "Techset/TechniqueStateMapCache.h" #include "Techset/TechniqueStateMapCache.h"
#include "Techset/TechsetCommon.h"
#include "Techset/TechsetDefinitionCache.h" #include "Techset/TechsetDefinitionCache.h"
#include "Techset/TechsetFileReader.h" #include "Techset/TechsetFileReader.h"
#include "Utils/Alignment.h" #include "Utils/Alignment.h"
@@ -25,6 +26,7 @@
#include <unordered_map> #include <unordered_map>
using namespace IW4; using namespace IW4;
using namespace ::techset;
using namespace std::string_literals; using namespace std::string_literals;
namespace namespace
@@ -62,7 +64,7 @@ namespace
.first->second.get(); .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); const auto& existingEntry = m_allocated_literals.find(source);
@@ -81,7 +83,7 @@ namespace
private: private:
std::unordered_map<std::string, std::unique_ptr<LoadedTechnique>> m_loaded_techniques; std::unordered_map<std::string, std::unique_ptr<LoadedTechnique>> m_loaded_techniques;
std::map<techset::ShaderArgumentLiteralSource, literal_t> m_allocated_literals; std::map<ShaderArgumentLiteralSource, literal_t> m_allocated_literals;
}; };
class ShaderInfoFromFileSystemCacheState final : public IZoneAssetCreationState class ShaderInfoFromFileSystemCacheState final : public IZoneAssetCreationState
@@ -121,7 +123,7 @@ namespace
std::unordered_map<std::string, std::unique_ptr<d3d9::ShaderInfo>> m_cached_shader_info; std::unordered_map<std::string, std::unique_ptr<d3d9::ShaderInfo>> m_cached_shader_info;
}; };
class TechniqueCreator final : public techset::ITechniqueDefinitionAcceptor class TechniqueCreator final : public ITechniqueDefinitionAcceptor
{ {
public: public:
class PassShaderArgument class PassShaderArgument
@@ -197,14 +199,17 @@ namespace
std::vector<PassShaderArgument> m_arguments; std::vector<PassShaderArgument> m_arguments;
}; };
TechniqueCreator( TechniqueCreator(const std::string& techniqueName,
const std::string& techniqueName, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, ITechsetCreator* techsetCreator) ISearchPath& searchPath,
MemoryManager& memory,
AssetCreationContext& context,
IW4::techset::ICreator* techsetCreator)
: m_technique_name(techniqueName), : m_technique_name(techniqueName),
m_search_path(searchPath), m_search_path(searchPath),
m_memory(memory), m_memory(memory),
m_context(context), m_context(context),
m_zone_state(context.GetZoneAssetCreationState<TechniqueZoneLoadingState>()), m_zone_state(context.GetZoneAssetCreationState<TechniqueZoneLoadingState>()),
m_state_map_cache(context.GetZoneAssetCreationState<techset::TechniqueStateMapCache>()), m_state_map_cache(context.GetZoneAssetCreationState<TechniqueStateMapCache>()),
m_shader_info_cache(context.GetZoneAssetCreationState<ShaderInfoFromFileSystemCacheState>()), m_shader_info_cache(context.GetZoneAssetCreationState<ShaderInfoFromFileSystemCacheState>()),
m_techset_creator(techsetCreator) m_techset_creator(techsetCreator)
{ {
@@ -230,7 +235,7 @@ namespace
|| constant.m_type == d3d9::ParameterType::SAMPLER_CUBE; || constant.m_type == d3d9::ParameterType::SAMPLER_CUBE;
} }
bool AutoCreateShaderArgument(const techset::ShaderSelector shaderType, bool AutoCreateShaderArgument(const ShaderSelector shaderType,
const d3d9::ShaderConstant& shaderArgument, const d3d9::ShaderConstant& shaderArgument,
const size_t elementOffset, const size_t elementOffset,
const size_t registerOffset) const size_t registerOffset)
@@ -239,7 +244,7 @@ namespace
auto& pass = m_passes.at(m_passes.size() - 1); auto& pass = m_passes.at(m_passes.size() - 1);
const auto isSamplerArgument = IsSamplerArgument(shaderArgument); const auto isSamplerArgument = IsSamplerArgument(shaderArgument);
if (shaderType == techset::ShaderSelector::VERTEX_SHADER && isSamplerArgument) if (shaderType == ShaderSelector::VERTEX_SHADER && isSamplerArgument)
return false; return false;
MaterialShaderArgument argument; MaterialShaderArgument argument;
@@ -270,7 +275,7 @@ namespace
if (!constantSource) if (!constantSource)
return false; 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<uint16_t>(constantSource->source + elementOffset); argument.u.codeConst.index = static_cast<uint16_t>(constantSource->source + elementOffset);
argument.u.codeConst.firstRow = 0u; argument.u.codeConst.firstRow = 0u;
argument.u.codeConst.rowCount = static_cast<unsigned char>(shaderArgument.m_type_rows); argument.u.codeConst.rowCount = static_cast<unsigned char>(shaderArgument.m_type_rows);
@@ -301,7 +306,7 @@ namespace
{ {
if (!pass.m_handled_vertex_shader_arguments[argumentHandledIndex + elementIndex]) 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; std::string elementIndexStr;
if (argument.m_type_elements > 1) if (argument.m_type_elements > 1)
@@ -336,7 +341,7 @@ namespace
{ {
if (!pass.m_handled_pixel_shader_arguments[argumentHandledIndex + elementIndex]) 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; std::ostringstream ss;
ss << "Unassigned pixel shader \"" << pass.m_pixel_shader->m_name << "\" arg: " << argument.m_name; ss << "Unassigned pixel shader \"" << pass.m_pixel_shader->m_name << "\" arg: " << argument.m_name;
@@ -572,11 +577,8 @@ namespace
return foundSource; return foundSource;
} }
static bool FindShaderArgument(const d3d9::ShaderInfo& shaderInfo, static bool FindShaderArgument(
const techset::ShaderArgument& argument, const d3d9::ShaderInfo& shaderInfo, const ShaderArgument& argument, size_t& constantIndex, size_t& registerOffset, std::string& errorMessage)
size_t& constantIndex,
size_t& registerOffset,
std::string& errorMessage)
{ {
const auto matchingShaderConstant = std::ranges::find_if(shaderInfo.m_constants, const auto matchingShaderConstant = std::ranges::find_if(shaderInfo.m_constants,
[argument](const d3d9::ShaderConstant& constant) [argument](const d3d9::ShaderConstant& constant)
@@ -622,7 +624,7 @@ namespace
} }
static bool SetArgumentCodeConst(MaterialShaderArgument& argument, static bool SetArgumentCodeConst(MaterialShaderArgument& argument,
const techset::ShaderArgumentCodeSource& source, const ShaderArgumentCodeSource& source,
const d3d9::ShaderConstant& shaderConstant, const d3d9::ShaderConstant& shaderConstant,
const unsigned sourceIndex, const unsigned sourceIndex,
const unsigned arrayCount, const unsigned arrayCount,
@@ -660,7 +662,7 @@ namespace
} }
static bool SetArgumentCodeSampler(MaterialShaderArgument& argument, static bool SetArgumentCodeSampler(MaterialShaderArgument& argument,
const techset::ShaderArgumentCodeSource& source, const ShaderArgumentCodeSource& source,
const d3d9::ShaderConstant& shaderConstant, const d3d9::ShaderConstant& shaderConstant,
const unsigned sourceIndex, const unsigned sourceIndex,
const unsigned arrayCount, const unsigned arrayCount,
@@ -695,9 +697,7 @@ namespace
return true; return true;
} }
bool AcceptVertexShaderConstantArgument(const techset::ShaderArgument& shaderArgument, bool AcceptVertexShaderConstantArgument(const ShaderArgument& shaderArgument, const ShaderArgumentCodeSource& source, std::string& errorMessage)
const techset::ShaderArgumentCodeSource& source,
std::string& errorMessage)
{ {
assert(!m_passes.empty()); assert(!m_passes.empty());
auto& pass = m_passes.at(m_passes.size() - 1); auto& pass = m_passes.at(m_passes.size() - 1);
@@ -745,8 +745,8 @@ namespace
return true; return true;
} }
bool AcceptPixelShaderCodeArgument(const techset::ShaderArgument& shaderArgument, bool AcceptPixelShaderCodeArgument(const ShaderArgument& shaderArgument,
const techset::ShaderArgumentCodeSource& source, const ShaderArgumentCodeSource& source,
std::string& errorMessage, std::string& errorMessage,
const bool isSampler) const bool isSampler)
{ {
@@ -826,36 +826,36 @@ namespace
return true; return true;
} }
bool AcceptShaderConstantArgument(const techset::ShaderSelector shader, bool AcceptShaderConstantArgument(const ShaderSelector shader,
const techset::ShaderArgument shaderArgument, const ShaderArgument shaderArgument,
const techset::ShaderArgumentCodeSource source, const ShaderArgumentCodeSource source,
std::string& errorMessage) override std::string& errorMessage) override
{ {
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == ShaderSelector::VERTEX_SHADER)
return AcceptVertexShaderConstantArgument(shaderArgument, source, errorMessage); return AcceptVertexShaderConstantArgument(shaderArgument, source, errorMessage);
assert(shader == techset::ShaderSelector::PIXEL_SHADER); assert(shader == ShaderSelector::PIXEL_SHADER);
return AcceptPixelShaderCodeArgument(shaderArgument, source, errorMessage, false); return AcceptPixelShaderCodeArgument(shaderArgument, source, errorMessage, false);
} }
bool AcceptShaderSamplerArgument(const techset::ShaderSelector shader, bool AcceptShaderSamplerArgument(const ShaderSelector shader,
const techset::ShaderArgument shaderArgument, const ShaderArgument shaderArgument,
const techset::ShaderArgumentCodeSource source, const ShaderArgumentCodeSource source,
std::string& errorMessage) override std::string& errorMessage) override
{ {
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == ShaderSelector::VERTEX_SHADER)
{ {
errorMessage = "Vertex sampler are unsupported"; errorMessage = "Vertex sampler are unsupported";
return false; return false;
} }
assert(shader == techset::ShaderSelector::PIXEL_SHADER); assert(shader == ShaderSelector::PIXEL_SHADER);
return AcceptPixelShaderCodeArgument(shaderArgument, source, errorMessage, true); return AcceptPixelShaderCodeArgument(shaderArgument, source, errorMessage, true);
} }
bool AcceptShaderLiteralArgument(const techset::ShaderSelector shader, bool AcceptShaderLiteralArgument(const ShaderSelector shader,
const techset::ShaderArgument shaderArgument, const ShaderArgument shaderArgument,
const techset::ShaderArgumentLiteralSource source, const ShaderArgumentLiteralSource source,
std::string& errorMessage) override std::string& errorMessage) override
{ {
assert(!m_passes.empty()); assert(!m_passes.empty());
@@ -864,14 +864,14 @@ namespace
MaterialShaderArgument argument; MaterialShaderArgument argument;
const d3d9::ShaderInfo* shaderInfo; const d3d9::ShaderInfo* shaderInfo;
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == ShaderSelector::VERTEX_SHADER)
{ {
argument.type = MTL_ARG_LITERAL_VERTEX_CONST; argument.type = MTL_ARG_LITERAL_VERTEX_CONST;
shaderInfo = pass.m_vertex_shader_info; shaderInfo = pass.m_vertex_shader_info;
} }
else else
{ {
assert(shader == techset::ShaderSelector::PIXEL_SHADER); assert(shader == ShaderSelector::PIXEL_SHADER);
argument.type = MTL_ARG_LITERAL_PIXEL_CONST; argument.type = MTL_ARG_LITERAL_PIXEL_CONST;
shaderInfo = pass.m_pixel_shader_info; shaderInfo = pass.m_pixel_shader_info;
} }
@@ -892,7 +892,7 @@ namespace
const auto argumentIsSampler = IsSamplerArgument(shaderConstant); const auto argumentIsSampler = IsSamplerArgument(shaderConstant);
if (argumentIsSampler) if (argumentIsSampler)
{ {
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == ShaderSelector::VERTEX_SHADER)
errorMessage = "Vertex shader argument expects sampler but got constant"; errorMessage = "Vertex shader argument expects sampler but got constant";
else else
errorMessage = "Pixel shader argument expects sampler but got constant"; errorMessage = "Pixel shader argument expects sampler but got constant";
@@ -904,7 +904,7 @@ namespace
argument.u.literalConst = m_zone_state.GetAllocatedLiteral(m_memory, source); argument.u.literalConst = m_zone_state.GetAllocatedLiteral(m_memory, source);
pass.m_arguments.emplace_back(argument); 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; pass.m_handled_vertex_shader_arguments[pass.m_vertex_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true;
else else
pass.m_handled_pixel_shader_arguments[pass.m_pixel_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true; pass.m_handled_pixel_shader_arguments[pass.m_pixel_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true;
@@ -912,9 +912,9 @@ namespace
return true; return true;
} }
bool AcceptShaderMaterialArgument(const techset::ShaderSelector shader, bool AcceptShaderMaterialArgument(const ShaderSelector shader,
const techset::ShaderArgument shaderArgument, const ShaderArgument shaderArgument,
const techset::ShaderArgumentMaterialSource source, const ShaderArgumentMaterialSource source,
std::string& errorMessage) override std::string& errorMessage) override
{ {
assert(!m_passes.empty()); assert(!m_passes.empty());
@@ -923,13 +923,13 @@ namespace
MaterialShaderArgument argument; MaterialShaderArgument argument;
const d3d9::ShaderInfo* shaderInfo; const d3d9::ShaderInfo* shaderInfo;
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == ShaderSelector::VERTEX_SHADER)
{ {
shaderInfo = pass.m_vertex_shader_info; shaderInfo = pass.m_vertex_shader_info;
} }
else else
{ {
assert(shader == techset::ShaderSelector::PIXEL_SHADER); assert(shader == ShaderSelector::PIXEL_SHADER);
shaderInfo = pass.m_pixel_shader_info; 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 elementOffset = shaderArgument.m_argument_index_specified ? shaderArgument.m_argument_index : 0u;
const auto& shaderConstant = shaderInfo->m_constants[shaderConstantIndex]; const auto& shaderConstant = shaderInfo->m_constants[shaderConstantIndex];
const auto argumentIsSampler = IsSamplerArgument(shaderConstant); const auto argumentIsSampler = IsSamplerArgument(shaderConstant);
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == ShaderSelector::VERTEX_SHADER)
{ {
if (argumentIsSampler) if (argumentIsSampler)
{ {
@@ -958,7 +958,7 @@ namespace
} }
else 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; argument.type = !argumentIsSampler ? MTL_ARG_MATERIAL_PIXEL_CONST : MTL_ARG_MATERIAL_PIXEL_SAMPLER;
} }
@@ -970,7 +970,7 @@ namespace
argument.dest = static_cast<uint16_t>(shaderConstant.m_register_index + registerOffset); argument.dest = static_cast<uint16_t>(shaderConstant.m_register_index + registerOffset);
pass.m_arguments.emplace_back(argument); 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; pass.m_handled_vertex_shader_arguments[pass.m_vertex_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true;
else else
pass.m_handled_pixel_shader_arguments[pass.m_pixel_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true; pass.m_handled_pixel_shader_arguments[pass.m_pixel_shader_argument_handled_offset[shaderConstantIndex] + elementOffset] = true;
@@ -1024,15 +1024,15 @@ namespace
MemoryManager& m_memory; MemoryManager& m_memory;
AssetCreationContext& m_context; AssetCreationContext& m_context;
TechniqueZoneLoadingState& m_zone_state; TechniqueZoneLoadingState& m_zone_state;
techset::TechniqueStateMapCache& m_state_map_cache; TechniqueStateMapCache& m_state_map_cache;
ShaderInfoFromFileSystemCacheState& m_shader_info_cache; ShaderInfoFromFileSystemCacheState& m_shader_info_cache;
ITechsetCreator* m_techset_creator; IW4::techset::ICreator* m_techset_creator;
}; };
class TechniqueLoader class TechniqueLoader
{ {
public: 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_search_path(searchPath),
m_memory(memory), m_memory(memory),
m_context(context), m_context(context),
@@ -1243,13 +1243,13 @@ namespace
MaterialTechnique* LoadTechniqueFromRaw(const std::string& techniqueName, std::vector<XAssetInfoGeneric*>& dependencies) const MaterialTechnique* LoadTechniqueFromRaw(const std::string& techniqueName, std::vector<XAssetInfoGeneric*>& dependencies) const
{ {
const auto techniqueFileName = GetTechniqueFileName(techniqueName); const auto techniqueFileName = GetFileNameForTechniqueName(techniqueName);
const auto file = m_search_path.Open(techniqueFileName); const auto file = m_search_path.Open(techniqueFileName);
if (!file.IsOpen()) if (!file.IsOpen())
return nullptr; return nullptr;
TechniqueCreator creator(techniqueName, m_search_path, m_memory, m_context, m_techset_creator); 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()) if (!reader.ReadTechniqueDefinition())
return nullptr; return nullptr;
@@ -1260,10 +1260,10 @@ namespace
MemoryManager& m_memory; MemoryManager& m_memory;
AssetCreationContext& m_context; AssetCreationContext& m_context;
TechniqueZoneLoadingState& m_zone_state; 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: public:
TechsetLoader(MemoryManager& memory, ISearchPath& searchPath) TechsetLoader(MemoryManager& memory, ISearchPath& searchPath)
@@ -1283,8 +1283,7 @@ namespace
} }
private: private:
AssetCreationResult AssetCreationResult CreateTechsetFromDefinition(const std::string& assetName, const TechsetDefinition& definition, AssetCreationContext& context)
CreateTechsetFromDefinition(const std::string& assetName, const techset::TechsetDefinition& definition, AssetCreationContext& context)
{ {
auto* techset = m_memory.Alloc<MaterialTechniqueSet>(); auto* techset = m_memory.Alloc<MaterialTechniqueSet>();
techset->name = m_memory.Dup(assetName.c_str()); techset->name = m_memory.Dup(assetName.c_str());
@@ -1312,20 +1311,20 @@ namespace
return AssetCreationResult::Success(context.AddAsset(std::move(registration))); 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; failure = false;
auto& definitionCache = context.GetZoneAssetCreationState<techset::TechsetDefinitionCache>(); auto& definitionCache = context.GetZoneAssetCreationState<TechsetDefinitionCache>();
auto* cachedTechsetDefinition = definitionCache.GetCachedTechsetDefinition(assetName); auto* cachedTechsetDefinition = definitionCache.GetCachedTechsetDefinition(assetName);
if (cachedTechsetDefinition) if (cachedTechsetDefinition)
return cachedTechsetDefinition; return cachedTechsetDefinition;
const auto techsetFileName = GetTechsetFileName(assetName); const auto techsetFileName = GetFileNameForTechsetName(assetName);
const auto file = m_search_path.Open(techsetFileName); const auto file = m_search_path.Open(techsetFileName);
if (!file.IsOpen()) if (!file.IsOpen())
return nullptr; return nullptr;
const techset::TechsetFileReader reader(*file.m_stream, techsetFileName, techniqueTypeNames, std::extent_v<decltype(techniqueTypeNames)>); const TechsetFileReader reader(*file.m_stream, techsetFileName, techniqueTypeNames, std::extent_v<decltype(techniqueTypeNames)>);
auto techsetDefinition = reader.ReadTechsetDefinition(); auto techsetDefinition = reader.ReadTechsetDefinition();
if (!techsetDefinition) if (!techsetDefinition)
{ {
@@ -1342,12 +1341,12 @@ namespace
const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) override const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) override
{ {
auto& stateMapCache = context.GetZoneAssetCreationState<techset::TechniqueStateMapCache>(); auto& stateMapCache = context.GetZoneAssetCreationState<TechniqueStateMapCache>();
auto* cachedStateMap = stateMapCache.GetCachedStateMap(stateMapName); auto* cachedStateMap = stateMapCache.GetCachedStateMap(stateMapName);
if (cachedStateMap) if (cachedStateMap)
return cachedStateMap; return cachedStateMap;
const auto stateMapFileName = GetStateMapFileName(stateMapName); const auto stateMapFileName = GetFileNameForStateMapName(stateMapName);
const auto file = m_search_path.Open(stateMapFileName); const auto file = m_search_path.Open(stateMapFileName);
if (!file.IsOpen()) if (!file.IsOpen())
return nullptr; return nullptr;
@@ -1370,25 +1369,10 @@ namespace
}; };
} // namespace } // namespace
namespace IW4 namespace IW4::techset
{ {
std::string GetTechsetFileName(const std::string& techsetAssetName) std::unique_ptr<ICreator> CreateLoader(MemoryManager& memory, ISearchPath& searchPath)
{
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<ITechsetCreator> CreateTechsetLoader(MemoryManager& memory, ISearchPath& searchPath)
{ {
return std::make_unique<TechsetLoader>(memory, searchPath); return std::make_unique<TechsetLoader>(memory, searchPath);
} }
} // namespace IW4 } // namespace IW4::techset

View File

@@ -10,21 +10,17 @@
#include <memory> #include <memory>
#include <string> #include <string>
namespace IW4 namespace IW4::techset
{ {
[[nodiscard]] std::string GetTechsetFileName(const std::string& techsetAssetName); class ICreator : public AssetCreator<AssetTechniqueSet>
[[nodiscard]] std::string GetTechniqueFileName(const std::string& techniqueName);
[[nodiscard]] std::string GetStateMapFileName(const std::string& stateMapName);
class ITechsetCreator : public AssetCreator<AssetTechniqueSet>
{ {
public: public:
ITechsetCreator() = default; ICreator() = default;
virtual ~ITechsetCreator() = 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; virtual const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) = 0;
}; };
std::unique_ptr<ITechsetCreator> CreateTechsetLoader(MemoryManager& memory, ISearchPath& searchPath); std::unique_ptr<ICreator> CreateLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4 } // namespace IW4::techset

View File

@@ -92,10 +92,10 @@ namespace
}; };
} // namespace } // namespace
namespace IW4 namespace IW4::vertex_decl
{ {
std::unique_ptr<AssetCreator<AssetVertexDecl>> CreateVertexDeclLoader(MemoryManager& memory) std::unique_ptr<AssetCreator<AssetVertexDecl>> CreateLoader(MemoryManager& memory)
{ {
return std::make_unique<LoaderVertexDecl>(memory); return std::make_unique<LoaderVertexDecl>(memory);
} }
} // namespace IW4 } // namespace IW4::vertex_decl

View File

@@ -7,7 +7,7 @@
#include <memory> #include <memory>
namespace IW4 namespace IW4::vertex_decl
{ {
std::unique_ptr<AssetCreator<AssetVertexDecl>> CreateVertexDeclLoader(MemoryManager& memory); std::unique_ptr<AssetCreator<AssetVertexDecl>> CreateLoader(MemoryManager& memory);
} // namespace IW4 } // namespace IW4::vertex_decl

View File

@@ -25,8 +25,8 @@ namespace
{ {
auto& memory = zone.Memory(); auto& memory = zone.Memory();
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition)) if (image::IwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir)); collection.AddAssetPostProcessor(std::make_unique<image::IwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
} }
} // namespace } // namespace

View File

@@ -25,8 +25,8 @@ namespace
{ {
auto& memory = zone.Memory(); auto& memory = zone.Memory();
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition)) if (image::IwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir)); collection.AddAssetPostProcessor(std::make_unique<image::IwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
} }
} // namespace } // namespace

View File

@@ -18,7 +18,7 @@ namespace
: m_memory(memory), : m_memory(memory),
m_zone(zone), m_zone(zone),
m_zone_definition(zoneDefinition), m_zone_definition(zoneDefinition),
m_kvp_creator(zoneStates.GetZoneAssetCreationState<KeyValuePairsCreator>()) m_kvp_creator(zoneStates.GetZoneAssetCreationState<::key_value_pairs::Creator>())
{ {
} }
@@ -67,15 +67,15 @@ namespace
MemoryManager& m_memory; MemoryManager& m_memory;
const Zone& m_zone; const Zone& m_zone;
const ZoneDefinition& m_zone_definition; const ZoneDefinition& m_zone_definition;
KeyValuePairsCreator& m_kvp_creator; ::key_value_pairs::Creator m_kvp_creator;
}; };
} // namespace } // namespace
namespace T6 namespace T6::key_value_pairs
{ {
std::unique_ptr<IAssetCreator> std::unique_ptr<IAssetCreator>
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<KeyValuePairsCompiler>(memory, zone, zoneDefinition, zoneStates); return std::make_unique<KeyValuePairsCompiler>(memory, zone, zoneDefinition, zoneStates);
} }
} // namespace T6 } // namespace T6::key_value_pairs

View File

@@ -9,8 +9,8 @@
#include <memory> #include <memory>
namespace T6 namespace T6::key_value_pairs
{ {
std::unique_ptr<IAssetCreator> std::unique_ptr<IAssetCreator>
CreateKeyValuePairsCompiler(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates); CreateCompiler(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates);
} // namespace T6 } // namespace T6::key_value_pairs

View File

@@ -19,7 +19,7 @@ namespace
{ {
auto& memory = zone.Memory(); 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, void ConfigurePostProcessors(AssetCreatorCollection& collection,
@@ -31,11 +31,11 @@ namespace
{ {
auto& memory = zone.Memory(); auto& memory = zone.Memory();
if (ImageIPakPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition)) if (image::IPakPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<ImageIPakPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir)); collection.AddAssetPostProcessor(std::make_unique<image::IPakPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition)) if (image::IwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir)); collection.AddAssetPostProcessor(std::make_unique<image::IwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
} }
} // namespace } // namespace

View File

@@ -371,68 +371,71 @@ namespace
}; };
} // namespace } // namespace
IPakToCreate::IPakToCreate(std::string name) namespace image
: m_name(std::move(name))
{ {
} IPakToCreate::IPakToCreate(std::string name)
: m_name(std::move(name))
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)
{ {
std::cerr << std::format("Failed to open file for ipak {}\n", m_name);
return;
} }
IPakWriter writer(*file, searchPath, m_image_names); void IPakToCreate::AddImage(std::string imageName)
writer.Write(); {
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<std::string>& IPakToCreate::GetImageNames() const IPakWriter writer(*file, searchPath, m_image_names);
{ writer.Write();
return m_image_names;
}
IPakCreator::IPakCreator() std::cout << std::format("Created ipak {} with {} entries\n", m_name, m_image_names.size());
: m_kvp_creator(nullptr) }
{
}
void IPakCreator::Inject(ZoneAssetCreationInjection& inject) const std::vector<std::string>& IPakToCreate::GetImageNames() const
{ {
m_kvp_creator = &inject.m_zone_states.GetZoneAssetCreationState<KeyValuePairsCreator>(); return m_image_names;
} }
IPakToCreate* IPakCreator::GetOrAddIPak(const std::string& ipakName) IPakCreator::IPakCreator()
{ : m_kvp_creator(nullptr)
const auto existingIPak = m_ipak_lookup.find(ipakName); {
if (existingIPak != m_ipak_lookup.end()) }
return existingIPak->second;
auto newIPak = std::make_unique<IPakToCreate>(ipakName); void IPakCreator::Inject(ZoneAssetCreationInjection& inject)
auto* result = newIPak.get(); {
m_ipak_lookup.emplace(ipakName, result); m_kvp_creator = &inject.m_zone_states.GetZoneAssetCreationState<key_value_pairs::Creator>();
m_ipaks.emplace_back(std::move(newIPak)); }
assert(m_kvp_creator); IPakToCreate* IPakCreator::GetOrAddIPak(const std::string& ipakName)
m_kvp_creator->AddKeyValuePair(CommonKeyValuePair("ipak_read", 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<IPakToCreate>(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) assert(m_kvp_creator);
{ m_kvp_creator->AddKeyValuePair(key_value_pairs::CommonKeyValuePair("ipak_read", ipakName));
for (const auto& ipakToCreate : m_ipaks)
ipakToCreate->Build(searchPath, outPath);
m_ipaks.clear(); return result;
m_ipak_lookup.clear(); }
}
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

View File

@@ -9,32 +9,35 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
class IPakToCreate namespace image
{ {
public: class IPakToCreate
explicit IPakToCreate(std::string name); {
public:
explicit IPakToCreate(std::string name);
void AddImage(std::string imageName); void AddImage(std::string imageName);
void Build(ISearchPath& searchPath, IOutputPath& outPath); void Build(ISearchPath& searchPath, IOutputPath& outPath);
[[nodiscard]] const std::vector<std::string>& GetImageNames() const; [[nodiscard]] const std::vector<std::string>& GetImageNames() const;
private: private:
std::string m_name; std::string m_name;
std::vector<std::string> m_image_names; std::vector<std::string> m_image_names;
}; };
class IPakCreator final : public IZoneAssetCreationState class IPakCreator final : public IZoneAssetCreationState
{ {
public: public:
IPakCreator(); IPakCreator();
void Inject(ZoneAssetCreationInjection& inject) override; void Inject(ZoneAssetCreationInjection& inject) override;
IPakToCreate* GetOrAddIPak(const std::string& ipakName); IPakToCreate* GetOrAddIPak(const std::string& ipakName);
void Finalize(ISearchPath& searchPath, IOutputPath& outPath); void Finalize(ISearchPath& searchPath, IOutputPath& outPath);
private: private:
KeyValuePairsCreator* m_kvp_creator; key_value_pairs::Creator* m_kvp_creator;
std::unordered_map<std::string, IPakToCreate*> m_ipak_lookup; std::unordered_map<std::string, IPakToCreate*> m_ipak_lookup;
std::vector<std::unique_ptr<IPakToCreate>> m_ipaks; std::vector<std::unique_ptr<IPakToCreate>> m_ipaks;
}; };
} // namespace image

View File

@@ -4,63 +4,66 @@
#include <algorithm> #include <algorithm>
AbstractImageIPakPostProcessor::AbstractImageIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition, namespace image
ISearchPath& searchPath,
ZoneAssetCreationStateContainer& zoneStates,
IOutputPath& outDir)
: m_zone_definition(zoneDefinition),
m_search_path(searchPath),
m_ipak_creator(zoneStates.GetZoneAssetCreationState<IPakCreator>()),
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)
{ {
FindNextObjContainer(); AbstractIPakPostProcessor::AbstractIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition,
} ISearchPath& searchPath,
ZoneAssetCreationStateContainer& zoneStates,
bool AbstractImageIPakPostProcessor::AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition) IOutputPath& outDir)
{ : m_zone_definition(zoneDefinition),
return std::ranges::any_of(zoneDefinition.m_zone_definition.m_obj_containers, m_search_path(searchPath),
[](const ZoneDefinitionObjContainer& objContainer) m_ipak_creator(zoneStates.GetZoneAssetCreationState<IPakCreator>()),
{ m_out_dir(outDir),
return objContainer.m_type == ZoneDefinitionObjContainerType::IPAK; m_obj_container_index(0u),
}); m_current_ipak(nullptr),
} m_current_ipak_start_index(0u),
m_current_ipak_end_index(0u)
void AbstractImageIPakPostProcessor::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++]; FindNextObjContainer();
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;
} }
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) void AbstractIPakPostProcessor::FindNextObjContainer()
{ {
if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',') const auto objContainerCount = m_zone_definition.m_zone_definition.m_obj_containers.size();
return; 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) if (objContainer.m_type != ZoneDefinitionObjContainerType::IPAK)
FindNextObjContainer(); continue;
if (m_current_ipak && m_zone_definition.m_asset_index_in_definition >= m_current_ipak_start_index) m_current_ipak = m_ipak_creator.GetOrAddIPak(objContainer.m_name);
m_current_ipak->AddImage(assetInfo.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_current_ipak = nullptr;
{ }
m_ipak_creator.Finalize(m_search_path, m_out_dir);
} 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

View File

@@ -5,48 +5,51 @@
#include "Image/IPak/IPakCreator.h" #include "Image/IPak/IPakCreator.h"
#include "SearchPath/IOutputPath.h" #include "SearchPath/IOutputPath.h"
class AbstractImageIPakPostProcessor : public IAssetPostProcessor namespace image
{ {
public: class AbstractIPakPostProcessor : public IAssetPostProcessor
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<typename AssetType> class ImageIPakPostProcessor final : public AbstractImageIPakPostProcessor
{
public:
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
ImageIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition,
ISearchPath& searchPath,
ZoneAssetCreationStateContainer& zoneStates,
IOutputPath& outDir)
: AbstractImageIPakPostProcessor(zoneDefinition, searchPath, zoneStates, outDir)
{ {
} 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<typename AssetType> class IPakPostProcessor final : public AbstractIPakPostProcessor
{ {
return AssetType::EnumEntry; public:
} static_assert(std::is_base_of_v<IAssetBase, AssetType>);
};
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

View File

@@ -1,67 +1,71 @@
#include "ImageIwdPostProcessor.h" #include "ImageIwdPostProcessor.h"
#include "Image/ImageCommon.h"
#include "Iwd/IwdCreator.h" #include "Iwd/IwdCreator.h"
#include <algorithm> #include <algorithm>
#include <format> #include <format>
AbstractImageIwdPostProcessor::AbstractImageIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition, namespace image
ISearchPath& searchPath,
ZoneAssetCreationStateContainer& zoneStates,
IOutputPath& outDir)
: m_zone_definition(zoneDefinition),
m_search_path(searchPath),
m_iwd_creator(zoneStates.GetZoneAssetCreationState<IwdCreator>()),
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)
{ {
FindNextObjContainer(); AbstractIwdPostProcessor::AbstractIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition,
} ISearchPath& searchPath,
ZoneAssetCreationStateContainer& zoneStates,
bool AbstractImageIwdPostProcessor::AppliesToZoneDefinition(const ZoneDefinitionContext& zoneDefinition) IOutputPath& outDir)
{ : m_zone_definition(zoneDefinition),
return std::ranges::any_of(zoneDefinition.m_zone_definition.m_obj_containers, m_search_path(searchPath),
[](const ZoneDefinitionObjContainer& objContainer) m_iwd_creator(zoneStates.GetZoneAssetCreationState<IwdCreator>()),
{ m_out_dir(outDir),
return objContainer.m_type == ZoneDefinitionObjContainerType::IWD; m_obj_container_index(0u),
}); m_current_iwd(nullptr),
} m_current_iwd_start_index(0u),
m_current_iwd_end_index(0u)
void AbstractImageIwdPostProcessor::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++]; FindNextObjContainer();
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;
} }
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) void AbstractIwdPostProcessor::FindNextObjContainer()
{ {
if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',') const auto objContainerCount = m_zone_definition.m_zone_definition.m_obj_containers.size();
return; 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) if (objContainer.m_type != ZoneDefinitionObjContainerType::IWD)
FindNextObjContainer(); continue;
if (m_current_iwd && m_zone_definition.m_asset_index_in_definition >= m_current_iwd_start_index) m_current_iwd = m_iwd_creator.GetOrAddIwd(objContainer.m_name);
m_current_iwd->AddFile(std::format("images/{}.iwi", assetInfo.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_current_iwd = nullptr;
{ }
m_iwd_creator.Finalize(m_search_path, m_out_dir);
} 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

View File

@@ -5,48 +5,48 @@
#include "Iwd/IwdCreator.h" #include "Iwd/IwdCreator.h"
#include "SearchPath/IOutputPath.h" #include "SearchPath/IOutputPath.h"
class AbstractImageIwdPostProcessor : public IAssetPostProcessor namespace image
{ {
public: class AbstractIwdPostProcessor : public IAssetPostProcessor
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<typename AssetType> class ImageIwdPostProcessor final : public AbstractImageIwdPostProcessor
{
public:
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
ImageIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition,
ISearchPath& searchPath,
ZoneAssetCreationStateContainer& zoneStates,
IOutputPath& outDir)
: AbstractImageIwdPostProcessor(zoneDefinition, searchPath, zoneStates, outDir)
{ {
} 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<typename AssetType> class IwdPostProcessor final : public AbstractIwdPostProcessor
{ {
return AssetType::EnumEntry; public:
} static_assert(std::is_base_of_v<IAssetBase, AssetType>);
};
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

View File

@@ -5,72 +5,75 @@
#include <iostream> #include <iostream>
#include <ranges> #include <ranges>
CommonKeyValuePair::CommonKeyValuePair(std::string keyStr, std::string value) namespace key_value_pairs
: m_key_str(std::move(keyStr)),
m_value(std::move(value))
{ {
} CommonKeyValuePair::CommonKeyValuePair(std::string keyStr, std::string value)
: m_key_str(std::move(keyStr)),
CommonKeyValuePair::CommonKeyValuePair(const unsigned keyHash, std::string value) m_value(std::move(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)
{ {
if (metaData.first.rfind("level.", 0) == 0)
{
std::string strValue = metaData.first.substr(std::char_traits<char>::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, CommonKeyValuePair::CommonKeyValuePair(const unsigned keyHash, std::string value)
[](const CommonKeyValuePair& v0, const CommonKeyValuePair& v1) : m_key_hash(keyHash),
{ m_value(std::move(value))
if (v0.m_key_str.has_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<char>::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()) if (v0.m_key_str.has_value())
return true; {
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()) if (!v1.m_key_hash.has_value())
return false; return false;
return *v0.m_key_hash < *v1.m_key_hash; return *v0.m_key_hash < *v1.m_key_hash;
}); });
} }
std::vector<CommonKeyValuePair> KeyValuePairsCreator::GetFinalKeyValuePairs() std::vector<CommonKeyValuePair> Creator::GetFinalKeyValuePairs()
{ {
return std::move(m_key_value_pairs); return std::move(m_key_value_pairs);
} }
} // namespace key_value_pairs

View File

@@ -7,24 +7,27 @@
#include <string> #include <string>
#include <vector> #include <vector>
class CommonKeyValuePair namespace key_value_pairs
{ {
public: class CommonKeyValuePair
CommonKeyValuePair(std::string keyStr, std::string value); {
CommonKeyValuePair(unsigned keyHash, std::string value); public:
CommonKeyValuePair(std::string keyStr, std::string value);
CommonKeyValuePair(unsigned keyHash, std::string value);
std::optional<std::string> m_key_str; std::optional<std::string> m_key_str;
std::optional<unsigned> m_key_hash; std::optional<unsigned> m_key_hash;
std::string m_value; std::string m_value;
}; };
class KeyValuePairsCreator final : public IZoneAssetCreationState class Creator final : public IZoneAssetCreationState
{ {
public: public:
void AddKeyValuePair(CommonKeyValuePair keyValuePair); void AddKeyValuePair(CommonKeyValuePair keyValuePair);
void Finalize(const ZoneDefinition& zoneDefinition); void Finalize(const ZoneDefinition& zoneDefinition);
std::vector<CommonKeyValuePair> GetFinalKeyValuePairs(); std::vector<CommonKeyValuePair> GetFinalKeyValuePairs();
private: private:
std::vector<CommonKeyValuePair> m_key_value_pairs; std::vector<CommonKeyValuePair> m_key_value_pairs;
}; };
} // namespace key_value_pairs

View File

@@ -11,14 +11,15 @@ namespace techset
{ {
class TechniqueFileReader class TechniqueFileReader
{ {
public:
TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor);
[[nodiscard]] bool ReadTechniqueDefinition() const;
private:
std::string m_file_name; std::string m_file_name;
ITechniqueDefinitionAcceptor* m_acceptor; ITechniqueDefinitionAcceptor* m_acceptor;
std::unique_ptr<IParserLineStream> m_base_stream; std::unique_ptr<IParserLineStream> m_base_stream;
std::unique_ptr<IParserLineStream> m_comment_proxy; std::unique_ptr<IParserLineStream> m_comment_proxy;
public:
TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor);
_NODISCARD bool ReadTechniqueDefinition() const;
}; };
} // namespace techset } // namespace techset

View File

@@ -26,13 +26,13 @@ namespace
m_creators(m_zone), m_creators(m_zone),
m_ignored_assets(), m_ignored_assets(),
m_context(m_zone, &m_creators, &m_ignored_assets), m_context(m_zone, &m_creators, &m_ignored_assets),
m_kvp_creator(m_zone_states.GetZoneAssetCreationState<KeyValuePairsCreator>()) m_kvp_creator(m_zone_states.GetZoneAssetCreationState<::key_value_pairs::Creator>())
{ {
} }
std::unique_ptr<IAssetCreator> CreateSut() std::unique_ptr<IAssetCreator> 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; TestMemoryManager m_memory;
@@ -43,7 +43,7 @@ namespace
IgnoredAssetLookup m_ignored_assets; IgnoredAssetLookup m_ignored_assets;
AssetCreationContext m_context; AssetCreationContext m_context;
KeyValuePairsCreator& m_kvp_creator; ::key_value_pairs::Creator& m_kvp_creator;
}; };
} // namespace } // namespace
@@ -81,7 +81,7 @@ namespace test::game::t6::keyvaluepairs
TestContext testContext; TestContext testContext;
const auto sut = testContext.CreateSut(); 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); sut->FinalizeZone(testContext.m_context);
@@ -107,7 +107,7 @@ namespace test::game::t6::keyvaluepairs
TestContext testContext; TestContext testContext;
const auto sut = testContext.CreateSut(); 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); sut->FinalizeZone(testContext.m_context);

View File

@@ -26,9 +26,9 @@ namespace
{ {
} }
IPakCreator& CreateSut() image::IPakCreator& CreateSut()
{ {
return m_zone_states.GetZoneAssetCreationState<IPakCreator>(); return m_zone_states.GetZoneAssetCreationState<image::IPakCreator>();
} }
Zone m_zone; Zone m_zone;

View File

@@ -28,13 +28,13 @@ namespace
m_ignored_assets(), m_ignored_assets(),
m_out_dir(), m_out_dir(),
m_context(m_zone, &m_creators, &m_ignored_assets), m_context(m_zone, &m_creators, &m_ignored_assets),
m_ipak_creator(m_zone_states.GetZoneAssetCreationState<IPakCreator>()) m_ipak_creator(m_zone_states.GetZoneAssetCreationState<image::IPakCreator>())
{ {
} }
std::unique_ptr<IAssetPostProcessor> CreateSut() std::unique_ptr<IAssetPostProcessor> CreateSut()
{ {
return std::make_unique<ImageIPakPostProcessor<AssetImage>>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir); return std::make_unique<image::IPakPostProcessor<AssetImage>>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir);
} }
Zone m_zone; Zone m_zone;
@@ -47,7 +47,7 @@ namespace
MockOutputPath m_out_dir; MockOutputPath m_out_dir;
AssetCreationContext m_context; AssetCreationContext m_context;
IPakCreator& m_ipak_creator; image::IPakCreator& m_ipak_creator;
}; };
} // namespace } // namespace

View File

@@ -33,7 +33,7 @@ namespace
std::unique_ptr<IAssetPostProcessor> CreateSut() std::unique_ptr<IAssetPostProcessor> CreateSut()
{ {
return std::make_unique<ImageIwdPostProcessor<AssetImage>>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir); return std::make_unique<image::IwdPostProcessor<AssetImage>>(m_zone_definition_context, m_search_path, m_zone_states, m_out_dir);
} }
Zone m_zone; Zone m_zone;

View File

@@ -13,7 +13,7 @@ namespace test::keyvaluepairs
{ {
TEST_CASE("KeyValuePairsCreator: ZoneDefinition with no properties produces no KeyValuePairs", "[keyvaluepairs]") TEST_CASE("KeyValuePairsCreator: ZoneDefinition with no properties produces no KeyValuePairs", "[keyvaluepairs]")
{ {
KeyValuePairsCreator sut; key_value_pairs::Creator sut;
ZoneDefinition zoneDefinition; ZoneDefinition zoneDefinition;
sut.Finalize(zoneDefinition); sut.Finalize(zoneDefinition);
@@ -25,7 +25,7 @@ namespace test::keyvaluepairs
TEST_CASE("KeyValuePairsCreator: ZoneDefinition with unrelated properties produce no KeyValuePairs", "[keyvaluepairs]") TEST_CASE("KeyValuePairsCreator: ZoneDefinition with unrelated properties produce no KeyValuePairs", "[keyvaluepairs]")
{ {
KeyValuePairsCreator sut; key_value_pairs::Creator sut;
ZoneDefinition zoneDefinition; ZoneDefinition zoneDefinition;
zoneDefinition.m_properties.AddProperty("linker.test", "yes"); zoneDefinition.m_properties.AddProperty("linker.test", "yes");
@@ -38,7 +38,7 @@ namespace test::keyvaluepairs
TEST_CASE("KeyValuePairsCreator: ZoneDefinition with level properties produce KeyValuePairs", "[keyvaluepairs]") TEST_CASE("KeyValuePairsCreator: ZoneDefinition with level properties produce KeyValuePairs", "[keyvaluepairs]")
{ {
KeyValuePairsCreator sut; key_value_pairs::Creator sut;
ZoneDefinition zoneDefinition; ZoneDefinition zoneDefinition;
zoneDefinition.m_properties.AddProperty("linker.test", "yes"); 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]") TEST_CASE("KeyValuePairsCreator: ZoneDefinition can have level properties with hash", "[keyvaluepairs]")
{ {
KeyValuePairsCreator sut; key_value_pairs::Creator sut;
ZoneDefinition zoneDefinition; ZoneDefinition zoneDefinition;
zoneDefinition.m_properties.AddProperty("level.@D34DB33F", "yes"); 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]") TEST_CASE("KeyValuePairsCreator: ZoneDefinition can have level properties with name and/or hash", "[keyvaluepairs]")
{ {
KeyValuePairsCreator sut; key_value_pairs::Creator sut;
ZoneDefinition zoneDefinition; ZoneDefinition zoneDefinition;
zoneDefinition.m_properties.AddProperty("level.ipak_read", "asdf"); zoneDefinition.m_properties.AddProperty("level.ipak_read", "asdf");