Mercurial > mm7
annotate DecalBuilder.cpp @ 1241:ae812777b1d4
fix in arcomagecards
author | Gloval |
---|---|
date | Mon, 10 Jun 2013 00:09:21 +0400 |
parents | 45a8862d8b6e |
children | 1803172dffd9 |
rev | line source |
---|---|
0 | 1 #include "DecalBuilder.h" |
2 #include "Game.h" | |
3 #include "Time.h" | |
4 #include "stru314.h" | |
5 #include "Outdoor.h" | |
6 #include "Log.h" | |
7 | |
8 #include "mm7_data.h" | |
9 | |
1016 | 10 #include "stru9.h" |
0 | 11 |
12 | |
13 | |
14 struct DecalBuilder *pDecalBuilder = new DecalBuilder; | |
15 struct BloodsplatContainer *pBloodsplatContainer = new BloodsplatContainer; | |
16 | |
17 | |
18 //----- (0043B570) -------------------------------------------------------- | |
19 double DecalBuilder_stru0::_43B570_get_color_mult_by_time() | |
20 { | |
21 double result; // st7@3 | |
22 | |
23 if (field_1C_flags & 1) | |
24 { | |
25 if ((field_20_time - pEventTimer->Time() + 384) / 384.0 >= 0.0) | |
26 result = (field_20_time - pEventTimer->Time() + 384) / 384.0; | |
27 else | |
28 result = 0.0; | |
29 } | |
30 else | |
31 { | |
32 result = 1.0; | |
33 } | |
34 return result; | |
35 } | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 //----- (0043B6EF) -------------------------------------------------------- | |
42 bool BloodsplatContainer::AddBloodsplat(float x, float y, float z, float radius, char r, char g, char b) | |
43 { | |
44 int *v8; // esi@1 | |
45 int v9; // eax@3 | |
46 Bloodsplat *v10; // eax@3 | |
47 int *result; // eax@3 | |
48 int v12; // ecx@3 | |
49 | |
50 v8 = &this->uNumBloodsplats; | |
51 if ( this->uNumBloodsplats == 64 ) | |
52 *v8 = 0; | |
53 v9 = 5 * (*v8)++; | |
54 v10 = &this->std__vector_pBloodsplats[8 * v9 / 0x28u]; | |
55 v10->x = x; | |
56 v10->y = y; | |
57 v10->z = z; | |
58 v10->radius = radius; | |
59 v10->r = r; | |
60 v10->g = g; | |
61 v10->b = b; | |
62 result = (int *)&this->std__vector_pBloodsplats_size; | |
63 v12 = this->std__vector_pBloodsplats_size + 1; | |
64 if ( v12 > 64 ) | |
65 v12 = 64; | |
66 *result = v12; | |
67 LOBYTE(result) = 1; | |
68 return (bool)result; | |
69 } | |
70 | |
71 //----- (0049B490) -------------------------------------------------------- | |
72 bool DecalBuilder::AddBloodsplat(float x, float y, float z, float r, float g, float b, float radius, int a8, int a9) | |
73 { | |
74 //double v10; // ST1C_8@1 | |
75 char v11; // ST24_1@1 | |
76 //double v12; // ST1C_8@1 | |
77 //double v13; // ST1C_8@1 | |
78 int a7a; // [sp+40h] [bp+18h]@1 | |
79 //float arg14a; // [sp+44h] [bp+1Ch]@1 | |
80 //float arg14b; // [sp+44h] [bp+1Ch]@1 | |
81 //float arg14c; // [sp+44h] [bp+1Ch]@1 | |
82 | |
83 /*arg14a = b * 255.0; | |
84 v10 = arg14a + 6.7553994e15; | |
85 v11 = LOBYTE(v10); | |
86 arg14b = g * 255.0; | |
87 v12 = arg14b + 6.7553994e15; | |
88 a7a = LODWORD(v12); | |
89 arg14c = r * 255.0; | |
90 v13 = arg14c + 6.7553994e15;*/ | |
91 return pBloodsplatContainer->AddBloodsplat(x, y, z, radius, | |
92 //SLOBYTE(v13), a7a, v11); | |
93 r * 255.0f, | |
94 g * 255.0f, | |
95 b * 255.0f); | |
96 } | |
97 | |
98 //----- (0049B525) -------------------------------------------------------- | |
99 void DecalBuilder::Reset(unsigned int bPreserveBloodsplats) | |
100 { | |
101 if ( !bPreserveBloodsplats ) | |
102 { | |
103 pBloodsplatContainer->std__vector_pBloodsplats_size = 0; | |
104 pBloodsplatContainer->uNumBloodsplats = 0; | |
105 } | |
106 std__vector_pDecals_size = 0; | |
107 } | |
108 | |
109 //----- (0049B540) -------------------------------------------------------- | |
638 | 110 char DecalBuilder::ApplyDecals(int light_level, char a3, stru154 *a4, int a5, RenderVertexSoft *a6, IndoorCameraD3D_Vec4 *a7, char a8, unsigned int uSectorID) |
0 | 111 { |
112 char *v9; // eax@3 | |
113 signed int v10; // ecx@3 | |
114 RenderVertexSoft *v11; // eax@10 | |
115 unsigned int v12; // edx@10 | |
116 RenderVertexSoft *v13; // esi@11 | |
117 RenderVertexSoft *v14; // edi@11 | |
118 char v15; // zf@11 | |
119 stru154 *v16; // esi@12 | |
120 double v18; // st7@17 | |
121 double v19; // st6@17 | |
122 float v20; // eax@17 | |
123 Bloodsplat *v21; // esi@21 | |
124 int v22; // eax@21 | |
125 int v23; // ecx@21 | |
126 double v24; // st7@21 | |
127 int v25; // ebx@21 | |
128 double v26; // st7@21 | |
129 int v27; // edi@21 | |
130 double v28; // st7@21 | |
1077 | 131 float v29; // ST10_4@21 |
0 | 132 int v30; // ST08_4@21 |
920 | 133 //DecalBuilder *v31; // esi@21 |
0 | 134 int v32; // [sp+4h] [bp-44h]@18 |
1077 | 135 float v33; // [sp+8h] [bp-40h]@21 |
0 | 136 stru314 *v34; // [sp+Ch] [bp-3Ch]@21 |
137 float v35; // [sp+10h] [bp-38h]@21 | |
138 float v36; // [sp+14h] [bp-34h]@17 | |
139 int v37; // [sp+18h] [bp-30h]@17 | |
140 int a5a; // [sp+28h] [bp-20h]@21 | |
141 int v39; // [sp+2Ch] [bp-1Ch]@21 | |
142 int v40; // [sp+30h] [bp-18h]@21 | |
143 int v41; // [sp+34h] [bp-14h]@22 | |
144 int v42; // [sp+38h] [bp-10h]@21 | |
145 int v43; // [sp+3Ch] [bp-Ch]@21 | |
920 | 146 //DecalBuilder *thisa; // [sp+40h] [bp-8h]@1 |
147 //RenderVertexSoft *a11; // [sp+44h] [bp-4h]@8 | |
1076 | 148 int a6a; |
149 int *a6b; | |
150 | |
0 | 151 |
920 | 152 // __debugbreak(); |
0 | 153 |
920 | 154 //auto a2 = light_level; |
155 //auto a9 = uSectorID; | |
0 | 156 |
920 | 157 //thisa = this; |
0 | 158 if ( !a5 ) |
159 return 0; | |
160 | |
161 static RenderVertexSoft static_AE4F90[64]; | |
162 static bool __init_flag1 = false; | |
163 if (!__init_flag1) | |
164 { | |
165 __init_flag1 = true; | |
166 | |
167 for (uint i = 0; i < 64; ++i) | |
168 static_AE4F90[i].flt_2C = 0.0f; | |
169 } | |
170 | |
171 static stru314 static_AE4F60; // idb | |
172 /*static bool __init_flag2 = false; | |
173 if (!__init_flag2) | |
174 { | |
175 __init_flag2 = true; | |
176 | |
177 stru314::stru314(&static_AE4F60); | |
178 }*/ | |
179 | |
920 | 180 //a11 = a6; |
0 | 181 if ( a7 ) |
182 { | |
1076 | 183 for(int i=0; i < a5;i++) |
0 | 184 { |
1076 | 185 memcpy(&static_AE4F90[i], a6, 0x30u); |
186 ++a6; | |
0 | 187 } |
188 v16 = a4; | |
189 if ( pGame->pIndoorCameraD3D->_437376(a4, static_AE4F90, (unsigned int *)&a5) == 1 ) | |
190 { | |
191 if ( !a5 ) | |
192 return 0; | |
920 | 193 a6 = static_AE4F90; |
0 | 194 } |
195 } | |
196 else | |
197 { | |
198 v16 = a4; | |
199 } | |
200 v18 = v16->face_plane.vNormal.z; | |
201 v19 = v16->face_plane.vNormal.y; | |
202 v20 = v16->face_plane.vNormal.x; | |
203 v37 = (int)&static_AE4F60.field_1C; | |
204 static_AE4F60.field_4.y = v19; | |
205 static_AE4F60.field_4.x = v20; | |
206 LODWORD(v36) = (DWORD)&static_AE4F60.field_10; | |
207 static_AE4F60.field_4.z = v18; | |
208 static_AE4F60.dist = v16->face_plane.dist; | |
920 | 209 if ( !pGame->pIndoorCameraD3D->GetFacetOrientation(v16->polygonType, &static_AE4F60.field_4, &static_AE4F60.field_10, &static_AE4F60.field_1C) ) |
0 | 210 { |
211 MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:101", 0); | |
212 } | |
213 int _a7 = 0; | |
920 | 214 if ( this->uNumDecals > 0 ) |
0 | 215 { |
1076 | 216 a6b = this->std__vector_30B00C; |
0 | 217 do |
218 { | |
1076 | 219 v21 = &pBloodsplatContainer->std__vector_pBloodsplats[*a6b]; |
220 v22 = _43F5C8_get_point_light_level_with_respect_to_lights(light_level, uSectorID, v21->x, v21->y, v21->z); | |
0 | 221 v23 = v21->b; |
222 v24 = v21->x; | |
223 v42 = v22; | |
224 BYTE3(v22) = 0; | |
225 *(short *)((char *)&v22 + 1) = v21->r; | |
226 LOBYTE(v22) = v21->g; | |
227 v43 = v23 | (v22 << 8); | |
228 v25 = (signed __int64)v24; | |
229 v26 = v21->z; | |
230 v27 = (signed __int64)v21->y; | |
231 v37 = a8; | |
232 v40 = (signed __int64)v26; | |
233 v28 = v21->dot_dist; | |
1076 | 234 //LODWORD(v36) = (uint32)a6; |
0 | 235 a5a = v25; |
236 v39 = v27; | |
237 LODWORD(v35) = a5; | |
238 v34 = &static_AE4F60; | |
1077 | 239 v33 = v28; |
0 | 240 v32 = v23 | (v22 << 8); |
1077 | 241 v29 = v21->radius; |
242 //v30 = (int)v21; | |
920 | 243 //v31 = thisa; |
1077 | 244 if ( !this->_49B790_build_decal_geometry(v42, a3, (DecalBuilder_stru0 *)v21, (int)&a5a, SLODWORD(v29), v43, v33, &static_AE4F60, a5, a6, a8) ) |
0 | 245 { |
246 MessageBoxW(nullptr, L"Error: Failed to build decal geometry", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:114", 0); | |
247 } | |
248 ++_a7; | |
1076 | 249 ++a6b; |
0 | 250 } |
920 | 251 while ( _a7 < this->uNumDecals ); |
0 | 252 } |
253 return 1; | |
254 } | |
255 | |
256 //----- (0049B790) -------------------------------------------------------- | |
1077 | 257 char DecalBuilder::_49B790_build_decal_geometry(int a2, char a3, DecalBuilder_stru0 *a4, int a5, float a6, unsigned int uColorMultiplier, float a8, stru314 *a9, signed int a10, RenderVertexSoft *a11, char uClipFlags) |
0 | 258 { |
259 DecalBuilder *v12; // esi@1 | |
260 Decal *v13; // edi@2 | |
1077 | 261 int *v14; // eax@2 |
0 | 262 double v15; // st7@4 |
263 double v16; // st7@4 | |
264 int v17; // eax@4 | |
265 stru314 *v18; // ebx@4 | |
266 double v19; // st7@4 | |
267 double v20; // st7@4 | |
268 double v21; // st7@4 | |
269 double v22; // st6@4 | |
270 double v23; // st6@4 | |
271 double v24; // st5@4 | |
272 char *v25; // eax@4 | |
273 signed int v26; // ecx@4 | |
274 double v27; // st5@4 | |
275 double v28; // st7@5 | |
276 double v29; // st7@6 | |
277 char result; // al@6 | |
278 unsigned int *v31; // edi@7 | |
279 RenderVertexSoft *v32; // ebx@8 | |
280 std::string *v33; // ecx@15 | |
281 int v34; // eax@19 | |
282 const char *v35; // [sp-Ch] [bp-2Ch]@15 | |
283 int v36; // [sp-8h] [bp-28h]@15 | |
284 std::string v37; // [sp-4h] [bp-24h]@15 | |
285 float v38; // [sp+8h] [bp-18h]@6 | |
286 RenderVertexSoft *v39; // [sp+Ch] [bp-14h]@6 | |
1077 | 287 unsigned int v40; // [sp+10h] [bp-10h]@6 |
288 | |
289 int a6a; | |
290 RenderVertexSoft *a8a; | |
291 unsigned int a8b = 0; | |
0 | 292 |
293 v12 = this; | |
1077 | 294 if ( a6 == 0.0 ) |
295 return 1; | |
0 | 296 v13 = &this->std__vector_pDecals[this->field_308008]; |
1077 | 297 v14 = &this->std__vector_pDecals[this->field_308008].field_C1C; |
298 this->std__vector_pDecals[this->field_308008].field_C18 = a4; | |
299 *v14 = 0; | |
0 | 300 if ( a3 & 2 ) |
1077 | 301 *v14 = 1; |
302 v15 = a6 - a8; | |
303 this->field_30C028 = v15; | |
304 v16 = sqrt((a6 + a6 - v15) * v15); | |
305 v12->field_30C02C = v16; | |
0 | 306 v17 = a5; |
307 v18 = a9; | |
1077 | 308 v12->flt_30C030 = 1.0 - (a6 - v16) / a6; |
309 v13->field_C08 = (signed __int64)((double)*(signed int *)v17 - a8 * v18->field_4.x); | |
310 v13->field_C0A = (signed __int64)((double)*(signed int *)(a5 + 4) - a8 * v18->field_4.y); | |
311 v19 = a6; | |
312 v13->field_C0C = (signed __int64)((double)*(signed int *)(a5 + 8) - a8 * v18->field_4.z); | |
0 | 313 v20 = v19 * v12->flt_30C030; |
1077 | 314 a8a = v13->pVertices; |
0 | 315 v12->field_30C034 = v20; |
316 v12->field_30C010 = v20 * v18->field_10.x; | |
317 v12->field_30C014 = v20 * v18->field_10.y; | |
318 v12->field_30C018 = v20 * v18->field_10.z; | |
319 v12->field_30C01C = v20 * v18->field_1C.x; | |
320 v12->field_30C020 = v20 * v18->field_1C.y; | |
321 v12->field_30C024 = v20 * v18->field_1C.z; | |
1077 | 322 a6a = v13->field_C08; |
323 v21 = (double)a6a; | |
0 | 324 v22 = v21 - v12->field_30C01C; |
1077 | 325 a6a = v13->field_C0A; |
0 | 326 v13->pVertices[0].vWorldPosition.x = v22 + v12->field_30C010; |
1077 | 327 v23 = (double)a6a; |
0 | 328 v24 = v23 - v12->field_30C020 + v12->field_30C014; |
329 v25 = (char *)&v13->pVertices[0].vWorldPosition.y; | |
330 a6 = v13->field_C0C; | |
331 v26 = 4; | |
332 v13->pVertices[0].vWorldPosition.y = v24; | |
1077 | 333 v27 = (double)a6a; |
334 a6 = v27; | |
0 | 335 v13->pVertices[0].vWorldPosition.z = v27 - v12->field_30C024 + v12->field_30C018; |
336 v13->pVertices[0].u = 0.0; | |
337 v13->pVertices[0].v = 0.0; | |
338 v13->pVertices[1].vWorldPosition.x = v21 - v12->field_30C01C - v12->field_30C010; | |
339 v13->pVertices[1].vWorldPosition.y = v23 - v12->field_30C020 - v12->field_30C014; | |
340 v13->pVertices[1].vWorldPosition.z = v27 - v12->field_30C024 - v12->field_30C018; | |
341 v13->pVertices[1].u = 0.0; | |
342 v13->pVertices[1].v = 1.0; | |
343 v13->pVertices[2].vWorldPosition.x = v21 + v12->field_30C01C - v12->field_30C010; | |
344 v13->pVertices[2].vWorldPosition.y = v23 + v12->field_30C020 - v12->field_30C014; | |
345 v13->pVertices[2].vWorldPosition.z = v27 + v12->field_30C024 - v12->field_30C018; | |
346 v13->pVertices[2].u = 1.0; | |
347 v13->pVertices[2].v = 1.0; | |
348 v13->pVertices[3].vWorldPosition.x = v21 + v12->field_30C01C + v12->field_30C010; | |
349 v13->pVertices[3].vWorldPosition.y = v23 + v12->field_30C020 + v12->field_30C014; | |
1077 | 350 v13->pVertices[3].vWorldPosition.z = a6 + v12->field_30C024 + v12->field_30C018; |
0 | 351 v13->pVertices[3].u = 1.0; |
352 v13->pVertices[3].v = 0.0; | |
353 do | |
354 { | |
355 v28 = v18->field_4.y * *(float *)v25 | |
356 + *((float *)v25 - 1) * v18->field_4.x | |
357 + *((float *)v25 + 1) * v18->field_4.z | |
358 + v18->dist; | |
359 *((float *)v25 - 1) = *((float *)v25 - 1) - v28 * v18->field_4.x; | |
360 *(float *)v25 = *(float *)v25 - v28 * v18->field_4.y; | |
361 v25 += 48; | |
362 --v26; | |
363 *((float *)v25 - 11) = *((float *)v25 - 11) - v28 * v18->field_4.z; | |
364 } | |
365 while ( v26 ); | |
366 v13->uColorMultiplier = uColorMultiplier; | |
1077 | 367 //v40 = (unsigned int *)&v13->uNumVertices; |
0 | 368 v39 = v13->pVertices; |
369 v13->uNumVertices = 4; | |
370 v13->field_C14 = a2; | |
371 v29 = v18->field_4.z; | |
1077 | 372 //a6a = (unsigned int *)&v13->uNumVertices; |
0 | 373 v38 = v29; |
1077 | 374 result = pGame->pStru9Instance->_4980B9(a11, a10, v18->field_4.x, v18->field_4.y, v38, v39, (unsigned int*)&v13->uNumVertices); |
0 | 375 if ( result ) |
376 { | |
1077 | 377 //v31 = a6a; |
378 if ( !v13->uNumVertices ) | |
379 return 1; | |
380 v32 = a8a; | |
381 //v40 = *a6a; | |
382 v39 = a8a; | |
383 pGame->pIndoorCameraD3D->ViewTransform(a8a, (unsigned int)v13->uNumVertices); | |
0 | 384 v40 = 0; |
1086 | 385 pGame->pIndoorCameraD3D->Project(v32, v13->uNumVertices, 0); |
0 | 386 if ( !(uClipFlags & 1) ) |
387 { | |
388 ++v12->field_308008; | |
389 v34 = 1024; | |
390 if ( v12->field_308008 == 1024 ) | |
391 v12->field_308008 = 0; | |
392 if ( (signed int)(v12->std__vector_pDecals_size + 1) <= 1024 ) | |
393 v34 = v12->std__vector_pDecals_size + 1; | |
394 v12->std__vector_pDecals_size = v34; | |
1077 | 395 return 1; |
0 | 396 } |
397 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor ) | |
398 { | |
399 if ( uClipFlags & 2 ) | |
400 { | |
1077 | 401 v40 = (int)&a8; |
0 | 402 v39 = v12->pVertices; |
1077 | 403 pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(v32, *v31, v12->pVertices, &a8b); |
404 v40 = (int)v31; | |
0 | 405 v39 = v12->pVertices; |
1077 | 406 pGame->pIndoorCameraD3D->_437143(a8b, v32, v12->pVertices, v31); |
0 | 407 } |
1077 | 408 else if ( uClipFlags & 4 ) |
0 | 409 { |
1077 | 410 v40 = (int)&a8; |
411 v39 = v12->pVertices; | |
412 pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(v32, *v31, v12->pVertices, &a8b); | |
413 v40 = (int)v31; | |
0 | 414 v39 = v12->pVertices; |
1077 | 415 pGame->pIndoorCameraD3D->_437143(a8b, v32, v12->pVertices, v31); |
0 | 416 } |
1077 | 417 else |
418 { | |
419 v39 = (RenderVertexSoft *)"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:258"; | |
420 v35 = "Undefined clip flag specified"; | |
421 MessageBoxA(nullptr, v35, (const char *)v39, 0); | |
422 } | |
0 | 423 } |
424 else | |
425 { | |
426 v39 = (RenderVertexSoft *)"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:263"; | |
427 v35 = "Lightpoly builder native indoor clipping not implemented"; | |
1077 | 428 MessageBoxA(nullptr, v35, (const char *)v39, 0); |
0 | 429 } |
1077 | 430 if ( a8b != 0 ) |
431 { | |
432 ++v12->field_308008; | |
433 v34 = 1024; | |
434 if ( v12->field_308008 == 1024 ) | |
435 v12->field_308008 = 0; | |
436 if ( (signed int)(v12->std__vector_pDecals_size + 1) <= 1024 ) | |
437 v34 = v12->std__vector_pDecals_size + 1; | |
438 v12->std__vector_pDecals_size = v34; | |
439 return 1; | |
440 } | |
0 | 441 result = 1; |
442 } | |
443 return result; | |
444 } | |
445 | |
446 //----- (0049BBBD) -------------------------------------------------------- | |
447 bool DecalBuilder::ApplyBloodsplatDecals_IndoorFace(unsigned int uFaceID) | |
448 { | |
449 double v7; // st7@12 | |
450 | |
1079 | 451 uNumDecals = 0; |
0 | 452 if (!pBloodsplatContainer->std__vector_pBloodsplats_size) |
453 return true; | |
454 | |
455 auto pFace = &pIndoor->pFaces[uFaceID]; | |
456 | |
457 if (pFace->uAttributes & 0x400000) | |
458 return true; | |
791 | 459 if (pFace->Fluid()) |
0 | 460 return true; |
461 for (uint i = 0; i < pBloodsplatContainer->std__vector_pBloodsplats_size; ++i) | |
462 { | |
463 auto pBloodsplat = pBloodsplatContainer->std__vector_pBloodsplats + i; | |
464 if (pFace->pBounding.x1 - pBloodsplat->radius < pBloodsplat->x && | |
465 pFace->pBounding.x2 + pBloodsplat->radius > pBloodsplat->x && | |
466 pFace->pBounding.y1 - pBloodsplat->radius < pBloodsplat->y && | |
467 pFace->pBounding.y2 + pBloodsplat->radius > pBloodsplat->y && | |
468 pFace->pBounding.z1 - pBloodsplat->radius < pBloodsplat->z && | |
469 pFace->pBounding.z2 + pBloodsplat->radius > pBloodsplat->z) | |
470 { | |
471 v7 = pFace->pFacePlane.vNormal.z * pBloodsplat->z + | |
472 pFace->pFacePlane.vNormal.y * pBloodsplat->y + | |
473 pFace->pFacePlane.vNormal.x * pBloodsplat->x + | |
474 pFace->pFacePlane.dist; | |
475 if (v7 <= pBloodsplat->radius) | |
476 { | |
477 pBloodsplat->dot_dist = v7; | |
478 std__vector_30B00C[uNumDecals++] = i; | |
479 } | |
480 } | |
481 } | |
482 | |
483 return true; | |
484 } | |
485 | |
486 //----- (0049BCEB) -------------------------------------------------------- | |
487 char DecalBuilder::ApplyDecals_OutdoorFace(ODMFace *pFace) | |
488 { | |
1119 | 489 double v8; // st7@12 |
490 unsigned int v10; // [sp+20h] [bp-1Ch]@1 | |
491 | |
492 Bloodsplat *pBloodsplat; | |
0 | 493 |
1119 | 494 this->uNumDecals = 0; |
495 v10 = pBloodsplatContainer->std__vector_pBloodsplats_size; | |
496 if ( !(pFace->uAttributes & 0x400000) && !(pFace->uAttributes & 0x10) ) | |
497 { | |
498 for(int i = 0; i < pBloodsplatContainer->std__vector_pBloodsplats_size; i++ ) | |
499 { | |
500 pBloodsplat = &pBloodsplatContainer->std__vector_pBloodsplats[i]; | |
501 if ( (double)pFace->pBoundingBox.x1 - pBloodsplat->radius < pBloodsplat->x && | |
502 (double)pFace->pBoundingBox.x2 + pBloodsplat->radius > pBloodsplat->x && | |
503 (double)pFace->pBoundingBox.y1 - pBloodsplat->radius < pBloodsplat->y && | |
504 (double)pFace->pBoundingBox.y2 + pBloodsplat->radius > pBloodsplat->y && | |
505 (double)pFace->pBoundingBox.z1 - pBloodsplat->radius < pBloodsplat->z && | |
506 (double)pFace->pBoundingBox.z2 + pBloodsplat->radius > pBloodsplat->z ) | |
507 { | |
508 v8 = (double)((pFace->pFacePlane.dist | |
509 + round(pBloodsplat->x) * pFace->pFacePlane.vNormal.x | |
510 + round(pBloodsplat->y) * pFace->pFacePlane.vNormal.y | |
511 + round(pBloodsplat->z) * pFace->pFacePlane.vNormal.z) >> 16); | |
512 if ( v8 <= pBloodsplat->radius ) | |
513 { | |
514 pBloodsplat->dot_dist = v8; | |
515 this->std__vector_30B00C[this->uNumDecals++] = i; | |
516 } | |
517 } | |
518 } | |
519 } | |
520 return 1; | |
0 | 521 } |
522 | |
523 //----- (0049BE8A) -------------------------------------------------------- | |
1075 | 524 bool DecalBuilder::_49BE8A(struct stru148 *a2, Vec3_float_ *_a3, float *a4, RenderVertexSoft *a5, unsigned int uStripType, char a7) |
0 | 525 { |
526 bool result; // eax@1 | |
527 RenderVertexSoft *v8; // edi@3 | |
1075 | 528 Vec3_float_ *v9; // ebx@3 |
529 Bloodsplat *v10; // esi@3 | |
0 | 530 float v11; // eax@5 |
531 float v12; // eax@6 | |
532 double v13; // st7@13 | |
533 double v14; // st7@19 | |
1075 | 534 short v15; // eax@20 |
0 | 535 int v16; // eax@22 |
536 int v17; // edx@24 | |
537 DecalBuilder *v18; // eax@24 | |
538 std::string v19; // [sp-18h] [bp-54h]@12 | |
539 const char *v20; // [sp-8h] [bp-44h]@12 | |
540 int v21; // [sp-4h] [bp-40h]@12 | |
541 double v22; // [sp+Ch] [bp-30h]@19 | |
542 unsigned int v23; // [sp+14h] [bp-28h]@1 | |
543 DecalBuilder *v24; // [sp+18h] [bp-24h]@1 | |
544 int v25; // [sp+1Ch] [bp-20h]@19 | |
545 float v26; // [sp+20h] [bp-1Ch]@12 | |
546 int v27; // [sp+24h] [bp-18h]@12 | |
547 float v28; // [sp+28h] [bp-14h]@13 | |
548 float v29; // [sp+2Ch] [bp-10h]@7 | |
549 float v30; // [sp+30h] [bp-Ch]@6 | |
550 float v31; // [sp+34h] [bp-8h]@6 | |
551 bool v32; // [sp+38h] [bp-4h]@2 | |
1075 | 552 float a3; |
0 | 553 |
554 this->uNumDecals = 0; | |
1113
39eaa6b00141
something to bool cast (performance warning) mostly fixed
Grumpy7
parents:
1086
diff
changeset
|
555 result = pBloodsplatContainer->std__vector_pBloodsplats_size != 0; |
0 | 556 v24 = this; |
557 v23 = pBloodsplatContainer->std__vector_pBloodsplats_size; | |
558 if ( pBloodsplatContainer->std__vector_pBloodsplats_size ) | |
559 { | |
560 v32 = 0; | |
561 if ( (signed int)pBloodsplatContainer->std__vector_pBloodsplats_size > 0 ) | |
562 { | |
563 v8 = a5; | |
1075 | 564 v9 = _a3; |
565 v10 = pBloodsplatContainer->std__vector_pBloodsplats; | |
566 while ( v32 < (signed int)v23) | |
0 | 567 { |
1075 | 568 if ( uStripType == 4 ) |
569 { | |
570 a3 = v8->vWorldPosition.x; | |
571 v11 = v8[3].vWorldPosition.x; | |
572 v31 = v11; | |
573 v30 = v8[1].vWorldPosition.y; | |
574 v12 = v8->vWorldPosition.y; | |
575 v29 = v12; | |
576 } | |
577 else if ( uStripType == 3 ) | |
0 | 578 { |
579 if ( a7 ) | |
580 { | |
581 a3 = v8->vWorldPosition.x; | |
582 v31 = v8[2].vWorldPosition.x; | |
583 v30 = v8[1].vWorldPosition.y; | |
584 v12 = v8[2].vWorldPosition.y; | |
1075 | 585 v29 = v12; |
0 | 586 } |
1075 | 587 else |
588 { | |
589 a3 = v8[1].vWorldPosition.x; | |
590 v11 = v8[2].vWorldPosition.x; | |
591 v31 = v11; | |
592 v30 = v8[1].vWorldPosition.y; | |
593 v12 = v8->vWorldPosition.y; | |
594 v29 = v12; | |
595 } | |
0 | 596 } |
1075 | 597 else |
598 MessageBoxW(nullptr, L"Uknown strip type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:434", 0); | |
0 | 599 v21 = uStripType; |
600 v13 = pGame->pIndoorCameraD3D->GetPolygonMinZ(v8, uStripType); | |
601 v21 = uStripType; | |
602 v28 = v13; | |
603 v26 = pGame->pIndoorCameraD3D->GetPolygonMaxZ(v8, uStripType); | |
1075 | 604 if ( a3 - v10->radius < v10->x && |
605 v31 + v10->radius > v10->x && | |
606 v30 - v10->radius < v10->y && | |
607 v29 + v10->radius > v10->y && | |
608 v28 - v10->radius < v10->z && | |
609 v26 + v10->radius > v10->z ) | |
0 | 610 { |
1075 | 611 Vec3_float_::NegDot(&v8->vWorldPosition, v9, a4); |
612 v26 = v9->y * v10->y | |
613 + v9->z * v10->z | |
614 + v9->x * v10->x | |
615 + *a4; | |
616 v22 = v26 + 6.7553994e15; | |
617 v25 = LODWORD(v22); | |
618 v14 = (double)SLODWORD(v22); | |
619 v28 = v14; | |
620 if ( v14 <= v10->radius ) | |
621 { | |
622 v15 = a2->flags; | |
623 if ( v15 & 2 || BYTE1(v15) & 1 ) | |
624 { | |
625 v16 = v10->field_1C; | |
626 if ( !(v16 & 1) ) | |
627 { | |
628 LOBYTE(v16) = v16 | 1; | |
629 v10->field_1C = v16; | |
630 v10->field_20 = pEventTimer->Time(); | |
631 } | |
632 } | |
633 v17 = v32; | |
634 v10->dot_dist = LODWORD(v28); | |
635 v18 = v24; | |
636 v24->std__vector_30B00C[v24->uNumDecals] = v17; | |
637 ++v18->uNumDecals; | |
638 } | |
0 | 639 } |
640 ++v32; | |
1075 | 641 ++v10; |
0 | 642 result = v32; |
643 } | |
644 } | |
645 } | |
646 LOBYTE(result) = 1; | |
647 return result; | |
648 } | |
649 | |
650 //----- (0049C095) -------------------------------------------------------- | |
651 void DecalBuilder::DrawDecal(Decal *pDecal, float z_bias) | |
652 { | |
653 signed int v21; // [sp+Ch] [bp-864h]@15 | |
654 RenderVertexD3D3 pVerticesD3D[64]; // [sp+20h] [bp-850h]@6 | |
655 | |
656 if (pDecal->uNumVertices < 3) | |
657 { | |
658 Log::Warning(L"Decal has < 3 vertices"); | |
659 return; | |
660 } | |
661 | |
662 float color_mult; | |
663 if ( pDecal->field_C1C & 1 ) | |
664 color_mult = 1.0; | |
665 else | |
666 color_mult = pDecal->field_C18->_43B570_get_color_mult_by_time(); | |
667 | |
668 for (uint i = 0; i < pDecal->uNumVertices; ++i) | |
669 { | |
670 uint uTint = pRenderer->GetActorTintColor(pDecal->pVertices[i].vWorldViewPosition.x, pDecal->field_C14, 0, 0, nullptr); | |
671 | |
672 uint uTintR = (uTint >> 16) & 0xFF, | |
673 uTintG = (uTint >> 8) & 0xFF, | |
674 uTintB = uTint & 0xFF; | |
675 | |
676 uint uDecalColorMultR = (pDecal->uColorMultiplier >> 16) & 0xFF, | |
677 uDecalColorMultG = (pDecal->uColorMultiplier >> 8) & 0xFF, | |
678 uDecalColorMultB = pDecal->uColorMultiplier & 0xFF; | |
679 | |
680 uint uFinalR = floorf(uTintR / 255.0 * color_mult * uDecalColorMultR + 0.0f), | |
681 uFinalG = floorf(uTintG / 255.0 * color_mult * uDecalColorMultG + 0.0f), | |
682 uFinalB = floorf(uTintB / 255.0 * color_mult * uDecalColorMultB + 0.0f); | |
683 | |
684 | |
685 float v15; | |
686 if (fabs(z_bias) < 1e-5) | |
687 v15 = 1.0 - 1.0 / ((1.0f / get_shading_dist_mist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0); | |
688 else | |
689 { | |
690 v15 = 1.0 - 1.0 / ((1.0f / get_shading_dist_mist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias; | |
691 if (v15 < 0.000099999997) | |
692 v15 = 0.000099999997; | |
693 } | |
694 | |
695 pVerticesD3D[i].pos.z = v15; | |
696 | |
697 pVerticesD3D[i].pos.x = pDecal->pVertices[i].vWorldViewProjX; | |
698 pVerticesD3D[i].pos.y = pDecal->pVertices[i].vWorldViewProjY; | |
699 pVerticesD3D[i].texcoord.x = pDecal->pVertices[i].u; | |
700 pVerticesD3D[i].texcoord.y = pDecal->pVertices[i].v; | |
701 pVerticesD3D[i].diffuse = (uFinalR << 16) | (uFinalG << 8) | uFinalB; | |
702 pVerticesD3D[i].specular = 0; | |
703 pVerticesD3D[i].rhw = 1.0 / pDecal->pVertices[i].vWorldViewPosition.x; | |
704 } | |
705 | |
706 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
707 v21 = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS; | |
708 else | |
709 v21 = D3DDP_DONOTLIGHT; | |
710 | |
711 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, | |
712 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, | |
713 pVerticesD3D, | |
714 pDecal->uNumVertices, | |
715 v21)); | |
716 } | |
717 | |
718 //----- (0049C2CD) -------------------------------------------------------- | |
719 void DecalBuilder::DrawDecals(float z_bias) | |
720 { | |
721 for (uint i = 0; i < std__vector_pDecals_size; ++i) | |
722 DrawDecal(std__vector_pDecals + i, z_bias); | |
723 } | |
724 | |
725 //----- (0049C304) -------------------------------------------------------- | |
726 void DecalBuilder::DrawBloodsplats() | |
727 { | |
728 if (!std__vector_pDecals_size) | |
729 return; | |
730 | |
731 if (pRenderer->bUsingSpecular) | |
186 | 732 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE)); |
733 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP)); | |
0 | 734 |
186 | 735 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); |
736 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE)); | |
737 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE)); | |
738 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); | |
739 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); | |
740 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); | |
0 | 741 |
742 auto pTex = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("hwsplat04"); | |
743 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex)); | |
744 | |
745 DrawDecals(0.00039999999); | |
186 | 746 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW)); |
747 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE)); | |
748 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); | |
749 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); | |
750 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); | |
0 | 751 |
752 if (pRenderer->bUsingSpecular) | |
186 | 753 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); |
0 | 754 } |
755 | |
756 //----- (0049C550) -------------------------------------------------------- | |
757 void DecalBuilder::DrawDecalDebugOutlines() | |
758 { | |
1075 | 759 for(int i = 0; i < std__vector_pDecals_size; i++) |
760 pGame->pIndoorCameraD3D->debug_outline_sw(std__vector_pDecals[i].pVertices, std__vector_pDecals[i].uNumVertices, 0xC86400u, 0.0); | |
0 | 761 } |
762 | |
763 //----- (0040E4C2) -------------------------------------------------------- | |
764 void Decal::Decal_base_ctor() | |
765 { | |
766 uNumVertices = -1; | |
767 for (uint i = 0; i < 64; ++i) | |
768 pVertices[i].flt_2C = 0.0f; | |
769 } |