2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-08-30 21:53:15 +00:00

Merge pull request #488 from Laupetin/refactor/dumper-asset-folders

refactor: streamlining of loader and dumper layout, namespaces
This commit is contained in:
Jan
2025-08-06 23:23:25 +02:00
committed by GitHub
567 changed files with 10797 additions and 10913 deletions

View File

@@ -1,11 +1,11 @@
#include "FontIconCommonT6.h"
#include "FontIconCommon.h"
#include "Utils/StringUtils.h"
#include <filesystem>
namespace fs = std::filesystem;
namespace T6::font_icon
namespace font_icon
{
std::string GetJsonFileNameForAssetName(const std::string& assetName)
{
@@ -20,4 +20,4 @@ namespace T6::font_icon
return assetName;
}
} // namespace T6::font_icon
} // namespace font_icon

View File

@@ -2,7 +2,7 @@
#include <string>
namespace T6::font_icon
namespace font_icon
{
std::string GetJsonFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,15 @@
#include "ImageCommon.h"
#include <algorithm>
#include <format>
namespace image
{
std::string GetFileNameForAsset(std::string assetName, const std::string& extension)
{
std::string cleanAssetName(std::move(assetName));
std::ranges::replace(cleanAssetName, '*', '_');
return std::format("images/{}{}", cleanAssetName, extension);
}
} // namespace image

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace image
{
std::string GetFileNameForAsset(std::string assetName, const std::string& extension);
}

View File

@@ -0,0 +1,11 @@
#include "LeaderboardCommon.h"
#include <format>
namespace leaderboard
{
std::string GetJsonFileNameForAsset(const std::string& assetName)
{
return std::format("leaderboards/{}.json", assetName);
}
} // namespace leaderboard

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace leaderboard
{
std::string GetJsonFileNameForAsset(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "LightDefCommon.h"
#include <format>
namespace light_def
{
std::string GetFileNameForAsset(const std::string& assetName)
{
return std::format("lights/{}", assetName);
}
} // namespace light_def

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace light_def
{
std::string GetFileNameForAsset(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "PhysCollmapCommon.h"
#include <format>
namespace phys_collmap
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("phys_collmaps/{}.map", assetName);
}
} // namespace phys_collmap

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace phys_collmap
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "PhysConstraintsCommon.h"
#include <format>
namespace phys_constraints
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("physconstraints/{}", assetName);
}
} // namespace phys_constraints

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace phys_constraints
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "PhysPresetCommon.h"
#include <format>
namespace phys_preset
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("physic/{}", assetName);
}
} // namespace phys_preset

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace phys_preset
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,16 @@
#include "ShaderCommon.h"
#include <format>
namespace shader
{
std::string GetFileNameForPixelShaderAssetName(const std::string& assetName)
{
return std::format("shader_bin/ps_{}.cso", assetName);
}
std::string GetFileNameForVertexShaderAssetName(const std::string& assetName)
{
return std::format("shader_bin/vs_{}.cso", assetName);
}
} // namespace shader

View File

@@ -0,0 +1,9 @@
#pragma once
#include <string>
namespace shader
{
std::string GetFileNameForPixelShaderAssetName(const std::string& assetName);
std::string GetFileNameForVertexShaderAssetName(const std::string& assetName);
} // namespace shader

View File

@@ -0,0 +1,11 @@
#include "SoundCurveCommon.h"
#include <format>
namespace sound_curve
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("soundaliases/{}.vfcurve", assetName);
}
} // namespace sound_curve

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace sound_curve
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,21 @@
#include "TechsetCommon.h"
#include <format>
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);
}
std::string GetFileNameForTechsetName(const std::string& assetName)
{
return std::format("techsets/{}.techset", assetName);
}
} // namespace techset

View File

@@ -0,0 +1,10 @@
#pragma once
#include <string>
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

View File

@@ -0,0 +1,11 @@
#include "TracerCommon.h"
#include <format>
namespace tracer
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("tracer/{}", assetName);
}
} // namespace tracer

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace tracer
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "VehicleCommon.h"
#include <format>
namespace vehicle
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("vehicles/{}", assetName);
}
} // namespace vehicle

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace vehicle
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,16 @@
#include "AttachmentCommon.h"
#include <format>
namespace attachment
{
std::string GetInfoStringFileNameForAssetName(const std::string& assetName)
{
return std::format("attachment/{}", assetName);
}
std::string GetJsonFileNameForAssetName(const std::string& assetName)
{
return std::format("attachment/{}.json", assetName);
}
} // namespace attachment

View File

@@ -0,0 +1,9 @@
#pragma once
#include <string>
namespace attachment
{
std::string GetInfoStringFileNameForAssetName(const std::string& assetName);
std::string GetJsonFileNameForAssetName(const std::string& assetName);
} // namespace attachment

View File

@@ -0,0 +1,11 @@
#include "AttachmentUniqueCommon.h"
#include <format>
namespace attachment_unique
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("attachmentunique/{}", assetName);
}
} // namespace attachment_unique

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace attachment_unique
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "WeaponCommon.h"
#include <format>
namespace camo
{
std::string GetJsonFileNameForAssetName(const std::string& assetName)
{
return std::format("camo/{}.json", assetName);
}
} // namespace camo

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace camo
{
std::string GetJsonFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "WeaponCommon.h"
#include <format>
namespace weapon
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("weapons/{}", assetName);
}
} // namespace weapon

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace weapon
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

