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