Mercurial > mm7
annotate LightmapBuilder.cpp @ 1324:78f0f74eab1d
GetActual(stat) functions changed to similar code
author | Grumpy7 |
---|---|
date | Tue, 02 Jul 2013 00:39:26 +0200 |
parents | 1803172dffd9 |
children | 613c77e51e38 |
rev | line source |
---|---|
0 | 1 #include "LightmapBuilder.h" |
2 #include "Game.h" | |
3 #include "stru314.h" | |
4 #include "Outdoor.h" | |
1277 | 5 #include "Outdoor_stuff.h" |
0 | 6 #include "Log.h" |
7 | |
1016 | 8 #include "OutdoorCamera.h" |
1262 | 9 #include "Lights.h" |
1016 | 10 |
0 | 11 #include "mm7_data.h" |
12 | |
13 | |
14 | |
1016 | 15 #include "stru9.h" |
0 | 16 |
17 | |
18 | |
19 | |
20 LightsStack_StationaryLight_ *pStationaryLightsStack = new LightsStack_StationaryLight_; | |
21 //StationaryLight pStationaryLights[400]; | |
22 //int uNumStationaryLightsApplied; // weak | |
23 LightsStack_MobileLight_ *pMobileLightsStack = new LightsStack_MobileLight_; | |
24 //MobileLight pMobileLights[400]; | |
25 //int uNumMobileLightsApplied; | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 //----- (0045DF13) -------------------------------------------------------- | |
32 Lightmap::Lightmap() | |
33 { | |
34 field_C18 = 0; | |
35 } | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 //----- (0045BB06) -------------------------------------------------------- | |
42 LightmapBuilder::LightmapBuilder() | |
43 { | |
44 } | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 //----- (0045BC07) -------------------------------------------------------- | |
51 bool LightmapBuilder::ApplyLights(stru320 *a2, stru154 *a3, unsigned int uNumVertices, RenderVertexSoft *a5, IndoorCameraD3D_Vec4 *a6, char uClipFlag) | |
52 { | |
53 Vec3_int_ pos; // [sp+2Ch] [bp-40h]@21 | |
54 RenderVertexSoft *a9; // [sp+68h] [bp-4h]@8 | |
55 | |
56 if (!uNumVertices) | |
57 return false; | |
58 | |
59 static RenderVertexSoft static_69B140[64]; | |
60 | |
61 a9 = a5; | |
62 if (a6) | |
63 { | |
64 for (uint i = 0; i < uNumVertices; ++i) | |
65 memcpy(static_69B140 + i, a5 + i, sizeof(RenderVertexSoft)); | |
66 | |
687 | 67 //__debugbreak(); |
0 | 68 if (pGame->pIndoorCameraD3D->_437376( |
69 a3, | |
70 static_69B140, | |
71 &uNumVertices) == 1) | |
72 { | |
73 if ( !uNumVertices ) | |
74 return false; | |
75 a9 = static_69B140; | |
76 } | |
77 } | |
78 | |
79 static stru314 static_69B110; | |
80 static_69B110.field_4.x = a3->face_plane.vNormal.x; | |
81 static_69B110.field_4.y = a3->face_plane.vNormal.y; | |
82 static_69B110.field_4.z = a3->face_plane.vNormal.z; | |
83 static_69B110.dist = a3->face_plane.dist; | |
84 if (!pGame->pIndoorCameraD3D->GetFacetOrientation( | |
85 a3->polygonType, | |
86 &static_69B110.field_4, | |
87 &static_69B110.field_10, | |
88 &static_69B110.field_1C)) | |
89 { | |
90 MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0); | |
91 ExitProcess(0); | |
92 } | |
93 | |
94 for (uint i = 0; i < a2->uNumLightsApplied; ++i) | |
95 { | |
96 pos.x = a2->_blv_lights_xs[i]; | |
97 pos.y = a2->_blv_lights_ys[i]; | |
98 pos.z = a2->_blv_lights_zs[i]; | |
99 | |
100 uint uColorR = (uint)floorf(a2->_blv_lights_rs[i] * 255.0 + 0.5f) & 0xFF, | |
101 uColorG = (uint)floorf(a2->_blv_lights_gs[i] * 255.0 + 0.5f) & 0xFF, | |
102 uColorB = (uint)floorf(a2->_blv_lights_bs[i] * 255.0 + 0.5f) & 0xFF; | |
103 uint uColor = (uColorR << 16) | (uColorG << 8) | uColorB; | |
104 if (!uColor) | |
105 uColor = 0x00FFFFF; | |
106 | |
107 if (!_45BE86_build_light_polygon( | |
108 &pos, | |
109 a2->_blv_lights_radii[i], | |
110 uColor, | |
111 a2->_blv_lights_light_dot_faces[i], | |
112 a2->_blv_lights_types[i], | |
113 &static_69B110, | |
114 uNumVertices, | |
115 a9, | |
116 uClipFlag) ) | |
117 { | |
118 MessageBoxW(nullptr, L"Error: Failed to build light polygon", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:138", 0); | |
119 } | |
120 } | |
121 return true; | |
122 } | |
123 | |
124 //----- (0045BE86) -------------------------------------------------------- | |
125 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) | |
126 { | |
127 Lightmap *v11; // edi@3 | |
128 double v17; // st7@5 | |
129 double v24; // st7@6 | |
130 int v31; // eax@8 | |
131 int v32; // ebx@8 | |
132 unsigned int v33; // ecx@8 | |
133 int v34; // edx@9 | |
134 int v35; // edx@11 | |
135 unsigned int v36; // edx@13 | |
136 int v37; // ecx@14 | |
137 double v38; // st7@14 | |
138 double v39; // st7@16 | |
139 double v40; // st7@16 | |
140 int v45; // eax@24 | |
141 int v53; // [sp-8h] [bp-54h]@34 | |
142 | |
143 if (fabsf(radius) < 1e-6f) | |
144 return true; | |
145 | |
146 v11 = uLightType & 1 ? &std__vector_000004[std__vector_000004_size] : | |
147 &std__vector_183808[std__vector_183808_size]; | |
148 flt_3C8C24 = radius - dot_dist; | |
149 flt_3C8C28 = sqrt((radius + dot_dist) * (radius - dot_dist)); | |
150 flt_3C8C2C_lightmaps_brightness = 1.0 - (radius - flt_3C8C28) / radius; | |
151 v11->field_C08 = (double)pos->x - dot_dist * a7->field_4.x; | |
152 v11->field_C0A = (double)pos->y - dot_dist * a7->field_4.y; | |
153 v11->field_C0C = (double)pos->z - dot_dist * a7->field_4.z; | |
154 | |
155 v17 = radius * flt_3C8C2C_lightmaps_brightness; | |
156 flt_3C8C30 = v17; | |
157 flt_3C8C0C = v17 * a7->field_10.x; | |
158 flt_3C8C10 = v17 * a7->field_10.y; | |
159 flt_3C8C14 = v17 * a7->field_10.z; | |
160 flt_3C8C18 = v17 * a7->field_1C.x; | |
161 flt_3C8C1C = v17 * a7->field_1C.y; | |
162 flt_3C8C20 = v17 * a7->field_1C.z; | |
163 | |
164 /* | |
165 v11->pVertices[0].vWorldPosition.x = v11->field_C08 - flt_3C8C18 + flt_3C8C0C; | |
166 v11->pVertices[0].vWorldPosition.y = v11->field_C0A - flt_3C8C1C + flt_3C8C10; | |
167 v11->pVertices[0].vWorldPosition.z = v11->field_C0C - flt_3C8C20 + flt_3C8C14; | |
168 v11->pVertices[0].u = 0.0; | |
169 v11->pVertices[0].v = 0.0; | |
170 | |
171 v11->pVertices[1].vWorldPosition.x = v11->field_C08 - flt_3C8C18 - flt_3C8C0C; | |
172 v11->pVertices[1].vWorldPosition.y = v11->field_C0A - flt_3C8C1C - flt_3C8C10; | |
173 v11->pVertices[1].vWorldPosition.z = v11->field_C0C - flt_3C8C20 - flt_3C8C14; | |
174 v11->pVertices[1].u = 0.0; | |
175 v11->pVertices[1].v = 1.0; | |
176 | |
177 v11->pVertices[2].vWorldPosition.x = v11->field_C08 + flt_3C8C18 - flt_3C8C0C; | |
178 v11->pVertices[2].vWorldPosition.y = v11->field_C0A + flt_3C8C1C - flt_3C8C10; | |
179 v11->pVertices[2].vWorldPosition.z = v11->field_C0C + flt_3C8C20 - flt_3C8C14; | |
180 v11->pVertices[2].u = 1.0; | |
181 v11->pVertices[2].v = 1.0; | |
182 | |
183 v11->pVertices[3].vWorldPosition.x = v11->field_C08 + flt_3C8C18 + flt_3C8C0C; | |
184 v11->pVertices[3].vWorldPosition.y = v11->field_C0A + flt_3C8C1C + flt_3C8C10; | |
185 v11->pVertices[3].vWorldPosition.z = v11->field_C0C + flt_3C8C20 + flt_3C8C14; | |
186 v11->pVertices[3].u = 1.0; | |
187 v11->pVertices[3].v = 0.0; | |
188 */ | |
189 | |
190 for (uint i = 0; i < 4; ++i) | |
191 { | |
192 v11->pVertices[i].vWorldPosition.x = v11->field_C08 - flt_3C8C18 + flt_3C8C0C; | |
193 v11->pVertices[i].vWorldPosition.y = v11->field_C0A - flt_3C8C1C + flt_3C8C10; | |
194 v11->pVertices[i].vWorldPosition.z = v11->field_C0C - flt_3C8C20 + flt_3C8C14; | |
195 v11->pVertices[i].u = 0.0; | |
196 v11->pVertices[i].v = 0.0; | |
197 | |
198 v24 = a7->field_4.y * v11->pVertices[i].vWorldPosition.y | |
199 + a7->field_4.z * v11->pVertices[i].vWorldPosition.z | |
200 + a7->field_4.x * v11->pVertices[i].vWorldPosition.x | |
201 + a7->dist; | |
202 | |
203 v11->pVertices[i].vWorldPosition.x -= v24 * a7->field_4.x; | |
204 v11->pVertices[i].vWorldPosition.y -= v24 * a7->field_4.y; | |
205 v11->pVertices[i].vWorldPosition.z -= v24 * a7->field_4.z; | |
206 } | |
207 | |
208 v11->uColorMask = uColorMask; | |
209 v11->uNumVertices = 4; | |
210 | |
211 if (~pGame->uFlags2 & 4) | |
212 v11->fBrightness = flt_3C8C2C_lightmaps_brightness; | |
213 else | |
214 { | |
215 Vec3_float_ a1; // [sp+2Ch] [bp-20h]@8 | |
216 a1.x = (double)pos->x - v11->field_C08; | |
217 a1.y = (double)pos->y - v11->field_C0A; | |
218 a1.z = (double)pos->z - v11->field_C0C; | |
219 a1.Normalize(); | |
220 | |
221 auto dist_x = abs(pos->x - v11->field_C08), //v31 | |
222 dist_y = abs(pos->y - v11->field_C0A), //v32 arg0a | |
223 dist_z = abs(pos->z - v11->field_C0C); //v33 _v64 | |
224 v31 = dist_x; | |
225 v32 = dist_y; | |
226 v33 = dist_z; | |
227 if (v31 < dist_y) | |
228 { | |
229 v34 = v31; | |
230 v31 = dist_y; | |
231 v32 = v34; | |
232 } | |
233 if (v31 < dist_z)//SHIDWORD(v64) ) | |
234 { | |
235 v35 = v31; | |
236 v31 = dist_z;//HIDWORD(v64); | |
237 v33 = v35; | |
238 } | |
239 if ( v32 < (signed int)v33 ) | |
240 { | |
241 v36 = v33; | |
242 v33 = v32; | |
243 v32 = v36; | |
244 } | |
245 v37 = v33 >> 2; | |
246 //LODWORD(a5) = ((unsigned int)(11 * v32) >> 5) + v37 + v31; | |
247 v38 = (double)(signed)(((unsigned int)(11 * v32) >> 5) + v37 + v31); | |
248 if (v38 > radius) | |
249 return true; | |
250 //radius = (1 / radius) * v38; | |
251 if ( uLightType & 4 ) | |
252 { | |
253 //v59 = (void *)v37; | |
254 //uLightType = flt_4D86CC; | |
255 //v58 = v37; | |
256 v39 = fabs(a1.x * a7->field_4.x + a1.z * a7->field_4.z + a1.y * a7->field_4.y); | |
257 v40 = v39 * 1.0 * flt_4D86CC; | |
258 | |
259 v11->fBrightness = v40 - (1 / radius) * v38 * v40; | |
260 } | |
261 else if ( uLightType & 8 ) | |
262 { | |
263 v40 = 1.0 * 1.0; | |
264 v11->fBrightness = v40 - (1 / radius) * v38; | |
265 } | |
266 else | |
267 { | |
268 MessageBoxW(nullptr, L"Invalid light type!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:277", 0); | |
269 } | |
270 } | |
271 | |
272 if (!pGame->pStru9Instance->_4980B9(a9, uNumVertices, | |
273 a7->field_4.x, a7->field_4.y, a7->field_4.z, | |
274 v11->pVertices, &v11->uNumVertices)) | |
275 return false; | |
276 | |
277 //v44 = &v11->uNumVertices; | |
278 if (!v11->uNumVertices) | |
279 return true; | |
280 | |
281 v45 = _45C6D6(uNumVertices, a9, v11); | |
282 if ( v45 != uNumVertices && v45 > 0 ) | |
283 _45C4B9(uNumVertices, a9, v11); | |
284 //v59 = v11->uNumVertices; | |
285 //v46 = (RenderVertexSoft *)pLightmapVertices_; | |
286 pGame->pIndoorCameraD3D->ViewTransform(v11->pVertices, v11->uNumVertices); | |
287 //v59 = 0; | |
288 //v58 = v11->uNumVertices; | |
289 pGame->pIndoorCameraD3D->Project(v11->pVertices, v11->uNumVertices, 0); | |
290 | |
291 unsigned int _a4 = 0; | |
292 if ( !(uClipFlag & 1) ) | |
293 _a4 = 1; | |
294 else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
295 { | |
296 if ( uClipFlag & 2 ) | |
297 { | |
298 //v59 = &a4; | |
299 //v58 = (unsigned int)field_3C8C34; | |
300 //v57 = *v44; | |
301 pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(v11->pVertices, v11->uNumVertices, field_3C8C34, &_a4); | |
302 | |
303 //v59 = v44; | |
304 //v58 = (unsigned int)field_3C8C34; | |
305 //v57 = (int)v46; | |
306 //v56 = a4; | |
307 pGame->pIndoorCameraD3D->_437143(_a4, v11->pVertices, field_3C8C34, &v11->uNumVertices); | |
308 } | |
309 else if ( uClipFlag & 4 ) | |
310 { | |
311 //v59 = &a4; | |
312 //v58 = (unsigned int)field_3C8C34; | |
313 //v57 = *v44; | |
314 pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(v11->pVertices, v11->uNumVertices, field_3C8C34, &_a4); | |
315 | |
316 //v59 = v44; | |
317 //v58 = (unsigned int)field_3C8C34; | |
318 //v57 = (int)v46; | |
319 //v56 = a4; | |
320 pGame->pIndoorCameraD3D->_437143(_a4, v11->pVertices, field_3C8C34, &v11->uNumVertices); | |
321 } | |
322 else | |
323 MessageBoxW(nullptr, L"Undefined clip flag specified", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330", 0); | |
324 } | |
325 else | |
326 MessageBoxW(nullptr, L"Lightpoly builder native indoor clipping not implemented", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:335", 0); | |
327 | |
328 if (_a4) | |
329 { | |
330 if (uLightType & 1) | |
331 { | |
332 //v48 = (char *)&std__vector_000004_size; | |
333 //v49 = std__vector_000004_size; | |
334 //v51 = __OFSUB__(std__vector_000004_size, 511); | |
335 //v50 = std__vector_000004_size - 511 < 0; | |
336 if (std__vector_000004_size < 512 - 1) | |
337 ++std__vector_000004_size; | |
338 } | |
339 else | |
340 { | |
341 //v48 = (char *)&std__vector_183808_size; | |
342 //v49 = std__vector_183808_size; | |
343 //v51 = __OFSUB__(std__vector_183808_size, 767); | |
344 //v50 = std__vector_183808_size - 767 < 0; | |
345 if (std__vector_183808_size < 768 - 1) | |
346 ++std__vector_183808_size; | |
347 } | |
348 //if ( v50 ^ v51 ) | |
349 // *(unsigned int *)v48 = v49 + 1; | |
350 } | |
351 return true; | |
352 } | |
353 | |
354 //----- (0045C4B9) -------------------------------------------------------- | |
355 int LightmapBuilder::_45C4B9(int a2, RenderVertexSoft *a3, Lightmap *pLightmap) | |
356 { | |
357 Lightmap *v4; // edi@1 | |
358 int v5; // eax@1 | |
359 signed int v6; // ecx@1 | |
360 RenderVertexSoft *v7; // ebx@2 | |
361 int v8; // edx@3 | |
362 RenderVertexSoft *v9; // esi@3 | |
363 int v10; // eax@6 | |
364 char *v11; // edi@7 | |
365 RenderVertexSoft *v12; // ecx@8 | |
366 char v13; // bl@17 | |
367 signed int v14; // edx@17 | |
368 double v15; // st6@18 | |
369 double v16; // st6@21 | |
370 double v17; // st6@24 | |
371 signed int v18; // edx@33 | |
372 int v20; // [sp+4h] [bp-1Ch]@3 | |
373 int v21; // [sp+8h] [bp-18h]@8 | |
374 float v22; // [sp+Ch] [bp-14h]@23 | |
375 float v23; // [sp+10h] [bp-10h]@20 | |
376 int v24; // [sp+14h] [bp-Ch]@1 | |
377 RenderVertexSoft *v25; // [sp+18h] [bp-8h]@2 | |
378 char v26; // [sp+1Eh] [bp-2h]@17 | |
379 char v27; // [sp+1Fh] [bp-1h]@17 | |
380 | |
381 v4 = pLightmap; | |
382 v5 = 0; | |
383 v6 = pLightmap->uNumVertices; | |
384 v24 = 0; | |
385 if ( v6 > 0 ) | |
386 { | |
387 v7 = pLightmap->pVertices; | |
388 v25 = pLightmap->pVertices; | |
389 do | |
390 { | |
391 v20 = v5 + 1; | |
392 v8 = (v5 + 1) % v6; | |
393 v9 = &v4->pVertices[v8]; | |
394 if ( v7->vWorldPosition.x != v9->vWorldPosition.x | |
395 || v7->vWorldPosition.y != v4->pVertices[v8].vWorldPosition.y | |
396 || v7->vWorldPosition.z != v4->pVertices[v8].vWorldPosition.z ) | |
397 { | |
398 v10 = 0; | |
399 if ( a2 > 0 ) | |
400 { | |
401 v11 = (char *)&a3->vWorldPosition.z; | |
402 do | |
403 { | |
404 v21 = v10 + 1; | |
405 v12 = &a3[(v10 + 1) % a2]; | |
406 if ( (*((float *)v11 - 2) != v12->vWorldPosition.x | |
407 || *((float *)v11 - 1) != v12->vWorldPosition.y | |
408 || *(float *)v11 != v12->vWorldPosition.z) | |
409 && v7->vWorldPosition.x == *((float *)v11 - 2) | |
410 && v7->vWorldPosition.y == *((float *)v11 - 1) | |
411 && v7->vWorldPosition.z == *(float *)v11 | |
412 && (v9->vWorldPosition.x != v12->vWorldPosition.x | |
413 || v9->vWorldPosition.y != v12->vWorldPosition.y | |
414 || v9->vWorldPosition.z != v12->vWorldPosition.z) ) | |
415 { | |
416 v13 = 0; | |
417 v14 = 0; | |
418 v27 = 0; | |
419 v26 = 0; | |
420 if ( v9->vWorldPosition.x <= (double)v12->vWorldPosition.x ) | |
421 v15 = v12->vWorldPosition.x - v9->vWorldPosition.x; | |
422 else | |
423 v15 = v9->vWorldPosition.x - v12->vWorldPosition.x; | |
424 v23 = v15; | |
425 if ( v9->vWorldPosition.y <= (double)v12->vWorldPosition.y ) | |
426 v16 = v12->vWorldPosition.y - v9->vWorldPosition.y; | |
427 else | |
428 v16 = v9->vWorldPosition.y - v12->vWorldPosition.y; | |
429 v22 = v16; | |
430 if ( v9->vWorldPosition.z <= (double)v12->vWorldPosition.z ) | |
431 v17 = v12->vWorldPosition.z - v9->vWorldPosition.z; | |
432 else | |
433 v17 = v9->vWorldPosition.z - v12->vWorldPosition.z; | |
434 if ( v23 < 1.0 ) | |
435 { | |
436 v13 = 1; | |
437 v14 = 1; | |
438 } | |
439 if ( v22 < 1.0 ) | |
440 { | |
441 v27 = 1; | |
442 ++v14; | |
443 } | |
444 if ( v17 < 1.0 ) | |
445 { | |
446 v26 = 1; | |
447 ++v14; | |
448 } | |
449 if ( v14 > 1 ) | |
450 { | |
451 v18 = 0; | |
452 if ( v13 && v9->vWorldPosition.x != v12->vWorldPosition.x ) | |
453 { | |
454 v18 = 1; | |
455 v9->vWorldPosition.x = v12->vWorldPosition.x; | |
456 } | |
457 if ( v27 && v9->vWorldPosition.y != v12->vWorldPosition.y ) | |
458 { | |
459 ++v18; | |
460 v9->vWorldPosition.y = v12->vWorldPosition.y; | |
461 } | |
462 if ( v26 && v9->vWorldPosition.z != v12->vWorldPosition.z ) | |
463 { | |
464 ++v18; | |
465 v9->vWorldPosition.z = v12->vWorldPosition.z; | |
466 } | |
467 if ( v18 > 0 ) | |
468 ++v24; | |
469 } | |
470 v7 = v25; | |
471 } | |
472 ++v10; | |
473 v11 += 48; | |
474 } | |
475 while ( v21 < a2 ); | |
476 v4 = pLightmap; | |
477 } | |
478 } | |
479 v5 = v20; | |
480 v6 = v4->uNumVertices; | |
481 ++v7; | |
482 v25 = v7; | |
483 } | |
484 while ( v20 < v6 ); | |
485 } | |
486 return v24; | |
487 } | |
488 | |
489 //----- (0045C6D6) -------------------------------------------------------- | |
490 int LightmapBuilder::_45C6D6(int a2, RenderVertexSoft *a3, Lightmap *pLightmap) | |
491 { | |
492 Lightmap *v4; // edi@1 | |
493 signed int v5; // ebx@1 | |
494 signed int v6; // esi@1 | |
495 RenderVertexSoft *v7; // ecx@2 | |
496 char *v8; // edx@4 | |
497 double v9; // st7@6 | |
498 double v10; // st6@10 | |
499 double v11; // st5@14 | |
500 double v12; // st7@17 | |
501 RenderVertexSoft *v13; // eax@21 | |
502 int v15; // [sp+Ch] [bp-8h]@1 | |
503 float v16; // [sp+10h] [bp-4h]@1 | |
504 int pLightmapa; // [sp+24h] [bp+10h]@3 | |
505 | |
506 v4 = pLightmap; | |
507 v5 = 0; | |
508 v6 = -1; | |
509 v16 = 3.4028235e38; | |
510 v15 = 0; | |
511 if ( (signed int)pLightmap->uNumVertices > 0 ) | |
512 { | |
513 v7 = pLightmap->pVertices; | |
514 do | |
515 { | |
516 pLightmapa = 0; | |
517 if ( a2 > 0 ) | |
518 { | |
519 v8 = (char *)&a3->vWorldPosition.z; | |
520 do | |
521 { | |
522 if ( v7->vWorldPosition.x <= (double)*((float *)v8 - 2) ) | |
523 v9 = *((float *)v8 - 2) - v7->vWorldPosition.x; | |
524 else | |
525 v9 = v7->vWorldPosition.x - *((float *)v8 - 2); | |
526 if ( v9 < 2.0 ) | |
527 { | |
528 v10 = v7->vWorldPosition.y <= (double)*((float *)v8 - 1) ? *((float *)v8 - 1) - v7->vWorldPosition.y : v7->vWorldPosition.y - *((float *)v8 - 1); | |
529 if ( v10 < 2.0 ) | |
530 { | |
531 v11 = v7->vWorldPosition.z <= (double)*(float *)v8 ? *(float *)v8 - v7->vWorldPosition.z : v7->vWorldPosition.z - *(float *)v8; | |
532 if ( v11 < 2.0 ) | |
533 { | |
534 v12 = v9 + v11 + v10; | |
535 if ( v12 < v16 ) | |
536 { | |
537 v16 = v12; | |
538 v6 = pLightmapa; | |
539 } | |
540 } | |
541 } | |
542 } | |
543 ++pLightmapa; | |
544 v8 += 48; | |
545 } | |
546 while ( pLightmapa < a2 ); | |
547 if ( v6 != -1 ) | |
548 { | |
549 v13 = &a3[v6]; | |
550 ++v15; | |
551 v7->vWorldPosition.x = v13->vWorldPosition.x; | |
552 v7->vWorldPosition.y = v13->vWorldPosition.y; | |
553 v7->vWorldPosition.z = v13->vWorldPosition.z; | |
554 } | |
555 } | |
556 v6 = -1; | |
557 ++v5; | |
558 ++v7; | |
559 v16 = 3.4028235e38; | |
560 } | |
561 while ( v5 < (signed int)v4->uNumVertices ); | |
562 } | |
563 return v15; | |
564 } | |
565 | |
566 //----- (0045C7F6) -------------------------------------------------------- | |
567 bool LightmapBuilder::ApplyLights_IndoorFace(unsigned int uFaceID) | |
568 { | |
569 auto pFace = &pIndoor->pFaces[uFaceID]; | |
570 auto pSector = pIndoor->pSectors + pFace->uSectorID; | |
571 | |
572 stru_F8AD28.uCurrentAmbientLightLevel = (stru_F8AD28.uDefaultAmbientLightLevel + pSector->uMinAmbientLightLevel) << 16; | |
573 | |
574 uint uNumLightsApplied = 0; | |
575 for (uint i = 0; i < pMobileLightsStack->uNumLightsActive; ++i) | |
576 { | |
577 if (uNumLightsApplied >= 20) | |
578 break; | |
579 | |
580 ApplyLight_BLV((StationaryLight *)(pMobileLightsStack->pLights + i), pFace, &uNumLightsApplied, true, 0); | |
581 } | |
582 | |
583 for (uint i = 0; i < pSector->uNumLights; ++i) | |
584 { | |
585 if (uNumLightsApplied >= 20 ) | |
586 break; | |
587 | |
588 auto pLight = &pIndoor->pLights[pSector->pLights[i]]; | |
589 if (~pLight->uAtributes & 0x08) | |
590 ApplyLight_BLV((StationaryLight *)pLight, pFace, &uFaceID, false, &byte_4E94D0); | |
591 } | |
592 | |
593 for (uint i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i) | |
594 { | |
595 if (uNumLightsApplied >= 20) | |
596 break; | |
597 | |
598 ApplyLight_BLV(pStationaryLightsStack->pLights + i, pFace, &uNumLightsApplied, false, &byte_4E94D0); | |
599 } | |
600 | |
601 stru_F8AD28.uNumLightsApplied = uNumLightsApplied; | |
602 return true; | |
603 } | |
604 | |
605 //----- (0045C911) -------------------------------------------------------- | |
606 bool LightmapBuilder::ApplyLight_BLV(StationaryLight *pLight, BLVFace *a2, unsigned int *pSlot, bool bLightBackfaces, char *a5) | |
607 { | |
608 double v13; // st7@8 | |
609 | |
610 if (!pLight->uRadius) | |
611 return false; | |
612 | |
613 if (pLight->vPosition.x > a2->pBounding.x1 - pLight->uRadius && | |
614 pLight->vPosition.x < a2->pBounding.x2 + pLight->uRadius && | |
615 pLight->vPosition.y > a2->pBounding.y1 - pLight->uRadius && | |
616 pLight->vPosition.y < a2->pBounding.y2 + pLight->uRadius && | |
617 pLight->vPosition.z > a2->pBounding.z1 - pLight->uRadius && | |
618 pLight->vPosition.z < a2->pBounding.z2 + pLight->uRadius) | |
619 { | |
620 v13 = (double)pLight->vPosition.z * a2->pFacePlane.vNormal.z + | |
621 (double)pLight->vPosition.y * a2->pFacePlane.vNormal.y + | |
622 (double)pLight->vPosition.x * a2->pFacePlane.vNormal.x + | |
623 a2->pFacePlane.dist; | |
624 if ((bLightBackfaces || v13 >= 0.0f) && fabsf(v13) <= pLight->uRadius) | |
625 { | |
626 auto slot = *pSlot; | |
627 | |
628 stru_F8AD28._blv_lights_radii[slot] = pLight->uRadius; | |
629 stru_F8AD28._blv_lights_inv_radii[slot] = 65536 / pLight->uRadius; | |
630 stru_F8AD28._blv_lights_xs[slot] = pLight->vPosition.x; | |
631 stru_F8AD28._blv_lights_ys[slot] = pLight->vPosition.y; | |
632 stru_F8AD28._blv_lights_zs[slot] = pLight->vPosition.z; | |
633 stru_F8AD28._blv_lights_rs[slot] = (double)pLight->uLightColorR / 255.0f; | |
634 stru_F8AD28._blv_lights_gs[slot] = (double)pLight->uLightColorG / 255.0f; | |
635 stru_F8AD28._blv_lights_bs[slot] = (double)pLight->uLightColorB / 255.0f; | |
636 stru_F8AD28._blv_lights_light_dot_faces[slot] = abs((int)floorf(v13 + 0.5f)); | |
637 stru_F8AD28._blv_lights_types[slot] = pLight->uLightType; | |
638 | |
639 *pSlot += 1; | |
640 return true; | |
641 } | |
642 } | |
643 | |
644 return false; | |
645 } | |
646 | |
647 //----- (0045CA88) -------------------------------------------------------- | |
648 int LightmapBuilder::_45CA88(stru320 *a2, RenderVertexSoft *a3, int a4, Vec3_float_ *pNormal) | |
649 { | |
650 int result; // eax@1 | |
651 stru320 *v6; // ecx@2 | |
652 RenderVertexSoft *v7; // ebx@2 | |
653 double v8; // st7@2 | |
654 double v9; // st6@2 | |
655 char *v10; // eax@3 | |
656 double v11; // st7@5 | |
657 __int64 v12; // ST2C_8@5 | |
658 float v13; // edx@5 | |
659 int v14; // eax@5 | |
660 float v15; // ST10_4@5 | |
661 Vec3_float_ v16; // ST00_12@5 | |
662 double v17; // st7@5 | |
663 int a5; // [sp+2Ch] [bp-1Ch]@1 | |
664 float v19; // [sp+30h] [bp-18h]@1 | |
665 float v20; // [sp+34h] [bp-14h]@1 | |
666 LightmapBuilder *thisa; // [sp+38h] [bp-10h]@1 | |
667 int v22; // [sp+3Ch] [bp-Ch]@1 | |
668 int *j; // [sp+40h] [bp-8h]@3 | |
669 int i; // [sp+44h] [bp-4h]@1 | |
670 int a3a; // [sp+58h] [bp+10h]@2 | |
671 | |
672 *(float *)&a5 = 0.0; | |
673 v19 = 0.0; | |
674 thisa = this; | |
675 v20 = 0.0; | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1089
diff
changeset
|
676 result = _45CBD4(a3, a4, dword_69B010.data(), &v22); |
0 | 677 for ( i = 0; i < v22; result = i ) |
678 { | |
679 v6 = a2; | |
680 a3a = 0; | |
681 v7 = &a3[dword_69B010[i]]; | |
682 v8 = v7->vWorldPosition.z; | |
683 v9 = v7->vWorldPosition.y; | |
684 *(float *)&a5 = v7->vWorldPosition.x; | |
685 v19 = v9; | |
686 v20 = v8; | |
687 v7->flt_2C = 0.0; | |
688 if ( a2->uNumLightsApplied > 0 ) | |
689 { | |
690 v10 = (char *)a2->_blv_lights_ys; | |
691 for ( j = a2->_blv_lights_ys; ; v10 = (char *)j ) | |
692 { | |
693 v11 = (double)*((signed int *)v10 - 60); | |
694 LODWORD(v12) = *((unsigned int *)v10 - 20); | |
695 HIDWORD(v12) = *(unsigned int *)v10; | |
696 LODWORD(v13) = *((unsigned int *)v10 + 60); | |
697 v14 = a3a; | |
698 LOBYTE(v14) = v6->_blv_lights_types[a3a]; | |
699 v15 = v11; | |
700 *(_QWORD *)&v16.x = v12; | |
701 v16.z = v13; | |
702 v17 = _45CC0C_light(v16/*COERCE_VEC3_FLOAT_(v16.x)*/, 1.0, v15, pNormal, *(float *)&a5/*COERCE_FLOAT(&a5)*/, v14) | |
703 + v7->flt_2C; | |
704 ++a3a; | |
705 ++j; | |
706 v7->flt_2C = v17; | |
707 if ( a3a >= a2->uNumLightsApplied ) | |
708 break; | |
709 v6 = a2; | |
710 } | |
711 } | |
712 ++i; | |
713 } | |
714 return result; | |
715 } | |
716 | |
717 //----- (0045CB89) -------------------------------------------------------- | |
718 int LightmapBuilder::_45CB89(RenderVertexSoft *a1, int a2) | |
719 { | |
720 int v3; // edx@1 | |
721 int result; // eax@2 | |
722 char *v5; // ecx@2 | |
723 double v6; // st7@4 | |
724 __int16 v7; // fps@4 | |
725 char v8; // c0@4 | |
726 char v9; // c2@4 | |
727 char v10; // c3@4 | |
728 double v11; // st7@5 | |
729 double v12; // st7@6 | |
730 __int16 v13; // fps@6 | |
731 char v14; // c0@6 | |
732 char v15; // c2@6 | |
733 char v16; // c3@6 | |
734 | |
735 v3 = a2; | |
736 if ( a2 > 0 ) | |
737 { | |
738 HIWORD(result) = HIWORD(a1); | |
739 v5 = (char *)&a1->flt_2C; | |
740 do | |
741 { | |
742 if ( *(float *)v5 < 0.0 | |
743 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) ) | |
744 { | |
745 v12 = *(float *)v5; | |
746 //UNDEF(v13); | |
747 v14 = 0.0 < v12; | |
748 v15 = 0; | |
749 v16 = 0.0 == v12; | |
750 LOWORD(result) = v13; | |
751 if ( v12 >= 0.0 ) | |
752 v11 = *(float *)v5; | |
753 else | |
754 v11 = 0.0; | |
755 } | |
756 else | |
757 { | |
758 v11 = 1.0; | |
759 } | |
760 *(float *)v5 = v11; | |
761 v5 += 48; | |
762 --v3; | |
763 } | |
764 while ( v3 ); | |
765 } | |
766 return result; | |
767 } | |
768 | |
769 //----- (0045CBD4) -------------------------------------------------------- | |
770 int LightmapBuilder::_45CBD4(RenderVertexSoft *a2, int a3, int *a4, int *a5) | |
771 { | |
772 int result; // eax@1 | |
773 int v6; // edx@1 | |
774 int v7; // ecx@2 | |
775 int v8; // esi@2 | |
776 | |
777 result = (int)a5; | |
778 v6 = 0; | |
779 for ( *a5 = 0; v6 < a3; ++v6 ) | |
780 { | |
781 v7 = *a5; | |
782 v8 = 0; | |
783 if ( *a5 <= 0 ) | |
784 { | |
785 LABEL_5: | |
786 a4[v7] = v6; | |
787 ++*a5; | |
788 } | |
789 else | |
790 { | |
791 while ( a4[v8] != v6 ) | |
792 { | |
793 ++v8; | |
794 if ( v8 >= v7 ) | |
795 goto LABEL_5; | |
796 } | |
797 } | |
798 } | |
799 return result; | |
800 } | |
801 | |
802 //----- (0045CC0C) -------------------------------------------------------- | |
803 double LightmapBuilder::_45CC0C_light(Vec3_float_ a1, float a2, float a3, Vec3_float_ *pNormal, float a5, int uLightType) | |
804 { | |
805 float v7; // esi@1 | |
806 int v8; // eax@1 | |
807 int v9; // ebx@1 | |
808 unsigned int v10; // ecx@1 | |
809 int v11; // edx@2 | |
810 int v12; // edx@4 | |
811 unsigned int v13; // edx@6 | |
812 double v14; // st7@7 | |
813 double result; // st7@8 | |
814 double v16; // st7@9 | |
815 int v17; // esi@9 | |
816 const char *v18; // ecx@9 | |
817 double v19; // st7@10 | |
818 double v20; // st7@10 | |
819 std::string v21; // [sp-10h] [bp-40h]@13 | |
820 const char *v22[6]; // [sp+0h] [bp-30h]@10 | |
821 double v23; // [sp+18h] [bp-18h]@1 | |
822 double v24; // [sp+20h] [bp-10h]@1 | |
823 int v25; // [sp+28h] [bp-8h]@1 | |
824 int v26; // [sp+2Ch] [bp-4h]@1 | |
825 | |
826 v7 = a5; | |
827 LODWORD(a5) = *(unsigned int *)(LODWORD(a5) + 8); | |
828 //v24 = a5 + 6.7553994e15; | |
829 v26 = floorf(a5 + 0.5f);//LODWORD(v24); | |
830 LODWORD(a5) = *(unsigned int *)(LODWORD(v7) + 4); | |
831 //v24 = a5 + 6.7553994e15; | |
832 auto _v24 = floorf(a5 + 0.5f); | |
833 LODWORD(a5) = *(unsigned int *)LODWORD(v7); | |
834 //v23 = a5 + 6.7553994e15; | |
835 auto _v23 = floorf(a5 + 0.5f); | |
836 //*(_QWORD *)((char *)&v24 + 4) = __PAIR__(LODWORD(v24), LODWORD(v23)); | |
837 v26 = abs((signed)LODWORD(a1.z) - v26); | |
838 //v25 = abs((signed)LODWORD(a1.y) - (signed)LODWORD(v24)); | |
839 //v8 = abs((int)a1.x - (signed)LODWORD(v23)); | |
840 v25 = abs((signed)LODWORD(a1.y) - (signed)_v24); | |
841 v8 = abs((int)a1.x - (signed)_v23); | |
842 LODWORD(a5) = v8; | |
843 v9 = v25; | |
844 v10 = v26; | |
845 if ( v8 < v25 ) | |
846 { | |
847 v11 = v8; | |
848 v8 = v25; | |
849 v9 = v11; | |
850 } | |
851 if ( v8 < v26 ) | |
852 { | |
853 v12 = v8; | |
854 v8 = v26; | |
855 v10 = v12; | |
856 } | |
857 if ( v9 < (signed int)v10 ) | |
858 { | |
859 v13 = v10; | |
860 v10 = v9; | |
861 v9 = v13; | |
862 } | |
863 v14 = (double)(signed int)(((unsigned int)(11 * v9) >> 5) + (v10 >> 2) + v8); | |
864 if ( v14 <= a3 ) | |
865 { | |
866 a5 = v14 / a3; | |
867 v16 = (double)(signed int)a1.x; | |
868 *(float *)&v23 = (double)SLODWORD(a1.y); | |
869 LODWORD(a1.x) = *(unsigned int *)LODWORD(v7); | |
870 v17 = LODWORD(v7) + 4; | |
871 *((float *)&v23 + 1) = (double)SLODWORD(a1.z); | |
872 LODWORD(a1.y) = *(unsigned int *)v17; | |
873 LODWORD(a1.z) = *(unsigned int *)(v17 + 4); | |
874 a3 = *((float *)&v23 + 1) - a1.z; | |
875 a1.z = a3; | |
876 a1.x = v16 - a1.x; | |
877 a1.y = (float)v23 - a1.y; | |
878 a1.Normalize(); | |
879 if ( uLightType & 4 ) | |
880 { | |
881 v22[1] = v18; | |
882 uLightType = dword_4D86D8; | |
883 v22[0] = v18; | |
884 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x); | |
885 v20 = v19 * *(float *)&uLightType * a2; | |
886 } | |
887 else | |
888 { | |
889 if ( uLightType & 8 ) | |
890 { | |
891 v20 = 1.3 * a2; | |
892 } | |
893 else | |
894 { | |
895 MessageBoxW(nullptr, L"Invalid light type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:783", 0); | |
896 v20 = *(float *)&uLightType; | |
897 } | |
898 } | |
899 result = v20 - a5 * v20; | |
900 } | |
901 else | |
902 { | |
903 result = 0.0; | |
904 } | |
905 return result; | |
906 } | |
907 // 4D86D8: using guessed type int dword_4D86D8; | |
908 | |
909 //----- (0045CDB7) -------------------------------------------------------- | |
910 bool LightmapBuilder::ApplyLights_OutdoorFace(ODMFace *pFace) | |
911 { | |
912 int v2; // esi@1 | |
913 int v3; // eax@1 | |
914 MobileLight *pMobileLight; // ebx@2 | |
915 int v5; // esi@5 | |
916 StationaryLight *pStationaryLight; // ebx@6 | |
917 bool result; // eax@9 | |
918 LightmapBuilder *thisa; // [sp+Ch] [bp-8h]@1 | |
919 int pSlot; // [sp+10h] [bp-4h]@1 | |
920 | |
921 v2 = 0; | |
922 thisa = this; | |
923 v3 = stru_F8AD28.uDefaultAmbientLightLevel + pFace->uShadeType; | |
924 pSlot = 0; | |
925 stru_F8AD28.uCurrentAmbientLightLevel = v3 << 16; | |
926 if ( pMobileLightsStack->uNumLightsActive > 0 ) | |
927 { | |
928 pMobileLight = pMobileLightsStack->pLights; | |
929 do | |
930 { | |
931 if ( pSlot >= 20 ) | |
932 break; | |
933 ApplyLight_ODM((StationaryLight *)pMobileLight, pFace, (unsigned int *)&pSlot, 1); | |
934 ++v2; | |
935 ++pMobileLight; | |
936 } | |
937 while ( v2 < pMobileLightsStack->uNumLightsActive ); | |
938 } | |
939 v5 = 0; | |
940 if ( pStationaryLightsStack->uNumLightsActive > 0 ) | |
941 { | |
942 pStationaryLight = pStationaryLightsStack->pLights; | |
943 do | |
944 { | |
945 if ( pSlot >= 20 ) | |
946 break; | |
947 ApplyLight_ODM(pStationaryLight, pFace, (unsigned int *)&pSlot, 0); | |
948 ++v5; | |
949 ++pStationaryLight; | |
950 } | |
951 while ( v5 < pStationaryLightsStack->uNumLightsActive ); | |
952 } | |
953 result = pSlot; | |
954 stru_F8AD28.uNumLightsApplied = pSlot; | |
955 return true; | |
956 } | |
957 | |
958 //----- (0045CE50) -------------------------------------------------------- | |
959 bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4) | |
960 { | |
961 int result; // eax@0 | |
962 signed int v6; // ebx@1 | |
963 int v7; // ecx@2 | |
964 int v8; // esi@4 | |
965 int v9; // edx@6 | |
966 int v10; // ecx@8 | |
967 int v11; // eax@11 | |
968 unsigned int v12; // ebx@11 | |
969 RenderD3D *v13; // ecx@11 | |
970 char v14; // dl@11 | |
971 | |
62 | 972 //__debugbreak(); |
0 | 973 |
974 v6 = pLight->uRadius; | |
975 if ( v6 > 0 | |
976 && (result = (int)pFace, v7 = pLight->vPosition.x, v7 > pFace->pBoundingBox.x1 - v6) | |
977 && v7 < v6 + pFace->pBoundingBox.x2 | |
978 && (v8 = pLight->vPosition.y, v8 > pFace->pBoundingBox.y1 - v6) | |
979 && v8 < v6 + pFace->pBoundingBox.y2 | |
980 && (v9 = pLight->vPosition.z, v9 > pFace->pBoundingBox.z1 - v6) | |
981 && v9 < v6 + pFace->pBoundingBox.z2 | |
982 && ((v10 = (pFace->pFacePlane.dist | |
983 + pLight->vPosition.x * pFace->pFacePlane.vNormal.x | |
984 + v8 * pFace->pFacePlane.vNormal.y | |
985 + v9 * pFace->pFacePlane.vNormal.z) >> 16, | |
986 a4) | |
987 || v10 >= 0) | |
988 && v10 <= v6 ) | |
989 { | |
990 stru_F8AD28._blv_lights_radii[*pSlot] = v6; | |
991 stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / v6; | |
992 stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x; | |
993 stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y; | |
994 stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z; | |
995 stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689; | |
996 stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689; | |
997 stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689; | |
998 v11 = abs(v10); | |
999 v12 = pRenderer->bUsingSpecular; | |
1000 stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = v11; | |
1001 stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType; | |
1002 v13 = pRenderer->pRenderD3D; | |
1003 v14 = stru_F8AD28._blv_lights_types[*pSlot]; | |
1004 if ( pRenderer->pRenderD3D && v12 && v14 & 4 ) | |
1005 v14 = _4E94D2_light_type; | |
1006 stru_F8AD28._blv_lights_types[*pSlot] = v14; | |
1007 result = 4 * *pSlot; | |
1008 if ( v13 && v12 ) | |
1009 { | |
1010 if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 ) | |
1011 { | |
1012 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) | |
1013 * 0.33000001; | |
1014 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result) | |
1015 * 0.33000001; | |
1016 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result) | |
1017 * 0.33000001; | |
1018 } | |
1019 } | |
1020 ++*pSlot; | |
1021 LOBYTE(result) = 1; | |
1022 } | |
1023 else | |
1024 { | |
1025 LOBYTE(result) = 0; | |
1026 } | |
1027 return result; | |
1028 } | |
1029 // 4E94D2: using guessed type char _4E94D2_light_type; | |
1030 | |
1031 //----- (0045D036) -------------------------------------------------------- | |
86 | 1032 bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a2, RenderVertexSoft *a3, unsigned int uStripType, bool bLightBackfaces) |
0 | 1033 { |
86 | 1034 /*int v6; // esi@1 |
0 | 1035 //LightmapBuilder *v7; // edi@1 |
1036 MobileLight *v8; // ebx@2 | |
1037 int v9; // esi@5 | |
1038 StationaryLight *v10; // ebx@6 | |
1039 //bool result; // eax@9 | |
1040 unsigned int a7; // [sp+Ch] [bp-4h]@1 | |
1041 | |
1042 v6 = 0; | |
1043 //v7 = this; | |
1044 a7 = 0; | |
1045 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type; | |
1046 if ( pMobileLightsStack->uNumLightsActive > 0 ) | |
1047 { | |
1048 v8 = pMobileLightsStack->pLights; | |
1049 do | |
1050 { | |
1051 if ( (signed int)a7 >= 20 ) | |
1052 break; | |
1053 StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, bLightBackfaces, &a7); | |
1054 ++v6; | |
1055 ++v8; | |
1056 } | |
1057 while ( v6 < pMobileLightsStack->uNumLightsActive ); | |
1058 } | |
1059 v9 = 0; | |
1060 if ( pStationaryLightsStack->uNumLightsActive > 0 ) | |
1061 { | |
1062 v10 = pStationaryLightsStack->pLights; | |
1063 do | |
1064 { | |
1065 if ( (signed int)a7 >= 20 ) | |
1066 break; | |
1067 StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, bLightBackfaces, &a7); | |
1068 ++v9; | |
1069 ++v10; | |
1070 } | |
1071 while ( v9 < pStationaryLightsStack->uNumLightsActive ); | |
1072 } | |
1073 | |
1074 stru_F8AD28.uNumLightsApplied = a7; | |
86 | 1075 return true;*/ |
1076 // bool __stdcall sub_45D036(struct Vec3<float> *pNormal, int a2, struct RenderVertex *a3, int a4, signed int X) | |
1077 //{ | |
1078 float v6; // ebx@2 | |
1079 unsigned int v10; // [sp+Ch] [bp-4h]@1 | |
1080 int i; | |
1081 | |
1082 v10 = 0; | |
638 | 1083 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->max_terrain_dimming_level; |
86 | 1084 for (i = 0; i < pMobileLightsStack->uNumLightsActive; ++i) |
1085 { | |
1086 if ( v10 >= 20 ) | |
1087 break; | |
1088 StackLight_TerrainFace((StationaryLight *)&pMobileLightsStack->pLights[i], pNormal, a2, a3, uStripType, bLightBackfaces, &v10); | |
1089 } | |
1090 | |
1091 for (i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i) | |
1092 { | |
1093 if ( v10 >= 20 ) | |
1094 break; | |
1095 StackLight_TerrainFace(&pStationaryLightsStack->pLights[i], pNormal, a2, a3, uStripType, bLightBackfaces, &v10); | |
1096 } | |
1097 | |
1098 stru_F8AD28.uNumLightsApplied = v10; | |
0 | 1099 return true; |
86 | 1100 |
0 | 1101 } |
1102 // 519AB4: using guessed type int uNumStationaryLightsApplied; | |
1103 | |
1104 //----- (0045D0D5) -------------------------------------------------------- | |
1105 bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X, unsigned int *pSlot) | |
1106 { | |
1107 StationaryLight *v8; // edi@1 | |
1108 bool result; // eax@1 | |
1109 unsigned int v10; // esi@2 | |
1110 RenderVertexSoft *v11; // ebx@2 | |
1111 float v12; // eax@3 | |
1112 float v13; // eax@4 | |
1113 double v14; // st7@11 | |
1114 double maxz; // st7@11 | |
1115 double v16; // st7@11 | |
1116 double v17; // st6@11 | |
1117 __int16 v18; // fps@11 | |
1118 char v19; // c0@11 | |
1119 char v20; // c2@11 | |
1120 char v21; // c3@11 | |
1121 double v22; // st6@12 | |
1122 __int16 v23; // fps@12 | |
1123 char v24; // c0@12 | |
1124 char v25; // c2@12 | |
1125 char v26; // c3@12 | |
1126 double v27; // st7@13 | |
1127 double v28; // st6@13 | |
1128 __int16 v29; // fps@13 | |
1129 char v30; // c0@13 | |
1130 char v31; // c2@13 | |
1131 char v32; // c3@13 | |
1132 double v33; // st6@14 | |
1133 __int16 v34; // fps@14 | |
1134 char v35; // c0@14 | |
1135 char v36; // c2@14 | |
1136 char v37; // c3@14 | |
1137 double v38; // st7@15 | |
1138 double v39; // st6@15 | |
1139 __int16 v40; // fps@15 | |
1140 char v41; // c0@15 | |
1141 char v42; // c2@15 | |
1142 char v43; // c3@15 | |
1143 double v44; // st6@16 | |
1144 __int16 v45; // fps@16 | |
1145 char v46; // c0@16 | |
1146 char v47; // c2@16 | |
1147 char v48; // c3@16 | |
1148 Vec3_float_ *v49; // esi@17 | |
1149 double v50; // st7@17 | |
1150 double v51; // st6@17 | |
1151 signed int v52; // ecx@17 | |
1152 unsigned int *v53; // esi@18 | |
1153 int v54; // eax@18 | |
1154 unsigned int v55; // ebx@18 | |
1155 RenderD3D *v56; // ecx@18 | |
1156 char v57; // dl@18 | |
1157 std::string v58; // [sp-18h] [bp-38h]@10 | |
1158 const char *v59; // [sp-8h] [bp-28h]@10 | |
1159 signed int v60; // [sp-4h] [bp-24h]@10 | |
1160 double v61; // [sp+Ch] [bp-14h]@11 | |
1161 float minz; // [sp+14h] [bp-Ch]@11 | |
1162 int v63; // [sp+18h] [bp-8h]@1 | |
1163 float v64; // [sp+1Ch] [bp-4h]@5 | |
1164 | |
1165 v8 = pLight; | |
1166 result = pLight->uRadius; | |
1167 v63 = pLight->uRadius; | |
1168 if ( result <= 0 ) | |
86 | 1169 return 0; |
1170 //v10 = uStripType; | |
0 | 1171 v11 = a1; |
1172 if ( uStripType == 4 ) | |
1173 { | |
1174 pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x); | |
1175 v12 = a1[3].vWorldPosition.x; | |
1176 } | |
1177 else | |
1178 { | |
1179 if ( uStripType != 3 ) | |
1180 { | |
1181 MessageBoxW(nullptr, L"Uknown strip type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:981", 0); | |
1182 goto LABEL_11; | |
1183 } | |
1184 if ( (unsigned char)X ) | |
1185 { | |
1186 pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x); | |
1187 uStripType = LODWORD(a1[2].vWorldPosition.x); | |
1188 a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y); | |
1189 v13 = v11[2].vWorldPosition.y; | |
1190 goto LABEL_5; | |
1191 } | |
1192 pLight = (StationaryLight *)LODWORD(a1[1].vWorldPosition.x); | |
1193 v12 = a1[2].vWorldPosition.x; | |
1194 } | |
1195 uStripType = LODWORD(v12); | |
1196 a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y); | |
1197 v13 = v11->vWorldPosition.y; | |
1198 LABEL_5: | |
1199 v64 = v13; | |
1200 LABEL_11: | |
86 | 1201 //v60 = v10; |
0 | 1202 v59 = (const char *)v11; |
86 | 1203 v60 = uStripType; |
1204 minz = pGame->pIndoorCameraD3D->GetPolygonMinZ(v11, uStripType); | |
1205 maxz = pGame->pIndoorCameraD3D->GetPolygonMaxZ(v11, uStripType); | |
0 | 1206 result = v8->vPosition.x; |
1207 *((float *)&v61 + 1) = maxz; | |
1208 v16 = (double)result; | |
1209 *(float *)&X = (double)v63; | |
1210 v17 = *(float *)&pLight - *(float *)&X; | |
1211 //UNDEF(v18); | |
86 | 1212 //v19 = v16 < v17; |
0 | 1213 v20 = 0; |
86 | 1214 //v21 = v16 == v17; |
1215 /* BYTE1(result) = HIBYTE(v18); | |
0 | 1216 if ( v16 <= v17 |
1217 || (v22 = *(float *)&X + *(float *)&uStripType, | |
1218 //UNDEF(v23), | |
1219 v24 = v16 < v22, | |
1220 v25 = 0, | |
1221 v26 = v16 == v22, | |
1222 BYTE1(result) = HIBYTE(v23), | |
1223 v16 >= v22) | |
1224 || (result = v8->vPosition.y, | |
1225 pLight = (StationaryLight *)v8->vPosition.y, | |
1226 v27 = (double)(signed int)pLight, | |
1227 v28 = *(float *)&a1 - *(float *)&X, | |
1228 //UNDEF(v29), | |
1229 v30 = v27 < v28, | |
1230 v31 = 0, | |
1231 v32 = v27 == v28, | |
1232 BYTE1(result) = HIBYTE(v29), | |
1233 v27 <= v28) | |
1234 || (v33 = *(float *)&X + v64, | |
1235 //UNDEF(v34), | |
1236 v35 = v27 < v33, | |
1237 v36 = 0, | |
1238 v37 = v27 == v33, | |
1239 BYTE1(result) = HIBYTE(v34), | |
1240 v27 >= v33) | |
1241 || (result = v8->vPosition.z, | |
1242 pLight = (StationaryLight *)v8->vPosition.z, | |
1243 v38 = (double)(signed int)pLight, | |
1244 v39 = minz - *(float *)&X, | |
1245 //UNDEF(v40), | |
1246 v41 = v38 < v39, | |
1247 v42 = 0, | |
1248 v43 = v38 == v39, | |
1249 BYTE1(result) = HIBYTE(v40), | |
1250 v38 <= v39) | |
1251 || (v44 = *(float *)&X + *((float *)&v61 + 1), | |
1252 //UNDEF(v45), | |
1253 v46 = v38 < v44, | |
1254 v47 = 0, | |
1255 v48 = v38 == v44, | |
1256 BYTE1(result) = HIBYTE(v45), | |
1257 v38 >= v44) | |
1258 || (v49 = pNormal, | |
1259 Vec3_float_::NegDot(&v11->vWorldPosition, pNormal, a3), | |
1260 X = v8->vPosition.y, | |
1261 v50 = (double)X * v49->y, | |
1262 X = v8->vPosition.z, | |
1263 v51 = (double)X * v49->z, | |
1264 X = v8->vPosition.x, | |
1265 *(float *)&a3 = v50 + v51 + (double)X * v49->x + *a3, | |
1266 v61 = *(float *)&a3 + 6.7553994e15, | |
1267 result = LODWORD(v61), | |
1268 X = LODWORD(v61), | |
1269 v52 = v63, | |
86 | 1270 SLODWORD(v61) > v63) )*/ |
1271 if (0) | |
1272 return 0; | |
0 | 1273 v53 = pSlot; |
1274 v60 = X; | |
1275 stru_F8AD28._blv_lights_radii[*pSlot] = v63; | |
86 | 1276 stru_F8AD28._blv_lights_inv_radii[*v53] = 65536 / v63; |
0 | 1277 stru_F8AD28._blv_lights_xs[*v53] = v8->vPosition.x; |
1278 stru_F8AD28._blv_lights_ys[*v53] = v8->vPosition.y; | |
1279 stru_F8AD28._blv_lights_zs[*v53] = v8->vPosition.z; | |
1280 a3 = (float *)v8->uLightColorR; | |
86 | 1281 stru_F8AD28._blv_lights_rs[*v53] = (double)(signed int)a3 * 0.003921568859368563; |
0 | 1282 a3 = (float *)v8->uLightColorG; |
86 | 1283 stru_F8AD28._blv_lights_gs[*v53] = (double)(signed int)a3 * 0.003921568859368563; |
0 | 1284 a3 = (float *)v8->uLightColorB; |
86 | 1285 stru_F8AD28._blv_lights_bs[*v53] = (double)(signed int)a3 * 0.003921568859368563; |
0 | 1286 v54 = abs(v60); |
1287 v55 = pRenderer->bUsingSpecular; | |
1288 stru_F8AD28._blv_lights_light_dot_faces[*v53] = v54; | |
1289 stru_F8AD28._blv_lights_types[*v53] = v8->uLightType; | |
1290 v56 = pRenderer->pRenderD3D; | |
1291 v57 = stru_F8AD28._blv_lights_types[*v53]; | |
1292 if ( pRenderer->pRenderD3D && v55 && v57 & 4 ) | |
1293 v57 = _4E94D2_light_type; | |
1294 stru_F8AD28._blv_lights_types[*v53] = v57; | |
1295 result = 4 * *v53; | |
1296 if ( v56 && v55 ) | |
1297 { | |
1298 if ( stru_F8AD28._blv_lights_types[*v53] & 4 ) | |
1299 { | |
1300 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) | |
86 | 1301 * 0.3300000131130219; |
0 | 1302 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result) |
86 | 1303 * 0.3300000131130219; |
0 | 1304 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result) |
86 | 1305 * 0.3300000131130219; |
0 | 1306 } |
1307 } | |
1308 ++*v53; | |
86 | 1309 return 1; |
0 | 1310 } |
1311 // 4E94D2: using guessed type char _4E94D2_light_type; | |
1312 | |
1313 //----- (0045D3C7) -------------------------------------------------------- | |
1314 bool LightmapBuilder::_45D3C7(stru148 *a1) | |
1315 { | |
1316 LightmapBuilder *v2; // ebx@1 | |
1317 stru148 *result; // eax@1 | |
1318 float v4; // ecx@2 | |
1319 Span *i; // edi@5 | |
1320 | |
1321 v2 = this; | |
1322 result = (stru148 *)a1->prolly_head; | |
1323 if ( result && (v4 = result->field_4, *(int *)&v4) != 0 && *(unsigned int *)(LODWORD(v4) + 60) ) | |
1324 { | |
1325 for ( i = a1->prolly_head; ; i = i->pNext ) | |
1326 { | |
1327 result = i->pParent; | |
1328 if ( result->field_108 ) | |
1329 result = (stru148 *)_45D426( | |
1330 i, | |
1331 a1->pEdgeList1, | |
1332 a1->uEdgeList1Size, | |
1333 (Edge *)a1->pEdgeList2, | |
1334 a1->uEdgeList2Size); | |
1335 if ( a1->prolly_tail == i ) | |
1336 break; | |
1337 } | |
1338 LOBYTE(result) = 1; | |
1339 } | |
1340 else | |
1341 { | |
1342 LOBYTE(result) = 0; | |
1343 } | |
1344 return (bool)result; | |
1345 } | |
1346 | |
1347 //----- (0045D426) -------------------------------------------------------- | |
1348 int LightmapBuilder::_45D426(Span *a1, Edge **a2, unsigned int a3, Edge *a4, int a5) | |
1349 { | |
1350 int v6; // edi@1 | |
1351 signed int v7; // ebx@3 | |
1352 signed int v8; // ecx@3 | |
1353 Span *v9; // esi@3 | |
1354 double v10; // st7@4 | |
1355 Edge *v11; // edx@5 | |
1356 double v12; // st7@11 | |
1357 int v13; // edx@12 | |
1358 int v14; // ebx@17 | |
1359 Edge *v15; // edi@17 | |
1360 float v16; // ST04_4@17 | |
1361 float v17; // ST04_4@17 | |
1362 double v18; // st7@17 | |
1363 int result; // eax@19 | |
1364 //double v20; // ST14_8@20 | |
1365 //double v21; // ST14_8@20 | |
1366 double v22; // st7@20 | |
1367 int v23; // ecx@20 | |
1368 double v24; // st6@20 | |
1369 double v25; // st7@23 | |
1370 double v26; // st7@28 | |
1371 __int16 v27; // fps@28 | |
1372 char v28; // c0@28 | |
1373 char v29; // c2@28 | |
1374 char v30; // c3@28 | |
1375 double v31; // st7@29 | |
1376 double v32; // st7@30 | |
1377 __int16 v33; // fps@30 | |
1378 char v34; // c0@30 | |
1379 char v35; // c2@30 | |
1380 char v36; // c3@30 | |
1381 LightmapBuilder *this_4; // [sp+14h] [bp-8h]@1 | |
1382 signed int v38; // [sp+18h] [bp-4h]@3 | |
1383 float a1a; // [sp+24h] [bp+8h]@20 | |
1384 float a2a; // [sp+28h] [bp+Ch]@17 | |
1385 float a3a; // [sp+2Ch] [bp+10h]@17 | |
1386 float a5a; // [sp+34h] [bp+18h]@20 | |
1387 float a5b; // [sp+34h] [bp+18h]@20 | |
1388 | |
1389 v6 = 0; | |
1390 this_4 = this; | |
1391 if ( a5 && a3 ) | |
1392 { | |
1393 v7 = -1; | |
1394 v8 = 0; | |
1395 v9 = a1; | |
1396 v38 = -1; | |
1397 if ( (signed int)a3 > 0 ) | |
1398 { | |
1399 v10 = (double)a1->field_A; | |
1400 while ( 1 ) | |
1401 { | |
1402 v11 = a2[v8]; | |
1403 if ( v10 >= v11->field_2C ) | |
1404 { | |
1405 if ( v10 <= v11->field_30 ) | |
1406 break; | |
1407 } | |
1408 ++v8; | |
1409 if ( v8 >= (signed int)a3 ) | |
1410 goto LABEL_10; | |
1411 } | |
1412 v38 = v8; | |
1413 } | |
1414 LABEL_10: | |
1415 if ( a5 > 0 ) | |
1416 { | |
1417 v12 = (double)a1->field_A; | |
1418 while ( 1 ) | |
1419 { | |
1420 v13 = *((unsigned int *)&a4->field_0 + v6); | |
1421 if ( v12 >= *(float *)(v13 + 44) ) | |
1422 { | |
1423 if ( v12 <= *(float *)(v13 + 48) ) | |
1424 break; | |
1425 } | |
1426 ++v6; | |
1427 if ( v6 >= a5 ) | |
1428 goto LABEL_17; | |
1429 } | |
1430 v7 = v6; | |
1431 } | |
1432 LABEL_17: | |
1433 v14 = *((unsigned int *)&a4->field_0 + v7); | |
1434 v15 = a2[v38]; | |
1435 v16 = (double)a1->field_A; | |
1436 a3a = _45D643(a2[v38], v16); | |
1437 v17 = (double)a1->field_A; | |
1438 v18 = _45D643((Edge *)v14, v17); | |
1439 a2a = v18; | |
1440 if ( byte_4D864C && BYTE1(pGame->uFlags) & 0x80 ) | |
1441 { | |
1442 HIWORD(result) = HIWORD(a3a); | |
1443 a1->field_14 = v18; | |
1444 a1->field_10 = a3a; | |
1445 } | |
1446 else | |
1447 { | |
1448 a5a = ((double)a1->field_A - v15->field_2C) * v15->field_4 + v15->field_24 - 0.5; | |
1449 //v20 = a5a + 6.7553994e15; | |
1450 //a5b = (double)SLODWORD(v20); | |
1451 a5b = (double)floorf(a5a + 0.5f); | |
1452 a1a = ((double)a1->field_A - *(float *)(v14 + 44)) * *(float *)(v14 + 4) + *(float *)(v14 + 36) + 0.5; | |
1453 //v21 = a1a + 6.7553994e15; | |
1454 //v22 = (double)SLODWORD(v21); | |
1455 v22 = (double)floorf(a1a + 0.5f); | |
1456 result = v9->field_8; | |
1457 v23 = v9->field_C; | |
1458 v24 = -((a3a - a2a) / (v22 - a5b)); | |
1459 v9->field_10 = ((double)result - a5b) * v24 + a3a; | |
1460 v9->field_14 = a2a - (v22 - (double)(result + v23)) * v24; | |
1461 } | |
1462 if ( v9->field_10 < 0.0 || v9->field_10 <= 1.0 ) | |
1463 { | |
1464 if ( v9->field_10 >= 0.0 ) | |
1465 v25 = v9->field_10; | |
1466 else | |
1467 v25 = 0.0; | |
1468 } | |
1469 else | |
1470 { | |
1471 v25 = 1.0; | |
1472 } | |
1473 v9->field_10 = v25; | |
1474 if ( v9->field_14 < 0.0 | |
1475 || (v26 = v9->field_14, | |
1476 //UNDEF(v27), | |
1477 v28 = 1.0 < v26, | |
1478 v29 = 0, | |
1479 v30 = 1.0 == v26, | |
1480 BYTE1(result) = HIBYTE(v27), | |
1481 v26 <= 1.0) ) | |
1482 { | |
1483 v32 = v9->field_14; | |
1484 //UNDEF(v33); | |
1485 v34 = 0.0 < v32; | |
1486 v35 = 0; | |
1487 v36 = 0.0 == v32; | |
1488 BYTE1(result) = HIBYTE(v33); | |
1489 if ( v32 >= 0.0 ) | |
1490 v31 = v9->field_14; | |
1491 else | |
1492 v31 = 0.0; | |
1493 } | |
1494 else | |
1495 { | |
1496 v31 = 1.0; | |
1497 } | |
1498 v9->field_14 = v31; | |
1499 LOBYTE(result) = 1; | |
1500 } | |
1501 else | |
1502 { | |
1503 LOBYTE(result) = 0; | |
1504 } | |
1505 return result; | |
1506 } | |
1507 // 4D864C: using guessed type char byte_4D864C; | |
1508 | |
1509 //----- (0045D643) -------------------------------------------------------- | |
1510 double LightmapBuilder::_45D643(Edge *a1, float a2) | |
1511 { | |
1512 double result; // st7@1 | |
1513 | |
1514 result = (a1->field_1C - a1->field_20) * -1.0 / (a1->field_30 - a1->field_2C) * (a2 - a1->field_2C) + a1->field_1C; | |
1515 if ( result < 0.0 || result <= 1.0 ) | |
1516 { | |
1517 if ( result < 0.0 ) | |
1518 result = 0.0; | |
1519 } | |
1520 else | |
1521 { | |
1522 result = 1.0; | |
1523 } | |
1524 return result; | |
1525 } | |
1526 | |
1527 //----- (0045D698) -------------------------------------------------------- | |
1528 bool LightmapBuilder::DrawDebugOutlines(char bit_one_for_list1__bit_two_for_list2) | |
1529 { | |
1530 bool result; // eax@1 | |
1531 LightmapBuilder *v3; // esi@1 | |
1532 RenderVertexSoft *v4; // edi@3 | |
1533 RenderVertexSoft *v5; // edi@7 | |
1534 IndoorCameraD3D *thisa; // [sp+10h] [bp-8h]@1 | |
1535 bool v7; // [sp+14h] [bp-4h]@2 | |
1536 bool a2a; // [sp+20h] [bp+8h]@6 | |
1537 | |
1538 result = (bool)pGame->pIndoorCameraD3D; | |
1539 v3 = this; | |
1540 thisa = pGame->pIndoorCameraD3D; | |
1541 if ( bit_one_for_list1__bit_two_for_list2 & 1 ) | |
1542 { | |
1543 v7 = 0; | |
1544 if ( (signed int)this->std__vector_000004_size > 0 ) | |
1545 { | |
1546 v4 = this->std__vector_000004[0].pVertices; | |
1547 do | |
1548 { | |
1549 pGame->pIndoorCameraD3D->debug_outline_sw(v4, *((unsigned int *)v4 - 1), 0xFF00u, 0.0); | |
1550 ++v7; | |
1551 v4 = (RenderVertexSoft *)((char *)v4 + 3100); | |
1552 result = v7; | |
1553 } | |
1554 while ( v7 < (signed int)v3->std__vector_000004_size ); | |
1555 } | |
1556 } | |
1557 if ( bit_one_for_list1__bit_two_for_list2 & 2 ) | |
1558 { | |
1559 a2a = 0; | |
1560 if ( (signed int)v3->std__vector_183808_size > 0 ) | |
1561 { | |
1562 v5 = v3->std__vector_183808[0].pVertices; | |
1563 do | |
1564 { | |
1565 pGame->pIndoorCameraD3D->debug_outline_sw(v5, *((unsigned int *)v5 - 1), 0xC04000u, 0.00019999999); | |
1566 ++a2a; | |
1567 v5 = (RenderVertexSoft *)((char *)v5 + 3100); | |
1568 result = a2a; | |
1569 } | |
1570 while ( a2a < (signed int)v3->std__vector_183808_size ); | |
1571 } | |
1572 } | |
1573 LOBYTE(result) = 1; | |
1574 return result; | |
1575 } | |
1576 | |
1577 //----- (0045D73F) -------------------------------------------------------- | |
1578 void LightmapBuilder::DrawLightmaps(int a2) | |
1579 { | |
1580 if ( a2 == 2 ) | |
1581 DoDrawLightmaps(); | |
1582 } | |
1583 | |
1584 //----- (0045D74F) -------------------------------------------------------- | |
1585 char LightmapBuilder::_45D74F_MessWithLight(int a2, int *a3) | |
1586 { | |
1587 char v3; // zf@1 | |
1588 IDirect3DDevice3 *v4; // eax@2 | |
1589 HRESULT v5; // eax@2 | |
1590 //char *v6; // eax@2 | |
1591 struct IDirect3DTexture2 *v7; // edi@4 | |
1592 HRESULT v8; // eax@8 | |
1593 HRESULT v9; // eax@8 | |
1594 HRESULT v10; // eax@8 | |
1595 HRESULT v11; // eax@8 | |
1596 HRESULT v12; // eax@8 | |
1597 int *v13; // eax@8 | |
1598 float v14; // ecx@15 | |
1599 IDirect3DDevice3 *v15; // eax@21 | |
1600 HRESULT v16; // eax@21 | |
1601 IDirect3DDevice3 *v17; // eax@21 | |
1602 HRESULT v18; // eax@21 | |
1603 IDirect3DDevice3 *v19; // eax@21 | |
1604 HRESULT v20; // eax@21 | |
1605 IDirect3DDevice3 *v21; // eax@21 | |
1606 HRESULT v22; // eax@21 | |
1607 //IDirect3DDevice3 *v23; // eax@23 | |
1608 std::string v25; // [sp+44h] [bp-44h]@12 | |
1609 signed int v26; // [sp+48h] [bp-40h]@21 | |
1610 signed int v27; // [sp+4Ch] [bp-3Ch]@21 | |
1611 Lightmap *v28; // [sp+50h] [bp-38h]@2 | |
1612 int v29; // [sp+54h] [bp-34h]@2 | |
1613 //float v30; // [sp+58h] [bp-30h]@2 | |
1614 int arg4; // [sp+68h] [bp-20h]@8 | |
1615 float v32; // [sp+6Ch] [bp-1Ch]@8 | |
1616 float v33; // [sp+70h] [bp-18h]@8 | |
1617 int v34; // [sp+74h] [bp-14h]@19 | |
1618 int v35; // [sp+78h] [bp-10h]@2 | |
1619 int *v36; // [sp+7Ch] [bp-Ch]@10 | |
1620 int a1; // [sp+80h] [bp-8h]@12 | |
1621 float v38; // [sp+84h] [bp-4h]@1 | |
1622 | |
1623 v3 = this->std__vector_000004_size == 0; | |
1624 LODWORD(v38) = (int)this; | |
1625 if ( !v3 ) | |
1626 { | |
1627 //v30 = 0.0; | |
1628 //v4 = pRenderer->pRenderD3D->pDevice; | |
595 | 1629 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 3u)); |
0 | 1630 //v6 = (char *)stru_69BD44.c_str(); |
1631 //if ( !stru_69BD44.c_str() ) | |
1632 // v6 = (char *)&dword_4D86F0; | |
1633 v7 = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03"); | |
1634 if ( pRenderer->bUsingSpecular ) | |
1635 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0); | |
1636 if ( !byte_4D864C || !(pGame->uFlags & 1) ) | |
1637 { | |
186 | 1638 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); |
1639 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); | |
0 | 1640 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v7)); |
186 | 1641 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1642 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); | |
0 | 1643 v13 = a3; |
1644 v33 = 1.0; | |
1645 v32 = 1.0; | |
1646 *(float *)&arg4 = 1.0; | |
1647 if ( a3 ) | |
1648 { | |
1649 if ( *a3 != -1 ) | |
1650 { | |
1651 v36 = a3; | |
1652 do | |
1653 { | |
1654 v28 = (Lightmap *)(3100 * *v13 + LODWORD(v38) + 4); | |
1655 if ( !DrawLightmap(v28, (Vec3_float_ *)&arg4, 0.0) ) | |
1656 { | |
1657 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1230", 0); | |
1658 a1 = 5080812; | |
1659 } | |
1660 v13 = v36 + 1; | |
1661 v36 = v13; | |
1662 } | |
1663 while ( *v13 != -1 ); | |
1664 } | |
1665 } | |
1666 else | |
1667 { | |
1668 v14 = v38; | |
1669 v36 = 0; | |
1670 if ( *(unsigned int *)(LODWORD(v38) + 1587204) > 0 ) | |
1671 { | |
1672 a1 = LODWORD(v38) + 4; | |
1673 while ( 1 ) | |
1674 { | |
1675 if ( !DrawLightmap((Lightmap *)a1, (Vec3_float_ *)&arg4, 0.0) ) | |
1676 { | |
1677 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1238", 0); | |
1678 v35 = 5080812; | |
1679 } | |
1680 v36 = (int *)((char *)v36 + 1); | |
1681 a1 += 3100; | |
1682 if ( (signed int)v36 >= *(unsigned int *)(LODWORD(v38) + 1587204) ) | |
1683 break; | |
1684 v14 = v38; | |
1685 } | |
1686 } | |
1687 } | |
1688 v15 = pRenderer->pRenderD3D->pDevice; | |
186 | 1689 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1690 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); | |
1691 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); | |
1692 ErrD3D(v15->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); | |
0 | 1693 } |
1694 if ( pRenderer->bUsingSpecular ) | |
1695 { | |
1696 //LODWORD(v30) = 1; | |
1697 //v29 = 28; | |
1698 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; | |
186 | 1699 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); |
0 | 1700 //v30 = pRenderer->uFogColor; |
1701 //v23 = pRenderer->pRenderD3D->pDevice; | |
1702 //v29 = 34; | |
1703 //v28 = (Lightmap *)v23; | |
1704 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, pRenderer->uFogColor)); | |
1705 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; | |
186 | 1706 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0)); |
0 | 1707 } |
1708 } | |
1709 return 1; | |
1710 } | |
1711 | |
1712 | |
1713 //----- (0045DA56) -------------------------------------------------------- | |
1714 bool LightmapBuilder::DrawLightmaps2(float z_bias) | |
1715 { | |
1716 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2 | |
1717 v.z = 1.0; | |
1718 v.y = 1.0; | |
1719 v.x = 1.0; | |
1720 | |
1721 for (uint i = 0; i < std__vector_183808_size; ++i) | |
1722 if (!DrawLightmap(std__vector_183808 + i, &v, z_bias)) | |
1723 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1288", 0); | |
1724 | |
1725 return true; | |
1726 } | |
1727 | |
1728 //----- (0045DAE8) -------------------------------------------------------- | |
1729 bool LightmapBuilder::DrawLightmap(Lightmap *pLightmap, Vec3_float_ *pColorMult, float z_bias) | |
1730 { | |
1731 double v10; // st7@4 | |
1732 double v14; // st7@7 | |
1733 __int16 v15; // fps@8 | |
1734 double v18; // st3@8 | |
1735 signed int v24; // [sp-1Ch] [bp-670h]@13 | |
1736 const char *v25; // [sp-18h] [bp-66Ch]@13 | |
1737 int v26; // [sp-14h] [bp-668h]@13 | |
1738 RenderVertexD3D3 a2[32]; // [sp+0h] [bp-654h]@7 | |
1739 | |
1740 | |
1741 if (pLightmap->uNumVertices < 3) | |
1742 { | |
1743 Log::Warning(L"Lightmap uNumVertices < 3"); | |
1744 return false; | |
1745 } | |
1746 | |
1747 uint uLightmapColorMaskR = (pLightmap->uColorMask >> 16) & 0xFF; | |
1748 uint uLightmapColorR = floorf(uLightmapColorMaskR * pLightmap->fBrightness * pColorMult->x + 0.5f); | |
1749 | |
1750 uint uLightmapColorMaskG = (pLightmap->uColorMask >> 8) & 0xFF; | |
1751 uint uLightmapColorG = floorf(uLightmapColorMaskG * pLightmap->fBrightness * pColorMult->y + 0.5f); | |
1752 | |
1753 uint uLightmapColorMaskB = pLightmap->uColorMask & 0xFF; | |
1754 uint uLightmapColorB = floorf(uLightmapColorMaskB * pLightmap->fBrightness * pColorMult->z + 0.5f); | |
1755 | |
1756 uint uLightmapColor = uLightmapColorB | (uLightmapColorMaskG << 8) | (uLightmapColorMaskR << 16); | |
1757 | |
1758 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
1759 v10 = (double)pOutdoorCamera->shading_dist_mist; | |
1760 else | |
1761 v10 = 16192.0; | |
1762 v14 = 1.0 / v10; | |
1763 | |
1764 for (uint i = 0; i < pLightmap->uNumVertices; ++i) | |
1765 { | |
1766 v18 = 1.0 - 1.0 / (v14 * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0); | |
1767 if (fabsf(z_bias) < 1e-5f) | |
1768 { | |
1769 v18 = v18 - z_bias; | |
1770 if (v18 < 0.000099999997) | |
1771 v18 = 0.000099999997; | |
1772 } | |
1773 | |
1774 a2[i].pos.x = pLightmap->pVertices[i].vWorldViewProjX; | |
1775 a2[i].pos.z = v18; | |
1776 a2[i].pos.y = pLightmap->pVertices[i].vWorldViewProjY; | |
1777 a2[i].rhw = 1.0 / pLightmap->pVertices[i].vWorldViewPosition.x; | |
1778 a2[i].diffuse = uLightmapColor; | |
1779 a2[i].specular = 0; | |
1780 a2[i].texcoord.x = pLightmap->pVertices[i].u; | |
1781 a2[i].texcoord.y = pLightmap->pVertices[i].v; | |
1782 } | |
1783 | |
1784 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
1785 v24 = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS; | |
1786 else | |
1787 v24 = D3DDP_DONOTLIGHT; | |
1788 | |
1789 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, | |
1790 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, | |
1791 a2, | |
1792 pLightmap->uNumVertices, | |
1793 v24)); | |
1794 | |
1795 return true; | |
1796 } | |
1797 | |
1798 //----- (0045DCA9) -------------------------------------------------------- | |
1799 void LightmapBuilder::DoDrawLightmaps() | |
1800 { | |
1801 if (!std__vector_183808_size) | |
1802 return; | |
1803 | |
1804 if (pRenderer->bUsingSpecular) | |
186 | 1805 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE)); |
0 | 1806 |
186 | 1807 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE)); |
1808 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE)); | |
1809 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); | |
1810 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); | |
0 | 1811 |
1812 auto pTex = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03"); | |
1813 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex)); | |
1814 | |
186 | 1815 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1816 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); | |
0 | 1817 |
1818 DrawLightmaps2(0.00050000002); | |
1819 | |
186 | 1820 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1821 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); | |
1822 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); | |
1823 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); | |
1824 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE)); | |
1825 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW)); | |
0 | 1826 |
1827 if (pRenderer->bUsingSpecular) | |
186 | 1828 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); |
0 | 1829 } |