comparison Engine/Graphics/LightmapBuilder.cpp @ 2532:9ec6b8be16fe

Mobile light
author Ritor1
date Mon, 19 Jan 2015 22:39:03 +0600
parents f6de3e15d4a5
children a902abdfc7f2
comparison
equal deleted inserted replaced
2531:f6de3e15d4a5 2532:9ec6b8be16fe
9 #include "Outdoor.h" 9 #include "Outdoor.h"
10 #include "../Log.h" 10 #include "../Log.h"
11 #include "../ErrorHandling.h" 11 #include "../ErrorHandling.h"
12 12
13 #include "Lights.h" 13 #include "Lights.h"
14 14 #include "..\MMT.h"
15 #include "stru9.h" 15 #include "stru9.h"
16
17
18
19 16
20 LightsStack_StationaryLight_ *pStationaryLightsStack = new LightsStack_StationaryLight_; 17 LightsStack_StationaryLight_ *pStationaryLightsStack = new LightsStack_StationaryLight_;
21 //StationaryLight pStationaryLights[400]; 18 //StationaryLight pStationaryLights[400];
22 //int uNumStationaryLightsApplied; // weak 19 //int uNumStationaryLightsApplied; // weak
23 LightsStack_MobileLight_ *pMobileLightsStack = new LightsStack_MobileLight_; 20 LightsStack_MobileLight_ *pMobileLightsStack = new LightsStack_MobileLight_;
24 //MobileLight pMobileLights[400]; 21 //MobileLight pMobileLights[400];
25 //int uNumMobileLightsApplied; 22 //int uNumMobileLightsApplied;
26 23
27 24
28
29
30
31 //----- (0045DF13) -------------------------------------------------------- 25 //----- (0045DF13) --------------------------------------------------------
32 Lightmap::Lightmap() 26 Lightmap::Lightmap()
33 { 27 {
34 uNumVertices = -1; 28 // For initialization step(I)
29
30 NumVertices = -1;
35 for (uint i = 0; i < 64; ++i) 31 for (uint i = 0; i < 64; ++i)
36 pVertices[i].flt_2C = 0.0f; 32 pVertices[i].flt_2C = 0.0f;
37 this->field_C18 = 0; 33 this->field_C18 = 0;
38 //this->vdestructor_ptr = &Lightmap_pvdtor; 34 //this->vdestructor_ptr = &Lightmap_pvdtor;
39 } 35 }
40 36
41 //----- (0045BB06) -------------------------------------------------------- 37 //----- (0045BB06) --------------------------------------------------------
42 LightmapBuilder::LightmapBuilder() 38 LightmapBuilder::LightmapBuilder()
43 { 39 {
44 char *v2; // eax@1 40 // For initialization step(II)
45 signed int v3; // ecx@1 41
46 42 for ( int i = 0; i < 512; ++i )//for light type 1
47 for ( int i = 0; i < 512; ++i )
48 this->std__vector_000004[i] = Lightmap(); 43 this->std__vector_000004[i] = Lightmap();
49 this->std__vector_000004_size = 0; 44 this->std__vector_000004_size = 0;
50 45
51 for ( int i = 0; i < 768; ++i ) 46 for ( int i = 0; i < 768; ++i )//for light type 2
52 this->std__vector_183808[i] = Lightmap(); 47 this->std__vector_183808[i] = Lightmap();
53 this->std__vector_183808_size = 0; 48 this->std__vector_183808_size = 0;
54 49
55 for ( int i = 0; i < 256; i++ ) 50 for ( int i = 0; i < 256; i++ )
56 this->field_3C8C34[i].flt_2C = 0.0f; 51 this->field_3C8C34[i].flt_2C = 0.0f;
57 } 52 }
58 53
59 //----- (0045BC07) -------------------------------------------------------- 54 //////////////////////////OUTDOOR LIGHT////////////////////////////////////////////
60 bool LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, IndoorCameraD3D_Vec4 *a6, char uClipFlag)
61 {
62 Vec3_int_ pos; // [sp+2Ch] [bp-40h]@21
63 RenderVertexSoft *a9; // [sp+68h] [bp-4h]@8
64
65 if (!uNumVertices)
66 return false;
67
68 static RenderVertexSoft static_69B140[64];
69
70 a9 = a5;
71 if (a6)
72 {
73 for (uint i = 0; i < uNumVertices; ++i)
74 memcpy(static_69B140 + i, a5 + i, sizeof(RenderVertexSoft));
75
76 //__debugbreak();
77 if (pGame->pIndoorCameraD3D->_437376(a3, static_69B140, &uNumVertices) == 1)
78 {
79 if ( !uNumVertices )
80 return false;
81 a9 = static_69B140;
82 }
83 }
84
85 static stru314 static_69B110;
86 static_69B110.field_4.x = a3->face_plane.vNormal.x;
87 static_69B110.field_4.y = a3->face_plane.vNormal.y;
88 static_69B110.field_4.z = a3->face_plane.vNormal.z;
89 static_69B110.dist = a3->face_plane.dist;
90 if (!pGame->pIndoorCameraD3D->GetFacetOrientation(a3->polygonType, &static_69B110.field_4,
91 &static_69B110.field_10, &static_69B110.field_1C))
92 {
93 MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0);
94 ExitProcess(0);
95 }
96
97 for (uint i = 0; i < a2->uNumLightsApplied; ++i)
98 {
99 pos.x = a2->_blv_lights_xs[i];
100 pos.y = a2->_blv_lights_ys[i];
101 pos.z = a2->_blv_lights_zs[i];
102
103 uint uColorR = (uint)floorf(a2->_blv_lights_rs[i] * 255.0 + 0.5f) & 0xFF,
104 uColorG = (uint)floorf(a2->_blv_lights_gs[i] * 255.0 + 0.5f) & 0xFF,
105 uColorB = (uint)floorf(a2->_blv_lights_bs[i] * 255.0 + 0.5f) & 0xFF;
106 uint uColor = (uColorR << 16) | (uColorG << 8) | uColorB;
107 if (!uColor)
108 uColor = 0x00FFFFF;
109
110 if (!_45BE86_build_light_polygon(&pos, a2->_blv_lights_radii[i], uColor, a2->_blv_lights_light_dot_faces[i],
111 a2->_blv_lights_types[i], &static_69B110, uNumVertices, a9, uClipFlag) )
112 {
113 MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0);
114 }
115 }
116 return true;
117 }
118
119 //----- (0045BE86) --------------------------------------------------------
120 bool LightmapBuilder::_45BE86_build_light_polygon(Vec3_int_ *pos, float radius, unsigned int uColorMask, float dot_dist, int uLightType, stru314 *a7, unsigned int uNumVertices, RenderVertexSoft *a9, char uClipFlag)
121 {
122 Lightmap *lightmap; // edi@3
123 double v17; // st7@5
124 double v24; // st7@6
125 double v38; // st7@14
126 double v39; // st7@16
127 double v40; // st7@16
128 int v45; // eax@24
129
130 if (radius < 0.0f)
131 return true;
132
133 lightmap = uLightType & 1 ? &std__vector_000004[std__vector_000004_size] :
134 &std__vector_183808[std__vector_183808_size];
135 tex_light_radius = radius - dot_dist;
136 flt_3C8C28 = sqrt((radius + radius - tex_light_radius) * tex_light_radius);
137 //flt_3C8C28 = sqrt(tex_light_radius * tex_light_radius);
138 flt_3C8C2C_lightmaps_brightness = 1.0 - (radius - flt_3C8C28) / radius;
139 lightmap->field_C08 = (double)pos->x - dot_dist * a7->field_4.x;
140 lightmap->field_C0A = (double)pos->y - dot_dist * a7->field_4.y;
141 lightmap->field_C0C = (double)pos->z - dot_dist * a7->field_4.z;
142
143 flt_3C8C30 = radius * flt_3C8C2C_lightmaps_brightness;
144 flt_3C8C0C = flt_3C8C30 * a7->field_10.x;
145 flt_3C8C10 = flt_3C8C30 * a7->field_10.y;
146 flt_3C8C14 = flt_3C8C30 * a7->field_10.z;
147
148 flt_3C8C18 = flt_3C8C30 * a7->field_1C.x;
149 flt_3C8C1C = flt_3C8C30 * a7->field_1C.y;
150 flt_3C8C20 = flt_3C8C30 * a7->field_1C.z;
151
152 lightmap->pVertices[0].vWorldPosition.x = lightmap->field_C08 - flt_3C8C18 + flt_3C8C0C;
153 lightmap->pVertices[0].vWorldPosition.y = lightmap->field_C0A - flt_3C8C1C + flt_3C8C10;
154 lightmap->pVertices[0].vWorldPosition.z = lightmap->field_C0C - flt_3C8C20 + flt_3C8C14;
155 lightmap->pVertices[0].u = 0.0;
156 lightmap->pVertices[0].v = 0.0;
157
158 lightmap->pVertices[1].vWorldPosition.x = lightmap->field_C08 - flt_3C8C18 - flt_3C8C0C;
159 lightmap->pVertices[1].vWorldPosition.y = lightmap->field_C0A - flt_3C8C1C - flt_3C8C10;
160 lightmap->pVertices[1].vWorldPosition.z = lightmap->field_C0C - flt_3C8C20 - flt_3C8C14;
161 lightmap->pVertices[1].u = 0.0;
162 lightmap->pVertices[1].v = 1.0;
163
164 lightmap->pVertices[2].vWorldPosition.x = lightmap->field_C08 + flt_3C8C18 - flt_3C8C0C;
165 lightmap->pVertices[2].vWorldPosition.y = lightmap->field_C0A + flt_3C8C1C - flt_3C8C10;
166 lightmap->pVertices[2].vWorldPosition.z = lightmap->field_C0C + flt_3C8C20 - flt_3C8C14;
167 lightmap->pVertices[2].u = 1.0;
168 lightmap->pVertices[2].v = 1.0;
169
170 lightmap->pVertices[3].vWorldPosition.x = lightmap->field_C08 + flt_3C8C18 + flt_3C8C0C;
171 lightmap->pVertices[3].vWorldPosition.y = lightmap->field_C0A + flt_3C8C1C + flt_3C8C10;
172 lightmap->pVertices[3].vWorldPosition.z = lightmap->field_C0C + flt_3C8C20 + flt_3C8C14;
173 lightmap->pVertices[3].u = 1.0;
174 lightmap->pVertices[3].v = 0.0;
175
176 for (uint i = 0; i < 4; ++i)
177 {
178 v24 = a7->field_4.y * lightmap->pVertices[i].vWorldPosition.y
179 + a7->field_4.z * lightmap->pVertices[i].vWorldPosition.z
180 + a7->field_4.x * lightmap->pVertices[i].vWorldPosition.x
181 + a7->dist;
182
183 lightmap->pVertices[i].vWorldPosition.x -= v24 * a7->field_4.x;
184 lightmap->pVertices[i].vWorldPosition.y -= v24 * a7->field_4.y;
185 lightmap->pVertices[i].vWorldPosition.z -= v24 * a7->field_4.z;
186 }
187
188 lightmap->uColorMask = uColorMask;
189 lightmap->uNumVertices = 4;
190
191 //Brightness(ÿðêîñòü)/////////////////////////////////
192 if (~pGame->uFlags2 & 4)
193 lightmap->fBrightness = flt_3C8C2C_lightmaps_brightness;
194 else
195 {
196 Vec3_float_ a1; // [sp+2Ch] [bp-20h]@8
197 a1.x = (double)pos->x - lightmap->field_C08;
198 a1.y = (double)pos->y - lightmap->field_C0A;
199 a1.z = (double)pos->z - lightmap->field_C0C;
200 a1.Normalize();
201
202 auto temp1 = lightmap->field_C08 + 0.5f,
203 temp2 = lightmap->field_C0A + 0.5f,
204 temp3 = lightmap->field_C0C + 0.5f;
205
206 auto dist_x = abs(pos->x - temp1), //v31
207 dist_y = abs(pos->y - temp2), //v32 arg0a
208 dist_z = abs(pos->z - temp3); //v33 _v64
209 v38 = int_get_vector_length(dist_x, dist_y, dist_z);
210 if (v38 > radius)
211 return true;
212 //radius = (1 / radius) * v38;
213 if ( uLightType & 4 )
214 {
215 v39 = fabs(a1.x * a7->field_4.x + a1.z * a7->field_4.z + a1.y * a7->field_4.y);
216 v40 = v39 * 1.0 * flt_4D86CC;
217
218 lightmap->fBrightness = v40 - ((1 / radius) * v38) * v40;
219 }
220 else if ( uLightType & 8 )
221 {
222 v40 = 1.0 * 1.0;
223 lightmap->fBrightness = v40 - ((1 / radius) * v38);
224 }
225 else
226 MessageBoxW(nullptr, L"Invalid light type!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:277", 0);
227 }
228 //Brightness(ÿðêîñòü)/////////////////////////////////////////////////////
229
230 if (!pGame->pStru9Instance->_4980B9(a9, uNumVertices,
231 a7->field_4.x, a7->field_4.y, a7->field_4.z,
232 lightmap->pVertices, &lightmap->uNumVertices))
233 return false;
234
235 if (!lightmap->uNumVertices)
236 return true;
237
238 v45 = _45C6D6(uNumVertices, a9, lightmap);
239 if ( v45 != uNumVertices && v45 > 0 )
240 _45C4B9(uNumVertices, a9, lightmap);
241
242 pGame->pIndoorCameraD3D->ViewTransform(lightmap->pVertices, lightmap->uNumVertices);
243 pGame->pIndoorCameraD3D->Project(lightmap->pVertices, lightmap->uNumVertices, 0);
244
245 unsigned int _a4 = 0;
246 if ( !(uClipFlag & 1) )
247 _a4 = 1;
248 else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
249 {
250 if ( uClipFlag & 2 )
251 {
252 pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(lightmap->pVertices, lightmap->uNumVertices, field_3C8C34, &_a4);
253 pGame->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->uNumVertices);
254 }
255 else if ( uClipFlag & 4 )
256 {
257 pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(lightmap->pVertices, lightmap->uNumVertices, field_3C8C34, &_a4);
258 pGame->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->uNumVertices);
259 }
260 else
261 MessageBoxW(nullptr, L"Undefined clip flag specified", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330", 0);
262 }
263 else
264 MessageBoxW(nullptr, L"Lightpoly builder native indoor clipping not implemented", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:335", 0);
265
266 if (_a4)
267 {
268 if (uLightType & 1)
269 {
270 if (std__vector_000004_size < 512 - 1)
271 ++std__vector_000004_size;
272 }
273 else
274 {
275 if (std__vector_183808_size < 768 - 1)
276 ++std__vector_183808_size;
277 }
278 //if ( v50 ^ v51 )
279 // *(unsigned int *)v48 = v49 + 1;
280 }
281 return true;
282 }
283
284 //----- (0045C4B9) --------------------------------------------------------
285 int LightmapBuilder::_45C4B9(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
286 {
287 RenderVertexSoft *v9; // esi@3
288 RenderVertexSoft *v12; // ecx@8
289 char v13; // bl@17
290 signed int v14; // edx@17
291 double v15; // st6@18
292 double v16; // st6@21
293 double v17; // st6@24
294 signed int v18; // edx@33
295 float v22; // [sp+Ch] [bp-14h]@23
296 float v23; // [sp+10h] [bp-10h]@20
297 int v24; // [sp+14h] [bp-Ch]@1
298 char v26; // [sp+1Eh] [bp-2h]@17
299 char v27; // [sp+1Fh] [bp-1h]@17
300
301 v24 = 0;
302 for ( uint i = 0; i < pLightmap->uNumVertices; i++)
303 {
304 v9 = &pLightmap->pVertices[(i + 1) % pLightmap->uNumVertices];
305 if ( pLightmap->pVertices[i].vWorldPosition.x != v9->vWorldPosition.x
306 || pLightmap->pVertices[i].vWorldPosition.y != v9->vWorldPosition.y
307 || pLightmap->pVertices[i].vWorldPosition.z != v9->vWorldPosition.z )
308 {
309 for ( uint j = 0; j < a2; ++j )
310 {
311 v12 = &a3[(j + 1) % a2];
312 if ((a3[j].vWorldPosition.x != v12->vWorldPosition.x
313 || a3[j].vWorldPosition.y != v12->vWorldPosition.y
314 || a3[j].vWorldPosition.z != v12->vWorldPosition.z)
315 && pLightmap->pVertices[i].vWorldPosition.x == a3[j].vWorldPosition.x
316 && pLightmap->pVertices[i].vWorldPosition.y == a3[j].vWorldPosition.y
317 && pLightmap->pVertices[i].vWorldPosition.z == a3[j].vWorldPosition.z
318 && (v9->vWorldPosition.x != v12->vWorldPosition.x
319 || v9->vWorldPosition.y != v12->vWorldPosition.y
320 || v9->vWorldPosition.z != v12->vWorldPosition.z) )
321 {
322 v13 = 0;
323 v14 = 0;
324 v27 = 0;
325 v26 = 0;
326
327 if ( v9->vWorldPosition.x <= (double)v12->vWorldPosition.x )
328 v15 = v12->vWorldPosition.x - v9->vWorldPosition.x;
329 else
330 v15 = v9->vWorldPosition.x - v12->vWorldPosition.x;
331 v23 = v15;
332
333 if ( v9->vWorldPosition.y <= (double)v12->vWorldPosition.y )
334 v16 = v12->vWorldPosition.y - v9->vWorldPosition.y;
335 else
336 v16 = v9->vWorldPosition.y - v12->vWorldPosition.y;
337 v22 = v16;
338
339 if ( v9->vWorldPosition.z <= (double)v12->vWorldPosition.z )
340 v17 = v12->vWorldPosition.z - v9->vWorldPosition.z;
341 else
342 v17 = v9->vWorldPosition.z - v12->vWorldPosition.z;
343
344 if ( v23 < 1.0 )
345 {
346 v13 = 1;
347 v14 = 1;
348 }
349
350 if ( v22 < 1.0 )
351 {
352 v27 = 1;
353 ++v14;
354 }
355
356 if ( v17 < 1.0 )
357 {
358 v26 = 1;
359 ++v14;
360 }
361
362 if ( v14 > 1 )
363 {
364 v18 = 0;
365 if ( v13 && v9->vWorldPosition.x != v12->vWorldPosition.x )
366 {
367 v18 = 1;
368 v9->vWorldPosition.x = v12->vWorldPosition.x;
369 }
370
371 if ( v27 && v9->vWorldPosition.y != v12->vWorldPosition.y )
372 {
373 ++v18;
374 v9->vWorldPosition.y = v12->vWorldPosition.y;
375 }
376
377 if ( v26 && v9->vWorldPosition.z != v12->vWorldPosition.z )
378 {
379 ++v18;
380 v9->vWorldPosition.z = v12->vWorldPosition.z;
381 }
382
383 if ( v18 > 0 )
384 ++v24;
385 }
386 }
387 }
388 }
389 }
390 return v24;
391 }
392
393 //----- (0045C6D6) --------------------------------------------------------
394 int LightmapBuilder::_45C6D6(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
395 {
396 signed int v6; // esi@1
397 double v9; // st7@6
398 double v10; // st6@10
399 double v11; // st5@14
400 double v12; // st7@17
401 int v15; // [sp+Ch] [bp-8h]@1
402 float v16; // [sp+10h] [bp-4h]@1
403
404 v6 = -1;
405 v16 = 3.4028235e38;
406 v15 = 0;
407 if ( (signed int)pLightmap->uNumVertices > 0 )
408 {
409 for ( uint i = 0; i < (signed int)pLightmap->uNumVertices; ++i )
410 {
411 if ( a2 > 0 )
412 {
413 for ( uint j = 0; j < a2; ++j )
414 {
415 if ( pLightmap->pVertices[i].vWorldPosition.x <= (double)a3[j].vWorldPosition.x )
416 v9 = a3[j].vWorldPosition.x - pLightmap->pVertices[i].vWorldPosition.x;
417 else
418 v9 = pLightmap->pVertices[i].vWorldPosition.x - a3[j].vWorldPosition.x;
419 if ( v9 < 2.0 )
420 {
421 v10 = pLightmap->pVertices[i].vWorldPosition.y <= (double)a3[j].vWorldPosition.y
422 ? a3[j].vWorldPosition.y - pLightmap->pVertices[i].vWorldPosition.y
423 : pLightmap->pVertices[i].vWorldPosition.y - a3[j].vWorldPosition.y;
424 if ( v10 < 2.0 )
425 {
426 v11 = pLightmap->pVertices[i].vWorldPosition.z <= (double)a3[j].vWorldPosition.z
427 ? a3[j].vWorldPosition.z - pLightmap->pVertices[i].vWorldPosition.z
428 : pLightmap->pVertices[i].vWorldPosition.z - a3[j].vWorldPosition.z;
429 if ( v11 < 2.0 )
430 {
431 v12 = v9 + v11 + v10;
432 if ( v12 < v16 )
433 {
434 v16 = v12;
435 v6 = j;
436 }
437 }
438 }
439 }
440 }
441 if ( v6 != -1 )
442 {
443 ++v15;
444 pLightmap->pVertices[i].vWorldPosition.x = a3[v6].vWorldPosition.x;
445 pLightmap->pVertices[i].vWorldPosition.y = a3[v6].vWorldPosition.y;
446 pLightmap->pVertices[i].vWorldPosition.z = a3[v6].vWorldPosition.z;
447 }
448 }
449 v6 = -1;
450 v16 = 3.4028235e38;
451 }
452 }
453 return v15;
454 }
455
456 //----- (0045C7F6) --------------------------------------------------------
457 bool LightmapBuilder::ApplyLights_IndoorFace(unsigned int uFaceID)
458 {
459 BLVFace* pFace = &pIndoor->pFaces[uFaceID];
460 BLVSector* pSector = &pIndoor->pSectors[pFace->uSectorID];
461
462 stru_F8AD28.uCurrentAmbientLightLevel = (stru_F8AD28.uDefaultAmbientLightLevel + pSector->uMinAmbientLightLevel) << 16;
463
464 uint uNumLightsApplied = 0;
465 for (uint i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
466 {
467 if (uNumLightsApplied >= 20)
468 break;
469
470 ApplyLight_BLV((StationaryLight *)(pMobileLightsStack->pLights + i), pFace, &uNumLightsApplied, true, 0);
471 }
472
473 for (uint i = 0; i < pSector->uNumLights; ++i)
474 {
475 if (uNumLightsApplied >= 20 )
476 break;
477
478 BLVLightMM7* pLight = &pIndoor->pLights[pSector->pLights[i]];
479 if (~pLight->uAtributes & 0x08)
480 ApplyLight_BLV((StationaryLight *)pLight, pFace, &uFaceID, false, &_4E94D0_light_type);
481 }
482
483 for (uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
484 {
485 if (uNumLightsApplied >= 20)
486 break;
487
488 ApplyLight_BLV(pStationaryLightsStack->pLights + i, pFace, &uNumLightsApplied, false, &_4E94D0_light_type);
489 }
490
491 stru_F8AD28.uNumLightsApplied = uNumLightsApplied;
492 return true;
493 }
494
495 //----- (0045C911) --------------------------------------------------------
496 bool LightmapBuilder::ApplyLight_BLV(StationaryLight *pLight, BLVFace *a2, unsigned int *pSlot, bool bLightBackfaces, char *a5)
497 {
498 double v13; // st7@8
499
500 if (!pLight->uRadius)
501 return false;
502
503 if (pLight->vPosition.x > a2->pBounding.x1 - pLight->uRadius && pLight->vPosition.x < a2->pBounding.x2 + pLight->uRadius &&
504 pLight->vPosition.y > a2->pBounding.y1 - pLight->uRadius && pLight->vPosition.y < a2->pBounding.y2 + pLight->uRadius &&
505 pLight->vPosition.z > a2->pBounding.z1 - pLight->uRadius && pLight->vPosition.z < a2->pBounding.z2 + pLight->uRadius)
506 {
507 v13 = (double)pLight->vPosition.z * a2->pFacePlane.vNormal.z +
508 (double)pLight->vPosition.y * a2->pFacePlane.vNormal.y +
509 (double)pLight->vPosition.x * a2->pFacePlane.vNormal.x +
510 a2->pFacePlane.dist;
511 if ((bLightBackfaces || v13 >= 0.0f) && fabsf(v13) <= pLight->uRadius)
512 {
513 unsigned int slot = *pSlot;
514
515 stru_F8AD28._blv_lights_radii[slot] = pLight->uRadius;
516 stru_F8AD28._blv_lights_inv_radii[slot] = 65536 / pLight->uRadius;
517 stru_F8AD28._blv_lights_xs[slot] = pLight->vPosition.x;
518 stru_F8AD28._blv_lights_ys[slot] = pLight->vPosition.y;
519 stru_F8AD28._blv_lights_zs[slot] = pLight->vPosition.z;
520 stru_F8AD28._blv_lights_rs[slot] = (double)pLight->uLightColorR / 255.0f;
521 stru_F8AD28._blv_lights_gs[slot] = (double)pLight->uLightColorG / 255.0f;
522 stru_F8AD28._blv_lights_bs[slot] = (double)pLight->uLightColorB / 255.0f;
523 stru_F8AD28._blv_lights_light_dot_faces[slot] = abs((int)floorf(v13 + 0.5f));
524 stru_F8AD28._blv_lights_types[slot] = pLight->uLightType;
525
526 *pSlot += 1;
527 return true;
528 }
529 }
530
531 return false;
532 }
533
534 //----- (0045CA88) --------------------------------------------------------
535 int LightmapBuilder::_45CA88(stru320 *a2, RenderVertexSoft *a3, int a4, Vec3_float_ *pNormal)
536 {
537 int result; // eax@1
538 stru320 *v6; // ecx@2
539 RenderVertexSoft *v7; // ebx@2
540 double v8; // st7@2
541 double v9; // st6@2
542 char *v10; // eax@3
543 double v11; // st7@5
544 __int64 v12; // ST2C_8@5
545 float v13; // edx@5
546 int v14; // eax@5
547 float v15; // ST10_4@5
548 Vec3_float_ v16; // ST00_12@5
549 double v17; // st7@5
550 int a5; // [sp+2Ch] [bp-1Ch]@1
551 float v19; // [sp+30h] [bp-18h]@1
552 float v20; // [sp+34h] [bp-14h]@1
553 //LightmapBuilder *thisa; // [sp+38h] [bp-10h]@1
554 int v22; // [sp+3Ch] [bp-Ch]@1
555 int *j; // [sp+40h] [bp-8h]@3
556 int i; // [sp+44h] [bp-4h]@1
557 int a3a; // [sp+58h] [bp+10h]@2
558
559 __debugbreak();//Ritor1: needed cleaning
560
561 *(float *)&a5 = 0.0;
562 v19 = 0.0;
563 //thisa = this;
564 v20 = 0.0;
565 result = _45CBD4(a3, a4, dword_69B010.data(), &v22);
566 for ( i = 0; i < v22; result = i )
567 {
568 v6 = a2;
569 a3a = 0;
570 v7 = &a3[dword_69B010[i]];
571 v8 = v7->vWorldPosition.z;
572 v9 = v7->vWorldPosition.y;
573 *(float *)&a5 = v7->vWorldPosition.x;
574 v19 = v9;
575 v20 = v8;
576 v7->flt_2C = 0.0;
577 if ( a2->uNumLightsApplied > 0 )
578 {
579 v10 = (char *)a2->_blv_lights_ys;
580 for ( j = a2->_blv_lights_ys; ; v10 = (char *)j )
581 {
582 v11 = (double)*((signed int *)v10 - 60);
583 LODWORD(v12) = *((unsigned int *)v10 - 20);
584 HIDWORD(v12) = *(unsigned int *)v10;
585 LODWORD(v13) = *((unsigned int *)v10 + 60);
586 v14 = a3a;
587 LOBYTE(v14) = v6->_blv_lights_types[a3a];
588 v15 = v11;
589 *(_QWORD *)&v16.x = v12;
590 v16.z = v13;
591 v17 = _45CC0C_light(v16/*COERCE_VEC3_FLOAT_(v16.x)*/, 1.0, v15, pNormal, *(float *)&a5/*COERCE_FLOAT(&a5)*/, v14)
592 + v7->flt_2C;
593 ++a3a;
594 ++j;
595 v7->flt_2C = v17;
596 if ( a3a >= a2->uNumLightsApplied )
597 break;
598 v6 = a2;
599 }
600 }
601 ++i;
602 }
603 return result;
604 }
605
606 //----- (0045CB89) --------------------------------------------------------
607 int LightmapBuilder::_45CB89(RenderVertexSoft *a1, int a2)
608 {
609 int v3; // edx@1
610 int result; // eax@2
611 char *v5; // ecx@2
612 double v6; // st7@4
613 __int16 v7; // fps@4
614 char v8; // c0@4
615 char v9; // c2@4
616 char v10; // c3@4
617 double v11; // st7@5
618 double v12; // st7@6
619 __int16 v13; // fps@6
620 char v14; // c0@6
621 char v15; // c2@6
622 char v16; // c3@6
623
624 v3 = a2;
625 if ( a2 > 0 )
626 {
627 HIWORD(result) = HIWORD(a1);
628 v5 = (char *)&a1->flt_2C;
629 do
630 {
631 __debugbreak(); // warning C4700: uninitialized local variable 'v7' used
632 if ( *(float *)v5 < 0.0
633 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) )
634 {
635 v12 = *(float *)v5;
636 //UNDEF(v13);
637 v14 = 0.0 < v12;
638 v15 = 0;
639 v16 = 0.0 == v12;
640 __debugbreak(); // warning C4700: uninitialized local variable 'v13' used
641 LOWORD(result) = v13;
642 if ( v12 >= 0.0 )
643 v11 = *(float *)v5;
644 else
645 v11 = 0.0;
646 }
647 else
648 {
649 v11 = 1.0;
650 }
651 *(float *)v5 = v11;
652 v5 += 48;
653 --v3;
654 }
655 while ( v3 );
656 }
657 return result;
658 }
659
660 //----- (0045CBD4) --------------------------------------------------------
661 int LightmapBuilder::_45CBD4(RenderVertexSoft *a2, int a3, int *a4, int *a5)
662 {
663 int result; // eax@1
664 int v6; // edx@1
665 int v7; // ecx@2
666 int v8; // esi@2
667
668 result = (int)a5;
669 v6 = 0;
670 for ( *a5 = 0; v6 < a3; ++v6 )
671 {
672 v7 = *a5;
673 v8 = 0;
674 if ( *a5 <= 0 )
675 {
676 //LABEL_5:
677 a4[v7] = v6;
678 ++*a5;
679 }
680 else
681 {
682 while ( a4[v8] != v6 )
683 {
684 ++v8;
685 if (v8 >= v7)
686 {
687 a4[v7] = v6;
688 ++*a5;
689 break;
690 //goto LABEL_5;
691 }
692 }
693 }
694 }
695 return result;
696 }
697
698 //----- (0045CC0C) --------------------------------------------------------
699 double LightmapBuilder::_45CC0C_light(Vec3_float_ a1, float a2, float a3, Vec3_float_ *pNormal, float a5, int uLightType)
700 {
701 float v7; // esi@1
702 int v8; // eax@1
703 double v14; // st7@7
704 double result; // st7@8
705 double v16; // st7@9
706 int v17; // esi@9
707 const char *v18; // ecx@9
708 double v19; // st7@10
709 double v20; // st7@10
710 std::string v21; // [sp-10h] [bp-40h]@13
711 const char *v22[6]; // [sp+0h] [bp-30h]@10
712 double v23; // [sp+18h] [bp-18h]@1
713 // double v24; // [sp+20h] [bp-10h]@1
714 int v25; // [sp+28h] [bp-8h]@1
715 int v26; // [sp+2Ch] [bp-4h]@1
716
717 v7 = a5;
718 LODWORD(a5) = *(unsigned int *)(LODWORD(a5) + 8);
719 //v24 = a5 + 6.7553994e15;
720 v26 = floorf(a5 + 0.5f);//LODWORD(v24);
721 LODWORD(a5) = *(unsigned int *)(LODWORD(v7) + 4);
722 //v24 = a5 + 6.7553994e15;
723 auto _v24 = floorf(a5 + 0.5f);
724 LODWORD(a5) = *(unsigned int *)LODWORD(v7);
725 //v23 = a5 + 6.7553994e15;
726 auto _v23 = floorf(a5 + 0.5f);
727 //*(_QWORD *)((char *)&v24 + 4) = __PAIR__(LODWORD(v24), LODWORD(v23));
728 v26 = abs((signed)LODWORD(a1.z) - v26);
729 //v25 = abs((signed)LODWORD(a1.y) - (signed)LODWORD(v24));
730 //v8 = abs((int)a1.x - (signed)LODWORD(v23));
731 v25 = abs((signed)LODWORD(a1.y) - (signed)_v24);
732 v8 = abs((int)a1.x - (signed)_v23);
733 v14 = int_get_vector_length(v26, v25, v8);
734 if ( v14 <= a3 )
735 {
736 a5 = v14 / a3;
737 v16 = (double)(signed int)a1.x;
738 *(float *)&v23 = (double)SLODWORD(a1.y);
739 LODWORD(a1.x) = *(unsigned int *)LODWORD(v7);
740 v17 = LODWORD(v7) + 4;
741 *((float *)&v23 + 1) = (double)SLODWORD(a1.z);
742 LODWORD(a1.y) = *(unsigned int *)v17;
743 LODWORD(a1.z) = *(unsigned int *)(v17 + 4);
744 a3 = *((float *)&v23 + 1) - a1.z;
745 a1.z = a3;
746 a1.x = v16 - a1.x;
747 a1.y = (float)v23 - a1.y;
748 a1.Normalize();
749 if ( uLightType & 4 )
750 {
751 __debugbreak(); // warning C4700: uninitialized local variable 'v18' used
752 v22[1] = v18;
753 uLightType = dword_4D86D8;
754 v22[0] = v18;
755 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x);
756 v20 = v19 * *(float *)&uLightType * a2;
757 }
758 else
759 {
760 if ( uLightType & 8 )
761 {
762 v20 = 1.3 * a2;
763 }
764 else
765 {
766 MessageBoxW(nullptr, L"Invalid light type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:783", 0);
767 v20 = *(float *)&uLightType;
768 }
769 }
770 result = v20 - a5 * v20;
771 }
772 else
773 {
774 result = 0.0;
775 }
776 return result;
777 }
778 // 4D86D8: using guessed type int dword_4D86D8;
779
780 //----- (0045CDB7) -------------------------------------------------------- 55 //----- (0045CDB7) --------------------------------------------------------
781 bool LightmapBuilder::ApplyLights_OutdoorFace(ODMFace *pFace) 56 bool LightmapBuilder::ApplyLights_OutdoorFace(ODMFace *pFace)
782 { 57 {
58 //For outdoor light (I)
783 int v3; // eax@1 59 int v3; // eax@1
784 bool result; // eax@9 60 bool result; // eax@9
785 int pSlot; // [sp+10h] [bp-4h]@1 61 int pSlot; // [sp+10h] [bp-4h]@1
786 62
787 v3 = stru_F8AD28.uDefaultAmbientLightLevel + pFace->uShadeType; 63 v3 = stru_F8AD28.uDefaultAmbientLightLevel + pFace->uShadeType;
802 result = pSlot; 78 result = pSlot;
803 stru_F8AD28.uNumLightsApplied = pSlot; 79 stru_F8AD28.uNumLightsApplied = pSlot;
804 return true; 80 return true;
805 } 81 }
806 82
807 //----- (0045CE50) --------------------------------------------------------
808 bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4)
809 {
810 int result; // eax@0
811 int v10; // ecx@8
812 char v14; // dl@11
813
814 v10 = (pFace->pFacePlane.dist
815 + pLight->vPosition.x * pFace->pFacePlane.vNormal.x
816 + pLight->vPosition.y * pFace->pFacePlane.vNormal.y
817 + pLight->vPosition.z * pFace->pFacePlane.vNormal.z) >> 16;
818 if ( pLight->uRadius > 0
819 && (pLight->vPosition.x > pFace->pBoundingBox.x1 - pLight->uRadius) && pLight->vPosition.x < pLight->uRadius + pFace->pBoundingBox.x2
820 && (pLight->vPosition.y > pFace->pBoundingBox.y1 - pLight->uRadius) && pLight->vPosition.y < pLight->uRadius + pFace->pBoundingBox.y2
821 && (pLight->vPosition.z > pFace->pBoundingBox.z1 - pLight->uRadius) && pLight->vPosition.z < pLight->uRadius + pFace->pBoundingBox.z2
822 && ((a4) || v10 >= 0) && v10 <= pLight->uRadius )
823 {
824 stru_F8AD28._blv_lights_radii[*pSlot] = pLight->uRadius;
825 stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / pLight->uRadius;
826 stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x;
827 stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y;
828 stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z;
829 stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689;
830 stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689;
831 stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689;
832 //v11 = abs(v10);
833 //v12 = pRenderer->bUsingSpecular;
834 stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = abs(v10);
835 stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType;
836 //v13 = pRenderer->pRenderD3D;
837 v14 = stru_F8AD28._blv_lights_types[*pSlot];
838 if ( /*pRenderer->pRenderD3D &&*/ pRenderer->bUsingSpecular && v14 & 4 )
839 v14 = _4E94D2_light_type;
840 stru_F8AD28._blv_lights_types[*pSlot] = v14;
841 result = 4 * *pSlot;
842 if ( /*v13*/true && pRenderer->bUsingSpecular )
843 {
844 if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 )
845 {
846 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result)
847 * 0.33000001;
848 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result)
849 * 0.33000001;
850 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result)
851 * 0.33000001;
852 }
853 }
854 ++*pSlot;
855 return true;
856 }
857 else
858 return false;
859 }
860 // 4E94D2: using guessed type char _4E94D2_light_type;
861
862 //----- (0045D036) --------------------------------------------------------
863 bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *Light_tile_dist, RenderVertexSoft *a3, unsigned int uStripType, bool bLightBackfaces)
864 {
865 /*int v6; // esi@1
866 //LightmapBuilder *v7; // edi@1
867 MobileLight *v8; // ebx@2
868 int v9; // esi@5
869 StationaryLight *v10; // ebx@6
870 //bool result; // eax@9
871 unsigned int a7; // [sp+Ch] [bp-4h]@1
872
873 v6 = 0;
874 //v7 = this;
875 a7 = 0;
876 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type;
877 if ( pMobileLightsStack->uNumLightsActive > 0 )
878 {
879 v8 = pMobileLightsStack->pLights;
880 do
881 {
882 if ( (signed int)a7 >= 20 )
883 break;
884 StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
885 ++v6;
886 ++v8;
887 }
888 while ( v6 < pMobileLightsStack->uNumLightsActive );
889 }
890 v9 = 0;
891 if ( pStationaryLightsStack->uNumLightsActive > 0 )
892 {
893 v10 = pStationaryLightsStack->pLights;
894 do
895 {
896 if ( (signed int)a7 >= 20 )
897 break;
898 StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
899 ++v9;
900 ++v10;
901 }
902 while ( v9 < pStationaryLightsStack->uNumLightsActive );
903 }
904
905 stru_F8AD28.uNumLightsApplied = a7;
906 return true;*/
907 // bool __stdcall sub_45D036(struct Vec3<float> *pNormal, int a2, struct RenderVertex *a3, int a4, signed int X)
908 //{
909 // float v6; // ebx@2
910 unsigned int num_lights; // [sp+Ch] [bp-4h]@1
911 int i;
912
913 num_lights = 0;
914 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->max_terrain_dimming_level;
915 for (i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
916 {
917 if ( num_lights >= 20 )
918 break;
919 StackLight_TerrainFace((StationaryLight *)&pMobileLightsStack->pLights[i], pNormal, Light_tile_dist, a3, uStripType, bLightBackfaces, &num_lights);
920 }
921
922 for (i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
923 {
924 if ( num_lights >= 20 )
925 break;
926 StackLight_TerrainFace(&pStationaryLightsStack->pLights[i], pNormal, Light_tile_dist, a3, uStripType, bLightBackfaces, &num_lights);
927 }
928
929 stru_F8AD28.uNumLightsApplied = num_lights;
930 return true;
931
932 }
933 // 519AB4: using guessed type int uNumStationaryLightsApplied;
934
935 //----- (0045D0D5) -------------------------------------------------------- 83 //----- (0045D0D5) --------------------------------------------------------
936 bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X, unsigned int *pSlot) 84 bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X, unsigned int *pSlot)
937 { 85 {
86 //For outdoor terrain light (II)
938 bool result; // eax@1 87 bool result; // eax@1
939 double maxz; // st7@11 88 double maxz; // st7@11
940 char v20; // c2@11 89 char v20; // c2@11
941 signed int v52; // ecx@17 90 signed int v52; // ecx@17
942 char v57; // dl@18 91 char v57; // dl@18
1057 } 206 }
1058 ++*pSlot; 207 ++*pSlot;
1059 return 1; 208 return 1;
1060 } 209 }
1061 210
211 //----- (0045CE50) --------------------------------------------------------
212 bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4)
213 {
214 //For outdoor light (IV)
215 int result; // eax@0
216 int v10; // ecx@8
217 char v14; // dl@11
218
219 v10 = (pFace->pFacePlane.dist
220 + pLight->vPosition.x * pFace->pFacePlane.vNormal.x
221 + pLight->vPosition.y * pFace->pFacePlane.vNormal.y
222 + pLight->vPosition.z * pFace->pFacePlane.vNormal.z) >> 16;
223 if ( pLight->uRadius > 0
224 && (pLight->vPosition.x > pFace->pBoundingBox.x1 - pLight->uRadius) && pLight->vPosition.x < pLight->uRadius + pFace->pBoundingBox.x2
225 && (pLight->vPosition.y > pFace->pBoundingBox.y1 - pLight->uRadius) && pLight->vPosition.y < pLight->uRadius + pFace->pBoundingBox.y2
226 && (pLight->vPosition.z > pFace->pBoundingBox.z1 - pLight->uRadius) && pLight->vPosition.z < pLight->uRadius + pFace->pBoundingBox.z2
227 && ((a4) || v10 >= 0) && v10 <= pLight->uRadius )
228 {
229 stru_F8AD28._blv_lights_radii[*pSlot] = pLight->uRadius;
230 stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / pLight->uRadius;
231 stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x;
232 stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y;
233 stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z;
234 stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689;
235 stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689;
236 stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689;
237 //v11 = abs(v10);
238 //v12 = pRenderer->bUsingSpecular;
239 stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = abs(v10);
240 stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType;
241 //v13 = pRenderer->pRenderD3D;
242 v14 = stru_F8AD28._blv_lights_types[*pSlot];
243 if ( /*pRenderer->pRenderD3D &&*/ pRenderer->bUsingSpecular && v14 & 4 )
244 v14 = _4E94D2_light_type;
245 stru_F8AD28._blv_lights_types[*pSlot] = v14;
246 result = 4 * *pSlot;
247 if ( /*v13*/true && pRenderer->bUsingSpecular )
248 {
249 if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 )
250 {
251 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result)
252 * 0.33000001;
253 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result)
254 * 0.33000001;
255 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result)
256 * 0.33000001;
257 }
258 }
259 ++*pSlot;
260 return true;
261 }
262 else
263 return false;
264 }
265
266
267 //////////////////////////INDOOR LIGHT////////////////////////////////////////////
268 //----- (0045C7F6) --------------------------------------------------------
269 bool LightmapBuilder::ApplyLights_IndoorFace(unsigned int uFaceID)
270 {
271 //For Indoor light (I)
272 BLVFace* pFace = &pIndoor->pFaces[uFaceID];
273 BLVSector* pSector = &pIndoor->pSectors[pFace->uSectorID];
274
275 stru_F8AD28.uCurrentAmbientLightLevel = (stru_F8AD28.uDefaultAmbientLightLevel + pSector->uMinAmbientLightLevel) << 16;//0x00180000
276
277 uint uNumLightsApplied = 0;
278 for (uint i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
279 {
280 if (uNumLightsApplied >= 20)
281 break;
282
283 ApplyLight_BLV((StationaryLight *)(pMobileLightsStack->pLights + i), pFace, &uNumLightsApplied, true, 0);
284 }
285
286 for (uint i = 0; i < pSector->uNumLights; ++i)
287 {
288 if (uNumLightsApplied >= 20 )
289 break;
290
291 BLVLightMM7* pLight = &pIndoor->pLights[pSector->pLights[i]];
292 if (~pLight->uAtributes & 0x08)
293 ApplyLight_BLV((StationaryLight *)pLight, pFace, &uFaceID, false, &_4E94D0_light_type);
294 }
295
296 for (uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
297 {
298 if (uNumLightsApplied >= 20)
299 break;
300
301 ApplyLight_BLV(pStationaryLightsStack->pLights + i, pFace, &uNumLightsApplied, false, &_4E94D0_light_type);
302 }
303
304 stru_F8AD28.uNumLightsApplied = uNumLightsApplied;
305 return true;
306 }
307
308 //----- (0045C911) --------------------------------------------------------
309 bool LightmapBuilder::ApplyLight_BLV(StationaryLight *pLight, BLVFace *a2, unsigned int *pSlot, bool bLightBackfaces, char *a5)
310 {
311 //For indoor light (II)
312 double v13; // st7@8
313
314 if (!pLight->uRadius)//800
315 return false;
316
317 if (pLight->vPosition.x > a2->pBounding.x1 - pLight->uRadius && pLight->vPosition.x < a2->pBounding.x2 + pLight->uRadius &&
318 pLight->vPosition.y > a2->pBounding.y1 - pLight->uRadius && pLight->vPosition.y < a2->pBounding.y2 + pLight->uRadius &&
319 pLight->vPosition.z > a2->pBounding.z1 - pLight->uRadius && pLight->vPosition.z < a2->pBounding.z2 + pLight->uRadius)
320 {
321 v13 = (double)pLight->vPosition.z * a2->pFacePlane.vNormal.z +
322 (double)pLight->vPosition.y * a2->pFacePlane.vNormal.y +
323 (double)pLight->vPosition.x * a2->pFacePlane.vNormal.x +
324 a2->pFacePlane.dist;
325 if ((bLightBackfaces || v13 >= 0.0f) && fabsf(v13) <= pLight->uRadius)
326 {
327 unsigned int slot = *pSlot;
328
329 stru_F8AD28._blv_lights_radii[slot] = pLight->uRadius;
330 stru_F8AD28._blv_lights_inv_radii[slot] = 65536 / pLight->uRadius;
331 stru_F8AD28._blv_lights_xs[slot] = pLight->vPosition.x;
332 stru_F8AD28._blv_lights_ys[slot] = pLight->vPosition.y;
333 stru_F8AD28._blv_lights_zs[slot] = pLight->vPosition.z;
334 stru_F8AD28._blv_lights_rs[slot] = (double)pLight->uLightColorR / 255.0f;
335 stru_F8AD28._blv_lights_gs[slot] = (double)pLight->uLightColorG / 255.0f;
336 stru_F8AD28._blv_lights_bs[slot] = (double)pLight->uLightColorB / 255.0f;
337 stru_F8AD28._blv_lights_light_dot_faces[slot] = abs((int)floorf(v13 + 0.5f));
338 stru_F8AD28._blv_lights_types[slot] = pLight->uLightType;
339
340 *pSlot += 1;
341 return true;
342 }
343 }
344
345 return false;
346 }
347
348 //----- (0045DA56) --------------------------------------------------------
349 bool LightmapBuilder::DoDraw_183808_Lightmaps(float z_bias)
350 {
351 //For indoor light (X)
352 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2
353 v.z = 1.0;
354 v.y = 1.0;
355 v.x = 1.0;
356
357 for (uint i = 0; i < std__vector_183808_size; ++i)
358 if (!pRenderer->DrawLightmap(std__vector_183808 + i, &v, z_bias))
359 Error("Invalid lightmap detected! (%u)", i);
360
361 return true;
362 }
363
364 //----- (0045C4B9) --------------------------------------------------------
365 int LightmapBuilder::_45C4B9(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
366 {
367 //For indoor light (?)
368 RenderVertexSoft *v9; // esi@3
369 RenderVertexSoft *v12; // ecx@8
370 char v13; // bl@17
371 signed int v14; // edx@17
372 double v15; // st6@18
373 double v16; // st6@21
374 double v17; // st6@24
375 signed int v18; // edx@33
376 float v22; // [sp+Ch] [bp-14h]@23
377 float v23; // [sp+10h] [bp-10h]@20
378 int v24; // [sp+14h] [bp-Ch]@1
379 char v26; // [sp+1Eh] [bp-2h]@17
380 char v27; // [sp+1Fh] [bp-1h]@17
381
382 v24 = 0;
383 for ( uint i = 0; i < pLightmap->NumVertices; i++)
384 {
385 v9 = &pLightmap->pVertices[(i + 1) % pLightmap->NumVertices];
386 if ( pLightmap->pVertices[i].vWorldPosition.x != v9->vWorldPosition.x
387 || pLightmap->pVertices[i].vWorldPosition.y != v9->vWorldPosition.y
388 || pLightmap->pVertices[i].vWorldPosition.z != v9->vWorldPosition.z )
389 {
390 for ( uint j = 0; j < a2; ++j )
391 {
392 v12 = &a3[(j + 1) % a2];
393 if ((a3[j].vWorldPosition.x != v12->vWorldPosition.x
394 || a3[j].vWorldPosition.y != v12->vWorldPosition.y
395 || a3[j].vWorldPosition.z != v12->vWorldPosition.z)
396 && pLightmap->pVertices[i].vWorldPosition.x == a3[j].vWorldPosition.x
397 && pLightmap->pVertices[i].vWorldPosition.y == a3[j].vWorldPosition.y
398 && pLightmap->pVertices[i].vWorldPosition.z == a3[j].vWorldPosition.z
399 && (v9->vWorldPosition.x != v12->vWorldPosition.x
400 || v9->vWorldPosition.y != v12->vWorldPosition.y
401 || v9->vWorldPosition.z != v12->vWorldPosition.z) )
402 {
403 v13 = 0;
404 v14 = 0;
405 v27 = 0;
406 v26 = 0;
407
408 if ( v9->vWorldPosition.x <= (double)v12->vWorldPosition.x )
409 v15 = v12->vWorldPosition.x - v9->vWorldPosition.x;
410 else
411 v15 = v9->vWorldPosition.x - v12->vWorldPosition.x;
412 v23 = v15;
413
414 if ( v9->vWorldPosition.y <= (double)v12->vWorldPosition.y )
415 v16 = v12->vWorldPosition.y - v9->vWorldPosition.y;
416 else
417 v16 = v9->vWorldPosition.y - v12->vWorldPosition.y;
418 v22 = v16;
419
420 if ( v9->vWorldPosition.z <= (double)v12->vWorldPosition.z )
421 v17 = v12->vWorldPosition.z - v9->vWorldPosition.z;
422 else
423 v17 = v9->vWorldPosition.z - v12->vWorldPosition.z;
424
425 if ( v23 < 1.0 )
426 {
427 v13 = 1;
428 v14 = 1;
429 }
430
431 if ( v22 < 1.0 )
432 {
433 v27 = 1;
434 ++v14;
435 }
436
437 if ( v17 < 1.0 )
438 {
439 v26 = 1;
440 ++v14;
441 }
442
443 if ( v14 > 1 )
444 {
445 v18 = 0;
446 if ( v13 && v9->vWorldPosition.x != v12->vWorldPosition.x )
447 {
448 v18 = 1;
449 v9->vWorldPosition.x = v12->vWorldPosition.x;
450 }
451
452 if ( v27 && v9->vWorldPosition.y != v12->vWorldPosition.y )
453 {
454 ++v18;
455 v9->vWorldPosition.y = v12->vWorldPosition.y;
456 }
457
458 if ( v26 && v9->vWorldPosition.z != v12->vWorldPosition.z )
459 {
460 ++v18;
461 v9->vWorldPosition.z = v12->vWorldPosition.z;
462 }
463
464 if ( v18 > 0 )
465 ++v24;
466 }
467 }
468 }
469 }
470 }
471 return v24;
472 }
473
474 ////////////////////////FOR OUTDOOR TERRAIN//////////////////////////////////////////
475 //----- (0045D036) --------------------------------------------------------
476 bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *Light_tile_dist, RenderVertexSoft *a3, unsigned int uStripType, bool bLightBackfaces)
477 {
478 /*int v6; // esi@1
479 //LightmapBuilder *v7; // edi@1
480 MobileLight *v8; // ebx@2
481 int v9; // esi@5
482 StationaryLight *v10; // ebx@6
483 //bool result; // eax@9
484 unsigned int a7; // [sp+Ch] [bp-4h]@1
485
486 v6 = 0;
487 //v7 = this;
488 a7 = 0;
489 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type;
490 if ( pMobileLightsStack->uNumLightsActive > 0 )
491 {
492 v8 = pMobileLightsStack->pLights;
493 do
494 {
495 if ( (signed int)a7 >= 20 )
496 break;
497 StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
498 ++v6;
499 ++v8;
500 }
501 while ( v6 < pMobileLightsStack->uNumLightsActive );
502 }
503 v9 = 0;
504 if ( pStationaryLightsStack->uNumLightsActive > 0 )
505 {
506 v10 = pStationaryLightsStack->pLights;
507 do
508 {
509 if ( (signed int)a7 >= 20 )
510 break;
511 StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, bLightBackfaces, &a7);
512 ++v9;
513 ++v10;
514 }
515 while ( v9 < pStationaryLightsStack->uNumLightsActive );
516 }
517
518 stru_F8AD28.uNumLightsApplied = a7;
519 return true;*/
520 // bool __stdcall sub_45D036(struct Vec3<float> *pNormal, int a2, struct RenderVertex *a3, int a4, signed int X)
521 //{
522 // float v6; // ebx@2
523
524 //For outdoor terrain light(I)
525 unsigned int num_lights; // [sp+Ch] [bp-4h]@1
526 int i;
527
528 num_lights = 0;
529 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->max_terrain_dimming_level;
530 for (i = 0; i < pMobileLightsStack->uNumLightsActive; ++i)
531 {
532 if ( num_lights >= 20 )
533 break;
534 StackLight_TerrainFace((StationaryLight *)&pMobileLightsStack->pLights[i], pNormal, Light_tile_dist, a3, uStripType, bLightBackfaces, &num_lights);
535 }
536
537 for (i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i)
538 {
539 if ( num_lights >= 20 )
540 break;
541 StackLight_TerrainFace(&pStationaryLightsStack->pLights[i], pNormal, Light_tile_dist, a3, uStripType, bLightBackfaces, &num_lights);
542 }
543
544 stru_F8AD28.uNumLightsApplied = num_lights;
545 return true;
546
547 }
548
549
550 /////////////////////////TOGETHER///////////////////////////////////////////////////////
551 //----- (0045BC07) --------------------------------------------------------
552 bool LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, IndoorCameraD3D_Vec4 *a6, char uClipFlag)
553 {
554 //For outdoor terrain and indoor light (III)(III)
555 Vec3_int_ pos; // [sp+2Ch] [bp-40h]@21
556 RenderVertexSoft *a9; // [sp+68h] [bp-4h]@8
557
558 if (!uNumVertices)
559 return false;
560
561 static RenderVertexSoft static_69B140[64];
562
563 a9 = a5;
564 if (a6)
565 {
566 for (uint i = 0; i < uNumVertices; ++i)
567 memcpy(&static_69B140[i], a5 + i, sizeof(RenderVertexSoft));
568
569 if (pGame->pIndoorCameraD3D->_437376(a3, static_69B140, &uNumVertices) == 1)
570 {
571 if ( !uNumVertices )
572 return false;
573 a9 = static_69B140;
574 }
575 }
576
577 static stru314 static_69B110;
578 static_69B110.field_4.x = a3->face_plane.vNormal.x;
579 static_69B110.field_4.y = a3->face_plane.vNormal.y;
580 static_69B110.field_4.z = a3->face_plane.vNormal.z;
581 static_69B110.dist = a3->face_plane.dist;
582 if (!pGame->pIndoorCameraD3D->GetFacetOrientation(a3->polygonType, &static_69B110.field_4,
583 &static_69B110.field_10, &static_69B110.field_1C))
584 {
585 MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0);
586 ExitProcess(0);
587 }
588
589 for (uint i = 0; i < a2->uNumLightsApplied; ++i)
590 {
591 pos.x = a2->_blv_lights_xs[i];
592 pos.y = a2->_blv_lights_ys[i];
593 pos.z = a2->_blv_lights_zs[i];
594
595 uint uColorR = (uint)floorf(a2->_blv_lights_rs[i] * 255.0 + 0.5f) & 0xFF,
596 uColorG = (uint)floorf(a2->_blv_lights_gs[i] * 255.0 + 0.5f) & 0xFF,
597 uColorB = (uint)floorf(a2->_blv_lights_bs[i] * 255.0 + 0.5f) & 0xFF;
598 uint uColor = (uColorR << 16) | (uColorG << 8) | uColorB;
599 if (!uColor)
600 uColor = 0x0FFFFF;//0x00FFFFF;
601
602 if (!_45BE86_build_light_polygon(&pos, a2->_blv_lights_radii[i], uColor, a2->_blv_lights_light_dot_faces[i],
603 a2->_blv_lights_types[i], &static_69B110, uNumVertices, a9, uClipFlag) )
604 {
605 MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0);
606 }
607 }
608 return true;
609 }
610
611 //----- (0045BE86) --------------------------------------------------------
612 bool LightmapBuilder::_45BE86_build_light_polygon(Vec3_int_ *pos, float radius, unsigned int uColorMask, float dot_dist, int uLightType, stru314 *a7, unsigned int uNumVertices, RenderVertexSoft *a9, char uClipFlag)
613 {
614 //For outdoor terrain and indoor light (IV)(IV)
615 Lightmap *lightmap; // edi@3
616 double v17; // st7@5
617 double v24; // st7@6
618 double v38; // st7@14
619 double v39; // st7@16
620 double v40; // st7@16
621 int v45; // eax@24
622
623 if (radius < 0.0f)
624 return true;
625
626 lightmap = uLightType & 1 ? &std__vector_000004[std__vector_000004_size] ://stationary
627 &std__vector_183808[std__vector_183808_size];//mobile
628 tex_light_radius = radius - dot_dist;
629 flt_3C8C28 = sqrt((radius + radius - tex_light_radius) * tex_light_radius);
630 //flt_3C8C28 = sqrt(tex_light_radius * tex_light_radius);
631 flt_3C8C2C_lightmaps_brightness = 1.0 - (radius - flt_3C8C28) / radius;
632 lightmap->position_x = (double)pos->x - dot_dist * a7->field_4.x;
633 lightmap->position_y = (double)pos->y - dot_dist * a7->field_4.y;
634 lightmap->position_z = (double)pos->z - dot_dist * a7->field_4.z;
635
636 flt_3C8C30 = radius * flt_3C8C2C_lightmaps_brightness;
637 flt_3C8C0C = flt_3C8C30 * a7->field_10.x;
638 flt_3C8C10 = flt_3C8C30 * a7->field_10.y;
639 flt_3C8C14 = flt_3C8C30 * a7->field_10.z;
640
641 flt_3C8C18 = flt_3C8C30 * a7->field_1C.x;
642 flt_3C8C1C = flt_3C8C30 * a7->field_1C.y;
643 flt_3C8C20 = flt_3C8C30 * a7->field_1C.z;
644
645 lightmap->pVertices[0].vWorldPosition.x = lightmap->position_x - flt_3C8C18 + flt_3C8C0C;
646 lightmap->pVertices[0].vWorldPosition.y = lightmap->position_y - flt_3C8C1C + flt_3C8C10;
647 lightmap->pVertices[0].vWorldPosition.z = lightmap->position_z - flt_3C8C20 + flt_3C8C14;
648 lightmap->pVertices[0].u = 0.0;
649 lightmap->pVertices[0].v = 0.0;
650
651 lightmap->pVertices[1].vWorldPosition.x = lightmap->position_x - flt_3C8C18 - flt_3C8C0C;
652 lightmap->pVertices[1].vWorldPosition.y = lightmap->position_y - flt_3C8C1C - flt_3C8C10;
653 lightmap->pVertices[1].vWorldPosition.z = lightmap->position_z - flt_3C8C20 - flt_3C8C14;
654 lightmap->pVertices[1].u = 0.0;
655 lightmap->pVertices[1].v = 1.0;
656
657 lightmap->pVertices[2].vWorldPosition.x = lightmap->position_x + flt_3C8C18 - flt_3C8C0C;
658 lightmap->pVertices[2].vWorldPosition.y = lightmap->position_y + flt_3C8C1C - flt_3C8C10;
659 lightmap->pVertices[2].vWorldPosition.z = lightmap->position_z + flt_3C8C20 - flt_3C8C14;
660 lightmap->pVertices[2].u = 1.0;
661 lightmap->pVertices[2].v = 1.0;
662
663 lightmap->pVertices[3].vWorldPosition.x = lightmap->position_x + flt_3C8C18 + flt_3C8C0C;
664 lightmap->pVertices[3].vWorldPosition.y = lightmap->position_y + flt_3C8C1C + flt_3C8C10;
665 lightmap->pVertices[3].vWorldPosition.z = lightmap->position_z + flt_3C8C20 + flt_3C8C14;
666 lightmap->pVertices[3].u = 1.0;
667 lightmap->pVertices[3].v = 0.0;
668
669 for (uint i = 0; i < 4; ++i)
670 {
671 v24 = a7->field_4.y * lightmap->pVertices[i].vWorldPosition.y
672 + a7->field_4.z * lightmap->pVertices[i].vWorldPosition.z
673 + a7->field_4.x * lightmap->pVertices[i].vWorldPosition.x
674 + a7->dist;
675
676 lightmap->pVertices[i].vWorldPosition.x -= v24 * a7->field_4.x;
677 lightmap->pVertices[i].vWorldPosition.y -= v24 * a7->field_4.y;
678 lightmap->pVertices[i].vWorldPosition.z -= v24 * a7->field_4.z;
679 }
680
681 lightmap->uColorMask = uColorMask;
682 lightmap->NumVertices = 4;
683
684 //Brightness(ÿðêîñòü)/////////////////////////////////
685 if (~pGame->uFlags2 & 4)
686 lightmap->fBrightness = flt_3C8C2C_lightmaps_brightness;
687 else
688 {
689 Vec3_float_ a1; // [sp+2Ch] [bp-20h]@8
690 a1.x = (double)pos->x - lightmap->position_x;
691 a1.y = (double)pos->y - lightmap->position_y;
692 a1.z = (double)pos->z - lightmap->position_z;
693 a1.Normalize();
694
695 auto temp1 = lightmap->position_x + 0.5f,
696 temp2 = lightmap->position_y + 0.5f,
697 temp3 = lightmap->position_z + 0.5f;
698
699 auto dist_x = abs(pos->x - temp1), //v31
700 dist_y = abs(pos->y - temp2), //v32 arg0a
701 dist_z = abs(pos->z - temp3); //v33 _v64
702 v38 = int_get_vector_length(dist_x, dist_y, dist_z);
703 if (v38 > radius)
704 return true;
705 //radius = (1 / radius) * v38;
706 if ( uLightType & 4 )
707 {
708 v39 = fabs(a1.x * a7->field_4.x + a1.z * a7->field_4.z + a1.y * a7->field_4.y);
709 v40 = v39 * 1.0 * flt_4D86CC;
710
711 lightmap->fBrightness = v40 - ((1 / radius) * v38) * v40;
712 }
713 else if ( uLightType & 8 )
714 {
715 v40 = 1.0 * 1.0;
716 lightmap->fBrightness = v40 - ((1 / radius) * v38);
717 }
718 else
719 MessageBoxW(nullptr, L"Invalid light type!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:277", 0);
720 }
721 //Brightness(ÿðêîñòü)/////////////////////////////////////////////////////
722
723 if (!pGame->pStru9Instance->_4980B9(a9, uNumVertices,
724 a7->field_4.x, a7->field_4.y, a7->field_4.z,
725 lightmap->pVertices, &lightmap->NumVertices))
726 return false;
727
728 if (!lightmap->NumVertices)
729 return true;
730
731 v45 = _45C6D6(uNumVertices, a9, lightmap);
732 if ( v45 != uNumVertices && v45 > 0 )
733 _45C4B9(uNumVertices, a9, lightmap);
734
735 pGame->pIndoorCameraD3D->ViewTransform(lightmap->pVertices, lightmap->NumVertices);
736 pGame->pIndoorCameraD3D->Project(lightmap->pVertices, lightmap->NumVertices, 0);
737
738 unsigned int _a4 = 0;
739 if ( !(uClipFlag & 1) )
740 _a4 = 1;
741 else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
742 {
743 if ( uClipFlag & 2 )
744 {
745 pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
746 pGame->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
747 }
748 else if ( uClipFlag & 4 )
749 {
750 pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
751 pGame->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
752 }
753 else
754 MessageBoxW(nullptr, L"Undefined clip flag specified", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330", 0);
755 }
756 else
757 MessageBoxW(nullptr, L"Lightpoly builder native indoor clipping not implemented", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:335", 0);
758
759 if (_a4)
760 {
761 if (uLightType & 1)
762 {
763 if (std__vector_000004_size < 512 - 1)
764 ++std__vector_000004_size;
765 }
766 else
767 {
768 if (std__vector_183808_size < 768 - 1)
769 ++std__vector_183808_size;
770 }
771 //if ( v50 ^ v51 )
772 // *(unsigned int *)v48 = v49 + 1;
773 }
774 return true;
775 }
776
777 //----- (0045C6D6) --------------------------------------------------------
778 int LightmapBuilder::_45C6D6(int a2, RenderVertexSoft *a3, Lightmap *pLightmap)
779 {
780 //For outdoor terrain and indoor light (V)(V)
781 signed int v6; // esi@1
782 float temp_x; // st7@6
783 float temp_y; // st6@10
784 float temp_z; // st5@14
785 float v12; // st7@17
786 int v15; // [sp+Ch] [bp-8h]@1
787
788 v6 = -1;
789 v15 = 0;
790 if ( (signed int)pLightmap->NumVertices > 0 )
791 {
792 for ( uint i = 0; i < (signed int)pLightmap->NumVertices; ++i )
793 {
794 if ( a2 > 0 )
795 {
796 for ( uint j = 0; j < a2; ++j )
797 {
798 if ( pLightmap->pVertices[i].vWorldPosition.x <= (double)a3[j].vWorldPosition.x )
799 temp_x = a3[j].vWorldPosition.x - pLightmap->pVertices[i].vWorldPosition.x;
800 else
801 temp_x = pLightmap->pVertices[i].vWorldPosition.x - a3[j].vWorldPosition.x;
802 if ( temp_x < 2.0 )
803 {
804 if ( pLightmap->pVertices[i].vWorldPosition.y <= (double)a3[j].vWorldPosition.y )
805 temp_y = a3[j].vWorldPosition.y - pLightmap->pVertices[i].vWorldPosition.y;
806 else
807 temp_y = pLightmap->pVertices[i].vWorldPosition.y - a3[j].vWorldPosition.y;
808 if ( temp_y < 2.0 )
809 {
810 if ( pLightmap->pVertices[i].vWorldPosition.z <= (double)a3[j].vWorldPosition.z )
811 temp_z = a3[j].vWorldPosition.z - pLightmap->pVertices[i].vWorldPosition.z;
812 else
813 temp_z = pLightmap->pVertices[i].vWorldPosition.z - a3[j].vWorldPosition.z;
814 if ( temp_z < 2.0 )
815 {
816 v12 = temp_x + temp_y + temp_z;
817 if ( v12 < FLT_MAX )
818 v6 = j;
819 }
820 }
821 }
822 }//For
823 if ( v6 != -1 )
824 {
825 ++v15;
826 pLightmap->pVertices[i].vWorldPosition.x = a3[v6].vWorldPosition.x;
827 pLightmap->pVertices[i].vWorldPosition.y = a3[v6].vWorldPosition.y;
828 pLightmap->pVertices[i].vWorldPosition.z = a3[v6].vWorldPosition.z;
829 }
830 }
831 v6 = -1;
832 }//For
833 }
834 return v15;
835 }
836
837 //----- (0045D73F) --------------------------------------------------------
838 void LightmapBuilder::DrawLightmapsType(int type)
839 {
840 //For outdoor and indoor light (II)(VIII)
841 if (type == 2)
842 Draw_183808_Lightmaps();
843 }
844
845 //----- (0045D74F) --------------------------------------------------------
846 bool LightmapBuilder::DrawLightmaps(int *indices)
847 {
848 //For outdoor terrain and indoor light (VI)(VI)
849 Lightmap *v28; // [sp+50h] [bp-38h]@2
850 Vec3_float_ arg4;
851
852 if (std__vector_000004_size == 0)
853 return true;
854
855 if (byte_4D864C && pGame->uFlags & GAME_FLAGS_1_01_lightmap_related)
856 return true;
857
858 pRenderer->BeginLightmaps();
859
860 arg4.x = 1.0f;
861 arg4.y = 1.0f;
862 arg4.z = 1.0f;
863 if (indices)
864 {
865 for (int* i = indices; *i != -1; ++i)
866 {
867 __debugbreak();//Not used?
868 v28 = &std__vector_000004[*i];
869 if ( !pRenderer->DrawLightmap(v28, &arg4, 0.0) )
870 Error("Invalid lightmap detected! (%u)", *i);
871 }
872 }
873 else
874 if (for_refactoring)
875 {
876 for (unsigned int i = 0; i < std__vector_000004_size; ++i)
877 if ( !pRenderer->DrawLightmap(std__vector_000004 + i, &arg4, 0.0) )
878 Error("Invalid lightmap detected! (%u)", i);
879 }
880
881 pRenderer->EndLightmaps();
882
883 return true;
884 }
885
886 //----- (0045DAE8) --------------------------------------------------------
887 bool Render::DrawLightmap(Lightmap *pLightmap, Vec3_float_ *pColorMult, float z_bias)
888 {
889 //For outdoor terrain and indoor light (VII)(VII)
890 signed int dwFlags; // [sp-1Ch] [bp-670h]@13
891 RenderVertexD3D3 pVerticesD3D[64]; // [sp+0h] [bp-654h]@7
892
893 if (pLightmap->NumVertices < 3)
894 {
895 Log::Warning(L"Lightmap uNumVertices < 3");
896 return false;
897 }
898
899 uint uLightmapColorMaskR = (pLightmap->uColorMask >> 16) & 0xFF,
900 uLightmapColorMaskG = (pLightmap->uColorMask >> 8) & 0xFF,
901 uLightmapColorMaskB = pLightmap->uColorMask & 0xFF;
902
903 uint uLightmapColorR = floorf(uLightmapColorMaskR * pLightmap->fBrightness * pColorMult->x + 0.5f),
904 uLightmapColorG = floorf(uLightmapColorMaskG * pLightmap->fBrightness * pColorMult->y + 0.5f),
905 uLightmapColorB = floorf(uLightmapColorMaskB * pLightmap->fBrightness * pColorMult->z + 0.5f);
906
907 for (uint i = 0; i < pLightmap->NumVertices; ++i)
908 {
909 float v18;
910 if (fabs(z_bias) < 1e-5)
911 v18 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0);
912 else
913 {
914 v18 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias;
915 if (v18 < 0.000099999997)
916 v18 = 0.000099999997;
917 }
918
919 pVerticesD3D[i].pos.x = pLightmap->pVertices[i].vWorldViewProjX;
920 pVerticesD3D[i].pos.y = pLightmap->pVertices[i].vWorldViewProjY;
921 pVerticesD3D[i].pos.z = v18;
922
923 pVerticesD3D[i].rhw = 1.0 / pLightmap->pVertices[i].vWorldViewPosition.x;
924 pVerticesD3D[i].diffuse = (uLightmapColorMaskR << 16) | (uLightmapColorMaskG << 8) | uLightmapColorB;
925 pVerticesD3D[i].specular = 0;
926
927 pVerticesD3D[i].texcoord.x = pLightmap->pVertices[i].u;
928 pVerticesD3D[i].texcoord.y = pLightmap->pVertices[i].v;
929 }
930
931 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
932 dwFlags = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS;
933 else
934 dwFlags = D3DDP_DONOTLIGHT;
935
936 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
937 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
938 pVerticesD3D, pLightmap->NumVertices, dwFlags));
939
940 return true;
941 }
942
943 //----- (0045DCA9) --------------------------------------------------------
944 void LightmapBuilder::Draw_183808_Lightmaps()
945 {
946 //For outdoor and indoor light (III)(IX)
947 if (!std__vector_183808_size)
948 return;
949
950 pRenderer->BeginLightmaps2();
951
952 DoDraw_183808_Lightmaps(0.00050000002);
953
954 pRenderer->EndLightmaps2();
955 }
956
957
958 ////////////////////////OTHER////////////////////////////////////////////////////////
959 //----- (0045CA88) --------------------------------------------------------
960 int LightmapBuilder::_45CA88(stru320 *a2, RenderVertexSoft *a3, int a4, Vec3_float_ *pNormal)
961 {
962 int result; // eax@1
963 stru320 *v6; // ecx@2
964 RenderVertexSoft *v7; // ebx@2
965 double v8; // st7@2
966 double v9; // st6@2
967 char *v10; // eax@3
968 double v11; // st7@5
969 __int64 v12; // ST2C_8@5
970 float v13; // edx@5
971 int v14; // eax@5
972 float v15; // ST10_4@5
973 Vec3_float_ v16; // ST00_12@5
974 double v17; // st7@5
975 int a5; // [sp+2Ch] [bp-1Ch]@1
976 float v19; // [sp+30h] [bp-18h]@1
977 float v20; // [sp+34h] [bp-14h]@1
978 //LightmapBuilder *thisa; // [sp+38h] [bp-10h]@1
979 int v22; // [sp+3Ch] [bp-Ch]@1
980 int *j; // [sp+40h] [bp-8h]@3
981 int i; // [sp+44h] [bp-4h]@1
982 int a3a; // [sp+58h] [bp+10h]@2
983
984 __debugbreak();//Not used?
985
986 *(float *)&a5 = 0.0;
987 v19 = 0.0;
988 //thisa = this;
989 v20 = 0.0;
990 result = _45CBD4(a3, a4, dword_69B010.data(), &v22);
991 for ( i = 0; i < v22; result = i )
992 {
993 v6 = a2;
994 a3a = 0;
995 v7 = &a3[dword_69B010[i]];
996 v8 = v7->vWorldPosition.z;
997 v9 = v7->vWorldPosition.y;
998 *(float *)&a5 = v7->vWorldPosition.x;
999 v19 = v9;
1000 v20 = v8;
1001 v7->flt_2C = 0.0;
1002 if ( a2->uNumLightsApplied > 0 )
1003 {
1004 v10 = (char *)a2->_blv_lights_ys;
1005 for ( j = a2->_blv_lights_ys; ; v10 = (char *)j )
1006 {
1007 v11 = (double)*((signed int *)v10 - 60);
1008 LODWORD(v12) = *((unsigned int *)v10 - 20);
1009 HIDWORD(v12) = *(unsigned int *)v10;
1010 LODWORD(v13) = *((unsigned int *)v10 + 60);
1011 v14 = a3a;
1012 LOBYTE(v14) = v6->_blv_lights_types[a3a];
1013 v15 = v11;
1014 *(_QWORD *)&v16.x = v12;
1015 v16.z = v13;
1016 v17 = _45CC0C_light(v16/*COERCE_VEC3_FLOAT_(v16.x)*/, 1.0, v15, pNormal, *(float *)&a5/*COERCE_FLOAT(&a5)*/, v14)
1017 + v7->flt_2C;
1018 ++a3a;
1019 ++j;
1020 v7->flt_2C = v17;
1021 if ( a3a >= a2->uNumLightsApplied )
1022 break;
1023 v6 = a2;
1024 }
1025 }
1026 ++i;
1027 }
1028 return result;
1029 }
1030
1031 //----- (0045CB89) --------------------------------------------------------
1032 int LightmapBuilder::_45CB89(RenderVertexSoft *a1, int a2)
1033 {
1034 int v3; // edx@1
1035 int result; // eax@2
1036 char *v5; // ecx@2
1037 double v6; // st7@4
1038 __int16 v7; // fps@4
1039 char v8; // c0@4
1040 char v9; // c2@4
1041 char v10; // c3@4
1042 double v11; // st7@5
1043 double v12; // st7@6
1044 __int16 v13; // fps@6
1045 char v14; // c0@6
1046 char v15; // c2@6
1047 char v16; // c3@6
1048
1049 __debugbreak();//Not used?
1050 v3 = a2;
1051 if ( a2 > 0 )
1052 {
1053 HIWORD(result) = HIWORD(a1);
1054 v5 = (char *)&a1->flt_2C;
1055 do
1056 {
1057 __debugbreak(); // warning C4700: uninitialized local variable 'v7' used
1058 if ( *(float *)v5 < 0.0
1059 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) )
1060 {
1061 v12 = *(float *)v5;
1062 //UNDEF(v13);
1063 v14 = 0.0 < v12;
1064 v15 = 0;
1065 v16 = 0.0 == v12;
1066 __debugbreak(); // warning C4700: uninitialized local variable 'v13' used
1067 LOWORD(result) = v13;
1068 if ( v12 >= 0.0 )
1069 v11 = *(float *)v5;
1070 else
1071 v11 = 0.0;
1072 }
1073 else
1074 {
1075 v11 = 1.0;
1076 }
1077 *(float *)v5 = v11;
1078 v5 += 48;
1079 --v3;
1080 }
1081 while ( v3 );
1082 }
1083 return result;
1084 }
1085
1086 //----- (0045CBD4) --------------------------------------------------------
1087 int LightmapBuilder::_45CBD4(RenderVertexSoft *a2, int a3, int *a4, int *a5)
1088 {
1089 int result; // eax@1
1090 int v6; // edx@1
1091 int v7; // ecx@2
1092 int v8; // esi@2
1093
1094 __debugbreak();//Not used?
1095 result = (int)a5;
1096 v6 = 0;
1097 for ( *a5 = 0; v6 < a3; ++v6 )
1098 {
1099 v7 = *a5;
1100 v8 = 0;
1101 if ( *a5 <= 0 )
1102 {
1103 //LABEL_5:
1104 a4[v7] = v6;
1105 ++*a5;
1106 }
1107 else
1108 {
1109 while ( a4[v8] != v6 )
1110 {
1111 ++v8;
1112 if (v8 >= v7)
1113 {
1114 a4[v7] = v6;
1115 ++*a5;
1116 break;
1117 //goto LABEL_5;
1118 }
1119 }
1120 }
1121 }
1122 return result;
1123 }
1124
1125 //----- (0045CC0C) --------------------------------------------------------
1126 double LightmapBuilder::_45CC0C_light(Vec3_float_ a1, float a2, float a3, Vec3_float_ *pNormal, float a5, int uLightType)
1127 {
1128 float v7; // esi@1
1129 int v8; // eax@1
1130 double v14; // st7@7
1131 double result; // st7@8
1132 double v16; // st7@9
1133 int v17; // esi@9
1134 const char *v18; // ecx@9
1135 double v19; // st7@10
1136 double v20; // st7@10
1137 std::string v21; // [sp-10h] [bp-40h]@13
1138 const char *v22[6]; // [sp+0h] [bp-30h]@10
1139 double v23; // [sp+18h] [bp-18h]@1
1140 // double v24; // [sp+20h] [bp-10h]@1
1141 int v25; // [sp+28h] [bp-8h]@1
1142 int v26; // [sp+2Ch] [bp-4h]@1
1143
1144 __debugbreak();//Not used?
1145 v7 = a5;
1146 LODWORD(a5) = *(unsigned int *)(LODWORD(a5) + 8);
1147 //v24 = a5 + 6.7553994e15;
1148 v26 = floorf(a5 + 0.5f);//LODWORD(v24);
1149 LODWORD(a5) = *(unsigned int *)(LODWORD(v7) + 4);
1150 //v24 = a5 + 6.7553994e15;
1151 auto _v24 = floorf(a5 + 0.5f);
1152 LODWORD(a5) = *(unsigned int *)LODWORD(v7);
1153 //v23 = a5 + 6.7553994e15;
1154 auto _v23 = floorf(a5 + 0.5f);
1155 //*(_QWORD *)((char *)&v24 + 4) = __PAIR__(LODWORD(v24), LODWORD(v23));
1156 v26 = abs((signed)LODWORD(a1.z) - v26);
1157 //v25 = abs((signed)LODWORD(a1.y) - (signed)LODWORD(v24));
1158 //v8 = abs((int)a1.x - (signed)LODWORD(v23));
1159 v25 = abs((signed)LODWORD(a1.y) - (signed)_v24);
1160 v8 = abs((int)a1.x - (signed)_v23);
1161 v14 = int_get_vector_length(v26, v25, v8);
1162 if ( v14 <= a3 )
1163 {
1164 a5 = v14 / a3;
1165 v16 = (double)(signed int)a1.x;
1166 *(float *)&v23 = (double)SLODWORD(a1.y);
1167 LODWORD(a1.x) = *(unsigned int *)LODWORD(v7);
1168 v17 = LODWORD(v7) + 4;
1169 *((float *)&v23 + 1) = (double)SLODWORD(a1.z);
1170 LODWORD(a1.y) = *(unsigned int *)v17;
1171 LODWORD(a1.z) = *(unsigned int *)(v17 + 4);
1172 a3 = *((float *)&v23 + 1) - a1.z;
1173 a1.z = a3;
1174 a1.x = v16 - a1.x;
1175 a1.y = (float)v23 - a1.y;
1176 a1.Normalize();
1177 if ( uLightType & 4 )
1178 {
1179 __debugbreak(); // warning C4700: uninitialized local variable 'v18' used
1180 v22[1] = v18;
1181 uLightType = dword_4D86D8;
1182 v22[0] = v18;
1183 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x);
1184 v20 = v19 * *(float *)&uLightType * a2;
1185 }
1186 else
1187 {
1188 if ( uLightType & 8 )
1189 {
1190 v20 = 1.3 * a2;
1191 }
1192 else
1193 {
1194 MessageBoxW(nullptr, L"Invalid light type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:783", 0);
1195 v20 = *(float *)&uLightType;
1196 }
1197 }
1198 result = v20 - a5 * v20;
1199 }
1200 else
1201 {
1202 result = 0.0;
1203 }
1204 return result;
1205 }
1206
1207 // 4D86D8: using guessed type int dword_4D86D8;
1208 // 4E94D2: using guessed type char _4E94D2_light_type;
1209 // 519AB4: using guessed type int uNumStationaryLightsApplied;
1210
1062 //----- (0045D698) -------------------------------------------------------- 1211 //----- (0045D698) --------------------------------------------------------
1063 bool LightmapBuilder::DrawDebugOutlines(char bit_one_for_list1__bit_two_for_list2) 1212 bool LightmapBuilder::DrawDebugOutlines(char bit_one_for_list1__bit_two_for_list2)
1064 { 1213 {
1065 bool result; // eax@1 1214 bool result; // eax@1
1066 LightmapBuilder *v3; // esi@1 1215 LightmapBuilder *v3; // esi@1
1068 RenderVertexSoft *v5; // edi@7 1217 RenderVertexSoft *v5; // edi@7
1069 IndoorCameraD3D *thisa; // [sp+10h] [bp-8h]@1 1218 IndoorCameraD3D *thisa; // [sp+10h] [bp-8h]@1
1070 bool v7; // [sp+14h] [bp-4h]@2 1219 bool v7; // [sp+14h] [bp-4h]@2
1071 bool a2a; // [sp+20h] [bp+8h]@6 1220 bool a2a; // [sp+20h] [bp+8h]@6
1072 1221
1222 __debugbreak();//Not used?
1073 result = (bool)pGame->pIndoorCameraD3D; 1223 result = (bool)pGame->pIndoorCameraD3D;
1074 v3 = this; 1224 v3 = this;
1075 thisa = pGame->pIndoorCameraD3D; 1225 thisa = pGame->pIndoorCameraD3D;
1076 if ( bit_one_for_list1__bit_two_for_list2 & 1 ) 1226 if ( bit_one_for_list1__bit_two_for_list2 & 1 )
1077 { 1227 {
1106 } 1256 }
1107 } 1257 }
1108 LOBYTE(result) = 1; 1258 LOBYTE(result) = 1;
1109 return result; 1259 return result;
1110 } 1260 }
1111
1112 //----- (0045D73F) --------------------------------------------------------
1113 void LightmapBuilder::DrawLightmapsType(int type)
1114 {
1115 if (type == 2)
1116 Draw_183808_Lightmaps();
1117 }
1118
1119 //----- (0045D74F) --------------------------------------------------------
1120 bool LightmapBuilder::DrawLightmaps(int *indices)
1121 {
1122 std::string v25; // [sp+44h] [bp-44h]@12
1123 Lightmap *v28; // [sp+50h] [bp-38h]@2
1124 Vec3_float_ arg4;
1125
1126 if (std__vector_000004_size == 0)
1127 return true;
1128
1129 if (byte_4D864C && pGame->uFlags & GAME_FLAGS_1_01_lightmap_related)
1130 return true;
1131
1132 pRenderer->BeginLightmaps();
1133
1134 arg4.x = 1.0f;
1135 arg4.y = 1.0f;
1136 arg4.z = 1.0f;
1137 if (indices)
1138 {
1139 for (int* i = indices; *i != -1; ++i)
1140 {
1141 v28 = &std__vector_000004[*i];
1142 if ( !pRenderer->DrawLightmap(v28, &arg4, 0.0) )
1143 Error("Invalid lightmap detected! (%u)", *i);
1144 }
1145 }
1146 else
1147 {
1148 for (unsigned int i = 0; i < std__vector_000004_size; ++i)
1149 {
1150 Lightmap* _a1 = &std__vector_000004[(int)i];
1151 if ( !pRenderer->DrawLightmap(_a1, &arg4, 0.0) )
1152 Error("Invalid lightmap detected! (%u)", i);
1153 }
1154 }
1155
1156 pRenderer->EndLightmaps();
1157
1158 return true;
1159 }
1160
1161
1162 //----- (0045DA56) --------------------------------------------------------
1163 bool LightmapBuilder::DoDraw_183808_Lightmaps(float z_bias)
1164 {
1165 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2
1166 v.z = 1.0;
1167 v.y = 1.0;
1168 v.x = 1.0;
1169
1170 for (uint i = 0; i < std__vector_183808_size; ++i)
1171 if (!pRenderer->DrawLightmap(std__vector_183808 + i, &v, z_bias))
1172 Error("Invalid lightmap detected! (%u)", i);
1173
1174 return true;
1175 }
1176
1177 //----- (0045DAE8) --------------------------------------------------------
1178 bool Render::DrawLightmap(Lightmap *pLightmap, Vec3_float_ *pColorMult, float z_bias)
1179 {
1180 double v10; // st7@4
1181 double v14; // st7@7
1182 double v18; // st3@8
1183 signed int v24; // [sp-1Ch] [bp-670h]@13
1184 RenderVertexD3D3 a2[32]; // [sp+0h] [bp-654h]@7
1185
1186
1187 if (pLightmap->uNumVertices < 3)
1188 {
1189 Log::Warning(L"Lightmap uNumVertices < 3");
1190 return false;
1191 }
1192
1193 uint uLightmapColorMaskR = (pLightmap->uColorMask >> 16) & 0xFF;
1194 uint uLightmapColorR = floorf(uLightmapColorMaskR * pLightmap->fBrightness * pColorMult->x + 0.5f);
1195
1196 uint uLightmapColorMaskG = (pLightmap->uColorMask >> 8) & 0xFF;
1197 uint uLightmapColorG = floorf(uLightmapColorMaskG * pLightmap->fBrightness * pColorMult->y + 0.5f);
1198
1199 uint uLightmapColorMaskB = pLightmap->uColorMask & 0xFF;
1200 uint uLightmapColorB = floorf(uLightmapColorMaskB * pLightmap->fBrightness * pColorMult->z + 0.5f);
1201
1202 uint uLightmapColor = uLightmapColorB | (uLightmapColorMaskG << 8) | (uLightmapColorMaskR << 16);
1203
1204 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
1205 v10 = (double)pODMRenderParams->shading_dist_mist;
1206 else
1207 v10 = 16192.0;
1208 v14 = 1.0 / v10;
1209
1210 for (uint i = 0; i < pLightmap->uNumVertices; ++i)
1211 {
1212 v18 = 1.0 - 1.0 / (v14 * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0);
1213 if (fabsf(z_bias) < 1e-5f)
1214 {
1215 v18 = v18 - z_bias;
1216 if (v18 < 0.000099999997)
1217 v18 = 0.000099999997;
1218 }
1219
1220 a2[i].pos.x = pLightmap->pVertices[i].vWorldViewProjX;
1221 a2[i].pos.z = v18;
1222 a2[i].pos.y = pLightmap->pVertices[i].vWorldViewProjY;
1223 a2[i].rhw = 1.0 / pLightmap->pVertices[i].vWorldViewPosition.x;
1224 a2[i].diffuse = uLightmapColor;
1225 a2[i].specular = 0;
1226 a2[i].texcoord.x = pLightmap->pVertices[i].u;
1227 a2[i].texcoord.y = pLightmap->pVertices[i].v;
1228 }
1229
1230 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
1231 v24 = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS;
1232 else
1233 v24 = D3DDP_DONOTLIGHT;
1234
1235 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
1236 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
1237 a2,
1238 pLightmap->uNumVertices,
1239 v24));
1240
1241 return true;
1242 }
1243
1244 //----- (0045DCA9) --------------------------------------------------------
1245 void LightmapBuilder::Draw_183808_Lightmaps()
1246 {
1247 if (!std__vector_183808_size)
1248 return;
1249
1250 pRenderer->BeginLightmaps2();
1251
1252 DoDraw_183808_Lightmaps(0.00050000002);
1253
1254 pRenderer->EndLightmaps2();
1255 }