Mercurial > might-and-magic-trilogy
diff LightmapBuilder.cpp @ 0:8b8875f5b359
Initial commit
author | Nomad |
---|---|
date | Fri, 05 Oct 2012 16:07:14 +0200 |
parents | |
children | 2ca04ccb612a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightmapBuilder.cpp Fri Oct 05 16:07:14 2012 +0200 @@ -0,0 +1,2128 @@ +#include "LightmapBuilder.h" +#include "Game.h" +#include "stru314.h" +#include "Outdoor.h" + +#include "mm7_data.h" + + + + + + + +LightsStack_StationaryLight_ *pStationaryLightsStack; +StationaryLight pStationaryLights[400]; +int uNumStationaryLightsApplied; // weak +LightsStack_MobileLight_ *pMobileLightsStack; +MobileLight pMobileLights[400]; +int uNumMobileLightsApplied; + + + + + +//----- (0045DF13) -------------------------------------------------------- +Lightmap::Lightmap() +{ + field_C18 = 0; +} + + + + + +//----- (0045BB06) -------------------------------------------------------- +LightmapBuilder::LightmapBuilder() +{ + //std__vector_000004.reserve(512); + //std__vector_183808.reserve(768); + + for (uint i = 0; i < 256; ++i) + field_3C8C34[i].flt_2C = 0.0f; +} + + + + + +//----- (0045BC07) -------------------------------------------------------- +char LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, float a6, char a7) +{ + char *v7; // eax@3 + signed int v8; // ecx@3 + RenderVertexSoft *v9; // eax@10 + unsigned int v10; // edx@10 + const void *v11; // esi@11 + void *v12; // edi@11 + char v13; // zf@11 + stru154 *v14; // esi@12 + double v16; // st7@17 + double v17; // st6@17 + float v18; // eax@17 + int *v19; // esi@20 + double v20; // st7@21 + int v21; // eax@21 + unsigned int v22; // eax@21 + int v23; // ecx@23 + float v24; // ST04_4@23 + float v25; // [sp+8h] [bp-64h]@18 + Vec3_float_ *v26; // [sp+18h] [bp-54h]@17 + int v27; // [sp+1Ch] [bp-50h]@17 + int arg0; // [sp+2Ch] [bp-40h]@21 + int v29; // [sp+30h] [bp-3Ch]@21 + int v30; // [sp+34h] [bp-38h]@21 + double v31; // [sp+38h] [bp-34h]@21 + double v32; // [sp+40h] [bp-2Ch]@21 + double v33; // [sp+48h] [bp-24h]@21 + int v34; // [sp+50h] [bp-1Ch]@24 + LightmapBuilder *thisa; // [sp+54h] [bp-18h]@1 + int v36; // [sp+58h] [bp-14h]@21 + int v37; // [sp+5Ch] [bp-10h]@21 + unsigned __int64 v38; // [sp+60h] [bp-Ch]@21 + int a9; // [sp+68h] [bp-4h]@8 + + thisa = this; + if ( !uNumVertices ) + return 0; + + static bool _static_initialized = false; + static RenderVertexSoft LightmapBuilder_static_sub_45BC07_stru_69B140[64]; + if (!_static_initialized) + { + for (uint i = 0; i < 64; ++i) + LightmapBuilder_static_sub_45BC07_stru_69B140[i].flt_2C = 0.0f; + _static_initialized = true; + } + + a9 = (int)a5; + if ( a6 == 0.0 ) + { + v14 = a3; + } + else + { + if ( (signed int)uNumVertices > 0 ) + { + v9 = LightmapBuilder_static_sub_45BC07_stru_69B140; + v10 = (char *)a5 - (char *)LightmapBuilder_static_sub_45BC07_stru_69B140; + a5 = (RenderVertexSoft *)uNumVertices; + do + { + v11 = (char *)v9 + v10; + v12 = v9; + ++v9; + v13 = a5 == (RenderVertexSoft *)1; + a5 = (RenderVertexSoft *)((char *)a5 - 1); + memcpy(v12, v11, 0x30u); + } + while ( !v13 ); + } + v14 = a3; + if ( pGame->pIndoorCameraD3D->_437376( + a3, + LightmapBuilder_static_sub_45BC07_stru_69B140, + &uNumVertices) == 1 ) + { + if ( !uNumVertices ) + return 0; + a9 = (int)LightmapBuilder_static_sub_45BC07_stru_69B140; + } + } + v16 = v14->vNormal.z; + v17 = v14->vNormal.y; + v18 = v14->vNormal.x; + + static stru314 LightmapBuilder_static_sub_45BC07_stru_69B110; + v27 = (int)&LightmapBuilder_static_sub_45BC07_stru_69B110.field_1C; + LightmapBuilder_static_sub_45BC07_stru_69B110.field_4.y = v17; + LightmapBuilder_static_sub_45BC07_stru_69B110.field_4.x = v18; + v26 = &LightmapBuilder_static_sub_45BC07_stru_69B110.field_10; + LightmapBuilder_static_sub_45BC07_stru_69B110.field_4.z = v16; + dword_69B138 = LODWORD(v14->field_10); + if ( !pGame->pIndoorCameraD3D->GetFacetOrientation( + v14->field_14, + &LightmapBuilder_static_sub_45BC07_stru_69B110.field_4, + &LightmapBuilder_static_sub_45BC07_stru_69B110.field_10, + &LightmapBuilder_static_sub_45BC07_stru_69B110.field_1C) ) + { + MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0); + ExitProcess(0); + } + a5 = 0; + if ( a2->field_AC > 0 ) + { + v19 = a2->_blv_lights_ys; + do + { + v20 = *((float *)v19 + 80) * 255.0; + arg0 = *(v19 - 20); + v29 = *v19; + v30 = v19[60]; + v21 = *(v19 - 60); + a6 = v20; + v36 = v21; + v37 = v19[20]; + v33 = a6 + 6.7553994e15; + a6 = *((float *)v19 + 100) * 255.0; + v32 = a6 + 6.7553994e15; + a6 = *((float *)v19 + 120) * 255.0; + v31 = a6 + 6.7553994e15; + v38 = __PAIR__(LODWORD(v32), LODWORD(v31)); + v22 = LODWORD(v31) | ((LODWORD(v32) | (LODWORD(v33) << 8)) << 8); + if ( !(LODWORD(v31) | ((LODWORD(v32) | (LODWORD(v33) << 8)) << 8)) ) + v22 = 0xFFFFFFu; + v27 = a7; + v23 = (int)a5; + v26 = (Vec3_float_ *)a9; + LOBYTE(v23) = *((unsigned char *)&a5[20].vWorldViewPosition.y + (unsigned int)a2); + v25 = (double)v37; + v24 = (double)v36; + if ( !_45BE86_build_light_polygon( + (int)&arg0, + v24, + v22, + v25, + v23, + &LightmapBuilder_static_sub_45BC07_stru_69B110, + uNumVertices, + (RenderVertexSoft *)a9, + a7) ) + { + MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0); + v34 = 5080748; + } + a5 = (RenderVertexSoft *)((char *)a5 + 1); + ++v19; + } + while ( (signed int)a5 < a2->field_AC ); + } + return 1; +} + +//----- (0045BE86) -------------------------------------------------------- +char LightmapBuilder::_45BE86_build_light_polygon(int arg0, float a4, int arg8, float a5, int uLightType, stru314 *a7, signed int a2, RenderVertexSoft *a9, char uClipFlag) +{ + LightmapBuilder *v10; // esi@1 + Lightmap *v11; // edi@3 + double v12; // st7@5 + double v13; // st7@5 + stru314 *v14; // ebx@5 + double v15; // st7@5 + RenderVertexSoft *pLightmapVertices; // edx@5 + double v17; // st7@5 + double v18; // st7@5 + char *v19; // eax@5 + double v20; // st6@5 + double v21; // st5@5 + signed int v22; // ecx@5 + double v23; // st5@5 + double v24; // st7@6 + int v25; // ebx@8 + double v26; // st7@8 + int v27; // eax@8 + double v28; // st6@8 + double v29; // st6@8 + double v30; // st5@8 + int v31; // eax@8 + int v32; // ebx@8 + unsigned int v33; // ecx@8 + int v34; // edx@9 + int v35; // edx@11 + unsigned int v36; // edx@13 + int v37; // ecx@14 + double v38; // st7@14 + double v39; // st7@16 + double v40; // st7@16 + double v41; // st7@22 + stru9 *v42; // ecx@22 + char result; // al@22 + unsigned int *v44; // ebx@23 + int v45; // eax@24 + RenderVertexSoft *v46; // edi@27 + std::string *v47; // ecx@34 + char *v48; // esi@39 + int v49; // eax@39 + unsigned __int8 v50; // sf@39 + unsigned __int8 v51; // of@39 + const char *v52; // [sp-Ch] [bp-58h]@34 + int v53; // [sp-8h] [bp-54h]@34 + std::string v54; // [sp-4h] [bp-50h]@19 + float v55; // [sp+0h] [bp-4Ch]@22 + float v56; // [sp+4h] [bp-48h]@22 + int v57; // [sp+8h] [bp-44h]@22 + unsigned int v58; // [sp+Ch] [bp-40h]@16 + void *v59; // [sp+10h] [bp-3Ch]@16 + float v60; // [sp+20h] [bp-2Ch]@8 + float v61; // [sp+24h] [bp-28h]@8 + float v62; // [sp+28h] [bp-24h]@8 + Vec3_float_ a1; // [sp+2Ch] [bp-20h]@8 + double v64; // [sp+38h] [bp-14h]@8 + int pLightmapVertices_; // [sp+40h] [bp-Ch]@5 + float v66; // [sp+44h] [bp-8h]@5 + char v67; // [sp+4Bh] [bp-1h]@2 + float arg0b; // [sp+54h] [bp+8h]@8 + int arg0c; // [sp+54h] [bp+8h]@8 + int arg0a; // [sp+54h] [bp+8h]@8 + + v10 = this; + if ( a4 == 0.0 ) + return 1; + v67 = uLightType & 1; + v11 = uLightType & 1 ? &std__vector_000004[std__vector_000004_size] : + &std__vector_183808[std__vector_183808_size]; + v12 = a4 - a5; + this->flt_3C8C24 = v12; + v13 = sqrt((a4 + a4 - v12) * v12); + v10->flt_3C8C28 = v13; + v14 = a7; + v66 = 1.0 / a4; + v10->flt_3C8C2C = 1.0 - (a4 - v13) * v66; + v11->field_C08 = (signed __int64)((double)*(signed int *)arg0 - a5 * v14->field_4.x); + v11->field_C0A = (signed __int64)((double)*(signed int *)(arg0 + 4) - a5 * v14->field_4.y); + v15 = a4; + v11->field_C0C = (signed __int64)((double)*(signed int *)(arg0 + 8) - a5 * v14->field_4.z); + pLightmapVertices = v11->pVertices; + v17 = v15 * v10->flt_3C8C2C; + pLightmapVertices_ = (int)v11->pVertices; + v10->flt_3C8C30 = v17; + v10->flt_3C8C0C = v17 * v14->field_10.x; + v10->flt_3C8C10 = v17 * v14->field_10.y; + v10->flt_3C8C14 = v17 * v14->field_10.z; + v10->flt_3C8C18 = v17 * v14->field_1C.x; + v10->flt_3C8C1C = v17 * v14->field_1C.y; + v10->flt_3C8C20 = v17 * v14->field_1C.z; + LODWORD(a5) = v11->field_C08; + v18 = (double)SLODWORD(a5); + v11->pVertices[0].vWorldPosition.x = v18 - v10->flt_3C8C18 + v10->flt_3C8C0C; + LODWORD(a5) = v11->field_C0A; + v19 = (char *)&v11->pVertices[0].vWorldPosition.y; + v20 = (double)SLODWORD(a5); + v21 = v20 - v10->flt_3C8C1C; + LODWORD(a5) = v11->field_C0C; + v22 = 4; + v11->pVertices[0].vWorldPosition.y = v21 + v10->flt_3C8C10; + v23 = (double)SLODWORD(a5); + a5 = v23; + v11->pVertices[0].vWorldPosition.z = v23 - v10->flt_3C8C20 + v10->flt_3C8C14; + v11->pVertices[0].u = 0.0; + v11->pVertices[0].v = 0.0; + v11->pVertices[1].vWorldPosition.x = v18 - v10->flt_3C8C18 - v10->flt_3C8C0C; + v11->pVertices[1].vWorldPosition.y = v20 - v10->flt_3C8C1C - v10->flt_3C8C10; + v11->pVertices[1].vWorldPosition.z = v23 - v10->flt_3C8C20 - v10->flt_3C8C14; + v11->pVertices[1].u = 0.0; + v11->pVertices[1].v = 1.0; + v11->pVertices[2].vWorldPosition.x = v18 + v10->flt_3C8C18 - v10->flt_3C8C0C; + v11->pVertices[2].vWorldPosition.y = v20 + v10->flt_3C8C1C - v10->flt_3C8C10; + v11->pVertices[2].vWorldPosition.z = v23 + v10->flt_3C8C20 - v10->flt_3C8C14; + v11->pVertices[2].u = 1.0; + v11->pVertices[2].v = 1.0; + v11->pVertices[3].vWorldPosition.x = v18 + v10->flt_3C8C18 + v10->flt_3C8C0C; + v11->pVertices[3].vWorldPosition.y = v20 + v10->flt_3C8C1C + v10->flt_3C8C10; + v11->pVertices[3].vWorldPosition.z = a5 + v10->flt_3C8C20 + v10->flt_3C8C14; + v11->pVertices[3].u = 1.0; + v11->pVertices[3].v = 0.0; + do + { + v24 = v14->field_4.y * *(float *)v19 + + *((float *)v19 + 1) * v14->field_4.z + + v14->field_4.x * *((float *)v19 - 1) + + *(float *)&v14->field_28; + *((float *)v19 - 1) = *((float *)v19 - 1) - v24 * v14->field_4.x; + *(float *)v19 = *(float *)v19 - v24 * v14->field_4.y; + v19 += 48; + --v22; + *((float *)v19 - 11) = *((float *)v19 - 11) - v24 * v14->field_4.z; + } + while ( v22 ); + v11->field_C10 = arg8; + v11->uNumVertices = 4; + if ( pGame->uFlags2 & 4 ) + { + LODWORD(a5) = v11->field_C0C; + v25 = arg0; + v26 = (double)SLODWORD(a5); + LODWORD(a5) = v11->field_C0A; + v27 = v11->field_C08; + a5 = (double)SLODWORD(a5); + arg8 = v27; + v28 = (double)v27; + v61 = a5; + v60 = v28; + v62 = v26; + *(float *)&arg8 = (double)*(signed int *)(arg0 + 8); + arg0b = (double)*(signed int *)(arg0 + 4); + v29 = (double)*(signed int *)v25 - v28; + v30 = arg0b - a5; + a5 = *(float *)&arg8 - v26; + a1.x = v29; + a1.z = a5; + a1.y = v30; + a1.Normalize(); + v64 = v62 + 6.7553994e15; + LODWORD(a5) = LODWORD(v64); + v64 = v61 + 6.7553994e15; + arg0c = LODWORD(v64); + v64 = v60 + 6.7553994e15; + arg8 = LODWORD(v64); + HIDWORD(v64) = abs(*(int *)(v25 + 8) - (signed)LODWORD(a5)); + arg0a = abs(*(int *)(v25 + 4) - arg0c); + v31 = abs(*(int *)v25 - arg8); + LODWORD(a5) = v31; + v32 = arg0a; + v33 = HIDWORD(v64); + if ( v31 < arg0a ) + { + v34 = v31; + v31 = arg0a; + v32 = v34; + } + if ( v31 < SHIDWORD(v64) ) + { + v35 = v31; + v31 = HIDWORD(v64); + v33 = v35; + } + if ( v32 < (signed int)v33 ) + { + v36 = v33; + v33 = v32; + v32 = v36; + } + v37 = v33 >> 2; + LODWORD(a5) = ((unsigned int)(11 * v32) >> 5) + v37 + v31; + v38 = (double)SLODWORD(a5); + if ( v38 > a4 ) + return 1; + a4 = v66 * v38; + if ( uLightType & 4 ) + { + v59 = (void *)v37; + uLightType = dword_4D86CC; + v58 = v37; + v39 = fabs(a1.x * a7->field_4.x + a1.z * a7->field_4.z + a1.y * a7->field_4.y); + v40 = v39 * 1.0 * *(float *)&uLightType; + } + else + { + if ( uLightType & 8 ) + { + v40 = 1.0 * 1.0; + } + else + { + MessageBoxW(nullptr, L"Invalid light type!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:277", 0); + v40 = *(float *)&uLightType; + } + } + v14 = a7; + pLightmapVertices = (RenderVertexSoft *)pLightmapVertices_; + v11->flt_C14 = v40 - a4 * v40; + } + else + { + v11->flt_C14 = v10->flt_3C8C2C; + } + v41 = v14->field_4.z; + v42 = pGame->pStru9Instance; + v59 = &v11->uNumVertices; + v58 = (unsigned int)pLightmapVertices; + *(float *)&v57 = v41; + v56 = v14->field_4.y; + v55 = v14->field_4.x; + result = v42->_4980B9(a9, a2, v55, v56, *(float *)&v57, pLightmapVertices, &v11->uNumVertices); + if ( !result ) + return result; + v44 = &v11->uNumVertices; + if ( !v11->uNumVertices ) + return 1; + v45 = v10->_45C6D6(a2, a9, v11); + if ( v45 != a2 && v45 > 0 ) + v10->_45C4B9(a2, a9, v11); + v59 = (void *)*v44; + v46 = (RenderVertexSoft *)pLightmapVertices_; + pGame->pIndoorCameraD3D->ViewTransform((RenderVertexSoft *)pLightmapVertices_, (unsigned int)v59); + v59 = 0; + v58 = *v44; + pGame->pIndoorCameraD3D->_436BB7_project_and_stuff(v46, v58, 0); + if ( !(uClipFlag & 1) ) + goto LABEL_38; + if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor) + { + if ( uClipFlag & 2 ) + { + v59 = &a4; + v58 = (unsigned int)v10->field_3C8C34; + v57 = *v44; + pGame->pIndoorCameraD3D->_436CDC(v46, v57, v10->field_3C8C34, (unsigned int *)&a4); +LABEL_33: + v59 = v44; + v58 = (unsigned int)v10->field_3C8C34; + v57 = (int)v46; + v56 = a4; + pGame->pIndoorCameraD3D->_437143(LODWORD(a4), v46, v10->field_3C8C34, v44); + goto LABEL_37; + } + if ( uClipFlag & 4 ) + { + v59 = &a4; + v58 = (unsigned int)v10->field_3C8C34; + v57 = *v44; + pGame->pIndoorCameraD3D->_436F09(v46, v57, v10->field_3C8C34, (unsigned int *)&a4); + goto LABEL_33; + } + v58 = (unsigned int)"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330"; + v52 = "Undefined clip flag specified"; + } + else + { + v58 = (unsigned int)"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:335"; + v52 = "Lightpoly builder native indoor clipping not implemented"; + } + MessageBoxA(nullptr, v52, (const char *)v58, 0); +LABEL_37: + if ( a4 != 0.0 ) + { +LABEL_38: + if ( v67 ) + { + v48 = (char *)&v10->std__vector_000004_size; + v49 = *(unsigned int *)v48; + v51 = __OFSUB__(*(unsigned int *)v48, 511); + v50 = *(unsigned int *)v48 - 511 < 0; + } + else + { + v48 = (char *)&v10->std__vector_183808_size; + v49 = *(unsigned int *)v48; + v51 = __OFSUB__(*(unsigned int *)v48, 767); + v50 = *(unsigned int *)v48 - 767 < 0; + } + if ( v50 ^ v51 ) + *(unsigned int *)v48 = v49 + 1; + } + return 1; +} + +//----- (0045C4B9) -------------------------------------------------------- +int LightmapBuilder::_45C4B9(int a2, RenderVertexSoft *a3, Lightmap *pLightmap) +{ + Lightmap *v4; // edi@1 + int v5; // eax@1 + signed int v6; // ecx@1 + RenderVertexSoft *v7; // ebx@2 + int v8; // edx@3 + RenderVertexSoft *v9; // esi@3 + int v10; // eax@6 + char *v11; // edi@7 + RenderVertexSoft *v12; // ecx@8 + char v13; // bl@17 + signed int v14; // edx@17 + double v15; // st6@18 + double v16; // st6@21 + double v17; // st6@24 + signed int v18; // edx@33 + int v20; // [sp+4h] [bp-1Ch]@3 + int v21; // [sp+8h] [bp-18h]@8 + float v22; // [sp+Ch] [bp-14h]@23 + float v23; // [sp+10h] [bp-10h]@20 + int v24; // [sp+14h] [bp-Ch]@1 + RenderVertexSoft *v25; // [sp+18h] [bp-8h]@2 + char v26; // [sp+1Eh] [bp-2h]@17 + char v27; // [sp+1Fh] [bp-1h]@17 + + v4 = pLightmap; + v5 = 0; + v6 = pLightmap->uNumVertices; + v24 = 0; + if ( v6 > 0 ) + { + v7 = pLightmap->pVertices; + v25 = pLightmap->pVertices; + do + { + v20 = v5 + 1; + v8 = (v5 + 1) % v6; + v9 = &v4->pVertices[v8]; + if ( v7->vWorldPosition.x != v9->vWorldPosition.x + || v7->vWorldPosition.y != v4->pVertices[v8].vWorldPosition.y + || v7->vWorldPosition.z != v4->pVertices[v8].vWorldPosition.z ) + { + v10 = 0; + if ( a2 > 0 ) + { + v11 = (char *)&a3->vWorldPosition.z; + do + { + v21 = v10 + 1; + v12 = &a3[(v10 + 1) % a2]; + if ( (*((float *)v11 - 2) != v12->vWorldPosition.x + || *((float *)v11 - 1) != v12->vWorldPosition.y + || *(float *)v11 != v12->vWorldPosition.z) + && v7->vWorldPosition.x == *((float *)v11 - 2) + && v7->vWorldPosition.y == *((float *)v11 - 1) + && v7->vWorldPosition.z == *(float *)v11 + && (v9->vWorldPosition.x != v12->vWorldPosition.x + || v9->vWorldPosition.y != v12->vWorldPosition.y + || v9->vWorldPosition.z != v12->vWorldPosition.z) ) + { + v13 = 0; + v14 = 0; + v27 = 0; + v26 = 0; + if ( v9->vWorldPosition.x <= (double)v12->vWorldPosition.x ) + v15 = v12->vWorldPosition.x - v9->vWorldPosition.x; + else + v15 = v9->vWorldPosition.x - v12->vWorldPosition.x; + v23 = v15; + if ( v9->vWorldPosition.y <= (double)v12->vWorldPosition.y ) + v16 = v12->vWorldPosition.y - v9->vWorldPosition.y; + else + v16 = v9->vWorldPosition.y - v12->vWorldPosition.y; + v22 = v16; + if ( v9->vWorldPosition.z <= (double)v12->vWorldPosition.z ) + v17 = v12->vWorldPosition.z - v9->vWorldPosition.z; + else + v17 = v9->vWorldPosition.z - v12->vWorldPosition.z; + if ( v23 < 1.0 ) + { + v13 = 1; + v14 = 1; + } + if ( v22 < 1.0 ) + { + v27 = 1; + ++v14; + } + if ( v17 < 1.0 ) + { + v26 = 1; + ++v14; + } + if ( v14 > 1 ) + { + v18 = 0; + if ( v13 && v9->vWorldPosition.x != v12->vWorldPosition.x ) + { + v18 = 1; + v9->vWorldPosition.x = v12->vWorldPosition.x; + } + if ( v27 && v9->vWorldPosition.y != v12->vWorldPosition.y ) + { + ++v18; + v9->vWorldPosition.y = v12->vWorldPosition.y; + } + if ( v26 && v9->vWorldPosition.z != v12->vWorldPosition.z ) + { + ++v18; + v9->vWorldPosition.z = v12->vWorldPosition.z; + } + if ( v18 > 0 ) + ++v24; + } + v7 = v25; + } + ++v10; + v11 += 48; + } + while ( v21 < a2 ); + v4 = pLightmap; + } + } + v5 = v20; + v6 = v4->uNumVertices; + ++v7; + v25 = v7; + } + while ( v20 < v6 ); + } + return v24; +} + +//----- (0045C6D6) -------------------------------------------------------- +int LightmapBuilder::_45C6D6(int a2, RenderVertexSoft *a3, Lightmap *pLightmap) +{ + Lightmap *v4; // edi@1 + signed int v5; // ebx@1 + signed int v6; // esi@1 + RenderVertexSoft *v7; // ecx@2 + char *v8; // edx@4 + double v9; // st7@6 + double v10; // st6@10 + double v11; // st5@14 + double v12; // st7@17 + RenderVertexSoft *v13; // eax@21 + int v15; // [sp+Ch] [bp-8h]@1 + float v16; // [sp+10h] [bp-4h]@1 + int pLightmapa; // [sp+24h] [bp+10h]@3 + + v4 = pLightmap; + v5 = 0; + v6 = -1; + v16 = 3.4028235e38; + v15 = 0; + if ( (signed int)pLightmap->uNumVertices > 0 ) + { + v7 = pLightmap->pVertices; + do + { + pLightmapa = 0; + if ( a2 > 0 ) + { + v8 = (char *)&a3->vWorldPosition.z; + do + { + if ( v7->vWorldPosition.x <= (double)*((float *)v8 - 2) ) + v9 = *((float *)v8 - 2) - v7->vWorldPosition.x; + else + v9 = v7->vWorldPosition.x - *((float *)v8 - 2); + if ( v9 < 2.0 ) + { + v10 = v7->vWorldPosition.y <= (double)*((float *)v8 - 1) ? *((float *)v8 - 1) - v7->vWorldPosition.y : v7->vWorldPosition.y - *((float *)v8 - 1); + if ( v10 < 2.0 ) + { + v11 = v7->vWorldPosition.z <= (double)*(float *)v8 ? *(float *)v8 - v7->vWorldPosition.z : v7->vWorldPosition.z - *(float *)v8; + if ( v11 < 2.0 ) + { + v12 = v9 + v11 + v10; + if ( v12 < v16 ) + { + v16 = v12; + v6 = pLightmapa; + } + } + } + } + ++pLightmapa; + v8 += 48; + } + while ( pLightmapa < a2 ); + if ( v6 != -1 ) + { + v13 = &a3[v6]; + ++v15; + v7->vWorldPosition.x = v13->vWorldPosition.x; + v7->vWorldPosition.y = v13->vWorldPosition.y; + v7->vWorldPosition.z = v13->vWorldPosition.z; + } + } + v6 = -1; + ++v5; + ++v7; + v16 = 3.4028235e38; + } + while ( v5 < (signed int)v4->uNumVertices ); + } + return v15; +} + +//----- (0045C7F6) -------------------------------------------------------- +bool LightmapBuilder::ApplyLights_IndoorFace(unsigned int uFaceID) +{ + BLVFace *pFace; // esi@1 + int v3; // ebx@1 + int uSectorID; // edi@1 + int v5; // ecx@5 + BLVLightMM7 *v6; // eax@7 + int v7; // edi@10 + bool result; // eax@14 + LightmapBuilder *thisa; // [sp+Ch] [bp-Ch]@1 + MobileLight *pMobileLight; // [sp+10h] [bp-8h]@2 + int uSectLights; // [sp+10h] [bp-8h]@5 + StationaryLight *pStationaryLight; // [sp+10h] [bp-8h]@11 + int v13; // [sp+14h] [bp-4h]@1 + int i; // [sp+14h] [bp-4h]@5 + + pFace = &pIndoor->pFaces[uFaceID]; + v3 = uNumMobileLightsApplied; + v13 = 0; + thisa = this; + uSectorID = pFace->uSectorID; + uFaceID = 0; + stru_F8AD28.field_2C = (stru_F8AD28.field_3F8 + pIndoor->pSectors[uSectorID].uMinAmbientLightLevel) << 16; + if ( uNumMobileLightsApplied > 0 ) + { + pMobileLight = pMobileLights; + do + { + if ( (signed int)uFaceID >= 20 ) + break; + ApplyLight_BLV((StationaryLight *)pMobileLight, pFace, &uFaceID, 1, 0); + ++v13; + ++pMobileLight; + } + while ( v13 < v3 ); + } + v5 = 0; + i = 0; + for ( uSectLights = pIndoor->pSectors[uSectorID].uNumLights; i < uSectLights; v5 = i++ + 1 ) + { + if ( (signed int)uFaceID >= 20 ) + break; + v6 = &pIndoor->pLights[*(&pIndoor->pSectors[uSectorID].pLights->vPosition.x + v5)]; + if ( !(v6->uAtributes & 8) ) + ApplyLight_BLV((StationaryLight *)v6, pFace, &uFaceID, 0, (int)&byte_4E94D0); + } + v7 = 0; + if ( uNumStationaryLightsApplied > 0 ) + { + pStationaryLight = pStationaryLights; + do + { + if ( (signed int)uFaceID >= 20 ) + break; + ApplyLight_BLV(pStationaryLight, pFace, &uFaceID, 0, (int)&byte_4E94D0); + ++pStationaryLight; + ++v7; + } + while ( v7 < uNumStationaryLightsApplied ); + } + result = uFaceID; + stru_F8AD28.field_AC = uFaceID; + LOBYTE(result) = 1; + return result; +} +// 4E94D0: using guessed type char byte_4E94D0; +// 519AB4: using guessed type int uNumStationaryLightsApplied; + +//----- (0045C911) -------------------------------------------------------- +bool LightmapBuilder::ApplyLight_BLV(StationaryLight *pLight, BLVFace *a2, unsigned int *pSlot, char X, int a5) +{ + BLVFace *result; // eax@0 + StationaryLight *v7; // edi@1 + signed int v8; // ecx@1 + int v9; // edx@2 + int v10; // edx@4 + int v11; // esi@4 + int v12; // edx@6 + double v13; // st7@8 + __int16 v14; // fps@8 + char v15; // c0@9 + char v16; // c2@9 + char v17; // c3@9 + double v18; // st6@12 + __int16 v19; // fps@12 + char v20; // c0@12 + char v21; // c2@12 + char v22; // c3@12 + signed int v23; // [sp+10h] [bp-4h]@2 + float pLighta; // [sp+1Ch] [bp+8h]@13 + signed int a2a; // [sp+20h] [bp+Ch]@4 + + v7 = pLight; + v8 = pLight->uRadius; + if ( v8 > 0 + && (result = a2, v9 = pLight->vPosition.x, v23 = v9, v9 > a2->pBounding.x1 - v8) + && v9 < v8 + a2->pBounding.x2 + && (v10 = pLight->vPosition.y, v11 = a2->pBounding.y1 - v8, a2a = v10, v10 > v11) + && v10 < v8 + result->pBounding.y2 + && (v12 = pLight->vPosition.z, v12 > result->pBounding.z1 - v8) + && v12 < v8 + result->pBounding.z2 + && ((v13 = (double)v12 * result->pFacePlane.vNormal.z + + (double)a2a * result->pFacePlane.vNormal.y + + (double)v23 * result->pFacePlane.vNormal.x + + result->pFacePlane.dist, + //UNDEF(v14), + X) + || (v15 = v13 < 0.0, v16 = 0, v17 = v13 == 0.0, BYTE1(result) = HIBYTE(v14), v13 >= 0.0)) + && (v18 = (double)pLight->uRadius, + //UNDEF(v19), + v20 = v13 < v18, + v21 = 0, + v22 = v13 == v18, + BYTE1(result) = HIBYTE(v19), + v13 <= v18) ) + { + stru_F8AD28._blv_lights_radii[*pSlot] = v8; + stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / v8; + stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x; + stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y; + stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z; + stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689; + stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689; + stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689; + pLighta = v13; + stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = abs(COERCE_UNSIGNED_INT64(pLighta + 6.7553994e15)); + result = (BLVFace *)*pSlot; + stru_F8AD28._blv_lights_smthngs[(*pSlot)++] = v7->field_B; + LOBYTE(result) = 1; + } + else + { + LOBYTE(result) = 0; + } + return (bool)result; +} + +//----- (0045CA88) -------------------------------------------------------- +int LightmapBuilder::_45CA88(stru320 *a2, RenderVertexSoft *a3, int a4, Vec3_float_ *pNormal) +{ + int result; // eax@1 + stru320 *v6; // ecx@2 + RenderVertexSoft *v7; // ebx@2 + double v8; // st7@2 + double v9; // st6@2 + char *v10; // eax@3 + double v11; // st7@5 + __int64 v12; // ST2C_8@5 + float v13; // edx@5 + int v14; // eax@5 + float v15; // ST10_4@5 + Vec3_float_ v16; // ST00_12@5 + double v17; // st7@5 + int a5; // [sp+2Ch] [bp-1Ch]@1 + float v19; // [sp+30h] [bp-18h]@1 + float v20; // [sp+34h] [bp-14h]@1 + LightmapBuilder *thisa; // [sp+38h] [bp-10h]@1 + int v22; // [sp+3Ch] [bp-Ch]@1 + int *j; // [sp+40h] [bp-8h]@3 + int i; // [sp+44h] [bp-4h]@1 + int a3a; // [sp+58h] [bp+10h]@2 + + *(float *)&a5 = 0.0; + v19 = 0.0; + thisa = this; + v20 = 0.0; + result = _45CBD4(a3, a4, dword_69B010, &v22); + for ( i = 0; i < v22; result = i ) + { + v6 = a2; + a3a = 0; + v7 = &a3[dword_69B010[i]]; + v8 = v7->vWorldPosition.z; + v9 = v7->vWorldPosition.y; + *(float *)&a5 = v7->vWorldPosition.x; + v19 = v9; + v20 = v8; + v7->flt_2C = 0.0; + if ( a2->field_AC > 0 ) + { + v10 = (char *)a2->_blv_lights_ys; + for ( j = a2->_blv_lights_ys; ; v10 = (char *)j ) + { + v11 = (double)*((signed int *)v10 - 60); + LODWORD(v12) = *((unsigned int *)v10 - 20); + HIDWORD(v12) = *(unsigned int *)v10; + LODWORD(v13) = *((unsigned int *)v10 + 60); + v14 = a3a; + LOBYTE(v14) = v6->_blv_lights_smthngs[a3a]; + v15 = v11; + *(_QWORD *)&v16.x = v12; + v16.z = v13; + v17 = _45CC0C_light(v16/*COERCE_VEC3_FLOAT_(v16.x)*/, 1.0, v15, pNormal, *(float *)&a5/*COERCE_FLOAT(&a5)*/, v14) + + v7->flt_2C; + ++a3a; + ++j; + v7->flt_2C = v17; + if ( a3a >= a2->field_AC ) + break; + v6 = a2; + } + } + ++i; + } + return result; +} + +//----- (0045CB89) -------------------------------------------------------- +int LightmapBuilder::_45CB89(RenderVertexSoft *a1, int a2) +{ + int v3; // edx@1 + int result; // eax@2 + char *v5; // ecx@2 + double v6; // st7@4 + __int16 v7; // fps@4 + char v8; // c0@4 + char v9; // c2@4 + char v10; // c3@4 + double v11; // st7@5 + double v12; // st7@6 + __int16 v13; // fps@6 + char v14; // c0@6 + char v15; // c2@6 + char v16; // c3@6 + + v3 = a2; + if ( a2 > 0 ) + { + HIWORD(result) = HIWORD(a1); + v5 = (char *)&a1->flt_2C; + do + { + if ( *(float *)v5 < 0.0 + || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) ) + { + v12 = *(float *)v5; + //UNDEF(v13); + v14 = 0.0 < v12; + v15 = 0; + v16 = 0.0 == v12; + LOWORD(result) = v13; + if ( v12 >= 0.0 ) + v11 = *(float *)v5; + else + v11 = 0.0; + } + else + { + v11 = 1.0; + } + *(float *)v5 = v11; + v5 += 48; + --v3; + } + while ( v3 ); + } + return result; +} + +//----- (0045CBD4) -------------------------------------------------------- +int LightmapBuilder::_45CBD4(RenderVertexSoft *a2, int a3, int *a4, int *a5) +{ + int result; // eax@1 + int v6; // edx@1 + int v7; // ecx@2 + int v8; // esi@2 + + result = (int)a5; + v6 = 0; + for ( *a5 = 0; v6 < a3; ++v6 ) + { + v7 = *a5; + v8 = 0; + if ( *a5 <= 0 ) + { +LABEL_5: + a4[v7] = v6; + ++*a5; + } + else + { + while ( a4[v8] != v6 ) + { + ++v8; + if ( v8 >= v7 ) + goto LABEL_5; + } + } + } + return result; +} + +//----- (0045CC0C) -------------------------------------------------------- +double LightmapBuilder::_45CC0C_light(Vec3_float_ a1, float a2, float a3, Vec3_float_ *pNormal, float a5, int uLightType) +{ + float v7; // esi@1 + int v8; // eax@1 + int v9; // ebx@1 + unsigned int v10; // ecx@1 + int v11; // edx@2 + int v12; // edx@4 + unsigned int v13; // edx@6 + double v14; // st7@7 + double result; // st7@8 + double v16; // st7@9 + int v17; // esi@9 + const char *v18; // ecx@9 + double v19; // st7@10 + double v20; // st7@10 + std::string v21; // [sp-10h] [bp-40h]@13 + const char *v22[6]; // [sp+0h] [bp-30h]@10 + double v23; // [sp+18h] [bp-18h]@1 + double v24; // [sp+20h] [bp-10h]@1 + int v25; // [sp+28h] [bp-8h]@1 + int v26; // [sp+2Ch] [bp-4h]@1 + + v7 = a5; + LODWORD(a5) = *(unsigned int *)(LODWORD(a5) + 8); + v24 = a5 + 6.7553994e15; + v26 = LODWORD(v24); + LODWORD(a5) = *(unsigned int *)(LODWORD(v7) + 4); + v24 = a5 + 6.7553994e15; + LODWORD(a5) = *(unsigned int *)LODWORD(v7); + v23 = a5 + 6.7553994e15; + *(_QWORD *)((char *)&v24 + 4) = __PAIR__(LODWORD(v24), LODWORD(v23)); + v26 = abs((signed)LODWORD(a1.z) - v26); + v25 = abs((signed)LODWORD(a1.y) - (signed)LODWORD(v24)); + v8 = abs((int)a1.x - (signed)LODWORD(v23)); + LODWORD(a5) = v8; + v9 = v25; + v10 = v26; + if ( v8 < v25 ) + { + v11 = v8; + v8 = v25; + v9 = v11; + } + if ( v8 < v26 ) + { + v12 = v8; + v8 = v26; + v10 = v12; + } + if ( v9 < (signed int)v10 ) + { + v13 = v10; + v10 = v9; + v9 = v13; + } + v14 = (double)(signed int)(((unsigned int)(11 * v9) >> 5) + (v10 >> 2) + v8); + if ( v14 <= a3 ) + { + a5 = v14 / a3; + v16 = (double)(signed int)a1.x; + *(float *)&v23 = (double)SLODWORD(a1.y); + LODWORD(a1.x) = *(unsigned int *)LODWORD(v7); + v17 = LODWORD(v7) + 4; + *((float *)&v23 + 1) = (double)SLODWORD(a1.z); + LODWORD(a1.y) = *(unsigned int *)v17; + LODWORD(a1.z) = *(unsigned int *)(v17 + 4); + a3 = *((float *)&v23 + 1) - a1.z; + a1.z = a3; + a1.x = v16 - a1.x; + a1.y = (float)v23 - a1.y; + a1.Normalize(); + if ( uLightType & 4 ) + { + v22[1] = v18; + uLightType = dword_4D86D8; + v22[0] = v18; + v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x); + v20 = v19 * *(float *)&uLightType * a2; + } + else + { + if ( uLightType & 8 ) + { + v20 = 1.3 * a2; + } + else + { + MessageBoxW(nullptr, L"Invalid light type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:783", 0); + v20 = *(float *)&uLightType; + } + } + result = v20 - a5 * v20; + } + else + { + result = 0.0; + } + return result; +} +// 4D86D8: using guessed type int dword_4D86D8; + +//----- (0045CDB7) -------------------------------------------------------- +bool LightmapBuilder::ApplyLights_OutdoorFace(ODMFace *pFace) +{ + int v2; // esi@1 + int v3; // eax@1 + MobileLight *pMobileLight; // ebx@2 + int v5; // esi@5 + StationaryLight *pStationaryLight; // ebx@6 + bool result; // eax@9 + LightmapBuilder *thisa; // [sp+Ch] [bp-8h]@1 + int pSlot; // [sp+10h] [bp-4h]@1 + + v2 = 0; + thisa = this; + v3 = stru_F8AD28.field_3F8 + pFace->uShadeType; + pSlot = 0; + stru_F8AD28.field_2C = v3 << 16; + if ( uNumMobileLightsApplied > 0 ) + { + pMobileLight = pMobileLights; + do + { + if ( pSlot >= 20 ) + break; + ApplyLight_ODM((StationaryLight *)pMobileLight, pFace, (unsigned int *)&pSlot, 1); + ++v2; + ++pMobileLight; + } + while ( v2 < uNumMobileLightsApplied ); + } + v5 = 0; + if ( uNumStationaryLightsApplied > 0 ) + { + pStationaryLight = pStationaryLights; + do + { + if ( pSlot >= 20 ) + break; + ApplyLight_ODM(pStationaryLight, pFace, (unsigned int *)&pSlot, 0); + ++v5; + ++pStationaryLight; + } + while ( v5 < uNumStationaryLightsApplied ); + } + result = pSlot; + stru_F8AD28.field_AC = pSlot; + LOBYTE(result) = 1; + return result; +} +// 519AB4: using guessed type int uNumStationaryLightsApplied; + +//----- (0045CE50) -------------------------------------------------------- +bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4) +{ + int result; // eax@0 + signed int v6; // ebx@1 + int v7; // ecx@2 + int v8; // esi@4 + int v9; // edx@6 + int v10; // ecx@8 + int v11; // eax@11 + unsigned int v12; // ebx@11 + RenderD3D *v13; // ecx@11 + char v14; // dl@11 + + v6 = pLight->uRadius; + if ( v6 > 0 + && (result = (int)pFace, v7 = pLight->vPosition.x, v7 > pFace->pBoundingBox.x1 - v6) + && v7 < v6 + pFace->pBoundingBox.x2 + && (v8 = pLight->vPosition.y, v8 > pFace->pBoundingBox.y1 - v6) + && v8 < v6 + pFace->pBoundingBox.y2 + && (v9 = pLight->vPosition.z, v9 > pFace->pBoundingBox.z1 - v6) + && v9 < v6 + pFace->pBoundingBox.z2 + && ((v10 = (pFace->pFacePlane.dist + + pLight->vPosition.x * pFace->pFacePlane.vNormal.x + + v8 * pFace->pFacePlane.vNormal.y + + v9 * pFace->pFacePlane.vNormal.z) >> 16, + a4) + || v10 >= 0) + && v10 <= v6 ) + { + stru_F8AD28._blv_lights_radii[*pSlot] = v6; + stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / v6; + stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x; + stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y; + stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z; + stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689; + stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689; + stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689; + v11 = abs(v10); + v12 = pRenderer->bUsingSpecular; + stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = v11; + stru_F8AD28._blv_lights_smthngs[*pSlot] = pLight->field_B; + v13 = pRenderer->pRenderD3D; + v14 = stru_F8AD28._blv_lights_smthngs[*pSlot]; + if ( pRenderer->pRenderD3D && v12 && v14 & 4 ) + v14 = byte_4E94D2; + stru_F8AD28._blv_lights_smthngs[*pSlot] = v14; + result = 4 * *pSlot; + if ( v13 && v12 ) + { + if ( stru_F8AD28._blv_lights_smthngs[*pSlot] & 4 ) + { + *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) + * 0.33000001; + *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result) + * 0.33000001; + *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result) + * 0.33000001; + } + } + ++*pSlot; + LOBYTE(result) = 1; + } + else + { + LOBYTE(result) = 0; + } + return result; +} +// 4E94D2: using guessed type char byte_4E94D2; + +//----- (0045D036) -------------------------------------------------------- +bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X) +{ + int v6; // esi@1 + LightmapBuilder *v7; // edi@1 + MobileLight *v8; // ebx@2 + int v9; // esi@5 + StationaryLight *v10; // ebx@6 + bool result; // eax@9 + unsigned int a7; // [sp+Ch] [bp-4h]@1 + + v6 = 0; + v7 = this; + a7 = 0; + stru_F8AD28.field_2C = pOutdoor->field_CBC_terrain_triangles_shade_type; + if ( uNumMobileLightsApplied > 0 ) + { + v8 = pMobileLights; + do + { + if ( (signed int)a7 >= 20 ) + break; + StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, X, &a7); + ++v6; + ++v8; + } + while ( v6 < uNumMobileLightsApplied ); + } + v9 = 0; + if ( uNumStationaryLightsApplied > 0 ) + { + v10 = pStationaryLights; + do + { + if ( (signed int)a7 >= 20 ) + break; + StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, X, &a7); + ++v9; + ++v10; + } + while ( v9 < uNumStationaryLightsApplied ); + } + result = a7; + stru_F8AD28.field_AC = a7; + LOBYTE(result) = 1; + return result; +} +// 519AB4: using guessed type int uNumStationaryLightsApplied; + +//----- (0045D0D5) -------------------------------------------------------- +bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X, unsigned int *pSlot) +{ + StationaryLight *v8; // edi@1 + bool result; // eax@1 + unsigned int v10; // esi@2 + RenderVertexSoft *v11; // ebx@2 + float v12; // eax@3 + float v13; // eax@4 + double v14; // st7@11 + double maxz; // st7@11 + double v16; // st7@11 + double v17; // st6@11 + __int16 v18; // fps@11 + char v19; // c0@11 + char v20; // c2@11 + char v21; // c3@11 + double v22; // st6@12 + __int16 v23; // fps@12 + char v24; // c0@12 + char v25; // c2@12 + char v26; // c3@12 + double v27; // st7@13 + double v28; // st6@13 + __int16 v29; // fps@13 + char v30; // c0@13 + char v31; // c2@13 + char v32; // c3@13 + double v33; // st6@14 + __int16 v34; // fps@14 + char v35; // c0@14 + char v36; // c2@14 + char v37; // c3@14 + double v38; // st7@15 + double v39; // st6@15 + __int16 v40; // fps@15 + char v41; // c0@15 + char v42; // c2@15 + char v43; // c3@15 + double v44; // st6@16 + __int16 v45; // fps@16 + char v46; // c0@16 + char v47; // c2@16 + char v48; // c3@16 + Vec3_float_ *v49; // esi@17 + double v50; // st7@17 + double v51; // st6@17 + signed int v52; // ecx@17 + unsigned int *v53; // esi@18 + int v54; // eax@18 + unsigned int v55; // ebx@18 + RenderD3D *v56; // ecx@18 + char v57; // dl@18 + std::string v58; // [sp-18h] [bp-38h]@10 + const char *v59; // [sp-8h] [bp-28h]@10 + signed int v60; // [sp-4h] [bp-24h]@10 + double v61; // [sp+Ch] [bp-14h]@11 + float minz; // [sp+14h] [bp-Ch]@11 + int v63; // [sp+18h] [bp-8h]@1 + float v64; // [sp+1Ch] [bp-4h]@5 + + v8 = pLight; + result = pLight->uRadius; + v63 = pLight->uRadius; + if ( result <= 0 ) + goto LABEL_27; + v10 = uStripType; + v11 = a1; + if ( uStripType == 4 ) + { + pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x); + v12 = a1[3].vWorldPosition.x; + } + else + { + if ( uStripType != 3 ) + { + MessageBoxW(nullptr, L"Uknown strip type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:981", 0); + goto LABEL_11; + } + if ( (unsigned char)X ) + { + pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x); + uStripType = LODWORD(a1[2].vWorldPosition.x); + a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y); + v13 = v11[2].vWorldPosition.y; + goto LABEL_5; + } + pLight = (StationaryLight *)LODWORD(a1[1].vWorldPosition.x); + v12 = a1[2].vWorldPosition.x; + } + uStripType = LODWORD(v12); + a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y); + v13 = v11->vWorldPosition.y; +LABEL_5: + v64 = v13; +LABEL_11: + v60 = v10; + v59 = (const char *)v11; + v14 = pGame->pIndoorCameraD3D->GetPolygonMinZ(v11, v10); + v60 = v10; + minz = v14; + maxz = pGame->pIndoorCameraD3D->GetPolygonMaxZ(v11, v10); + result = v8->vPosition.x; + *((float *)&v61 + 1) = maxz; + v16 = (double)result; + *(float *)&X = (double)v63; + v17 = *(float *)&pLight - *(float *)&X; + //UNDEF(v18); + v19 = v16 < v17; + v20 = 0; + v21 = v16 == v17; + BYTE1(result) = HIBYTE(v18); + if ( v16 <= v17 + || (v22 = *(float *)&X + *(float *)&uStripType, + //UNDEF(v23), + v24 = v16 < v22, + v25 = 0, + v26 = v16 == v22, + BYTE1(result) = HIBYTE(v23), + v16 >= v22) + || (result = v8->vPosition.y, + pLight = (StationaryLight *)v8->vPosition.y, + v27 = (double)(signed int)pLight, + v28 = *(float *)&a1 - *(float *)&X, + //UNDEF(v29), + v30 = v27 < v28, + v31 = 0, + v32 = v27 == v28, + BYTE1(result) = HIBYTE(v29), + v27 <= v28) + || (v33 = *(float *)&X + v64, + //UNDEF(v34), + v35 = v27 < v33, + v36 = 0, + v37 = v27 == v33, + BYTE1(result) = HIBYTE(v34), + v27 >= v33) + || (result = v8->vPosition.z, + pLight = (StationaryLight *)v8->vPosition.z, + v38 = (double)(signed int)pLight, + v39 = minz - *(float *)&X, + //UNDEF(v40), + v41 = v38 < v39, + v42 = 0, + v43 = v38 == v39, + BYTE1(result) = HIBYTE(v40), + v38 <= v39) + || (v44 = *(float *)&X + *((float *)&v61 + 1), + //UNDEF(v45), + v46 = v38 < v44, + v47 = 0, + v48 = v38 == v44, + BYTE1(result) = HIBYTE(v45), + v38 >= v44) + || (v49 = pNormal, + Vec3_float_::NegDot(&v11->vWorldPosition, pNormal, a3), + X = v8->vPosition.y, + v50 = (double)X * v49->y, + X = v8->vPosition.z, + v51 = (double)X * v49->z, + X = v8->vPosition.x, + *(float *)&a3 = v50 + v51 + (double)X * v49->x + *a3, + v61 = *(float *)&a3 + 6.7553994e15, + result = LODWORD(v61), + X = LODWORD(v61), + v52 = v63, + SLODWORD(v61) > v63) ) + { +LABEL_27: + LOBYTE(result) = 0; + return result; + } + v53 = pSlot; + v60 = X; + stru_F8AD28._blv_lights_radii[*pSlot] = v63; + stru_F8AD28._blv_lights_inv_radii[*v53] = 65536 / v52; + stru_F8AD28._blv_lights_xs[*v53] = v8->vPosition.x; + stru_F8AD28._blv_lights_ys[*v53] = v8->vPosition.y; + stru_F8AD28._blv_lights_zs[*v53] = v8->vPosition.z; + a3 = (float *)v8->uLightColorR; + stru_F8AD28._blv_lights_rs[*v53] = (double)(signed int)a3 * 0.0039215689; + a3 = (float *)v8->uLightColorG; + stru_F8AD28._blv_lights_gs[*v53] = (double)(signed int)a3 * 0.0039215689; + a3 = (float *)v8->uLightColorB; + stru_F8AD28._blv_lights_bs[*v53] = (double)(signed int)a3 * 0.0039215689; + v54 = abs(v60); + v55 = pRenderer->bUsingSpecular; + stru_F8AD28._blv_lights_light_dot_faces[*v53] = v54; + stru_F8AD28._blv_lights_smthngs[*v53] = v8->field_B; + v56 = pRenderer->pRenderD3D; + v57 = stru_F8AD28._blv_lights_smthngs[*v53]; + if ( pRenderer->pRenderD3D && v55 && v57 & 4 ) + v57 = byte_4E94D2; + stru_F8AD28._blv_lights_smthngs[*v53] = v57; + result = 4 * *v53; + if ( v56 && v55 ) + { + if ( stru_F8AD28._blv_lights_smthngs[*v53] & 4 ) + { + *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) + * 0.33000001; + *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result) + * 0.33000001; + *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result) + * 0.33000001; + } + } + ++*v53; + LOBYTE(result) = 1; + return result; +} +// 4E94D2: using guessed type char byte_4E94D2; + +//----- (0045D3C7) -------------------------------------------------------- +bool LightmapBuilder::_45D3C7(stru148 *a1) +{ + LightmapBuilder *v2; // ebx@1 + stru148 *result; // eax@1 + float v4; // ecx@2 + Span *i; // edi@5 + + v2 = this; + result = (stru148 *)a1->prolly_head; + if ( result && (v4 = result->field_4, *(int *)&v4) != 0 && *(unsigned int *)(LODWORD(v4) + 60) ) + { + for ( i = a1->prolly_head; ; i = i->pNext ) + { + result = i->pParent; + if ( result->field_108 ) + result = (stru148 *)_45D426( + i, + a1->pEdgeList1, + a1->uEdgeList1Size, + (Edge *)a1->pEdgeList2, + a1->uEdgeList2Size); + if ( a1->prolly_tail == i ) + break; + } + LOBYTE(result) = 1; + } + else + { + LOBYTE(result) = 0; + } + return (bool)result; +} + +//----- (0045D426) -------------------------------------------------------- +int LightmapBuilder::_45D426(Span *a1, Edge **a2, unsigned int a3, Edge *a4, int a5) +{ + int v6; // edi@1 + signed int v7; // ebx@3 + signed int v8; // ecx@3 + Span *v9; // esi@3 + double v10; // st7@4 + Edge *v11; // edx@5 + double v12; // st7@11 + int v13; // edx@12 + int v14; // ebx@17 + Edge *v15; // edi@17 + float v16; // ST04_4@17 + float v17; // ST04_4@17 + double v18; // st7@17 + int result; // eax@19 + double v20; // ST14_8@20 + double v21; // ST14_8@20 + double v22; // st7@20 + int v23; // ecx@20 + double v24; // st6@20 + double v25; // st7@23 + double v26; // st7@28 + __int16 v27; // fps@28 + char v28; // c0@28 + char v29; // c2@28 + char v30; // c3@28 + double v31; // st7@29 + double v32; // st7@30 + __int16 v33; // fps@30 + char v34; // c0@30 + char v35; // c2@30 + char v36; // c3@30 + LightmapBuilder *this_4; // [sp+14h] [bp-8h]@1 + signed int v38; // [sp+18h] [bp-4h]@3 + float a1a; // [sp+24h] [bp+8h]@20 + float a2a; // [sp+28h] [bp+Ch]@17 + float a3a; // [sp+2Ch] [bp+10h]@17 + float a5a; // [sp+34h] [bp+18h]@20 + float a5b; // [sp+34h] [bp+18h]@20 + + v6 = 0; + this_4 = this; + if ( a5 && a3 ) + { + v7 = -1; + v8 = 0; + v9 = a1; + v38 = -1; + if ( (signed int)a3 > 0 ) + { + v10 = (double)a1->field_A; + while ( 1 ) + { + v11 = a2[v8]; + if ( v10 >= v11->field_2C ) + { + if ( v10 <= v11->field_30 ) + break; + } + ++v8; + if ( v8 >= (signed int)a3 ) + goto LABEL_10; + } + v38 = v8; + } +LABEL_10: + if ( a5 > 0 ) + { + v12 = (double)a1->field_A; + while ( 1 ) + { + v13 = *((unsigned int *)&a4->field_0 + v6); + if ( v12 >= *(float *)(v13 + 44) ) + { + if ( v12 <= *(float *)(v13 + 48) ) + break; + } + ++v6; + if ( v6 >= a5 ) + goto LABEL_17; + } + v7 = v6; + } +LABEL_17: + v14 = *((unsigned int *)&a4->field_0 + v7); + v15 = a2[v38]; + v16 = (double)a1->field_A; + a3a = _45D643(a2[v38], v16); + v17 = (double)a1->field_A; + v18 = _45D643((Edge *)v14, v17); + a2a = v18; + if ( byte_4D864C && BYTE1(pGame->uFlags) & 0x80 ) + { + HIWORD(result) = HIWORD(a3a); + a1->field_14 = v18; + a1->field_10 = a3a; + } + else + { + a5a = ((double)a1->field_A - v15->field_2C) * v15->field_4 + v15->field_24 - 0.5; + v20 = a5a + 6.7553994e15; + a5b = (double)SLODWORD(v20); + a1a = ((double)a1->field_A - *(float *)(v14 + 44)) * *(float *)(v14 + 4) + *(float *)(v14 + 36) + 0.5; + v21 = a1a + 6.7553994e15; + v22 = (double)SLODWORD(v21); + result = v9->field_8; + v23 = v9->field_C; + v24 = -((a3a - a2a) / (v22 - a5b)); + v9->field_10 = ((double)result - a5b) * v24 + a3a; + v9->field_14 = a2a - (v22 - (double)(result + v23)) * v24; + } + if ( v9->field_10 < 0.0 || v9->field_10 <= 1.0 ) + { + if ( v9->field_10 >= 0.0 ) + v25 = v9->field_10; + else + v25 = 0.0; + } + else + { + v25 = 1.0; + } + v9->field_10 = v25; + if ( v9->field_14 < 0.0 + || (v26 = v9->field_14, + //UNDEF(v27), + v28 = 1.0 < v26, + v29 = 0, + v30 = 1.0 == v26, + BYTE1(result) = HIBYTE(v27), + v26 <= 1.0) ) + { + v32 = v9->field_14; + //UNDEF(v33); + v34 = 0.0 < v32; + v35 = 0; + v36 = 0.0 == v32; + BYTE1(result) = HIBYTE(v33); + if ( v32 >= 0.0 ) + v31 = v9->field_14; + else + v31 = 0.0; + } + else + { + v31 = 1.0; + } + v9->field_14 = v31; + LOBYTE(result) = 1; + } + else + { + LOBYTE(result) = 0; + } + return result; +} +// 4D864C: using guessed type char byte_4D864C; + +//----- (0045D643) -------------------------------------------------------- +double LightmapBuilder::_45D643(Edge *a1, float a2) +{ + double result; // st7@1 + + result = (a1->field_1C - a1->field_20) * -1.0 / (a1->field_30 - a1->field_2C) * (a2 - a1->field_2C) + a1->field_1C; + if ( result < 0.0 || result <= 1.0 ) + { + if ( result < 0.0 ) + result = 0.0; + } + else + { + result = 1.0; + } + return result; +} + +//----- (0045D698) -------------------------------------------------------- +bool LightmapBuilder::DrawDebugOutlines(char bit_one_for_list1__bit_two_for_list2) +{ + bool result; // eax@1 + LightmapBuilder *v3; // esi@1 + RenderVertexSoft *v4; // edi@3 + RenderVertexSoft *v5; // edi@7 + IndoorCameraD3D *thisa; // [sp+10h] [bp-8h]@1 + bool v7; // [sp+14h] [bp-4h]@2 + bool a2a; // [sp+20h] [bp+8h]@6 + + result = (bool)pGame->pIndoorCameraD3D; + v3 = this; + thisa = pGame->pIndoorCameraD3D; + if ( bit_one_for_list1__bit_two_for_list2 & 1 ) + { + v7 = 0; + if ( (signed int)this->std__vector_000004_size > 0 ) + { + v4 = this->std__vector_000004[0].pVertices; + do + { + pGame->pIndoorCameraD3D->debug_outline_sw(v4, *((unsigned int *)v4 - 1), 0xFF00u, 0.0); + ++v7; + v4 = (RenderVertexSoft *)((char *)v4 + 3100); + result = v7; + } + while ( v7 < (signed int)v3->std__vector_000004_size ); + } + } + if ( bit_one_for_list1__bit_two_for_list2 & 2 ) + { + a2a = 0; + if ( (signed int)v3->std__vector_183808_size > 0 ) + { + v5 = v3->std__vector_183808[0].pVertices; + do + { + pGame->pIndoorCameraD3D->debug_outline_sw(v5, *((unsigned int *)v5 - 1), 0xC04000u, 0.00019999999); + ++a2a; + v5 = (RenderVertexSoft *)((char *)v5 + 3100); + result = a2a; + } + while ( a2a < (signed int)v3->std__vector_183808_size ); + } + } + LOBYTE(result) = 1; + return result; +} + +//----- (0045D73F) -------------------------------------------------------- +void LightmapBuilder::DrawLightmaps(int a2) +{ + if ( a2 == 2 ) + DoDrawLightmaps(); +} + +//----- (0045D74F) -------------------------------------------------------- +char LightmapBuilder::_45D74F_MessWithLight(int a2, int *a3) +{ + char v3; // zf@1 + IDirect3DDevice3 *v4; // eax@2 + HRESULT v5; // eax@2 + char *v6; // eax@2 + struct IDirect3DTexture2 *v7; // edi@4 + HRESULT v8; // eax@8 + HRESULT v9; // eax@8 + HRESULT v10; // eax@8 + HRESULT v11; // eax@8 + HRESULT v12; // eax@8 + int *v13; // eax@8 + float v14; // ecx@15 + IDirect3DDevice3 *v15; // eax@21 + HRESULT v16; // eax@21 + IDirect3DDevice3 *v17; // eax@21 + HRESULT v18; // eax@21 + IDirect3DDevice3 *v19; // eax@21 + HRESULT v20; // eax@21 + IDirect3DDevice3 *v21; // eax@21 + HRESULT v22; // eax@21 + IDirect3DDevice3 *v23; // eax@23 + std::string v25; // [sp+44h] [bp-44h]@12 + signed int v26; // [sp+48h] [bp-40h]@21 + signed int v27; // [sp+4Ch] [bp-3Ch]@21 + Lightmap *v28; // [sp+50h] [bp-38h]@2 + int v29; // [sp+54h] [bp-34h]@2 + float v30; // [sp+58h] [bp-30h]@2 + int arg4; // [sp+68h] [bp-20h]@8 + float v32; // [sp+6Ch] [bp-1Ch]@8 + float v33; // [sp+70h] [bp-18h]@8 + int v34; // [sp+74h] [bp-14h]@19 + int v35; // [sp+78h] [bp-10h]@2 + int *v36; // [sp+7Ch] [bp-Ch]@10 + int a1; // [sp+80h] [bp-8h]@12 + float v38; // [sp+84h] [bp-4h]@1 + + v3 = this->std__vector_000004_size == 0; + LODWORD(v38) = (int)this; + if ( !v3 ) + { + v30 = 0.0; + //v4 = pRenderer->pRenderD3D->pDevice; + ErrD3D(v4->SetTextureStageState(0, D3DTSS_ADDRESS, 3u)); + v6 = (char *)stru_69BD44.c_str(); + if ( !stru_69BD44.c_str() ) + v6 = (char *)&dword_4D86F0; + v7 = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr(v6); + if ( pRenderer->bUsingSpecular ) + pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0); + if ( !byte_4D864C || !(pGame->uFlags & 1) ) + { + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v7)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u)); + v13 = a3; + v33 = 1.0; + v32 = 1.0; + *(float *)&arg4 = 1.0; + if ( a3 ) + { + if ( *a3 != -1 ) + { + v36 = a3; + do + { + v28 = (Lightmap *)(3100 * *v13 + LODWORD(v38) + 4); + if ( !DrawLightmap(v28, (Vec3_float_ *)&arg4, 0.0) ) + { + MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1230", 0); + a1 = 5080812; + } + v13 = v36 + 1; + v36 = v13; + } + while ( *v13 != -1 ); + } + } + else + { + v14 = v38; + v36 = 0; + if ( *(unsigned int *)(LODWORD(v38) + 1587204) > 0 ) + { + a1 = LODWORD(v38) + 4; + while ( 1 ) + { + if ( !DrawLightmap((Lightmap *)a1, (Vec3_float_ *)&arg4, 0.0) ) + { + MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1238", 0); + v35 = 5080812; + } + v36 = (int *)((char *)v36 + 1); + a1 += 3100; + if ( (signed int)v36 >= *(unsigned int *)(LODWORD(v38) + 1587204) ) + break; + v14 = v38; + } + } + } + v15 = pRenderer->pRenderD3D->pDevice; + ErrD3D(v15->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u)); + ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u)); + ErrD3D(v15->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0)); + ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u)); + } + if ( pRenderer->bUsingSpecular ) + { + //LODWORD(v30) = 1; + //v29 = 28; + //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; + pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1); + v30 = pRenderer->uFogColor; + v23 = pRenderer->pRenderD3D->pDevice; + //v29 = 34; + //v28 = (Lightmap *)v23; + v23->SetRenderState(D3DRENDERSTATE_FOGCOLOR, LODWORD(pRenderer->uFogColor)); + //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; + pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, false); + } + } + return 1; +} +// 4D864C: using guessed type char byte_4D864C; +// 4D86F0: using guessed type int dword_4D86F0; + +//----- (0045DA56) -------------------------------------------------------- +bool LightmapBuilder::DrawLightmaps2(float a2) +{ + LightmapBuilder *v2; // esi@1 + bool result; // eax@1 + signed int v4; // edi@2 + std::string v5; // [sp-14h] [bp-3Ch]@5 + const char *v6; // [sp-4h] [bp-2Ch]@5 + int v7; // [sp+0h] [bp-28h]@5 + Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2 + std::string *v9; // [sp+18h] [bp-10h]@5 + unsigned int v10; // [sp+1Ch] [bp-Ch]@5 + Lightmap *a1; // [sp+20h] [bp-8h]@3 + int a3; // [sp+27h] [bp-1h]@5 + + v2 = this; + result = this->std__vector_183808_size; + if ( result ) + { + v4 = 0; + v.z = 1.0; + v.y = 1.0; + v.x = 1.0; + if ( result > 0 ) + { + a1 = this->std__vector_183808; + do + { + result = DrawLightmap(a1, &v, a2); + if ( !result ) + { + MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1288", 0); + v10 = 0x4D86ECu; + } + ++a1; + ++v4; + } + while ( v4 < (signed int)v2->std__vector_183808_size); + } + } + LOBYTE(result) = 1; + return result; +} + +//----- (0045DAE8) -------------------------------------------------------- +bool LightmapBuilder::DrawLightmap(Lightmap *a1, Vec3_float_ *arg4, float thisa) +{ + Lightmap *v4; // edx@1 + bool result; // eax@2 + double v6; // st7@3 + Vec3_float_ *v7; // ecx@3 + LEVEL_TYPE v8; // edi@3 + int v9; // esi@3 + double v10; // st7@4 + unsigned int v11; // ebx@6 + char *v12; // ecx@7 + int v13; // edx@7 + double v14; // st7@7 + __int16 v15; // fps@8 + unsigned __int8 v16; // c2@8 + unsigned __int8 v17; // c3@8 + double v18; // st3@8 + int v19; // eax@11 + double v20; // st3@11 + int v21; // eax@11 + char v22; // zf@11 + HRESULT v23; // eax@15 + signed int v24; // [sp-1Ch] [bp-670h]@13 + const char *v25; // [sp-18h] [bp-66Ch]@13 + int v26; // [sp-14h] [bp-668h]@13 + HRESULT a2; // [sp+0h] [bp-654h]@15 + char v28; // [sp+4h] [bp-650h]@7 + double v29; // [sp+640h] [bp-14h]@3 + __int64 v30; // [sp+648h] [bp-Ch]@3 + float v31; // [sp+650h] [bp-4h]@3 + signed int a1b; // [sp+65Ch] [bp+8h]@3 + float a1c; // [sp+65Ch] [bp+8h]@3 + float a1d; // [sp+65Ch] [bp+8h]@3 + float a1e; // [sp+65Ch] [bp+8h]@3 + unsigned int a1a; // [sp+65Ch] [bp+8h]@7 + int arg4a; // [sp+660h] [bp+Ch]@3 + + v4 = a1; + if ( (signed int)a1->uNumVertices >= 3 ) + { + v6 = (double)BYTE1(a1->field_C10) * a1->flt_C14; + v30 = a1->field_C10 & 0xFFi64; + a1b = BYTE2(a1->field_C10); + v7 = arg4; + v31 = v6; + *((float *)&v30 + 1) = (double)v30 * v4->flt_C14; + a1c = (double)a1b * v4->flt_C14 * arg4->x; + v29 = a1c + 6.7553994e15; + arg4a = LODWORD(v29); + a1d = v31 * v7->y; + v29 = a1d + 6.7553994e15; + LODWORD(v31) = LODWORD(v29); + a1e = *((float *)&v30 + 1) * v7->z; + v29 = a1e + 6.7553994e15; + HIDWORD(v30) = LODWORD(v29); + v8 = uCurrentlyLoadedLevelType; + v9 = LODWORD(v29) | ((LODWORD(v31) | (arg4a << 8)) << 8); + if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor) + v10 = (double)pOutdoorCamera->shading_dist_mist; + else + v10 = 16192.0; + v11 = v4->uNumVertices; + if ( (signed int)v11 > 0 ) + { + v12 = &v28; + v13 = (int)&v4->pVertices[0].vWorldViewPosition; + v14 = 1.0 / v10; + a1a = v11; + do + { + //UNDEF(v15); + v18 = 1.0 - 1.0 / (v14 * *(float *)v13 * 1000.0); + if ( !(v17 | v16) ) + { + v18 = v18 - thisa; + if ( v18 < 0.000099999997 ) + v18 = 0.000099999997; + } + *((float *)v12 + 1) = v18; + v19 = *(unsigned int *)(v13 + 12); + *((unsigned int *)v12 + 4) = 0; + v20 = 1.0 / *(float *)v13; + *((unsigned int *)v12 - 1) = v19; + *(unsigned int *)v12 = *(unsigned int *)(v13 + 16); + *((unsigned int *)v12 + 5) = *(unsigned int *)(v13 + 24); + v21 = *(unsigned int *)(v13 + 28); + *((unsigned int *)v12 + 3) = v9; + *((unsigned int *)v12 + 6) = v21; + v13 += 48; + v12 += 32; + v22 = a1a-- == 1; + *((float *)v12 - 6) = v20; + } + while ( !v22 ); + } + if ( v8 == 1 ) + { + v26 = 1346; + v25 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp"; + v24 = 28; + } + else + { + v26 = 1354; + v25 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp"; + v24 = 16; + } + v23 = pRenderer->pRenderD3D->pDevice->DrawPrimitive( + D3DPT_TRIANGLEFAN, + 452, + &a2, + v11, + v24); + //CheckHRESULT((CheckHRESULT_stru0 *)&thisa, v23, v25, v26, 0); + LOBYTE(result) = 1; + } + else + { + LOBYTE(result) = 0; + } + return result; +} + +//----- (0045DCA9) -------------------------------------------------------- +void LightmapBuilder::DoDrawLightmaps() +{ + const char *v1; // ebx@0 + int v2; // ebp@0 + int v3; // edi@0 + int v4; // esi@0 + HRESULT v5; // eax@4 + HRESULT v6; // eax@4 + HRESULT v7; // eax@4 + char *v8; // eax@4 + //IDirect3DDevice3Vtbl *v9; // ebp@6 + struct IDirect3DTexture2 *v10; // ST90_4@6 + //IDirect3DDevice3 *v11; // ST88_4@6 + HRESULT v12; // eax@6 + HRESULT v13; // eax@6 + HRESULT v14; // eax@6 + HRESULT v15; // eax@6 + HRESULT v16; // eax@6 + HRESULT v17; // eax@6 + HRESULT v18; // eax@6 + HRESULT v19; // eax@6 + LightmapBuilder *v20; // [sp+98h] [bp-8h]@1 + LightmapBuilder *v21; // [sp+9Ch] [bp-4h]@1 + LightmapBuilder *thisa; // [sp+A4h] [bp+4h]@0 + //CheckHRESULT_stru0 a8; // [sp+A8h] [bp+8h]@0 + //CheckHRESULT_stru0 thisaa; // [sp+B4h] [bp+14h]@0 + + v21 = this; + v20 = this; + if ( this->std__vector_183808_size ) + { + if ( pRenderer->bUsingSpecular ) + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0)); + + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0)); + + v8 = (char *)stru_69BD44.c_str(); + if ( !stru_69BD44.size() ) + v8 = (char *)&dword_4D86F0; + //v9 = pRenderer->pRenderD3D->pDevice->lpVtbl; + v10 = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr(v8); + //v11 = pRenderer->pRenderD3D->pDevice; + ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v10)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u)); + + DrawLightmaps2(0.00050000002); + + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u)); + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2)); + if ( pRenderer->bUsingSpecular ) + ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u)); + } +} \ No newline at end of file