@@ -1,6 +1,7 @@
#include "XModelCommon.h"
#include <cmath>
#include <format>
#include <limits>
#include <tuple>
@@ -99,3 +100,11 @@ bool operator<(const VertexMergerPos& lhs, const VertexMergerPos& rhs)
return false;
}
namespace xmodel
{
std::string GetJsonFileNameForAssetName(const std::string& assetName)
{
return std::format("xmodel/{}.json", assetName);
}
} // namespace xmodel

View File

@@ -127,3 +127,8 @@ struct VertexMergerPos
};
typedef DistinctMapper<VertexMergerPos> VertexMerger;
namespace xmodel
{
std::string GetJsonFileNameForAssetName(const std::string& assetName);
}

View File

@@ -0,0 +1,11 @@
#include "ZBarrierCommon.h"
#include <format>
namespace z_barrier
{
std::string GetFileNameForAssetName(const std::string& assetName)
{
return std::format("zbarrier/{}", assetName);
}
} // namespace z_barrier

View File

@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace z_barrier
{
std::string GetFileNameForAssetName(const std::string& assetName);
}

View File

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

View File

@@ -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 <cmath>
@@ -45,9 +46,9 @@ namespace
m_search_path(searchPath),
m_context(context),
m_registration(registration),
m_state_map_cache(context.GetZoneAssetCreationState<techset::TechniqueStateMapCache>()),
m_state_map_cache(context.GetZoneAssetCreationState<::techset::TechniqueStateMapCache>()),
m_base_state_bits{},
m_techset_creator(CreateTechsetLoader(memory, searchPath))
m_techset_creator(techset::CreateLoaderIW4(memory, searchPath))
{
}
@@ -793,7 +794,7 @@ namespace
m_registration.AddDependency(techset);
m_material.techniqueSet = techset->Asset();
auto& definitionCache = m_context.GetZoneAssetCreationState<techset::TechsetDefinitionCache>();
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<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;
GfxStateBits m_base_state_bits;
@@ -1324,7 +1325,7 @@ namespace
std::vector<MaterialTextureDef> m_textures;
std::vector<MaterialConstantDef> m_constants;
std::unique_ptr<ITechsetCreator> m_techset_creator;
std::unique_ptr<techset::ICreatorIW4> m_techset_creator;
};
class MaterialLoader final : public AssetCreator<AssetMaterial>
@@ -1374,10 +1375,10 @@ namespace
};
} // namespace
namespace IW4
namespace material
{
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialCompiler(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt)
std::unique_ptr<AssetCreator<AssetMaterial>> CreateCompilerIW4(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt)
{
return std::make_unique<MaterialLoader>(memory, searchPath, gdt);
}
} // namespace IW4
} // namespace material

View File

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

View File

@@ -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::CreateCompilerIW4(memory, searchPath, gdt));
collection.AddAssetCreator(techset::CreateLoaderIW4(memory, searchPath));
#endif
collection.AddAssetCreator(CreateVertexDeclLoader(memory));
collection.AddAssetCreator(vertex_decl::CreateLoaderIW4(memory));
}
void ConfigurePostProcessors(AssetCreatorCollection& collection,
@@ -32,8 +32,8 @@ namespace
{
auto& memory = zone.Memory();
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
if (image::IwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
collection.AddAssetPostProcessor(std::make_unique<image::IwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
}
} // namespace

View File

@@ -5,9 +5,11 @@
#include "Game/IW4/Shader/LoaderVertexShaderIW4.h"
#include "Game/IW4/TechsetConstantsIW4.h"
#include "Shader/D3D9ShaderAnalyser.h"
#include "Shader/ShaderCommon.h"
#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"
@@ -24,6 +26,7 @@
#include <unordered_map>
using namespace IW4;
using namespace ::techset;
using namespace std::string_literals;
namespace
@@ -61,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);
@@ -80,7 +83,7 @@ namespace
private:
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
@@ -120,7 +123,7 @@ namespace
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:
class PassShaderArgument
@@ -196,14 +199,17 @@ namespace
std::vector<PassShaderArgument> 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,
techset::ICreatorIW4* techsetCreator)
: m_technique_name(techniqueName),
m_search_path(searchPath),
m_memory(memory),
m_context(context),
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_techset_creator(techsetCreator)
{
@@ -229,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)
@@ -238,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;
@@ -269,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<uint16_t>(constantSource->source + elementOffset);
argument.u.codeConst.firstRow = 0u;
argument.u.codeConst.rowCount = static_cast<unsigned char>(shaderArgument.m_type_rows);
@@ -300,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)
@@ -335,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;
@@ -460,7 +466,8 @@ namespace
if (pass.m_vertex_shader->Asset()->name && pass.m_vertex_shader->Asset()->name[0] == ',')
{
pass.m_vertex_shader_info = m_shader_info_cache.LoadShaderInfoFromDisk(m_search_path, GetVertexShaderFileName(vertexShaderName));
pass.m_vertex_shader_info =
m_shader_info_cache.LoadShaderInfoFromDisk(m_search_path, ::shader::GetFileNameForVertexShaderAssetName(vertexShaderName));
}
else
{
@@ -495,7 +502,8 @@ namespace
if (pass.m_pixel_shader->Asset()->name && pass.m_pixel_shader->Asset()->name[0] == ',')
{
pass.m_pixel_shader_info = m_shader_info_cache.LoadShaderInfoFromDisk(m_search_path, GetPixelShaderFileName(pixelShaderName));
pass.m_pixel_shader_info =
m_shader_info_cache.LoadShaderInfoFromDisk(m_search_path, ::shader::GetFileNameForPixelShaderAssetName(pixelShaderName));
}
else
{
@@ -569,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)
@@ -619,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,
@@ -657,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,
@@ -692,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);
@@ -742,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)
{
@@ -823,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());
@@ -861,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;
}
@@ -889,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";
@@ -901,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;
@@ -909,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());
@@ -920,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;
}
@@ -944,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)
{
@@ -955,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;
}
@@ -967,7 +970,7 @@ namespace
argument.dest = static_cast<uint16_t>(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;
@@ -1021,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;
techset::ICreatorIW4* m_techset_creator;
};
class TechniqueLoader
{
public:
TechniqueLoader(ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, ITechsetCreator* techsetCreator)
TechniqueLoader(ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, techset::ICreatorIW4* techsetCreator)
: m_search_path(searchPath),
m_memory(memory),
m_context(context),
@@ -1240,13 +1243,13 @@ namespace
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);
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;
@@ -1257,10 +1260,10 @@ namespace
MemoryManager& m_memory;
AssetCreationContext& m_context;
TechniqueZoneLoadingState& m_zone_state;
ITechsetCreator* m_techset_creator;
techset::ICreatorIW4* m_techset_creator;
};
class TechsetLoader final : public ITechsetCreator
class TechsetLoader final : public techset::ICreatorIW4
{
public:
TechsetLoader(MemoryManager& memory, ISearchPath& searchPath)
@@ -1280,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<MaterialTechniqueSet>();
techset->name = m_memory.Dup(assetName.c_str());
@@ -1309,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<techset::TechsetDefinitionCache>();
auto& definitionCache = context.GetZoneAssetCreationState<TechsetDefinitionCache>();
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<decltype(techniqueTypeNames)>);
const TechsetFileReader reader(*file.m_stream, techsetFileName, techniqueTypeNames, std::extent_v<decltype(techniqueTypeNames)>);
auto techsetDefinition = reader.ReadTechsetDefinition();
if (!techsetDefinition)
{
@@ -1339,12 +1341,12 @@ namespace
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);
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;
@@ -1367,25 +1369,10 @@ namespace
};
} // namespace
namespace IW4
namespace 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<ITechsetCreator> CreateTechsetLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<ICreatorIW4> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<TechsetLoader>(memory, searchPath);
}
} // namespace IW4
} // namespace techset

