Mercurial > might-and-magic-trilogy
diff LightmapBuilder.cpp @ 59:5159d2e6f559
BLV render
author | Nomad |
---|---|
date | Fri, 26 Oct 2012 02:38:26 +0200 |
parents | fde5c5acb66e |
children | fdacbc653945 |
line wrap: on
line diff
--- a/LightmapBuilder.cpp Thu Oct 25 02:05:16 2012 +0200 +++ b/LightmapBuilder.cpp Fri Oct 26 02:38:26 2012 +0200 @@ -13,11 +13,11 @@ LightsStack_StationaryLight_ *pStationaryLightsStack = new LightsStack_StationaryLight_; -StationaryLight pStationaryLights[400]; -int uNumStationaryLightsApplied; // weak +//StationaryLight pStationaryLights[400]; +//int uNumStationaryLightsApplied; // weak LightsStack_MobileLight_ *pMobileLightsStack = new LightsStack_MobileLight_; -MobileLight pMobileLights[400]; -int uNumMobileLightsApplied; +//MobileLight pMobileLights[400]; +//int uNumMobileLightsApplied; @@ -36,11 +36,6 @@ //----- (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; } @@ -48,186 +43,103 @@ //----- (0045BC07) -------------------------------------------------------- -char LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, IndoorCameraD3D_Vec4 *a6, char a7) +bool LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, IndoorCameraD3D_Vec4 *a6, char uClipFlag) { - 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 + Vec3_int_ pos; // [sp+2Ch] [bp-40h]@21 + RenderVertexSoft *a9; // [sp+68h] [bp-4h]@8 + + if (!uNumVertices) + return false; + + static RenderVertexSoft static_69B140[64]; - thisa = this; - if ( !uNumVertices ) - return 0; + a9 = a5; + if (a6) + { + for (uint i = 0; i < uNumVertices; ++i) + memcpy(static_69B140 + i, a5 + i, sizeof(RenderVertexSoft)); - 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; + __debugbreak(); + if (pGame->pIndoorCameraD3D->_437376( + a3, + static_69B140, + &uNumVertices) == 1) + { + if ( !uNumVertices ) + return false; + a9 = static_69B140; + } } - a9 = (int)a5; - if ( !a6) - { - 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) ) + static stru314 static_69B110; + static_69B110.field_4.x = a3->face_plane.vNormal.x; + static_69B110.field_4.y = a3->face_plane.vNormal.y; + static_69B110.field_4.z = a3->face_plane.vNormal.z; + static_69B110.dist = a3->face_plane.dist; + if (!pGame->pIndoorCameraD3D->GetFacetOrientation( + a3->polygonType, + &static_69B110.field_4, + &static_69B110.field_10, + &static_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 ) + + for (uint i = 0; i < a2->uNumLightsApplied; ++i) { - v19 = a2->_blv_lights_ys; - do + pos.x = a2->_blv_lights_xs[i]; + pos.y = a2->_blv_lights_ys[i]; + pos.z = a2->_blv_lights_zs[i]; + + uint uColorR = (uint)floorf(a2->_blv_lights_rs[i] * 255.0 + 0.5f) & 0xFF, + uColorG = (uint)floorf(a2->_blv_lights_gs[i] * 255.0 + 0.5f) & 0xFF, + uColorB = (uint)floorf(a2->_blv_lights_bs[i] * 255.0 + 0.5f) & 0xFF; + uint uColor = (uColorR << 16) | (uColorG << 8) | uColorB; + if (!uColor) + uColor = 0x00FFFFF; + + if (!_45BE86_build_light_polygon( + &pos, + a2->_blv_lights_radii[i], + uColor, + a2->_blv_lights_light_dot_faces[i], + a2->_blv_lights_types[i], + &static_69B110, + uNumVertices, + a9, + uClipFlag) ) { - v20 = *((float *)v19 + 80) * 255.0; - arg0 = *(v19 - 20); - v29 = *v19; - v30 = v19[60]; - v21 = *(v19 - 60); - //a6 = v20; - v36 = v21; - v37 = v19[20]; - auto _a6_1 = floorf(v20 + 0.5f); - //v33 = a6 + 6.7553994e15; - auto _a6_2 = *((float *)v19 + 100) * 255.0; - //v32 = a6 + 6.7553994e15; - auto _a6_3 = *((float *)v19 + 120) * 255.0; - //v31 = a6 + 6.7553994e15; - //v38 = __PAIR__(LODWORD(v32), LODWORD(v31)); - v38 = __PAIR__((int)floorf(_a6_2 + 0.5f), (int)floorf(_a6_3 + 0.5f)); - //v22 = LODWORD(v31) | ((LODWORD(v32) | (LODWORD(v33) << 8)) << 8); - v22 = (int)floorf(_a6_3 + 0.5f) | (((int)floorf(_a6_2 + 0.5f) | ((int)floorf(_a6_1 + 0.5f) << 8)) << 8); - if (!v22) - v22 = 0x00FFFFFF; - 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; + MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0); } - while ( (signed int)a5 < a2->field_AC ); } - return 1; + return true; } //----- (0045BE86) -------------------------------------------------------- -char LightmapBuilder::_45BE86_build_light_polygon(int arg0, float a4, unsigned int uColorMask, float a5, int uLightType, stru314 *a7, signed int a2, RenderVertexSoft *a9, char uClipFlag) +bool LightmapBuilder::_45BE86_build_light_polygon(Vec3_int_ *pos, float radius, unsigned int uColorMask, float dot_dist, int uLightType, stru314 *a7, signed int a2, RenderVertexSoft *a9, char uClipFlag) { - LightmapBuilder *v10; // esi@1 + //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 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 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 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 @@ -238,156 +150,186 @@ 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 + //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 + //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 + //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 + //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; + //auto a4 = radius; + //auto a5 = dot_dist; + + //v10 = this; + if (fabsf(radius) < 1e-6f) + return true; + + //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_lightmaps_brightness = 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_lightmaps_brightness; - 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; + //v12 = radius - dot_dist; + flt_3C8C24 = radius - dot_dist; + //v13 = sqrt((radius + dot_dist) * (radius - dot_dist)); + flt_3C8C28 = sqrt((radius + dot_dist) * (radius - dot_dist)); + //v14 = a7; + //v66 = 1.0 / radius; + flt_3C8C2C_lightmaps_brightness = 1.0 - (radius - flt_3C8C28) / radius; + v11->field_C08 = (double)pos->x - dot_dist * a7->field_4.x; + v11->field_C0A = (double)pos->y - dot_dist * a7->field_4.y; + v11->field_C0C = (double)pos->z - dot_dist * a7->field_4.z; + //v15 = a4; + //pLightmapVertices = v11->pVertices; + v17 = radius * flt_3C8C2C_lightmaps_brightness; + //pLightmapVertices_ = (int)v11->pVertices; + flt_3C8C30 = v17; + flt_3C8C0C = v17 * a7->field_10.x; + flt_3C8C10 = v17 * a7->field_10.y; + flt_3C8C14 = v17 * a7->field_10.z; + flt_3C8C18 = v17 * a7->field_1C.x; + flt_3C8C1C = v17 * a7->field_1C.y; + flt_3C8C20 = v17 * a7->field_1C.z; + //LODWORD(a5) = v11->field_C08; + //v18 = (double)SLODWORD(a5); + //LODWORD(a5) = v11->field_C0A; + //v19 = (char *)&v11->pVertices[0].vWorldPosition.y; + //v20 = (double)SLODWORD(a5); + //v21 = v11->field_C0A - flt_3C8C1C; + //LODWORD(a5) = v11->field_C0C; + //v22 = 4; + //v23 = (double)SLODWORD(a5); + //a5 = v23; + + + /* + v11->pVertices[0].vWorldPosition.x = v11->field_C08 - flt_3C8C18 + flt_3C8C0C; + v11->pVertices[0].vWorldPosition.y = v11->field_C0A - flt_3C8C1C + flt_3C8C10; + v11->pVertices[0].vWorldPosition.z = v11->field_C0C - flt_3C8C20 + 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].vWorldPosition.x = v11->field_C08 - flt_3C8C18 - flt_3C8C0C; + v11->pVertices[1].vWorldPosition.y = v11->field_C0A - flt_3C8C1C - flt_3C8C10; + v11->pVertices[1].vWorldPosition.z = v11->field_C0C - flt_3C8C20 - 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].vWorldPosition.x = v11->field_C08 + flt_3C8C18 - flt_3C8C0C; + v11->pVertices[2].vWorldPosition.y = v11->field_C0A + flt_3C8C1C - flt_3C8C10; + v11->pVertices[2].vWorldPosition.z = v11->field_C0C + flt_3C8C20 - 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].vWorldPosition.x = v11->field_C08 + flt_3C8C18 + flt_3C8C0C; + v11->pVertices[3].vWorldPosition.y = v11->field_C0A + flt_3C8C1C + flt_3C8C10; + v11->pVertices[3].vWorldPosition.z = v11->field_C0C + flt_3C8C20 + flt_3C8C14; v11->pVertices[3].u = 1.0; v11->pVertices[3].v = 0.0; - do + */ + //v19 = (char *)&v11->pVertices[0].vWorldPosition.y; + for (uint i = 0; i < 4; ++i) { - 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; + v11->pVertices[i].vWorldPosition.x = v11->field_C08 - flt_3C8C18 + flt_3C8C0C; + v11->pVertices[i].vWorldPosition.y = v11->field_C0A - flt_3C8C1C + flt_3C8C10; + v11->pVertices[i].vWorldPosition.z = v11->field_C0C - flt_3C8C20 + flt_3C8C14; + v11->pVertices[i].u = 0.0; + v11->pVertices[i].v = 0.0; + + v24 = a7->field_4.y * v11->pVertices[i].vWorldPosition.y + + a7->field_4.z * v11->pVertices[i].vWorldPosition.z + + a7->field_4.x * v11->pVertices[i].vWorldPosition.x + + a7->dist; + + v11->pVertices[i].vWorldPosition.x -= v24 * a7->field_4.x; + v11->pVertices[i].vWorldPosition.y -= v24 * a7->field_4.y; + v11->pVertices[i].vWorldPosition.z -= v24 * a7->field_4.z; + //v19 += 48; + //--v22; } - while ( v22 ); + //while ( v22 ); + v11->uColorMask = uColorMask; v11->uNumVertices = 4; - if ( pGame->uFlags2 & 4 ) + + if (~pGame->uFlags2 & 4) + v11->fBrightness = flt_3C8C2C_lightmaps_brightness; + else { - LODWORD(a5) = v11->field_C0C; - v25 = arg0; - v26 = (double)SLODWORD(a5); - LODWORD(a5) = v11->field_C0A; - v27 = v11->field_C08; - a5 = (double)SLODWORD(a5); - uColorMask = v27; - v28 = (double)v27; - v61 = a5; - v60 = v28; - v62 = v26; - *(float *)&uColorMask = (double)*(signed int *)(arg0 + 8); - arg0b = (double)*(signed int *)(arg0 + 4); - v29 = (double)*(signed int *)v25 - v28; - v30 = arg0b - a5; - a5 = *(float *)&uColorMask - v26; - a1.x = v29; - a1.z = a5; - a1.y = v30; + //LODWORD(a5) = v11->field_C0C; + //v25 = pos; + //v26 = v11->field_C0C; + //LODWORD(a5) = v11->field_C0A; + //v27 = v11->field_C08; + //a5 = v11->field_C0A; + //uColorMask = v27; + //v28 = (double)v27; + //v61 = a5; + //v60 = v27; + //v62 = v26; + //*(float *)&uColorMask = (double)pos->z; + //arg0b = (double)pos->y; + //v29 = (double)pos->x - v11->field_C08; + //v30 = (double)pos->y - v11->field_C0A; + //a5 = (double)pos->z - v11->field_C0C; + Vec3_float_ a1; // [sp+2Ch] [bp-20h]@8 + a1.x = (double)pos->x - v11->field_C08; + a1.y = (double)pos->y - v11->field_C0A; + a1.z = (double)pos->z - v11->field_C0C; a1.Normalize(); //v64 = v62 + 6.7553994e15; //LODWORD(a5) = LODWORD(v64); - LODWORD(a5) = floorf(v62 + 0.5f); + //LODWORD(a5) = floorf(v11->field_C0C + 0.5f); //v64 = v61 + 6.7553994e15; //arg0c = LODWORD(v64); - arg0c = floorf(v61 + 0.5f); + //arg0c = floorf(v11->field_C0A + 0.5f); //v64 = v60 + 6.7553994e15; //arg8 = LODWORD(v64); - uColorMask = floorf(v60 + 0.5f); - auto v64 /*HIDWORD(v64)*/ = abs(*(int *)(v25 + 8) - (signed)LODWORD(a5)); - arg0a = abs(*(int *)(v25 + 4) - arg0c); - v31 = abs(*(int *)v25 - (int)uColorMask); - LODWORD(a5) = v31; - v32 = arg0a; - v33 = v64;//HIDWORD(v64); - if ( v31 < arg0a ) + //uColorMask = floorf(v11->field_C08 + 0.5f); + //auto _v64 /*HIDWORD(v64)*/ = abs(pos->z - v11->field_C0C); + //arg0a = abs(pos->y - v11->field_C0A); + //v31 = abs(pos->x - v11->field_C08); + //LODWORD(a5) = v31; + //v32 = arg0a; + //v33 = _v64;//HIDWORD(v64); + auto dist_x = abs(pos->x - v11->field_C08), //v31 + dist_y = abs(pos->y - v11->field_C0A), //v32 arg0a + dist_z = abs(pos->z - v11->field_C0C); //v33 _v64 + v31 = dist_x; + v32 = dist_y; + v33 = dist_z; + if (v31 < dist_y) { v34 = v31; - v31 = arg0a; + v31 = dist_y; v32 = v34; } - if ( v31 < v64)//SHIDWORD(v64) ) + if (v31 < dist_z)//SHIDWORD(v64) ) { v35 = v31; - v31 = v64;//HIDWORD(v64); + v31 = dist_z;//HIDWORD(v64); v33 = v35; } if ( v32 < (signed int)v33 ) @@ -397,118 +339,123 @@ 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; + //LODWORD(a5) = ((unsigned int)(11 * v32) >> 5) + v37 + v31; + v38 = (double)(signed)(((unsigned int)(11 * v32) >> 5) + v37 + v31); + if (v38 > radius) + return true; + //radius = (1 / radius) * v38; if ( uLightType & 4 ) { - v59 = (void *)v37; - uLightType = dword_4D86CC; - v58 = v37; + //v59 = (void *)v37; + //uLightType = flt_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; + v40 = v39 * 1.0 * flt_4D86CC; + + v11->fBrightness = v40 - (1 / radius) * v38 * v40; + } + else if ( uLightType & 8 ) + { + v40 = 1.0 * 1.0; + v11->fBrightness = v40 - (1 / radius) * v38; } 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->fBrightness = v40 - a4 * v40; - } - else - { - v11->fBrightness = v10->flt_3C8C2C_lightmaps_brightness; + //v14 = a7; + //pLightmapVertices = (RenderVertexSoft *)pLightmapVertices_; } - 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); + + + //v41 = a7->field_4.z; + //v42 = pGame->pStru9Instance; + //v59 = &v11->uNumVertices; + //v58 = (unsigned int)pLightmapVertices; + //*(float *)&v57 = v41; + //v56 = a7->field_4.y; + //v55 = a7->field_4.x; + //result = v42->_4980B9(a9, a2, v55, v56, *(float *)&v57, pLightmapVertices, &v11->uNumVertices); + if (pGame->pStru9Instance->_4980B9(a9, a2, + a7->field_4.x, a7->field_4.y, a7->field_4.z, + v11->pVertices, &v11->uNumVertices)) + return false; + + //v44 = &v11->uNumVertices; + if (!v11->uNumVertices) + return true; + + v45 = _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); + _45C4B9(a2, a9, v11); + //v59 = v11->uNumVertices; + //v46 = (RenderVertexSoft *)pLightmapVertices_; + pGame->pIndoorCameraD3D->ViewTransform(v11->pVertices, v11->uNumVertices); + //v59 = 0; + //v58 = v11->uNumVertices; + pGame->pIndoorCameraD3D->Project(v11->pVertices, v11->uNumVertices, 0); + + unsigned int _a4 = 0; if ( !(uClipFlag & 1) ) - goto LABEL_38; - if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor) + _a4 = 1; + else 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; + //v59 = &a4; + //v58 = (unsigned int)field_3C8C34; + //v57 = *v44; + pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(v11->pVertices, v11->uNumVertices, field_3C8C34, &_a4); + + //v59 = v44; + //v58 = (unsigned int)field_3C8C34; + //v57 = (int)v46; + //v56 = a4; + pGame->pIndoorCameraD3D->_437143(_a4, v11->pVertices, field_3C8C34, &v11->uNumVertices); } - if ( uClipFlag & 4 ) + else 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; + //v59 = &a4; + //v58 = (unsigned int)field_3C8C34; + //v57 = *v44; + pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(v11->pVertices, v11->uNumVertices, field_3C8C34, &_a4); + + //v59 = v44; + //v58 = (unsigned int)field_3C8C34; + //v57 = (int)v46; + //v56 = a4; + pGame->pIndoorCameraD3D->_437143(_a4, v11->pVertices, field_3C8C34, &v11->uNumVertices); } - v58 = (unsigned int)"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330"; - v52 = "Undefined clip flag specified"; + else + MessageBoxW(nullptr, L"Undefined clip flag specified", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330", 0); } 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 ) + MessageBoxW(nullptr, L"Lightpoly builder native indoor clipping not implemented", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:335", 0); + + if (_a4) { -LABEL_38: - if ( v67 ) + if (uLightType & 1) { - v48 = (char *)&v10->std__vector_000004_size; - v49 = *(unsigned int *)v48; - v51 = __OFSUB__(*(unsigned int *)v48, 511); - v50 = *(unsigned int *)v48 - 511 < 0; + //v48 = (char *)&std__vector_000004_size; + //v49 = std__vector_000004_size; + //v51 = __OFSUB__(std__vector_000004_size, 511); + //v50 = std__vector_000004_size - 511 < 0; + if (std__vector_000004_size < 512 - 1) + ++std__vector_000004_size; } else { - v48 = (char *)&v10->std__vector_183808_size; - v49 = *(unsigned int *)v48; - v51 = __OFSUB__(*(unsigned int *)v48, 767); - v50 = *(unsigned int *)v48 - 767 < 0; + //v48 = (char *)&std__vector_183808_size; + //v49 = std__vector_183808_size; + //v51 = __OFSUB__(std__vector_183808_size, 767); + //v50 = std__vector_183808_size - 767 < 0; + if (std__vector_183808_size < 768 - 1) + ++std__vector_183808_size; } - if ( v50 ^ v51 ) - *(unsigned int *)v48 = v49 + 1; + //if ( v50 ^ v51 ) + // *(unsigned int *)v48 = v49 + 1; } - return 1; + return true; } //----- (0045C4B9) -------------------------------------------------------- @@ -726,139 +673,82 @@ //----- (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 + auto pFace = &pIndoor->pFaces[uFaceID]; + auto pSector = pIndoor->pSectors + pFace->uSectorID; + + stru_F8AD28.uCurrentAmbientLightLevel = (stru_F8AD28.uDefaultAmbientLightLevel + pSector->uMinAmbientLightLevel) << 16; - 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 ) + uint uNumLightsApplied = 0; + for (uint i = 0; i < pMobileLightsStack->uNumLightsActive; ++i) + { + if (uNumLightsApplied >= 20) + break; + + ApplyLight_BLV((StationaryLight *)(pMobileLightsStack->pLights + i), pFace, &uNumLightsApplied, true, 0); + } + + for (uint i = 0; i < pSector->uNumLights; ++i) { - 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 ) + if (uNumLightsApplied >= 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); + + auto pLight = &pIndoor->pLights[pSector->pLights[i]]; + if (~pLight->uAtributes & 0x08) + ApplyLight_BLV((StationaryLight *)pLight, pFace, &uFaceID, false, &byte_4E94D0); } - v7 = 0; - if ( uNumStationaryLightsApplied > 0 ) + + for (uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i) { - pStationaryLight = pStationaryLights; - do - { - if ( (signed int)uFaceID >= 20 ) - break; - ApplyLight_BLV(pStationaryLight, pFace, &uFaceID, 0, (int)&byte_4E94D0); - ++pStationaryLight; - ++v7; - } - while ( v7 < uNumStationaryLightsApplied ); + if (uNumLightsApplied >= 20) + break; + + ApplyLight_BLV(pStationaryLightsStack->pLights + i, pFace, &uNumLightsApplied, false, &byte_4E94D0); } - result = uFaceID; - stru_F8AD28.field_AC = uFaceID; - LOBYTE(result) = 1; - return result; + + stru_F8AD28.uNumLightsApplied = uNumLightsApplied; + return true; } -// 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) +bool LightmapBuilder::ApplyLight_BLV(StationaryLight *pLight, BLVFace *a2, unsigned int *pSlot, bool bLightBackfaces, char *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 + + if (!pLight->uRadius) + return false; - 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) ) + if (pLight->vPosition.x > a2->pBounding.x1 - pLight->uRadius && + pLight->vPosition.x < a2->pBounding.x2 + pLight->uRadius && + pLight->vPosition.y > a2->pBounding.y1 - pLight->uRadius && + pLight->vPosition.y < a2->pBounding.y2 + pLight->uRadius && + pLight->vPosition.z > a2->pBounding.z1 - pLight->uRadius && + pLight->vPosition.z < a2->pBounding.z2 + pLight->uRadius) { - 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((int)floorf(v13 + 0.5f));//COERCE_UNSIGNED_INT64(pLighta + 6.7553994e15)); - result = (BLVFace *)*pSlot; - stru_F8AD28._blv_lights_smthngs[(*pSlot)++] = v7->field_B; - LOBYTE(result) = 1; + v13 = (double)pLight->vPosition.z * a2->pFacePlane.vNormal.z + + (double)pLight->vPosition.y * a2->pFacePlane.vNormal.y + + (double)pLight->vPosition.x * a2->pFacePlane.vNormal.x + + a2->pFacePlane.dist; + if ((bLightBackfaces || v13 >= 0.0f) && fabsf(v13) <= pLight->uRadius) + { + auto slot = *pSlot; + + stru_F8AD28._blv_lights_radii[slot] = pLight->uRadius; + stru_F8AD28._blv_lights_inv_radii[slot] = 65536 / pLight->uRadius; + stru_F8AD28._blv_lights_xs[slot] = pLight->vPosition.x; + stru_F8AD28._blv_lights_ys[slot] = pLight->vPosition.y; + stru_F8AD28._blv_lights_zs[slot] = pLight->vPosition.z; + stru_F8AD28._blv_lights_rs[slot] = (double)pLight->uLightColorR / 255.0f; + stru_F8AD28._blv_lights_gs[slot] = (double)pLight->uLightColorG / 255.0f; + stru_F8AD28._blv_lights_bs[slot] = (double)pLight->uLightColorB / 255.0f; + stru_F8AD28._blv_lights_light_dot_faces[slot] = abs((int)floorf(v13 + 0.5f)); + stru_F8AD28._blv_lights_types[slot] = pLight->uLightType; + + *pSlot += 1; + return true; + } } - else - { - LOBYTE(result) = 0; - } - return (bool)result; + + return false; } //----- (0045CA88) -------------------------------------------------------- @@ -902,7 +792,7 @@ v19 = v9; v20 = v8; v7->flt_2C = 0.0; - if ( a2->field_AC > 0 ) + if ( a2->uNumLightsApplied > 0 ) { v10 = (char *)a2->_blv_lights_ys; for ( j = a2->_blv_lights_ys; ; v10 = (char *)j ) @@ -912,7 +802,7 @@ HIDWORD(v12) = *(unsigned int *)v10; LODWORD(v13) = *((unsigned int *)v10 + 60); v14 = a3a; - LOBYTE(v14) = v6->_blv_lights_smthngs[a3a]; + LOBYTE(v14) = v6->_blv_lights_types[a3a]; v15 = v11; *(_QWORD *)&v16.x = v12; v16.z = v13; @@ -921,7 +811,7 @@ ++a3a; ++j; v7->flt_2C = v17; - if ( a3a >= a2->field_AC ) + if ( a3a >= a2->uNumLightsApplied ) break; v6 = a2; } @@ -1137,12 +1027,12 @@ v2 = 0; thisa = this; - v3 = stru_F8AD28.field_3F8 + pFace->uShadeType; + v3 = stru_F8AD28.uDefaultAmbientLightLevel + pFace->uShadeType; pSlot = 0; - stru_F8AD28.field_2C = v3 << 16; - if ( uNumMobileLightsApplied > 0 ) + stru_F8AD28.uCurrentAmbientLightLevel = v3 << 16; + if ( pMobileLightsStack->uNumLightsActive > 0 ) { - pMobileLight = pMobileLights; + pMobileLight = pMobileLightsStack->pLights; do { if ( pSlot >= 20 ) @@ -1151,12 +1041,12 @@ ++v2; ++pMobileLight; } - while ( v2 < uNumMobileLightsApplied ); + while ( v2 < pMobileLightsStack->uNumLightsActive ); } v5 = 0; - if ( uNumStationaryLightsApplied > 0 ) + if ( pStationaryLightsStack->uNumLightsActive > 0 ) { - pStationaryLight = pStationaryLights; + pStationaryLight = pStationaryLightsStack->pLights; do { if ( pSlot >= 20 ) @@ -1165,14 +1055,12 @@ ++v5; ++pStationaryLight; } - while ( v5 < uNumStationaryLightsApplied ); + while ( v5 < pStationaryLightsStack->uNumLightsActive ); } result = pSlot; - stru_F8AD28.field_AC = pSlot; - LOBYTE(result) = 1; - return result; + stru_F8AD28.uNumLightsApplied = pSlot; + return true; } -// 519AB4: using guessed type int uNumStationaryLightsApplied; //----- (0045CE50) -------------------------------------------------------- bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4) @@ -1188,6 +1076,8 @@ RenderD3D *v13; // ecx@11 char v14; // dl@11 + __debugbreak(); + v6 = pLight->uRadius; if ( v6 > 0 && (result = (int)pFace, v7 = pLight->vPosition.x, v7 > pFace->pBoundingBox.x1 - v6) @@ -1215,16 +1105,16 @@ v11 = abs(v10); v12 = pRenderer->bUsingSpecular; stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = v11; - stru_F8AD28._blv_lights_smthngs[*pSlot] = pLight->field_B; + stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType; v13 = pRenderer->pRenderD3D; - v14 = stru_F8AD28._blv_lights_smthngs[*pSlot]; + v14 = stru_F8AD28._blv_lights_types[*pSlot]; if ( pRenderer->pRenderD3D && v12 && v14 & 4 ) - v14 = byte_4E94D2; - stru_F8AD28._blv_lights_smthngs[*pSlot] = v14; + v14 = _4E94D2_light_type; + stru_F8AD28._blv_lights_types[*pSlot] = v14; result = 4 * *pSlot; if ( v13 && v12 ) { - if ( stru_F8AD28._blv_lights_smthngs[*pSlot] & 4 ) + if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 ) { *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) * 0.33000001; @@ -1243,54 +1133,53 @@ } return result; } -// 4E94D2: using guessed type char byte_4E94D2; +// 4E94D2: using guessed type char _4E94D2_light_type; //----- (0045D036) -------------------------------------------------------- -bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X) +bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, bool bLightBackfaces) { int v6; // esi@1 - LightmapBuilder *v7; // edi@1 + //LightmapBuilder *v7; // edi@1 MobileLight *v8; // ebx@2 int v9; // esi@5 StationaryLight *v10; // ebx@6 - bool result; // eax@9 + //bool result; // eax@9 unsigned int a7; // [sp+Ch] [bp-4h]@1 v6 = 0; - v7 = this; + //v7 = this; a7 = 0; - stru_F8AD28.field_2C = pOutdoor->field_CBC_terrain_triangles_shade_type; - if ( uNumMobileLightsApplied > 0 ) + stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type; + if ( pMobileLightsStack->uNumLightsActive > 0 ) { - v8 = pMobileLights; + v8 = pMobileLightsStack->pLights; do { if ( (signed int)a7 >= 20 ) break; - StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, X, &a7); + StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, bLightBackfaces, &a7); ++v6; ++v8; } - while ( v6 < uNumMobileLightsApplied ); + while ( v6 < pMobileLightsStack->uNumLightsActive ); } v9 = 0; - if ( uNumStationaryLightsApplied > 0 ) + if ( pStationaryLightsStack->uNumLightsActive > 0 ) { - v10 = pStationaryLights; + v10 = pStationaryLightsStack->pLights; do { if ( (signed int)a7 >= 20 ) break; - StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, X, &a7); + StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, bLightBackfaces, &a7); ++v9; ++v10; } - while ( v9 < uNumStationaryLightsApplied ); + while ( v9 < pStationaryLightsStack->uNumLightsActive ); } - result = a7; - stru_F8AD28.field_AC = a7; - LOBYTE(result) = 1; - return result; + + stru_F8AD28.uNumLightsApplied = a7; + return true; } // 519AB4: using guessed type int uNumStationaryLightsApplied; @@ -1483,16 +1372,16 @@ v54 = abs(v60); v55 = pRenderer->bUsingSpecular; stru_F8AD28._blv_lights_light_dot_faces[*v53] = v54; - stru_F8AD28._blv_lights_smthngs[*v53] = v8->field_B; + stru_F8AD28._blv_lights_types[*v53] = v8->uLightType; v56 = pRenderer->pRenderD3D; - v57 = stru_F8AD28._blv_lights_smthngs[*v53]; + v57 = stru_F8AD28._blv_lights_types[*v53]; if ( pRenderer->pRenderD3D && v55 && v57 & 4 ) - v57 = byte_4E94D2; - stru_F8AD28._blv_lights_smthngs[*v53] = v57; + v57 = _4E94D2_light_type; + stru_F8AD28._blv_lights_types[*v53] = v57; result = 4 * *v53; if ( v56 && v55 ) { - if ( stru_F8AD28._blv_lights_smthngs[*v53] & 4 ) + if ( stru_F8AD28._blv_lights_types[*v53] & 4 ) { *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) * 0.33000001; @@ -1506,7 +1395,7 @@ LOBYTE(result) = 1; return result; } -// 4E94D2: using guessed type char byte_4E94D2; +// 4E94D2: using guessed type char _4E94D2_light_type; //----- (0045D3C7) -------------------------------------------------------- bool LightmapBuilder::_45D3C7(stru148 *a1)