From 8cc4147d035fa66dc4e06c7227bb8ceefcc6c36e Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 25 Dec 2024 21:39:05 +0100 Subject: [PATCH] chore: WIP refactor IW4 asset loaders --- src/Linker/ZoneCreation/ZoneCreator.cpp | 19 +- .../PhysPresetFields.h | 1 + src/ObjLoading/Asset/AssetCreationContext.cpp | 3 + src/ObjLoading/Asset/AssetCreationContext.h | 4 +- src/ObjLoading/Asset/AssetRegistration.h | 12 +- .../AssetLoading/AssetLoadingContext.cpp | 45 +-- .../AssetLoading/AssetLoadingContext.h | 7 +- src/ObjLoading/AssetLoading/IAssetLoader.h | 3 +- .../IW3/RawFile/AssetLoaderRawFileIW3.cpp | 1 - .../AssetLoaders/AssetLoaderAddonMapEnts.cpp | 17 - .../AssetLoaders/AssetLoaderAddonMapEnts.h | 14 - .../IW4/AssetLoaders/AssetLoaderClipMap.cpp | 27 -- .../IW4/AssetLoaders/AssetLoaderClipMap.h | 25 -- .../IW4/AssetLoaders/AssetLoaderComWorld.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderComWorld.h | 14 - .../Game/IW4/AssetLoaders/AssetLoaderFont.cpp | 17 - .../Game/IW4/AssetLoaders/AssetLoaderFont.h | 14 - .../Game/IW4/AssetLoaders/AssetLoaderFx.cpp | 17 - .../Game/IW4/AssetLoaders/AssetLoaderFx.h | 14 - .../AssetLoaders/AssetLoaderFxImpactTable.cpp | 17 - .../AssetLoaders/AssetLoaderFxImpactTable.h | 14 - .../IW4/AssetLoaders/AssetLoaderFxWorld.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderFxWorld.h | 14 - .../AssetLoaders/AssetLoaderGameWorldMp.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderGameWorldMp.h | 14 - .../AssetLoaders/AssetLoaderGameWorldSp.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderGameWorldSp.h | 14 - .../IW4/AssetLoaders/AssetLoaderGfxImage.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderGfxImage.h | 14 - .../AssetLoaders/AssetLoaderGfxLightDef.cpp | 72 ----- .../IW4/AssetLoaders/AssetLoaderGfxLightDef.h | 21 -- .../IW4/AssetLoaders/AssetLoaderGfxWorld.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderGfxWorld.h | 14 - .../AssetLoaders/AssetLoaderLeaderboard.cpp | 43 --- .../IW4/AssetLoaders/AssetLoaderLeaderboard.h | 17 - .../AssetLoaders/AssetLoaderLoadedSound.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderLoadedSound.h | 14 - .../IW4/AssetLoaders/AssetLoaderMapEnts.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderMapEnts.h | 14 - .../IW4/AssetLoaders/AssetLoaderMaterial.h | 17 - .../IW4/AssetLoaders/AssetLoaderMenuDef.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderMenuDef.h | 14 - .../IW4/AssetLoaders/AssetLoaderMenuList.cpp | 233 -------------- .../IW4/AssetLoaders/AssetLoaderMenuList.h | 19 -- .../AssetLoaders/AssetLoaderPhysCollmap.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderPhysCollmap.h | 14 - .../AssetLoaders/AssetLoaderPhysPreset.cpp | 134 -------- .../IW4/AssetLoaders/AssetLoaderPhysPreset.h | 26 -- .../AssetLoaders/AssetLoaderPixelShader.cpp | 63 ---- .../IW4/AssetLoaders/AssetLoaderPixelShader.h | 21 -- .../IW4/AssetLoaders/AssetLoaderRawFile.cpp | 80 ----- .../IW4/AssetLoaders/AssetLoaderRawFile.h | 19 -- .../IW4/AssetLoaders/AssetLoaderSndCurve.cpp | 63 ---- .../IW4/AssetLoaders/AssetLoaderSndCurve.h | 17 - .../AssetLoaderSoundAliasList.cpp | 17 - .../AssetLoaders/AssetLoaderSoundAliasList.h | 14 - .../AssetLoaders/AssetLoaderStringTable.cpp | 40 --- .../IW4/AssetLoaders/AssetLoaderStringTable.h | 17 - .../AssetLoaderStructuredDataDefSet.cpp | 220 ------------- .../AssetLoaderStructuredDataDefSet.h | 29 -- .../AssetLoaders/AssetLoaderTechniqueSet.h | 36 --- .../IW4/AssetLoaders/AssetLoaderTracer.cpp | 17 - .../Game/IW4/AssetLoaders/AssetLoaderTracer.h | 14 - .../IW4/AssetLoaders/AssetLoaderVehicle.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderVehicle.h | 14 - .../AssetLoaders/AssetLoaderVertexDecl.cpp | 101 ------ .../IW4/AssetLoaders/AssetLoaderVertexDecl.h | 20 -- .../AssetLoaders/AssetLoaderVertexShader.cpp | 63 ---- .../AssetLoaders/AssetLoaderVertexShader.h | 19 -- .../IW4/AssetLoaders/AssetLoaderXAnim.cpp | 17 - .../Game/IW4/AssetLoaders/AssetLoaderXAnim.h | 14 - .../IW4/AssetLoaders/AssetLoaderXModel.cpp | 17 - .../Game/IW4/AssetLoaders/AssetLoaderXModel.h | 14 - .../AssetLoaders/AssetLoaderXModelSurfs.cpp | 17 - .../IW4/AssetLoaders/AssetLoaderXModelSurfs.h | 14 - .../InfoStringToStructConverter.cpp | 47 +-- .../InfoString/InfoStringToStructConverter.h | 21 +- .../IW4/Leaderboard/LoaderLeaderboardIW4.cpp | 53 ++++ .../IW4/Leaderboard/LoaderLeaderboardIW4.h | 13 + .../Game/IW4/LightDef/LoaderLightDefIW4.cpp | 82 +++++ .../Game/IW4/LightDef/LoaderLightDefIW4.h | 13 + .../IW4/Localize/AssetLoaderLocalizeIW4.cpp | 23 -- .../IW4/Localize/AssetLoaderLocalizeIW4.h | 25 -- .../Game/IW4/Localize/LoaderLocalizeIW4.cpp | 44 +++ .../Game/IW4/Localize/LoaderLocalizeIW4.h | 14 + .../LoaderMaterialIW4.cpp} | 256 +++++++--------- .../Game/IW4/Material/LoaderMaterialIW4.h | 12 + .../Game/IW4/Menu/LoaderMenuListIW4.cpp | 230 ++++++++++++++ .../Game/IW4/Menu/LoaderMenuListIW4.h | 13 + .../Game/IW4/Menu/MenuConverterIW4.cpp | 214 ++++++------- .../Game/IW4/Menu/MenuConverterIW4.h | 19 +- src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp | 54 ++-- src/ObjLoading/Game/IW4/ObjLoaderIW4.h | 2 +- .../IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp | 35 +++ .../IW4/PhysPreset/GdtLoaderPhysPresetIW4.h | 22 ++ .../InfoStringLoaderPhysPresetIW4.cpp | 86 ++++++ .../InfoStringLoaderPhysPresetIW4.h | 20 ++ .../IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp | 36 +++ .../IW4/PhysPreset/RawLoaderPhysPresetIW4.h | 22 ++ .../Game/IW4/RawFile/LoaderRawFileIW4.cpp | 91 ++++++ .../Game/IW4/RawFile/LoaderRawFileIW4.h | 13 + .../Game/IW4/Shader/LoaderPixelShaderIW4.cpp | 67 ++++ .../Game/IW4/Shader/LoaderPixelShaderIW4.h | 13 + .../Game/IW4/Shader/LoaderVertexShaderIW4.cpp | 67 ++++ .../Game/IW4/Shader/LoaderVertexShaderIW4.h | 13 + .../Game/IW4/Sound/LoaderSoundCurveIW4.cpp | 78 +++++ .../Game/IW4/Sound/LoaderSoundCurveIW4.h | 13 + .../IW4/StringTable/LoaderStringTableIW4.cpp | 47 +++ .../IW4/StringTable/LoaderStringTableIW4.h | 13 + .../LoaderStructuredDataDefIW4.cpp | 225 ++++++++++++++ .../LoaderStructuredDataDefIW4.h | 13 + .../LoaderTechsetIW4.cpp} | 290 +++++++++--------- .../Game/IW4/Techset/LoaderTechsetIW4.h | 26 ++ .../Game/IW4/Techset/LoaderVertexDeclIW4.cpp | 101 ++++++ .../Game/IW4/Techset/LoaderVertexDeclIW4.h | 13 + .../LoaderWeaponIW4.cpp} | 0 .../LoaderWeaponIW4.h} | 0 src/ObjLoading/Gdt/GdtLookup.cpp | 44 +++ src/ObjLoading/Gdt/GdtLookup.h | 18 ++ .../{AssetLoading => Gdt}/IGdtQueryable.h | 1 + src/ObjLoading/IObjLoader.h | 3 +- .../InfoStringToStructConverterBase.cpp | 61 +--- .../InfoStringToStructConverterBase.h | 48 +-- src/ObjLoading/Menu/AbstractMenuConverter.cpp | 22 +- src/ObjLoading/Menu/AbstractMenuConverter.h | 16 +- src/ObjLoading/Sound/SoundCurveLoader.cpp | 21 -- src/ObjLoading/Sound/SoundCurveLoader.h | 11 - .../AssetDumpers/AssetDumperPhysPreset.cpp | 2 +- 128 files changed, 2070 insertions(+), 2773 deletions(-) rename src/ObjCommon/Game/IW4/{InfoString => PhysPreset}/PhysPresetFields.h (99%) delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.h delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.cpp delete mode 100644 src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.h create mode 100644 src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h create mode 100644 src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.h delete mode 100644 src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.cpp delete mode 100644 src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.h create mode 100644 src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h rename src/ObjLoading/Game/IW4/{AssetLoaders/AssetLoaderMaterial.cpp => Material/LoaderMaterialIW4.cpp} (87%) create mode 100644 src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h create mode 100644 src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h create mode 100644 src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h create mode 100644 src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h create mode 100644 src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h create mode 100644 src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h create mode 100644 src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h create mode 100644 src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h create mode 100644 src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h create mode 100644 src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h create mode 100644 src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h rename src/ObjLoading/Game/IW4/{AssetLoaders/AssetLoaderTechniqueSet.cpp => Techset/LoaderTechsetIW4.cpp} (89%) create mode 100644 src/ObjLoading/Game/IW4/Techset/LoaderTechsetIW4.h create mode 100644 src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.cpp create mode 100644 src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.h rename src/ObjLoading/Game/IW4/{AssetLoaders/AssetLoaderWeapon.cpp => Weapon/LoaderWeaponIW4.cpp} (100%) rename src/ObjLoading/Game/IW4/{AssetLoaders/AssetLoaderWeapon.h => Weapon/LoaderWeaponIW4.h} (100%) create mode 100644 src/ObjLoading/Gdt/GdtLookup.cpp create mode 100644 src/ObjLoading/Gdt/GdtLookup.h rename src/ObjLoading/{AssetLoading => Gdt}/IGdtQueryable.h (99%) delete mode 100644 src/ObjLoading/Sound/SoundCurveLoader.cpp delete mode 100644 src/ObjLoading/Sound/SoundCurveLoader.h diff --git a/src/Linker/ZoneCreation/ZoneCreator.cpp b/src/Linker/ZoneCreation/ZoneCreator.cpp index a7f6422d8..384b4be80 100644 --- a/src/Linker/ZoneCreation/ZoneCreator.cpp +++ b/src/Linker/ZoneCreation/ZoneCreator.cpp @@ -1,6 +1,7 @@ #include "ZoneCreator.h" #include "AssetLoading/AssetLoadingContext.h" +#include "Gdt/GdtLookup.h" #include "IObjCompiler.h" #include "IObjLoader.h" @@ -45,6 +46,19 @@ namespace namespace zone_creator { + void InitLookup(const ZoneCreationContext& context, GdtLookup& lookup) + { + std::vector gdtFiles; + gdtFiles.reserve(context.m_gdt_files.size()); + + for (const auto& gdt : context.m_gdt_files) + { + gdtFiles.emplace_back(gdt.get()); + } + + lookup.Initialize(gdtFiles); + } + std::unique_ptr CreateZoneForDefinition(GameId gameId, ZoneCreationContext& context) { auto zone = CreateZone(context, gameId); @@ -53,12 +67,15 @@ namespace zone_creator IgnoreReferencesFromAssets(context); IgnoredAssetLookup ignoredAssetLookup(context.m_ignored_assets); + GdtLookup lookup; + InitLookup(context, lookup); + const auto* objCompiler = IObjCompiler::GetObjCompilerForGame(gameId); const auto* objLoader = IObjLoader::GetObjLoaderForGame(gameId); AssetCreatorCollection creatorCollection(*zone); objCompiler->ConfigureCreatorCollection(creatorCollection, *zone, *context.m_definition); - objLoader->ConfigureCreatorCollection(creatorCollection, *zone, *context.m_asset_search_path); + objLoader->ConfigureCreatorCollection(creatorCollection, *zone, *context.m_asset_search_path, gdtLookup); AssetCreationContext creationContext(zone.get(), &creatorCollection, &ignoredAssetLookup); diff --git a/src/ObjCommon/Game/IW4/InfoString/PhysPresetFields.h b/src/ObjCommon/Game/IW4/PhysPreset/PhysPresetFields.h similarity index 99% rename from src/ObjCommon/Game/IW4/InfoString/PhysPresetFields.h rename to src/ObjCommon/Game/IW4/PhysPreset/PhysPresetFields.h index bc3ab22e1..1423f3a8e 100644 --- a/src/ObjCommon/Game/IW4/InfoString/PhysPresetFields.h +++ b/src/ObjCommon/Game/IW4/PhysPreset/PhysPresetFields.h @@ -1,4 +1,5 @@ #pragma once + #include "Game/IW4/IW4.h" namespace IW4 diff --git a/src/ObjLoading/Asset/AssetCreationContext.cpp b/src/ObjLoading/Asset/AssetCreationContext.cpp index fc8a8332d..f2f5cc257 100644 --- a/src/ObjLoading/Asset/AssetCreationContext.cpp +++ b/src/ObjLoading/Asset/AssetCreationContext.cpp @@ -1,5 +1,6 @@ #include "AssetCreationContext.h" +#include #include #include @@ -51,6 +52,8 @@ void GenericAssetRegistration::AddIndirectAssetReference(IndirectAssetReference std::unique_ptr GenericAssetRegistration::CreateXAssetInfo() { + assert(m_asset); + std::vector dependencies(m_dependencies.begin(), m_dependencies.end()); std::vector scriptStrings(m_used_script_strings.begin(), m_used_script_strings.end()); std::vector indirectAssetReferences(m_indirect_asset_references.begin(), m_indirect_asset_references.end()); diff --git a/src/ObjLoading/Asset/AssetCreationContext.h b/src/ObjLoading/Asset/AssetCreationContext.h index 5e0a6d770..804edff55 100644 --- a/src/ObjLoading/Asset/AssetCreationContext.h +++ b/src/ObjLoading/Asset/AssetCreationContext.h @@ -52,7 +52,7 @@ class AssetCreationContext { static_assert(std::is_base_of_v); - return static_cast*>(LoadDependencyInternal(AssetType::EnumEntry, assetName)); + return static_cast*>(LoadDependencyGeneric(AssetType::EnumEntry, assetName)); } XAssetInfoGeneric* LoadDependencyGeneric(asset_type_t assetType, const std::string& assetName); @@ -76,7 +76,7 @@ class AssetCreationContext return dynamic_cast(foundEntry->second.get()); auto newState = std::make_unique(); - newState->SetZone(&m_zone); + newState->SetZone(m_zone); auto* newStatePtr = newState.get(); m_zone_asset_loader_states.emplace(std::make_pair>(typeid(T), std::move(newState))); return newStatePtr; diff --git a/src/ObjLoading/Asset/AssetRegistration.h b/src/ObjLoading/Asset/AssetRegistration.h index 18e9794b5..a0b549ec3 100644 --- a/src/ObjLoading/Asset/AssetRegistration.h +++ b/src/ObjLoading/Asset/AssetRegistration.h @@ -25,7 +25,7 @@ class GenericAssetRegistration std::unique_ptr CreateXAssetInfo(); -private: +protected: asset_type_t m_type; std::string m_name; void* m_asset; @@ -39,6 +39,11 @@ template class AssetRegistration : public GenericAssetRegist static_assert(std::is_base_of_v); public: + AssetRegistration(std::string assetName) + : GenericAssetRegistration(AssetType::EnumEntry, std::move(assetName), nullptr) + { + } + AssetRegistration(std::string assetName, typename AssetType::Type* asset) : GenericAssetRegistration(AssetType::EnumEntry, std::move(assetName), asset) { @@ -48,4 +53,9 @@ template class AssetRegistration : public GenericAssetRegist AssetRegistration(AssetRegistration&& other) = default; AssetRegistration& operator=(const AssetRegistration& other) = delete; AssetRegistration& operator=(AssetRegistration&& other) noexcept = default; + + void SetAsset(typename AssetType::Type* asset) + { + m_asset = asset; + } }; diff --git a/src/ObjLoading/AssetLoading/AssetLoadingContext.cpp b/src/ObjLoading/AssetLoading/AssetLoadingContext.cpp index 26480fd9c..dbd2f2cf4 100644 --- a/src/ObjLoading/AssetLoading/AssetLoadingContext.cpp +++ b/src/ObjLoading/AssetLoading/AssetLoadingContext.cpp @@ -2,49 +2,6 @@ AssetLoadingContext::AssetLoadingContext(Zone& zone, ISearchPath& rawSearchPath, std::vector gdtFiles) : m_zone(zone), - m_raw_search_path(rawSearchPath), - m_gdt_files(std::move(gdtFiles)) + m_raw_search_path(rawSearchPath) { - BuildGdtEntryCache(); -} - -void AssetLoadingContext::BuildGdtEntryCache() -{ - for (const auto* gdt : m_gdt_files) - { - for (const auto& entry : gdt->m_entries) - { - auto gdfMapEntry = m_entries_by_gdf_and_by_name.find(entry->m_gdf_name); - if (gdfMapEntry == m_entries_by_gdf_and_by_name.end()) - { - std::unordered_map entryMap; - entryMap.emplace(std::make_pair(entry->m_name, entry.get())); - m_entries_by_gdf_and_by_name.emplace(std::make_pair(entry->m_gdf_name, std::move(entryMap))); - } - else - { - auto entryMapEntry = gdfMapEntry->second.find(entry->m_name); - - if (entryMapEntry == gdfMapEntry->second.end()) - gdfMapEntry->second.emplace(std::make_pair(entry->m_name, entry.get())); - else - entryMapEntry->second = entry.get(); - } - } - } -} - -GdtEntry* AssetLoadingContext::GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) -{ - const auto foundGdtMap = m_entries_by_gdf_and_by_name.find(gdfName); - - if (foundGdtMap == m_entries_by_gdf_and_by_name.end()) - return nullptr; - - const auto foundGdtEntry = foundGdtMap->second.find(entryName); - - if (foundGdtEntry == foundGdtMap->second.end()) - return nullptr; - - return foundGdtEntry->second; } diff --git a/src/ObjLoading/AssetLoading/AssetLoadingContext.h b/src/ObjLoading/AssetLoading/AssetLoadingContext.h index 18a425969..c57fb6c7c 100644 --- a/src/ObjLoading/AssetLoading/AssetLoadingContext.h +++ b/src/ObjLoading/AssetLoading/AssetLoadingContext.h @@ -1,6 +1,6 @@ #pragma once -#include "IGdtQueryable.h" +#include "Gdt/IGdtQueryable.h" #include "IZoneAssetLoaderState.h" #include "Obj/Gdt/Gdt.h" #include "SearchPath/ISearchPath.h" @@ -32,15 +32,10 @@ class AssetLoadingContext final : public IGdtQueryable return newStatePtr; } -private: - void BuildGdtEntryCache(); - public: Zone& m_zone; ISearchPath& m_raw_search_path; - const std::vector m_gdt_files; std::unordered_map m_ignored_asset_map; - std::unordered_map> m_entries_by_gdf_and_by_name; std::unordered_map> m_zone_asset_loader_states; }; diff --git a/src/ObjLoading/AssetLoading/IAssetLoader.h b/src/ObjLoading/AssetLoading/IAssetLoader.h index 625c72b53..910f6d61a 100644 --- a/src/ObjLoading/AssetLoading/IAssetLoader.h +++ b/src/ObjLoading/AssetLoading/IAssetLoader.h @@ -1,6 +1,7 @@ #pragma once + +#include "Gdt/IGdtQueryable.h" #include "IAssetLoadingManager.h" -#include "IGdtQueryable.h" #include "SearchPath/ISearchPath.h" #include "Utils/ClassUtils.h" #include "Zone/ZoneTypes.h" diff --git a/src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp b/src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp index b0f50f5f0..b304a2f3e 100644 --- a/src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp +++ b/src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp @@ -1,7 +1,6 @@ #include "AssetLoaderRawFileIW3.h" #include "Game/IW3/IW3.h" -#include "Pool/GlobalAssetPool.h" #include diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.cpp deleted file mode 100644 index bc1efe016..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderAddonMapEnts.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderAddonMapEnts::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* addonMapEnts = memory->Create(); - memset(addonMapEnts, 0, sizeof(AddonMapEnts)); - addonMapEnts->name = memory->Dup(assetName.c_str()); - return addonMapEnts; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.h deleted file mode 100644 index 119bbd73d..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderAddonMapEnts.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderAddonMapEnts final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.cpp deleted file mode 100644 index 874a6ffe8..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "AssetLoaderClipMap.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderClipMap::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* clipMap = memory->Create(); - memset(clipMap, 0, sizeof(clipMap_t)); - clipMap->name = memory->Dup(assetName.c_str()); - return clipMap; -} - -asset_type_t AssetLoaderClipMapSp::GetHandlingAssetType() const -{ - return ASSET_TYPE_CLIPMAP_SP; -} - -asset_type_t AssetLoaderClipMapMp::GetHandlingAssetType() const -{ - return ASSET_TYPE_CLIPMAP_MP; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.h deleted file mode 100644 index dabf4c803..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderClipMap.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderClipMap : public BasicAssetLoaderWithoutType - { - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; - - class AssetLoaderClipMapSp final : public AssetLoaderClipMap - { - public: - _NODISCARD asset_type_t GetHandlingAssetType() const override; - }; - - class AssetLoaderClipMapMp final : public AssetLoaderClipMap - { - public: - _NODISCARD asset_type_t GetHandlingAssetType() const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.cpp deleted file mode 100644 index bb373c783..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderComWorld.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderComWorld::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* comWorld = memory->Create(); - memset(comWorld, 0, sizeof(ComWorld)); - comWorld->name = memory->Dup(assetName.c_str()); - return comWorld; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.h deleted file mode 100644 index 534ffa72e..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderComWorld.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderComWorld final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.cpp deleted file mode 100644 index 4afef3a49..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderFont.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderFont::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* font = memory->Create(); - memset(font, 0, sizeof(Font_s)); - font->fontName = memory->Dup(assetName.c_str()); - return font; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.h deleted file mode 100644 index 101752219..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFont.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderFont final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.cpp deleted file mode 100644 index 4bed0ab55..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderFx.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderFx::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* fx = memory->Create(); - memset(fx, 0, sizeof(FxEffectDef)); - fx->name = memory->Dup(assetName.c_str()); - return fx; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.h deleted file mode 100644 index 3cddeb717..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFx.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderFx final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.cpp deleted file mode 100644 index 148e69e09..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderFxImpactTable.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderFxImpactTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* fxImpactTable = memory->Create(); - memset(fxImpactTable, 0, sizeof(FxImpactTable)); - fxImpactTable->name = memory->Dup(assetName.c_str()); - return fxImpactTable; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.h deleted file mode 100644 index b7ff4c107..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxImpactTable.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderFxImpactTable final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.cpp deleted file mode 100644 index 70c880dba..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderFxWorld.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderFxWorld::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* fxWorld = memory->Create(); - memset(fxWorld, 0, sizeof(FxWorld)); - fxWorld->name = memory->Dup(assetName.c_str()); - return fxWorld; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.h deleted file mode 100644 index bbdc1ec6b..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderFxWorld.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderFxWorld final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.cpp deleted file mode 100644 index 93bf930bf..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderGameWorldMp.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderGameWorldMp::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* gameWorld = memory->Create(); - memset(gameWorld, 0, sizeof(GameWorldMp)); - gameWorld->name = memory->Dup(assetName.c_str()); - return gameWorld; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.h deleted file mode 100644 index 4b9ce8277..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldMp.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderGameWorldMp final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.cpp deleted file mode 100644 index 331e7c030..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderGameWorldSp.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderGameWorldSp::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* gameWorld = memory->Create(); - memset(gameWorld, 0, sizeof(GameWorldSp)); - gameWorld->name = memory->Dup(assetName.c_str()); - return gameWorld; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.h deleted file mode 100644 index f952186e6..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGameWorldSp.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderGameWorldSp final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.cpp deleted file mode 100644 index 10d6697c4..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderGfxImage.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderGfxImage::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* image = memory->Create(); - memset(image, 0, sizeof(GfxImage)); - image->name = memory->Dup(assetName.c_str()); - return image; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.h deleted file mode 100644 index e63c470f9..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxImage.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderGfxImage final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.cpp deleted file mode 100644 index 775eb766c..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "AssetLoaderGfxLightDef.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace IW4; - -std::string AssetLoaderGfxLightDef::GetAssetFilename(const std::string& assetName) -{ - std::ostringstream ss; - - ss << "lights/" << assetName; - - return ss.str(); -} - -void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* lightDef = memory->Create(); - memset(lightDef, 0, sizeof(GfxLightDef)); - lightDef->name = memory->Dup(assetName.c_str()); - return lightDef; -} - -bool AssetLoaderGfxLightDef::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderGfxLightDef::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto filename = GetAssetFilename(assetName); - const auto file = searchPath->Open(filename); - if (!file.IsOpen()) - return false; - - const auto imageNameSize = file.m_length - sizeof(char) - sizeof(char); - if (imageNameSize < 0 || imageNameSize > MAX_IMAGE_NAME_SIZE) - return false; - - std::string imageName(static_cast(imageNameSize), '\0'); - - int8_t samplerState; - int8_t lmapLookupStart; - file.m_stream->read(reinterpret_cast(&samplerState), sizeof(int8_t)); - file.m_stream->read(&imageName[0], static_cast(imageNameSize)); - file.m_stream->read(reinterpret_cast(&lmapLookupStart), sizeof(int8_t)); - - auto* imageDependency = manager->LoadDependency(imageName); - - if (!imageDependency) - { - std::cerr << "Could not load GfxLightDef \"" << assetName << "\" due to missing image \"" << imageName << "\"\n"; - return false; - } - - auto* lightDef = memory->Create(); - lightDef->name = memory->Dup(assetName.c_str()); - lightDef->attenuation.samplerState = samplerState; - lightDef->attenuation.image = imageDependency->Asset(); - lightDef->lmapLookupStart = static_cast(static_cast(lmapLookupStart)); - - manager->AddAsset(assetName, lightDef); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.h deleted file mode 100644 index f8fbae58a..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxLightDef.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderGfxLightDef final : public BasicAssetLoader - { - static constexpr auto MAX_IMAGE_NAME_SIZE = 0x800; - - static std::string GetAssetFilename(const std::string& assetName); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.cpp deleted file mode 100644 index b31d51123..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderGfxWorld.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderGfxWorld::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* gfxWorld = memory->Create(); - memset(gfxWorld, 0, sizeof(GfxWorld)); - gfxWorld->name = memory->Dup(assetName.c_str()); - return gfxWorld; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.h deleted file mode 100644 index 2f87ed12b..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderGfxWorld.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderGfxWorld final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.cpp deleted file mode 100644 index 17952169d..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "AssetLoaderLeaderboard.h" - -#include "Game/IW4/IW4.h" -#include "Game/IW4/Leaderboard/JsonLeaderboardDefLoader.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace IW4; - -void* AssetLoaderLeaderboard::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* leaderboard = memory->Create(); - memset(leaderboard, 0, sizeof(LeaderboardDef)); - leaderboard->name = memory->Dup(assetName.c_str()); - return leaderboard; -} - -bool AssetLoaderLeaderboard::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderLeaderboard::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(std::format("leaderboards/{}.json", assetName)); - if (!file.IsOpen()) - return false; - - auto* leaderboardDef = memory->Alloc(); - leaderboardDef->name = memory->Dup(assetName.c_str()); - - if (LoadLeaderboardAsJson(*file.m_stream, *leaderboardDef, memory)) - manager->AddAsset(assetName, leaderboardDef); - else - std::cerr << std::format("Failed to load leaderboard \"{}\"\n", assetName); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.h deleted file mode 100644 index 1d3a224d8..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLeaderboard.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderLeaderboard final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.cpp deleted file mode 100644 index b94bc60eb..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderLoadedSound.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderLoadedSound::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* loadedSound = memory->Create(); - memset(loadedSound, 0, sizeof(LoadedSound)); - loadedSound->name = memory->Dup(assetName.c_str()); - return loadedSound; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.h deleted file mode 100644 index 8b166f297..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLoadedSound.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderLoadedSound final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.cpp deleted file mode 100644 index 012cb0f8e..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderMapEnts.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderMapEnts::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* mapEnts = memory->Create(); - memset(mapEnts, 0, sizeof(MapEnts)); - mapEnts->name = memory->Dup(assetName.c_str()); - return mapEnts; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.h deleted file mode 100644 index 518e5666b..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMapEnts.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderMapEnts final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.h deleted file mode 100644 index d5642e7ce..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderMaterial final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.cpp deleted file mode 100644 index b2fe05008..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderMenuDef.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderMenuDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* menu = memory->Create(); - memset(menu, 0, sizeof(menuDef_t)); - menu->window.name = memory->Dup(assetName.c_str()); - return menu; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.h deleted file mode 100644 index 35d0910a8..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderMenuDef final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.cpp deleted file mode 100644 index 276cefc3e..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.cpp +++ /dev/null @@ -1,233 +0,0 @@ -#include "AssetLoaderMenuList.h" - -#include "Game/IW4/IW4.h" -#include "Game/IW4/Menu/MenuConversionZoneStateIW4.h" -#include "Game/IW4/Menu/MenuConverterIW4.h" -#include "ObjLoading.h" -#include "Parsing/Menu/MenuFileReader.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include - -using namespace IW4; - -namespace IW4 -{ - class MenuLoader - { - public: - static bool ProcessParsedResults(const std::string& fileName, - ISearchPath* searchPath, - MemoryManager* memory, - IAssetLoadingManager* manager, - menu::ParsingResult* parsingResult, - menu::MenuAssetZoneState* zoneState, - MenuConversionZoneState* conversionState, - std::vector& menus, - std::vector& menuListDependencies) - { - const auto menuCount = parsingResult->m_menus.size(); - const auto functionCount = parsingResult->m_functions.size(); - const auto menuLoadCount = parsingResult->m_menus_to_load.size(); - auto totalItemCount = 0u; - for (const auto& menu : parsingResult->m_menus) - totalItemCount += menu->m_items.size(); - - std::cout << "Successfully read menu file \"" << fileName << "\" (" << menuLoadCount << " loads, " << menuCount << " menus, " << functionCount - << " functions, " << totalItemCount << " items)\n"; - - // Add all functions to the zone state to make them available for all menus to be converted - for (auto& function : parsingResult->m_functions) - zoneState->AddFunction(std::move(function)); - - // Prepare a list of all menus of this file - std::vector*> allMenusOfFile; - allMenusOfFile.reserve(parsingResult->m_menus.size()); - - // Convert all menus and add them as assets - for (auto& menu : parsingResult->m_menus) - { - MenuConverter converter(ObjLoading::Configuration.MenuNoOptimization, searchPath, memory, manager); - auto* menuAsset = converter.ConvertMenu(*menu); - if (menuAsset == nullptr) - { - std::cout << "Failed to convert menu file \"" << menu->m_name << "\"\n"; - return false; - } - - menus.push_back(menuAsset); - auto* menuAssetInfo = manager->AddAsset(menu->m_name, menuAsset, std::move(converter.GetDependencies())); - - if (menuAssetInfo) - { - allMenusOfFile.push_back(menuAssetInfo); - menuListDependencies.push_back(menuAssetInfo); - } - - zoneState->AddMenu(std::move(menu)); - } - - // Register this file with all loaded menus - conversionState->AddLoadedFile(fileName, std::move(allMenusOfFile)); - - return true; - } - - static MenuList* CreateMenuListAsset(const std::string& assetName, MemoryManager* memory, const std::vector& menus) - { - auto* menuListAsset = memory->Create(); - menuListAsset->name = memory->Dup(assetName.c_str()); - menuListAsset->menuCount = static_cast(menus.size()); - - if (menuListAsset->menuCount > 0) - { - menuListAsset->menus = memory->Alloc(menuListAsset->menuCount); - for (auto i = 0; i < menuListAsset->menuCount; i++) - menuListAsset->menus[i] = menus[i]; - } - else - menuListAsset->menus = nullptr; - - return menuListAsset; - } - - static std::unique_ptr - ParseMenuFile(const std::string& menuFileName, ISearchPath* searchPath, const menu::MenuAssetZoneState* zoneState) - { - const auto file = searchPath->Open(menuFileName); - if (!file.IsOpen()) - return nullptr; - - menu::MenuFileReader reader(*file.m_stream, - menuFileName, - menu::FeatureLevel::IW4, - [searchPath](const std::string& filename, const std::string& sourceFile) -> std::unique_ptr - { - auto foundFileToInclude = searchPath->Open(filename); - if (!foundFileToInclude.IsOpen() || !foundFileToInclude.m_stream) - return nullptr; - - return std::move(foundFileToInclude.m_stream); - }); - - reader.IncludeZoneState(zoneState); - reader.SetPermissiveMode(ObjLoading::Configuration.MenuPermissiveParsing); - - return reader.ReadMenuFile(); - } - }; -} // namespace IW4 - -void* AssetLoaderMenuList::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* menuList = memory->Create(); - memset(menuList, 0, sizeof(MenuList)); - menuList->name = memory->Dup(assetName.c_str()); - return menuList; -} - -bool AssetLoaderMenuList::CanLoadFromRaw() const -{ - return true; -} - -bool BuildMenuFileQueue(std::deque& menuLoadQueue, - const std::string& menuListAssetName, - ISearchPath* searchPath, - MemoryManager* memory, - IAssetLoadingManager* manager, - menu::MenuAssetZoneState* zoneState, - MenuConversionZoneState* conversionState, - std::vector& menus, - std::vector& menuListDependencies) -{ - const auto alreadyLoadedMenuListFileMenus = conversionState->m_menus_by_filename.find(menuListAssetName); - - if (alreadyLoadedMenuListFileMenus == conversionState->m_menus_by_filename.end()) - { - const auto menuListResult = MenuLoader::ParseMenuFile(menuListAssetName, searchPath, zoneState); - if (menuListResult) - { - MenuLoader::ProcessParsedResults( - menuListAssetName, searchPath, memory, manager, menuListResult.get(), zoneState, conversionState, menus, menuListDependencies); - - for (const auto& menuToLoad : menuListResult->m_menus_to_load) - menuLoadQueue.push_back(menuToLoad); - - zoneState->AddMenusToLoad(menuListAssetName, std::move(menuListResult->m_menus_to_load)); - } - else - return false; - } - - return true; -} - -void LoadMenuFileFromQueue(const std::string& menuFilePath, - ISearchPath* searchPath, - MemoryManager* memory, - IAssetLoadingManager* manager, - menu::MenuAssetZoneState* zoneState, - MenuConversionZoneState* conversionState, - std::vector& menus, - std::vector& menuListDependencies) -{ - const auto alreadyLoadedMenuFile = conversionState->m_menus_by_filename.find(menuFilePath); - if (alreadyLoadedMenuFile != conversionState->m_menus_by_filename.end()) - { - std::cout << "Already loaded \"" << menuFilePath << "\", skipping\n"; - for (auto* menu : alreadyLoadedMenuFile->second) - { - menus.push_back(menu->Asset()); - menuListDependencies.push_back(menu); - } - return; - } - - const auto menuFileResult = MenuLoader::ParseMenuFile(menuFilePath, searchPath, zoneState); - if (menuFileResult) - { - MenuLoader::ProcessParsedResults( - menuFilePath, searchPath, memory, manager, menuFileResult.get(), zoneState, conversionState, menus, menuListDependencies); - if (!menuFileResult->m_menus_to_load.empty()) - std::cout << "WARNING: Menu file has menus to load even though it is not a menu list, ignoring: \"" << menuFilePath << "\"\n"; - } - else - std::cerr << "Could not read menu file \"" << menuFilePath << "\"\n"; -} - -bool AssetLoaderMenuList::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - std::vector menus; - std::vector menuListDependencies; - - auto* zoneState = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState(); - auto* conversionState = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState(); - - std::deque menuLoadQueue; - if (!BuildMenuFileQueue(menuLoadQueue, assetName, searchPath, memory, manager, zoneState, conversionState, menus, menuListDependencies)) - return false; - - while (!menuLoadQueue.empty()) - { - const auto& menuFileToLoad = menuLoadQueue.front(); - - LoadMenuFileFromQueue(menuFileToLoad, searchPath, memory, manager, zoneState, conversionState, menus, menuListDependencies); - - menuLoadQueue.pop_front(); - } - - auto* menuListAsset = MenuLoader::CreateMenuListAsset(assetName, memory, menus); - - if (menuListAsset) - manager->AddAsset(assetName, menuListAsset, menuListDependencies); - - return true; -} - -void AssetLoaderMenuList::FinalizeAssetsForZone(AssetLoadingContext& context) const -{ - context.GetZoneAssetLoaderState()->FinalizeSupportingData(); -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.h deleted file mode 100644 index 61f45486d..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderMenuList final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - void FinalizeAssetsForZone(AssetLoadingContext& context) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.cpp deleted file mode 100644 index 805e14aaa..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderPhysCollmap.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderPhysCollmap::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* collmap = memory->Create(); - memset(collmap, 0, sizeof(PhysCollmap)); - collmap->name = memory->Dup(assetName.c_str()); - return collmap; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.h deleted file mode 100644 index 86cbed6c6..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysCollmap.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderPhysCollmap final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.cpp deleted file mode 100644 index 6f08e0c47..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "AssetLoaderPhysPreset.h" - -#include "Game/IW4/IW4.h" -#include "Game/IW4/InfoString/InfoStringToStructConverter.h" -#include "Game/IW4/InfoString/PhysPresetFields.h" -#include "Game/IW4/ObjConstantsIW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace IW4; - -namespace IW4 -{ - class InfoStringToPhysPresetConverter final : public InfoStringToStructConverter - { - protected: - bool ConvertExtensionField(const cspField_t& field, const std::string& value) override - { - assert(false); - return false; - } - - public: - InfoStringToPhysPresetConverter(const InfoString& infoString, - PhysPresetInfo* physPreset, - ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, - const cspField_t* fields, - const size_t fieldCount) - : InfoStringToStructConverter(infoString, physPreset, zoneScriptStrings, memory, manager, fields, fieldCount) - { - } - }; -} // namespace IW4 - -void AssetLoaderPhysPreset::CopyFromPhysPresetInfo(const PhysPresetInfo* physPresetInfo, PhysPreset* physPreset) -{ - physPreset->mass = std::clamp(physPresetInfo->mass, 1.0f, 2000.0f) * 0.001f; - physPreset->bounce = physPresetInfo->bounce; - - if (physPresetInfo->isFrictionInfinity != 0) - physPreset->friction = std::numeric_limits::infinity(); - else - physPreset->friction = physPresetInfo->friction; - - physPreset->bulletForceScale = physPresetInfo->bulletForceScale; - physPreset->explosiveForceScale = physPresetInfo->explosiveForceScale; - physPreset->sndAliasPrefix = physPresetInfo->sndAliasPrefix; - physPreset->piecesSpreadFraction = physPresetInfo->piecesSpreadFraction; - physPreset->piecesUpwardVelocity = physPresetInfo->piecesUpwardVelocity; - physPreset->tempDefaultToCylinder = physPresetInfo->tempDefaultToCylinder != 0; - physPreset->perSurfaceSndAlias = physPresetInfo->perSurfaceSndAlias != 0; -} - -bool AssetLoaderPhysPreset::LoadFromInfoString( - const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) -{ - const auto presetInfo = std::make_unique(); - memset(presetInfo.get(), 0, sizeof(PhysPresetInfo)); - InfoStringToPhysPresetConverter converter( - infoString, presetInfo.get(), zone->m_script_strings, memory, manager, phys_preset_fields, std::extent_v); - if (!converter.Convert()) - { - std::cout << "Failed to parse phys preset: \"" << assetName << "\"\n"; - return true; - } - - auto* physPreset = memory->Create(); - - CopyFromPhysPresetInfo(presetInfo.get(), physPreset); - physPreset->name = memory->Dup(assetName.c_str()); - - manager->AddAsset(assetName, physPreset, converter.GetDependencies(), converter.GetUsedScriptStrings()); - - return true; -} - -void* AssetLoaderPhysPreset::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* physPreset = memory->Create(); - memset(physPreset, 0, sizeof(PhysPreset)); - physPreset->name = memory->Dup(assetName.c_str()); - return physPreset; -} - -bool AssetLoaderPhysPreset::CanLoadFromGdt() const -{ - return true; -} - -bool AssetLoaderPhysPreset::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_PRESET, assetName); - if (gdtEntry == nullptr) - return false; - - InfoString infoString; - if (!infoString.FromGdtProperties(*gdtEntry)) - { - std::cout << "Failed to read phys preset gdt entry: \"" << assetName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} - -bool AssetLoaderPhysPreset::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderPhysPreset::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = "physic/" + assetName; - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - InfoString infoString; - if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream)) - { - std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n"; - return true; - } - - return LoadFromInfoString(infoString, assetName, memory, manager, zone); -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.h deleted file mode 100644 index 4d3730bb9..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPhysPreset.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "InfoString/InfoString.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderPhysPreset final : public BasicAssetLoader - { - static void CopyFromPhysPresetInfo(const PhysPresetInfo* physPresetInfo, PhysPreset* physPreset); - - static bool - LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromGdt() const override; - bool LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.cpp deleted file mode 100644 index e034f6da7..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "AssetLoaderPixelShader.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include -#include - -using namespace IW4; - -void* AssetLoaderPixelShader::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* pixelShader = memory->Create(); - memset(pixelShader, 0, sizeof(MaterialPixelShader)); - pixelShader->name = memory->Dup(assetName.c_str()); - return pixelShader; -} - -bool AssetLoaderPixelShader::CanLoadFromRaw() const -{ - return true; -} - -std::string AssetLoaderPixelShader::GetFileNameForAsset(const std::string& assetName) -{ - std::ostringstream ss; - ss << "shader_bin/ps_" << assetName << ".cso"; - return ss.str(); -} - -bool AssetLoaderPixelShader::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = GetFileNameForAsset(assetName); - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - if (file.m_length % sizeof(uint32_t) != 0) - { - std::cerr << "Invalid pixel shader \"" << assetName << "\": Size must be dividable by " << sizeof(uint32_t) << "\n"; - return false; - } - - auto* pixelShader = memory->Create(); - pixelShader->name = memory->Dup(assetName.c_str()); - pixelShader->prog.loadDef.programSize = static_cast(static_cast(file.m_length) / sizeof(uint32_t)); - pixelShader->prog.loadDef.loadForRenderer = 0; - pixelShader->prog.ps = nullptr; - - auto* fileBuffer = memory->Alloc(pixelShader->prog.loadDef.programSize); - file.m_stream->read(reinterpret_cast(fileBuffer), static_cast(pixelShader->prog.loadDef.programSize) * sizeof(uint32_t)); - if (file.m_stream->gcount() != file.m_length) - return false; - - pixelShader->prog.loadDef.program = fileBuffer; - manager->AddAsset(assetName, pixelShader); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.h deleted file mode 100644 index 3ac44c5ca..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderPixelShader.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -#include - -namespace IW4 -{ - class AssetLoaderPixelShader final : public BasicAssetLoader - { - public: - _NODISCARD static std::string GetFileNameForAsset(const std::string& assetName); - - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.cpp deleted file mode 100644 index 20db51ad0..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "AssetLoaderRawFile.h" - -#include "Game/IW4/IW4.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include -#include - -using namespace IW4; - -void* AssetLoaderRawFile::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* rawFile = memory->Create(); - memset(rawFile, 0, sizeof(RawFile)); - rawFile->name = memory->Dup(assetName.c_str()); - return rawFile; -} - -bool AssetLoaderRawFile::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderRawFile::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - const auto uncompressedBuffer = std::make_unique(static_cast(file.m_length)); - file.m_stream->read(uncompressedBuffer.get(), file.m_length); - if (file.m_stream->gcount() != file.m_length) - return false; - - const auto compressionBufferSize = static_cast(file.m_length + COMPRESSED_BUFFER_SIZE_PADDING); - auto* compressedBuffer = memory->Alloc(compressionBufferSize); - - z_stream_s zs{}; - - zs.zalloc = Z_NULL; - zs.zfree = Z_NULL; - zs.opaque = Z_NULL; - zs.avail_in = static_cast(file.m_length); - zs.avail_out = compressionBufferSize; - zs.next_in = reinterpret_cast(uncompressedBuffer.get()); - zs.next_out = reinterpret_cast(compressedBuffer); - - int ret = deflateInit(&zs, Z_DEFAULT_COMPRESSION); - - if (ret != Z_OK) - { - throw std::runtime_error("Initializing deflate failed"); - } - - ret = deflate(&zs, Z_FINISH); - - if (ret != Z_STREAM_END) - { - std::cerr << "Deflate failed for loading rawfile \"" << assetName << "\"\n"; - deflateEnd(&zs); - return false; - } - - const auto compressedSize = compressionBufferSize - zs.avail_out; - - auto* rawFile = memory->Create(); - rawFile->name = memory->Dup(assetName.c_str()); - rawFile->compressedLen = static_cast(compressedSize); - rawFile->len = static_cast(file.m_length); - rawFile->data.compressedBuffer = static_cast(compressedBuffer); - - deflateEnd(&zs); - - manager->AddAsset(assetName, rawFile); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.h deleted file mode 100644 index c8b558ccd..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderRawFile.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "AssetLoading/BasicAssetLoader.h" -#include "AssetLoading/IAssetLoadingManager.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderRawFile final : public BasicAssetLoader - { - static constexpr size_t COMPRESSED_BUFFER_SIZE_PADDING = 64; - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.cpp deleted file mode 100644 index e21d51905..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "AssetLoaderSndCurve.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" -#include "Sound/SoundCurveLoader.h" - -#include -#include -#include - -using namespace IW4; - -void* AssetLoaderSndCurve::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* sndCurve = memory->Create(); - memset(sndCurve, 0, sizeof(SndCurve)); - sndCurve->filename = memory->Dup(assetName.c_str()); - return sndCurve; -} - -bool AssetLoaderSndCurve::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderSndCurve::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto sndCurveData = sound_curve::LoadSoundCurve(manager, assetName); - - if (!sndCurveData) - return false; - - if (sndCurveData->knots.size() > std::extent_v) - { - std::cerr << "Failed to load SndCurve \"" << assetName << "\": Too many knots (" << sndCurveData->knots.size() << ")\n"; - return false; - } - - auto* sndCurve = memory->Create(); - sndCurve->filename = memory->Dup(assetName.c_str()); - sndCurve->knotCount = static_cast(sndCurveData->knots.size()); - - for (auto i = 0u; i < std::extent_v; i++) - { - if (i < sndCurveData->knots.size()) - { - const auto& [x, y] = sndCurveData->knots[i]; - sndCurve->knots[i][0] = static_cast(x); - sndCurve->knots[i][1] = static_cast(y); - } - else - { - sndCurve->knots[i][0] = 0; - sndCurve->knots[i][1] = 0; - } - } - - manager->AddAsset(assetName, sndCurve); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.h deleted file mode 100644 index 1d184ef1d..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSndCurve.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderSndCurve final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.cpp deleted file mode 100644 index 290ba1c91..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderSoundAliasList.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderSoundAliasList::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* sndAliasList = memory->Create(); - memset(sndAliasList, 0, sizeof(snd_alias_list_t)); - sndAliasList->aliasName = memory->Dup(assetName.c_str()); - return sndAliasList; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.h deleted file mode 100644 index 86177d8b2..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderSoundAliasList.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderSoundAliasList final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.cpp deleted file mode 100644 index 081216610..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "AssetLoaderStringTable.h" - -#include "Csv/CsvStream.h" -#include "Game/IW4/CommonIW4.h" -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" -#include "StringTable/StringTableLoader.h" - -#include - -using namespace IW4; - -void* AssetLoaderStringTable::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* stringTable = memory->Create(); - memset(stringTable, 0, sizeof(StringTable)); - stringTable->name = memory->Dup(assetName.c_str()); - return stringTable; -} - -bool AssetLoaderStringTable::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderStringTable::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - string_table::StringTableLoaderV2 loader; - auto* stringTable = loader.LoadFromStream(assetName, *memory, *file.m_stream); - - manager->AddAsset(assetName, stringTable); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.h deleted file mode 100644 index 19fe5caaa..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStringTable.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderStringTable final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.cpp deleted file mode 100644 index ee5c81835..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include "AssetLoaderStructuredDataDefSet.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" -#include "StructuredDataDef/StructuredDataDefReader.h" -#include "Utils/Alignment.h" - -#include - -using namespace IW4; - -void* AssetLoaderStructuredDataDefSet::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* structuredDataDefSet = memory->Create(); - memset(structuredDataDefSet, 0, sizeof(StructuredDataDefSet)); - structuredDataDefSet->name = memory->Dup(assetName.c_str()); - return structuredDataDefSet; -} - -bool AssetLoaderStructuredDataDefSet::CanLoadFromRaw() const -{ - return true; -} - -StructuredDataType AssetLoaderStructuredDataDefSet::ConvertType(CommonStructuredDataType inputType) -{ - switch (inputType.m_category) - { - case CommonStructuredDataTypeCategory::INT: - return {DATA_INT, {0}}; - case CommonStructuredDataTypeCategory::BYTE: - return {DATA_BYTE, {0}}; - case CommonStructuredDataTypeCategory::BOOL: - return {DATA_BOOL, {0}}; - case CommonStructuredDataTypeCategory::FLOAT: - return {DATA_FLOAT, {0}}; - case CommonStructuredDataTypeCategory::SHORT: - return {DATA_SHORT, {0}}; - case CommonStructuredDataTypeCategory::STRING: - return {DATA_STRING, {inputType.m_info.string_length}}; - case CommonStructuredDataTypeCategory::ENUM: - return {DATA_ENUM, {inputType.m_info.type_index}}; - case CommonStructuredDataTypeCategory::STRUCT: - return {DATA_STRUCT, {inputType.m_info.type_index}}; - case CommonStructuredDataTypeCategory::INDEXED_ARRAY: - return {DATA_INDEXED_ARRAY, {inputType.m_info.type_index}}; - case CommonStructuredDataTypeCategory::ENUM_ARRAY: - return {DATA_ENUM_ARRAY, {inputType.m_info.type_index}}; - case CommonStructuredDataTypeCategory::UNKNOWN: - default: - assert(false); - return {DATA_INT, {0}}; - } -} - -void AssetLoaderStructuredDataDefSet::ConvertEnum(StructuredDataEnum* outputEnum, CommonStructuredDataEnum* inputEnum, MemoryManager* memory) -{ - outputEnum->entryCount = static_cast(inputEnum->m_entries.size()); - if (inputEnum->m_reserved_entry_count <= 0) - outputEnum->reservedEntryCount = outputEnum->entryCount; - else - outputEnum->reservedEntryCount = inputEnum->m_reserved_entry_count; - - inputEnum->SortEntriesByName(); - if (!inputEnum->m_entries.empty()) - { - outputEnum->entries = memory->Alloc(inputEnum->m_entries.size()); - for (auto entryIndex = 0u; entryIndex < inputEnum->m_entries.size(); entryIndex++) - { - auto& outputEntry = outputEnum->entries[entryIndex]; - const auto& inputEntry = inputEnum->m_entries[entryIndex]; - - outputEntry.string = memory->Dup(inputEntry.m_name.c_str()); - outputEntry.index = static_cast(inputEntry.m_value); - } - } - else - outputEnum->entries = nullptr; -} - -void AssetLoaderStructuredDataDefSet::ConvertStruct(StructuredDataStruct* outputStruct, CommonStructuredDataStruct* inputStruct, MemoryManager* memory) -{ - outputStruct->size = static_cast(inputStruct->m_size_in_byte); - outputStruct->bitOffset = inputStruct->m_bit_offset; - - outputStruct->propertyCount = static_cast(inputStruct->m_properties.size()); - inputStruct->SortPropertiesByName(); - if (!inputStruct->m_properties.empty()) - { - outputStruct->properties = memory->Alloc(inputStruct->m_properties.size()); - for (auto propertyIndex = 0u; propertyIndex < inputStruct->m_properties.size(); propertyIndex++) - { - auto& outputProperty = outputStruct->properties[propertyIndex]; - const auto& inputProperty = inputStruct->m_properties[propertyIndex]; - - outputProperty.name = memory->Dup(inputProperty.m_name.c_str()); - outputProperty.type = ConvertType(inputProperty.m_type); - - if (outputProperty.type.type != DATA_BOOL) - { - assert(inputProperty.m_offset_in_bits % 8 == 0); - outputProperty.offset = inputProperty.m_offset_in_bits / 8; - } - else - outputProperty.offset = inputProperty.m_offset_in_bits; - } - } - else - outputStruct->properties = nullptr; -} - -void AssetLoaderStructuredDataDefSet::ConvertIndexedArray(StructuredDataIndexedArray* outputIndexedArray, - const CommonStructuredDataIndexedArray* inputIndexedArray, - MemoryManager* memory) -{ - outputIndexedArray->arraySize = static_cast(inputIndexedArray->m_element_count); - outputIndexedArray->elementType = ConvertType(inputIndexedArray->m_array_type); - outputIndexedArray->elementSize = utils::Align(inputIndexedArray->m_element_size_in_bits, 8u) / 8u; -} - -void AssetLoaderStructuredDataDefSet::ConvertEnumedArray(StructuredDataEnumedArray* outputEnumedArray, - const CommonStructuredDataEnumedArray* inputEnumedArray, - MemoryManager* memory) -{ - outputEnumedArray->enumIndex = static_cast(inputEnumedArray->m_enum_index); - outputEnumedArray->elementType = ConvertType(inputEnumedArray->m_array_type); - outputEnumedArray->elementSize = utils::Align(inputEnumedArray->m_element_size_in_bits, 8u) / 8u; -} - -void AssetLoaderStructuredDataDefSet::ConvertDef(StructuredDataDef* outputDef, const CommonStructuredDataDef* inputDef, MemoryManager* memory) -{ - outputDef->version = inputDef->m_version; - outputDef->formatChecksum = inputDef->m_checksum; - - outputDef->enumCount = static_cast(inputDef->m_enums.size()); - if (!inputDef->m_enums.empty()) - { - outputDef->enums = memory->Alloc(inputDef->m_enums.size()); - for (auto enumIndex = 0u; enumIndex < inputDef->m_enums.size(); enumIndex++) - ConvertEnum(&outputDef->enums[enumIndex], inputDef->m_enums[enumIndex].get(), memory); - } - else - outputDef->enums = nullptr; - - outputDef->structCount = static_cast(inputDef->m_structs.size()); - if (!inputDef->m_structs.empty()) - { - outputDef->structs = memory->Alloc(inputDef->m_structs.size()); - for (auto structIndex = 0u; structIndex < inputDef->m_structs.size(); structIndex++) - ConvertStruct(&outputDef->structs[structIndex], inputDef->m_structs[structIndex].get(), memory); - } - else - outputDef->structs = nullptr; - - outputDef->indexedArrayCount = static_cast(inputDef->m_indexed_arrays.size()); - if (!inputDef->m_indexed_arrays.empty()) - { - outputDef->indexedArrays = memory->Alloc(inputDef->m_indexed_arrays.size()); - for (auto indexedArrayIndex = 0u; indexedArrayIndex < inputDef->m_indexed_arrays.size(); indexedArrayIndex++) - ConvertIndexedArray(&outputDef->indexedArrays[indexedArrayIndex], &inputDef->m_indexed_arrays[indexedArrayIndex], memory); - } - else - outputDef->indexedArrays = nullptr; - - outputDef->enumedArrayCount = static_cast(inputDef->m_enumed_arrays.size()); - if (!inputDef->m_enumed_arrays.empty()) - { - outputDef->enumedArrays = memory->Alloc(inputDef->m_enumed_arrays.size()); - for (auto enumedArrayIndex = 0u; enumedArrayIndex < inputDef->m_enumed_arrays.size(); enumedArrayIndex++) - ConvertEnumedArray(&outputDef->enumedArrays[enumedArrayIndex], &inputDef->m_enumed_arrays[enumedArrayIndex], memory); - } - else - outputDef->enumedArrays = nullptr; - - outputDef->rootType = ConvertType(inputDef->m_root_type); - outputDef->size = inputDef->m_size_in_byte; -} - -StructuredDataDefSet* AssetLoaderStructuredDataDefSet::ConvertSet(const std::string& assetName, - const std::vector>& defs, - MemoryManager* memory) -{ - auto* set = memory->Create(); - set->name = memory->Dup(assetName.c_str()); - set->defCount = defs.size(); - set->defs = memory->Alloc(defs.size()); - - for (auto defIndex = 0u; defIndex < defs.size(); defIndex++) - ConvertDef(&set->defs[defIndex], defs[defIndex].get(), memory); - - return set; -} - -bool AssetLoaderStructuredDataDefSet::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto file = searchPath->Open(assetName); - if (!file.IsOpen()) - return false; - - StructuredDataDefReader reader(*file.m_stream, - assetName, - [searchPath](const std::string& filename, const std::string& sourceFile) -> std::unique_ptr - { - auto foundFileToInclude = searchPath->Open(filename); - if (!foundFileToInclude.IsOpen() || !foundFileToInclude.m_stream) - return nullptr; - - return std::move(foundFileToInclude.m_stream); - }); - - bool readingDefsSuccessful; - const auto defs = reader.ReadStructureDataDefs(readingDefsSuccessful); - - if (readingDefsSuccessful) - manager->AddAsset(assetName, ConvertSet(assetName, defs, memory)); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.h deleted file mode 100644 index ef57fc8ec..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderStructuredDataDefSet.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" -#include "StructuredDataDef/CommonStructuredDataDef.h" - -namespace IW4 -{ - class AssetLoaderStructuredDataDefSet final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - static StructuredDataType ConvertType(CommonStructuredDataType inputType); - static void ConvertEnum(StructuredDataEnum* outputEnum, CommonStructuredDataEnum* inputEnum, MemoryManager* memory); - static void ConvertStruct(StructuredDataStruct* outputStruct, CommonStructuredDataStruct* inputStruct, MemoryManager* memory); - static void ConvertIndexedArray(StructuredDataIndexedArray* outputIndexedArray, - const CommonStructuredDataIndexedArray* inputIndexedArray, - MemoryManager* memory); - static void - ConvertEnumedArray(StructuredDataEnumedArray* outputEnumedArray, const CommonStructuredDataEnumedArray* inputEnumedArray, MemoryManager* memory); - static void ConvertDef(StructuredDataDef* outputDef, const CommonStructuredDataDef* inputDef, MemoryManager* memory); - static StructuredDataDefSet* - ConvertSet(const std::string& assetName, const std::vector>& defs, MemoryManager* memory); - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.h deleted file mode 100644 index e66a9d67f..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" -#include "StateMap/StateMapDefinition.h" -#include "Techset/TechniqueStateMapCache.h" -#include "Techset/TechsetDefinition.h" -#include "Techset/TechsetDefinitionCache.h" - -namespace IW4 -{ - class AssetLoaderTechniqueSet final : public BasicAssetLoader - { - static bool CreateTechsetFromDefinition(const std::string& assetName, - const techset::TechsetDefinition& definition, - ISearchPath* searchPath, - MemoryManager* memory, - IAssetLoadingManager* manager); - - public: - static std::string GetTechsetFileName(const std::string& techsetAssetName); - static std::string GetTechniqueFileName(const std::string& techniqueName); - static std::string GetStateMapFileName(const std::string& stateMapName); - - static techset::TechsetDefinition* - LoadTechsetDefinition(const std::string& assetName, ISearchPath* searchPath, techset::TechsetDefinitionCache* definitionCache); - static const state_map::StateMapDefinition* - LoadStateMapDefinition(const std::string& stateMapName, ISearchPath* searchPath, techset::TechniqueStateMapCache* stateMapCache); - - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.cpp deleted file mode 100644 index bbce11b8a..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderTracer.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderTracer::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* tracer = memory->Create(); - memset(tracer, 0, sizeof(TracerDef)); - tracer->name = memory->Dup(assetName.c_str()); - return tracer; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.h deleted file mode 100644 index c501ad39d..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTracer.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderTracer final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.cpp deleted file mode 100644 index 343bd8908..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderVehicle.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderVehicle::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* vehicle = memory->Create(); - memset(vehicle, 0, sizeof(VehicleDef)); - vehicle->name = memory->Dup(assetName.c_str()); - return vehicle; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.h deleted file mode 100644 index d260d8533..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVehicle.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderVehicle final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.cpp deleted file mode 100644 index 8f616e492..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "AssetLoaderVertexDecl.h" - -#include "Game/IW4/IW4.h" -#include "Game/IW4/TechsetConstantsIW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include - -using namespace IW4; - -void* AssetLoaderVertexDecl::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* vertexDecl = memory->Create(); - memset(vertexDecl, 0, sizeof(MaterialVertexDeclaration)); - vertexDecl->name = memory->Dup(assetName.c_str()); - return vertexDecl; -} - -bool AssetLoaderVertexDecl::CanLoadFromRaw() const -{ - return true; -} - -bool AssetLoaderVertexDecl::NextAbbreviation(const std::string& assetName, std::string& abbreviation, size_t& offset) -{ - if (offset >= assetName.size()) - return false; - - if (offset + 1 < assetName.size() && isdigit(assetName[offset + 1])) - { - abbreviation = std::string(assetName, offset, 2); - offset += 2; - } - else - { - abbreviation = std::string(assetName, offset, 1); - offset += 1; - } - - return true; -} - -bool AssetLoaderVertexDecl::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - MaterialVertexDeclaration decl{}; - - size_t currentOffset = 0u; - - if (!assetName.empty() && assetName[0] == ',') - currentOffset = 1u; - - std::string sourceAbbreviation; - while (NextAbbreviation(assetName, sourceAbbreviation, currentOffset)) - { - if (decl.streamCount >= std::extent_v) - { - std::cout << "Failed to add vertex decl stream. Too many abbreviations: " << assetName << "\n"; - return false; - } - - std::string destinationAbbreviation; - if (!NextAbbreviation(assetName, destinationAbbreviation, currentOffset)) - { - std::cout << "Failed to detect vertex decl destination abbreviation: " << assetName << "\n"; - return false; - } - - const auto foundSourceAbbreviation = std::ranges::find(materialStreamSourceAbbreviation, sourceAbbreviation); - if (foundSourceAbbreviation == std::end(materialStreamSourceAbbreviation)) - { - std::cout << "Unknown vertex decl source abbreviation: " << sourceAbbreviation << "\n"; - return false; - } - - const auto foundDestinationAbbreviation = std::ranges::find(materialStreamDestinationAbbreviation, destinationAbbreviation); - if (foundDestinationAbbreviation == std::end(materialStreamDestinationAbbreviation)) - { - std::cout << "Unknown vertex decl destination abbreviation: " << destinationAbbreviation << "\n"; - return false; - } - - const auto sourceIndex = static_cast(foundSourceAbbreviation - std::begin(materialStreamSourceAbbreviation)); - const auto destinationIndex = - static_cast(foundDestinationAbbreviation - std::begin(materialStreamDestinationAbbreviation)); - - decl.routing.data[decl.streamCount].source = sourceIndex; - decl.routing.data[decl.streamCount].dest = destinationIndex; - decl.hasOptionalSource = decl.hasOptionalSource || sourceIndex >= STREAM_SRC_OPTIONAL_BEGIN; - decl.streamCount++; - } - - decl.name = memory->Dup(assetName.c_str()); - - auto* allocatedDecl = memory->Create(decl); - - manager->AddAsset(assetName, allocatedDecl); - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.h deleted file mode 100644 index 939c3a8c9..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexDecl.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderVertexDecl final : public BasicAssetLoader - { - static bool NextAbbreviation(const std::string& assetName, std::string& abbreviation, size_t& offset); - - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.cpp deleted file mode 100644 index 07df2b0ae..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "AssetLoaderVertexShader.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include -#include - -using namespace IW4; - -void* AssetLoaderVertexShader::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* vertexShader = memory->Create(); - memset(vertexShader, 0, sizeof(MaterialVertexShader)); - vertexShader->name = memory->Dup(assetName.c_str()); - return vertexShader; -} - -bool AssetLoaderVertexShader::CanLoadFromRaw() const -{ - return true; -} - -std::string AssetLoaderVertexShader::GetFileNameForAsset(const std::string& assetName) -{ - std::ostringstream ss; - ss << "shader_bin/vs_" << assetName << ".cso"; - return ss.str(); -} - -bool AssetLoaderVertexShader::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto fileName = GetFileNameForAsset(assetName); - const auto file = searchPath->Open(fileName); - if (!file.IsOpen()) - return false; - - if (file.m_length % sizeof(uint32_t) != 0) - { - std::cerr << "Invalid vertex shader \"" << assetName << "\": Size must be dividable by " << sizeof(uint32_t) << "\n"; - return false; - } - - auto* vertexShader = memory->Create(); - vertexShader->name = memory->Dup(assetName.c_str()); - vertexShader->prog.loadDef.programSize = static_cast(static_cast(file.m_length) / sizeof(uint32_t)); - vertexShader->prog.loadDef.loadForRenderer = 0; - vertexShader->prog.vs = nullptr; - - auto* fileBuffer = memory->Alloc(vertexShader->prog.loadDef.programSize); - file.m_stream->read(reinterpret_cast(fileBuffer), static_cast(vertexShader->prog.loadDef.programSize) * sizeof(uint32_t)); - if (file.m_stream->gcount() != file.m_length) - return false; - - vertexShader->prog.loadDef.program = fileBuffer; - manager->AddAsset(assetName, vertexShader); - - return true; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.h deleted file mode 100644 index 6a72596b4..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderVertexShader.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderVertexShader final : public BasicAssetLoader - { - public: - _NODISCARD static std::string GetFileNameForAsset(const std::string& assetName); - - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - _NODISCARD bool CanLoadFromRaw() const override; - bool - LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.cpp deleted file mode 100644 index 0f7ca8dc5..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderXAnim.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderXAnim::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* anim = memory->Create(); - memset(anim, 0, sizeof(XAnimParts)); - anim->name = memory->Dup(assetName.c_str()); - return anim; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.h deleted file mode 100644 index a44bbdb70..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXAnim.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderXAnim final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.cpp deleted file mode 100644 index b30da93d8..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderXModel.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderXModel::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* model = memory->Create(); - memset(model, 0, sizeof(XModel)); - model->name = memory->Dup(assetName.c_str()); - return model; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.h deleted file mode 100644 index 50af413d1..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModel.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderXModel final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.cpp deleted file mode 100644 index 7adf87f90..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "AssetLoaderXModelSurfs.h" - -#include "Game/IW4/IW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" - -#include - -using namespace IW4; - -void* AssetLoaderXModelSurfs::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* modelSurfs = memory->Create(); - memset(modelSurfs, 0, sizeof(XModelSurfs)); - modelSurfs->name = memory->Dup(assetName.c_str()); - return modelSurfs; -} diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.h b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.h deleted file mode 100644 index d7751ae38..000000000 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderXModelSurfs.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "AssetLoading/BasicAssetLoader.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" - -namespace IW4 -{ - class AssetLoaderXModelSurfs final : public BasicAssetLoader - { - public: - _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.cpp b/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.cpp index 4ac8d81a5..c8472e1d3 100644 --- a/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.cpp +++ b/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.cpp @@ -1,6 +1,7 @@ #include "InfoStringToStructConverter.h" #include +#include #include using namespace IW4; @@ -8,12 +9,12 @@ using namespace IW4; InfoStringToStructConverter::InfoStringToStructConverter(const InfoString& infoString, void* structure, ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, + MemoryManager& memory, + AssetCreationContext& context, + GenericAssetRegistration& registration, const cspField_t* fields, const size_t fieldCount) - : InfoStringToStructConverterBase(infoString, structure, zoneScriptStrings, memory), - m_loading_manager(manager), + : InfoStringToStructConverterBase(infoString, structure, zoneScriptStrings, memory, context, registration), m_fields(fields), m_field_count(fieldCount) { @@ -58,15 +59,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* fx = m_loading_manager->LoadDependency(value); + auto* fx = m_context.LoadDependency(value); if (fx == nullptr) { - std::cout << "Failed to load fx asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load fx asset \"{}\"\n", value); return false; } - m_dependencies.emplace(fx); + m_registration.AddDependency(fx); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = fx->Asset(); return true; @@ -80,15 +81,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* xmodel = m_loading_manager->LoadDependency(value); + auto* xmodel = m_context.LoadDependency(value); if (xmodel == nullptr) { - std::cout << "Failed to load xmodel asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load xmodel asset \"{}\"\n", value); return false; } - m_dependencies.emplace(xmodel); + m_registration.AddDependency(xmodel); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = xmodel->Asset(); return true; @@ -102,15 +103,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* material = m_loading_manager->LoadDependency(value); + auto* material = m_context.LoadDependency(value); if (material == nullptr) { - std::cout << "Failed to load material asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load material asset \"{}\"\n", value); return false; } - m_dependencies.emplace(material); + m_registration.AddDependency(material); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = material->Asset(); return true; @@ -124,15 +125,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* tracer = m_loading_manager->LoadDependency(value); + auto* tracer = m_context.LoadDependency(value); if (tracer == nullptr) { - std::cout << "Failed to load tracer asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load tracer asset \"{}\"\n", value); return false; } - m_dependencies.emplace(tracer); + m_registration.AddDependency(tracer); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = tracer->Asset(); return true; @@ -145,7 +146,7 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as mph\n"; + std::cerr << std::format("Failed to parse value \"{}\" as mph\n", value); return false; } @@ -160,15 +161,15 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* collmap = m_loading_manager->LoadDependency(value); + auto* collmap = m_context.LoadDependency(value); if (collmap == nullptr) { - std::cout << "Failed to load collmap asset \"" << value << "\"\n"; + std::cerr << std::format("Failed to load collmap asset \"{}\"\n", value); return false; } - m_dependencies.emplace(collmap); + m_registration.AddDependency(collmap); *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset) = collmap->Asset(); return true; @@ -182,12 +183,12 @@ bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, cons return true; } - auto* name = m_memory->Alloc(); - name->soundName = m_memory->Dup(value.c_str()); + auto* name = m_memory.Alloc(); + name->soundName = m_memory.Dup(value.c_str()); reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset)->name = name; - m_indirect_asset_references.emplace(ASSET_TYPE_SOUND, value); + m_registration.AddIndirectAssetReference(IndirectAssetReference(ASSET_TYPE_SOUND, value)); return true; } diff --git a/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.h b/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.h index 341a1b562..2953e74fa 100644 --- a/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.h +++ b/src/ObjLoading/Game/IW4/InfoString/InfoStringToStructConverter.h @@ -1,4 +1,5 @@ #pragma once + #include "AssetLoading/IAssetLoadingManager.h" #include "Game/IW4/IW4.h" #include "InfoString/InfoStringToStructConverterBase.h" @@ -7,22 +8,22 @@ namespace IW4 { class InfoStringToStructConverter : public InfoStringToStructConverterBase { - protected: - IAssetLoadingManager* m_loading_manager; - const cspField_t* m_fields; - size_t m_field_count; - - virtual bool ConvertExtensionField(const cspField_t& field, const std::string& value) = 0; - bool ConvertBaseField(const cspField_t& field, const std::string& value); - public: InfoStringToStructConverter(const InfoString& infoString, void* structure, ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory, - IAssetLoadingManager* manager, + MemoryManager& memory, + AssetCreationContext& context, + GenericAssetRegistration& registration, const cspField_t* fields, size_t fieldCount); bool Convert() override; + + protected: + virtual bool ConvertExtensionField(const cspField_t& field, const std::string& value) = 0; + bool ConvertBaseField(const cspField_t& field, const std::string& value); + + const cspField_t* m_fields; + size_t m_field_count; }; } // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp new file mode 100644 index 000000000..a37050ee9 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.cpp @@ -0,0 +1,53 @@ +#include "AssetLoaderLeaderboardIW4.h" + +#include "Game/IW4/IW4.h" +#include "JsonLeaderboardDefLoader.h" + +#include +#include +#include + +using namespace IW4; + +namespace +{ + class LeaderboardLoader final : public AssetCreator + { + public: + LeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(std::format("leaderboards/{}.json", 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)) + { + std::cerr << std::format("Failed to load leaderboard \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return AssetCreationResult::Success(context.AddAsset(assetName, leaderboardDef)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h new file mode 100644 index 000000000..3f0a86ce6 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Leaderboard/LoaderLeaderboardIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateLeaderboardLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.cpp b/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.cpp new file mode 100644 index 000000000..ceda7bcad --- /dev/null +++ b/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.cpp @@ -0,0 +1,82 @@ +#include "LoaderLightDefIW4.h" + +#include "Game/IW4/IW4.h" +#include "ObjLoading.h" +#include "Pool/GlobalAssetPool.h" + +#include +#include +#include + +using namespace IW4; + +namespace +{ + constexpr auto MAX_IMAGE_NAME_SIZE = 0x800; + + class LoaderLightDef final : public AssetCreator + { + public: + LoaderLightDef(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto filename = GetAssetFilename(assetName); + const auto file = m_search_path.Open(filename); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + const auto imageNameSize = file.m_length - sizeof(char) - sizeof(char); + if (imageNameSize < 0 || imageNameSize > MAX_IMAGE_NAME_SIZE) + return AssetCreationResult::Failure(); + + auto* lightDef = m_memory.Alloc(); + lightDef->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, lightDef); + + std::string imageName(static_cast(imageNameSize), '\0'); + + int8_t samplerState; + int8_t lmapLookupStart; + file.m_stream->read(reinterpret_cast(&samplerState), sizeof(int8_t)); + file.m_stream->read(&imageName[0], static_cast(imageNameSize)); + file.m_stream->read(reinterpret_cast(&lmapLookupStart), sizeof(int8_t)); + + auto* imageDependency = context.LoadDependency(imageName); + if (!imageDependency) + { + std::cerr << std::format("Could not load GfxLightDef \"{}\" due to missing image \"{}\"\n", assetName, imageName); + return AssetCreationResult::Failure(); + } + registration.AddDependency(imageDependency); + + lightDef->attenuation.samplerState = samplerState; + lightDef->attenuation.image = imageDependency->Asset(); + lightDef->lmapLookupStart = static_cast(static_cast(lmapLookupStart)); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } + + private: + std::string GetAssetFilename(const std::string& assetName) + { + return std::format("lights/{}", assetName); + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateLightDefLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.h b/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.h new file mode 100644 index 000000000..92eec1bb9 --- /dev/null +++ b/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateLightDefLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.cpp b/src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.cpp deleted file mode 100644 index f96e65ee4..000000000 --- a/src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "AssetLoaderLocalizeIW4.h" - -using namespace IW4; - -AssetLoaderLocalize::AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) - : CommonLocalizeLoader(searchPath, zone), - m_memory(memory) -{ -} - -AssetCreationResult AssetLoaderLocalize::CreateAsset(const std::string& assetName, AssetCreationContext& context) -{ - return CreateLocalizeAsset(assetName, context); -} - -AssetCreationResult AssetLoaderLocalize::CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) -{ - auto* asset = m_memory.Alloc(); - asset->name = m_memory.Dup(localizeEntry.m_key.c_str()); - asset->value = m_memory.Dup(localizeEntry.m_value.c_str()); - - return AssetCreationResult::Success(context.AddAsset(localizeEntry.m_key, asset)); -} diff --git a/src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.h b/src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.h deleted file mode 100644 index 4be1da324..000000000 --- a/src/ObjLoading/Game/IW4/Localize/AssetLoaderLocalizeIW4.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "Asset/AssetCreationContext.h" -#include "Asset/IAssetCreator.h" -#include "Game/IW4/IW4.h" -#include "Localize/CommonLocalizeLoader.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" -#include "Zone/Zone.h" - -namespace IW4 -{ - class AssetLoaderLocalize final : public AssetCreator, public CommonLocalizeLoader - { - public: - AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); - AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override; - - protected: - AssetCreationResult CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) override; - - private: - MemoryManager& m_memory; - }; -} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp new file mode 100644 index 000000000..85d179007 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.cpp @@ -0,0 +1,44 @@ +#include "AssetLoaderLocalizeIW4.h" + +#include "Localize/CommonLocalizeLoader.h" + +using namespace IW4; + +namespace +{ + class LocalizeLoader final : public AssetCreator, public CommonLocalizeLoader + { + public: + LocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : CommonLocalizeLoader(searchPath, zone), + m_memory(memory) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + return CreateLocalizeAsset(assetName, context); + } + + protected: + AssetCreationResult CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) override + { + auto* asset = m_memory.Alloc(); + asset->name = m_memory.Dup(localizeEntry.m_key.c_str()); + asset->value = m_memory.Dup(localizeEntry.m_value.c_str()); + + return AssetCreationResult::Success(context.AddAsset(localizeEntry.m_key, asset)); + } + + private: + MemoryManager& m_memory; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + { + return std::make_unique(memory, searchPath, zone); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h new file mode 100644 index 000000000..c7ae0d9d1 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Localize/LoaderLocalizeIW4.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" +#include "Zone/Zone.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.cpp similarity index 87% rename from src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp rename to src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.cpp index 02c81a664..26b82dc1d 100644 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp +++ b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.cpp @@ -1,4 +1,4 @@ -#include "AssetLoaderMaterial.h" +#include "LoaderMaterialIW4.h" #include "AssetLoaderTechniqueSet.h" #include "AssetLoading/AbstractGdtEntryReader.h" @@ -12,15 +12,18 @@ #include "StateMap/StateMapFromTechniqueExtractor.h" #include "StateMap/StateMapHandler.h" #include "Techset/TechniqueFileReader.h" +#include "Techset/TechniqueStateMapCache.h" +#include "Techset/TechsetDefinitionCache.h" #include #include +#include #include #include using namespace IW4; -namespace IW4 +namespace { class SkipMaterialException final : public std::exception { @@ -29,37 +32,30 @@ namespace IW4 class MaterialGdtLoader : AbstractGdtEntryReader { public: - MaterialGdtLoader(const GdtEntry& entry, MemoryManager* memory, ISearchPath* searchPath, IAssetLoadingManager* manager) + MaterialGdtLoader(const GdtEntry& entry, + Material& material, + MemoryManager& memory, + ISearchPath& searchPath, + AssetCreationContext& context, + AssetRegistration& registration) : AbstractGdtEntryReader(entry), + m_material(material), m_memory(memory), m_search_path(searchPath), - m_manager(manager), - m_state_map_cache(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState()), - m_material(nullptr), + m_context(context), + m_registration(registration), + m_state_map_cache(context.GetZoneAssetLoaderState()), m_base_state_bits{} { } bool Load() { - m_material = m_memory->Create(); - memset(m_material, 0, sizeof(Material)); - - m_material->info.name = m_memory->Dup(m_entry.m_name.c_str()); material_template(); FinalizeMaterial(); - return true; - } - _NODISCARD Material* GetMaterial() const - { - return m_material; - } - - _NODISCARD std::vector GetDependencies() - { - return std::move(m_dependencies); + return true; } private: @@ -120,11 +116,7 @@ namespace IW4 custom_template(); } else - { - std::ostringstream ss; - ss << "Unknown material type: \"" << materialType << "\""; - throw GdtReadingException(ss.str()); - } + throw GdtReadingException(std::format("Unknown material type: \"{}\"", materialType)); } void mtl_phong_template() @@ -253,7 +245,7 @@ namespace IW4 else throw GdtReadingException("ColorMap may not be blank in particle cloud materials"); - std::cout << "Using particlecloud for \"" << m_material->info.name << "\"\n"; + std::cout << std::format("Using particlecloud for \"{}\"\n", m_material.info.name); } void mtl_tools_template() @@ -332,11 +324,7 @@ namespace IW4 mtl_splatter_template(); } else - { - std::ostringstream ss; - ss << "Unknown custom template: \"" << customTemplate << "\""; - throw GdtReadingException(ss.str()); - } + throw GdtReadingException(std::format("Unknown custom template: \"{}\"", customTemplate)); } void mtl_custom_template() @@ -584,11 +572,7 @@ namespace IW4 const auto sortKeyNum = strtoul(sortKey.c_str(), &endPtr, 10); if (endPtr != &sortKey[sortKey.size()]) - { - std::ostringstream ss; - ss << "Invalid sort value: \"" << sortKey << "\""; - throw GdtReadingException(ss.str()); - } + throw GdtReadingException(std::format("Invalid sort value: \"{}\"", sortKey)); SetSort(static_cast(sortKeyNum)); } @@ -628,11 +612,7 @@ namespace IW4 else if (alphaTest == GDT_ALPHA_TEST_GT0) // TODO: This is not available for IW3 SetAlphaTest(AlphaTest_e::GT0); else - { - std::ostringstream ss; - ss << "Invalid alphatest value: \"" << alphaTest << "\""; - throw GdtReadingException(ss.str()); - } + throw GdtReadingException(std::format("Invalid alphatest value: \"{}\"", alphaTest)); } void blendfunc_template() @@ -682,9 +662,7 @@ namespace IW4 } else { - std::ostringstream ss; - ss << "Invalid blendfunc value: \"" << blendFunc << "\""; - throw GdtReadingException(ss.str()); + throw GdtReadingException(std::format("Invalid blendfunc value: \"{}\"", blendFunc)); } } @@ -740,9 +718,7 @@ namespace IW4 SetDepthWrite(false); else { - std::ostringstream ss; - ss << "Invalid depthWrite blendFunc value: \"" << blendFunc << "\""; - throw GdtReadingException(ss.str()); + throw GdtReadingException(std::format("Invalid depthWrite blendFunc value: \"{}\"", blendFunc)); } } @@ -807,28 +783,20 @@ namespace IW4 void SetTechniqueSet(const std::string& techsetName) { - auto* techset = m_manager->LoadDependency(techsetName); + auto* techset = m_context.LoadDependency(techsetName); if (techset == nullptr) - { - std::ostringstream ss; - ss << "Could not load techset: \"" << techsetName << "\""; - throw GdtReadingException(ss.str()); - } + throw GdtReadingException(std::format("Could not load techset: \"{}\"", techsetName)); - m_dependencies.push_back(techset); - m_material->techniqueSet = techset->Asset(); + m_registration.AddDependency(techset); + m_material.techniqueSet = techset->Asset(); - auto* loadingContext = m_manager->GetAssetLoadingContext(); - auto& searchPath = loadingContext->m_raw_search_path; - auto* definitionCache = loadingContext->GetZoneAssetLoaderState(); + auto* definitionCache = m_context.GetZoneAssetLoaderState(); - const auto* techsetDefinition = AssetLoaderTechniqueSet::LoadTechsetDefinition(techsetName, &searchPath, definitionCache); + const auto* techsetDefinition = AssetLoaderTechniqueSet::LoadTechsetDefinition(techsetName, &m_search_path, definitionCache); if (techsetDefinition == nullptr) { - std::ostringstream ss; - ss << "Could not find techset definition for: \"" << techsetName << "\""; - throw GdtReadingException(ss.str()); + throw GdtReadingException(std::format("Could not find techset definition for: \"{}\"", techsetName)); } SetTechniqueSetStateBits(techsetDefinition); @@ -852,17 +820,17 @@ namespace IW4 if (foundStateBits != m_state_bits.end()) { - m_material->stateBitsEntry[i] = static_cast(foundStateBits - m_state_bits.begin()); + m_material.stateBitsEntry[i] = static_cast(foundStateBits - m_state_bits.begin()); } else { - m_material->stateBitsEntry[i] = static_cast(m_state_bits.size()); + m_material.stateBitsEntry[i] = static_cast(m_state_bits.size()); m_state_bits.push_back(stateBitsForTechnique); } } else { - m_material->stateBitsEntry[i] = std::numeric_limits::max(); + m_material.stateBitsEntry[i] = std::numeric_limits::max(); } } } @@ -890,7 +858,7 @@ namespace IW4 return preloadedStateMap; const auto techniqueFileName = AssetLoaderTechniqueSet::GetTechniqueFileName(techniqueName); - const auto file = m_search_path->Open(techniqueFileName); + const auto file = m_search_path.Open(techniqueFileName); if (!file.IsOpen()) return nullptr; @@ -924,18 +892,18 @@ namespace IW4 std::string tempName; if (techsetDefinition->GetTechniqueByIndex(TECHNIQUE_LIT, tempName)) { - if (m_material->info.sortKey >= SORTKEY_TRANS_START) - m_material->cameraRegion = CAMERA_REGION_LIT_TRANS; + if (m_material.info.sortKey >= SORTKEY_TRANS_START) + m_material.cameraRegion = CAMERA_REGION_LIT_TRANS; else - m_material->cameraRegion = CAMERA_REGION_LIT_OPAQUE; + m_material.cameraRegion = CAMERA_REGION_LIT_OPAQUE; } else if (techsetDefinition->GetTechniqueByIndex(TECHNIQUE_EMISSIVE, tempName)) { - m_material->cameraRegion = CAMERA_REGION_EMISSIVE; + m_material.cameraRegion = CAMERA_REGION_EMISSIVE; } else { - m_material->cameraRegion = CAMERA_REGION_NONE; + m_material.cameraRegion = CAMERA_REGION_NONE; } } @@ -993,16 +961,12 @@ namespace IW4 break; } - auto* image = m_manager->LoadDependency(textureName); + auto* image = m_context.LoadDependency(textureName); if (image == nullptr) - { - std::ostringstream ss; - ss << "Could not load image: \"" << textureName << "\""; - throw GdtReadingException(ss.str()); - } + throw GdtReadingException(std::format("Could not load image: \"{}\"", textureName)); - m_dependencies.push_back(image); + m_registration.AddDependency(image); textureDef.u.image = image->Asset(); m_textures.push_back(textureDef); @@ -1023,13 +987,13 @@ namespace IW4 void SetSort(const unsigned char sort) const { - m_material->info.sortKey = sort; + m_material.info.sortKey = sort; } void SetTextureAtlas(const unsigned char rowCount, const unsigned char columnCount) const { - m_material->info.textureAtlasRowCount = rowCount; - m_material->info.textureAtlasColumnCount = columnCount; + m_material.info.textureAtlasRowCount = rowCount; + m_material.info.textureAtlasColumnCount = columnCount; } void SetAlphaTest(const AlphaTest_e alphaTest) @@ -1054,9 +1018,7 @@ namespace IW4 case AlphaTest_e::UNKNOWN: default: - std::ostringstream ss; - ss << "Unknown alphatest value: \"" << static_cast(alphaTest) << "\""; - throw GdtReadingException(ss.str()); + throw GdtReadingException(std::format("Unknown alphatest value: \"{}\"", static_cast(alphaTest))); } } @@ -1113,9 +1075,7 @@ namespace IW4 if (colorWriteRed != colorWriteGreen || colorWriteRed != colorWriteBlue) { - std::ostringstream ss; - ss << "Invalid ColorWrite values: values for rgb must match"; - throw GdtReadingException(ss.str()); + throw GdtReadingException("Invalid ColorWrite values: values for rgb must match"); } m_base_state_bits.loadBits[0] &= ~GFXS0_COLORWRITE_MASK; @@ -1286,38 +1246,38 @@ namespace IW4 { if (!m_textures.empty()) { - m_material->textureTable = m_memory->Alloc(m_textures.size()); - m_material->textureCount = static_cast(m_textures.size()); - memcpy(m_material->textureTable, m_textures.data(), sizeof(MaterialTextureDef) * m_textures.size()); + m_material.textureTable = m_memory.Alloc(m_textures.size()); + m_material.textureCount = static_cast(m_textures.size()); + std::memcpy(m_material.textureTable, m_textures.data(), sizeof(MaterialTextureDef) * m_textures.size()); } else { - m_material->textureTable = nullptr; - m_material->textureCount = 0u; + m_material.textureTable = nullptr; + m_material.textureCount = 0u; } if (!m_constants.empty()) { - m_material->constantTable = m_memory->Alloc(m_constants.size()); - m_material->constantCount = static_cast(m_constants.size()); - memcpy(m_material->constantTable, m_constants.data(), sizeof(MaterialConstantDef) * m_constants.size()); + m_material.constantTable = m_memory.Alloc(m_constants.size()); + m_material.constantCount = static_cast(m_constants.size()); + std::memcpy(m_material.constantTable, m_constants.data(), sizeof(MaterialConstantDef) * m_constants.size()); } else { - m_material->constantTable = nullptr; - m_material->constantCount = 0u; + m_material.constantTable = nullptr; + m_material.constantCount = 0u; } if (!m_state_bits.empty()) { - m_material->stateBitsTable = m_memory->Alloc(m_state_bits.size()); - m_material->stateBitsCount = static_cast(m_state_bits.size()); - memcpy(m_material->stateBitsTable, m_state_bits.data(), sizeof(GfxStateBits) * m_state_bits.size()); + m_material.stateBitsTable = m_memory.Alloc(m_state_bits.size()); + m_material.stateBitsCount = static_cast(m_state_bits.size()); + std::memcpy(m_material.stateBitsTable, m_state_bits.data(), sizeof(GfxStateBits) * m_state_bits.size()); } else { - m_material->stateBitsTable = nullptr; - m_material->stateBitsCount = 0u; + m_material.stateBitsTable = nullptr; + m_material.stateBitsCount = 0u; } } @@ -1330,9 +1290,7 @@ namespace IW4 return i; } - std::ostringstream ss; - ss << "Unknown " << propertyName << " value: \"" << value << "\""; - throw GdtReadingException(ss.str()); + throw GdtReadingException(std::format("Unknown {} value: \"{}\"", propertyName, value)); } template T ReadEnumProperty(const std::string& propertyName, const char** validValuesArray, const size_t validValuesArraySize) const @@ -1340,59 +1298,67 @@ namespace IW4 return static_cast(GetIndexForString(propertyName, ReadStringProperty(propertyName), validValuesArray, validValuesArraySize)); } - MemoryManager* m_memory; - ISearchPath* m_search_path; - IAssetLoadingManager* m_manager; + Material& m_material; + MemoryManager& m_memory; + ISearchPath& m_search_path; + AssetCreationContext& m_context; + AssetRegistration& m_registration; + techset::TechniqueStateMapCache* m_state_map_cache; std::unordered_map m_state_bits_per_state_map; - std::vector m_dependencies; - Material* m_material; GfxStateBits m_base_state_bits; std::vector m_state_bits; std::vector m_textures; std::vector m_constants; }; -} // namespace IW4 -void* AssetLoaderMaterial::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* material = memory->Create(); - memset(material, 0, sizeof(Material)); - material->info.name = memory->Dup(assetName.c_str()); - return material; -} + class MaterialLoader final : public AssetCreator + { + public: + MaterialLoader(MemoryManager& memory, ISearchPath& searchPath); -bool AssetLoaderMaterial::CanLoadFromGdt() const -{ - return true; -} + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto* entry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_MATERIAL, assetName); + if (!entry) + return AssetCreationResult::NoAction(); -bool AssetLoaderMaterial::LoadFromGdt( - const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - const auto* entry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_MATERIAL, assetName); - if (!entry) - return false; + auto* material = m_memory.Alloc(); + material->info.name = m_memory.Dup(assetName.c_str()); - MaterialGdtLoader loader(*entry, memory, &manager->GetAssetLoadingContext()->m_raw_search_path, manager); + AssetRegistration registration(assetName, material); - try - { - if (loader.Load()) - { - manager->AddAsset(assetName, loader.GetMaterial(), loader.GetDependencies()); + MaterialGdtLoader loader(*entry, *material, m_memory, m_search_path, context, registration); + + try + { + if (loader.Load()) + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } + catch (const SkipMaterialException&) + { + return AssetCreationResult::NoAction(); + } + catch (const GdtReadingException& e) + { + std::cerr << std::format("Error while trying to load material from gdt: {} @ GdtEntry \"{}\"\n", e.what(), entry->m_name); + } + + return AssetCreationResult::Failure(); } - } - catch (const SkipMaterialException&) - { - return false; - } - catch (const GdtReadingException& e) + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + IGdtQueryable& m_gdt; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt) { - std::cerr << "Error while trying to load material from gdt: " << e.what() << " @ GdtEntry \"" << entry->m_name << "\"\n"; - return false; + return std::make_unique(memory, searchPath, gdt); } - - return true; -} +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h new file mode 100644 index 000000000..04b975e09 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Material/LoaderMaterialIW4.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +namespace IW4 +{ + std::unique_ptr> CreateMaterialLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp new file mode 100644 index 000000000..427b6ef0a --- /dev/null +++ b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp @@ -0,0 +1,230 @@ +#include "AssetLoaderMenuListIW4.h" + +#include "Game/IW4/IW4.h" +#include "Game/IW4/Menu/MenuConversionZoneStateIW4.h" +#include "Game/IW4/Menu/MenuConverterIW4.h" +#include "ObjLoading.h" +#include "Parsing/Menu/MenuFileReader.h" + +#include +#include +#include + +using namespace IW4; + +namespace +{ + class MenuListLoader final : public AssetCreator + { + public: + MenuListLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + std::vector menus; + AssetRegistration registration(assetName); + + auto* zoneState = context.GetZoneAssetLoaderState(); + auto* conversionState = context.GetZoneAssetLoaderState(); + + std::deque menuLoadQueue; + const auto alreadyLoadedMenuListFileMenus = conversionState->m_menus_by_filename.find(assetName); + + if (alreadyLoadedMenuListFileMenus == conversionState->m_menus_by_filename.end()) + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + const auto menuListResult = ParseMenuFile(*file.m_stream, assetName, zoneState); + if (menuListResult) + { + ProcessParsedResults(assetName, context, menuListResult.get(), zoneState, conversionState, menus, registration); + + for (const auto& menuToLoad : menuListResult->m_menus_to_load) + menuLoadQueue.emplace_back(menuToLoad); + + zoneState->AddMenusToLoad(assetName, std::move(menuListResult->m_menus_to_load)); + } + else + return AssetCreationResult::Failure(); + } + + while (!menuLoadQueue.empty()) + { + const auto& menuFileToLoad = menuLoadQueue.front(); + + LoadMenuFileFromQueue(menuFileToLoad, context, zoneState, conversionState, menus, registration); + + menuLoadQueue.pop_front(); + } + + auto* menuListAsset = m_memory.Create(); + menuListAsset->name = m_memory.Dup(assetName.c_str()); + registration.SetAsset(menuListAsset); + + CreateMenuListAsset(*menuListAsset, menus); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } + + void FinalizeZone(AssetCreationContext& context) override + { + context.GetZoneAssetLoaderState()->FinalizeSupportingData(); + } + + private: + bool LoadMenuFileFromQueue(const std::string& menuFilePath, + AssetCreationContext& context, + menu::MenuAssetZoneState* zoneState, + MenuConversionZoneState* conversionState, + std::vector& menus, + AssetRegistration& registration) + { + const auto alreadyLoadedMenuFile = conversionState->m_menus_by_filename.find(menuFilePath); + if (alreadyLoadedMenuFile != conversionState->m_menus_by_filename.end()) + { + std::cout << std::format("Already loaded \"{}\", skipping\n", menuFilePath); + for (auto* menu : alreadyLoadedMenuFile->second) + { + menus.emplace_back(menu->Asset()); + registration.AddDependency(menu); + } + return true; + } + + const auto file = m_search_path.Open(menuFilePath); + if (!file.IsOpen()) + { + std::cerr << std::format("Could not open menu file \"{}\"\n", menuFilePath); + return false; + } + + const auto menuFileResult = ParseMenuFile(*file.m_stream, menuFilePath, zoneState); + if (menuFileResult) + { + ProcessParsedResults(menuFilePath, context, menuFileResult.get(), zoneState, conversionState, menus, registration); + if (!menuFileResult->m_menus_to_load.empty()) + std::cout << std::format("WARNING: Menu file has menus to load even though it is not a menu list, ignoring: \"{}\"\n", menuFilePath); + + return true; + } + else + std::cerr << std::format("Could not read menu file \"{}\"\n", menuFilePath); + + return false; + } + + bool ProcessParsedResults(const std::string& fileName, + AssetCreationContext& context, + menu::ParsingResult* parsingResult, + menu::MenuAssetZoneState* zoneState, + MenuConversionZoneState* conversionState, + std::vector& menus, + AssetRegistration& registration) + { + const auto menuCount = parsingResult->m_menus.size(); + const auto functionCount = parsingResult->m_functions.size(); + const auto menuLoadCount = parsingResult->m_menus_to_load.size(); + auto totalItemCount = 0u; + for (const auto& menu : parsingResult->m_menus) + totalItemCount += menu->m_items.size(); + + std::cout << std::format("Successfully read menu file \"{}\" ({} loads, {} menus, {} functions, {} items)\n", + fileName, + menuLoadCount, + menuCount, + functionCount, + totalItemCount); + + // Add all functions to the zone state to make them available for all menus to be converted + for (auto& function : parsingResult->m_functions) + zoneState->AddFunction(std::move(function)); + + // Prepare a list of all menus of this file + std::vector*> allMenusOfFile; + allMenusOfFile.reserve(parsingResult->m_menus.size()); + + // Convert all menus and add them as assets + for (auto& commonMenu : parsingResult->m_menus) + { + auto converter = IMenuConverter::Create(ObjLoading::Configuration.MenuNoOptimization, m_search_path, m_memory, context); + + auto* menuAsset = m_memory.Alloc(); + AssetRegistration menuRegistration(commonMenu->m_name, menuAsset); + + converter->ConvertMenu(*commonMenu, *menuAsset, menuRegistration); + if (menuAsset == nullptr) + { + std::cerr << std::format("Failed to convert menu file \"{}\"\n", commonMenu->m_name); + return false; + } + + menus.emplace_back(menuAsset); + auto* menuAssetInfo = context.AddAsset(std::move(menuRegistration)); + + if (menuAssetInfo) + { + allMenusOfFile.emplace_back(menuAssetInfo); + registration.AddDependency(menuAssetInfo); + } + + zoneState->AddMenu(std::move(commonMenu)); + } + + // Register this file with all loaded menus + conversionState->AddLoadedFile(fileName, std::move(allMenusOfFile)); + + return true; + } + + void CreateMenuListAsset(MenuList& menuList, const std::vector& menus) + { + menuList.menuCount = static_cast(menus.size()); + + if (menuList.menuCount > 0) + { + menuList.menus = m_memory.Alloc(menuList.menuCount); + for (auto i = 0; i < menuList.menuCount; i++) + menuList.menus[i] = menus[i]; + } + else + menuList.menus = nullptr; + } + + std::unique_ptr ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState* zoneState) + { + menu::MenuFileReader reader(stream, + menuFileName, + menu::FeatureLevel::IW4, + [this](const std::string& filename, const std::string& sourceFile) -> std::unique_ptr + { + auto foundFileToInclude = m_search_path.Open(filename); + if (!foundFileToInclude.IsOpen() || !foundFileToInclude.m_stream) + return nullptr; + + return std::move(foundFileToInclude.m_stream); + }); + + reader.IncludeZoneState(zoneState); + reader.SetPermissiveMode(ObjLoading::Configuration.MenuPermissiveParsing); + + return reader.ReadMenuFile(); + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateMenuListLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h new file mode 100644 index 000000000..6a1d0499e --- /dev/null +++ b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateMenuListLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp index 4c27dbd5d..fd037d219 100644 --- a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp +++ b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp @@ -16,19 +16,17 @@ #include #include +#include #include using namespace IW4; using namespace menu; -namespace IW4 +namespace { - class MenuConverterImpl : public AbstractMenuConverter + class MenuConverter : public AbstractMenuConverter, public IMenuConverter { - MenuConversionZoneState* m_conversion_zone_state; - MenuAssetZoneState* m_parsing_zone_state; - - _NODISCARD static rectDef_s ConvertRectDef(const CommonRect& rect) + [[nodiscard]] static rectDef_s ConvertRectDef(const CommonRect& rect) { return rectDef_s{ static_cast(rect.x), @@ -40,7 +38,7 @@ namespace IW4 }; } - _NODISCARD static rectDef_s ConvertRectDefRelativeTo(const CommonRect& rect, const CommonRect& rectRelativeTo) + [[nodiscard]] static rectDef_s ConvertRectDefRelativeTo(const CommonRect& rect, const CommonRect& rectRelativeTo) { return rectDef_s{ static_cast(rectRelativeTo.x + rect.x), @@ -78,26 +76,26 @@ namespace IW4 return input; } - _NODISCARD Material* ConvertMaterial(const std::string& materialName, const CommonMenuDef* menu, const CommonItemDef* item = nullptr) const + [[nodiscard]] Material* ConvertMaterial(const std::string& materialName, const CommonMenuDef* menu, const CommonItemDef* item = nullptr) const { if (materialName.empty()) return nullptr; - auto* materialDependency = m_manager->LoadDependency(materialName); + auto* materialDependency = m_context.LoadDependency(materialName); if (!materialDependency) - throw MenuConversionException("Failed to load material \"" + materialName + "\"", menu, item); + throw MenuConversionException(std::format("Failed to load material \"{}\"", materialName), menu, item); return materialDependency->Asset(); } - _NODISCARD snd_alias_list_t* ConvertSound(const std::string& soundName, const CommonMenuDef* menu, const CommonItemDef* item = nullptr) const + [[nodiscard]] snd_alias_list_t* ConvertSound(const std::string& soundName, const CommonMenuDef* menu, const CommonItemDef* item = nullptr) const { if (soundName.empty()) return nullptr; - auto* soundDependency = m_manager->LoadDependency(soundName); + auto* soundDependency = m_context.LoadDependency(soundName); if (!soundDependency) - throw MenuConversionException("Failed to load sound \"" + soundName + "\"", menu, item); + throw MenuConversionException(std::format("Failed to load sound \"{}\"", soundName), menu, item); return soundDependency->Asset(); } @@ -416,7 +414,7 @@ namespace IW4 if (!expression) return nullptr; - auto* statement = m_memory->Create(); + auto* statement = m_memory.Alloc(); statement->lastResult = Operand{}; statement->lastExecuteTime = 0; statement->supportingData = nullptr; // Supporting data is set upon using it @@ -424,7 +422,7 @@ namespace IW4 std::vector expressionEntries; ConvertExpressionEntry(statement, expressionEntries, expression, menu, item); - auto* outputExpressionEntries = m_memory->Alloc(expressionEntries.size()); + auto* outputExpressionEntries = m_memory.Alloc(expressionEntries.size()); memcpy(outputExpressionEntries, expressionEntries.data(), sizeof(expressionEntry) * expressionEntries.size()); statement->entries = outputExpressionEntries; @@ -481,7 +479,7 @@ namespace IW4 switch (value.m_type) { case SimpleExpressionValue::Type::STRING: - staticValue = m_memory->Dup(value.m_string_value->c_str()); + staticValue = m_memory.Dup(value.m_string_value->c_str()); break; case SimpleExpressionValue::Type::DOUBLE: @@ -586,13 +584,13 @@ namespace IW4 if (!setLocalVar) return; - auto* outputHandler = m_memory->Alloc(); - auto* outputSetLocalVar = m_memory->Alloc(); + auto* outputHandler = m_memory.Alloc(); + auto* outputSetLocalVar = m_memory.Alloc(); outputHandler->eventType = SetLocalVarTypeToEventType(setLocalVar->m_type); outputHandler->eventData.setLocalVarData = outputSetLocalVar; - outputSetLocalVar->localVarName = m_memory->Dup(setLocalVar->m_var_name.c_str()); + outputSetLocalVar->localVarName = m_memory.Dup(setLocalVar->m_var_name.c_str()); outputSetLocalVar->expression = ConvertExpression(setLocalVar->m_value.get(), menu, item); elements.push_back(outputHandler); @@ -604,9 +602,9 @@ namespace IW4 if (!script) return; - auto* outputHandler = m_memory->Create(); + auto* outputHandler = m_memory.Alloc(); outputHandler->eventType = EVENT_UNCONDITIONAL; - outputHandler->eventData.unconditionalScript = m_memory->Dup(script->m_script.c_str()); + outputHandler->eventData.unconditionalScript = m_memory.Dup(script->m_script.c_str()); elements.push_back(outputHandler); } @@ -631,8 +629,8 @@ namespace IW4 } else { - auto* outputHandler = m_memory->Alloc(); - auto* outputCondition = m_memory->Alloc(); + auto* outputHandler = m_memory.Alloc(); + auto* outputCondition = m_memory.Alloc(); outputHandler->eventType = EVENT_IF; outputHandler->eventData.conditionalScript = outputCondition; @@ -644,7 +642,7 @@ namespace IW4 if (condition->m_else_elements) { - auto* outputElseHandler = m_memory->Create(); + auto* outputElseHandler = m_memory.Alloc(); outputElseHandler->eventType = EVENT_ELSE; outputElseHandler->eventData.elseScript = ConvertEventHandlerSet(condition->m_else_elements.get(), menu, item); @@ -699,8 +697,8 @@ namespace IW4 if (elements.empty()) return nullptr; - auto* outputSet = m_memory->Alloc(); - auto* outputElements = m_memory->Alloc(elements.size()); + auto* outputSet = m_memory.Alloc(); + auto* outputElements = m_memory.Alloc(elements.size()); memcpy(outputElements, elements.data(), sizeof(void*) * elements.size()); outputSet->eventHandlerCount = static_cast(elements.size()); @@ -717,7 +715,7 @@ namespace IW4 return nullptr; const auto keyHandlerCount = keyHandlers.size(); - auto* output = m_memory->Alloc(keyHandlerCount); + auto* output = m_memory.Alloc(keyHandlerCount); auto currentKeyHandler = keyHandlers.cbegin(); for (auto i = 0u; i < keyHandlerCount; i++) { @@ -829,7 +827,7 @@ namespace IW4 if (floatExpressionCount <= 0) return nullptr; - auto* floatExpressions = m_memory->Alloc(floatExpressionCount); + auto* floatExpressions = m_memory.Alloc(floatExpressionCount); auto floatExpressionIndex = 0; for (const auto& [expression, expressionIsStatic, target, staticValue, staticValueArraySize, dynamicFlagsToSet] : locations) { @@ -855,7 +853,7 @@ namespace IW4 ss << "\"" << element << "\" "; } - return m_memory->Dup(ss.str().c_str()); + return m_memory.Dup(ss.str().c_str()); } _NODISCARD const char* ConvertEnableDvar(const CommonItemDef& commonItem, int& dvarFlags) const @@ -903,7 +901,7 @@ namespace IW4 if (commonListBox == nullptr) return nullptr; - auto* listBox = m_memory->Alloc(); + auto* listBox = m_memory.Alloc(); listBox->notselectable = commonListBox->m_not_selectable ? 1 : 0; listBox->noScrollBars = commonListBox->m_no_scrollbars ? 1 : 0; listBox->usePaging = commonListBox->m_use_paging ? 1 : 0; @@ -938,7 +936,7 @@ namespace IW4 if (commonEditField == nullptr) return nullptr; - auto* editField = m_memory->Alloc(); + auto* editField = m_memory.Alloc(); editField->defVal = static_cast(commonEditField->m_def_val); editField->minVal = static_cast(commonEditField->m_min_val); editField->maxVal = static_cast(commonEditField->m_max_val); @@ -958,7 +956,7 @@ namespace IW4 if (commonMultiValue == nullptr) return nullptr; - auto* multiValue = m_memory->Alloc(); + auto* multiValue = m_memory.Alloc(); multiValue->count = static_cast(std::min(std::extent_v, commonMultiValue->m_step_names.size())); multiValue->strDef = !commonMultiValue->m_string_values.empty() ? 1 : 0; @@ -989,7 +987,7 @@ namespace IW4 if (commonNewsTicker == nullptr) return nullptr; - auto* newsTicker = m_memory->Alloc(); + auto* newsTicker = m_memory.Alloc(); newsTicker->spacing = commonNewsTicker->m_spacing; newsTicker->speed = commonNewsTicker->m_speed; newsTicker->feedId = commonNewsTicker->m_news_feed_id; @@ -999,8 +997,7 @@ namespace IW4 _NODISCARD itemDef_s* ConvertItem(const CommonMenuDef& parentMenu, const CommonItemDef& commonItem) const { - auto* item = m_memory->Create(); - memset(item, 0, sizeof(itemDef_s)); + auto* item = m_memory.Alloc(); item->window.name = ConvertString(commonItem.m_name); item->text = ConvertString(commonItem.m_text); @@ -1087,7 +1084,7 @@ namespace IW4 case CommonItemFeatureType::NONE: default: if (item->type == ITEM_TYPE_TEXT_SCROLL) - item->typeData.scroll = m_memory->Alloc(); + item->typeData.scroll = m_memory.Alloc(); break; } @@ -1103,7 +1100,7 @@ namespace IW4 return nullptr; } - auto* items = m_memory->Alloc(commonMenu.m_items.size()); + auto* items = m_memory.Alloc(commonMenu.m_items.size()); for (auto i = 0u; i < commonMenu.m_items.size(); i++) items[i] = ConvertItem(commonMenu, *commonMenu.m_items[i]); @@ -1113,98 +1110,75 @@ namespace IW4 } public: - MenuConverterImpl(const bool disableOptimizations, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) - : AbstractMenuConverter(disableOptimizations, searchPath, memory, manager), - m_conversion_zone_state(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState()), - m_parsing_zone_state(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState()) + MenuConverter(const bool disableOptimizations, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context) + : AbstractMenuConverter(disableOptimizations, searchPath, memory, context), + m_conversion_zone_state(context.GetZoneAssetLoaderState()), + m_parsing_zone_state(context.GetZoneAssetLoaderState()) { assert(m_conversion_zone_state); assert(m_parsing_zone_state); } - _NODISCARD menuDef_t* ConvertMenu(const CommonMenuDef& commonMenu) const + void ConvertMenu(const menu::CommonMenuDef& commonMenu, menuDef_t& menu, AssetRegistration& registration) override { - auto* menu = m_memory->Create(); - memset(menu, 0, sizeof(menuDef_t)); - - menu->window.name = m_memory->Dup(commonMenu.m_name.c_str()); - menu->fullScreen = commonMenu.m_full_screen; - ApplyFlag(menu->window.staticFlags, commonMenu.m_screen_space, WINDOW_FLAG_SCREEN_SPACE); - ApplyFlag(menu->window.staticFlags, commonMenu.m_decoration, WINDOW_FLAG_DECORATION); - menu->window.rect = ConvertRectDef(commonMenu.m_rect); - menu->window.style = commonMenu.m_style; - menu->window.border = commonMenu.m_border; - menu->window.borderSize = static_cast(commonMenu.m_border_size); - ConvertColor(menu->window.backColor, commonMenu.m_back_color); - ConvertColor(menu->window.foreColor, commonMenu.m_fore_color); - ConvertColor(menu->window.borderColor, commonMenu.m_border_color); - ConvertColor(menu->focusColor, commonMenu.m_focus_color); - menu->window.background = ConvertMaterial(commonMenu.m_background, &commonMenu); - menu->window.ownerDraw = commonMenu.m_owner_draw; - menu->window.ownerDrawFlags = commonMenu.m_owner_draw_flags; - ApplyFlag(menu->window.staticFlags, commonMenu.m_out_of_bounds_click, WINDOW_FLAG_OUT_OF_BOUNDS_CLICK); - menu->soundName = ConvertString(commonMenu.m_sound_loop); - ApplyFlag(menu->window.staticFlags, commonMenu.m_popup, WINDOW_FLAG_POPUP); - menu->fadeClamp = static_cast(commonMenu.m_fade_clamp); - menu->fadeCycle = commonMenu.m_fade_cycle; - menu->fadeAmount = static_cast(commonMenu.m_fade_amount); - menu->fadeInAmount = static_cast(commonMenu.m_fade_in_amount); - menu->blurRadius = static_cast(commonMenu.m_blur_radius); - ApplyFlag(menu->window.staticFlags, commonMenu.m_legacy_split_screen_scale, WINDOW_FLAG_LEGACY_SPLIT_SCREEN_SCALE); - ApplyFlag(menu->window.staticFlags, commonMenu.m_hidden_during_scope, WINDOW_FLAG_HIDDEN_DURING_SCOPE); - ApplyFlag(menu->window.staticFlags, commonMenu.m_hidden_during_flashbang, WINDOW_FLAG_HIDDEN_DURING_FLASH_BANG); - ApplyFlag(menu->window.staticFlags, commonMenu.m_hidden_during_ui, WINDOW_FLAG_HIDDEN_DURING_UI); - menu->allowedBinding = ConvertString(commonMenu.m_allowed_binding); - ApplyFlag(menu->window.staticFlags, commonMenu.m_text_only_focus, WINDOW_FLAG_TEXT_ONLY_FOCUS); - menu->visibleExp = ConvertVisibleExpression(&menu->window, commonMenu.m_visible_expression.get(), &commonMenu); - menu->rectXExp = ConvertOrApplyStatement(menu->window.rect.x, commonMenu.m_rect_x_exp.get(), &commonMenu); - menu->rectYExp = ConvertOrApplyStatement(menu->window.rect.y, commonMenu.m_rect_y_exp.get(), &commonMenu); - menu->rectWExp = ConvertOrApplyStatement(menu->window.rect.w, commonMenu.m_rect_w_exp.get(), &commonMenu); - menu->rectHExp = ConvertOrApplyStatement(menu->window.rect.h, commonMenu.m_rect_h_exp.get(), &commonMenu); - menu->openSoundExp = ConvertExpression(commonMenu.m_open_sound_exp.get(), &commonMenu); - menu->closeSoundExp = ConvertExpression(commonMenu.m_close_sound_exp.get(), &commonMenu); - menu->onOpen = ConvertEventHandlerSet(commonMenu.m_on_open.get(), &commonMenu); - menu->onClose = ConvertEventHandlerSet(commonMenu.m_on_close.get(), &commonMenu); - menu->onCloseRequest = ConvertEventHandlerSet(commonMenu.m_on_request_close.get(), &commonMenu); - menu->onESC = ConvertEventHandlerSet(commonMenu.m_on_esc.get(), &commonMenu); - menu->onKey = ConvertKeyHandler(commonMenu.m_key_handlers, &commonMenu); - menu->items = ConvertMenuItems(commonMenu, menu->itemCount); - menu->expressionData = m_conversion_zone_state->m_supporting_data; - - return menu; + try + { + menu.window.name = m_memory.Dup(commonMenu.m_name.c_str()); + menu.fullScreen = commonMenu.m_full_screen; + ApplyFlag(menu.window.staticFlags, commonMenu.m_screen_space, WINDOW_FLAG_SCREEN_SPACE); + ApplyFlag(menu.window.staticFlags, commonMenu.m_decoration, WINDOW_FLAG_DECORATION); + menu.window.rect = ConvertRectDef(commonMenu.m_rect); + menu.window.style = commonMenu.m_style; + menu.window.border = commonMenu.m_border; + menu.window.borderSize = static_cast(commonMenu.m_border_size); + ConvertColor(menu.window.backColor, commonMenu.m_back_color); + ConvertColor(menu.window.foreColor, commonMenu.m_fore_color); + ConvertColor(menu.window.borderColor, commonMenu.m_border_color); + ConvertColor(menu.focusColor, commonMenu.m_focus_color); + menu.window.background = ConvertMaterial(commonMenu.m_background, &commonMenu); + menu.window.ownerDraw = commonMenu.m_owner_draw; + menu.window.ownerDrawFlags = commonMenu.m_owner_draw_flags; + ApplyFlag(menu.window.staticFlags, commonMenu.m_out_of_bounds_click, WINDOW_FLAG_OUT_OF_BOUNDS_CLICK); + menu.soundName = ConvertString(commonMenu.m_sound_loop); + ApplyFlag(menu.window.staticFlags, commonMenu.m_popup, WINDOW_FLAG_POPUP); + menu.fadeClamp = static_cast(commonMenu.m_fade_clamp); + menu.fadeCycle = commonMenu.m_fade_cycle; + menu.fadeAmount = static_cast(commonMenu.m_fade_amount); + menu.fadeInAmount = static_cast(commonMenu.m_fade_in_amount); + menu.blurRadius = static_cast(commonMenu.m_blur_radius); + ApplyFlag(menu.window.staticFlags, commonMenu.m_legacy_split_screen_scale, WINDOW_FLAG_LEGACY_SPLIT_SCREEN_SCALE); + ApplyFlag(menu.window.staticFlags, commonMenu.m_hidden_during_scope, WINDOW_FLAG_HIDDEN_DURING_SCOPE); + ApplyFlag(menu.window.staticFlags, commonMenu.m_hidden_during_flashbang, WINDOW_FLAG_HIDDEN_DURING_FLASH_BANG); + ApplyFlag(menu.window.staticFlags, commonMenu.m_hidden_during_ui, WINDOW_FLAG_HIDDEN_DURING_UI); + menu.allowedBinding = ConvertString(commonMenu.m_allowed_binding); + ApplyFlag(menu.window.staticFlags, commonMenu.m_text_only_focus, WINDOW_FLAG_TEXT_ONLY_FOCUS); + menu.visibleExp = ConvertVisibleExpression(&menu.window, commonMenu.m_visible_expression.get(), &commonMenu); + menu.rectXExp = ConvertOrApplyStatement(menu.window.rect.x, commonMenu.m_rect_x_exp.get(), &commonMenu); + menu.rectYExp = ConvertOrApplyStatement(menu.window.rect.y, commonMenu.m_rect_y_exp.get(), &commonMenu); + menu.rectWExp = ConvertOrApplyStatement(menu.window.rect.w, commonMenu.m_rect_w_exp.get(), &commonMenu); + menu.rectHExp = ConvertOrApplyStatement(menu.window.rect.h, commonMenu.m_rect_h_exp.get(), &commonMenu); + menu.openSoundExp = ConvertExpression(commonMenu.m_open_sound_exp.get(), &commonMenu); + menu.closeSoundExp = ConvertExpression(commonMenu.m_close_sound_exp.get(), &commonMenu); + menu.onOpen = ConvertEventHandlerSet(commonMenu.m_on_open.get(), &commonMenu); + menu.onClose = ConvertEventHandlerSet(commonMenu.m_on_close.get(), &commonMenu); + menu.onCloseRequest = ConvertEventHandlerSet(commonMenu.m_on_request_close.get(), &commonMenu); + menu.onESC = ConvertEventHandlerSet(commonMenu.m_on_esc.get(), &commonMenu); + menu.onKey = ConvertKeyHandler(commonMenu.m_key_handlers, &commonMenu); + menu.items = ConvertMenuItems(commonMenu, menu.itemCount); + menu.expressionData = m_conversion_zone_state->m_supporting_data; + } + catch (const MenuConversionException& e) + { + PrintConversionExceptionDetails(e); + } } - std::vector m_dependencies; + MenuConversionZoneState* m_conversion_zone_state; + MenuAssetZoneState* m_parsing_zone_state; }; -} // namespace IW4 +} // namespace -MenuConverter::MenuConverter(const bool disableOptimizations, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) - : m_disable_optimizations(disableOptimizations), - m_search_path(searchPath), - m_memory(memory), - m_manager(manager) +std::unique_ptr IMenuConverter::Create(bool disableOptimizations, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context) { -} - -std::vector& MenuConverter::GetDependencies() -{ - return m_dependencies; -} - -menuDef_t* MenuConverter::ConvertMenu(const CommonMenuDef& commonMenu) -{ - MenuConverterImpl impl(m_disable_optimizations, m_search_path, m_memory, m_manager); - - try - { - auto* result = impl.ConvertMenu(commonMenu); - m_dependencies = std::move(impl.m_dependencies); - return result; - } - catch (const MenuConversionException& e) - { - MenuConverterImpl::PrintConversionExceptionDetails(e); - } - - return nullptr; + return std::make_unique(disableOptimizations, searchPath, memory, context); } diff --git a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h index ffe6f40b4..234cedb52 100644 --- a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h +++ b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.h @@ -1,26 +1,21 @@ #pragma once -#include "AssetLoading/IAssetLoadingManager.h" +#include "Asset/AssetCreationContext.h" #include "Game/IW4/IW4.h" #include "Parsing/Menu/Domain/CommonMenuDef.h" #include "SearchPath/ISearchPath.h" -#include "Utils/ClassUtils.h" #include "Utils/MemoryManager.h" namespace IW4 { - class MenuConverter + class IMenuConverter { - bool m_disable_optimizations; - ISearchPath* m_search_path; - MemoryManager* m_memory; - IAssetLoadingManager* m_manager; - std::vector m_dependencies; - public: - MenuConverter(bool disableOptimizations, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager); + IMenuConverter() = default; + virtual ~IMenuConverter() = default; + + virtual void ConvertMenu(const menu::CommonMenuDef& commonMenu, menuDef_t& menu, AssetRegistration& registration) = 0; - std::vector& GetDependencies(); - _NODISCARD menuDef_t* ConvertMenu(const menu::CommonMenuDef& commonMenu); + static std::unique_ptr Create(bool disableOptimizations, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context); }; } // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp index 874dd67aa..47b452011 100644 --- a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp @@ -3,8 +3,23 @@ #include "Asset/GlobalAssetPoolsLoader.h" #include "Game/IW4/GameIW4.h" #include "Game/IW4/IW4.h" -#include "Localize/AssetLoaderLocalizeIW4.h" +#include "Leaderboard/LoaderLeaderboardIW4.h" +#include "LightDef/LoaderLightDefIW4.h" +#include "Localize/LoaderLocalizeIW4.h" +#include "Material/LoaderMaterialIW4.h" +#include "Menu/LoaderMenuListIW4.h" #include "ObjLoading.h" +#include "PhysPreset/GdtLoaderPhysPresetIW4.h" +#include "PhysPreset/RawLoaderPhysPresetIW4.h" +#include "RawFile/LoaderRawFileIW4.h" +#include "Shader/LoaderPixelShaderIW4.h" +#include "Shader/LoaderVertexShaderIW4.h" +#include "Sound/LoaderSoundCurveIW4.h" +#include "StringTable/LoaderStringTableIW4.h" +#include "StructuredDataDef/LoaderStructuredDataDefIW4.h" +#include "Techset/LoaderTechsetIW4.h" +#include "Techset/LoaderVertexDeclIW4.h" +#include "Weapon/LoaderWeaponIW4.h" #include @@ -100,23 +115,24 @@ namespace collection.AddAssetCreator(std::make_unique>(zone)); } - void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) + void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) { auto& memory = *zone.GetMemory(); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(std::make_unique(memory, searchPath, zone)); + collection.AddAssetCreator(std::make_unique(memory, gdt, zone)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateMaterialLoader(memory, searchPath, gdt)); + collection.AddAssetCreator(CreatePixelShaderLoader(memory, searchPath)); + collection.AddAssetCreator(CreateVertexShaderLoader(memory, searchPath)); + collection.AddAssetCreator(CreateVertexDeclLoader(memory)); + collection.AddAssetCreator(CreateTechsetLoader(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(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); @@ -126,27 +142,27 @@ namespace // collection.AddAssetCreator(std::make_unique(memory)); // 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(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateMenuListLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); - collection.AddAssetCreator(std::make_unique(memory, searchPath, zone)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone)); + collection.AddAssetCreator(CreateWeaponLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // collection.AddAssetCreator(std::make_unique(memory)); - // 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(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); } } // namespace -void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const +void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const { ConfigureDefaultCreators(collection, zone); - ConfigureLoaders(collection, zone, searchPath); + ConfigureLoaders(collection, zone, searchPath, gdt); ConfigureGlobalAssetPoolsLoaders(collection, zone); } diff --git a/src/ObjLoading/Game/IW4/ObjLoaderIW4.h b/src/ObjLoading/Game/IW4/ObjLoaderIW4.h index 23d0fe5b8..335dbffc3 100644 --- a/src/ObjLoading/Game/IW4/ObjLoaderIW4.h +++ b/src/ObjLoading/Game/IW4/ObjLoaderIW4.h @@ -13,6 +13,6 @@ namespace IW4 void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override; void UnloadContainersOfZone(Zone& zone) const override; - void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const override; + void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const override; }; } // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp new file mode 100644 index 000000000..afd65d709 --- /dev/null +++ b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.cpp @@ -0,0 +1,35 @@ +#include "GdtLoaderPhysPresetIW4.h" + +#include "Game/IW4/IW4.h" +#include "Game/IW4/ObjConstantsIW4.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderPhysPresetIW4.h" + +#include +#include + +using namespace IW4; + +GdtLoaderPhysPreset::GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone) + : m_memory(memory), + m_gdt(gdt), + m_zone(zone) +{ +} + +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)) + { + std::cerr << std::format("Failed to read phys preset gdt entry: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + InfoStringLoaderPhysPreset infoStringLoader(m_memory, m_zone); + return infoStringLoader.CreateAsset(assetName, infoString, context); +} diff --git a/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h new file mode 100644 index 000000000..59b65bc15 --- /dev/null +++ b/src/ObjLoading/Game/IW4/PhysPreset/GdtLoaderPhysPresetIW4.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "Gdt/IGdtQueryable.h" +#include "Utils/MemoryManager.h" + +namespace IW4 +{ + 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 diff --git a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp new file mode 100644 index 000000000..b283c4457 --- /dev/null +++ b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.cpp @@ -0,0 +1,86 @@ +#include "InfoStringLoaderPhysPresetIW4.h" + +#include "Game/IW4/IW4.h" +#include "Game/IW4/InfoString/InfoStringToStructConverter.h" +#include "Game/IW4/PhysPreset/PhysPresetFields.h" + +#include +#include +#include +#include +#include + +using namespace IW4; + +namespace +{ + class InfoStringToPhysPresetConverter final : public InfoStringToStructConverter + { + public: + InfoStringToPhysPresetConverter(const InfoString& infoString, + void* structure, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + GenericAssetRegistration& registration, + const cspField_t* fields, + size_t fieldCount) + : InfoStringToStructConverter(infoString, structure, zoneScriptStrings, memory, context, registration, fields, fieldCount) + { + } + + protected: + bool ConvertExtensionField(const cspField_t& field, const std::string& value) override + { + assert(false); + return false; + } + }; + + void CopyFromPhysPresetInfo(const PhysPresetInfo& physPresetInfo, PhysPreset& physPreset) + { + physPreset.mass = std::clamp(physPresetInfo.mass, 1.0f, 2000.0f) * 0.001f; + physPreset.bounce = physPresetInfo.bounce; + + if (physPresetInfo.isFrictionInfinity != 0) + physPreset.friction = std::numeric_limits::infinity(); + else + physPreset.friction = physPresetInfo.friction; + + physPreset.bulletForceScale = physPresetInfo.bulletForceScale; + physPreset.explosiveForceScale = physPresetInfo.explosiveForceScale; + physPreset.sndAliasPrefix = physPresetInfo.sndAliasPrefix; + physPreset.piecesSpreadFraction = physPresetInfo.piecesSpreadFraction; + physPreset.piecesUpwardVelocity = physPresetInfo.piecesUpwardVelocity; + physPreset.tempDefaultToCylinder = physPresetInfo.tempDefaultToCylinder != 0; + physPreset.perSurfaceSndAlias = physPresetInfo.perSurfaceSndAlias != 0; + } +} // namespace + +InfoStringLoaderPhysPreset::InfoStringLoaderPhysPreset(MemoryManager& memory, Zone& zone) + : m_memory(memory), + m_zone(zone) +{ +} + +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()) + { + 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))); +} diff --git a/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h new file mode 100644 index 000000000..952809564 --- /dev/null +++ b/src/ObjLoading/Game/IW4/PhysPreset/InfoStringLoaderPhysPresetIW4.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetCreationResult.h" +#include "InfoString/InfoString.h" + +namespace IW4 +{ + class InfoStringLoaderPhysPreset + { + public: + explicit InfoStringLoaderPhysPreset(MemoryManager& memory, Zone& zone); + + AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); + + private: + MemoryManager& m_memory; + Zone& m_zone; + }; +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp new file mode 100644 index 000000000..ada031acf --- /dev/null +++ b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.cpp @@ -0,0 +1,36 @@ +#include "RawLoaderPhysPresetIW4.h" + +#include "Game/IW4/IW4.h" +#include "Game/IW4/ObjConstantsIW4.h" +#include "InfoString/InfoString.h" +#include "InfoStringLoaderPhysPresetIW4.h" + +#include +#include + +using namespace IW4; + +RawLoaderPhysPreset::RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) +{ +} + +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)) + { + std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName); + return AssetCreationResult::Failure(); + } + + InfoStringLoaderPhysPreset infoStringLoader(m_memory, m_zone); + return infoStringLoader.CreateAsset(assetName, infoString, context); +} diff --git a/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h new file mode 100644 index 000000000..1c3dd8413 --- /dev/null +++ b/src/ObjLoading/Game/IW4/PhysPreset/RawLoaderPhysPresetIW4.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +namespace IW4 +{ + 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 diff --git a/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp new file mode 100644 index 000000000..724276924 --- /dev/null +++ b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.cpp @@ -0,0 +1,91 @@ +#include "AssetLoaderRawFileIW4.h" + +#include "Game/IW4/IW4.h" + +#include +#include +#include +#include +#include + +using namespace IW4; + +namespace +{ + constexpr size_t COMPRESSED_BUFFER_SIZE_PADDING = 64u; + + class RawFileLoader final : public AssetCreator + { + public: + RawFileLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + const auto uncompressedBuffer = std::make_unique(static_cast(file.m_length)); + file.m_stream->read(uncompressedBuffer.get(), file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + + const auto compressionBufferSize = static_cast(file.m_length + COMPRESSED_BUFFER_SIZE_PADDING); + auto* compressedBuffer = m_memory.Alloc(compressionBufferSize); + + z_stream_s zs{}; + + zs.zalloc = Z_NULL; + zs.zfree = Z_NULL; + zs.opaque = Z_NULL; + zs.avail_in = static_cast(file.m_length); + zs.avail_out = compressionBufferSize; + zs.next_in = reinterpret_cast(uncompressedBuffer.get()); + zs.next_out = reinterpret_cast(compressedBuffer); + + int ret = deflateInit(&zs, Z_DEFAULT_COMPRESSION); + + if (ret != Z_OK) + { + throw std::runtime_error("Initializing deflate failed"); + } + + ret = deflate(&zs, Z_FINISH); + + if (ret != Z_STREAM_END) + { + std::cerr << std::format("Deflate failed for loading rawfile \"{}\"\n", assetName); + deflateEnd(&zs); + return AssetCreationResult::Failure(); + } + + const auto compressedSize = compressionBufferSize - zs.avail_out; + + auto* rawFile = m_memory.Alloc(); + rawFile->name = m_memory.Dup(assetName.c_str()); + rawFile->compressedLen = static_cast(compressedSize); + rawFile->len = static_cast(file.m_length); + rawFile->data.compressedBuffer = static_cast(compressedBuffer); + + deflateEnd(&zs); + + return AssetCreationResult::Success(context.AddAsset(assetName, rawFile)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h new file mode 100644 index 000000000..e81633420 --- /dev/null +++ b/src/ObjLoading/Game/IW4/RawFile/LoaderRawFileIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp new file mode 100644 index 000000000..876189d5a --- /dev/null +++ b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp @@ -0,0 +1,67 @@ +#include "AssetLoaderPixelShaderIW4.h" + +#include "Game/IW4/IW4.h" + +#include +#include +#include + +using namespace IW4; + +namespace +{ + class PixelShaderLoader final : public AssetCreator + { + public: + PixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = GetFileNameForAsset(assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + if (file.m_length % sizeof(uint32_t) != 0) + { + std::cerr << std::format("Invalid pixel shader \"{}\": Size must be dividable by {}\n", assetName, sizeof(uint32_t)); + return AssetCreationResult::Failure(); + } + + auto* pixelShader = m_memory.Alloc(); + pixelShader->name = m_memory.Dup(assetName.c_str()); + pixelShader->prog.loadDef.programSize = static_cast(static_cast(file.m_length) / sizeof(uint32_t)); + pixelShader->prog.loadDef.loadForRenderer = 0; + pixelShader->prog.ps = nullptr; + + auto* fileBuffer = m_memory.Alloc(pixelShader->prog.loadDef.programSize); + file.m_stream->read(reinterpret_cast(fileBuffer), static_cast(pixelShader->prog.loadDef.programSize) * sizeof(uint32_t)); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + + pixelShader->prog.loadDef.program = fileBuffer; + return AssetCreationResult::Success(context.AddAsset(assetName, pixelShader)); + } + + private: + std::string GetFileNameForAsset(const std::string& assetName) + { + return std::format("shader_bin/ps_{}.cso", assetName); + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreatePixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h new file mode 100644 index 000000000..2eb215adb --- /dev/null +++ b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreatePixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp new file mode 100644 index 000000000..2bfbeafa7 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp @@ -0,0 +1,67 @@ +#include "AssetLoaderVertexShaderIW4.h" + +#include "Game/IW4/IW4.h" + +#include +#include +#include + +using namespace IW4; + +namespace +{ + class VertexShaderLoader final : public AssetCreator + { + public: + VertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = GetFileNameForAsset(assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + if (file.m_length % sizeof(uint32_t) != 0) + { + std::cerr << std::format("Invalid vertex shader \"{}\": Size must be dividable by {}\n", assetName, sizeof(uint32_t)); + return AssetCreationResult::Failure(); + } + + auto* vertexShader = m_memory.Alloc(); + vertexShader->name = m_memory.Dup(assetName.c_str()); + vertexShader->prog.loadDef.programSize = static_cast(static_cast(file.m_length) / sizeof(uint32_t)); + vertexShader->prog.loadDef.loadForRenderer = 0; + vertexShader->prog.vs = nullptr; + + auto* fileBuffer = m_memory.Alloc(vertexShader->prog.loadDef.programSize); + file.m_stream->read(reinterpret_cast(fileBuffer), static_cast(vertexShader->prog.loadDef.programSize) * sizeof(uint32_t)); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + + vertexShader->prog.loadDef.program = fileBuffer; + return AssetCreationResult::Success(context.AddAsset(assetName, vertexShader)); + } + + private: + std::string GetFileNameForAsset(const std::string& assetName) + { + return std::format("shader_bin/vs_{}.cso", assetName); + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateVertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h new file mode 100644 index 000000000..d8c7dd574 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateVertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp new file mode 100644 index 000000000..5f7607541 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.cpp @@ -0,0 +1,78 @@ +#include "LoaderSoundCurveIW4.h" + +#include "Game/IW4/IW4.h" +#include "ObjLoading.h" +#include "Parsing/Graph2D/Graph2DReader.h" +#include "Pool/GlobalAssetPool.h" + +#include +#include +#include +#include + +using namespace IW4; + +namespace +{ + class LoaderSoundCurve final : public AssetCreator + { + public: + LoaderSoundCurve(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = std::format("soundaliases/{}.vfcurve", assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + const auto sndCurveData = graph2d::Read("sound curve", "SNDCURVE", *file.m_stream, fileName, assetName); + + if (!sndCurveData) + return AssetCreationResult::Failure(); + + if (sndCurveData->knots.size() > std::extent_v) + { + std::cerr << std::format("Failed to load SndCurve \"{}\": Too many knots ({})\n", assetName, sndCurveData->knots.size()); + return AssetCreationResult::Failure(); + } + + auto* sndCurve = m_memory.Alloc(); + sndCurve->filename = m_memory.Dup(assetName.c_str()); + sndCurve->knotCount = static_cast(sndCurveData->knots.size()); + + for (auto i = 0u; i < std::extent_v; i++) + { + if (i < sndCurveData->knots.size()) + { + const auto& [x, y] = sndCurveData->knots[i]; + sndCurve->knots[i][0] = static_cast(x); + sndCurve->knots[i][1] = static_cast(y); + } + else + { + sndCurve->knots[i][0] = 0; + sndCurve->knots[i][1] = 0; + } + } + + return AssetCreationResult::Success(context.AddAsset(assetName, sndCurve)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateSoundCurveLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h new file mode 100644 index 000000000..19f1bb3c6 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Sound/LoaderSoundCurveIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateSoundCurveLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp new file mode 100644 index 000000000..d45307722 --- /dev/null +++ b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.cpp @@ -0,0 +1,47 @@ +#include "LoaderStringTableIW4.h" + +#include "Csv/CsvStream.h" +#include "Game/IW4/CommonIW4.h" +#include "Game/IW4/IW4.h" +#include "StringTable/StringTableLoader.h" + +using namespace IW4; + +namespace +{ + class LoaderStringTable final : public AssetCreator + { + public: + LoaderStringTable(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + string_table::StringTableLoaderV2 loader; + auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream); + if (!stringTable) + return AssetCreationResult::Failure(); + + return AssetCreationResult::Success(context.AddAsset(assetName, stringTable)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h new file mode 100644 index 000000000..c9cbd55f9 --- /dev/null +++ b/src/ObjLoading/Game/IW4/StringTable/LoaderStringTableIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp new file mode 100644 index 000000000..cbf2e51f6 --- /dev/null +++ b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.cpp @@ -0,0 +1,225 @@ +#include "LoaderStructuredDataDefIW4.h" + +#include "Game/IW4/IW4.h" +#include "StructuredDataDef/StructuredDataDefReader.h" +#include "Utils/Alignment.h" + +#include +#include + +using namespace IW4; + +namespace +{ + class StructuredDataDefLoader final : public AssetCreator + { + public: + StructuredDataDefLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(assetName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + StructuredDataDefReader reader(*file.m_stream, + assetName, + [this](const std::string& filename, const std::string& sourceFile) -> std::unique_ptr + { + auto foundFileToInclude = m_search_path.Open(filename); + if (!foundFileToInclude.IsOpen() || !foundFileToInclude.m_stream) + return nullptr; + + return std::move(foundFileToInclude.m_stream); + }); + + bool readingDefsSuccessful; + const auto defs = reader.ReadStructureDataDefs(readingDefsSuccessful); + + if (!readingDefsSuccessful) + return AssetCreationResult::Failure(); + + return AssetCreationResult::Success(context.AddAsset(assetName, ConvertSet(assetName, defs))); + } + + private: + StructuredDataType ConvertType(CommonStructuredDataType inputType) + { + switch (inputType.m_category) + { + case CommonStructuredDataTypeCategory::INT: + return {DATA_INT, {0}}; + case CommonStructuredDataTypeCategory::BYTE: + return {DATA_BYTE, {0}}; + case CommonStructuredDataTypeCategory::BOOL: + return {DATA_BOOL, {0}}; + case CommonStructuredDataTypeCategory::FLOAT: + return {DATA_FLOAT, {0}}; + case CommonStructuredDataTypeCategory::SHORT: + return {DATA_SHORT, {0}}; + case CommonStructuredDataTypeCategory::STRING: + return {DATA_STRING, {inputType.m_info.string_length}}; + case CommonStructuredDataTypeCategory::ENUM: + return {DATA_ENUM, {inputType.m_info.type_index}}; + case CommonStructuredDataTypeCategory::STRUCT: + return {DATA_STRUCT, {inputType.m_info.type_index}}; + case CommonStructuredDataTypeCategory::INDEXED_ARRAY: + return {DATA_INDEXED_ARRAY, {inputType.m_info.type_index}}; + case CommonStructuredDataTypeCategory::ENUM_ARRAY: + return {DATA_ENUM_ARRAY, {inputType.m_info.type_index}}; + case CommonStructuredDataTypeCategory::UNKNOWN: + default: + assert(false); + return {DATA_INT, {0}}; + } + } + + void ConvertEnum(CommonStructuredDataEnum& inputEnum, StructuredDataEnum& outputEnum) + { + outputEnum.entryCount = static_cast(inputEnum.m_entries.size()); + if (inputEnum.m_reserved_entry_count <= 0) + outputEnum.reservedEntryCount = outputEnum.entryCount; + else + outputEnum.reservedEntryCount = inputEnum.m_reserved_entry_count; + + inputEnum.SortEntriesByName(); + if (!inputEnum.m_entries.empty()) + { + outputEnum.entries = m_memory.Alloc(inputEnum.m_entries.size()); + for (auto entryIndex = 0u; entryIndex < inputEnum.m_entries.size(); entryIndex++) + { + auto& outputEntry = outputEnum.entries[entryIndex]; + const auto& inputEntry = inputEnum.m_entries[entryIndex]; + + outputEntry.string = m_memory.Dup(inputEntry.m_name.c_str()); + outputEntry.index = static_cast(inputEntry.m_value); + } + } + else + outputEnum.entries = nullptr; + } + + void ConvertStruct(CommonStructuredDataStruct& inputStruct, StructuredDataStruct& outputStruct) + { + outputStruct.size = static_cast(inputStruct.m_size_in_byte); + outputStruct.bitOffset = inputStruct.m_bit_offset; + + outputStruct.propertyCount = static_cast(inputStruct.m_properties.size()); + inputStruct.SortPropertiesByName(); + if (!inputStruct.m_properties.empty()) + { + outputStruct.properties = m_memory.Alloc(inputStruct.m_properties.size()); + for (auto propertyIndex = 0u; propertyIndex < inputStruct.m_properties.size(); propertyIndex++) + { + auto& outputProperty = outputStruct.properties[propertyIndex]; + const auto& inputProperty = inputStruct.m_properties[propertyIndex]; + + outputProperty.name = m_memory.Dup(inputProperty.m_name.c_str()); + outputProperty.type = ConvertType(inputProperty.m_type); + + if (outputProperty.type.type != DATA_BOOL) + { + assert(inputProperty.m_offset_in_bits % 8 == 0); + outputProperty.offset = inputProperty.m_offset_in_bits / 8; + } + else + outputProperty.offset = inputProperty.m_offset_in_bits; + } + } + else + outputStruct.properties = nullptr; + } + + void ConvertIndexedArray(const CommonStructuredDataIndexedArray& inputIndexedArray, StructuredDataIndexedArray& outputIndexedArray) + { + outputIndexedArray.arraySize = static_cast(inputIndexedArray.m_element_count); + outputIndexedArray.elementType = ConvertType(inputIndexedArray.m_array_type); + outputIndexedArray.elementSize = utils::Align(inputIndexedArray.m_element_size_in_bits, 8u) / 8u; + } + + void ConvertEnumedArray(const CommonStructuredDataEnumedArray& inputEnumedArray, StructuredDataEnumedArray& outputEnumedArray) + { + outputEnumedArray.enumIndex = static_cast(inputEnumedArray.m_enum_index); + outputEnumedArray.elementType = ConvertType(inputEnumedArray.m_array_type); + outputEnumedArray.elementSize = utils::Align(inputEnumedArray.m_element_size_in_bits, 8u) / 8u; + } + + void ConvertDef(const CommonStructuredDataDef& inputDef, StructuredDataDef& outputDef) + { + outputDef.version = inputDef.m_version; + outputDef.formatChecksum = inputDef.m_checksum; + + outputDef.enumCount = static_cast(inputDef.m_enums.size()); + if (!inputDef.m_enums.empty()) + { + outputDef.enums = m_memory.Alloc(inputDef.m_enums.size()); + for (auto enumIndex = 0u; enumIndex < inputDef.m_enums.size(); enumIndex++) + ConvertEnum(*inputDef.m_enums[enumIndex], outputDef.enums[enumIndex]); + } + else + outputDef.enums = nullptr; + + outputDef.structCount = static_cast(inputDef.m_structs.size()); + if (!inputDef.m_structs.empty()) + { + outputDef.structs = m_memory.Alloc(inputDef.m_structs.size()); + for (auto structIndex = 0u; structIndex < inputDef.m_structs.size(); structIndex++) + ConvertStruct(*inputDef.m_structs[structIndex], outputDef.structs[structIndex]); + } + else + outputDef.structs = nullptr; + + outputDef.indexedArrayCount = static_cast(inputDef.m_indexed_arrays.size()); + if (!inputDef.m_indexed_arrays.empty()) + { + outputDef.indexedArrays = m_memory.Alloc(inputDef.m_indexed_arrays.size()); + for (auto indexedArrayIndex = 0u; indexedArrayIndex < inputDef.m_indexed_arrays.size(); indexedArrayIndex++) + ConvertIndexedArray(inputDef.m_indexed_arrays[indexedArrayIndex], outputDef.indexedArrays[indexedArrayIndex]); + } + else + outputDef.indexedArrays = nullptr; + + outputDef.enumedArrayCount = static_cast(inputDef.m_enumed_arrays.size()); + if (!inputDef.m_enumed_arrays.empty()) + { + outputDef.enumedArrays = m_memory.Alloc(inputDef.m_enumed_arrays.size()); + for (auto enumedArrayIndex = 0u; enumedArrayIndex < inputDef.m_enumed_arrays.size(); enumedArrayIndex++) + ConvertEnumedArray(inputDef.m_enumed_arrays[enumedArrayIndex], outputDef.enumedArrays[enumedArrayIndex]); + } + else + outputDef.enumedArrays = nullptr; + + outputDef.rootType = ConvertType(inputDef.m_root_type); + outputDef.size = inputDef.m_size_in_byte; + } + + StructuredDataDefSet* ConvertSet(const std::string& assetName, const std::vector>& commonDefs) + { + auto* set = m_memory.Alloc(); + set->name = m_memory.Dup(assetName.c_str()); + + set->defCount = commonDefs.size(); + set->defs = m_memory.Alloc(commonDefs.size()); + + for (auto defIndex = 0u; defIndex < commonDefs.size(); defIndex++) + ConvertDef(*commonDefs[defIndex], set->defs[defIndex]); + + return set; + } + + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateStructuredDataDefLoader(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h new file mode 100644 index 000000000..22d40f098 --- /dev/null +++ b/src/ObjLoading/Game/IW4/StructuredDataDef/LoaderStructuredDataDefIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateStructuredDataDefLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp b/src/ObjLoading/Game/IW4/Techset/LoaderTechsetIW4.cpp similarity index 89% rename from src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp rename to src/ObjLoading/Game/IW4/Techset/LoaderTechsetIW4.cpp index c7b330ecd..02c99a08c 100644 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp +++ b/src/ObjLoading/Game/IW4/Techset/LoaderTechsetIW4.cpp @@ -1,11 +1,9 @@ -#include "AssetLoaderTechniqueSet.h" +#include "LoaderTechsetIW4.h" #include "AssetLoaderPixelShader.h" #include "AssetLoaderVertexShader.h" #include "Game/IW4/IW4.h" #include "Game/IW4/TechsetConstantsIW4.h" -#include "ObjLoading.h" -#include "Pool/GlobalAssetPool.h" #include "Shader/D3D9ShaderAnalyser.h" #include "StateMap/StateMapReader.h" #include "Techset/TechniqueFileReader.h" @@ -13,9 +11,9 @@ #include "Techset/TechsetDefinitionCache.h" #include "Techset/TechsetFileReader.h" #include "Utils/Alignment.h" -#include "Utils/ClassUtils.h" #include +#include #include #include #include @@ -25,7 +23,7 @@ using namespace IW4; using namespace std::string_literals; -namespace IW4 +namespace { class LoadedTechnique { @@ -121,14 +119,6 @@ namespace IW4 class TechniqueCreator final : public techset::ITechniqueDefinitionAcceptor { - const std::string& m_technique_name; - ISearchPath* const m_search_path; - MemoryManager* const m_memory; - IAssetLoadingManager* const m_manager; - TechniqueZoneLoadingState* const m_zone_state; - techset::TechniqueStateMapCache* const m_state_map_cache; - ShaderInfoFromFileSystemCacheState* const m_shader_info_cache; - public: class PassShaderArgument { @@ -206,20 +196,14 @@ namespace IW4 std::vector m_passes; std::vector m_dependencies; - TechniqueCreator(const std::string& techniqueName, - ISearchPath* searchPath, - MemoryManager* memory, - IAssetLoadingManager* manager, - TechniqueZoneLoadingState* zoneState, - ShaderInfoFromFileSystemCacheState* shaderInfoCache, - techset::TechniqueStateMapCache* stateMapCache) + TechniqueCreator(const std::string& techniqueName, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context) : m_technique_name(techniqueName), m_search_path(searchPath), m_memory(memory), - m_manager(manager), - m_zone_state(zoneState), - m_state_map_cache(stateMapCache), - m_shader_info_cache(shaderInfoCache) + m_context(context), + m_zone_state(context.GetZoneAssetLoaderState()), + m_state_map_cache(context.GetZoneAssetLoaderState()), + m_shader_info_cache(context.GetZoneAssetLoaderState()) { } @@ -1036,17 +1020,45 @@ namespace IW4 pass.m_vertex_decl.streamCount++; return true; } + + private: + const std::string& m_technique_name; + ISearchPath& m_search_path; + MemoryManager& m_memory; + AssetCreationContext& m_context; + TechniqueZoneLoadingState* m_zone_state; + techset::TechniqueStateMapCache* m_state_map_cache; + ShaderInfoFromFileSystemCacheState* m_shader_info_cache; }; class TechniqueLoader { - ISearchPath* m_search_path; - MemoryManager* m_memory; - IAssetLoadingManager* m_manager; - TechniqueZoneLoadingState* m_zone_state; - ShaderInfoFromFileSystemCacheState* m_shader_info_cache; - techset::TechniqueStateMapCache* m_state_map_cache; + public: + TechniqueLoader(ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context) + : m_search_path(searchPath), + m_memory(memory), + m_context(context), + m_zone_state(context.GetZoneAssetLoaderState()), + m_shader_info_cache(context.GetZoneAssetLoaderState()), + m_state_map_cache(context.GetZoneAssetLoaderState()) + { + } + _NODISCARD const LoadedTechnique* LoadMaterialTechnique(const std::string& techniqueName) const + { + auto* technique = m_zone_state->FindLoadedTechnique(techniqueName); + if (technique) + return technique; + + std::vector dependencies; + auto* techniqueFromRaw = LoadTechniqueFromRaw(techniqueName, dependencies); + if (techniqueFromRaw == nullptr) + return nullptr; + + return m_zone_state->AddLoadedTechnique(techniqueName, techniqueFromRaw, dependencies); + } + + private: static void UpdateTechniqueFlags(MaterialTechnique& technique) { // This is stupid but that's what the game does for zprepass for sure @@ -1159,7 +1171,7 @@ namespace IW4 out.pixelShader = in.m_pixel_shader->Asset(); out.vertexDecl = in.m_vertex_decl_asset->Asset(); - out.args = m_memory->Alloc(in.m_arguments.size()); + out.args = m_memory.Alloc(in.m_arguments.size()); size_t perObjArgCount = 0u; size_t perPrimArgCount = 0u; @@ -1220,8 +1232,8 @@ namespace IW4 { assert(!passes.empty()); const auto techniqueSize = sizeof(MaterialTechnique) + (passes.size() - 1u) * sizeof(MaterialPass); - auto* technique = static_cast(m_memory->AllocRaw(techniqueSize)); - technique->name = m_memory->Dup(techniqueName.c_str()); + auto* technique = static_cast(m_memory.AllocRaw(techniqueSize)); + technique->name = m_memory.Dup(techniqueName.c_str()); technique->passCount = static_cast(passes.size()); UpdateTechniqueFlags(*technique); @@ -1235,11 +1247,11 @@ namespace IW4 MaterialTechnique* LoadTechniqueFromRaw(const std::string& techniqueName, std::vector& dependencies) const { const auto techniqueFileName = AssetLoaderTechniqueSet::GetTechniqueFileName(techniqueName); - const auto file = m_search_path->Open(techniqueFileName); + const auto file = m_search_path.Open(techniqueFileName); if (!file.IsOpen()) return nullptr; - TechniqueCreator creator(techniqueName, m_search_path, m_memory, m_manager, m_zone_state, m_shader_info_cache, m_state_map_cache); + TechniqueCreator creator(techniqueName, m_search_path, m_memory, m_context, m_zone_state, m_shader_info_cache, m_state_map_cache); const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &creator); if (!reader.ReadTechniqueDefinition()) return nullptr; @@ -1247,150 +1259,124 @@ namespace IW4 return ConvertTechnique(techniqueName, creator.m_passes, dependencies); } + ISearchPath& m_search_path; + MemoryManager& m_memory; + AssetCreationContext& m_context; + TechniqueZoneLoadingState* m_zone_state; + ShaderInfoFromFileSystemCacheState* m_shader_info_cache; + techset::TechniqueStateMapCache* m_state_map_cache; + }; + + class LoaderTechset final : public ITechsetCreator + { public: - TechniqueLoader(ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) - : m_search_path(searchPath), - m_memory(memory), - m_manager(manager), - m_zone_state(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState()), - m_shader_info_cache(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState()), - m_state_map_cache(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState()) + LoaderTechset(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) { } - _NODISCARD const LoadedTechnique* LoadMaterialTechnique(const std::string& techniqueName) const + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - auto* technique = m_zone_state->FindLoadedTechnique(techniqueName); - if (technique) - return technique; + const auto* techsetDefinition = LoadTechsetDefinition(assetName, context); + if (techsetDefinition) + return CreateTechsetFromDefinition(assetName, *techsetDefinition, context); - std::vector dependencies; - auto* techniqueFromRaw = LoadTechniqueFromRaw(techniqueName, dependencies); - if (techniqueFromRaw == nullptr) - return nullptr; - - return m_zone_state->AddLoadedTechnique(techniqueName, techniqueFromRaw, dependencies); + return false; } - }; -} // namespace IW4 -void* AssetLoaderTechniqueSet::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) -{ - auto* techset = memory->Create(); - memset(techset, 0, sizeof(MaterialTechniqueSet)); - techset->name = memory->Dup(assetName.c_str()); - return techset; -} - -std::string AssetLoaderTechniqueSet::GetTechsetFileName(const std::string& techsetAssetName) -{ - std::ostringstream ss; - ss << "techsets/" << techsetAssetName << ".techset"; - return ss.str(); -} - -std::string AssetLoaderTechniqueSet::GetTechniqueFileName(const std::string& techniqueName) -{ - std::ostringstream ss; - ss << "techniques/" << techniqueName << ".tech"; - return ss.str(); -} + private: + bool CreateTechsetFromDefinition(const std::string& assetName, const techset::TechsetDefinition& definition, AssetCreationContext& context) + { + auto* techset = m_memory.Alloc(); + techset->name = m_memory.Dup(assetName.c_str()); -std::string AssetLoaderTechniqueSet::GetStateMapFileName(const std::string& stateMapName) -{ - std::ostringstream ss; - ss << "statemaps/" << stateMapName << ".sm"; - return ss.str(); -} + const TechniqueLoader techniqueLoader(m_search_path, m_memory, context); + std::set dependencies; + for (auto i = 0u; i < std::extent_v; i++) + { + std::string techniqueName; + if (definition.GetTechniqueByIndex(i, techniqueName)) + { + auto* technique = techniqueLoader.LoadMaterialTechnique(techniqueName); -bool AssetLoaderTechniqueSet::CreateTechsetFromDefinition( - const std::string& assetName, const techset::TechsetDefinition& definition, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) -{ - auto* techset = memory->Create(); - memset(techset, 0, sizeof(MaterialTechniqueSet)); - techset->name = memory->Dup(assetName.c_str()); + if (!technique) + return false; - const TechniqueLoader techniqueLoader(searchPath, memory, manager); - std::set dependencies; - for (auto i = 0u; i < std::extent_v; i++) - { - std::string techniqueName; - if (definition.GetTechniqueByIndex(i, techniqueName)) - { - auto* technique = techniqueLoader.LoadMaterialTechnique(techniqueName); + for (auto* techniqueDependency : technique->m_dependencies) + dependencies.emplace(techniqueDependency); - if (!technique) - return false; + techset->techniques[i] = technique->m_technique; + } + } - for (auto* techniqueDependency : technique->m_dependencies) - dependencies.emplace(techniqueDependency); + manager->AddAsset(assetName, techset, std::vector(dependencies.begin(), dependencies.end())); - techset->techniques[i] = technique->m_technique; + return true; } - } - manager->AddAsset(assetName, techset, std::vector(dependencies.begin(), dependencies.end())); - - return true; -} + static std::string GetTechsetFileName(const std::string& techsetAssetName) + { + return std::format("techsets/{}.techset", techsetAssetName); + } -techset::TechsetDefinition* - AssetLoaderTechniqueSet::LoadTechsetDefinition(const std::string& assetName, ISearchPath* searchPath, techset::TechsetDefinitionCache* definitionCache) -{ - auto* cachedTechsetDefinition = definitionCache->GetCachedTechsetDefinition(assetName); - if (cachedTechsetDefinition) - return cachedTechsetDefinition; + std::string GetTechniqueFileName(const std::string& techniqueName) const override + { + return std::format("techniques/{}.tech", techniqueName); + } - const auto techsetFileName = GetTechsetFileName(assetName); - const auto file = searchPath->Open(techsetFileName); - if (!file.IsOpen()) - return nullptr; + static std::string GetStateMapFileName(const std::string& stateMapName) + { + return std::format("statemaps/{}.sm", stateMapName); + } - const techset::TechsetFileReader reader(*file.m_stream, techsetFileName, techniqueTypeNames, std::extent_v); - auto techsetDefinition = reader.ReadTechsetDefinition(); - auto* techsetDefinitionPtr = techsetDefinition.get(); + techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context) override + { + auto* definitionCache = context.GetZoneAssetLoaderState(); + auto* cachedTechsetDefinition = definitionCache->GetCachedTechsetDefinition(assetName); + if (cachedTechsetDefinition) + return cachedTechsetDefinition; - definitionCache->AddTechsetDefinitionToCache(assetName, std::move(techsetDefinition)); + const auto techsetFileName = GetTechsetFileName(assetName); + const auto file = m_search_path.Open(techsetFileName); + if (!file.IsOpen()) + return nullptr; - return techsetDefinitionPtr; -} + const techset::TechsetFileReader reader(*file.m_stream, techsetFileName, techniqueTypeNames, std::extent_v); + auto techsetDefinition = reader.ReadTechsetDefinition(); + auto* techsetDefinitionPtr = techsetDefinition.get(); -const state_map::StateMapDefinition* - AssetLoaderTechniqueSet::LoadStateMapDefinition(const std::string& stateMapName, ISearchPath* searchPath, techset::TechniqueStateMapCache* stateMapCache) -{ - auto* cachedStateMap = stateMapCache->GetCachedStateMap(stateMapName); - if (cachedStateMap) - return cachedStateMap; + definitionCache->AddTechsetDefinitionToCache(assetName, std::move(techsetDefinition)); - const auto stateMapFileName = GetStateMapFileName(stateMapName); - const auto file = searchPath->Open(stateMapFileName); - if (!file.IsOpen()) - return nullptr; + return techsetDefinitionPtr; + } - const state_map::StateMapReader reader(*file.m_stream, stateMapFileName, stateMapName, stateMapLayout); - auto stateMapDefinition = reader.ReadStateMapDefinition(); - if (!stateMapDefinition) - return nullptr; + const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) override + { + auto* stateMapCache = context.GetZoneAssetLoaderState(); + auto* cachedStateMap = stateMapCache->GetCachedStateMap(stateMapName); + if (cachedStateMap) + return cachedStateMap; - const auto* stateMapDefinitionPtr = stateMapDefinition.get(); + const auto stateMapFileName = GetStateMapFileName(stateMapName); + const auto file = m_search_path.Open(stateMapFileName); + if (!file.IsOpen()) + return nullptr; - stateMapCache->AddStateMapToCache(std::move(stateMapDefinition)); + const state_map::StateMapReader reader(*file.m_stream, stateMapFileName, stateMapName, stateMapLayout); + auto stateMapDefinition = reader.ReadStateMapDefinition(); + if (!stateMapDefinition) + return nullptr; - return stateMapDefinitionPtr; -} + const auto* stateMapDefinitionPtr = stateMapDefinition.get(); -bool AssetLoaderTechniqueSet::CanLoadFromRaw() const -{ - return true; -} + stateMapCache->AddStateMapToCache(std::move(stateMapDefinition)); -bool AssetLoaderTechniqueSet::LoadFromRaw( - const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const -{ - auto* definitionCache = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState(); - const auto* techsetDefinition = LoadTechsetDefinition(assetName, searchPath, definitionCache); - if (techsetDefinition) - return CreateTechsetFromDefinition(assetName, *techsetDefinition, searchPath, memory, manager); + return stateMapDefinitionPtr; + } - return false; -} + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace diff --git a/src/ObjLoading/Game/IW4/Techset/LoaderTechsetIW4.h b/src/ObjLoading/Game/IW4/Techset/LoaderTechsetIW4.h new file mode 100644 index 000000000..0512c0406 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Techset/LoaderTechsetIW4.h @@ -0,0 +1,26 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "StateMap/StateMapDefinition.h" +#include "Techset/TechsetDefinition.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + class ITechsetCreator : public AssetCreator + { + public: + ITechsetCreator() = default; + virtual ~ITechsetCreator() = default; + + virtual std::string GetTechniqueFileName(const std::string& techniqueName) const = 0; + virtual techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context) = 0; + virtual const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) = 0; + }; + + std::unique_ptr CreateTechsetLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.cpp b/src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.cpp new file mode 100644 index 000000000..64071166d --- /dev/null +++ b/src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.cpp @@ -0,0 +1,101 @@ +#include "LoaderVertexDeclIW4.h" + +#include "Game/IW4/IW4.h" +#include "Game/IW4/TechsetConstantsIW4.h" + +#include +#include +#include + +using namespace IW4; + +namespace +{ + class LoaderVertexDecl final : public AssetCreator + { + public: + LoaderVertexDecl(MemoryManager& memory) + : m_memory(memory) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + auto* decl = m_memory.Alloc(); + decl->name = m_memory.Dup(assetName.c_str()); + + size_t currentOffset = 0u; + + std::string sourceAbbreviation; + while (NextAbbreviation(assetName, sourceAbbreviation, currentOffset)) + { + if (decl->streamCount >= std::extent_v) + { + std::cerr << std::format("Failed to add vertex decl stream. Too many abbreviations: {}\n", assetName); + return AssetCreationResult::Failure(); + } + + std::string destinationAbbreviation; + if (!NextAbbreviation(assetName, destinationAbbreviation, currentOffset)) + { + std::cerr << std::format("Failed to detect vertex decl destination abbreviation: {}\n", assetName); + return AssetCreationResult::Failure(); + } + + const auto foundSourceAbbreviation = std::ranges::find(materialStreamSourceAbbreviation, sourceAbbreviation); + if (foundSourceAbbreviation == std::end(materialStreamSourceAbbreviation)) + { + std::cerr << std::format("Unknown vertex decl source abbreviation: {}\n", sourceAbbreviation); + return AssetCreationResult::Failure(); + } + + const auto foundDestinationAbbreviation = std::ranges::find(materialStreamDestinationAbbreviation, destinationAbbreviation); + if (foundDestinationAbbreviation == std::end(materialStreamDestinationAbbreviation)) + { + std::cerr << std::format("Unknown vertex decl destination abbreviation: {}\n", destinationAbbreviation); + return AssetCreationResult::Failure(); + } + + const auto sourceIndex = static_cast(foundSourceAbbreviation - std::begin(materialStreamSourceAbbreviation)); + const auto destinationIndex = + static_cast(foundDestinationAbbreviation - std::begin(materialStreamDestinationAbbreviation)); + + decl->routing.data[decl->streamCount].source = sourceIndex; + decl->routing.data[decl->streamCount].dest = destinationIndex; + decl->hasOptionalSource = decl->hasOptionalSource || sourceIndex >= STREAM_SRC_OPTIONAL_BEGIN; + decl->streamCount++; + } + + return AssetCreationResult::Success(context.AddAsset(assetName, decl)); + } + + static bool NextAbbreviation(const std::string& assetName, std::string& abbreviation, size_t& offset) + { + if (offset >= assetName.size()) + return false; + + if (offset + 1 < assetName.size() && isdigit(assetName[offset + 1])) + { + abbreviation = std::string(assetName, offset, 2); + offset += 2; + } + else + { + abbreviation = std::string(assetName, offset, 1); + offset += 1; + } + + return true; + } + + MemoryManager& m_memory; + }; +} // namespace + +namespace IW4 +{ + std::unique_ptr> CreateVertexDeclLoader(MemoryManager& memory) + { + return std::make_unique(memory); + } +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.h b/src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.h new file mode 100644 index 000000000..d4bd1b683 --- /dev/null +++ b/src/ObjLoading/Game/IW4/Techset/LoaderVertexDeclIW4.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/IW4/IW4.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace IW4 +{ + std::unique_ptr> CreateVertexDeclLoader(MemoryManager& memory); +} // namespace IW4 diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderWeapon.cpp b/src/ObjLoading/Game/IW4/Weapon/LoaderWeaponIW4.cpp similarity index 100% rename from src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderWeapon.cpp rename to src/ObjLoading/Game/IW4/Weapon/LoaderWeaponIW4.cpp diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderWeapon.h b/src/ObjLoading/Game/IW4/Weapon/LoaderWeaponIW4.h similarity index 100% rename from src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderWeapon.h rename to src/ObjLoading/Game/IW4/Weapon/LoaderWeaponIW4.h diff --git a/src/ObjLoading/Gdt/GdtLookup.cpp b/src/ObjLoading/Gdt/GdtLookup.cpp new file mode 100644 index 000000000..9cd66ed9d --- /dev/null +++ b/src/ObjLoading/Gdt/GdtLookup.cpp @@ -0,0 +1,44 @@ +#include "GdtLookup.h" + +void GdtLookup::Initialize(const std::vector& gdtFiles) +{ + m_entries_by_gdf_and_by_name.clear(); + + for (const auto* gdt : gdtFiles) + { + for (const auto& entry : gdt->m_entries) + { + auto gdfMapEntry = m_entries_by_gdf_and_by_name.find(entry->m_gdf_name); + if (gdfMapEntry == m_entries_by_gdf_and_by_name.end()) + { + std::unordered_map entryMap; + entryMap.emplace(entry->m_name, entry.get()); + m_entries_by_gdf_and_by_name.emplace(entry->m_gdf_name, std::move(entryMap)); + } + else + { + auto entryMapEntry = gdfMapEntry->second.find(entry->m_name); + + if (entryMapEntry == gdfMapEntry->second.end()) + gdfMapEntry->second.emplace(entry->m_name, entry.get()); + else + entryMapEntry->second = entry.get(); + } + } + } +} + +GdtEntry* GdtLookup::GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) +{ + const auto foundGdtMap = m_entries_by_gdf_and_by_name.find(gdfName); + + if (foundGdtMap == m_entries_by_gdf_and_by_name.end()) + return nullptr; + + const auto foundGdtEntry = foundGdtMap->second.find(entryName); + + if (foundGdtEntry == foundGdtMap->second.end()) + return nullptr; + + return foundGdtEntry->second; +} diff --git a/src/ObjLoading/Gdt/GdtLookup.h b/src/ObjLoading/Gdt/GdtLookup.h new file mode 100644 index 000000000..c7d073f18 --- /dev/null +++ b/src/ObjLoading/Gdt/GdtLookup.h @@ -0,0 +1,18 @@ +#pragma once + +#include "IGdtQueryable.h" +#include "Obj/Gdt/Gdt.h" + +#include +#include +#include + +class GdtLookup : public IGdtQueryable +{ +public: + void Initialize(const std::vector& gdtFiles); + GdtEntry* GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) override; + +private: + std::unordered_map> m_entries_by_gdf_and_by_name; +}; diff --git a/src/ObjLoading/AssetLoading/IGdtQueryable.h b/src/ObjLoading/Gdt/IGdtQueryable.h similarity index 99% rename from src/ObjLoading/AssetLoading/IGdtQueryable.h rename to src/ObjLoading/Gdt/IGdtQueryable.h index 09b034e57..9bf228560 100644 --- a/src/ObjLoading/AssetLoading/IGdtQueryable.h +++ b/src/ObjLoading/Gdt/IGdtQueryable.h @@ -1,4 +1,5 @@ #pragma once + #include "Obj/Gdt/GdtEntry.h" #include diff --git a/src/ObjLoading/IObjLoader.h b/src/ObjLoading/IObjLoader.h index 8df2d82f0..6b7c89013 100644 --- a/src/ObjLoading/IObjLoader.h +++ b/src/ObjLoading/IObjLoader.h @@ -2,6 +2,7 @@ #include "Asset/AssetCreatorCollection.h" #include "AssetLoading/AssetLoadingContext.h" +#include "Gdt/IGdtQueryable.h" #include "SearchPath/ISearchPath.h" #include "Zone/Zone.h" @@ -28,7 +29,7 @@ class IObjLoader */ virtual void UnloadContainersOfZone(Zone& zone) const = 0; - virtual void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const = 0; + virtual void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const = 0; static const IObjLoader* GetObjLoaderForGame(GameId game); }; diff --git a/src/ObjLoading/InfoString/InfoStringToStructConverterBase.cpp b/src/ObjLoading/InfoString/InfoStringToStructConverterBase.cpp index a2686ddf5..33e6dd601 100644 --- a/src/ObjLoading/InfoString/InfoStringToStructConverterBase.cpp +++ b/src/ObjLoading/InfoString/InfoStringToStructConverterBase.cpp @@ -1,17 +1,22 @@ #include "InfoStringToStructConverterBase.h" #include +#include #include #include InfoStringToStructConverterBase::InfoStringToStructConverterBase(const InfoString& infoString, void* structure, ZoneScriptStrings& zoneScriptStrings, - MemoryManager* memory) + MemoryManager& memory, + AssetCreationContext& context, + GenericAssetRegistration& registration) : m_info_string(infoString), + m_structure(structure), m_zone_script_strings(zoneScriptStrings), m_memory(memory), - m_structure(structure) + m_context(context), + m_registration(registration) { } @@ -44,7 +49,7 @@ bool InfoStringToStructConverterBase::ParseAsArray(const std::string& value, std bool InfoStringToStructConverterBase::ConvertString(const std::string& value, const size_t offset) { - *reinterpret_cast(reinterpret_cast(m_structure) + offset) = m_memory->Dup(value.c_str()); + *reinterpret_cast(reinterpret_cast(m_structure) + offset) = m_memory.Dup(value.c_str()); return true; } @@ -61,7 +66,7 @@ bool InfoStringToStructConverterBase::ConvertInt(const std::string& value, const if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as int\n"; + std::cerr << std::format("Failed to parse value \"{}\" as int\n", value); return false; } @@ -75,7 +80,7 @@ bool InfoStringToStructConverterBase::ConvertUint(const std::string& value, cons if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as uint\n"; + std::cerr << std::format("Failed to parse value \"{}\" as uint\n", value); return false; } @@ -90,7 +95,7 @@ bool InfoStringToStructConverterBase::ConvertBool(const std::string& value, cons *reinterpret_cast(reinterpret_cast(m_structure) + offset) = intValue != 0; if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as bool\n"; + std::cerr << std::format("Failed to parse value \"{}\" as bool\n", value); return false; } @@ -105,7 +110,7 @@ bool InfoStringToStructConverterBase::ConvertQBoolean(const std::string& value, *reinterpret_cast(reinterpret_cast(m_structure) + offset) = intValue != 0 ? 1 : 0; if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as qboolean\n"; + std::cerr << std::format("Failed to parse value \"{}\" as qboolean\n", value); return false; } @@ -119,7 +124,7 @@ bool InfoStringToStructConverterBase::ConvertFloat(const std::string& value, con if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as float\n"; + std::cerr << std::format("Failed to parse value \"{}\" as float\n", value); return false; } @@ -133,7 +138,7 @@ bool InfoStringToStructConverterBase::ConvertMilliseconds(const std::string& val if (endPtr != &value[value.size()]) { - std::cout << "Failed to parse value \"" << value << "\" as milliseconds\n"; + std::cerr << std::format("Failed to parse value \"{}\" as milliseconds\n", value); return false; } @@ -143,7 +148,7 @@ bool InfoStringToStructConverterBase::ConvertMilliseconds(const std::string& val bool InfoStringToStructConverterBase::ConvertScriptString(const std::string& value, const size_t offset) { auto scrStrValue = m_zone_script_strings.AddOrGetScriptString(value); - m_used_script_string_list.emplace(scrStrValue); + m_registration.AddScriptString(scrStrValue); *reinterpret_cast(reinterpret_cast(m_structure) + offset) = scrStrValue; return true; @@ -176,39 +181,3 @@ bool InfoStringToStructConverterBase::ConvertEnumInt( return false; } - -std::vector InfoStringToStructConverterBase::GetUsedScriptStrings() const -{ - std::vector scrStringList; - scrStringList.reserve(m_used_script_string_list.size()); - for (auto scrStr : m_used_script_string_list) - { - scrStringList.push_back(scrStr); - } - - return scrStringList; -} - -std::vector InfoStringToStructConverterBase::GetDependencies() const -{ - std::vector dependencyList; - dependencyList.reserve(m_dependencies.size()); - for (auto* dependency : m_dependencies) - { - dependencyList.push_back(dependency); - } - - return dependencyList; -} - -std::vector InfoStringToStructConverterBase::GetIndirectAssetReferences() const -{ - std::vector indirectAssetReferences; - indirectAssetReferences.reserve(m_indirect_asset_references.size()); - for (auto& assetReference : m_indirect_asset_references) - { - indirectAssetReferences.emplace_back(assetReference); - } - - return indirectAssetReferences; -} diff --git a/src/ObjLoading/InfoString/InfoStringToStructConverterBase.h b/src/ObjLoading/InfoString/InfoStringToStructConverterBase.h index cc9be478a..af065f0f5 100644 --- a/src/ObjLoading/InfoString/InfoStringToStructConverterBase.h +++ b/src/ObjLoading/InfoString/InfoStringToStructConverterBase.h @@ -1,5 +1,7 @@ #pragma once +#include "Asset/AssetCreationContext.h" +#include "Asset/AssetRegistration.h" #include "InfoString/InfoString.h" #include "Pool/XAssetInfo.h" #include "Utils/ClassUtils.h" @@ -7,6 +9,7 @@ #include "Zone/ZoneScriptStrings.h" #include +#include #include #include #include @@ -14,15 +17,22 @@ class InfoStringToStructConverterBase { -protected: - const InfoString& m_info_string; - ZoneScriptStrings& m_zone_script_strings; - std::unordered_set m_used_script_string_list; - std::unordered_set m_dependencies; - std::unordered_set m_indirect_asset_references; - MemoryManager* m_memory; - void* m_structure; +public: + InfoStringToStructConverterBase(const InfoString& infoString, + void* structure, + ZoneScriptStrings& zoneScriptStrings, + MemoryManager& memory, + AssetCreationContext& context, + GenericAssetRegistration& registration); + virtual ~InfoStringToStructConverterBase() = default; + InfoStringToStructConverterBase(const InfoStringToStructConverterBase& other) = delete; + InfoStringToStructConverterBase(InfoStringToStructConverterBase&& other) noexcept = delete; + InfoStringToStructConverterBase& operator=(const InfoStringToStructConverterBase& other) = delete; + InfoStringToStructConverterBase& operator=(InfoStringToStructConverterBase&& other) noexcept = delete; + + virtual bool Convert() = 0; +protected: static bool ParseAsArray(const std::string& value, std::vector& valueArray); template static bool ParseAsArray(const std::string& value, std::vector>& valueArray) @@ -79,7 +89,7 @@ class InfoStringToStructConverterBase const auto isLastEntry = currentEntryOffset >= (ARRAY_SIZE - 1); if (isNextEntrySeparator != isLastEntry) { - std::cout << "Expected " << ARRAY_SIZE << " values but got new line\n"; + std::cerr << std::format("Expected {} values but got new line\n", ARRAY_SIZE); return false; } @@ -94,7 +104,7 @@ class InfoStringToStructConverterBase if (currentEntryOffset > 0) { - std::cout << "Expected " << ARRAY_SIZE << " values but got new line\n"; + std::cerr << std::format("Expected {} values but got new line\n", ARRAY_SIZE); return false; } @@ -112,16 +122,10 @@ class InfoStringToStructConverterBase bool ConvertScriptString(const std::string& value, size_t offset); bool ConvertEnumInt(const std::string& fieldName, const std::string& value, size_t offset, const char** enumValues, size_t enumSize); -public: - InfoStringToStructConverterBase(const InfoString& infoString, void* structure, ZoneScriptStrings& zoneScriptStrings, MemoryManager* memory); - virtual ~InfoStringToStructConverterBase() = default; - InfoStringToStructConverterBase(const InfoStringToStructConverterBase& other) = delete; - InfoStringToStructConverterBase(InfoStringToStructConverterBase&& other) noexcept = delete; - InfoStringToStructConverterBase& operator=(const InfoStringToStructConverterBase& other) = delete; - InfoStringToStructConverterBase& operator=(InfoStringToStructConverterBase&& other) noexcept = delete; - - virtual bool Convert() = 0; - _NODISCARD std::vector GetUsedScriptStrings() const; - _NODISCARD std::vector GetDependencies() const; - _NODISCARD std::vector GetIndirectAssetReferences() const; + const InfoString& m_info_string; + void* m_structure; + ZoneScriptStrings& m_zone_script_strings; + MemoryManager& m_memory; + AssetCreationContext& m_context; + GenericAssetRegistration& m_registration; }; diff --git a/src/ObjLoading/Menu/AbstractMenuConverter.cpp b/src/ObjLoading/Menu/AbstractMenuConverter.cpp index 0b05d76f7..86c4c6b60 100644 --- a/src/ObjLoading/Menu/AbstractMenuConverter.cpp +++ b/src/ObjLoading/Menu/AbstractMenuConverter.cpp @@ -1,35 +1,29 @@ #include "AbstractMenuConverter.h" +#include #include using namespace menu; -AbstractMenuConverter::AbstractMenuConverter(const bool disableOptimizations, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) +AbstractMenuConverter::AbstractMenuConverter(const bool disableOptimizations, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context) : m_disable_optimizations(disableOptimizations), m_search_path(searchPath), m_memory(memory), - m_manager(manager) + m_context(context) { } void AbstractMenuConverter::PrintConversionExceptionDetails(const MenuConversionException& e) { - std::cout << "ERROR while converting menu:\n"; - std::cout << " Menu: " << e.m_menu->m_name << "\n"; + std::cerr << "ERROR while converting menu:\n"; + std::cerr << std::format(" Menu: {}\n", e.m_menu->m_name); if (e.m_item) { - std::cout << "Item: "; - - if (!e.m_item->m_name.empty()) - { - std::cout << e.m_item->m_name << "\n"; - } - - std::cout << "\n"; + std::cerr << std::format("Item: {}\n", e.m_item->m_name); } - std::cout << " Message: " << e.m_message << "\n"; + std::cerr << std::format(" Message: {}\n", e.m_message); } const char* AbstractMenuConverter::ConvertString(const std::string& str) const @@ -37,5 +31,5 @@ const char* AbstractMenuConverter::ConvertString(const std::string& str) const if (str.empty()) return nullptr; - return m_memory->Dup(str.c_str()); + return m_memory.Dup(str.c_str()); } diff --git a/src/ObjLoading/Menu/AbstractMenuConverter.h b/src/ObjLoading/Menu/AbstractMenuConverter.h index 442e10544..1db72896a 100644 --- a/src/ObjLoading/Menu/AbstractMenuConverter.h +++ b/src/ObjLoading/Menu/AbstractMenuConverter.h @@ -1,6 +1,6 @@ #pragma once -#include "AssetLoading/IAssetLoadingManager.h" +#include "Asset/AssetCreationContext.h" #include "MenuConversionException.h" #include "SearchPath/ISearchPath.h" #include "Utils/ClassUtils.h" @@ -11,16 +11,14 @@ namespace menu class AbstractMenuConverter { protected: - bool m_disable_optimizations; - ISearchPath* m_search_path; - MemoryManager* m_memory; - IAssetLoadingManager* m_manager; - - AbstractMenuConverter(bool disableOptimizations, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager); + AbstractMenuConverter(bool disableOptimizations, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context); _NODISCARD const char* ConvertString(const std::string& str) const; - - public: static void PrintConversionExceptionDetails(const MenuConversionException& e); + + bool m_disable_optimizations; + ISearchPath& m_search_path; + MemoryManager& m_memory; + AssetCreationContext& m_context; }; } // namespace menu diff --git a/src/ObjLoading/Sound/SoundCurveLoader.cpp b/src/ObjLoading/Sound/SoundCurveLoader.cpp deleted file mode 100644 index cb5034ddc..000000000 --- a/src/ObjLoading/Sound/SoundCurveLoader.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "SoundCurveLoader.h" - -#include "Parsing/Graph2D/Graph2DReader.h" - -#include - -namespace sound_curve -{ - std::unique_ptr LoadSoundCurve(const IAssetLoadingManager* manager, const std::string& soundCurveName) - { - auto& searchPath = manager->GetAssetLoadingContext()->m_raw_search_path; - const auto fileName = std::format("soundaliases/{}.vfcurve", soundCurveName); - const auto file = searchPath.Open(fileName); - if (!file.IsOpen()) - { - return nullptr; - } - - return graph2d::Read("sound curve", "SNDCURVE", *file.m_stream, fileName, soundCurveName); - } -} // namespace sound_curve diff --git a/src/ObjLoading/Sound/SoundCurveLoader.h b/src/ObjLoading/Sound/SoundCurveLoader.h deleted file mode 100644 index 7982e780c..000000000 --- a/src/ObjLoading/Sound/SoundCurveLoader.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "AssetLoading/IAssetLoadingManager.h" -#include "Parsing/GenericGraph2D.h" - -#include - -namespace sound_curve -{ - std::unique_ptr LoadSoundCurve(const IAssetLoadingManager* manager, const std::string& soundCurveName); -} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPhysPreset.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPhysPreset.cpp index 05fe779d1..bfd6d990a 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPhysPreset.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPhysPreset.cpp @@ -1,8 +1,8 @@ #include "AssetDumperPhysPreset.h" #include "Game/IW4/InfoString/InfoStringFromStructConverter.h" -#include "Game/IW4/InfoString/PhysPresetFields.h" #include "Game/IW4/ObjConstantsIW4.h" +#include "Game/IW4/PhysPreset/PhysPresetFields.h" #include #include