View File

@@ -10,21 +10,17 @@
#include <memory>
#include <string>
namespace IW4
namespace 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<AssetTechniqueSet>
class ICreatorIW4 : public AssetCreator<IW4::AssetTechniqueSet>
{
public:
ITechsetCreator() = default;
virtual ~ITechsetCreator() = default;
ICreatorIW4() = default;
virtual ~ICreatorIW4() = default;
virtual techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context, bool& failure) = 0;
virtual 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<ITechsetCreator> CreateTechsetLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<ICreatorIW4> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace techset

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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<std::string>& 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<KeyValuePairsCreator>();
}
const std::vector<std::string>& 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<IPakToCreate>(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<key_value_pairs::Creator>();
}
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<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)
{
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

View File

@@ -9,32 +9,35 @@
#include <string>
#include <unordered_map>
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<std::string>& GetImageNames() const;
void AddImage(std::string imageName);
void Build(ISearchPath& searchPath, IOutputPath& outPath);
[[nodiscard]] const std::vector<std::string>& GetImageNames() const;
private:
std::string m_name;
std::vector<std::string> m_image_names;
};
private:
std::string m_name;
std::vector<std::string> 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<std::string, IPakToCreate*> m_ipak_lookup;
std::vector<std::unique_ptr<IPakToCreate>> m_ipaks;
};
private:
key_value_pairs::Creator* m_kvp_creator;
std::unordered_map<std::string, IPakToCreate*> m_ipak_lookup;
std::vector<std::unique_ptr<IPakToCreate>> m_ipaks;
};
} // namespace image

View File

@@ -4,63 +4,66 @@
#include <algorithm>
AbstractImageIPakPostProcessor::AbstractImageIPakPostProcessor(const ZoneDefinitionContext& zoneDefinition,
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)
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<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)
{
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

View File

@@ -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<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)
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<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 "Image/ImageCommon.h"
#include "Iwd/IwdCreator.h"
#include <algorithm>
#include <format>
AbstractImageIwdPostProcessor::AbstractImageIwdPostProcessor(const ZoneDefinitionContext& zoneDefinition,
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)
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<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)
{
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

View File

@@ -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<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)
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<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 <ranges>
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<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 (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<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())
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<CommonKeyValuePair> KeyValuePairsCreator::GetFinalKeyValuePairs()
{
return std::move(m_key_value_pairs);
}
std::vector<CommonKeyValuePair> Creator::GetFinalKeyValuePairs()
{
return std::move(m_key_value_pairs);
}
} // namespace key_value_pairs

View File

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

View File

