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