Mercurial > mm7
annotate LightmapBuilder.cpp @ 1422:6bbcb91b3b7d
m
author | Ritor1 |
---|---|
date | Tue, 30 Jul 2013 09:33:52 +0600 |
parents | 8ea496564034 |
children | c9e3b93ec570 |
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 { | |
744 if ( *(float *)v5 < 0.0 | |
745 || (v6 = *(float *)v5, /*UNDEF(v7),*/ v8 = 1.0 < v6, v9 = 0, v10 = 1.0 == v6, LOWORD(result) = v7, v6 <= 1.0) ) | |
746 { | |
747 v12 = *(float *)v5; | |
748 //UNDEF(v13); | |
749 v14 = 0.0 < v12; | |
750 v15 = 0; | |
751 v16 = 0.0 == v12; | |
752 LOWORD(result) = v13; | |
753 if ( v12 >= 0.0 ) | |
754 v11 = *(float *)v5; | |
755 else | |
756 v11 = 0.0; | |
757 } | |
758 else | |
759 { | |
760 v11 = 1.0; | |
761 } | |
762 *(float *)v5 = v11; | |
763 v5 += 48; | |
764 --v3; | |
765 } | |
766 while ( v3 ); | |
767 } | |
768 return result; | |
769 } | |
770 | |
771 //----- (0045CBD4) -------------------------------------------------------- | |
772 int LightmapBuilder::_45CBD4(RenderVertexSoft *a2, int a3, int *a4, int *a5) | |
773 { | |
774 int result; // eax@1 | |
775 int v6; // edx@1 | |
776 int v7; // ecx@2 | |
777 int v8; // esi@2 | |
778 | |
779 result = (int)a5; | |
780 v6 = 0; | |
781 for ( *a5 = 0; v6 < a3; ++v6 ) | |
782 { | |
783 v7 = *a5; | |
784 v8 = 0; | |
785 if ( *a5 <= 0 ) | |
786 { | |
787 LABEL_5: | |
788 a4[v7] = v6; | |
789 ++*a5; | |
790 } | |
791 else | |
792 { | |
793 while ( a4[v8] != v6 ) | |
794 { | |
795 ++v8; | |
796 if ( v8 >= v7 ) | |
797 goto LABEL_5; | |
798 } | |
799 } | |
800 } | |
801 return result; | |
802 } | |
803 | |
804 //----- (0045CC0C) -------------------------------------------------------- | |
805 double LightmapBuilder::_45CC0C_light(Vec3_float_ a1, float a2, float a3, Vec3_float_ *pNormal, float a5, int uLightType) | |
806 { | |
807 float v7; // esi@1 | |
808 int v8; // eax@1 | |
809 int v9; // ebx@1 | |
810 unsigned int v10; // ecx@1 | |
811 int v11; // edx@2 | |
812 int v12; // edx@4 | |
813 unsigned int v13; // edx@6 | |
814 double v14; // st7@7 | |
815 double result; // st7@8 | |
816 double v16; // st7@9 | |
817 int v17; // esi@9 | |
818 const char *v18; // ecx@9 | |
819 double v19; // st7@10 | |
820 double v20; // st7@10 | |
821 std::string v21; // [sp-10h] [bp-40h]@13 | |
822 const char *v22[6]; // [sp+0h] [bp-30h]@10 | |
823 double v23; // [sp+18h] [bp-18h]@1 | |
824 double v24; // [sp+20h] [bp-10h]@1 | |
825 int v25; // [sp+28h] [bp-8h]@1 | |
826 int v26; // [sp+2Ch] [bp-4h]@1 | |
827 | |
828 v7 = a5; | |
829 LODWORD(a5) = *(unsigned int *)(LODWORD(a5) + 8); | |
830 //v24 = a5 + 6.7553994e15; | |
831 v26 = floorf(a5 + 0.5f);//LODWORD(v24); | |
832 LODWORD(a5) = *(unsigned int *)(LODWORD(v7) + 4); | |
833 //v24 = a5 + 6.7553994e15; | |
834 auto _v24 = floorf(a5 + 0.5f); | |
835 LODWORD(a5) = *(unsigned int *)LODWORD(v7); | |
836 //v23 = a5 + 6.7553994e15; | |
837 auto _v23 = floorf(a5 + 0.5f); | |
838 //*(_QWORD *)((char *)&v24 + 4) = __PAIR__(LODWORD(v24), LODWORD(v23)); | |
839 v26 = abs((signed)LODWORD(a1.z) - v26); | |
840 //v25 = abs((signed)LODWORD(a1.y) - (signed)LODWORD(v24)); | |
841 //v8 = abs((int)a1.x - (signed)LODWORD(v23)); | |
842 v25 = abs((signed)LODWORD(a1.y) - (signed)_v24); | |
843 v8 = abs((int)a1.x - (signed)_v23); | |
844 LODWORD(a5) = v8; | |
845 v9 = v25; | |
846 v10 = v26; | |
847 if ( v8 < v25 ) | |
848 { | |
849 v11 = v8; | |
850 v8 = v25; | |
851 v9 = v11; | |
852 } | |
853 if ( v8 < v26 ) | |
854 { | |
855 v12 = v8; | |
856 v8 = v26; | |
857 v10 = v12; | |
858 } | |
859 if ( v9 < (signed int)v10 ) | |
860 { | |
861 v13 = v10; | |
862 v10 = v9; | |
863 v9 = v13; | |
864 } | |
865 v14 = (double)(signed int)(((unsigned int)(11 * v9) >> 5) + (v10 >> 2) + v8); | |
866 if ( v14 <= a3 ) | |
867 { | |
868 a5 = v14 / a3; | |
869 v16 = (double)(signed int)a1.x; | |
870 *(float *)&v23 = (double)SLODWORD(a1.y); | |
871 LODWORD(a1.x) = *(unsigned int *)LODWORD(v7); | |
872 v17 = LODWORD(v7) + 4; | |
873 *((float *)&v23 + 1) = (double)SLODWORD(a1.z); | |
874 LODWORD(a1.y) = *(unsigned int *)v17; | |
875 LODWORD(a1.z) = *(unsigned int *)(v17 + 4); | |
876 a3 = *((float *)&v23 + 1) - a1.z; | |
877 a1.z = a3; | |
878 a1.x = v16 - a1.x; | |
879 a1.y = (float)v23 - a1.y; | |
880 a1.Normalize(); | |
881 if ( uLightType & 4 ) | |
882 { | |
883 v22[1] = v18; | |
884 uLightType = dword_4D86D8; | |
885 v22[0] = v18; | |
886 v19 = fabs(a1.z * pNormal->z + a1.y * pNormal->y + a1.x * pNormal->x); | |
887 v20 = v19 * *(float *)&uLightType * a2; | |
888 } | |
889 else | |
890 { | |
891 if ( uLightType & 8 ) | |
892 { | |
893 v20 = 1.3 * a2; | |
894 } | |
895 else | |
896 { | |
897 MessageBoxW(nullptr, L"Invalid light type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:783", 0); | |
898 v20 = *(float *)&uLightType; | |
899 } | |
900 } | |
901 result = v20 - a5 * v20; | |
902 } | |
903 else | |
904 { | |
905 result = 0.0; | |
906 } | |
907 return result; | |
908 } | |
909 // 4D86D8: using guessed type int dword_4D86D8; | |
910 | |
911 //----- (0045CDB7) -------------------------------------------------------- | |
912 bool LightmapBuilder::ApplyLights_OutdoorFace(ODMFace *pFace) | |
913 { | |
914 int v2; // esi@1 | |
915 int v3; // eax@1 | |
916 MobileLight *pMobileLight; // ebx@2 | |
917 int v5; // esi@5 | |
918 StationaryLight *pStationaryLight; // ebx@6 | |
919 bool result; // eax@9 | |
920 LightmapBuilder *thisa; // [sp+Ch] [bp-8h]@1 | |
921 int pSlot; // [sp+10h] [bp-4h]@1 | |
922 | |
923 v2 = 0; | |
924 thisa = this; | |
925 v3 = stru_F8AD28.uDefaultAmbientLightLevel + pFace->uShadeType; | |
926 pSlot = 0; | |
927 stru_F8AD28.uCurrentAmbientLightLevel = v3 << 16; | |
928 if ( pMobileLightsStack->uNumLightsActive > 0 ) | |
929 { | |
930 pMobileLight = pMobileLightsStack->pLights; | |
931 do | |
932 { | |
933 if ( pSlot >= 20 ) | |
934 break; | |
935 ApplyLight_ODM((StationaryLight *)pMobileLight, pFace, (unsigned int *)&pSlot, 1); | |
936 ++v2; | |
937 ++pMobileLight; | |
938 } | |
939 while ( v2 < pMobileLightsStack->uNumLightsActive ); | |
940 } | |
941 v5 = 0; | |
942 if ( pStationaryLightsStack->uNumLightsActive > 0 ) | |
943 { | |
944 pStationaryLight = pStationaryLightsStack->pLights; | |
945 do | |
946 { | |
947 if ( pSlot >= 20 ) | |
948 break; | |
949 ApplyLight_ODM(pStationaryLight, pFace, (unsigned int *)&pSlot, 0); | |
950 ++v5; | |
951 ++pStationaryLight; | |
952 } | |
953 while ( v5 < pStationaryLightsStack->uNumLightsActive ); | |
954 } | |
955 result = pSlot; | |
956 stru_F8AD28.uNumLightsApplied = pSlot; | |
957 return true; | |
958 } | |
959 | |
960 //----- (0045CE50) -------------------------------------------------------- | |
961 bool LightmapBuilder::ApplyLight_ODM(StationaryLight *pLight, ODMFace *pFace, unsigned int *pSlot, char a4) | |
962 { | |
963 int result; // eax@0 | |
964 signed int v6; // ebx@1 | |
965 int v7; // ecx@2 | |
966 int v8; // esi@4 | |
967 int v9; // edx@6 | |
968 int v10; // ecx@8 | |
969 int v11; // eax@11 | |
970 unsigned int v12; // ebx@11 | |
971 RenderD3D *v13; // ecx@11 | |
972 char v14; // dl@11 | |
973 | |
62 | 974 //__debugbreak(); |
0 | 975 |
976 v6 = pLight->uRadius; | |
977 if ( v6 > 0 | |
978 && (result = (int)pFace, v7 = pLight->vPosition.x, v7 > pFace->pBoundingBox.x1 - v6) | |
979 && v7 < v6 + pFace->pBoundingBox.x2 | |
980 && (v8 = pLight->vPosition.y, v8 > pFace->pBoundingBox.y1 - v6) | |
981 && v8 < v6 + pFace->pBoundingBox.y2 | |
982 && (v9 = pLight->vPosition.z, v9 > pFace->pBoundingBox.z1 - v6) | |
983 && v9 < v6 + pFace->pBoundingBox.z2 | |
984 && ((v10 = (pFace->pFacePlane.dist | |
985 + pLight->vPosition.x * pFace->pFacePlane.vNormal.x | |
986 + v8 * pFace->pFacePlane.vNormal.y | |
987 + v9 * pFace->pFacePlane.vNormal.z) >> 16, | |
988 a4) | |
989 || v10 >= 0) | |
990 && v10 <= v6 ) | |
991 { | |
992 stru_F8AD28._blv_lights_radii[*pSlot] = v6; | |
993 stru_F8AD28._blv_lights_inv_radii[*pSlot] = 65536 / v6; | |
994 stru_F8AD28._blv_lights_xs[*pSlot] = pLight->vPosition.x; | |
995 stru_F8AD28._blv_lights_ys[*pSlot] = pLight->vPosition.y; | |
996 stru_F8AD28._blv_lights_zs[*pSlot] = pLight->vPosition.z; | |
997 stru_F8AD28._blv_lights_rs[*pSlot] = (double)pLight->uLightColorR * 0.0039215689; | |
998 stru_F8AD28._blv_lights_gs[*pSlot] = (double)pLight->uLightColorG * 0.0039215689; | |
999 stru_F8AD28._blv_lights_bs[*pSlot] = (double)pLight->uLightColorB * 0.0039215689; | |
1000 v11 = abs(v10); | |
1001 v12 = pRenderer->bUsingSpecular; | |
1002 stru_F8AD28._blv_lights_light_dot_faces[*pSlot] = v11; | |
1003 stru_F8AD28._blv_lights_types[*pSlot] = pLight->uLightType; | |
1004 v13 = pRenderer->pRenderD3D; | |
1005 v14 = stru_F8AD28._blv_lights_types[*pSlot]; | |
1006 if ( pRenderer->pRenderD3D && v12 && v14 & 4 ) | |
1007 v14 = _4E94D2_light_type; | |
1008 stru_F8AD28._blv_lights_types[*pSlot] = v14; | |
1009 result = 4 * *pSlot; | |
1010 if ( v13 && v12 ) | |
1011 { | |
1012 if ( stru_F8AD28._blv_lights_types[*pSlot] & 4 ) | |
1013 { | |
1014 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) | |
1015 * 0.33000001; | |
1016 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result) | |
1017 * 0.33000001; | |
1018 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result) | |
1019 * 0.33000001; | |
1020 } | |
1021 } | |
1022 ++*pSlot; | |
1023 LOBYTE(result) = 1; | |
1024 } | |
1025 else | |
1026 { | |
1027 LOBYTE(result) = 0; | |
1028 } | |
1029 return result; | |
1030 } | |
1031 // 4E94D2: using guessed type char _4E94D2_light_type; | |
1032 | |
1033 //----- (0045D036) -------------------------------------------------------- | |
86 | 1034 bool LightmapBuilder::StackLights_TerrainFace(Vec3_float_ *pNormal, float *a2, RenderVertexSoft *a3, unsigned int uStripType, bool bLightBackfaces) |
0 | 1035 { |
86 | 1036 /*int v6; // esi@1 |
0 | 1037 //LightmapBuilder *v7; // edi@1 |
1038 MobileLight *v8; // ebx@2 | |
1039 int v9; // esi@5 | |
1040 StationaryLight *v10; // ebx@6 | |
1041 //bool result; // eax@9 | |
1042 unsigned int a7; // [sp+Ch] [bp-4h]@1 | |
1043 | |
1044 v6 = 0; | |
1045 //v7 = this; | |
1046 a7 = 0; | |
1047 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->field_CBC_terrain_triangles_shade_type; | |
1048 if ( pMobileLightsStack->uNumLightsActive > 0 ) | |
1049 { | |
1050 v8 = pMobileLightsStack->pLights; | |
1051 do | |
1052 { | |
1053 if ( (signed int)a7 >= 20 ) | |
1054 break; | |
1055 StackLight_TerrainFace((StationaryLight *)v8, pNormal, a3, a1, uStripType, bLightBackfaces, &a7); | |
1056 ++v6; | |
1057 ++v8; | |
1058 } | |
1059 while ( v6 < pMobileLightsStack->uNumLightsActive ); | |
1060 } | |
1061 v9 = 0; | |
1062 if ( pStationaryLightsStack->uNumLightsActive > 0 ) | |
1063 { | |
1064 v10 = pStationaryLightsStack->pLights; | |
1065 do | |
1066 { | |
1067 if ( (signed int)a7 >= 20 ) | |
1068 break; | |
1069 StackLight_TerrainFace(v10, pNormal, a3, a1, uStripType, bLightBackfaces, &a7); | |
1070 ++v9; | |
1071 ++v10; | |
1072 } | |
1073 while ( v9 < pStationaryLightsStack->uNumLightsActive ); | |
1074 } | |
1075 | |
1076 stru_F8AD28.uNumLightsApplied = a7; | |
86 | 1077 return true;*/ |
1078 // bool __stdcall sub_45D036(struct Vec3<float> *pNormal, int a2, struct RenderVertex *a3, int a4, signed int X) | |
1079 //{ | |
1080 float v6; // ebx@2 | |
1081 unsigned int v10; // [sp+Ch] [bp-4h]@1 | |
1082 int i; | |
1083 | |
1084 v10 = 0; | |
638 | 1085 stru_F8AD28.uCurrentAmbientLightLevel = pOutdoor->max_terrain_dimming_level; |
86 | 1086 for (i = 0; i < pMobileLightsStack->uNumLightsActive; ++i) |
1087 { | |
1088 if ( v10 >= 20 ) | |
1089 break; | |
1090 StackLight_TerrainFace((StationaryLight *)&pMobileLightsStack->pLights[i], pNormal, a2, a3, uStripType, bLightBackfaces, &v10); | |
1091 } | |
1092 | |
1093 for (i = 0; i < pStationaryLightsStack->uNumLightsActive; ++i) | |
1094 { | |
1095 if ( v10 >= 20 ) | |
1096 break; | |
1097 StackLight_TerrainFace(&pStationaryLightsStack->pLights[i], pNormal, a2, a3, uStripType, bLightBackfaces, &v10); | |
1098 } | |
1099 | |
1100 stru_F8AD28.uNumLightsApplied = v10; | |
0 | 1101 return true; |
86 | 1102 |
0 | 1103 } |
1104 // 519AB4: using guessed type int uNumStationaryLightsApplied; | |
1105 | |
1106 //----- (0045D0D5) -------------------------------------------------------- | |
1107 bool LightmapBuilder::StackLight_TerrainFace(StationaryLight *pLight, Vec3_float_ *pNormal, float *a3, RenderVertexSoft *a1, unsigned int uStripType, int X, unsigned int *pSlot) | |
1108 { | |
1109 StationaryLight *v8; // edi@1 | |
1110 bool result; // eax@1 | |
1111 unsigned int v10; // esi@2 | |
1112 RenderVertexSoft *v11; // ebx@2 | |
1113 float v12; // eax@3 | |
1114 float v13; // eax@4 | |
1115 double v14; // st7@11 | |
1116 double maxz; // st7@11 | |
1117 double v16; // st7@11 | |
1118 double v17; // st6@11 | |
1119 __int16 v18; // fps@11 | |
1120 char v19; // c0@11 | |
1121 char v20; // c2@11 | |
1122 char v21; // c3@11 | |
1123 double v22; // st6@12 | |
1124 __int16 v23; // fps@12 | |
1125 char v24; // c0@12 | |
1126 char v25; // c2@12 | |
1127 char v26; // c3@12 | |
1128 double v27; // st7@13 | |
1129 double v28; // st6@13 | |
1130 __int16 v29; // fps@13 | |
1131 char v30; // c0@13 | |
1132 char v31; // c2@13 | |
1133 char v32; // c3@13 | |
1134 double v33; // st6@14 | |
1135 __int16 v34; // fps@14 | |
1136 char v35; // c0@14 | |
1137 char v36; // c2@14 | |
1138 char v37; // c3@14 | |
1139 double v38; // st7@15 | |
1140 double v39; // st6@15 | |
1141 __int16 v40; // fps@15 | |
1142 char v41; // c0@15 | |
1143 char v42; // c2@15 | |
1144 char v43; // c3@15 | |
1145 double v44; // st6@16 | |
1146 __int16 v45; // fps@16 | |
1147 char v46; // c0@16 | |
1148 char v47; // c2@16 | |
1149 char v48; // c3@16 | |
1150 Vec3_float_ *v49; // esi@17 | |
1151 double v50; // st7@17 | |
1152 double v51; // st6@17 | |
1153 signed int v52; // ecx@17 | |
1154 unsigned int *v53; // esi@18 | |
1155 int v54; // eax@18 | |
1156 unsigned int v55; // ebx@18 | |
1157 RenderD3D *v56; // ecx@18 | |
1158 char v57; // dl@18 | |
1159 std::string v58; // [sp-18h] [bp-38h]@10 | |
1160 const char *v59; // [sp-8h] [bp-28h]@10 | |
1161 signed int v60; // [sp-4h] [bp-24h]@10 | |
1162 double v61; // [sp+Ch] [bp-14h]@11 | |
1163 float minz; // [sp+14h] [bp-Ch]@11 | |
1164 int v63; // [sp+18h] [bp-8h]@1 | |
1165 float v64; // [sp+1Ch] [bp-4h]@5 | |
1166 | |
1167 v8 = pLight; | |
1168 result = pLight->uRadius; | |
1169 v63 = pLight->uRadius; | |
1170 if ( result <= 0 ) | |
86 | 1171 return 0; |
1172 //v10 = uStripType; | |
0 | 1173 v11 = a1; |
1174 if ( uStripType == 4 ) | |
1175 { | |
1176 pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x); | |
1177 v12 = a1[3].vWorldPosition.x; | |
1178 } | |
1179 else | |
1180 { | |
1181 if ( uStripType != 3 ) | |
1182 { | |
1183 MessageBoxW(nullptr, L"Uknown strip type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:981", 0); | |
1184 goto LABEL_11; | |
1185 } | |
1186 if ( (unsigned char)X ) | |
1187 { | |
1188 pLight = (StationaryLight *)LODWORD(a1->vWorldPosition.x); | |
1189 uStripType = LODWORD(a1[2].vWorldPosition.x); | |
1190 a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y); | |
1191 v13 = v11[2].vWorldPosition.y; | |
1192 goto LABEL_5; | |
1193 } | |
1194 pLight = (StationaryLight *)LODWORD(a1[1].vWorldPosition.x); | |
1195 v12 = a1[2].vWorldPosition.x; | |
1196 } | |
1197 uStripType = LODWORD(v12); | |
1198 a1 = (RenderVertexSoft *)LODWORD(a1[1].vWorldPosition.y); | |
1199 v13 = v11->vWorldPosition.y; | |
1200 LABEL_5: | |
1201 v64 = v13; | |
1202 LABEL_11: | |
86 | 1203 //v60 = v10; |
0 | 1204 v59 = (const char *)v11; |
86 | 1205 v60 = uStripType; |
1206 minz = pGame->pIndoorCameraD3D->GetPolygonMinZ(v11, uStripType); | |
1207 maxz = pGame->pIndoorCameraD3D->GetPolygonMaxZ(v11, uStripType); | |
0 | 1208 result = v8->vPosition.x; |
1209 *((float *)&v61 + 1) = maxz; | |
1210 v16 = (double)result; | |
1211 *(float *)&X = (double)v63; | |
1212 v17 = *(float *)&pLight - *(float *)&X; | |
1213 //UNDEF(v18); | |
86 | 1214 //v19 = v16 < v17; |
0 | 1215 v20 = 0; |
86 | 1216 //v21 = v16 == v17; |
1217 /* BYTE1(result) = HIBYTE(v18); | |
0 | 1218 if ( v16 <= v17 |
1219 || (v22 = *(float *)&X + *(float *)&uStripType, | |
1220 //UNDEF(v23), | |
1221 v24 = v16 < v22, | |
1222 v25 = 0, | |
1223 v26 = v16 == v22, | |
1224 BYTE1(result) = HIBYTE(v23), | |
1225 v16 >= v22) | |
1226 || (result = v8->vPosition.y, | |
1227 pLight = (StationaryLight *)v8->vPosition.y, | |
1228 v27 = (double)(signed int)pLight, | |
1229 v28 = *(float *)&a1 - *(float *)&X, | |
1230 //UNDEF(v29), | |
1231 v30 = v27 < v28, | |
1232 v31 = 0, | |
1233 v32 = v27 == v28, | |
1234 BYTE1(result) = HIBYTE(v29), | |
1235 v27 <= v28) | |
1236 || (v33 = *(float *)&X + v64, | |
1237 //UNDEF(v34), | |
1238 v35 = v27 < v33, | |
1239 v36 = 0, | |
1240 v37 = v27 == v33, | |
1241 BYTE1(result) = HIBYTE(v34), | |
1242 v27 >= v33) | |
1243 || (result = v8->vPosition.z, | |
1244 pLight = (StationaryLight *)v8->vPosition.z, | |
1245 v38 = (double)(signed int)pLight, | |
1246 v39 = minz - *(float *)&X, | |
1247 //UNDEF(v40), | |
1248 v41 = v38 < v39, | |
1249 v42 = 0, | |
1250 v43 = v38 == v39, | |
1251 BYTE1(result) = HIBYTE(v40), | |
1252 v38 <= v39) | |
1253 || (v44 = *(float *)&X + *((float *)&v61 + 1), | |
1254 //UNDEF(v45), | |
1255 v46 = v38 < v44, | |
1256 v47 = 0, | |
1257 v48 = v38 == v44, | |
1258 BYTE1(result) = HIBYTE(v45), | |
1259 v38 >= v44) | |
1260 || (v49 = pNormal, | |
1261 Vec3_float_::NegDot(&v11->vWorldPosition, pNormal, a3), | |
1262 X = v8->vPosition.y, | |
1263 v50 = (double)X * v49->y, | |
1264 X = v8->vPosition.z, | |
1265 v51 = (double)X * v49->z, | |
1266 X = v8->vPosition.x, | |
1267 *(float *)&a3 = v50 + v51 + (double)X * v49->x + *a3, | |
1268 v61 = *(float *)&a3 + 6.7553994e15, | |
1269 result = LODWORD(v61), | |
1270 X = LODWORD(v61), | |
1271 v52 = v63, | |
86 | 1272 SLODWORD(v61) > v63) )*/ |
1273 if (0) | |
1274 return 0; | |
0 | 1275 v53 = pSlot; |
1276 v60 = X; | |
1277 stru_F8AD28._blv_lights_radii[*pSlot] = v63; | |
86 | 1278 stru_F8AD28._blv_lights_inv_radii[*v53] = 65536 / v63; |
0 | 1279 stru_F8AD28._blv_lights_xs[*v53] = v8->vPosition.x; |
1280 stru_F8AD28._blv_lights_ys[*v53] = v8->vPosition.y; | |
1281 stru_F8AD28._blv_lights_zs[*v53] = v8->vPosition.z; | |
1282 a3 = (float *)v8->uLightColorR; | |
86 | 1283 stru_F8AD28._blv_lights_rs[*v53] = (double)(signed int)a3 * 0.003921568859368563; |
0 | 1284 a3 = (float *)v8->uLightColorG; |
86 | 1285 stru_F8AD28._blv_lights_gs[*v53] = (double)(signed int)a3 * 0.003921568859368563; |
0 | 1286 a3 = (float *)v8->uLightColorB; |
86 | 1287 stru_F8AD28._blv_lights_bs[*v53] = (double)(signed int)a3 * 0.003921568859368563; |
0 | 1288 v54 = abs(v60); |
1289 v55 = pRenderer->bUsingSpecular; | |
1290 stru_F8AD28._blv_lights_light_dot_faces[*v53] = v54; | |
1291 stru_F8AD28._blv_lights_types[*v53] = v8->uLightType; | |
1292 v56 = pRenderer->pRenderD3D; | |
1293 v57 = stru_F8AD28._blv_lights_types[*v53]; | |
1294 if ( pRenderer->pRenderD3D && v55 && v57 & 4 ) | |
1295 v57 = _4E94D2_light_type; | |
1296 stru_F8AD28._blv_lights_types[*v53] = v57; | |
1297 result = 4 * *v53; | |
1298 if ( v56 && v55 ) | |
1299 { | |
1300 if ( stru_F8AD28._blv_lights_types[*v53] & 4 ) | |
1301 { | |
1302 *(float *)((char *)stru_F8AD28._blv_lights_rs + result) = *(float *)((char *)stru_F8AD28._blv_lights_rs + result) | |
86 | 1303 * 0.3300000131130219; |
0 | 1304 *(float *)((char *)stru_F8AD28._blv_lights_gs + result) = *(float *)((char *)stru_F8AD28._blv_lights_gs + result) |
86 | 1305 * 0.3300000131130219; |
0 | 1306 *(float *)((char *)stru_F8AD28._blv_lights_bs + result) = *(float *)((char *)stru_F8AD28._blv_lights_bs + result) |
86 | 1307 * 0.3300000131130219; |
0 | 1308 } |
1309 } | |
1310 ++*v53; | |
86 | 1311 return 1; |
0 | 1312 } |
1313 // 4E94D2: using guessed type char _4E94D2_light_type; | |
1314 | |
1315 //----- (0045D3C7) -------------------------------------------------------- | |
1391
cc9a3a24d61d
Moved stru11, stru12 and some SW Rendering stuff to the archives.
Nomad
parents:
1390
diff
changeset
|
1316 bool LightmapBuilder::_45D3C7(struct Polygon *a1) |
0 | 1317 { |
1318 LightmapBuilder *v2; // ebx@1 | |
1391
cc9a3a24d61d
Moved stru11, stru12 and some SW Rendering stuff to the archives.
Nomad
parents:
1390
diff
changeset
|
1319 struct Polygon *result; // eax@1 |
0 | 1320 float v4; // ecx@2 |
1321 Span *i; // edi@5 | |
1322 | |
1323 v2 = this; | |
1391
cc9a3a24d61d
Moved stru11, stru12 and some SW Rendering stuff to the archives.
Nomad
parents:
1390
diff
changeset
|
1324 result = (struct Polygon *)a1->prolly_head; |
0 | 1325 if ( result && (v4 = result->field_4, *(int *)&v4) != 0 && *(unsigned int *)(LODWORD(v4) + 60) ) |
1326 { | |
1327 for ( i = a1->prolly_head; ; i = i->pNext ) | |
1328 { | |
1329 result = i->pParent; | |
1330 if ( result->field_108 ) | |
1391
cc9a3a24d61d
Moved stru11, stru12 and some SW Rendering stuff to the archives.
Nomad
parents:
1390
diff
changeset
|
1331 result = (struct Polygon *)_45D426( |
0 | 1332 i, |
1333 a1->pEdgeList1, | |
1334 a1->uEdgeList1Size, | |
1335 (Edge *)a1->pEdgeList2, | |
1336 a1->uEdgeList2Size); | |
1337 if ( a1->prolly_tail == i ) | |
1338 break; | |
1339 } | |
1340 LOBYTE(result) = 1; | |
1341 } | |
1342 else | |
1343 { | |
1344 LOBYTE(result) = 0; | |
1345 } | |
1346 return (bool)result; | |
1347 } | |
1348 | |
1349 //----- (0045D426) -------------------------------------------------------- | |
1350 int LightmapBuilder::_45D426(Span *a1, Edge **a2, unsigned int a3, Edge *a4, int a5) | |
1351 { | |
1352 int v6; // edi@1 | |
1353 signed int v7; // ebx@3 | |
1354 signed int v8; // ecx@3 | |
1355 Span *v9; // esi@3 | |
1356 double v10; // st7@4 | |
1357 Edge *v11; // edx@5 | |
1358 double v12; // st7@11 | |
1359 int v13; // edx@12 | |
1360 int v14; // ebx@17 | |
1361 Edge *v15; // edi@17 | |
1362 float v16; // ST04_4@17 | |
1363 float v17; // ST04_4@17 | |
1364 double v18; // st7@17 | |
1365 int result; // eax@19 | |
1366 //double v20; // ST14_8@20 | |
1367 //double v21; // ST14_8@20 | |
1368 double v22; // st7@20 | |
1369 int v23; // ecx@20 | |
1370 double v24; // st6@20 | |
1371 double v25; // st7@23 | |
1372 double v26; // st7@28 | |
1373 __int16 v27; // fps@28 | |
1374 char v28; // c0@28 | |
1375 char v29; // c2@28 | |
1376 char v30; // c3@28 | |
1377 double v31; // st7@29 | |
1378 double v32; // st7@30 | |
1379 __int16 v33; // fps@30 | |
1380 char v34; // c0@30 | |
1381 char v35; // c2@30 | |
1382 char v36; // c3@30 | |
1383 LightmapBuilder *this_4; // [sp+14h] [bp-8h]@1 | |
1384 signed int v38; // [sp+18h] [bp-4h]@3 | |
1385 float a1a; // [sp+24h] [bp+8h]@20 | |
1386 float a2a; // [sp+28h] [bp+Ch]@17 | |
1387 float a3a; // [sp+2Ch] [bp+10h]@17 | |
1388 float a5a; // [sp+34h] [bp+18h]@20 | |
1389 float a5b; // [sp+34h] [bp+18h]@20 | |
1390 | |
1391 v6 = 0; | |
1392 this_4 = this; | |
1393 if ( a5 && a3 ) | |
1394 { | |
1395 v7 = -1; | |
1396 v8 = 0; | |
1397 v9 = a1; | |
1398 v38 = -1; | |
1399 if ( (signed int)a3 > 0 ) | |
1400 { | |
1401 v10 = (double)a1->field_A; | |
1402 while ( 1 ) | |
1403 { | |
1404 v11 = a2[v8]; | |
1405 if ( v10 >= v11->field_2C ) | |
1406 { | |
1407 if ( v10 <= v11->field_30 ) | |
1408 break; | |
1409 } | |
1410 ++v8; | |
1411 if ( v8 >= (signed int)a3 ) | |
1412 goto LABEL_10; | |
1413 } | |
1414 v38 = v8; | |
1415 } | |
1416 LABEL_10: | |
1417 if ( a5 > 0 ) | |
1418 { | |
1419 v12 = (double)a1->field_A; | |
1420 while ( 1 ) | |
1421 { | |
1422 v13 = *((unsigned int *)&a4->field_0 + v6); | |
1423 if ( v12 >= *(float *)(v13 + 44) ) | |
1424 { | |
1425 if ( v12 <= *(float *)(v13 + 48) ) | |
1426 break; | |
1427 } | |
1428 ++v6; | |
1429 if ( v6 >= a5 ) | |
1430 goto LABEL_17; | |
1431 } | |
1432 v7 = v6; | |
1433 } | |
1434 LABEL_17: | |
1435 v14 = *((unsigned int *)&a4->field_0 + v7); | |
1436 v15 = a2[v38]; | |
1437 v16 = (double)a1->field_A; | |
1438 a3a = _45D643(a2[v38], v16); | |
1439 v17 = (double)a1->field_A; | |
1440 v18 = _45D643((Edge *)v14, v17); | |
1441 a2a = v18; | |
1442 if ( byte_4D864C && BYTE1(pGame->uFlags) & 0x80 ) | |
1443 { | |
1444 HIWORD(result) = HIWORD(a3a); | |
1445 a1->field_14 = v18; | |
1446 a1->field_10 = a3a; | |
1447 } | |
1448 else | |
1449 { | |
1450 a5a = ((double)a1->field_A - v15->field_2C) * v15->field_4 + v15->field_24 - 0.5; | |
1451 //v20 = a5a + 6.7553994e15; | |
1452 //a5b = (double)SLODWORD(v20); | |
1453 a5b = (double)floorf(a5a + 0.5f); | |
1454 a1a = ((double)a1->field_A - *(float *)(v14 + 44)) * *(float *)(v14 + 4) + *(float *)(v14 + 36) + 0.5; | |
1455 //v21 = a1a + 6.7553994e15; | |
1456 //v22 = (double)SLODWORD(v21); | |
1457 v22 = (double)floorf(a1a + 0.5f); | |
1458 result = v9->field_8; | |
1459 v23 = v9->field_C; | |
1460 v24 = -((a3a - a2a) / (v22 - a5b)); | |
1461 v9->field_10 = ((double)result - a5b) * v24 + a3a; | |
1462 v9->field_14 = a2a - (v22 - (double)(result + v23)) * v24; | |
1463 } | |
1464 if ( v9->field_10 < 0.0 || v9->field_10 <= 1.0 ) | |
1465 { | |
1466 if ( v9->field_10 >= 0.0 ) | |
1467 v25 = v9->field_10; | |
1468 else | |
1469 v25 = 0.0; | |
1470 } | |
1471 else | |
1472 { | |
1473 v25 = 1.0; | |
1474 } | |
1475 v9->field_10 = v25; | |
1476 if ( v9->field_14 < 0.0 | |
1477 || (v26 = v9->field_14, | |
1478 //UNDEF(v27), | |
1479 v28 = 1.0 < v26, | |
1480 v29 = 0, | |
1481 v30 = 1.0 == v26, | |
1482 BYTE1(result) = HIBYTE(v27), | |
1483 v26 <= 1.0) ) | |
1484 { | |
1485 v32 = v9->field_14; | |
1486 //UNDEF(v33); | |
1487 v34 = 0.0 < v32; | |
1488 v35 = 0; | |
1489 v36 = 0.0 == v32; | |
1490 BYTE1(result) = HIBYTE(v33); | |
1491 if ( v32 >= 0.0 ) | |
1492 v31 = v9->field_14; | |
1493 else | |
1494 v31 = 0.0; | |
1495 } | |
1496 else | |
1497 { | |
1498 v31 = 1.0; | |
1499 } | |
1500 v9->field_14 = v31; | |
1501 LOBYTE(result) = 1; | |
1502 } | |
1503 else | |
1504 { | |
1505 LOBYTE(result) = 0; | |
1506 } | |
1507 return result; | |
1508 } | |
1509 // 4D864C: using guessed type char byte_4D864C; | |
1510 | |
1511 //----- (0045D643) -------------------------------------------------------- | |
1512 double LightmapBuilder::_45D643(Edge *a1, float a2) | |
1513 { | |
1514 double result; // st7@1 | |
1515 | |
1516 result = (a1->field_1C - a1->field_20) * -1.0 / (a1->field_30 - a1->field_2C) * (a2 - a1->field_2C) + a1->field_1C; | |
1517 if ( result < 0.0 || result <= 1.0 ) | |
1518 { | |
1519 if ( result < 0.0 ) | |
1520 result = 0.0; | |
1521 } | |
1522 else | |
1523 { | |
1524 result = 1.0; | |
1525 } | |
1526 return result; | |
1527 } | |
1528 | |
1529 //----- (0045D698) -------------------------------------------------------- | |
1530 bool LightmapBuilder::DrawDebugOutlines(char bit_one_for_list1__bit_two_for_list2) | |
1531 { | |
1532 bool result; // eax@1 | |
1533 LightmapBuilder *v3; // esi@1 | |
1534 RenderVertexSoft *v4; // edi@3 | |
1535 RenderVertexSoft *v5; // edi@7 | |
1536 IndoorCameraD3D *thisa; // [sp+10h] [bp-8h]@1 | |
1537 bool v7; // [sp+14h] [bp-4h]@2 | |
1538 bool a2a; // [sp+20h] [bp+8h]@6 | |
1539 | |
1540 result = (bool)pGame->pIndoorCameraD3D; | |
1541 v3 = this; | |
1542 thisa = pGame->pIndoorCameraD3D; | |
1543 if ( bit_one_for_list1__bit_two_for_list2 & 1 ) | |
1544 { | |
1545 v7 = 0; | |
1546 if ( (signed int)this->std__vector_000004_size > 0 ) | |
1547 { | |
1548 v4 = this->std__vector_000004[0].pVertices; | |
1549 do | |
1550 { | |
1551 pGame->pIndoorCameraD3D->debug_outline_sw(v4, *((unsigned int *)v4 - 1), 0xFF00u, 0.0); | |
1552 ++v7; | |
1553 v4 = (RenderVertexSoft *)((char *)v4 + 3100); | |
1554 result = v7; | |
1555 } | |
1556 while ( v7 < (signed int)v3->std__vector_000004_size ); | |
1557 } | |
1558 } | |
1559 if ( bit_one_for_list1__bit_two_for_list2 & 2 ) | |
1560 { | |
1561 a2a = 0; | |
1562 if ( (signed int)v3->std__vector_183808_size > 0 ) | |
1563 { | |
1564 v5 = v3->std__vector_183808[0].pVertices; | |
1565 do | |
1566 { | |
1567 pGame->pIndoorCameraD3D->debug_outline_sw(v5, *((unsigned int *)v5 - 1), 0xC04000u, 0.00019999999); | |
1568 ++a2a; | |
1569 v5 = (RenderVertexSoft *)((char *)v5 + 3100); | |
1570 result = a2a; | |
1571 } | |
1572 while ( a2a < (signed int)v3->std__vector_183808_size ); | |
1573 } | |
1574 } | |
1575 LOBYTE(result) = 1; | |
1576 return result; | |
1577 } | |
1578 | |
1579 //----- (0045D73F) -------------------------------------------------------- | |
1394 | 1580 void LightmapBuilder::DrawLightmapsType(int type) |
0 | 1581 { |
1394 | 1582 if (type == 2) |
1583 Draw_183808_Lightmaps(); | |
0 | 1584 } |
1585 | |
1586 //----- (0045D74F) -------------------------------------------------------- | |
1394 | 1587 bool LightmapBuilder::DrawLightmaps(int *indices) |
0 | 1588 { |
1390 | 1589 //char v3; // zf@1 |
0 | 1590 IDirect3DDevice3 *v4; // eax@2 |
1591 HRESULT v5; // eax@2 | |
1592 //char *v6; // eax@2 | |
1593 struct IDirect3DTexture2 *v7; // edi@4 | |
1594 HRESULT v8; // eax@8 | |
1595 HRESULT v9; // eax@8 | |
1596 HRESULT v10; // eax@8 | |
1597 HRESULT v11; // eax@8 | |
1598 HRESULT v12; // eax@8 | |
1394 | 1599 //int *v13; // eax@8 |
1390 | 1600 //float v14; // ecx@15 |
1601 //IDirect3DDevice3 *v15; // eax@21 | |
1602 //HRESULT v16; // eax@21 | |
1603 //IDirect3DDevice3 *v17; // eax@21 | |
1604 //HRESULT v18; // eax@21 | |
1605 //IDirect3DDevice3 *v19; // eax@21 | |
1606 //HRESULT v20; // eax@21 | |
1607 //IDirect3DDevice3 *v21; // eax@21 | |
1608 //HRESULT v22; // eax@21 | |
0 | 1609 //IDirect3DDevice3 *v23; // eax@23 |
1610 std::string v25; // [sp+44h] [bp-44h]@12 | |
1611 signed int v26; // [sp+48h] [bp-40h]@21 | |
1612 signed int v27; // [sp+4Ch] [bp-3Ch]@21 | |
1613 Lightmap *v28; // [sp+50h] [bp-38h]@2 | |
1614 int v29; // [sp+54h] [bp-34h]@2 | |
1615 //float v30; // [sp+58h] [bp-30h]@2 | |
1394 | 1616 Vec3_float_ arg4; |
1617 //int arg4; // [sp+68h] [bp-20h]@8 | |
1618 //float v32; // [sp+6Ch] [bp-1Ch]@8 | |
1619 //float v33; // [sp+70h] [bp-18h]@8 | |
0 | 1620 int v34; // [sp+74h] [bp-14h]@19 |
1621 int v35; // [sp+78h] [bp-10h]@2 | |
1394 | 1622 //int *v36; // [sp+7Ch] [bp-Ch]@10 |
1390 | 1623 //int a1; // [sp+80h] [bp-8h]@12 |
1624 //float v38; // [sp+84h] [bp-4h]@1 | |
0 | 1625 |
1390 | 1626 if (std__vector_000004_size == 0) |
1627 return 1; | |
1628 | |
1394 | 1629 |
1630 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP)); | |
1631 | |
1632 v7 = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03"); | |
1633 if ( pRenderer->bUsingSpecular ) | |
1634 pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE); | |
1635 | |
1636 if ( !byte_4D864C || !(pGame->uFlags & GAME_FLAGS_1_01) ) | |
1637 { | |
186 | 1638 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); |
1639 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); | |
0 | 1640 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, v7)); |
186 | 1641 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1642 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); | |
1394 | 1643 |
1644 arg4.x = 1.0f; | |
1645 arg4.y = 1.0f; | |
1646 arg4.z = 1.0f; | |
1647 if (indices) | |
0 | 1648 { |
1394 | 1649 for (auto i = indices; *i != -1; ++i) |
0 | 1650 { |
1394 | 1651 v28 = &std__vector_000004[*i]; |
1652 if ( !DrawLightmap(v28, &arg4, 0.0) ) | |
1653 assert(false && "Invalid lightmap detected!"); | |
0 | 1654 } |
1655 } | |
1656 else | |
1657 { | |
1394 | 1658 for (auto i = 0; i < std__vector_000004_size; ++i) |
0 | 1659 { |
1394 | 1660 auto _a1 = &std__vector_000004[(int)i]; |
1661 if ( !DrawLightmap(_a1, &arg4, 0.0) ) | |
0 | 1662 { |
1663 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1238", 0); | |
1664 v35 = 5080812; | |
1665 } | |
1666 } | |
1667 } | |
1394 | 1668 |
1390 | 1669 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1670 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); | |
1671 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); | |
1672 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); | |
1394 | 1673 } |
1674 | |
0 | 1675 if ( pRenderer->bUsingSpecular ) |
1676 { | |
1677 //LODWORD(v30) = 1; | |
1678 //v29 = 28; | |
1679 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; | |
186 | 1680 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); |
0 | 1681 //v30 = pRenderer->uFogColor; |
1682 //v23 = pRenderer->pRenderD3D->pDevice; | |
1683 //v29 = 34; | |
1684 //v28 = (Lightmap *)v23; | |
1685 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, pRenderer->uFogColor)); | |
1686 //v28 = (Lightmap *)pRenderer->pRenderD3D->pDevice; | |
186 | 1687 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0)); |
0 | 1688 } |
1390 | 1689 |
1394 | 1690 return true; |
0 | 1691 } |
1692 | |
1693 | |
1694 //----- (0045DA56) -------------------------------------------------------- | |
1394 | 1695 bool LightmapBuilder::DoDraw_183808_Lightmaps(float z_bias) |
0 | 1696 { |
1697 Vec3_float_ v; // [sp+Ch] [bp-1Ch]@2 | |
1698 v.z = 1.0; | |
1699 v.y = 1.0; | |
1700 v.x = 1.0; | |
1701 | |
1702 for (uint i = 0; i < std__vector_183808_size; ++i) | |
1703 if (!DrawLightmap(std__vector_183808 + i, &v, z_bias)) | |
1704 MessageBoxW(nullptr, L"Invalid lightmap detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:1288", 0); | |
1705 | |
1706 return true; | |
1707 } | |
1708 | |
1709 //----- (0045DAE8) -------------------------------------------------------- | |
1710 bool LightmapBuilder::DrawLightmap(Lightmap *pLightmap, Vec3_float_ *pColorMult, float z_bias) | |
1711 { | |
1712 double v10; // st7@4 | |
1713 double v14; // st7@7 | |
1714 __int16 v15; // fps@8 | |
1715 double v18; // st3@8 | |
1716 signed int v24; // [sp-1Ch] [bp-670h]@13 | |
1717 const char *v25; // [sp-18h] [bp-66Ch]@13 | |
1718 int v26; // [sp-14h] [bp-668h]@13 | |
1719 RenderVertexD3D3 a2[32]; // [sp+0h] [bp-654h]@7 | |
1720 | |
1721 | |
1722 if (pLightmap->uNumVertices < 3) | |
1723 { | |
1724 Log::Warning(L"Lightmap uNumVertices < 3"); | |
1725 return false; | |
1726 } | |
1727 | |
1728 uint uLightmapColorMaskR = (pLightmap->uColorMask >> 16) & 0xFF; | |
1729 uint uLightmapColorR = floorf(uLightmapColorMaskR * pLightmap->fBrightness * pColorMult->x + 0.5f); | |
1730 | |
1731 uint uLightmapColorMaskG = (pLightmap->uColorMask >> 8) & 0xFF; | |
1732 uint uLightmapColorG = floorf(uLightmapColorMaskG * pLightmap->fBrightness * pColorMult->y + 0.5f); | |
1733 | |
1734 uint uLightmapColorMaskB = pLightmap->uColorMask & 0xFF; | |
1735 uint uLightmapColorB = floorf(uLightmapColorMaskB * pLightmap->fBrightness * pColorMult->z + 0.5f); | |
1736 | |
1737 uint uLightmapColor = uLightmapColorB | (uLightmapColorMaskG << 8) | (uLightmapColorMaskR << 16); | |
1738 | |
1739 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
1740 v10 = (double)pOutdoorCamera->shading_dist_mist; | |
1741 else | |
1742 v10 = 16192.0; | |
1743 v14 = 1.0 / v10; | |
1744 | |
1745 for (uint i = 0; i < pLightmap->uNumVertices; ++i) | |
1746 { | |
1747 v18 = 1.0 - 1.0 / (v14 * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0); | |
1748 if (fabsf(z_bias) < 1e-5f) | |
1749 { | |
1750 v18 = v18 - z_bias; | |
1751 if (v18 < 0.000099999997) | |
1752 v18 = 0.000099999997; | |
1753 } | |
1754 | |
1755 a2[i].pos.x = pLightmap->pVertices[i].vWorldViewProjX; | |
1756 a2[i].pos.z = v18; | |
1757 a2[i].pos.y = pLightmap->pVertices[i].vWorldViewProjY; | |
1758 a2[i].rhw = 1.0 / pLightmap->pVertices[i].vWorldViewPosition.x; | |
1759 a2[i].diffuse = uLightmapColor; | |
1760 a2[i].specular = 0; | |
1761 a2[i].texcoord.x = pLightmap->pVertices[i].u; | |
1762 a2[i].texcoord.y = pLightmap->pVertices[i].v; | |
1763 } | |
1764 | |
1765 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
1766 v24 = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS; | |
1767 else | |
1768 v24 = D3DDP_DONOTLIGHT; | |
1769 | |
1770 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, | |
1771 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, | |
1772 a2, | |
1773 pLightmap->uNumVertices, | |
1774 v24)); | |
1775 | |
1776 return true; | |
1777 } | |
1778 | |
1779 //----- (0045DCA9) -------------------------------------------------------- | |
1394 | 1780 void LightmapBuilder::Draw_183808_Lightmaps() |
0 | 1781 { |
1782 if (!std__vector_183808_size) | |
1783 return; | |
1784 | |
1785 if (pRenderer->bUsingSpecular) | |
186 | 1786 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE)); |
0 | 1787 |
186 | 1788 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE)); |
1789 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE)); | |
1790 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); | |
1791 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); | |
0 | 1792 |
1793 auto pTex = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03"); | |
1794 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex)); | |
1795 | |
186 | 1796 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1797 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); | |
0 | 1798 |
1394 | 1799 DoDraw_183808_Lightmaps(0.00050000002); |
0 | 1800 |
186 | 1801 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); |
1802 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); | |
1803 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); | |
1804 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); | |
1805 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE)); | |
1806 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW)); | |
0 | 1807 |
1808 if (pRenderer->bUsingSpecular) | |
186 | 1809 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); |
0 | 1810 } |