@@ -52,14 +52,15 @@ public:
static_assert(std::is_base_of_v<IZoneAssetCreationState, T>, "T must inherit IZoneAssetCreationState");
// T must also have a public default constructor
const auto foundEntry = m_zone_asset_creation_states.find(typeid(T));
std::type_index typeId = typeid(T);
const auto foundEntry = m_zone_asset_creation_states.find(typeId);
if (foundEntry != m_zone_asset_creation_states.end())
return *dynamic_cast<T*>(foundEntry->second.get());
auto newState = std::make_unique<T>();
newState->Inject(m_injection);
auto* newStatePtr = newState.get();
m_zone_asset_creation_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetCreationState>>(typeid(T), std::move(newState)));
m_zone_asset_creation_states.emplace(std::move(typeId), std::move(newState));
return *newStatePtr;
}

View File

@@ -122,10 +122,10 @@ namespace
};
} // namespace
namespace IW3
namespace image
{
std::unique_ptr<AssetCreator<AssetImage>> CreateImageLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetImage>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<ImageLoader>(memory, searchPath);
}
} // namespace IW3
} // namespace image

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW3
namespace image
{
std::unique_ptr<AssetCreator<AssetImage>> CreateImageLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW3
std::unique_ptr<AssetCreator<IW3::AssetImage>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath);
} // namespace image

View File

@@ -36,10 +36,10 @@ namespace
};
} // namespace
namespace IW3
namespace localize
{
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<LocalizeLoader>(memory, searchPath, zone);
}
} // namespace IW3
} // namespace localize

View File

@@ -8,7 +8,7 @@
#include <memory>
namespace IW3
namespace localize
{
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace IW3
std::unique_ptr<AssetCreator<IW3::AssetLocalize>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace localize

View File

@@ -45,10 +45,10 @@ namespace
};
} // namespace
namespace IW3
namespace material
{
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetMaterial>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<MaterialLoader>(memory, searchPath);
}
} // namespace IW3
} // namespace material

View File

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

View File

@@ -3,6 +3,7 @@
#include "Asset/GlobalAssetPoolsLoader.h"
#include "Game/IW3/GameIW3.h"
#include "Game/IW3/IW3.h"
#include "Game/IW3/XModel/LoaderXModelIW3.h"
#include "Image/AssetLoaderImageIW3.h"
#include "Localize/AssetLoaderLocalizeIW3.h"
#include "Material/LoaderMaterialIW3.h"
@@ -90,10 +91,10 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModel>(memory));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
collection.AddAssetCreator(xmodel::CreateLoaderIW3(memory, searchPath, zone));
collection.AddAssetCreator(material::CreateLoaderIW3(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
collection.AddAssetCreator(CreateImageLoader(memory, searchPath));
collection.AddAssetCreator(image::CreateLoaderIW3(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundCurve>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderLoadedSound>(memory));
@@ -107,13 +108,13 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderFont>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenuList>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenu>(memory));
collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone));
collection.AddAssetCreator(localize::CreateLoaderIW3(memory, searchPath, zone));
// collection.AddAssetCreator(std::make_unique<AssetLoaderWeapon>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundDriverGlobals>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderFx>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderImpactFx>(memory));
collection.AddAssetCreator(CreateRawFileLoader(memory, searchPath));
collection.AddAssetCreator(CreateStringTableLoader(memory, searchPath));
collection.AddAssetCreator(raw_file::CreateLoaderIW3(memory, searchPath));
collection.AddAssetCreator(string_table::CreateLoaderIW3(memory, searchPath));
}
} // namespace

View File

@@ -44,10 +44,10 @@ namespace
};
} // namespace
namespace IW3
namespace raw_file
{
std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetRawFile>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<RawFileLoader>(memory, searchPath);
}
} // namespace IW3
} // namespace raw_file

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW3
namespace raw_file
{
std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW3
std::unique_ptr<AssetCreator<IW3::AssetRawFile>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath);
} // namespace raw_file

View File

@@ -38,10 +38,10 @@ namespace
};
} // namespace
namespace IW3
namespace string_table
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetStringTable>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<StringTableLoader>(memory, searchPath);
}
} // namespace IW3
} // namespace string_table

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW3
namespace string_table
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW3
std::unique_ptr<AssetCreator<IW3::AssetStringTable>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath);
} // namespace string_table

View File

