diff --git a/src/ObjCommon/Sound/SoundCurveCommon.cpp b/src/ObjCommon/Sound/SoundCurveCommon.cpp new file mode 100644 index 00000000..461a3f08 --- /dev/null +++ b/src/ObjCommon/Sound/SoundCurveCommon.cpp @@ -0,0 +1,11 @@ +#include "SoundCurveCommon.h" + +#include + +namespace sound_curve +{ + std::string GetFileNameForAssetName(const std::string& assetName) + { + return std::format("soundaliases/{}.vfcurve", assetName); + } +} // namespace sound_curve diff --git a/src/ObjCommon/Sound/SoundCurveCommon.h b/src/ObjCommon/Sound/SoundCurveCommon.h new file mode 100644 index 00000000..8ac96a84 --- /dev/null +++ b/src/ObjCommon/Sound/SoundCurveCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace sound_curve +{ + std::string GetFileNameForAssetName(const std::string& assetName); +} diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp index bb53a3d5..321d3297 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp @@ -5,6 +5,7 @@ #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" @@ -460,7 +461,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 +497,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 { diff --git a/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.cpp b/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.cpp deleted file mode 100644 index 35c64c27..00000000 --- a/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "JsonLeaderboardDefLoader.h" - -#include "Game/IW4/CommonIW4.h" -#include "Game/IW4/Leaderboard/JsonLeaderboardDef.h" - -#include -#include -#include - -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(); - 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(jLeaderboardDef.columns.size()); - leaderboardDef.columns = m_memory.Alloc(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 diff --git a/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.h b/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.h deleted file mode 100644 index 22f85756..00000000 --- a/src/ObjLoading/Game/IW4/Leaderboard/JsonLeaderboardDefLoader.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "Game/IW4/IW4.h" -#include "Utils/MemoryManager.h" - -#include - -namespace IW4 -{ - bool LoadLeaderboardAsJson(std::istream& stream, LeaderboardDef& leaderboard, MemoryManager* memory); -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp index 60f4418e..3a8b7b12 100644 --- a/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp +++ b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp @@ -1,17 +1,110 @@ #include "LoaderLeaderboardIW4.h" #include "Game/IW4/IW4.h" -#include "JsonLeaderboardDefLoader.h" +#include "Game/IW4/Leaderboard/JsonLeaderboardDef.h" #include "Leaderboard/LeaderboardCommon.h" #include #include #include +#include +using namespace nlohmann; using namespace IW4; +using namespace ::leaderboard; 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(); + 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(jLeaderboardDef.columns.size()); + leaderboardDef.columns = m_memory.Alloc(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 { public: @@ -23,14 +116,15 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto file = m_search_path.Open(leaderboard::GetJsonFileNameForAsset(assetName)); + const auto file = m_search_path.Open(GetJsonFileNameForAsset(assetName)); if (!file.IsOpen()) return AssetCreationResult::NoAction(); auto* leaderboardDef = m_memory.Alloc(); 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(); @@ -45,10 +139,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::leaderboard { - std::unique_ptr> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::leaderboard diff --git a/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h index 3f0a86ce..832d6b94 100644 --- a/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h +++ b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::leaderboard { - std::unique_ptr> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::leaderboard diff --git a/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.cpp b/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.cpp index 8c610411..dacdf3d1 100644 --- a/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.cpp @@ -68,10 +68,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::light_def { - std::unique_ptr> CreateLightDefLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::light_def diff --git a/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.h b/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.h index 92eec1bb..96d93357 100644 --- a/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.h +++ b/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::light_def { - std::unique_ptr> CreateLightDefLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::light_def diff --git a/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp index 795939ed..a7dc2c42 100644 --- a/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp +++ b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp @@ -35,10 +35,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::localize { - std::unique_ptr> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) { return std::make_unique(memory, searchPath, zone); } -} // namespace IW4 +} // namespace IW4::localize diff --git a/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h index c7ae0d9d..032e02d6 100644 --- a/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h +++ b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h @@ -8,7 +8,7 @@ #include -namespace IW4 +namespace IW4::localize { - std::unique_ptr> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace IW4::localize diff --git a/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.cpp b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.cpp index be3bf8b0..5a37af7d 100644 --- a/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.cpp +++ b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.cpp @@ -8,6 +8,7 @@ #include using namespace IW4; +using namespace ::material; namespace { @@ -22,7 +23,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto file = m_search_path.Open(material::GetFileNameForAssetName(assetName)); + const auto file = m_search_path.Open(GetFileNameForAssetName(assetName)); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -45,10 +46,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::material { - std::unique_ptr> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::material diff --git a/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h index efd0a610..8f634c0c 100644 --- a/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h +++ b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h @@ -6,7 +6,7 @@ #include "SearchPath/ISearchPath.h" #include "Utils/MemoryManager.h" -namespace IW4 +namespace IW4::material { - std::unique_ptr> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::material diff --git a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp index 52e00c74..e6e8843f 100644 --- a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp +++ b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp @@ -11,6 +11,7 @@ #include using namespace IW4; +using namespace ::menu; namespace { @@ -28,7 +29,7 @@ namespace std::vector menus; AssetRegistration registration(assetName); - auto& zoneState = context.GetZoneAssetCreationState(); + auto& zoneState = context.GetZoneAssetCreationState(); auto& conversionState = context.GetZoneAssetCreationState(); std::deque menuLoadQueue; @@ -80,7 +81,7 @@ namespace private: bool LoadMenuFileFromQueue(const std::string& menuFilePath, AssetCreationContext& context, - menu::MenuAssetZoneState& zoneState, + MenuAssetZoneState& zoneState, MenuConversionZoneState& conversionState, std::vector& menus, AssetRegistration& registration) const @@ -121,8 +122,8 @@ namespace bool ProcessParsedResults(const std::string& fileName, AssetCreationContext& context, - menu::ParsingResult& parsingResult, - menu::MenuAssetZoneState& zoneState, + ParsingResult& parsingResult, + MenuAssetZoneState& zoneState, MenuConversionZoneState& conversionState, std::vector& menus, AssetRegistration& registration) const @@ -196,10 +197,9 @@ namespace menuList.menus = nullptr; } - std::unique_ptr - ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState& zoneState) const + std::unique_ptr ParseMenuFile(std::istream& stream, const std::string& menuFileName, const MenuAssetZoneState& zoneState) const { - menu::MenuFileReader reader(stream, menuFileName, menu::FeatureLevel::IW4, m_search_path); + MenuFileReader reader(stream, menuFileName, FeatureLevel::IW4, m_search_path); reader.IncludeZoneState(zoneState); reader.SetPermissiveMode(ObjLoading::Configuration.MenuPermissiveParsing); @@ -212,10 +212,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::menu { std::unique_ptr> CreateMenuListLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::menu diff --git a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h index 6a1d0499..2cb21bb3 100644 --- a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h +++ b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::menu { std::unique_ptr> CreateMenuListLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 +} // namespace IW4::menu diff --git a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h index 234cedb5..8b32e98b 100644 --- a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h +++ b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h @@ -14,7 +14,7 @@ namespace IW4 IMenuConverter() = default; virtual ~IMenuConverter() = default; - virtual void ConvertMenu(const menu::CommonMenuDef& commonMenu, menuDef_t& menu, AssetRegistration& registration) = 0; + virtual void ConvertMenu(const ::menu::CommonMenuDef& commonMenu, menuDef_t& menu, AssetRegistration& registration) = 0; static std::unique_ptr Create(bool disableOptimizations, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context); }; diff --git a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp index 118861ab..7e0811f6 100644 --- a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp @@ -119,19 +119,19 @@ namespace { auto& memory = zone.Memory(); - collection.AddAssetCreator(std::make_unique(memory, searchPath, zone)); - collection.AddAssetCreator(std::make_unique(memory, gdt, zone)); + collection.AddAssetCreator(phys_preset::CreateRawLoader(memory, searchPath, zone)); + collection.AddAssetCreator(phys_preset::CreateGdtLoader(memory, gdt, zone)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); collection.AddAssetCreator(xmodel::CreateXModelLoader(memory, searchPath, zone)); - collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath)); - collection.AddAssetCreator(CreatePixelShaderLoader(memory, searchPath)); - collection.AddAssetCreator(CreateVertexShaderLoader(memory, searchPath)); + collection.AddAssetCreator(material::CreateLoader(memory, searchPath)); + collection.AddAssetCreator(shader::CreatePixelShaderLoader(memory, searchPath)); + collection.AddAssetCreator(shader::CreateVertexShaderLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - collection.AddAssetCreator(CreateSoundCurveLoader(memory, searchPath)); + collection.AddAssetCreator(sound_curve::CreateLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); @@ -140,19 +140,19 @@ namespace // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - collection.AddAssetCreator(CreateLightDefLoader(memory, searchPath)); + collection.AddAssetCreator(light_def::CreateLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); - collection.AddAssetCreator(CreateMenuListLoader(memory, searchPath)); + collection.AddAssetCreator(menu::CreateMenuListLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); - collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone)); - collection.AddAssetCreator(CreateRawWeaponLoader(memory, searchPath, zone)); - collection.AddAssetCreator(CreateGdtWeaponLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(localize::CreateLoader(memory, searchPath, zone)); + collection.AddAssetCreator(weapon::CreateRawLoader(memory, searchPath, zone)); + collection.AddAssetCreator(weapon::CreateGdtLoader(memory, searchPath, gdt, zone)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(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::CreateLoader(memory, searchPath)); + collection.AddAssetCreator(string_table::CreateLoader(memory, searchPath)); + collection.AddAssetCreator(leaderboard::CreateLoader(memory, searchPath)); + collection.AddAssetCreator(structured_data_def::CreateLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); diff --git a/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp index afd65d70..4532e91e 100644 --- a/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp +++ b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp @@ -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 { - 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; + IW4::phys_preset::InfoStringLoader m_info_string_loader; + }; +} // namespace + +namespace IW4::phys_preset +{ + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone) + { + return std::make_unique(memory, gdt, zone); + } +} // namespace IW4::phys_preset diff --git a/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h index 59b65bc1..c51f29db 100644 --- a/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h +++ b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h @@ -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 + +namespace IW4::phys_preset { - class GdtLoaderPhysPreset final : public AssetCreator - { - 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> CreateGdtLoader(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone); +} // namespace IW4::phys_preset diff --git a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp index 25c8cc89..dc83cca1 100644 --- a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp +++ b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp @@ -58,30 +58,33 @@ namespace } } // namespace -InfoStringLoaderPhysPreset::InfoStringLoaderPhysPreset(MemoryManager& memory, Zone& zone) - : m_memory(memory), - m_zone(zone) +namespace IW4::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(); - AssetRegistration registration(assetName, physPreset); - - InfoStringToPhysPresetConverter converter( - infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v); - if (!converter.Convert()) + InfoStringLoader::InfoStringLoader(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 InfoStringLoader::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(); + AssetRegistration registration(assetName, physPreset); + + InfoStringToPhysPresetConverter converter( + infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v); + 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 IW4::phys_preset diff --git a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h index 0ca1cede..c864ca3e 100644 --- a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h +++ b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h @@ -4,12 +4,12 @@ #include "Asset/AssetCreationResult.h" #include "InfoString/InfoString.h" -namespace IW4 +namespace IW4::phys_preset { - class InfoStringLoaderPhysPreset + class InfoStringLoader { public: - InfoStringLoaderPhysPreset(MemoryManager& memory, Zone& zone); + InfoStringLoader(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 IW4::phys_preset diff --git a/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp index 11bd6813..aa9b88a5 100644 --- a/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp +++ b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp @@ -10,28 +10,46 @@ #include using namespace IW4; +using namespace ::phys_preset; -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 = 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)) + class RawLoaderPhysPreset final : public AssetCreator { - 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 = 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; + IW4::phys_preset::InfoStringLoader m_info_string_loader; + }; +} // namespace + +namespace IW4::phys_preset +{ + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace IW4::phys_preset diff --git a/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h index 1c3dd841..a711c13c 100644 --- a/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h +++ b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h @@ -5,18 +5,9 @@ #include "SearchPath/ISearchPath.h" #include "Utils/MemoryManager.h" -namespace IW4 +#include + +namespace IW4::phys_preset { - class RawLoaderPhysPreset final : public AssetCreator - { - 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> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace IW4::phys_preset diff --git a/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp index 5d708aa9..381d7b16 100644 --- a/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp +++ b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp @@ -82,10 +82,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::raw_file { - std::unique_ptr> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::raw_file diff --git a/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h index e8163342..1d483736 100644 --- a/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h +++ b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::raw_file { - std::unique_ptr> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::raw_file diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp index 670e6879..6e13a9e0 100644 --- a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp @@ -1,12 +1,14 @@ #include "LoaderPixelShaderIW4.h" #include "Game/IW4/IW4.h" +#include "Shader/ShaderCommon.h" #include #include #include using namespace IW4; +using namespace ::shader; namespace { @@ -21,7 +23,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = GetPixelShaderFileName(assetName); + const auto fileName = GetFileNameForPixelShaderAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -53,15 +55,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::shader { - std::string GetPixelShaderFileName(const std::string& pixelShaderAssetName) - { - return std::format("shader_bin/ps_{}.cso", pixelShaderAssetName); - } - std::unique_ptr> CreatePixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::shader diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h index d29d29ba..3ea15f98 100644 --- a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h +++ b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h @@ -7,9 +7,7 @@ #include -namespace IW4 +namespace IW4::shader { - [[nodiscard]] std::string GetPixelShaderFileName(const std::string& pixelShaderAssetName); - std::unique_ptr> CreatePixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 +} // namespace IW4::shader diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp index 6c1dd5bb..b47069f0 100644 --- a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp @@ -1,12 +1,14 @@ #include "LoaderVertexShaderIW4.h" #include "Game/IW4/IW4.h" +#include "Shader/ShaderCommon.h" #include #include #include using namespace IW4; +using namespace ::shader; namespace { @@ -21,7 +23,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = GetVertexShaderFileName(assetName); + const auto fileName = GetFileNameForVertexShaderAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -53,15 +55,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::shader { - std::string GetVertexShaderFileName(const std::string& vertexShaderAssetName) - { - return std::format("shader_bin/vs_{}.cso", vertexShaderAssetName); - } - std::unique_ptr> CreateVertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::shader diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h index e8139af0..7cc7e600 100644 --- a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h +++ b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h @@ -7,9 +7,7 @@ #include -namespace IW4 +namespace IW4::shader { - [[nodiscard]] std::string GetVertexShaderFileName(const std::string& vertexShaderAssetName); - std::unique_ptr> CreateVertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 +} // namespace IW4::shader diff --git a/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp index 5f760754..84a88655 100644 --- a/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp +++ b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp @@ -4,6 +4,7 @@ #include "ObjLoading.h" #include "Parsing/Graph2D/Graph2DReader.h" #include "Pool/GlobalAssetPool.h" +#include "Sound/SoundCurveCommon.h" #include #include @@ -11,6 +12,7 @@ #include using namespace IW4; +using namespace ::sound_curve; namespace { @@ -25,7 +27,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = std::format("soundaliases/{}.vfcurve", assetName); + const auto fileName = GetFileNameForAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -69,10 +71,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::sound_curve { - std::unique_ptr> CreateSoundCurveLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::sound_curve diff --git a/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h index 19f1bb3c..808cc0e1 100644 --- a/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h +++ b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::sound_curve { - std::unique_ptr> CreateSoundCurveLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::sound_curve diff --git a/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp index d4530772..d19d32d1 100644 --- a/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp +++ b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp @@ -6,6 +6,7 @@ #include "StringTable/StringTableLoader.h" using namespace IW4; +using namespace ::string_table; namespace { @@ -24,7 +25,7 @@ namespace if (!file.IsOpen()) return AssetCreationResult::NoAction(); - string_table::StringTableLoaderV2 loader; + StringTableLoaderV2 loader; auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream); if (!stringTable) return AssetCreationResult::Failure(); @@ -38,10 +39,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::string_table { - std::unique_ptr> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::string_table diff --git a/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h index c9cbd55f..5bba65f4 100644 --- a/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h +++ b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::string_table { - std::unique_ptr> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::string_table diff --git a/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp index 6f662ab2..8dad6ce2 100644 --- a/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp +++ b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp @@ -207,10 +207,10 @@ namespace }; } // namespace -namespace IW4 +namespace IW4::structured_data_def { - std::unique_ptr> CreateStructuredDataDefLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace IW4 +} // namespace IW4::structured_data_def diff --git a/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h index 22d40f09..c3670e25 100644 --- a/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h +++ b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::structured_data_def { - std::unique_ptr> CreateStructuredDataDefLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace IW4 + std::unique_ptr> CreateLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4::structured_data_def diff --git a/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.cpp b/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.cpp index 9b585add..ecd7f59a 100644 --- a/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.cpp +++ b/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.cpp @@ -40,14 +40,14 @@ namespace private: IGdtQueryable& m_gdt; - InfoStringLoaderWeapon m_info_string_loader; + IW4::weapon::InfoStringLoader m_info_string_loader; }; } // namespace -namespace IW4 +namespace IW4::weapon { - std::unique_ptr> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) { return std::make_unique(memory, searchPath, gdt, zone); } -} // namespace IW4 +} // namespace IW4::weapon diff --git a/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.h b/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.h index 44a699b8..ce66f584 100644 --- a/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.h +++ b/src/ObjLoading/Game/IW4/Weapon/GdtLoaderWeaponIW4.h @@ -8,7 +8,7 @@ #include -namespace IW4 +namespace IW4::weapon { - std::unique_ptr> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); -} // namespace IW4 + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace IW4::weapon diff --git a/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.cpp b/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.cpp index e44ef3c2..bd38e04a 100644 --- a/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.cpp +++ b/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.cpp @@ -426,33 +426,36 @@ namespace } } // namespace -InfoStringLoaderWeapon::InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) - : m_memory(memory), - m_search_path(searchPath), - m_zone(zone) +namespace IW4::weapon { -} - -AssetCreationResult InfoStringLoaderWeapon::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) -{ - auto* weaponFullDef = m_memory.Alloc(); - - InitWeaponFullDef(*weaponFullDef); - weaponFullDef->weapCompleteDef.szInternalName = m_memory.Dup(assetName.c_str()); - - AssetRegistration registration(assetName, &weaponFullDef->weapCompleteDef); - - InfoStringToWeaponConverter converter( - infoString, *weaponFullDef, m_zone.m_script_strings, m_memory, context, registration, weapon_fields, std::extent_v); - if (!converter.Convert()) + InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) { - std::cerr << std::format("Failed to parse weapon: \"{}\"\n", assetName); - return AssetCreationResult::Failure(); } - CalculateWeaponFields(*weaponFullDef, m_memory); + AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) + { + auto* weaponFullDef = m_memory.Alloc(); - LoadAccuracyGraphs(*weaponFullDef, m_memory, m_search_path, context); + InitWeaponFullDef(*weaponFullDef); + weaponFullDef->weapCompleteDef.szInternalName = m_memory.Dup(assetName.c_str()); - return AssetCreationResult::Success(context.AddAsset(std::move(registration))); -} + AssetRegistration registration(assetName, &weaponFullDef->weapCompleteDef); + + InfoStringToWeaponConverter converter( + infoString, *weaponFullDef, m_zone.m_script_strings, m_memory, context, registration, weapon_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse weapon: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculateWeaponFields(*weaponFullDef, m_memory); + + LoadAccuracyGraphs(*weaponFullDef, m_memory, m_search_path, context); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } +} // namespace IW4::weapon diff --git a/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.h b/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.h index 59204d85..d1ba5d80 100644 --- a/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.h +++ b/src/ObjLoading/Game/IW4/Weapon/InfoStringLoaderWeaponIW4.h @@ -4,12 +4,12 @@ #include "Asset/AssetCreationResult.h" #include "InfoString/InfoString.h" -namespace IW4 +namespace IW4::weapon { - class InfoStringLoaderWeapon + class InfoStringLoader { public: - InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); @@ -18,4 +18,4 @@ namespace IW4 ISearchPath& m_search_path; Zone& m_zone; }; -} // namespace IW4 +} // namespace IW4::weapon diff --git a/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.cpp b/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.cpp index a1b7b656..2b4b4283 100644 --- a/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.cpp +++ b/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.cpp @@ -4,12 +4,14 @@ #include "Game/IW4/ObjConstantsIW4.h" #include "InfoString/InfoString.h" #include "InfoStringLoaderWeaponIW4.h" +#include "Weapon/WeaponCommon.h" #include #include #include using namespace IW4; +using namespace ::weapon; namespace { @@ -24,7 +26,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = std::format("weapons/{}", assetName); + const auto fileName = GetFileNameForAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -41,14 +43,14 @@ namespace private: ISearchPath& m_search_path; - InfoStringLoaderWeapon m_info_string_loader; + IW4::weapon::InfoStringLoader m_info_string_loader; }; } // namespace -namespace IW4 +namespace IW4::weapon { - std::unique_ptr> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) { return std::make_unique(memory, searchPath, zone); } -} // namespace IW4 +} // namespace IW4::weapon diff --git a/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.h b/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.h index 786d7ce3..e8995ac3 100644 --- a/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.h +++ b/src/ObjLoading/Game/IW4/Weapon/RawLoaderWeaponIW4.h @@ -7,7 +7,7 @@ #include -namespace IW4 +namespace IW4::weapon { - std::unique_ptr> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); -} // namespace IW4 + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace IW4::weapon diff --git a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp index 75d93683..0a39cf0e 100644 --- a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp +++ b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp @@ -52,7 +52,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE) // DUMP_ASSET_POOL(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND) - DUMP_ASSET_POOL(sound::SndCurveDumper, m_sound_curve, ASSET_TYPE_SOUND_CURVE) + DUMP_ASSET_POOL(sound_curve::Dumper, m_sound_curve, ASSET_TYPE_SOUND_CURVE) DUMP_ASSET_POOL(sound::LoadedSoundDumper, m_loaded_sound, ASSET_TYPE_LOADED_SOUND) // DUMP_ASSET_POOL(AssetDumperClipMap, m_clip_map, ASSET_TYPE_CLIPMAP_MP) // DUMP_ASSET_POOL(AssetDumperComWorld, m_com_world, ASSET_TYPE_COMWORLD) diff --git a/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp b/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp index f5a38e94..69b51223 100644 --- a/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp +++ b/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp @@ -1,40 +1,30 @@ #include "SndCurveDumperIW4.h" -#include "Dumping/SndCurve/SndCurveDumper.h" +#include "Sound/SndCurveDumper.h" +#include "Sound/SoundCurveCommon.h" #include using namespace IW4; +using namespace ::sound_curve; -namespace +namespace IW4::sound_curve { - std::string GetAssetFilename(const std::string& assetName) - { - std::ostringstream ss; - - ss << "soundaliases/" << assetName << ".vfcurve"; - - return ss.str(); - } -} // namespace - -namespace IW4::sound -{ - bool SndCurveDumper::ShouldDump(XAssetInfo* asset) + bool Dumper::ShouldDump(XAssetInfo* asset) { return true; } - void SndCurveDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* sndCurve = asset->Asset(); - const auto assetFile = context.OpenAssetFile(GetAssetFilename(sndCurve->filename)); + const auto assetFile = context.OpenAssetFile(GetFileNameForAssetName(sndCurve->filename)); if (!assetFile) return; - ::SndCurveDumper dumper(*assetFile); + SndCurveDumper dumper(*assetFile); const auto knotCount = std::min(static_cast(sndCurve->knotCount), std::extent_v); dumper.Init(knotCount); @@ -42,4 +32,4 @@ namespace IW4::sound for (auto i = 0u; i < knotCount; i++) dumper.WriteKnot(sndCurve->knots[i][0], sndCurve->knots[i][1]); } -} // namespace IW4::sound +} // namespace IW4::sound_curve diff --git a/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.h b/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.h index 18cc1264..85ff48a1 100644 --- a/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.h +++ b/src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.h @@ -3,12 +3,12 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/IW4/IW4.h" -namespace IW4::sound +namespace IW4::sound_curve { - class SndCurveDumper final : public AbstractAssetDumper + class Dumper final : public AbstractAssetDumper { protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace IW4::sound +} // namespace IW4::sound_curve diff --git a/src/ObjWriting/Dumping/SndCurve/SndCurveDumper.cpp b/src/ObjWriting/Sound/SndCurveDumper.cpp similarity index 100% rename from src/ObjWriting/Dumping/SndCurve/SndCurveDumper.cpp rename to src/ObjWriting/Sound/SndCurveDumper.cpp diff --git a/src/ObjWriting/Dumping/SndCurve/SndCurveDumper.h b/src/ObjWriting/Sound/SndCurveDumper.h similarity index 100% rename from src/ObjWriting/Dumping/SndCurve/SndCurveDumper.h rename to src/ObjWriting/Sound/SndCurveDumper.h diff --git a/test/ObjLoadingTests/Game/IW4/AssetLoaders/LoaderStringTableIW4Test.cpp b/test/ObjLoadingTests/Game/IW4/AssetLoaders/LoaderStringTableIW4Test.cpp index 88fbe000..ff4c5c56 100644 --- a/test/ObjLoadingTests/Game/IW4/AssetLoaders/LoaderStringTableIW4Test.cpp +++ b/test/ObjLoadingTests/Game/IW4/AssetLoaders/LoaderStringTableIW4Test.cpp @@ -27,7 +27,7 @@ namespace IgnoredAssetLookup ignoredAssetLookup; AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup); - auto loader = CreateStringTableLoader(memory, searchPath); + auto loader = string_table::CreateLoader(memory, searchPath); auto result = loader->CreateAsset("mp/cooltable.csv", context); REQUIRE(result.HasBeenSuccessful()); diff --git a/test/ObjLoadingTests/Game/IW4/Material/LoaderMaterialIW4Test.cpp b/test/ObjLoadingTests/Game/IW4/Material/LoaderMaterialIW4Test.cpp index 0860550b..6af6297d 100644 --- a/test/ObjLoadingTests/Game/IW4/Material/LoaderMaterialIW4Test.cpp +++ b/test/ObjLoadingTests/Game/IW4/Material/LoaderMaterialIW4Test.cpp @@ -289,7 +289,7 @@ namespace GivenImage("ch_rubble01_col", context, memory); GivenTechset("mc_l_sm_r0c0n0s0", context, memory); - auto loader = CreateMaterialLoader(memory, searchPath); + auto loader = material::CreateLoader(memory, searchPath); auto result = loader->CreateAsset("mc/ch_rubble01", context); REQUIRE(result.HasBeenSuccessful()); diff --git a/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp b/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp index 69021fe5..d246deb2 100644 --- a/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp +++ b/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp @@ -11,7 +11,7 @@ #include #include -using namespace menu; +using namespace ::menu; using namespace IW4; using namespace std::literals; using namespace Catch::Matchers; @@ -36,7 +36,7 @@ namespace test::game::iw4::menu::parsing::it m_ignored_asset_lookup(), m_context(m_zone, &m_creator_collection, &m_ignored_asset_lookup) { - m_asset_creator = CreateMenuListLoader(m_zone.Memory(), m_search_path); + m_asset_creator = IW4::menu::CreateMenuListLoader(m_zone.Memory(), m_search_path); } void AddFile(std::string fileName, std::string data)