diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 3b9a6e42..b75f674a 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -421,6 +421,7 @@ namespace Components AssetHandler::RegisterInterface(new Assets::IMapEnts()); AssetHandler::RegisterInterface(new Assets::IRawFile()); AssetHandler::RegisterInterface(new Assets::IGfxImage()); + AssetHandler::RegisterInterface(new Assets::IGfxWorld()); AssetHandler::RegisterInterface(new Assets::ISndCurve()); AssetHandler::RegisterInterface(new Assets::IMaterial()); AssetHandler::RegisterInterface(new Assets::IPhysPreset()); @@ -437,7 +438,6 @@ namespace Components AssetHandler::RegisterInterface(new Assets::IMaterialVertexShader()); AssetHandler::RegisterInterface(new Assets::IStructuredDataDefSet()); AssetHandler::RegisterInterface(new Assets::IMaterialVertexDeclaration()); - AssetHandler::RegisterInterface(new Assets::IGfxWorld()); } } diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index cfdeba1f..60c7b18d 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -77,6 +77,7 @@ namespace Components #include "AssetInterfaces\IMapEnts.hpp" #include "AssetInterfaces\IRawFile.hpp" #include "AssetInterfaces\IGfxImage.hpp" +#include "AssetInterfaces\IGfxWorld.hpp" #include "AssetInterfaces\IMaterial.hpp" #include "AssetInterfaces\ISndCurve.hpp" #include "AssetInterfaces\IPhysPreset.hpp" @@ -93,4 +94,3 @@ namespace Components #include "AssetInterfaces\IMaterialVertexShader.hpp" #include "AssetInterfaces\IStructuredDataDefSet.hpp" #include "AssetInterfaces\IMaterialVertexDeclaration.hpp" -#include "AssetInterfaces\IGfxWorld.hpp" diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index 3b06fcc2..d3b9c7ad 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -2,280 +2,299 @@ namespace Assets { - void IGfxWorld::load(Game::XAssetHeader* /*header*/, std::string name, Components::ZoneBuilder::Zone* /*builder*/) + void IGfxWorld::load(Game::XAssetHeader* /*header*/, std::string name, Components::ZoneBuilder::Zone* /*builder*/) { Game::GfxWorld* map = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_GFX_MAP, name.data()).gfxMap; if (map) return; + Components::Logger::Error("Missing GfxMap %s... you can't make them yet you idiot.", name.data()); - } + } - void IGfxWorld::saveGfxWorldDpvsPlanes(Game::GfxWorld* world, Game::GfxWorldDpvsPlanes* asset, Game::GfxWorldDpvsPlanes* dest, Components::ZoneBuilder::Zone* builder) { - AssertSize(Game::GfxWorldDpvsPlanes, 16); + void IGfxWorld::saveGfxWorldDpvsPlanes(Game::GfxWorld* world, Game::GfxWorldDpvsPlanes* asset, Game::GfxWorldDpvsPlanes* dest, Components::ZoneBuilder::Zone* builder) { + AssertSize(Game::GfxWorldDpvsPlanes, 16); - Utils::Stream* buffer = builder->getBuffer(); + Utils::Stream* buffer = builder->getBuffer(); - if(asset->planes) { - if(builder->hasPointer(asset->planes)) { - dest->planes = builder->getPointer(asset->planes); - } else { - buffer->align(Utils::Stream::ALIGN_4); - builder->storePointer(asset->planes); + if (asset->planes) + { + if (builder->hasPointer(asset->planes)) + { + dest->planes = builder->getPointer(asset->planes); + } + else + { + buffer->align(Utils::Stream::ALIGN_4); + builder->storePointer(asset->planes); - buffer->saveArray(asset->planes, world->planeCount); - Utils::Stream::ClearPointer(&dest->planes); - } - } + buffer->saveArray(asset->planes, world->planeCount); + Utils::Stream::ClearPointer(&dest->planes); + } + } - if (asset->nodes) - { - buffer->align(Utils::Stream::ALIGN_2); - buffer->saveArray(asset->nodes, world->nodeCount); - Utils::Stream::ClearPointer(&dest->nodes); - } + if (asset->nodes) + { + buffer->align(Utils::Stream::ALIGN_2); + buffer->saveArray(asset->nodes, world->nodeCount); + Utils::Stream::ClearPointer(&dest->nodes); + } - buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); + buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); - if (asset->sceneEntCellBits) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->sceneEntCellBits, asset->cellCount); - Utils::Stream::ClearPointer(&dest->sceneEntCellBits); - } + if (asset->sceneEntCellBits) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->sceneEntCellBits, asset->cellCount); + Utils::Stream::ClearPointer(&dest->sceneEntCellBits); + } - buffer->popBlock(); - } + buffer->popBlock(); + } - void IGfxWorld::saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder) { - AssertSize(Game::GfxWorldDraw, 72); + void IGfxWorld::saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder) + { + AssertSize(Game::GfxWorldDraw, 72); - Utils::Stream* buffer = builder->getBuffer(); + Utils::Stream* buffer = builder->getBuffer(); - if (asset->reflectionImages) - { - buffer->align(Utils::Stream::ALIGN_4); + if (asset->reflectionImages) + { + buffer->align(Utils::Stream::ALIGN_4); - Game::GfxImage** imageDest = buffer->dest(); - buffer->saveArray(asset->reflectionImages, asset->reflectionProbeCount); + Game::GfxImage** imageDest = buffer->dest(); + buffer->saveArray(asset->reflectionImages, asset->reflectionProbeCount); - for (unsigned int i = 0; i < asset->reflectionProbeCount; i++) - { - imageDest[i] = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->reflectionImages[i]->name).image; - } - Utils::Stream::ClearPointer(asset->reflectionImages); - } + for (unsigned int i = 0; i < asset->reflectionProbeCount; i++) + { + imageDest[i] = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->reflectionImages[i]->name).image; + } - if (asset->reflectionProbes) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->reflectionProbes, asset->reflectionProbeCount); - Utils::Stream::ClearPointer(&dest->reflectionProbes); - } + Utils::Stream::ClearPointer(asset->reflectionImages); + } - buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); + if (asset->reflectionProbes) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->reflectionProbes, asset->reflectionProbeCount); + Utils::Stream::ClearPointer(&dest->reflectionProbes); + } - if (asset->reflectionProbeTextures) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->reflectionProbeTextures, asset->reflectionProbeCount); - Utils::Stream::ClearPointer(&dest->reflectionProbeTextures); - } + buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); - buffer->popBlock(); + if (asset->reflectionProbeTextures) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->reflectionProbeTextures, asset->reflectionProbeCount); + Utils::Stream::ClearPointer(&dest->reflectionProbeTextures); + } - if (asset->lightmaps) - { - buffer->align(Utils::Stream::ALIGN_4); + buffer->popBlock(); - Game::GfxLightmapArray* lightmapArrayDestTable = buffer->dest(); - buffer->saveArray(asset->lightmaps, asset->lightmapCount); + if (asset->lightmaps) + { + buffer->align(Utils::Stream::ALIGN_4); - for (int i = 0; i < asset->lightmapCount; i++) - { - Game::GfxLightmapArray* lightmapArrayDest = &lightmapArrayDestTable[i]; - Game::GfxLightmapArray* lightmapArray = &asset->lightmaps[i]; + Game::GfxLightmapArray* lightmapArrayDestTable = buffer->dest(); + buffer->saveArray(asset->lightmaps, asset->lightmapCount); - if (lightmapArray->primary) { - lightmapArrayDest->primary = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, lightmapArray->primary->name).image; - } + for (int i = 0; i < asset->lightmapCount; i++) + { + Game::GfxLightmapArray* lightmapArrayDest = &lightmapArrayDestTable[i]; + Game::GfxLightmapArray* lightmapArray = &asset->lightmaps[i]; - if (lightmapArray->secondary) { - lightmapArrayDest->secondary = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, lightmapArray->secondary->name).image; - } - } - Utils::Stream::ClearPointer(asset->reflectionImages); - } + if (lightmapArray->primary) + { + lightmapArrayDest->primary = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, lightmapArray->primary->name).image; + } - buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); + if (lightmapArray->secondary) + { + lightmapArrayDest->secondary = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, lightmapArray->secondary->name).image; + } + } + Utils::Stream::ClearPointer(asset->reflectionImages); + } - if (asset->lightmapPrimaryTextures) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->lightmapPrimaryTextures, asset->lightmapCount); - Utils::Stream::ClearPointer(&dest->lightmapPrimaryTextures); - } + buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); - if (asset->lightmapSecondaryTextures) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->lightmapSecondaryTextures, asset->lightmapCount); - Utils::Stream::ClearPointer(&dest->lightmapSecondaryTextures); - } + if (asset->lightmapPrimaryTextures) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->lightmapPrimaryTextures, asset->lightmapCount); + Utils::Stream::ClearPointer(&dest->lightmapPrimaryTextures); + } - buffer->popBlock(); + if (asset->lightmapSecondaryTextures) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->lightmapSecondaryTextures, asset->lightmapCount); + Utils::Stream::ClearPointer(&dest->lightmapSecondaryTextures); + } - if(asset->skyImage) { - dest->skyImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->skyImage->name).image; - } + buffer->popBlock(); - if(asset->outdoorImage) { - dest->outdoorImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->outdoorImage->name).image; - } + if (asset->skyImage) + { + dest->skyImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->skyImage->name).image; + } - // the next 2 blocks *SHOULD* be in their own functions but i'm too lazy to type it all out + if (asset->outdoorImage) + { + dest->outdoorImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->outdoorImage->name).image; + } - // saveGfxWorldVertexData - if (asset->vd.vertices) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->vd.vertices, asset->vertexCount); - Utils::Stream::ClearPointer(&dest->vd.vertices); - } + // the next 2 blocks *SHOULD* be in their own functions but i'm too lazy to type it all out - // this one has no if statement on purpouse - buffer->save(&asset->vd.worldVb, 1, 4); + // saveGfxWorldVertexData + if (asset->vd.vertices) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->vd.vertices, asset->vertexCount); + Utils::Stream::ClearPointer(&dest->vd.vertices); + } - // saveGfxWorldVertexLayerData - if (asset->vld.data) { - // no align for char - buffer->saveArray(asset->vld.data, asset->vertexLayerDataSize); - Utils::Stream::ClearPointer(&dest->vld.data); - } + // this one has no if statement on purpouse + buffer->save(&asset->vd.worldVb, 1, 4); - buffer->save(&asset->vld.layerVb, 1, 4); + // saveGfxWorldVertexLayerData + if (asset->vld.data) + { + // no align for char + buffer->saveArray(asset->vld.data, asset->vertexLayerDataSize); + Utils::Stream::ClearPointer(&dest->vld.data); + } - if (asset->indices) { - buffer->align(Utils::Stream::ALIGN_2); - buffer->saveArray(asset->indices, asset->indexCount); - Utils::Stream::ClearPointer(&dest->indices); - } - } + buffer->save(&asset->vld.layerVb, 1, 4); - void IGfxWorld::saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder) { - AssertSize(Game::GfxLightGrid, 56); + if (asset->indices) + { + buffer->align(Utils::Stream::ALIGN_2); + buffer->saveArray(asset->indices, asset->indexCount); + Utils::Stream::ClearPointer(&dest->indices); + } + } - Utils::Stream* buffer = builder->getBuffer(); + void IGfxWorld::saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder) + { + AssertSize(Game::GfxLightGrid, 56); - if (asset->rowDataStart) - { - buffer->align(Utils::Stream::ALIGN_2); - buffer->saveArray(asset->rowDataStart, (asset->maxs[asset->rowAxis] - asset->mins[asset->rowAxis]) + 2); - Utils::Stream::ClearPointer(&dest->rowDataStart); - } + Utils::Stream* buffer = builder->getBuffer(); - if (asset->rawRowData) - { - // no align for char - buffer->saveArray(asset->rawRowData, asset->rawRowDataSize); - Utils::Stream::ClearPointer(&dest->rawRowData); - } + if (asset->rowDataStart) + { + buffer->align(Utils::Stream::ALIGN_2); + buffer->saveArray(asset->rowDataStart, (asset->maxs[asset->rowAxis] - asset->mins[asset->rowAxis]) + 2); + Utils::Stream::ClearPointer(&dest->rowDataStart); + } - if (asset->entries) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->entries, asset->entryCount); - Utils::Stream::ClearPointer(&dest->entries); - } + if (asset->rawRowData) + { + // no align for char + buffer->saveArray(asset->rawRowData, asset->rawRowDataSize); + Utils::Stream::ClearPointer(&dest->rawRowData); + } - if (asset->colors) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->colors, asset->colorCount); - Utils::Stream::ClearPointer(&dest->colors); - } - } + if (asset->entries) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->entries, asset->entryCount); + Utils::Stream::ClearPointer(&dest->entries); + } - void IGfxWorld::savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder) { - AssertSize(Game::sunflare_t, 96); + if (asset->colors) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->colors, asset->colorCount); + Utils::Stream::ClearPointer(&dest->colors); + } + } - if(asset->spriteMaterial) { - dest->spriteMaterial = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->spriteMaterial->name).material; - } + void IGfxWorld::savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder) + { + AssertSize(Game::sunflare_t, 96); - if(asset->flareMaterial) { - dest->flareMaterial = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->flareMaterial->name).material; - } - } + if (asset->spriteMaterial) + { + dest->spriteMaterial = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->spriteMaterial->name).material; + } - void IGfxWorld::saveGfxWorldDpvsStatic(Game::GfxWorldDpvsStatic* /*asset*/, Game::GfxWorldDpvsStatic* /*dest*/, int /*planeCount*/, Components::ZoneBuilder::Zone* /*builder*/) { - AssertSize(Game::GfxWorldDpvsStatic, 108); + if (asset->flareMaterial) + { + dest->flareMaterial = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->flareMaterial->name).material; + } + } - //Utils::Stream* buffer = builder->getBuffer(); - } + void IGfxWorld::saveGfxWorldDpvsStatic(Game::GfxWorldDpvsStatic* /*asset*/, Game::GfxWorldDpvsStatic* /*dest*/, int /*planeCount*/, Components::ZoneBuilder::Zone* /*builder*/) + { + AssertSize(Game::GfxWorldDpvsStatic, 108); - void IGfxWorld::saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, int planeCount, Components::ZoneBuilder::Zone* builder) { - AssertSize(Game::GfxWorldDpvsDynamic, 48); + //Utils::Stream* buffer = builder->getBuffer(); + } - Utils::Stream* buffer = builder->getBuffer(); + void IGfxWorld::saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, int planeCount, Components::ZoneBuilder::Zone* builder) + { + AssertSize(Game::GfxWorldDpvsDynamic, 48); - buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); + Utils::Stream* buffer = builder->getBuffer(); - if (asset->dynEntCellBits[0]) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->dynEntCellBits[0], planeCount); - Utils::Stream::ClearPointer(&dest->dynEntCellBits[0]); - } + buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); - if (asset->dynEntCellBits[1]) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->dynEntCellBits[1], planeCount); - Utils::Stream::ClearPointer(&dest->dynEntCellBits[1]); - } + if (asset->dynEntCellBits[0]) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->dynEntCellBits[0], planeCount); + Utils::Stream::ClearPointer(&dest->dynEntCellBits[0]); + } - // this covers [0][0], [1][0], [0][1], [1][1], [0][2], [1][2] - for(char i = 0; i < 3; i++) - { - for (char j = 0; j < 2; j++) - { - if(asset->dynEntVisData[j][i]) - { - buffer->align(Utils::Stream::ALIGN_16); - buffer->save(asset->dynEntVisData[j][i], 32, asset->dynEntClientWordCount[j]); - Utils::Stream::ClearPointer(&dest->dynEntVisData[j][i]); - } - } - } + if (asset->dynEntCellBits[1]) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->dynEntCellBits[1], planeCount); + Utils::Stream::ClearPointer(&dest->dynEntCellBits[1]); + } - buffer->popBlock(); - } + // this covers [0][0], [1][0], [0][1], [1][1], [0][2], [1][2] + for (char i = 0; i < 3; i++) + { + for (char j = 0; j < 2; j++) + { + if (asset->dynEntVisData[j][i]) + { + buffer->align(Utils::Stream::ALIGN_16); + buffer->save(asset->dynEntVisData[j][i], 32, asset->dynEntClientWordCount[j]); + Utils::Stream::ClearPointer(&dest->dynEntVisData[j][i]); + } + } + } - void IGfxWorld::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) - { - AssertSize(Game::GfxWorld, 0x274); + buffer->popBlock(); + } - Utils::Stream* buffer = builder->getBuffer(); - Game::GfxWorld* asset = header.gfxMap; - Game::GfxWorld* dest = buffer->dest(); - buffer->save(asset); + void IGfxWorld::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) + { + AssertSize(Game::GfxWorld, 0x274); - buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL); + Utils::Stream* buffer = builder->getBuffer(); + Game::GfxWorld* asset = header.gfxMap; + Game::GfxWorld* dest = buffer->dest(); + buffer->save(asset); - if (asset->name) - { - buffer->saveString(builder->getAssetName(this->getType(), asset->name)); - Utils::Stream::ClearPointer(&dest->name); - } + buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL); - if (asset->baseName) - { - buffer->saveString(asset->baseName); - Utils::Stream::ClearPointer(&dest->baseName); - } + if (asset->name) + { + buffer->saveString(builder->getAssetName(this->getType(), asset->name)); + Utils::Stream::ClearPointer(&dest->name); + } - if (asset->skies) - { - AssertSize(Game::GfxSky, 16); + if (asset->baseName) + { + buffer->saveString(asset->baseName); + Utils::Stream::ClearPointer(&dest->baseName); + } + + if (asset->skies) + { + AssertSize(Game::GfxSky, 16); buffer->align(Utils::Stream::ALIGN_4); Game::GfxSky* destSkyTable = buffer->dest(); @@ -283,38 +302,40 @@ namespace Assets for (unsigned char i = 0; i < asset->skyCount; ++i) { - Game::GfxSky* destSky = &destSkyTable[i]; - Game::GfxSky* sky = &asset->skies[i]; + Game::GfxSky* destSky = &destSkyTable[i]; + Game::GfxSky* sky = &asset->skies[i]; - if (sky->skyStartSurfs) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(sky->skyStartSurfs, sky->skySurfCount); - Utils::Stream::ClearPointer(&destSky->skyStartSurfs); - } + if (sky->skyStartSurfs) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(sky->skyStartSurfs, sky->skySurfCount); + Utils::Stream::ClearPointer(&destSky->skyStartSurfs); + } - if(sky->skyImage) { - destSky->skyImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, sky->skyImage->name).image; - } - } - Utils::Stream::ClearPointer(&dest->skies); - } + if (sky->skyImage) { + destSky->skyImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, sky->skyImage->name).image; + } + } - this->saveGfxWorldDpvsPlanes(asset, &asset->dpvsPlanes, &dest->dpvsPlanes, builder); + Utils::Stream::ClearPointer(&dest->skies); + } - uint32_t cellCount = asset->dpvsPlanes.cellCount; + this->saveGfxWorldDpvsPlanes(asset, &asset->dpvsPlanes, &dest->dpvsPlanes, builder); - if (asset->aabbTreeCounts) - { - AssertSize(Game::GfxCellTreeCount, 4); + uint32_t cellCount = asset->dpvsPlanes.cellCount; - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->aabbTreeCounts, cellCount); - Utils::Stream::ClearPointer(&dest->aabbTreeCounts); - } - if (asset->aabbTrees) - { - AssertSize(Game::GfxCellTree, 4); + if (asset->aabbTreeCounts) + { + AssertSize(Game::GfxCellTreeCount, 4); + + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->aabbTreeCounts, cellCount); + Utils::Stream::ClearPointer(&dest->aabbTreeCounts); + } + + if (asset->aabbTrees) + { + AssertSize(Game::GfxCellTree, 4); buffer->align(Utils::Stream::ALIGN_128); Game::GfxCellTree* destCellTreeTable = buffer->dest(); @@ -322,52 +343,55 @@ namespace Assets for (unsigned char i = 0; i < cellCount; ++i) { - Game::GfxCellTree* destCellTree = &destCellTreeTable[i]; - Game::GfxCellTree* cellTree = &asset->aabbTrees[i]; + Game::GfxCellTree* destCellTree = &destCellTreeTable[i]; + Game::GfxCellTree* cellTree = &asset->aabbTrees[i]; - if (cellTree->aabbTree) - { - AssertSize(Game::GfxAabbTree, 44); + if (cellTree->aabbTree) + { + AssertSize(Game::GfxAabbTree, 44); - buffer->align(Utils::Stream::ALIGN_4); - Game::GfxAabbTree* destAabbTreeTable = buffer->dest(); - buffer->saveArray(cellTree->aabbTree, asset->aabbTreeCounts[i].aabbTreeCount); + buffer->align(Utils::Stream::ALIGN_4); + Game::GfxAabbTree* destAabbTreeTable = buffer->dest(); + buffer->saveArray(cellTree->aabbTree, asset->aabbTreeCounts[i].aabbTreeCount); - // ok this one is based on some assumptions because the actual count is this - // *(int *)((char *)&varGfxWorld->aabbTreeCounts->aabbTreeCount + (((char *)varGfxCellTree - (char *)varGfxWorld->aabbTrees) & 0xFFFFFFFC)) - // which makes no sense - // what DOES make sense is using the count from the strucutre + // ok this one is based on some assumptions because the actual count is this + // *(int *)((char *)&varGfxWorld->aabbTreeCounts->aabbTreeCount + (((char *)varGfxCellTree - (char *)varGfxWorld->aabbTrees) & 0xFFFFFFFC)) + // which makes no sense + // what DOES make sense is using the count from the strucutre - for (char j = 0; j < asset->aabbTreeCounts[i].aabbTreeCount; ++j) - { - Game::GfxAabbTree* destAabbTree = &destAabbTreeTable[j]; - Game::GfxAabbTree* aabbTree = &cellTree->aabbTree[j]; + for (char j = 0; j < asset->aabbTreeCounts[i].aabbTreeCount; ++j) + { + Game::GfxAabbTree* destAabbTree = &destAabbTreeTable[j]; + Game::GfxAabbTree* aabbTree = &cellTree->aabbTree[j]; - if (aabbTree->smodelIndexes) - { - if(builder->hasPointer(aabbTree->smodelIndexes)) { - destAabbTree->smodelIndexes = builder->getPointer(aabbTree->smodelIndexes); - } - else - { - buffer->align(Utils::Stream::ALIGN_2); - builder->storePointer(aabbTree->smodelIndexes); + if (aabbTree->smodelIndexes) + { + if (builder->hasPointer(aabbTree->smodelIndexes)) + { + destAabbTree->smodelIndexes = builder->getPointer(aabbTree->smodelIndexes); + } + else + { + buffer->align(Utils::Stream::ALIGN_2); + builder->storePointer(aabbTree->smodelIndexes); - buffer->saveArray(aabbTree->smodelIndexes, aabbTree->smodelIndexCount); - Utils::Stream::ClearPointer(&destAabbTree->smodelIndexes); - } - } - } - Utils::Stream::ClearPointer(&destCellTree->aabbTree); - } + buffer->saveArray(aabbTree->smodelIndexes, aabbTree->smodelIndexCount); + Utils::Stream::ClearPointer(&destAabbTree->smodelIndexes); + } + } + } - } - Utils::Stream::ClearPointer(&dest->aabbTrees); - } + Utils::Stream::ClearPointer(&destCellTree->aabbTree); + } - if (asset->cells) - { - AssertSize(Game::GfxCell, 40); + } + + Utils::Stream::ClearPointer(&dest->aabbTrees); + } + + if (asset->cells) + { + AssertSize(Game::GfxCell, 40); buffer->align(Utils::Stream::ALIGN_4); Game::GfxCell* destCellTable = buffer->dest(); @@ -375,54 +399,57 @@ namespace Assets for (unsigned char i = 0; i < cellCount; ++i) { - Game::GfxCell* destCell = &destCellTable[i]; - Game::GfxCell* cell = &asset->cells[i]; + Game::GfxCell* destCell = &destCellTable[i]; + Game::GfxCell* cell = &asset->cells[i]; - if (cell->portals) - { - AssertSize(Game::GfxPortal, 60); + if (cell->portals) + { + AssertSize(Game::GfxPortal, 60); - buffer->align(Utils::Stream::ALIGN_4); - Game::GfxPortal* destPortalTable = buffer->dest(); - buffer->saveArray(cell->portals, cell->portalCount); + buffer->align(Utils::Stream::ALIGN_4); + Game::GfxPortal* destPortalTable = buffer->dest(); + buffer->saveArray(cell->portals, cell->portalCount); - for (char j = 0; j < cell->portalCount; ++j) - { - Game::GfxPortal* destPortal = &destPortalTable[j]; - Game::GfxPortal* portal = &cell->portals[j]; + for (char j = 0; j < cell->portalCount; ++j) + { + Game::GfxPortal* destPortal = &destPortalTable[j]; + Game::GfxPortal* portal = &cell->portals[j]; - if (portal->vertices) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(portal->vertices, portal->vertexCount); - Utils::Stream::ClearPointer(&destPortal->vertices); - } - } - Utils::Stream::ClearPointer(&destCell->portals); - } + if (portal->vertices) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(portal->vertices, portal->vertexCount); + Utils::Stream::ClearPointer(&destPortal->vertices); + } + } - if (cell->reflectionProbes) - { - // no align for char - buffer->saveArray(cell->reflectionProbes, cell->reflectionProbeCount); - Utils::Stream::ClearPointer(&destCell->reflectionProbes); - } - } - Utils::Stream::ClearPointer(&dest->cells); - } + Utils::Stream::ClearPointer(&destCell->portals); + } - this->saveGfxWorldDraw(&asset->worldDraw, &dest->worldDraw, builder); - this->saveGfxLightGrid(&asset->lightGrid, &dest->lightGrid, builder); + if (cell->reflectionProbes) + { + // no align for char + buffer->saveArray(cell->reflectionProbes, cell->reflectionProbeCount); + Utils::Stream::ClearPointer(&destCell->reflectionProbes); + } + } - if (asset->models) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->models, asset->modelCount); - Utils::Stream::ClearPointer(&dest->aabbTreeCounts); - } - if (asset->materialMemory) - { - AssertSize(Game::MaterialMemory, 8); + Utils::Stream::ClearPointer(&dest->cells); + } + + this->saveGfxWorldDraw(&asset->worldDraw, &dest->worldDraw, builder); + this->saveGfxLightGrid(&asset->lightGrid, &dest->lightGrid, builder); + + if (asset->models) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->models, asset->modelCount); + Utils::Stream::ClearPointer(&dest->aabbTreeCounts); + } + + if (asset->materialMemory) + { + AssertSize(Game::MaterialMemory, 8); buffer->align(Utils::Stream::ALIGN_4); Game::MaterialMemory* destMaterialMemoryTable = buffer->dest(); @@ -430,86 +457,88 @@ namespace Assets for (char i = 0; i < asset->materialMemoryCount; ++i) { - Game::MaterialMemory* destMaterialMemory = &destMaterialMemoryTable[i]; - Game::MaterialMemory* materialMemory = &asset->materialMemory[i]; + Game::MaterialMemory* destMaterialMemory = &destMaterialMemoryTable[i]; + Game::MaterialMemory* materialMemory = &asset->materialMemory[i]; - if (materialMemory->material) - { - destMaterialMemory->material = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, materialMemory->material->name).material; - } - } - Utils::Stream::ClearPointer(&dest->materialMemory); - } + if (materialMemory->material) + { + destMaterialMemory->material = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, materialMemory->material->name).material; + } + } - this->savesunflare_t(&asset->sun, &dest->sun, builder); + Utils::Stream::ClearPointer(&dest->materialMemory); + } - if(asset->unknownImage) { - dest->unknownImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->unknownImage->name).image; - } + this->savesunflare_t(&asset->sun, &dest->sun, builder); - buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); + if (asset->unknownImage) + { + dest->unknownImage = builder->requireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->unknownImage->name).image; + } - if (asset->cellCasterBits[0]) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->cellCasterBits[0], cellCount * ((cellCount + 31) >> 5)); - Utils::Stream::ClearPointer(&dest->cellCasterBits[0]); - } + buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); - if (asset->cellCasterBits[1]) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->cellCasterBits[1], ((cellCount + 31) >> 5)); - Utils::Stream::ClearPointer(&dest->cellCasterBits[1]); - } + if (asset->cellCasterBits[0]) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->cellCasterBits[0], cellCount * ((cellCount + 31) >> 5)); + Utils::Stream::ClearPointer(&dest->cellCasterBits[0]); + } - if (asset->sceneDynModel) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->sceneDynModel, asset->dpvsDyn.dynEntClientCount[0]); - Utils::Stream::ClearPointer(&dest->sceneDynModel); - } + if (asset->cellCasterBits[1]) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->cellCasterBits[1], ((cellCount + 31) >> 5)); + Utils::Stream::ClearPointer(&dest->cellCasterBits[1]); + } - if (asset->sceneDynBrush) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->sceneDynBrush, asset->dpvsDyn.dynEntClientCount[1]); - Utils::Stream::ClearPointer(&dest->sceneDynBrush); - } + if (asset->sceneDynModel) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->sceneDynModel, asset->dpvsDyn.dynEntClientCount[0]); + Utils::Stream::ClearPointer(&dest->sceneDynModel); + } - if (asset->primaryLightEntityShadowVis) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->primaryLightEntityShadowVis, (asset->unkCount2 + 0x1FFFF - asset->unkCount1) << 15); - Utils::Stream::ClearPointer(&dest->primaryLightEntityShadowVis); - } + if (asset->sceneDynBrush) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->sceneDynBrush, asset->dpvsDyn.dynEntClientCount[1]); + Utils::Stream::ClearPointer(&dest->sceneDynBrush); + } - if (asset->primaryLightDynEntShadowVis[0]) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->primaryLightDynEntShadowVis[0], asset->dpvsDyn.dynEntClientCount[0] * (asset->unkCount2 - 1 - asset->unkCount1)); - Utils::Stream::ClearPointer(&dest->primaryLightDynEntShadowVis[0]); - } + if (asset->primaryLightEntityShadowVis) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->primaryLightEntityShadowVis, (asset->unkCount2 + 0x1FFFF - asset->unkCount1) << 15); + Utils::Stream::ClearPointer(&dest->primaryLightEntityShadowVis); + } - if (asset->primaryLightDynEntShadowVis[1]) - { - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(asset->primaryLightDynEntShadowVis[1], asset->dpvsDyn.dynEntClientCount[1] * (asset->unkCount2 - 1 - asset->unkCount1)); - Utils::Stream::ClearPointer(&dest->primaryLightDynEntShadowVis[1]); - } + if (asset->primaryLightDynEntShadowVis[0]) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->primaryLightDynEntShadowVis[0], asset->dpvsDyn.dynEntClientCount[0] * (asset->unkCount2 - 1 - asset->unkCount1)); + Utils::Stream::ClearPointer(&dest->primaryLightDynEntShadowVis[0]); + } - if (asset->primaryLightForModelDynEnt) - { - // no align cause char - buffer->saveArray(asset->primaryLightForModelDynEnt, asset->dpvsDyn.dynEntClientCount[0]); - Utils::Stream::ClearPointer(&dest->primaryLightForModelDynEnt); - } + if (asset->primaryLightDynEntShadowVis[1]) + { + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(asset->primaryLightDynEntShadowVis[1], asset->dpvsDyn.dynEntClientCount[1] * (asset->unkCount2 - 1 - asset->unkCount1)); + Utils::Stream::ClearPointer(&dest->primaryLightDynEntShadowVis[1]); + } - buffer->popBlock(); + if (asset->primaryLightForModelDynEnt) + { + // no align cause char + buffer->saveArray(asset->primaryLightForModelDynEnt, asset->dpvsDyn.dynEntClientCount[0]); + Utils::Stream::ClearPointer(&dest->primaryLightForModelDynEnt); + } - if (asset->shadowGeom) - { - AssertSize(Game::GfxShadowGeometry, 12); + buffer->popBlock(); + + if (asset->shadowGeom) + { + AssertSize(Game::GfxShadowGeometry, 12); buffer->align(Utils::Stream::ALIGN_4); Game::GfxShadowGeometry* destShadowGeometryTable = buffer->dest(); @@ -517,29 +546,30 @@ namespace Assets for (char i = 0; i < asset->unkCount2; ++i) { - Game::GfxShadowGeometry* destShadowGeometry = &destShadowGeometryTable[i]; - Game::GfxShadowGeometry* shadowGeometry = &asset->shadowGeom[i]; + Game::GfxShadowGeometry* destShadowGeometry = &destShadowGeometryTable[i]; + Game::GfxShadowGeometry* shadowGeometry = &asset->shadowGeom[i]; - if (shadowGeometry->sortedSurfIndex) - { - buffer->align(Utils::Stream::ALIGN_2); - buffer->saveArray(shadowGeometry->sortedSurfIndex, shadowGeometry->surfaceCount); - Utils::Stream::ClearPointer(&destShadowGeometry->sortedSurfIndex); - } + if (shadowGeometry->sortedSurfIndex) + { + buffer->align(Utils::Stream::ALIGN_2); + buffer->saveArray(shadowGeometry->sortedSurfIndex, shadowGeometry->surfaceCount); + Utils::Stream::ClearPointer(&destShadowGeometry->sortedSurfIndex); + } - if (shadowGeometry->smodelIndex) - { - buffer->align(Utils::Stream::ALIGN_2); - buffer->saveArray(shadowGeometry->smodelIndex, shadowGeometry->smodelCount); - Utils::Stream::ClearPointer(&destShadowGeometry->smodelIndex); - } - } - Utils::Stream::ClearPointer(&dest->shadowGeom); - } + if (shadowGeometry->smodelIndex) + { + buffer->align(Utils::Stream::ALIGN_2); + buffer->saveArray(shadowGeometry->smodelIndex, shadowGeometry->smodelCount); + Utils::Stream::ClearPointer(&destShadowGeometry->smodelIndex); + } + } - if (asset->lightRegion) - { - AssertSize(Game::GfxLightRegion, 8); + Utils::Stream::ClearPointer(&dest->shadowGeom); + } + + if (asset->lightRegion) + { + AssertSize(Game::GfxLightRegion, 8); buffer->align(Utils::Stream::ALIGN_4); Game::GfxLightRegion* destLightRegionTable = buffer->dest(); @@ -547,50 +577,52 @@ namespace Assets for (char i = 0; i < asset->unkCount2; ++i) { - Game::GfxLightRegion* destLightRegion = &destLightRegionTable[i]; - Game::GfxLightRegion* lightRegion = &asset->lightRegion[i]; + Game::GfxLightRegion* destLightRegion = &destLightRegionTable[i]; + Game::GfxLightRegion* lightRegion = &asset->lightRegion[i]; - if (lightRegion->hulls) - { - AssertSize(Game::GfxLightRegionHull, 80); + if (lightRegion->hulls) + { + AssertSize(Game::GfxLightRegionHull, 80); - buffer->align(Utils::Stream::ALIGN_4); - Game::GfxLightRegionHull* destLightRegionHullTable = buffer->dest(); - buffer->saveArray(lightRegion->hulls, lightRegion->hullCount); + buffer->align(Utils::Stream::ALIGN_4); + Game::GfxLightRegionHull* destLightRegionHullTable = buffer->dest(); + buffer->saveArray(lightRegion->hulls, lightRegion->hullCount); - for (unsigned char j = 0; j < lightRegion->hullCount; ++j) - { - Game::GfxLightRegionHull* destLightRegionHull = &destLightRegionHullTable[j]; - Game::GfxLightRegionHull* lightRegionHull = &lightRegion->hulls[j]; + for (unsigned char j = 0; j < lightRegion->hullCount; ++j) + { + Game::GfxLightRegionHull* destLightRegionHull = &destLightRegionHullTable[j]; + Game::GfxLightRegionHull* lightRegionHull = &lightRegion->hulls[j]; - if (lightRegionHull->axis) - { - AssertSize(Game::GfxLightRegionAxis, 20); + if (lightRegionHull->axis) + { + AssertSize(Game::GfxLightRegionAxis, 20); - buffer->align(Utils::Stream::ALIGN_4); - buffer->saveArray(lightRegionHull->axis, lightRegionHull->axisCount); - Utils::Stream::ClearPointer(&destLightRegionHull->axis); - } + buffer->align(Utils::Stream::ALIGN_4); + buffer->saveArray(lightRegionHull->axis, lightRegionHull->axisCount); + Utils::Stream::ClearPointer(&destLightRegionHull->axis); + } - } - Utils::Stream::ClearPointer(&destLightRegion->hulls); - } + } - } - Utils::Stream::ClearPointer(&dest->lightRegion); - } + Utils::Stream::ClearPointer(&destLightRegion->hulls); + } - this->saveGfxWorldDpvsStatic(&asset->dpvs, &dest->dpvs, asset->dpvsPlanes.cellCount, builder); - this->saveGfxWorldDpvsDynamic(&asset->dpvsDyn, &dest->dpvsDyn, asset->dpvsPlanes.cellCount, builder); + } - if (asset->heroOnlyLight) - { - // no assert cause we use save manually here - buffer->align(Utils::Stream::ALIGN_4); - buffer->save(asset->heroOnlyLight, 56, asset->heroOnlyLightCount); - Utils::Stream::ClearPointer(&dest->heroOnlyLight); - } + Utils::Stream::ClearPointer(&dest->lightRegion); + } - buffer->popBlock(); - } + this->saveGfxWorldDpvsStatic(&asset->dpvs, &dest->dpvs, asset->dpvsPlanes.cellCount, builder); + this->saveGfxWorldDpvsDynamic(&asset->dpvsDyn, &dest->dpvsDyn, asset->dpvsPlanes.cellCount, builder); + + if (asset->heroOnlyLight) + { + // no assert cause we use save manually here + buffer->align(Utils::Stream::ALIGN_4); + buffer->save(asset->heroOnlyLight, 56, asset->heroOnlyLightCount); + Utils::Stream::ClearPointer(&dest->heroOnlyLight); + } + + buffer->popBlock(); + } } diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp index 1448e339..c78afb0e 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp @@ -7,13 +7,12 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; - private: - void saveGfxWorldDpvsPlanes(Game::GfxWorld* world, Game::GfxWorldDpvsPlanes* asset, Game::GfxWorldDpvsPlanes* dest, Components::ZoneBuilder::Zone* builder); - void saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder); - void saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder); - void savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder); - void saveGfxWorldDpvsStatic(Game::GfxWorldDpvsStatic* asset, Game::GfxWorldDpvsStatic* dest, int planeCount, Components::ZoneBuilder::Zone* builder); - void saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, int planeCount, Components::ZoneBuilder::Zone* builder); - + private: + void saveGfxWorldDpvsPlanes(Game::GfxWorld* world, Game::GfxWorldDpvsPlanes* asset, Game::GfxWorldDpvsPlanes* dest, Components::ZoneBuilder::Zone* builder); + void saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder); + void saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder); + void savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder); + void saveGfxWorldDpvsStatic(Game::GfxWorldDpvsStatic* asset, Game::GfxWorldDpvsStatic* dest, int planeCount, Components::ZoneBuilder::Zone* builder); + void saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, int planeCount, Components::ZoneBuilder::Zone* builder); }; }