@@ -1,114 +0,0 @@
#include "JsonLeaderboardDefLoader.h"
#include "Game/IW4/CommonIW4.h"
#include "Game/IW4/Leaderboard/JsonLeaderboardDef.h"
#include <format>
#include <iostream>
#include <nlohmann/json.hpp>
using namespace nlohmann;
using namespace IW4;
namespace
{
class JsonLoader
{
public:
JsonLoader(std::istream& stream, MemoryManager& memory)
: m_stream(stream),
m_memory(memory)
{
}
bool Load(LeaderboardDef& leaderboardDef) const
{
try
{
const auto jRoot = json::parse(m_stream);
std::string type;
unsigned version;
jRoot.at("_type").get_to(type);
jRoot.at("_version").get_to(version);
if (type != "leaderboard" || version != 1u)
{
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
return false;
}
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
}
catch (const json::exception& e)
{
std::cerr << std::format("Failed to parse json of leaderboard: {}\n", e.what());
}
return false;
}
private:
bool CreateColumnDefFromJson(const JsonColumnDef& jColumn, LbColumnDef& lbColumnDef, LeaderboardDef& leaderboardDef) const
{
lbColumnDef.name = m_memory.Dup(jColumn.name.c_str());
lbColumnDef.id = jColumn.colId;
lbColumnDef.propertyId = jColumn.propertyId.value_or(0);
lbColumnDef.hidden = jColumn.hidden.value_or(false);
if (jColumn.statName)
lbColumnDef.statName = m_memory.Dup(jColumn.statName->c_str());
else
lbColumnDef.statName = nullptr;
lbColumnDef.type = jColumn.type;
lbColumnDef.precision = jColumn.precision.value_or(0);
lbColumnDef.agg = jColumn.aggregationFunction;
return true;
}
bool CreateLeaderboardFromJson(const JsonLeaderboardDef& jLeaderboardDef, LeaderboardDef& leaderboardDef) const
{
leaderboardDef.id = jLeaderboardDef.id;
leaderboardDef.xpColId = jLeaderboardDef.xpColId.value_or(-1);
leaderboardDef.prestigeColId = jLeaderboardDef.prestigeColId.value_or(-1);
if (!jLeaderboardDef.columns.empty())
{
leaderboardDef.columnCount = static_cast<int>(jLeaderboardDef.columns.size());
leaderboardDef.columns = m_memory.Alloc<LbColumnDef>(leaderboardDef.columnCount);
for (auto i = 0; i < leaderboardDef.columnCount; i++)
{
if (!CreateColumnDefFromJson(jLeaderboardDef.columns[i], leaderboardDef.columns[i], leaderboardDef))
return false;
}
}
else
{
leaderboardDef.columnCount = 0;
leaderboardDef.columns = nullptr;
}
return true;
}
std::istream& m_stream;
MemoryManager& m_memory;
};
} // namespace
namespace IW4
{
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory)
{
const JsonLoader loader(stream, *memory);
return loader.Load(leaderboard);
}
} // namespace IW4

View File

@@ -1,11 +0,0 @@
#pragma once
#include "Game/IW4/IW4.h"
#include "Utils/MemoryManager.h"
#include <istream>
namespace IW4
{
bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory);
} // namespace IW4

View File

@@ -1,16 +1,109 @@
#include "LoaderLeaderboardIW4.h"
#include "Game/IW4/IW4.h"
#include "JsonLeaderboardDefLoader.h"
#include "Game/IW4/Leaderboard/JsonLeaderboardDef.h"
#include "Leaderboard/LeaderboardCommon.h"
#include <cstring>
#include <format>
#include <iostream>
#include <nlohmann/json.hpp>
using namespace nlohmann;
using namespace IW4;
namespace
{
class JsonLoader
{
public:
JsonLoader(std::istream& stream, MemoryManager& memory)
: m_stream(stream),
m_memory(memory)
{
}
bool Load(LeaderboardDef& leaderboardDef) const
{
try
{
const auto jRoot = json::parse(m_stream);
std::string type;
unsigned version;
jRoot.at("_type").get_to(type);
jRoot.at("_version").get_to(version);
if (type != "leaderboard" || version != 1u)
{
std::cerr << std::format("Tried to load leaderboard \"{}\" but did not find expected type leaderboard of version 1\n", leaderboardDef.name);
return false;
}
const auto jLeaderboard = jRoot.get<JsonLeaderboardDef>();
return CreateLeaderboardFromJson(jLeaderboard, leaderboardDef);
}
catch (const json::exception& e)
{
std::cerr << std::format("Failed to parse json of leaderboard: {}\n", e.what());
}
return false;
}
private:
bool CreateColumnDefFromJson(const JsonColumnDef& jColumn, LbColumnDef& lbColumnDef, LeaderboardDef& leaderboardDef) const
{
lbColumnDef.name = m_memory.Dup(jColumn.name.c_str());
lbColumnDef.id = jColumn.colId;
lbColumnDef.propertyId = jColumn.propertyId.value_or(0);
lbColumnDef.hidden = jColumn.hidden.value_or(false);
if (jColumn.statName)
lbColumnDef.statName = m_memory.Dup(jColumn.statName->c_str());
else
lbColumnDef.statName = nullptr;
lbColumnDef.type = jColumn.type;
lbColumnDef.precision = jColumn.precision.value_or(0);
lbColumnDef.agg = jColumn.aggregationFunction;
return true;
}
bool CreateLeaderboardFromJson(const JsonLeaderboardDef& jLeaderboardDef, LeaderboardDef& leaderboardDef) const
{
leaderboardDef.id = jLeaderboardDef.id;
leaderboardDef.xpColId = jLeaderboardDef.xpColId.value_or(-1);
leaderboardDef.prestigeColId = jLeaderboardDef.prestigeColId.value_or(-1);
if (!jLeaderboardDef.columns.empty())
{
leaderboardDef.columnCount = static_cast<int>(jLeaderboardDef.columns.size());
leaderboardDef.columns = m_memory.Alloc<LbColumnDef>(leaderboardDef.columnCount);
for (auto i = 0; i < leaderboardDef.columnCount; i++)
{
if (!CreateColumnDefFromJson(jLeaderboardDef.columns[i], leaderboardDef.columns[i], leaderboardDef))
return false;
}
}
else
{
leaderboardDef.columnCount = 0;
leaderboardDef.columns = nullptr;
}
return true;
}
std::istream& m_stream;
MemoryManager& m_memory;
};
class LeaderboardLoader final : public AssetCreator<AssetLeaderboard>
{
public:
@@ -22,14 +115,15 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(std::format("leaderboards/{}.json", assetName));
const auto file = m_search_path.Open(leaderboard::GetJsonFileNameForAsset(assetName));
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* leaderboardDef = m_memory.Alloc<LeaderboardDef>();
leaderboardDef->name = m_memory.Dup(assetName.c_str());
if (!LoadLeaderboardAsJson(*file.m_stream, *leaderboardDef, &m_memory))
const JsonLoader loader(*file.m_stream, m_memory);
if (!loader.Load(*leaderboardDef))
{
std::cerr << std::format("Failed to load leaderboard \"{}\"\n", assetName);
return AssetCreationResult::Failure();
@@ -44,10 +138,10 @@ namespace
};
} // namespace
namespace IW4
namespace leaderboard
{
std::unique_ptr<AssetCreator<AssetLeaderboard>> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetLeaderboard>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LeaderboardLoader>(memory, searchPath);
}
} // namespace IW4
} // namespace leaderboard

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW4
namespace leaderboard
{
std::unique_ptr<AssetCreator<AssetLeaderboard>> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetLeaderboard>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace leaderboard

View File

@@ -1,6 +1,7 @@
#include "LoaderLightDefIW4.h"
#include "LightDefLoaderIW4.h"
#include "Game/IW4/IW4.h"
#include "LightDef/LightDefCommon.h"
#include <cstring>
#include <format>
@@ -23,7 +24,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto filename = GetAssetFilename(assetName);
const auto filename = light_def::GetFileNameForAsset(assetName);
const auto file = m_search_path.Open(filename);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -61,20 +62,15 @@ namespace
}
private:
std::string GetAssetFilename(const std::string& assetName)
{
return std::format("lights/{}", assetName);
}
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace IW4
namespace light_def
{
std::unique_ptr<AssetCreator<AssetLightDef>> CreateLightDefLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetLightDef>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LoaderLightDef>(memory, searchPath);
}
} // namespace IW4
} // namespace light_def

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW4
namespace light_def
{
std::unique_ptr<AssetCreator<AssetLightDef>> CreateLightDefLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetLightDef>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace light_def

View File

@@ -35,10 +35,10 @@ namespace
};
} // namespace
namespace IW4
namespace localize
{
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<LocalizeLoader>(memory, searchPath, zone);
}
} // namespace IW4
} // namespace localize

