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