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