View File

@@ -8,7 +8,7 @@
#include <memory>
namespace IW4
namespace localize
{
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetLocalize>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace localize

View File

@@ -45,10 +45,10 @@ namespace
};
} // namespace
namespace IW4
namespace material
{
std::unique_ptr<AssetCreator<AssetMaterial>> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetMaterial>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<MaterialLoader>(memory, searchPath);
}
} // namespace IW4
} // namespace material

View File

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

View File

@@ -212,10 +212,10 @@ namespace
};
} // namespace
namespace IW4
namespace menu
{
std::unique_ptr<AssetCreator<AssetMenuList>> CreateMenuListLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetMenuList>> CreateMenuListLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<MenuListLoader>(memory, searchPath);
}
} // namespace IW4
} // namespace menu

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW4
namespace menu
{
std::unique_ptr<AssetCreator<AssetMenuList>> CreateMenuListLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetMenuList>> CreateMenuListLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace menu

View File

@@ -5,7 +5,7 @@
#include "Game/IW4/IW4.h"
#include "Game/IW4/XModel/LoaderXModelIW4.h"
#include "Leaderboard/LoaderLeaderboardIW4.h"
#include "LightDef/LoaderLightDefIW4.h"
#include "LightDef/LightDefLoaderIW4.h"
#include "Localize/LoaderLocalizeIW4.h"
#include "Material/LoaderMaterialIW4.h"
#include "Menu/LoaderMenuListIW4.h"
@@ -119,19 +119,19 @@ namespace
{
auto& memory = zone.Memory();
collection.AddAssetCreator(std::make_unique<RawLoaderPhysPreset>(memory, searchPath, zone));
collection.AddAssetCreator(std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone));
collection.AddAssetCreator(phys_preset::CreateRawLoaderIW4(memory, searchPath, zone));
collection.AddAssetCreator(phys_preset::CreateGdtLoaderIW4(memory, gdt, zone));
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysCollMap>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModelSurfs>(memory));
collection.AddAssetCreator(CreateXModelLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath));
collection.AddAssetCreator(CreatePixelShaderLoader(memory, searchPath));
collection.AddAssetCreator(CreateVertexShaderLoader(memory, searchPath));
collection.AddAssetCreator(xmodel::CreateLoaderIW4(memory, searchPath, zone));
collection.AddAssetCreator(material::CreateLoaderIW4(memory, searchPath));
collection.AddAssetCreator(shader::CreatePixelShaderLoaderIW4(memory, searchPath));
collection.AddAssetCreator(shader::CreateVertexShaderLoaderIW4(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechset>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderImage>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
collection.AddAssetCreator(CreateSoundCurveLoader(memory, searchPath));
collection.AddAssetCreator(sound_curve::CreateLoaderIW4(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderLoadedSound>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderClipMap>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderComWorld>(memory));
@@ -140,19 +140,19 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderMapEnts>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderFxWorld>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderGfxWorld>(memory));
collection.AddAssetCreator(CreateLightDefLoader(memory, searchPath));
collection.AddAssetCreator(light_def::CreateLoaderIW4(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderFont>(memory));
collection.AddAssetCreator(CreateMenuListLoader(memory, searchPath));
collection.AddAssetCreator(menu::CreateMenuListLoaderIW4(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenu>(memory));
collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateRawWeaponLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateGdtWeaponLoader(memory, searchPath, gdt, zone));
collection.AddAssetCreator(localize::CreateLoaderIW4(memory, searchPath, zone));
collection.AddAssetCreator(weapon::CreateRawLoaderIW4(memory, searchPath, zone));
collection.AddAssetCreator(weapon::CreateGdtLoaderIW4(memory, searchPath, gdt, zone));
// collection.AddAssetCreator(std::make_unique<AssetLoaderFx>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderImpactFx>(memory));
collection.AddAssetCreator(CreateRawFileLoader(memory, searchPath));
collection.AddAssetCreator(CreateStringTableLoader(memory, searchPath));
collection.AddAssetCreator(CreateLeaderboardLoader(memory, searchPath));
collection.AddAssetCreator(CreateStructuredDataDefLoader(memory, searchPath));
collection.AddAssetCreator(raw_file::CreateLoaderIW4(memory, searchPath));
collection.AddAssetCreator(string_table::CreateLoaderIW4(memory, searchPath));
collection.AddAssetCreator(leaderboard::CreateLoaderIW4(memory, searchPath));
collection.AddAssetCreator(structured_data_def::CreateLoaderIW4(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTracer>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderVehicle>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderAddonMapEnts>(memory));

View File

@@ -10,26 +10,43 @@
using namespace IW4;
GdtLoaderPhysPreset::GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
: m_memory(memory),
m_gdt(gdt),
m_zone(zone)
namespace
{
}
AssetCreationResult GdtLoaderPhysPreset::CreateAsset(const std::string& assetName, AssetCreationContext& context)
{
auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_PRESET, assetName);
if (gdtEntry == nullptr)
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromGdtProperties(*gdtEntry))
class GdtLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
{
std::cerr << std::format("Failed to read phys preset gdt entry: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
public:
GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
: m_gdt(gdt),
m_info_string_loader(memory, zone)
{
}
InfoStringLoaderPhysPreset infoStringLoader(m_memory, m_zone);
return infoStringLoader.CreateAsset(assetName, infoString, context);
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_PRESET, assetName);
if (gdtEntry == nullptr)
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cerr << std::format("Failed to read phys preset gdt entry: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return m_info_string_loader.CreateAsset(assetName, infoString, context);
}
private:
IGdtQueryable& m_gdt;
phys_preset::InfoStringLoaderIW4 m_info_string_loader;
};
} // namespace
namespace phys_preset
{
std::unique_ptr<AssetCreator<IW4::AssetPhysPreset>> CreateGdtLoaderIW4(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone);
}
} // namespace phys_preset

View File

@@ -3,20 +3,12 @@
#include "Asset/IAssetCreator.h"
#include "Game/IW4/IW4.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
namespace IW4
#include <memory>
namespace phys_preset
{
class GdtLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
{
public:
GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
private:
MemoryManager& m_memory;
IGdtQueryable& m_gdt;
Zone& m_zone;
};
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetPhysPreset>> CreateGdtLoaderIW4(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone);
} // namespace phys_preset

View File

@@ -58,30 +58,33 @@ namespace
}
} // namespace
InfoStringLoaderPhysPreset::InfoStringLoaderPhysPreset(MemoryManager& memory, Zone& zone)
: m_memory(memory),
m_zone(zone)
namespace phys_preset
{
}
AssetCreationResult InfoStringLoaderPhysPreset::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
PhysPresetInfo presetInfo;
std::memset(&presetInfo, 0, sizeof(presetInfo));
auto* physPreset = m_memory.Alloc<PhysPreset>();
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
InfoStringToPhysPresetConverter converter(
infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
if (!converter.Convert())
InfoStringLoaderIW4::InfoStringLoaderIW4(MemoryManager& memory, Zone& zone)
: m_memory(memory),
m_zone(zone)
{
std::cerr << std::format("Failed to parse phys preset: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CopyFromPhysPresetInfo(presetInfo, *physPreset);
physPreset->name = m_memory.Dup(assetName.c_str());
AssetCreationResult InfoStringLoaderIW4::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
PhysPresetInfo presetInfo;
std::memset(&presetInfo, 0, sizeof(presetInfo));
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
auto* physPreset = m_memory.Alloc<PhysPreset>();
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
InfoStringToPhysPresetConverter converter(
infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse phys preset: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CopyFromPhysPresetInfo(presetInfo, *physPreset);
physPreset->name = m_memory.Dup(assetName.c_str());
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
} // namespace phys_preset

View File

@@ -4,12 +4,12 @@
#include "Asset/AssetCreationResult.h"
#include "InfoString/InfoString.h"
namespace IW4
namespace phys_preset
{
class InfoStringLoaderPhysPreset
class InfoStringLoaderIW4
{
public:
InfoStringLoaderPhysPreset(MemoryManager& memory, Zone& zone);
InfoStringLoaderIW4(MemoryManager& memory, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
@@ -17,4 +17,4 @@ namespace IW4
MemoryManager& m_memory;
Zone& m_zone;
};
} // namespace IW4
} // namespace phys_preset

View File

@@ -4,33 +4,51 @@
#include "Game/IW4/ObjConstantsIW4.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderPhysPresetIW4.h"
#include "PhysPreset/PhysPresetCommon.h"
#include <format>
#include <iostream>
using namespace IW4;
RawLoaderPhysPreset::RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
namespace
{
}
AssetCreationResult RawLoaderPhysPreset::CreateAsset(const std::string& assetName, AssetCreationContext& context)
{
const auto fileName = std::format("physic/{}", assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
class RawLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
{
std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName);
return AssetCreationResult::Failure();
}
public:
RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_search_path(searchPath),
m_info_string_loader(memory, zone)
{
}
InfoStringLoaderPhysPreset infoStringLoader(m_memory, m_zone);
return infoStringLoader.CreateAsset(assetName, infoString, context);
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = phys_preset::GetFileNameForAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
{
std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName);
return AssetCreationResult::Failure();
}
return m_info_string_loader.CreateAsset(assetName, infoString, context);
}
private:
ISearchPath& m_search_path;
phys_preset::InfoStringLoaderIW4 m_info_string_loader;
};
} // namespace
namespace phys_preset
{
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawLoaderIW4(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderPhysPreset>(memory, searchPath, zone);
}
} // namespace phys_preset

