Code: Select all
// Lego Island fix
// 0x3f7ffe00 == 1 - 2/0xffff or 2 Z units from the maximum Z. Integer math is faster
// and doesn't cause FP lib linker issues with the assembly.
INT32* pZ;
pZ = (INT32*)&TLVert[0].sz;
*pZ = (*pZ > 0x3f7ffe00) ? (0x3f7ffe00) : (*pZ);
pZ = (INT32*)&TLVert[1].sz;
*pZ = (*pZ > 0x3f7ffe00) ? (0x3f7ffe00) : (*pZ);
pZ = (INT32*)&TLVert[2].sz;
*pZ = (*pZ > 0x3f7ffe00) ? (0x3f7ffe00) : (*pZ);
The comment isn't super descriptive about exactly what this fixes in LEGO Island, but if you ignore the usage of hex and pointer trickery, the code itself is actually very straightforward. It simply clamps the Z values for each vertex of a triangle at 0.999969 (0x3f7ffe00 in hex). I guess 1.0 or higher cause some sort of problem in the game, and the fact that this fix had to be added at some point implies it used to work this way by default in earlier versions of Windows.
Could be interesting to try finding this code compiled in DDRAW.DLL (or whichever DLL it's in) and nopping it out to see if anything breaks.