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