From f173494fc69c17cafc8c42888ae6ae5f0ad7d5ed Mon Sep 17 00:00:00 2001 From: LJW-Dev <48092720+LJW-Dev@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:20:41 +0800 Subject: [PATCH] Minor improvements to GFX linker --- .../Game/T6/BSP/Linker/GfxWorldLinker.cpp | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp index 28307de3..510d84d3 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp @@ -44,10 +44,7 @@ namespace BSP assert(indexCount % 3 == 0); gfxWorld->draw.indexCount = static_cast(indexCount); gfxWorld->draw.indices = m_memory.Alloc(indexCount); - for (size_t indexIdx = 0; indexIdx < indexCount; indexIdx++) - { - gfxWorld->draw.indices[indexIdx] = bsp->gfxWorld.indices.at(indexIdx); - } + memcpy(gfxWorld->draw.indices, bsp->gfxWorld.indices.data(), sizeof(uint16_t) * indexCount); } bool GfxWorldLinker::loadMapSurfaces(BSPData* bsp, GfxWorld* gfxWorld) @@ -118,7 +115,7 @@ namespace BSP gfxSurface->tris.himipRadiusInvSq = 0.0f; } - // doesn't seem to matter what order the sorted surfs go in + // Some code uses Sorted surfs to index surfaces, so for simplicity keep the indexes sequential and from 0 gfxWorld->dpvs.sortedSurfIndex = m_memory.Alloc(surfaceCount); for (size_t surfIdx = 0; surfIdx < surfaceCount; surfIdx++) gfxWorld->dpvs.sortedSurfIndex[surfIdx] = static_cast(surfIdx); @@ -128,13 +125,13 @@ namespace BSP // set all surface types to lit opaque gfxWorld->dpvs.litSurfsBegin = 0; - gfxWorld->dpvs.litSurfsEnd = static_cast(surfaceCount); - gfxWorld->dpvs.emissiveOpaqueSurfsBegin = static_cast(surfaceCount); - gfxWorld->dpvs.emissiveOpaqueSurfsEnd = static_cast(surfaceCount); - gfxWorld->dpvs.emissiveTransSurfsBegin = static_cast(surfaceCount); - gfxWorld->dpvs.emissiveTransSurfsEnd = static_cast(surfaceCount); - gfxWorld->dpvs.litTransSurfsBegin = static_cast(surfaceCount); - gfxWorld->dpvs.litTransSurfsEnd = static_cast(surfaceCount); + gfxWorld->dpvs.litSurfsEnd = static_cast(surfaceCount - 1); + gfxWorld->dpvs.emissiveOpaqueSurfsBegin = static_cast(surfaceCount - 1); + gfxWorld->dpvs.emissiveOpaqueSurfsEnd = static_cast(surfaceCount - 1); + gfxWorld->dpvs.emissiveTransSurfsBegin = static_cast(surfaceCount - 1); + gfxWorld->dpvs.emissiveTransSurfsEnd = static_cast(surfaceCount - 1); + gfxWorld->dpvs.litTransSurfsBegin = static_cast(surfaceCount - 1); + gfxWorld->dpvs.litTransSurfsEnd = static_cast(surfaceCount - 1); // visdata is written to by the game // all visdata is alligned by 128 @@ -340,10 +337,13 @@ namespace BSP gfxWorld->shadowGeom = m_memory.Alloc(gfxWorld->primaryLightCount); for (unsigned int lightIdx = 0; lightIdx < gfxWorld->primaryLightCount; lightIdx++) { + gfxWorld->shadowGeom[lightIdx].smodelCount = 0; - gfxWorld->shadowGeom[lightIdx].surfaceCount = 0; gfxWorld->shadowGeom[lightIdx].smodelIndex = nullptr; - gfxWorld->shadowGeom[lightIdx].sortedSurfIndex = nullptr; + + // sorted surfs is written to by the game + gfxWorld->shadowGeom[lightIdx].surfaceCount = gfxWorld->dpvs.staticSurfaceCount; + gfxWorld->shadowGeom[lightIdx].sortedSurfIndex = m_memory.Alloc(gfxWorld->dpvs.staticSurfaceCount); } gfxWorld->lightRegion = m_memory.Alloc(gfxWorld->primaryLightCount); @@ -362,7 +362,7 @@ namespace BSP void GfxWorldLinker::loadLightGrid(GfxWorld* gfxWorld) { - // there is almost no basis for the values in this code, they were chosen based on what looks correct when reverse engineering. + // the values in this code were chosen based on what looked correct when reverse engineering. // mins and maxs define the range that the lightgrid will work in. // unknown how these values are calculated, but the below values are larger