View File

@@ -5,18 +5,9 @@
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
namespace IW4
#include <memory>
namespace phys_preset
{
class RawLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
{
public:
RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
Zone& m_zone;
};
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetPhysPreset>> CreateRawLoaderIW4(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace phys_preset

View File

@@ -82,10 +82,10 @@ namespace
};
} // namespace
namespace IW4
namespace raw_file
{
std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetRawFile>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<RawFileLoader>(memory, searchPath);
}
} // namespace IW4
} // namespace raw_file

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW4
namespace raw_file
{
std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetRawFile>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace raw_file

View File

@@ -1,6 +1,7 @@
#include "LoaderPixelShaderIW4.h"
#include "Game/IW4/IW4.h"
#include "Shader/ShaderCommon.h"
#include <cstdint>
#include <format>
@@ -21,7 +22,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = GetPixelShaderFileName(assetName);
const auto fileName = shader::GetFileNameForPixelShaderAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -53,15 +54,10 @@ namespace
};
} // namespace
namespace IW4
namespace shader
{
std::string GetPixelShaderFileName(const std::string& pixelShaderAssetName)
{
return std::format("shader_bin/ps_{}.cso", pixelShaderAssetName);
}
std::unique_ptr<AssetCreator<AssetPixelShader>> CreatePixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetPixelShader>> CreatePixelShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<PixelShaderLoader>(memory, searchPath);
}
} // namespace IW4
} // namespace shader

