From 6b72ac080fba4ebf26a03e4e561866f89f75b8be Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 14 Apr 2021 18:39:54 +0200 Subject: [PATCH] Finish iw3 zone code generation --- src/Common/Game/IW3/IW3_Assets.h | 31 +- src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp | 8 +- src/ZoneCode/Game/IW3/IW3.gen | 1 + src/ZoneCode/Game/IW3/IW3.h | 8 + src/ZoneCode/Game/IW3/IW3_Commands.txt | 2 +- src/ZoneCode/Game/IW3/XAssets/FxEffectDef.txt | 5 - src/ZoneCode/Game/IW3/XAssets/GameWorldSp.txt | 29 +- src/ZoneCode/Game/IW3/XAssets/GfxWorld.txt | 15 +- .../Game/IW3/XAssets/MaterialTechniqueSet.txt | 3 - src/ZoneCode/Game/IW3/XAssets/WeaponDef.txt | 25 +- src/ZoneCode/Game/IW3/XAssets/XModel.txt | 6 - src/ZoneCode/Game/IW3/XAssets/clipMap_t.txt | 2 +- src/ZoneCode/Game/IW3/XAssets/menuDef_t.txt | 4 +- .../Utils/AlignmentUtils.h | 3 + src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp | 332 ++++++++++++++++++ src/ZoneCommon/Game/IW3/GameAssetPoolIW3.h | 58 +++ .../IW3/XAssets/gfximage/gfximage_actions.cpp | 31 ++ .../IW3/XAssets/gfximage/gfximage_actions.h | 16 + .../loadedsound/loadedsound_actions.cpp | 24 ++ .../XAssets/loadedsound/loadedsound_actions.h | 15 + 20 files changed, 542 insertions(+), 76 deletions(-) diff --git a/src/Common/Game/IW3/IW3_Assets.h b/src/Common/Game/IW3/IW3_Assets.h index d3c65539..428ed715 100644 --- a/src/Common/Game/IW3/IW3_Assets.h +++ b/src/Common/Game/IW3/IW3_Assets.h @@ -414,7 +414,7 @@ namespace IW3 char pad[2]; }; - struct __declspec(align(2)) cbrushside_t + struct cbrushside_t { cplane_s* plane; unsigned int materialNum; @@ -462,6 +462,7 @@ namespace IW3 struct XModelStreamInfo { + char pad; }; struct XModel @@ -614,6 +615,22 @@ namespace IW3 unsigned int nameHash; }; + enum MaterialShaderArgumentType + { + MTL_ARG_MATERIAL_VERTEX_CONST = 0x0, + MTL_ARG_LITERAL_VERTEX_CONST = 0x1, + MTL_ARG_MATERIAL_PIXEL_SAMPLER = 0x2, + MTL_ARG_CODE_PRIM_BEGIN = 0x3, + MTL_ARG_CODE_VERTEX_CONST = 0x3, + MTL_ARG_CODE_PIXEL_SAMPLER = 0x4, + MTL_ARG_CODE_PIXEL_CONST = 0x5, + MTL_ARG_CODE_PRIM_END = 0x6, + MTL_ARG_MATERIAL_PIXEL_CONST = 0x6, + MTL_ARG_LITERAL_PIXEL_CONST = 0x7, + + MLT_ARG_COUNT + }; + struct MaterialShaderArgument { uint16_t type; @@ -731,10 +748,10 @@ namespace IW3 union GfxTexture { - void/*IDirect3DBaseTexture9*/* basemap; - void/*IDirect3DTexture9*/* map; - void/*IDirect3DVolumeTexture9*/* volmap; - void/*IDirect3DCubeTexture9*/* cubemap; + //void/*IDirect3DBaseTexture9*/* basemap; + //void/*IDirect3DTexture9*/* map; + //void/*IDirect3DVolumeTexture9*/* volmap; + //void/*IDirect3DCubeTexture9*/* cubemap; Texture* texture; GfxImageLoadDef* loadDef; }; @@ -1657,7 +1674,7 @@ namespace IW3 struct GfxWorldStreamInfo { - + char pad; }; struct GfxWorld @@ -1790,7 +1807,7 @@ namespace IW3 { int intVal; float floatVal; - const char* string; + const char* stringVal; }; enum expDataType diff --git a/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp b/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp index f5ad7e93..78a19afc 100644 --- a/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp +++ b/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp @@ -1,6 +1,6 @@ #include "ObjLoaderIW3.h" -#include "Game/IW4/GameIW4.h" -#include "Game/IW4/GameAssetPoolIW4.h" +#include "Game/IW3/GameIW3.h" +#include "Game/IW3/GameAssetPoolIW3.h" #include "ObjContainer/IPak/IPak.h" #include "ObjLoading.h" #include "AssetLoaders/AssetLoaderRawFile.h" @@ -49,7 +49,7 @@ ObjLoader::ObjLoader() bool ObjLoader::SupportsZone(Zone* zone) const { - return zone->m_game == &g_GameIW4; + return zone->m_game == &g_GameIW3; } bool ObjLoader::IsMpZone(Zone* zone) @@ -109,7 +109,7 @@ void ObjLoader::LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* void ObjLoader::LoadImageData(ISearchPath* searchPath, Zone* zone) { - auto* assetPool = dynamic_cast(zone->m_pools.get()); + auto* assetPool = dynamic_cast(zone->m_pools.get()); if (assetPool && assetPool->m_image != nullptr) { diff --git a/src/ZoneCode/Game/IW3/IW3.gen b/src/ZoneCode/Game/IW3/IW3.gen index e69de29b..7bd8cb1e 100644 --- a/src/ZoneCode/Game/IW3/IW3.gen +++ b/src/ZoneCode/Game/IW3/IW3.gen @@ -0,0 +1 @@ +# This file exists for automatically generating zone loading code. \ No newline at end of file diff --git a/src/ZoneCode/Game/IW3/IW3.h b/src/ZoneCode/Game/IW3/IW3.h index e69de29b..98e6e4af 100644 --- a/src/ZoneCode/Game/IW3/IW3.h +++ b/src/ZoneCode/Game/IW3/IW3.h @@ -0,0 +1,8 @@ +#pragma once + +// Entry point for IW3 code generation + +#include "../Common.h" +#include "../../../Common/Game/IW3/IW3_Assets.h" + +// EOF \ No newline at end of file diff --git a/src/ZoneCode/Game/IW3/IW3_Commands.txt b/src/ZoneCode/Game/IW3/IW3_Commands.txt index ef856e90..cf9d42f0 100644 --- a/src/ZoneCode/Game/IW3/IW3_Commands.txt +++ b/src/ZoneCode/Game/IW3/IW3_Commands.txt @@ -12,7 +12,7 @@ asset GfxImage ASSET_TYPE_IMAGE; asset snd_alias_list_t ASSET_TYPE_SOUND; asset SndCurve ASSET_TYPE_SOUND_CURVE; asset LoadedSound ASSET_TYPE_LOADED_SOUND; -asset clipMap_t ASSET_TYPE_CLIPMAP_MP; +asset clipMap_t ASSET_TYPE_CLIPMAP_PVS; asset ComWorld ASSET_TYPE_COMWORLD; asset GameWorldSp ASSET_TYPE_GAMEWORLD_SP; asset GameWorldMp ASSET_TYPE_GAMEWORLD_MP; diff --git a/src/ZoneCode/Game/IW3/XAssets/FxEffectDef.txt b/src/ZoneCode/Game/IW3/XAssets/FxEffectDef.txt index c0b1fc42..0e803c63 100644 --- a/src/ZoneCode/Game/IW3/XAssets/FxEffectDef.txt +++ b/src/ZoneCode/Game/IW3/XAssets/FxEffectDef.txt @@ -36,11 +36,6 @@ use FxEffectDefRef; set condition handle never; set string name; -// FxElemExtendedDefPtr -use FxElemExtendedDefPtr; -set condition trailDef FxElemDef::elemType == FX_ELEM_TYPE_TRAIL; -set condition sparkFountainDef FxElemDef::elemType == FX_ELEM_TYPE_SPARK_FOUNTAIN; - // FxTrailDef use FxTrailDef; set count verts vertCount; diff --git a/src/ZoneCode/Game/IW3/XAssets/GameWorldSp.txt b/src/ZoneCode/Game/IW3/XAssets/GameWorldSp.txt index 1cd3f011..c8d16979 100644 --- a/src/ZoneCode/Game/IW3/XAssets/GameWorldSp.txt +++ b/src/ZoneCode/Game/IW3/XAssets/GameWorldSp.txt @@ -36,31 +36,4 @@ set condition u::child axis >= 0; set reusable u::child; // pathnode_tree_nodes_t -set count pathnode_tree_nodes_t::nodes nodeCount; - -// VehicleTrack -use VehicleTrack; -set reusable segments; -set count segments segmentCount; - -// VehicleTrackSegment -use VehicleTrackSegment; -set string targetName; -set count sectors sectorCount; -set reusable nextBranches; -set count nextBranches nextBranchesCount; -set reusable prevBranches; -set count prevBranches prevBranchesCount; - -// VehicleTrackSector -set count VehicleTrackSector::obstacles obstacleCount; - -// G_GlassData -use G_GlassData; -set count glassPieces pieceCount; -set count glassNames glassNameCount; - -// G_GlassName -use G_GlassName; -set string nameStr; -set count pieceIndices pieceCount; \ No newline at end of file +set count pathnode_tree_nodes_t::nodes nodeCount; \ No newline at end of file diff --git a/src/ZoneCode/Game/IW3/XAssets/GfxWorld.txt b/src/ZoneCode/Game/IW3/XAssets/GfxWorld.txt index ceb27600..99e16a64 100644 --- a/src/ZoneCode/Game/IW3/XAssets/GfxWorld.txt +++ b/src/ZoneCode/Game/IW3/XAssets/GfxWorld.txt @@ -28,8 +28,8 @@ set count sceneDynBrush dpvsDyn::dynEntClientCount[1]; set block primaryLightEntityShadowVis XFILE_BLOCK_RUNTIME; set count primaryLightEntityShadowVis (primaryLightCount - sunPrimaryLightIndex - 1) * 0x2000; set block primaryLightDynEntShadowVis XFILE_BLOCK_RUNTIME; -set count primaryLightDynEntShadowVis[0] dpvsDyn::dynEntClientCount[0] * (primaryLightCount - lastSunPrimaryLightIndex - 1); -set count primaryLightDynEntShadowVis[1] dpvsDyn::dynEntClientCount[1] * (primaryLightCount - lastSunPrimaryLightIndex - 1); +set count primaryLightDynEntShadowVis[0] dpvsDyn::dynEntClientCount[0] * (primaryLightCount - sunPrimaryLightIndex - 1); +set count primaryLightDynEntShadowVis[1] dpvsDyn::dynEntClientCount[1] * (primaryLightCount - sunPrimaryLightIndex - 1); set block nonSunPrimaryLightForModelDynEnt XFILE_BLOCK_RUNTIME; set count nonSunPrimaryLightForModelDynEnt dpvsDyn::dynEntClientCount[0]; set count shadowGeom primaryLightCount; @@ -74,10 +74,14 @@ set count entries entryCount; set count colors colorCount; // GfxWorldVertexData -set count GfxWorldVertexData::vertices GfxWorld::vertexCount; +use GfxWorldVertexData; +set count vertices GfxWorld::vertexCount; +set condition worldVb never; // GfxWorldVertexLayerData -set count GfxWorldVertexLayerData::data GfxWorld::vertexLayerDataSize; +use GfxWorldVertexLayerData; +set count data GfxWorld::vertexLayerDataSize; +set condition layerVb never; // GfxShadowGeometry use GfxShadowGeometry; @@ -101,8 +105,7 @@ set count lodData 2 * smodelVisDataCount; set count sortedSurfIndex staticSurfaceCount + staticSurfaceCountNoDecal; set count smodelInsts smodelCount; set count surfaces GfxWorld::surfaceCount; -set count cullGroups cullGroupCount; -set count surfacesBounds GfxWorld::surfaceCount; +set count cullGroups GfxWorld::cullGroupCount; set count smodelDrawInsts smodelCount; set block surfaceMaterials XFILE_BLOCK_RUNTIME; set count surfaceMaterials staticSurfaceCount; diff --git a/src/ZoneCode/Game/IW3/XAssets/MaterialTechniqueSet.txt b/src/ZoneCode/Game/IW3/XAssets/MaterialTechniqueSet.txt index 158d61ed..c5180b64 100644 --- a/src/ZoneCode/Game/IW3/XAssets/MaterialTechniqueSet.txt +++ b/src/ZoneCode/Game/IW3/XAssets/MaterialTechniqueSet.txt @@ -34,9 +34,6 @@ set count GfxPixelShaderLoadDef::program programSize; // MaterialPixelShaderProgram set condition MaterialPixelShaderProgram::ps never; -// MaterialVertexDeclaration -set string MaterialVertexDeclaration::name; - // MaterialVertexStreamRouting set condition MaterialVertexStreamRouting::decl never; diff --git a/src/ZoneCode/Game/IW3/XAssets/WeaponDef.txt b/src/ZoneCode/Game/IW3/XAssets/WeaponDef.txt index f58c987a..25d9a0af 100644 --- a/src/ZoneCode/Game/IW3/XAssets/WeaponDef.txt +++ b/src/ZoneCode/Game/IW3/XAssets/WeaponDef.txt @@ -1,5 +1,5 @@ // ========================================= -// WeaponCompleteDef +// WeaponDef // ========================================= use WeaponDef; set string szInternalName; @@ -23,23 +23,24 @@ set reusable accuracyGraphKnots0; set reusable accuracyGraphKnots1; set reusable originalAccuracyGraphKnots0; set reusable originalAccuracyGraphKnots1; -set count accuracyGraphKnots0 WeaponCompleteDef::accuracyGraphKnotCount[0]; -set count accuracyGraphKnots1 WeaponCompleteDef::accuracyGraphKnotCount[1]; -set count originalAccuracyGraphKnots0 WeaponCompleteDef::accuracyGraphKnotCount[0]; // yeah it uses accuracyGraphKnotCount -set count originalAccuracyGraphKnots1 WeaponCompleteDef::accuracyGraphKnotCount[1]; +set count accuracyGraphKnots0 accuracyGraphKnotCount[0]; +set count accuracyGraphKnots1 accuracyGraphKnotCount[1]; +set count originalAccuracyGraphKnots0 accuracyGraphKnotCount[0]; // yeah it uses accuracyGraphKnotCount +set count originalAccuracyGraphKnots1 accuracyGraphKnotCount[1]; set string szUseHintString; set string dropHintString; set string szScript; set string fireRumble; set string meleeImpactRumble; + reorder: - ... - accuracyGraphName0 - accuracyGraphKnots0 - originalAccuracyGraphKnots0 - accuracyGraphName1 - accuracyGraphKnots1; - originalAccuracyGraphKnots1; +... +accuracyGraphName0 +accuracyGraphKnots0 +originalAccuracyGraphKnots0 +accuracyGraphName1 +accuracyGraphKnots1 +originalAccuracyGraphKnots1; // SndAliasCustom use SndAliasCustom; diff --git a/src/ZoneCode/Game/IW3/XAssets/XModel.txt b/src/ZoneCode/Game/IW3/XAssets/XModel.txt index 55b31df1..3d9bdd7c 100644 --- a/src/ZoneCode/Game/IW3/XAssets/XModel.txt +++ b/src/ZoneCode/Game/IW3/XAssets/XModel.txt @@ -32,12 +32,6 @@ set count geoms count; // PhysGeomInfo use PhysGeomInfo; -// XModelSurfs -use XModelSurfs; -set block XFILE_BLOCK_VIRTUAL; -set string name; -set count surfs XModelLodInfo::numsurfs; // No this is not a mistake. This is how the game does it. - // XSurface use XSurface; set reusable verts0; diff --git a/src/ZoneCode/Game/IW3/XAssets/clipMap_t.txt b/src/ZoneCode/Game/IW3/XAssets/clipMap_t.txt index 4aa10ca9..94a15464 100644 --- a/src/ZoneCode/Game/IW3/XAssets/clipMap_t.txt +++ b/src/ZoneCode/Game/IW3/XAssets/clipMap_t.txt @@ -23,7 +23,7 @@ set count partitions partitionCount; set count aabbTrees aabbTreeCount; set count cmodels numSubModels; set count brushes numBrushes; -set visibility numClusters * clusterBytes; +set count visibility numClusters * clusterBytes; set reusable box_brush; set count dynEntDefList[0] dynEntCount[0]; set count dynEntDefList[1] dynEntCount[1]; diff --git a/src/ZoneCode/Game/IW3/XAssets/menuDef_t.txt b/src/ZoneCode/Game/IW3/XAssets/menuDef_t.txt index a2d3f475..44bba130 100644 --- a/src/ZoneCode/Game/IW3/XAssets/menuDef_t.txt +++ b/src/ZoneCode/Game/IW3/XAssets/menuDef_t.txt @@ -34,7 +34,7 @@ use Operand; set condition internals::intVal dataType == VAL_INT; set condition internals::floatVal dataType == VAL_FLOAT; set condition internals::stringVal dataType == VAL_STRING; -set string internal::stringVal; +set string internals::stringVal; // itemDef_s use itemDef_s; @@ -70,8 +70,6 @@ set condition editField itemDef_s::type == 0 || itemDef_s::type == 23; set condition multi itemDef_s::type == 12; set condition enumDvarName itemDef_s::type == 13; -set condition ticker itemDef_s::type == 20; -set condition scroll itemDef_s::type == 21; // listBoxDef_s set string listBoxDef_s::doubleClick; diff --git a/src/ZoneCodeGeneratorLib/Utils/AlignmentUtils.h b/src/ZoneCodeGeneratorLib/Utils/AlignmentUtils.h index c9be689b..b734193f 100644 --- a/src/ZoneCodeGeneratorLib/Utils/AlignmentUtils.h +++ b/src/ZoneCodeGeneratorLib/Utils/AlignmentUtils.h @@ -6,6 +6,9 @@ public: template static T Align(T number, T alignmentValue) { + if (alignmentValue == 0) + return number; + return (number + (alignmentValue - 1)) / alignmentValue * alignmentValue; } }; \ No newline at end of file diff --git a/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp b/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp index e69de29b..97cb0f74 100644 --- a/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp +++ b/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp @@ -0,0 +1,332 @@ +#include "GameAssetPoolIW3.h" + +#include +#include + +#include "Pool/AssetPoolStatic.h" +#include "Pool/AssetPoolDynamic.h" + +using namespace IW3; + +const char* GameAssetPoolIW3::ASSET_TYPE_NAMES[] +{ + "physpreset", + "xanim", + "xmodelsurfs", + "xmodel", + "material", + "pixelshader", + "vertexshader", + "vertexdecl", + "techniqueset", + "image", + "sound", + "soundcurve", + "loadedsound", + "clipmap", + "clipmap", + "comworld", + "gameworldsp", + "gameworldmp", + "mapents", + "gfxworld", + "lightdef", + "uimap", + "font", + "menulist", + "menu", + "localize", + "weapon", + "snddriverglobals", + "fx", + "impactfx", + "aitype", + "mptype", + "character", + "xmodelalias", + "rawfile", + "stringtable" +}; + +/* + Asset Pool Table + Useful for macro generation via regex-replace for example + + #assetType, #typeName, #unionEntry, #poolName + ASSET_TYPE_PHYSPRESET, PhysPreset, physPreset, m_phys_preset + ASSET_TYPE_XANIMPARTS, XAnimParts, parts, m_xanim_parts + ASSET_TYPE_XMODEL, XModel, model, m_xmodel + ASSET_TYPE_MATERIAL, Material, material, m_material + ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet, techniqueSet, m_technique_set + ASSET_TYPE_IMAGE, GfxImage, image, m_image + ASSET_TYPE_SOUND, snd_alias_list_t, sound, m_sound + ASSET_TYPE_SOUND_CURVE, SndCurve, sndCurve, m_sound_curve + ASSET_TYPE_LOADED_SOUND, LoadedSound, loadSnd, m_loaded_sound + ASSET_TYPE_CLIPMAP, clipMap_t, clipMap, m_clip_map + ASSET_TYPE_CLIPMAP_PVS, clipMap_t, clipMap, m_clip_map + ASSET_TYPE_COMWORLD, ComWorld, comWorld, m_com_world + ASSET_TYPE_GAMEWORLD_SP, GameWorldSp, gameWorldSp, m_game_world_sp + ASSET_TYPE_GAMEWORLD_MP, GameWorldMp, gameWorldMp, m_game_world_mp + ASSET_TYPE_MAP_ENTS, MapEnts, mapEnts, m_map_ents + ASSET_TYPE_GFXWORLD, GfxWorld, gfxWorld, m_gfx_world + ASSET_TYPE_LIGHT_DEF, GfxLightDef, lightDef, m_gfx_light_def + ASSET_TYPE_FONT, Font_s, font, m_font + ASSET_TYPE_MENULIST, MenuList, menuList, m_menu_list + ASSET_TYPE_MENU, menuDef_t, menu, m_menu_def + ASSET_TYPE_LOCALIZE_ENTRY, LocalizeEntry, localize, m_localize + ASSET_TYPE_WEAPON, WeaponCompleteDef, weapon, m_weapon + ASSET_TYPE_SNDDRIVER_GLOBALS, SndDriverGlobals, sndDriverGlobals, m_snd_driver_globals + ASSET_TYPE_FX, FxEffectDef, fx, m_fx + ASSET_TYPE_IMPACT_FX, FxImpactTable, impactFx, m_fx_impact_table + ASSET_TYPE_RAWFILE, RawFile, rawfile, m_raw_file + ASSET_TYPE_STRINGTABLE, StringTable, stringTable, m_string_table + */ + +GameAssetPoolIW3::GameAssetPoolIW3(Zone* zone, const int priority) + : ZoneAssetPools(zone), + m_priority(priority) +{ + assert(std::extent::value == ASSET_TYPE_COUNT); + + m_phys_preset = nullptr; + m_xanim_parts = nullptr; + m_xmodel = nullptr; + m_material = nullptr; + m_material_pixel_shader = nullptr; + m_material_vertex_shader = nullptr; + m_material_vertex_decl = nullptr; + m_technique_set = nullptr; + m_image = nullptr; + m_sound = nullptr; + m_sound_curve = nullptr; + m_loaded_sound = nullptr; + m_clip_map = nullptr; + m_com_world = nullptr; + m_game_world_sp = nullptr; + m_game_world_mp = nullptr; + m_map_ents = nullptr; + m_gfx_world = nullptr; + m_gfx_light_def = nullptr; + m_font = nullptr; + m_menu_list = nullptr; + m_menu_def = nullptr; + m_localize = nullptr; + m_weapon = nullptr; + m_fx = nullptr; + m_fx_impact_table = nullptr; + m_raw_file = nullptr; + m_string_table = nullptr; +} + +void GameAssetPoolIW3::InitPoolStatic(const asset_type_t type, const size_t capacity) +{ +#define CASE_INIT_POOL_STATIC(assetType, poolName, poolType) \ + case assetType: \ + { \ + if((poolName) == nullptr && capacity > 0) \ + { \ + (poolName) = std::make_unique>(capacity, m_priority, (assetType)); \ + } \ + break; \ + } + + switch (type) + { + CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset, PhysPreset); + CASE_INIT_POOL_STATIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts, XAnimParts); + CASE_INIT_POOL_STATIC(ASSET_TYPE_XMODEL, m_xmodel, XModel); + CASE_INIT_POOL_STATIC(ASSET_TYPE_MATERIAL, m_material, Material); + CASE_INIT_POOL_STATIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set, MaterialTechniqueSet); + CASE_INIT_POOL_STATIC(ASSET_TYPE_IMAGE, m_image, GfxImage); + CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound, snd_alias_list_t); + CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve, SndCurve); + CASE_INIT_POOL_STATIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, LoadedSound); + CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP, m_clip_map, clipMap_t); + CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map, clipMap_t); + CASE_INIT_POOL_STATIC(ASSET_TYPE_COMWORLD, m_com_world, ComWorld); + CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp, GameWorldSp); + CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp, GameWorldMp); + CASE_INIT_POOL_STATIC(ASSET_TYPE_MAP_ENTS, m_map_ents, MapEnts); + CASE_INIT_POOL_STATIC(ASSET_TYPE_GFXWORLD, m_gfx_world, GfxWorld); + CASE_INIT_POOL_STATIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def, GfxLightDef); + CASE_INIT_POOL_STATIC(ASSET_TYPE_FONT, m_font, Font_s); + CASE_INIT_POOL_STATIC(ASSET_TYPE_MENULIST, m_menu_list, MenuList); + CASE_INIT_POOL_STATIC(ASSET_TYPE_MENU, m_menu_def, menuDef_t); + CASE_INIT_POOL_STATIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize, LocalizeEntry); + CASE_INIT_POOL_STATIC(ASSET_TYPE_WEAPON, m_weapon, WeaponDef); + CASE_INIT_POOL_STATIC(ASSET_TYPE_FX, m_fx, FxEffectDef); + CASE_INIT_POOL_STATIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table, FxImpactTable); + CASE_INIT_POOL_STATIC(ASSET_TYPE_RAWFILE, m_raw_file, RawFile); + CASE_INIT_POOL_STATIC(ASSET_TYPE_STRINGTABLE, m_string_table, StringTable); + + default: + assert(type >= 0 && type < ASSET_TYPE_COUNT); + break; + } + +#undef CASE_INIT_POOL_STATIC +} + +void GameAssetPoolIW3::InitPoolDynamic(const asset_type_t type) +{ +#define CASE_INIT_POOL_DYNAMIC(assetType, poolName, poolType) \ + case assetType: \ + { \ + if((poolName) == nullptr) \ + { \ + (poolName) = std::make_unique>(m_priority, (assetType)); \ + } \ + break; \ + } + + switch (type) + { + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset, PhysPreset); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts, XAnimParts); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XMODEL, m_xmodel, XModel); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MATERIAL, m_material, Material); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set, MaterialTechniqueSet); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMAGE, m_image, GfxImage); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound, snd_alias_list_t); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve, SndCurve); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, LoadedSound); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP, m_clip_map, clipMap_t); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map, clipMap_t); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_COMWORLD, m_com_world, ComWorld); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp, GameWorldSp); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp, GameWorldMp); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MAP_ENTS, m_map_ents, MapEnts); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GFXWORLD, m_gfx_world, GfxWorld); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def, GfxLightDef); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FONT, m_font, Font_s); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENULIST, m_menu_list, MenuList); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENU, m_menu_def, menuDef_t); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize, LocalizeEntry); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_WEAPON, m_weapon, WeaponDef); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FX, m_fx, FxEffectDef); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table, FxImpactTable); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_RAWFILE, m_raw_file, RawFile); + CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRINGTABLE, m_string_table, StringTable); + + default: + assert(type >= 0 && type < ASSET_TYPE_COUNT); + break; + } + +#undef CASE_INIT_POOL_STATIC +} + +XAssetInfoGeneric* GameAssetPoolIW3::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector dependencies, std::vector usedScriptStrings, Zone* zone) +{ + XAsset xAsset{}; + + xAsset.type = static_cast(type); + xAsset.header.data = asset; + +#define CASE_ADD_TO_POOL(assetType, poolName, headerName) \ + case assetType: \ + { \ + assert((poolName) != nullptr); \ + return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, zone, std::move(dependencies), std::move(usedScriptStrings)); \ + } + + switch (xAsset.type) + { + CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset, physPreset); + CASE_ADD_TO_POOL(ASSET_TYPE_XANIMPARTS, m_xanim_parts, parts); + CASE_ADD_TO_POOL(ASSET_TYPE_XMODEL, m_xmodel, model); + CASE_ADD_TO_POOL(ASSET_TYPE_MATERIAL, m_material, material); + CASE_ADD_TO_POOL(ASSET_TYPE_TECHNIQUE_SET, m_technique_set, techniqueSet); + CASE_ADD_TO_POOL(ASSET_TYPE_IMAGE, m_image, image); + CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound, sound); + CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_CURVE, m_sound_curve, sndCurve); + CASE_ADD_TO_POOL(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, loadSnd); + CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP, m_clip_map, clipMap); + CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_PVS, m_clip_map, clipMap); + CASE_ADD_TO_POOL(ASSET_TYPE_COMWORLD, m_com_world, comWorld); + CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp, gameWorldSp); + CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp, gameWorldMp); + CASE_ADD_TO_POOL(ASSET_TYPE_MAP_ENTS, m_map_ents, mapEnts); + CASE_ADD_TO_POOL(ASSET_TYPE_GFXWORLD, m_gfx_world, gfxWorld); + CASE_ADD_TO_POOL(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def, lightDef); + CASE_ADD_TO_POOL(ASSET_TYPE_FONT, m_font, font); + CASE_ADD_TO_POOL(ASSET_TYPE_MENULIST, m_menu_list, menuList); + CASE_ADD_TO_POOL(ASSET_TYPE_MENU, m_menu_def, menu); + CASE_ADD_TO_POOL(ASSET_TYPE_LOCALIZE_ENTRY, m_localize, localize); + CASE_ADD_TO_POOL(ASSET_TYPE_WEAPON, m_weapon, weapon); + CASE_ADD_TO_POOL(ASSET_TYPE_FX, m_fx, fx); + CASE_ADD_TO_POOL(ASSET_TYPE_IMPACT_FX, m_fx_impact_table, impactFx); + CASE_ADD_TO_POOL(ASSET_TYPE_RAWFILE, m_raw_file, rawfile); + CASE_ADD_TO_POOL(ASSET_TYPE_STRINGTABLE, m_string_table, stringTable); + + default: + assert(false); + break; + } + + return nullptr; + +#undef CASE_ADD_TO_POOL +} + +XAssetInfoGeneric* GameAssetPoolIW3::GetAsset(const asset_type_t type, std::string name) const +{ +#define CASE_GET_ASSET(assetType, poolName) \ + case assetType: \ + { \ + if((poolName) != nullptr) \ + return (poolName)->GetAsset(std::move(name)); \ + break; \ + } + + switch (type) + { + CASE_GET_ASSET(ASSET_TYPE_PHYSPRESET, m_phys_preset); + CASE_GET_ASSET(ASSET_TYPE_XANIMPARTS, m_xanim_parts); + CASE_GET_ASSET(ASSET_TYPE_XMODEL, m_xmodel); + CASE_GET_ASSET(ASSET_TYPE_MATERIAL, m_material); + CASE_GET_ASSET(ASSET_TYPE_TECHNIQUE_SET, m_technique_set); + CASE_GET_ASSET(ASSET_TYPE_IMAGE, m_image); + CASE_GET_ASSET(ASSET_TYPE_SOUND, m_sound); + CASE_GET_ASSET(ASSET_TYPE_SOUND_CURVE, m_sound_curve); + CASE_GET_ASSET(ASSET_TYPE_LOADED_SOUND, m_loaded_sound); + CASE_GET_ASSET(ASSET_TYPE_CLIPMAP, m_clip_map); + CASE_GET_ASSET(ASSET_TYPE_CLIPMAP_PVS, m_clip_map); + CASE_GET_ASSET(ASSET_TYPE_COMWORLD, m_com_world); + CASE_GET_ASSET(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp); + CASE_GET_ASSET(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp); + CASE_GET_ASSET(ASSET_TYPE_MAP_ENTS, m_map_ents); + CASE_GET_ASSET(ASSET_TYPE_GFXWORLD, m_gfx_world); + CASE_GET_ASSET(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def); + CASE_GET_ASSET(ASSET_TYPE_FONT, m_font); + CASE_GET_ASSET(ASSET_TYPE_MENULIST, m_menu_list); + CASE_GET_ASSET(ASSET_TYPE_MENU, m_menu_def); + CASE_GET_ASSET(ASSET_TYPE_LOCALIZE_ENTRY, m_localize); + CASE_GET_ASSET(ASSET_TYPE_WEAPON, m_weapon); + CASE_GET_ASSET(ASSET_TYPE_FX, m_fx); + CASE_GET_ASSET(ASSET_TYPE_IMPACT_FX, m_fx_impact_table); + CASE_GET_ASSET(ASSET_TYPE_RAWFILE, m_raw_file); + CASE_GET_ASSET(ASSET_TYPE_STRINGTABLE, m_string_table); + + default: + assert(false); + break; + } + + return nullptr; + +#undef CASE_GET_ASSET +} + +const char* GameAssetPoolIW3::AssetTypeNameByType(asset_type_t assetType) +{ + if (assetType >= 0 && assetType < static_cast(std::extent::value)) + return ASSET_TYPE_NAMES[assetType]; + + return ASSET_TYPE_INVALID; +} + +const char* GameAssetPoolIW3::GetAssetTypeName(const asset_type_t assetType) const +{ + return AssetTypeNameByType(assetType); +} diff --git a/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.h b/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.h index e69de29b..0beb9dea 100644 --- a/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.h +++ b/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.h @@ -0,0 +1,58 @@ +#pragma once + +#include + +#include "Pool/ZoneAssetPools.h" +#include "Pool/AssetPool.h" +#include "Game/IW3/IW3.h" + +class GameAssetPoolIW3 final : public ZoneAssetPools +{ + int m_priority; + + static constexpr const char* ASSET_TYPE_INVALID = "invalid_asset_type"; + static const char* ASSET_TYPE_NAMES[]; + +protected: + XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector dependencies, std::vector usedScriptStrings, Zone* zone) override; + +public: + std::unique_ptr> m_phys_preset; + std::unique_ptr> m_xanim_parts; + std::unique_ptr> m_xmodel; + std::unique_ptr> m_material; + std::unique_ptr> m_material_pixel_shader; + std::unique_ptr> m_material_vertex_shader; + std::unique_ptr> m_material_vertex_decl; + std::unique_ptr> m_technique_set; + std::unique_ptr> m_image; + std::unique_ptr> m_sound; + std::unique_ptr> m_sound_curve; + std::unique_ptr> m_loaded_sound; + std::unique_ptr> m_clip_map; + std::unique_ptr> m_com_world; + std::unique_ptr> m_game_world_sp; + std::unique_ptr> m_game_world_mp; + std::unique_ptr> m_map_ents; + std::unique_ptr> m_gfx_world; + std::unique_ptr> m_gfx_light_def; + std::unique_ptr> m_font; + std::unique_ptr> m_menu_list; + std::unique_ptr> m_menu_def; + std::unique_ptr> m_localize; + std::unique_ptr> m_weapon; + std::unique_ptr> m_fx; + std::unique_ptr> m_fx_impact_table; + std::unique_ptr> m_raw_file; + std::unique_ptr> m_string_table; + + GameAssetPoolIW3(Zone* zone, int priority); + ~GameAssetPoolIW3() override = default; + + void InitPoolStatic(asset_type_t type, size_t capacity) override; + void InitPoolDynamic(asset_type_t type) override; + + _NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override; + static const char* AssetTypeNameByType(asset_type_t assetType); + _NODISCARD const char* GetAssetTypeName(asset_type_t assetType) const override; +}; diff --git a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp index e69de29b..ce2a4144 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp @@ -0,0 +1,31 @@ +#include "gfximage_actions.h" + +#include +#include + +using namespace IW3; + +Actions_GfxImage::Actions_GfxImage(Zone* zone) + : AssetLoadingActions(zone) +{ +} + +void Actions_GfxImage::OnImageLoaded(GfxImage* image) const +{ + image->cardMemory.platform[0] = 0; +} + +void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const +{ + if (loadDef->resourceSize > 0) + { + const size_t loadDefSize = offsetof(IW3::GfxImageLoadDef, data) + loadDef->resourceSize; + + image->texture.loadDef = static_cast(m_zone->GetMemory()->Alloc(loadDefSize)); + memcpy(image->texture.loadDef, loadDef, loadDefSize); + } + else + { + image->texture.loadDef = nullptr; + } +} diff --git a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h index e69de29b..440bf9a4 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h +++ b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Loading/AssetLoadingActions.h" +#include "Game/IW3/IW3.h" + +namespace IW3 +{ + class Actions_GfxImage final : public AssetLoadingActions + { + public: + explicit Actions_GfxImage(Zone* zone); + + void OnImageLoaded(GfxImage* image) const; + void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const; + }; +} diff --git a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp index e69de29b..864040cb 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp +++ b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp @@ -0,0 +1,24 @@ +#include "loadedsound_actions.h" + +#include + +using namespace IW3; + +Actions_LoadedSound::Actions_LoadedSound(Zone* zone) + : AssetLoadingActions(zone) +{ +} + +void Actions_LoadedSound::SetSoundData(MssSound* sound) const +{ + if (sound->info.data_len > 0) + { + char* tempData = sound->data; + sound->data = static_cast(m_zone->GetMemory()->Alloc(sound->info.data_len)); + memcpy(sound->data, tempData, sound->info.data_len); + } + else + { + sound->data = nullptr; + } +} diff --git a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h index e69de29b..cb0b1332 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h +++ b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Loading/AssetLoadingActions.h" +#include "Game/IW3/IW3.h" + +namespace IW3 +{ + class Actions_LoadedSound final : public AssetLoadingActions + { + public: + explicit Actions_LoadedSound(Zone* zone); + + void SetSoundData(MssSound* sound) const; + }; +}