View File

@@ -7,9 +7,7 @@
#include <memory>
namespace IW4
namespace shader
{
[[nodiscard]] std::string GetPixelShaderFileName(const std::string& pixelShaderAssetName);
std::unique_ptr<AssetCreator<AssetPixelShader>> CreatePixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetPixelShader>> CreatePixelShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace shader

View File

@@ -1,6 +1,7 @@
#include "LoaderVertexShaderIW4.h"
#include "Game/IW4/IW4.h"
#include "Shader/ShaderCommon.h"
#include <cstdint>
#include <format>
@@ -21,7 +22,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = GetVertexShaderFileName(assetName);
const auto fileName = shader::GetFileNameForVertexShaderAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -53,15 +54,10 @@ namespace
};
} // namespace
namespace IW4
namespace shader
{
std::string GetVertexShaderFileName(const std::string& vertexShaderAssetName)
{
return std::format("shader_bin/vs_{}.cso", vertexShaderAssetName);
}
std::unique_ptr<AssetCreator<AssetVertexShader>> CreateVertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetVertexShader>> CreateVertexShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<VertexShaderLoader>(memory, searchPath);
}
} // namespace IW4
} // namespace shader

View File

@@ -7,9 +7,7 @@
#include <memory>
namespace IW4
namespace shader
{
[[nodiscard]] std::string GetVertexShaderFileName(const std::string& vertexShaderAssetName);
std::unique_ptr<AssetCreator<AssetVertexShader>> CreateVertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetVertexShader>> CreateVertexShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace shader

View File

@@ -4,6 +4,7 @@
#include "ObjLoading.h"
#include "Parsing/Graph2D/Graph2DReader.h"
#include "Pool/GlobalAssetPool.h"
#include "Sound/SoundCurveCommon.h"
#include <cstring>
#include <format>
@@ -25,7 +26,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = std::format("soundaliases/{}.vfcurve", assetName);
const auto fileName = sound_curve::GetFileNameForAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -69,10 +70,10 @@ namespace
};
} // namespace
namespace IW4
namespace sound_curve
{
std::unique_ptr<AssetCreator<AssetSoundCurve>> CreateSoundCurveLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetSoundCurve>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LoaderSoundCurve>(memory, searchPath);
}
} // namespace IW4
} // namespace sound_curve

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW4
namespace sound_curve
{
std::unique_ptr<AssetCreator<AssetSoundCurve>> CreateSoundCurveLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetSoundCurve>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace sound_curve

View File

@@ -38,10 +38,10 @@ namespace
};
} // namespace
namespace IW4
namespace string_table
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<AssetCreator<AssetStringTable>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LoaderStringTable>(memory, searchPath);
}
} // namespace IW4
} // namespace string_table

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace IW4
namespace string_table
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4
std::unique_ptr<AssetCreator<IW4::AssetStringTable>> CreateLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace string_table

Some files were not shown because too many files have changed in this diff Show More