comparison Render.cpp @ 0:9c0607679772

init
author Ritor1
date Sat, 12 Jan 2013 09:45:18 +0600
parents
children 8e33efd39355
comparison
equal deleted inserted replaced
-1:000000000000 0:9c0607679772
1 #include "Render.h"
2 #include "OutdoorCamera.h"
3 #include "IndoorCamera.h"
4 #include "Outdoor.h"
5 #include "Party.h"
6 #include "LOD.h"
7 #include "Viewport.h"
8 #include "Math.h"
9 #include "PaletteManager.h"
10 #include "Time.h"
11 #include "Game.h"
12 #include "LightmapBuilder.h"
13 #include "stru220.h"
14 #include "ObjectList.h"
15 #include "LayingItem.h"
16 #include "DecorationList.h"
17 #include "Allocator.h"
18 #include "OSInfo.h"
19 #include "Log.h"
20
21 #include "mm7_data.h"
22
23
24 #pragma comment(lib, "lib\\legacy_dx\\lib\\ddraw.lib")
25 #pragma comment(lib, "lib\\legacy_dx\\lib\\dxguid.lib")
26
27
28
29
30
31
32
33 struct IDirectDrawClipper *pDDrawClipper;
34 struct Render *pRenderer; // idb
35
36
37 int uNumDecorationsDrawnThisFrame; // weak
38 RenderBillboard pBillboardRenderList[500];
39 unsigned int uNumBillboardsToDraw;
40 int uNumSpritesDrawnThisFrame; // weak
41
42
43 RenderVertexSoft array_507D30[50];
44 RenderVertexSoft array_508690[50];
45 RenderVertexSoft array_508FF0[50];
46 RenderVertexSoft array_509950[50];
47 RenderVertexSoft array_50A2B0[50];
48 RenderVertexSoft array_50AC10[50];
49
50 RenderVertexSoft array_73D150[20];
51
52 RenderVertexD3D3 arary_77E5C8[50];
53
54 RenderVertexSoft *ptr_801A04;
55 RenderVertexSoft *ptr_801A08;
56
57 RenderVertexSoft pVerticesSR_801A10[384];
58 RenderVertexSoft pVerticesSR_806210[384];
59
60
61
62
63
64
65
66 void SetBillboardBlendOptions(RenderBillboardD3D::OpacityType a1);
67
68
69 /* 384 */
70 #pragma pack(push, 1)
71 struct PCXHeader_1
72 {
73 char manufacturer;
74 char version;
75 char encoding;
76 char bpp;
77 __int16 left;
78 __int16 up;
79 __int16 right;
80 __int16 bottom;
81 __int16 hdpi;
82 __int16 vdpi;
83 };
84 #pragma pack(pop)
85
86 /* 385 */
87 #pragma pack(push, 1)
88 struct PCXHeader_2
89 {
90 char reserved;
91 char planes;
92 __int16 pitch;
93 __int16 palette_info;
94 };
95 #pragma pack(pop)
96
97
98
99
100
101
102
103
104 HRESULT __stdcall D3DZBufferFormatEnumerator(DDPIXELFORMAT *Src, DDPIXELFORMAT *Dst);
105 HRESULT __stdcall DDrawDisplayModesEnumerator(DDSURFACEDESC2 *pSurfaceDesc, __int16 *a2);
106 HRESULT __stdcall D3DDeviceEnumerator(const GUID *lpGUID, const char *lpDeviceDesc, const char *lpDeviceName, D3DDEVICEDESC *pHWDesc, D3DDEVICEDESC *pSWDesc, struct RenderD3D_aux *a6);
107 signed int __stdcall RenderD3D__DeviceEnumerator(GUID *lpGUID, const char *lpDevDesc, const char *lpDriverName, RenderD3D__DevInfo *pOut); // idb
108
109
110
111
112
113
114
115
116
117
118
119
120 //----- (0049E79F) --------------------------------------------------------
121 bool __cdecl CheckTextureStages()
122 {
123 bool v0; // edi@1
124 IDirectDrawSurface4 *pSurface2; // [sp+Ch] [bp-14h]@1
125 IDirectDrawSurface4 *pSurface1; // [sp+10h] [bp-10h]@1
126 DWORD v4; // [sp+14h] [bp-Ch]@1
127 IDirect3DTexture2 *pTexture2; // [sp+18h] [bp-8h]@1
128 IDirect3DTexture2 *pTexture1; // [sp+1Ch] [bp-4h]@1
129
130 v0 = false;
131 pRenderer->pRenderD3D->CreateTexture(64u, 64u, &pSurface1, &pTexture1, true, false, 32u);
132 pRenderer->pRenderD3D->CreateTexture(64u, 64u, &pSurface2, &pTexture2, true, false, 32u);
133
134 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture1));
135 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
136 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 2u));
137 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
138 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2u));
139 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2u));
140 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 1u));
141
142 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture2));
143 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_ADDRESS, 3u));
144 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1u));
145 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, 7u));
146 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, 2u));
147 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, 1u));
148 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MAGFILTER, 2u));
149 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MINFILTER, 2u));
150 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MIPFILTER, 1u));
151
152 if ( !pRenderer->pRenderD3D->pDevice->ValidateDevice(&v4) && v4 == 1 )
153 v0 = true;
154 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, 1u));
155 pTexture1->Release();
156 pTexture2->Release();
157 pSurface1->Release();
158 pSurface2->Release();
159 return v0;
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173
174 //----- (00440CB8) --------------------------------------------------------
175 void Render::DrawBillboardList_BLV()
176 {
177 __int16 v2; // ax@3
178 int v5; // eax@11
179 RenderBillboardTransform_local0 soft_billboard; // [sp+4h] [bp-50h]@1
180
181 soft_billboard.uParentBillboardID = -1;
182 soft_billboard.pTarget = pBLVRenderParams->pRenderTarget;
183 soft_billboard.pTargetZ = pBLVRenderParams->pTargetZBuffer;
184 soft_billboard.uTargetPitch = pRenderer->uTargetSurfacePitch;
185 soft_billboard.uViewportX = pBLVRenderParams->uViewportX;
186 soft_billboard.uViewportY = pBLVRenderParams->uViewportY;
187 soft_billboard.uViewportZ = pBLVRenderParams->uViewportZ - 1;
188 soft_billboard.uViewportW = pBLVRenderParams->uViewportW;
189
190 pOutdoorCamera->uNumBillboards = uNumBillboardsToDraw;
191
192 for (uint i = 0; i < uNumBillboardsToDraw; ++i)
193 {
194 auto p = pBillboardRenderList + i;
195
196 soft_billboard.uScreenSpaceX = p->uScreenSpaceX;
197 soft_billboard.uParentBillboardID = i;
198 soft_billboard.uScreenSpaceY = p->uScreenSpaceY;
199 soft_billboard.field_10 = p->field_0;
200 soft_billboard.field_14 = p->field_4;
201 soft_billboard.sZValue = p->sZValue;
202 soft_billboard.uFlags = p->field_1E;
203 soft_billboard.uTintColor = p->uTintColor;
204 v2 = p->uHwSpriteID;
205 if ( v2 != -1 )
206 {
207 if ( pRenderer->pRenderD3D )
208 pRenderer->DrawBillboard_Indoor(&soft_billboard, &pSprites_LOD->pHardwareSprites[v2], p->uPaletteSubindex);
209 else
210 {
211 soft_billboard.pPalette = PaletteManager::Get_Dark_or_Red_LUT(p->uPalette, p->uPaletteSubindex, 1);
212 if (p->field_1E & 0x0100)
213 soft_billboard.pPalette = pPaletteManager->field_261600[p->uPalette];
214 if ( !(soft_billboard.uFlags & 0x40) && soft_billboard.uFlags & 0x80 )
215 soft_billboard.pPalette2 = PaletteManager::Get_Dark_or_Red_LUT(p->uPalette, 0, 1);
216 v5 = p->uHwSpriteID;
217 if ( v5 >= 0 )
218 pSprites_LOD->pSpriteHeaders[v5]._4ACC38(&soft_billboard, 1);
219 }
220 }
221 }
222 }
223
224
225
226
227
228 //----- (004A16A5) --------------------------------------------------------
229 bool __cdecl AreRenderSurfacesOk()
230 {
231 char v0; // zf@4
232 bool result; // eax@8
233
234 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
235 {
236 if ( !pRenderer->pBackBuffer4 )
237 goto LABEL_9;
238 v0 = pRenderer->pFrontBuffer4 == 0;
239 }
240 else
241 {
242 if ( !pRenderer->pBackBuffer2 )
243 goto LABEL_9;
244 v0 = pRenderer->pFrontBuffer2 == 0;
245 }
246 if ( !v0 )
247 {
248 LOBYTE(result) = 1;
249 return result;
250 }
251 LABEL_9:
252 LOBYTE(result) = 0;
253 return result;
254 }
255
256
257
258 //----- (00487389) --------------------------------------------------------
259 __int16 Render::ExecOutdoorDrawSW()
260 {
261 unsigned __int16 *v0; // ebx@1
262 unsigned int v1; // esi@1
263 stru148 *v2; // eax@1
264 Span *v3; // edi@6
265 stru148 *v4; // esi@9
266 Texture *v5; // ebp@10
267 int v6; // esi@16
268 unsigned int v7; // edx@16
269 char *v8; // ecx@17
270 unsigned int v9; // edi@22
271 int v10; // eax@26
272 int v11; // eax@27
273 unsigned int v12; // ebp@32
274 Span *v13; // esi@33
275 int v14; // ecx@37
276 int v15; // eax@40
277 Texture *v16; // ebp@51
278 unsigned int v17; // eax@51
279 int v18; // eax@54
280 char v19; // al@56
281 unsigned int v20; // eax@57
282 int v21; // ecx@57
283 unsigned int v22; // eax@57
284 stru149 *v23; // eax@65
285 int v24; // eax@67
286 ODMFace *v25; // eax@78
287 signed int v26; // edx@79
288 signed int v27; // ecx@79
289 unsigned int v28; // eax@106
290 unsigned int v29; // ebp@117
291 Span *v30; // esi@118
292 unsigned int v31; // ST04_4@124
293 int v33; // [sp+18h] [bp-44h]@80
294 signed int v34; // [sp+1Ch] [bp-40h]@3
295 signed int v35; // [sp+20h] [bp-3Ch]@79
296 Span **v36; // [sp+24h] [bp-38h]@4
297 unsigned int v37; // [sp+28h] [bp-34h]@1
298 unsigned __int16 *a1; // [sp+2Ch] [bp-30h]@1
299 int a1a; // [sp+2Ch] [bp-30h]@26
300 unsigned int a1b; // [sp+2Ch] [bp-30h]@116
301 char v41; // [sp+30h] [bp-2Ch]@57
302
303 v0 = pRenderer->pTargetSurface;
304 v1 = pOutdoorCamera->numStru148s;
305 a1 = pRenderer->pTargetSurface;
306 v2 = array_77EC08;
307 v37 = pOutdoorCamera->numStru148s;
308 if ( !(pParty->uFlags & 2) )
309 {
310 v1 = uNumElementsIn80AA28;
311 v2 = ptr_80AA28[0];
312 v37 = uNumElementsIn80AA28;
313 }
314 v34 = 0;
315 if ( (signed int)v1 > 0 )
316 {
317 v36 = &v2->prolly_head;
318 do
319 {
320 if ( pParty->uFlags & 2 )
321 v3 = *v36;
322 else
323 v3 = ptr_80AA28[v34]->prolly_head;
324 if ( v3 )
325 {
326 v4 = v3->pParent;
327 if ( v4 )
328 {
329 v5 = v4->pTexture;
330 if ( v5 )
331 {
332 if ( v3->field_8 >= (signed int)pViewport->uViewportX || v3->field_C != pViewport->uViewportX )
333 {
334 LOBYTE(v4->field_32) |= 2u;
335 v14 = *(int *)&v4->flags;
336 if ( v14 & 0x10 && v4->field_59 != 5 )
337 {
338 dword_80AA20 = (v4->field_5C - 64) << 25;
339 dword_80AA1C = dword_80AA20 + 0x1FF0000;
340 dword_80AA14 = (v4->field_5D << 25) + 0x7FFF0000;
341 dword_80AA18 = dword_80AA14 - 0x1FF0000;
342 byte_80AA10 = ((unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(
343 v4->field_5C,
344 v4->field_5D - 1) >> 9) & 1;
345 if ( *(int *)&v4->flags & 2 || (v15 = *(int *)&v4->flags, BYTE1(v15) & 1) )
346 {
347 if ( *(int *)&v4->flags & 2 )
348 {
349 while ( 1 )
350 {
351 if ( pOutdoorCamera->outdoor_no_wavy_water )
352 sr_sub_48408A_prolly_odm_water_no_waves(v3);
353 else
354 sr_sub_485407_prolly_odm_water_wavy(v3);
355 v3->field_E = LOWORD(unnamed_6BE060[1]);
356 if ( v4->prolly_tail == v3 )
357 break;
358 v3 = v3->pNext;
359 }
360 }
361 else
362 {
363 while ( 1 )
364 {
365 v16 = v4->pTexture;
366 v17 = pBitmaps_LOD->LoadTexture("wtrtyl");
367 v4->pTexture = (Texture *)(v17 != -1 ? (int)&pBitmaps_LOD->pTextures[v17] : 0);
368 if ( pOutdoorCamera->outdoor_no_wavy_water )
369 sr_sub_48408A_prolly_odm_water_no_waves(v3);
370 else
371 sr_sub_485407_prolly_odm_water_wavy(v3);
372 v18 = v4->field_5C - 64;
373 v4->pTexture = v16;
374 dword_80AA20 = v18 << 25;
375 dword_80AA1C = (v18 << 25) + 0x1FF0000;
376 dword_80AA14 = (v4->field_5D << 25) + 0x7FFF0000;
377 dword_80AA18 = dword_80AA14 - 0x1FF0000;
378 byte_80AA10 = ((unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(
379 v4->field_5C,
380 v4->field_5D - 1) >> 9) & 1;
381 sr_sub_484442(v3);
382 v3->field_E = LOWORD(unnamed_6BE060[1]);
383 if ( v4->prolly_tail == v3 )
384 break;
385 v3 = v3->pNext;
386 }
387 }
388 }
389 else
390 {
391 while ( sr_sub_48408A_prolly_odm_water_no_waves(v3) )
392 {
393 v3->field_E = LOWORD(unnamed_6BE060[1]);
394 if ( v4->prolly_tail == v3 )
395 break;
396 v3 = v3->pNext;
397 }
398 }
399 }
400 else
401 {
402 v19 = v4->field_59;
403 if ( v19 != 5 )
404 {
405 if ( v14 & 2 )
406 {
407 while ( 1 )
408 {
409 v28 = pBitmaps_LOD->LoadTexture("wtrtyla");
410 v4->pTexture = (Texture *)(v28 != -1 ? &pBitmaps_LOD->pTextures[v28] : 0);
411 if ( !sr_sub_4847EB(v3) )
412 break;
413 v4->pTexture = v5;
414 if ( !sr_sub_484442(v3) )
415 break;
416 v3->field_E = LOWORD(unnamed_6BE060[1]);
417 if ( v4->prolly_tail == v3 )
418 break;
419 v3 = v3->pNext;
420 v5 = v4->pTexture;
421 }
422 }
423 else
424 {
425 if ( v19 == 1 )
426 {
427 dword_80AA20 = (v4->field_5C - 64) << 25;
428 dword_80AA1C = dword_80AA20 + 33488896;
429 dword_80AA14 = (v4->field_5D << 25) + 0x7FFF0000;
430 dword_80AA18 = dword_80AA14 - 33488896;
431 byte_80AA10 = ((unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(
432 v4->field_5C,
433 v4->field_5D - 1) >> 9) & 1;
434 while ( 1 )
435 {
436 if ( !sr_sub_4847EB(v3) )
437 sr_sub_48585C_mb_DrawSpan(v3, &pRenderer->pTargetSurface[v3->field_8 + 640 * v3->field_A], 0);
438 v3->field_E = LOWORD(unnamed_6BE060[1]);
439 if ( v4->prolly_tail == v3 )
440 break;
441 v3 = v3->pNext;
442 }
443 }
444 }
445 goto LABEL_14;
446 }
447 v4->ptr_38 = (stru149 *)&v41;
448 v4->_479295();
449 v20 = GetTickCount();
450 v21 = *(int *)&v4->flags;
451 v22 = v20 >> 3;
452 if ( BYTE1(v21) & 4 )
453 {
454 v4->sTextureDeltaV -= v22 & v4->pTexture->uHeightMinus1;
455 }
456 else
457 {
458 if ( BYTE1(v21) & 8 )
459 v4->sTextureDeltaV += v22 & v4->pTexture->uHeightMinus1;
460 }
461 if ( BYTE1(v21) & 0x10 )
462 {
463 v4->sTextureDeltaU -= v22 & v4->pTexture->uWidthMinus1;
464 }
465 else
466 {
467 if ( BYTE1(v21) & 0x20 )
468 v4->sTextureDeltaU += v22 & v4->pTexture->uWidthMinus1;
469 }
470 v23 = v4->ptr_38;
471 v4->field_52 = 32;
472 v4->field_5A = 5;
473 if ( (double)abs(v23->field_C) > 52428.8 )
474 {
475 v4->field_52 = 8;
476 v4->field_5A = 3;
477 }
478 v24 = *(int *)&v4->flags;
479 if ( !(v24 & 0x10000) )
480 {
481 if ( !(v24 & 2) )
482 {
483 v25 = v4->pODMFace;
484 if ( v25->uPolygonType == 1 )
485 {
486 v26 = v25->pTextureUIDs[0];
487 dword_80AA1C = v26;
488 dword_80AA20 = v26;
489 v27 = v25->pTextureVIDs[0];
490 dword_80AA14 = v27;
491 dword_80AA18 = v27;
492 v35 = 1;
493 if ( v25->uNumVertices > 1u )
494 {
495 v33 = (int)&v25->pTextureVIDs[1];
496 do
497 {
498 if ( dword_80AA20 > *(short *)(v33 - 40) )
499 dword_80AA20 = *(short *)(v33 - 40);
500 if ( v26 < *(short *)(v33 - 40) )
501 {
502 v26 = *(short *)(v33 - 40);
503 dword_80AA1C = *(short *)(v33 - 40);
504 }
505 if ( dword_80AA18 > *(short *)v33 )
506 dword_80AA18 = *(short *)v33;
507 if ( v27 < *(short *)v33 )
508 {
509 v27 = *(short *)v33;
510 dword_80AA14 = *(short *)v33;
511 }
512 ++v35;
513 v33 += 2;
514 }
515 while ( v35 < v25->uNumVertices );
516 v0 = a1;
517 }
518 dword_80AA20 = (dword_80AA20 + v4->sTextureDeltaU) << 16;
519 dword_80AA1C = ((v26 + v4->sTextureDeltaU) << 16) - 65536;
520 dword_80AA18 = (dword_80AA18 + v4->sTextureDeltaV) << 16;
521 dword_80AA14 = ((v27 + v4->sTextureDeltaV) << 16) - 65536;
522 }
523 while ( 1 )
524 {
525 if ( !sr_sub_482E07(v3, v0) )
526 sr_sub_48585C_mb_DrawSpan(v3, &v0[v3->field_8 + 640 * v3->field_A], 0);
527 v3->field_E = LOWORD(unnamed_6BE060[1]);
528 if ( v4->prolly_tail == v3 )
529 break;
530 v3 = v3->pNext;
531 }
532 goto LABEL_14;
533 }
534 while ( 1 )
535 {
536 LABEL_74:
537 if ( !sr_sub_4839BD(v3, v0) )
538 sr_sub_48585C_mb_DrawSpan(v3, &v0[v3->field_8 + 640 * v3->field_A], 0);
539 v3->field_E = LOWORD(unnamed_6BE060[1]);
540 if ( v4->prolly_tail == v3 )
541 break;
542 v3 = v3->pNext;
543 }
544 goto LABEL_14;
545 }
546 if ( v24 & 2 )
547 goto LABEL_74;
548 while ( 1 )
549 {
550 if ( !sr_sub_482A94(v3) )
551 sr_sub_48585C_mb_DrawSpan(v3, &v0[v3->field_8 + 640 * v3->field_A], 0);
552 v3->field_E = LOWORD(unnamed_6BE060[1]);
553 if ( v4->prolly_tail == v3 )
554 break;
555 v3 = v3->pNext;
556 }
557 }
558 }
559 else
560 {
561 v3->field_E = LOWORD(unnamed_6BE060[1]);
562 }
563 }
564 }
565 }
566 LABEL_14:
567 ++v34;
568 LOWORD(v2) = v34;
569 v36 += 67;
570 }
571 while ( v34 < (signed int)v37 );
572 }
573 if ( pParty->uFlags & 2 )
574 {
575 v6 = pOutdoorCamera->numStru148s;
576 v7 = 0;
577 uNumElementsIn80AA28 = 0;
578 if ( pOutdoorCamera->numStru148s > 0 )
579 {
580 v8 = (char *)&array_77EC08[0].flags;
581 do
582 {
583 v2 = *(stru148 **)v8;
584 if ( (unsigned int)v2 & 0x20000 )
585 {
586 ++v7;
587 *(int *)v8 = (unsigned int)v2 & 0xFFFDFFFF;
588 LOWORD(v2) = (short)v8 - 48;
589 *(&uNumElementsIn80AA28 + v7) = (unsigned int)(v8 - 48);
590 }
591 v8 += 268;
592 --v6;
593 }
594 while ( v6 );
595 uNumElementsIn80AA28 = v7;
596 }
597 }
598 v9 = pOutdoorCamera->uNumSpans;
599 unnamed_6BE060[0] = pOutdoorCamera->uNumSpans;
600 if ( pOutdoorCamera->numStru148s >= 1999
601 || (array_77EC08[1999]._48607B(&stru_8019C8),
602 array_77EC08[1999].ptr_38->_48694B(),
603 v2 = (stru148 *)&pBitmaps_LOD->pTextures[pOutdoor->uMainTile_BitmapID],
604 (array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uMainTile_BitmapID != -1 ? (int)v2 : 0)) == 0) )
605 return (signed __int16)v2;
606 array_77EC08[1999].field_58 = 23 - (-20 * pOutdoor->vSunlight.z >> 16);
607 if ( array_77EC08[1999].field_58 > 20 )
608 array_77EC08[1999].field_58 = 20;
609 v10 = stru_5C6E00->SinCos(pIndoorCamera->sRotationX - stru_5C6E00->uIntegerHalfPi);
610 array_77EC08[1999].v_18.y = 0;
611 array_77EC08[1999].v_18.x = v10;
612 array_77EC08[1999].v_18.z = stru_5C6E00->SinCos(pIndoorCamera->sRotationX);
613 array_77EC08[1999].field_24 = 2048 - (pIndoorCamera->pos.z << 16);
614 a1a = (signed __int64)((double)(pIndoorCamera->pos.z * pOutdoorCamera->int_fov_rad)
615 / ((double)pOutdoorCamera->int_fov_rad + 8192.0)
616 + (double)pViewport->uScreenCenterY);
617 cos((double)pIndoorCamera->sRotationX * 0.0030664064);
618 sin((double)pIndoorCamera->sRotationX * 0.0030664064);
619 array_77EC08[1999]._48607B(&stru_8019C8);
620 array_77EC08[1999].ptr_38->_48694B();
621 v2 = (stru148 *)&pBitmaps_LOD->pTextures[pOutdoor->uSky_TextureID];
622 array_77EC08[1999].pTexture = (Texture *)(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0);
623 if ( !(pOutdoor->uSky_TextureID != -1 ? (int)v2 : 0) )
624 return (signed __int16)v2;
625 array_77EC08[1999].field_58 = 0;
626 v11 = stru_5C6E00->SinCos(pIndoorCamera->sRotationX + 16 - stru_5C6E00->uIntegerHalfPi);
627 array_77EC08[1999].v_18.y = 0;
628 array_77EC08[1999].v_18.x = -v11;
629 array_77EC08[1999].v_18.z = -stru_5C6E00->SinCos(pIndoorCamera->sRotationX + 16);
630 LOWORD(v2) = 224 * LOWORD(pMiscTimer->uTotalGameTimeElapsed);
631 array_77EC08[1999].field_24 = 0x2000000u;
632 array_77EC08[1999].sTextureDeltaU = 224 * pMiscTimer->uTotalGameTimeElapsed;
633 array_77EC08[1999].sTextureDeltaV = 224 * pMiscTimer->uTotalGameTimeElapsed;
634 if ( day_attrib & 1
635 && (LOWORD(v2) = LOWORD(pParty->uCurrentHour), pParty->uCurrentHour >= 5)
636 && pParty->uCurrentHour < 0x15
637 || bUnderwater )
638 {
639 v2 = (stru148 *)*(short *)PaletteManager::Get_Mist_or_Red_LUT(array_77EC08[1999].pTexture->palette_id2, 31, 1);
640 a1b = (unsigned int)v2;
641 if ( (signed int)v9 <= 0 )
642 return (signed __int16)v2;
643 v29 = v9;
644 while ( 1 )
645 {
646 v30 = &pSpans[v29 - 1];
647 v2 = (stru148 *)v30->field_E;
648 if ( v2 != (stru148 *)unnamed_6BE060[1] )
649 {
650 LOWORD(v2) = LOWORD(pViewport->uViewportX);
651 if ( v30->field_8 >= (signed int)pViewport->uViewportX )
652 goto LABEL_124;
653 if ( v30->field_C == pViewport->uViewportX )
654 {
655 v30->field_E = LOWORD(unnamed_6BE060[1]);
656 }
657 else
658 {
659 v30->field_8 = LOWORD(pViewport->uViewportX);
660 v30->field_C -= LOWORD(pViewport->uViewportX);
661 if ( v30->field_C >= 0 )
662 {
663 LABEL_124:
664 v31 = v30->field_C;
665 v30->pParent = &array_77EC08[1999];
666 fill_pixels_fast(
667 a1b,
668 &pRenderer->pTargetSurface[v30->field_8 + pRenderer->uTargetSurfacePitch * v30->field_A],
669 v31);
670 j_memset32(-65536, &pRenderer->pActiveZBuffer[v30->field_8 + 640 * v30->field_A], v30->field_C);
671 goto LABEL_125;
672 }
673 LOWORD(v2) = LOWORD(unnamed_6BE060[1]);
674 v30->field_E = LOWORD(unnamed_6BE060[1]);
675 }
676 }
677 LABEL_125:
678 --v29;
679 --v9;
680 if ( !v9 )
681 return (signed __int16)v2;
682 }
683 }
684 if ( (signed int)v9 > 0 )
685 {
686 v12 = v9;
687 do
688 {
689 v13 = &pSpans[v12 - 1];
690 v2 = (stru148 *)v13->field_E;
691 if ( v2 != (stru148 *)unnamed_6BE060[1] )
692 {
693 LOWORD(v2) = LOWORD(pViewport->uViewportX);
694 if ( v13->field_8 >= (signed int)pViewport->uViewportX )
695 goto LABEL_109;
696 if ( v13->field_C != pViewport->uViewportX )
697 {
698 v13->field_8 = LOWORD(pViewport->uViewportX);
699 v13->field_C -= LOWORD(pViewport->uViewportX);
700 if ( v13->field_C >= 0 )
701 {
702 LABEL_109:
703 if ( pOutdoorCamera->bNoSky )
704 {
705 const_1_0();
706 }
707 else
708 {
709 v13->pParent = &array_77EC08[1999];
710 if ( !Render::DrawSkySW(v13, &array_77EC08[1999], a1a) )
711 j_memset32(-65536, &pRenderer->pActiveZBuffer[v13->field_8 + 640 * v13->field_A], v13->field_C);
712 }
713 }
714 LOWORD(v2) = LOWORD(unnamed_6BE060[1]);
715 v13->field_E = LOWORD(unnamed_6BE060[1]);
716 goto LABEL_114;
717 }
718 v13->field_E = LOWORD(unnamed_6BE060[1]);
719 }
720 LABEL_114:
721 --v12;
722 --v9;
723 }
724 while ( v9 );
725 }
726 return (signed __int16)v2;
727 }
728 // 6BE030: using guessed type int day_attrib;
729 // 6BE3C4: using guessed type char bUnderwater;
730 // 80AA10: using guessed type char byte_80AA10;
731 // 80AA14: using guessed type int dword_80AA14;
732 // 80AA18: using guessed type int dword_80AA18;
733 // 80AA1C: using guessed type int dword_80AA1C;
734 // 80AA20: using guessed type int dword_80AA20;
735
736 //----- (00485044) --------------------------------------------------------
737 int Render::DrawSkySW(Span *a1, stru148 *a2, int a3)
738 {
739 stru148 *v3; // esi@1
740 Span *v4; // edi@1
741 float v5; // ST2C_4@1
742 signed int result; // eax@2
743 int v7; // ST40_4@3
744 stru149 *v8; // eax@3
745 int v9; // ebx@3
746 int v10; // ecx@3
747 int v11; // edx@3
748 int v12; // eax@3
749 int v13; // ST28_4@5
750 int v14; // eax@5
751 signed __int64 v15; // qtt@11
752 int v16; // ST28_4@11
753 int v17; // eax@11
754 signed int v18; // ecx@11
755 int v19; // ST40_4@11
756 int v20; // ST3C_4@11
757 int v21; // ST30_4@11
758 void *v22; // eax@11
759 Texture *v23; // esi@11
760 int v24; // ecx@11
761 unsigned int v25; // esi@11
762 int v26; // edi@11
763 unsigned __int16 *v27; // eax@11
764 int *v28; // ebx@12
765 int v29; // edx@13
766 unsigned __int16 v30; // cx@13
767 int v31; // edx@14
768 unsigned __int16 v32; // cx@14
769 unsigned __int8 v33; // sf@15
770 unsigned __int8 v34; // of@15
771 double v35; // [sp+14h] [bp-38h]@1
772 int v36; // [sp+18h] [bp-34h]@3
773 signed int v37; // [sp+18h] [bp-34h]@11
774 int v38; // [sp+1Ch] [bp-30h]@3
775 signed int v39; // [sp+1Ch] [bp-30h]@11
776 int v40; // [sp+20h] [bp-2Ch]@3
777 void *v41; // [sp+20h] [bp-2Ch]@11
778 int v42; // [sp+24h] [bp-28h]@3
779 unsigned __int8 *v43; // [sp+24h] [bp-28h]@11
780 int v44; // [sp+28h] [bp-24h]@11
781 int v45; // [sp+2Ch] [bp-20h]@3
782 signed int v46; // [sp+30h] [bp-1Ch]@3
783 __int16 v47; // [sp+30h] [bp-1Ch]@11
784 signed int v48; // [sp+34h] [bp-18h]@3
785 int v49; // [sp+34h] [bp-18h]@11
786 int v50; // [sp+38h] [bp-14h]@3
787 unsigned __int16 *v51; // [sp+38h] [bp-14h]@11
788 int v52; // [sp+3Ch] [bp-10h]@4
789 int a1a; // [sp+40h] [bp-Ch]@3
790 int v54; // [sp+44h] [bp-8h]@3
791 int v55; // [sp+48h] [bp-4h]@3
792 int v56; // [sp+54h] [bp+8h]@11
793 int *v57; // [sp+54h] [bp+8h]@11
794
795 v3 = a2;
796 v4 = a1;
797 v5 = (double)(pViewport->uViewportZ - pViewport->uViewportX) * 0.5 / tan(0.6457717418670654) + 0.5;
798 v35 = v5 + 6.7553994e15;
799 if ( LODWORD(v35) )
800 {
801 v55 = 65536 / SLODWORD(v35);
802 v7 = 65536 / SLODWORD(v35) * (a3 - v4->field_A);
803 v8 = v3->ptr_38;
804 v42 = ((unsigned __int64)(v3->ptr_38->field_14 * (signed __int64)v7) >> 16) + v8->field_C;
805 v40 = ((unsigned __int64)(v8->field_20 * (signed __int64)v7) >> 16) + v3->ptr_38->field_18;
806 v38 = pOutdoorCamera->camera_rotation_y_int_sine;
807 HIDWORD(v35) = pOutdoorCamera->camera_rotation_y_int_cosine;
808 v45 = v4->field_C;
809 v9 = ((unsigned __int64)(v3->v_18.z * (signed __int64)v7) >> 16) + v3->v_18.x;
810 v10 = 65536 / SLODWORD(v35) * (pViewport->uScreenCenterX - v4->field_8);
811 v48 = 0;
812 v50 = 65536 / SLODWORD(v35) * (pViewport->uScreenCenterX - v4->field_8);
813 v46 = -v3->field_24;
814 v11 = v4->field_A - 1;
815 v54 = v11;
816 v12 = 65536 / SLODWORD(v35) * (a3 - v11);
817 a1a = 65536 / SLODWORD(v35) * (a3 - v11);
818 while ( 1 )
819 {
820 v52 = v9;
821 if ( v9 )
822 {
823 v13 = abs(v46 >> 14);
824 v14 = abs(v9);
825 v11 = v54;
826 v10 = v50;
827 if ( v13 <= v14 )
828 break;
829 v12 = a1a;
830 }
831 if ( v11 <= (signed int)pViewport->uViewportY )
832 break;
833 v9 = ((unsigned __int64)(v3->v_18.z * (signed __int64)v12) >> 16) + v3->v_18.x;
834 --v54;
835 a1a += v55;
836 v12 = a1a;
837 v11 = v54;
838 v48 = 1;
839 }
840 if ( v48 )
841 v52 = ((unsigned __int64)(v3->v_18.z * (signed __int64)(v55 * (a3 + (signed int)v4->field_A - 2 * v11))) >> 16)
842 + v3->v_18.x;
843 LODWORD(v15) = v46 << 16;
844 HIDWORD(v15) = v46 >> 16;
845 v16 = v42 + ((unsigned __int64)(v3->ptr_38->field_10 * (signed __int64)v10) >> 16);
846 v17 = v40 + ((unsigned __int64)(v3->ptr_38->field_1C * (signed __int64)v10) >> 16);
847 v18 = v15 / v52;
848 v43 = v3->pTexture->pLevelOfDetail0;
849 v19 = v3->sTextureDeltaU + ((signed int)((unsigned __int64)(v16 * v15 / v52) >> 16) >> 3);
850 v56 = v15 / v52;
851 v20 = v3->sTextureDeltaV + ((signed int)((unsigned __int64)(v17 * v15 / v52) >> 16) >> 3);
852 v21 = (unsigned __int64)(v55 * (signed __int64)v56) >> 16;
853 v39 = (signed int)((unsigned __int64)(v21 * (signed __int64)v38) >> 16) >> 3;
854 v37 = (signed int)((unsigned __int64)(v21 * (signed __int64)v36) >> 16) >> 3;
855 v22 = sr_sub_47C178(v18, v3, 0, 1);
856 v23 = v3->pTexture;
857 v41 = v22;
858 v47 = 16 - v23->uWidthLn2;
859 v44 = v23->uTextureWidth - 1;
860 v49 = (v23->uTextureHeight << 16) - 65536;
861 v24 = v4->field_8;
862 v51 = &pRenderer->pTargetSurface[v24 + pRenderer->uTargetSurfacePitch * v4->field_A];
863 v57 = &pRenderer->pActiveZBuffer[v24 + 640 * v4->field_A];
864 v25 = v19;
865 v26 = v20;
866 v27 = v51;
867 if ( !(v45 & 1) )
868 goto LABEL_15;
869 --v45;
870 v27 = v51 - 1;
871 v28 = v57;
872 ++v57;
873 while ( 1 )
874 {
875 *v28 = -65536;
876 v31 = v44 & (v25 >> 16);
877 v27 += 2;
878 v25 += v39;
879 v32 = *((short *)v41 + *(&v43[v31] + ((v49 & (unsigned int)v26) >> v47)));
880 v26 += v37;
881 *(v27 - 1) = v32;
882 LABEL_15:
883 v34 = __OFSUB__(v45, 2);
884 v33 = v45 - 2 < 0;
885 v45 -= 2;
886 if ( v33 ^ v34 )
887 break;
888 v29 = v44 & (v25 >> 16);
889 v25 += v39;
890 v30 = *((short *)v41 + *(&v43[v29] + ((v49 & (unsigned int)v26) >> v47)));
891 v26 += v37;
892 v28 = v57;
893 *v27 = v30;
894 v57 += 2;
895 v28[1] = -65536;
896 }
897 result = 1;
898 }
899 else
900 {
901 result = 0;
902 }
903 return result;
904 }
905
906 //----- (0047F5C6) --------------------------------------------------------
907 float Render::DrawBezierTerrain()
908 {
909 //__debugbreak();Ritor1: it's temporarily
910 //return 0;
911
912 unsigned int v0; // ebx@1
913 unsigned int v1; // edi@1
914 unsigned int v2; // eax@1
915 int v3; // eax@3
916 int v4; // edi@3
917 int v5; // ebx@3
918 int v6; // esi@3
919 unsigned int v7; // eax@3
920 int v8; // eax@4
921 unsigned int v9; // eax@6
922 int v10; // eax@7
923 int v11; // ebx@9
924 int v12; // edi@9
925 int v13; // eax@21
926 int v14; // eax@31
927 int v15; // edi@33
928 float v16; // eax@34
929 int v17; // edx@34
930 int v18; // ebx@34
931 int v19; // eax@36
932 int v20; // eax@39
933 int v21; // ecx@43
934 char v22; // zf@44
935 int v23; // ecx@47
936 int v24; // edi@52
937 float v25; // eax@54
938 int v26; // ecx@54
939 int v27; // eax@56
940 int v28; // edx@60
941 int v29; // ecx@61
942 int v30; // ecx@64
943 int v31; // ecx@68
944 int v32; // eax@70
945 int v33; // ecx@71
946 int v34; // eax@73
947 int v35; // ecx@77
948 int v36; // ecx@81
949 int v37; // ecx@86
950 float v38; // eax@88
951 IndoorCameraD3D *v39; // ecx@88
952 int v40; // eax@90
953 int v41; // edx@94
954 int v42; // ecx@95
955 int v43; // ecx@98
956 int v44; // ecx@102
957 int v45; // eax@104
958 int v46; // eax@107
959 int v47; // ecx@111
960 int v48; // ecx@115
961 int v49; // edi@120
962 float v50; // eax@122
963 int v51; // ecx@122
964 int v52; // eax@124
965 int v53; // edx@128
966 int v54; // ecx@129
967 int v55; // ecx@132
968 int v56; // eax@139
969 int v57; // ecx@140
970 int v58; // eax@142
971 int v59; // ecx@146
972 int v60; // ecx@147
973 int v61; // ecx@150
974 int v62; // ecx@155
975 float v63; // eax@157
976 IndoorCameraD3D *v64; // ecx@157
977 int v65; // eax@159
978 int v66; // edx@163
979 int v67; // ecx@164
980 int v68; // ecx@167
981 int v69; // eax@173
982 int v70; // edi@178
983 int v71; // eax@178
984 int v72; // ecx@178
985 int v73; // ebx@180
986 int v74; // eax@182
987 int v75; // eax@184
988 IndoorCameraD3D *v76; // ecx@184
989 int v77; // ecx@184
990 int v79; // ebx@185
991 int v127; // esi@185
992 int v86; // edi@196
993 int v87; // eax@196
994 int v88; // ecx@196
995 int v89; // eax@198
996 int v90; // ecx@200
997 int v92; // ebx@203
998 int v93; // ST08_4@204
999 int v97; // ST08_4@204
1000 float result; // eax@212
1001 char v102; // [sp+Ch] [bp-68h]@191
1002 __int16 v103; // [sp+10h] [bp-64h]@190
1003 __int16 v104; // [sp+12h] [bp-62h]@190
1004 int v105; // [sp+1Ch] [bp-58h]@1
1005 int v106; // [sp+20h] [bp-54h]@3
1006 int v107; // [sp+24h] [bp-50h]@3
1007 int v108; // [sp+28h] [bp-4Ch]@9
1008 int v109; // [sp+2Ch] [bp-48h]@9
1009 int v110; // [sp+30h] [bp-44h]@9
1010 int v111; // [sp+34h] [bp-40h]@3
1011 int v112; // [sp+38h] [bp-3Ch]@6
1012 IndoorCameraD3D *a1; // [sp+3Ch] [bp-38h]@9
1013 int v114; // [sp+40h] [bp-34h]@9
1014 int v115; // [sp+44h] [bp-30h]@9
1015 int v116; // [sp+48h] [bp-2Ch]@9
1016 int v117; // [sp+4Ch] [bp-28h]@9
1017 int v118; // [sp+50h] [bp-24h]@9
1018 int v119; // [sp+54h] [bp-20h]@1
1019 int v120; // [sp+58h] [bp-1Ch]@1
1020 int i; // [sp+5Ch] [bp-18h]@1
1021 int v122; // [sp+60h] [bp-14h]@1
1022 int v123; // [sp+64h] [bp-10h]@1
1023 float v124; // [sp+68h] [bp-Ch]@1
1024 int v125; // [sp+6Ch] [bp-8h]@9
1025 float v126; // [sp+70h] [bp-4h]@9
1026
1027 memset(&v102, 0, sizeof(v102));
1028 v105 = pIndoorCamera->sRotationY / ((signed int)stru_5C6E00->uIntegerHalfPi / 2);
1029 v0 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerDoublePi - pIndoorCamera->sRotationY);
1030 v1 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + v0);
1031 LODWORD(v124) = (signed int)((pIndoorCamera->uMapGridCellX << 16)
1032 + 3
1033 * stru_5C6E00->SinCos(
1034 stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + v0))) >> 16;
1035 v123 = (signed int)((pIndoorCamera->uMapGridCellZ << 16)
1036 + 3 * stru_5C6E00->SinCos(v1 - stru_5C6E00->uIntegerHalfPi)) >> 16;
1037 v120 = pOutdoorCamera->outdoor_grid_band_3 + LODWORD(v124);
1038 v119 = pOutdoorCamera->outdoor_grid_band_3 + v123;
1039 v2 = pOutdoorCamera->uCameraFovInDegrees + 15;
1040 i = LODWORD(v124) - pOutdoorCamera->outdoor_grid_band_3;
1041 v122 = v123 - pOutdoorCamera->outdoor_grid_band_3;
1042 if ( (signed int)(pOutdoorCamera->uCameraFovInDegrees + 15) > 90 )
1043 v2 = 90;
1044 v3 = (signed int)(v2 << 11) / 720;
1045 v4 = stru_5C6E00->uDoublePiMask & (v0 - v3);
1046 v5 = stru_5C6E00->uDoublePiMask & (v3 + v0);
1047 v106 = stru_5C6E00->SinCos(v4);
1048 v107 = stru_5C6E00->SinCos(v4 - stru_5C6E00->uIntegerHalfPi);
1049 v111 = stru_5C6E00->SinCos(v5);
1050 v6 = stru_5C6E00->SinCos(v5 - stru_5C6E00->uIntegerHalfPi);
1051 v7 = v4 & stru_5C6E00->uPiMask;
1052 if ( (signed int)(v4 & stru_5C6E00->uPiMask) >= (signed int)stru_5C6E00->uIntegerHalfPi )
1053 v8 = -stru_5C6E00->pTanTable[stru_5C6E00->uIntegerPi - v7];
1054 else
1055 v8 = stru_5C6E00->pTanTable[v7];
1056 v112 = abs(v8);
1057 v9 = v5 & stru_5C6E00->uPiMask;
1058 if ( (signed int)(v5 & stru_5C6E00->uPiMask) >= (signed int)stru_5C6E00->uIntegerHalfPi )
1059 v10 = -stru_5C6E00->pTanTable[stru_5C6E00->uIntegerPi - v9];
1060 else
1061 v10 = stru_5C6E00->pTanTable[v9];
1062 v108 = abs(v10);
1063 v11 = LODWORD(v124);
1064 v12 = v123;
1065 v114 = 0;
1066 v115 = 0;
1067 a1 = 0;
1068 v125 = 0;
1069 v110 = 2 * (v106 >= 0) - 1;
1070 v126 = v124;
1071 v118 = v123;
1072 v109 = 2 * (v107 >= 0) - 1;
1073 v107 = 2 * (v111 >= 0) - 1;
1074 terrain_76E1C8[0] = 65535;
1075 v116 = 1;
1076 v106 = 2 * (v6 >= 0) - 1;
1077 v117 = 1;
1078 terrain_76E3C8[0] = 65535;
1079 terrain_76DDC8[0] = 65535;
1080 terrain_76DFC8[0] = 65535;
1081 while ( 1 )
1082 {
1083 if ( v112 >= 65536 )
1084 {
1085 v111 = 4294967296i64 / v112;
1086 v114 += v111;
1087 if ( v114 >= 65536 )
1088 {
1089 v11 += v110;
1090 v114 = (unsigned __int16)v114;
1091 }
1092 v12 += v109;
1093 }
1094 else
1095 {
1096 v11 += v110;
1097 v115 += v112;
1098 if ( v115 >= 65536 )
1099 {
1100 v12 += v109;
1101 v115 = (unsigned __int16)v115;
1102 }
1103 }
1104 if ( v116 > 128 || v11 < i || v11 > v120 || v12 < v122 || v12 > v119 )
1105 break;
1106 v13 = v116++;
1107 terrain_76E3C8[v13] = v11;
1108 terrain_76E1C8[v13] = v12;
1109 }
1110 while ( 1 )
1111 {
1112 if ( v108 >= 65536 )
1113 {
1114 v111 = 4294967296i64 / v108;
1115 a1 = (IndoorCameraD3D *)((char *)a1 + v111);
1116 if ( (signed int)a1 >= 65536 )
1117 {
1118 LODWORD(v126) += v107;
1119 a1 = (IndoorCameraD3D *)(unsigned __int16)a1;
1120 }
1121 v118 += v106;
1122 }
1123 else
1124 {
1125 v125 += v108;
1126 LODWORD(v126) += v107;
1127 if ( v125 >= 65536 )
1128 {
1129 v118 += v106;
1130 v125 = (unsigned __int16)v125;
1131 }
1132 }
1133 if ( v117 >= 128 )
1134 break;
1135 if ( SLODWORD(v126) < i )
1136 break;
1137 if ( SLODWORD(v126) > v120 )
1138 break;
1139 v14 = v118;
1140 if ( v118 < v122 )
1141 break;
1142 if ( v118 > v119 )
1143 break;
1144 v15 = v117++;
1145 terrain_76DFC8[v15] = LODWORD(v126);
1146 terrain_76DDC8[v15] = v14;
1147 }
1148 LODWORD(v16) = 0;
1149 LODWORD(v126) = 0;
1150 v17 = v117 - 1;
1151 v18 = v116 - 1;
1152 switch ( v105 )
1153 {
1154 case 0:
1155 case 7:
1156 v116 = terrain_76DFC8[v17];
1157 if ( v120 > v116 )
1158 {
1159 v125 = v120;
1160 memset32(terrain_76D9C8, v119 + 1, v120 - v116 + 1);
1161 v19 = v120;
1162 do
1163 terrain_76DBC8[LODWORD(v126)++] = v19--;
1164 while ( v19 >= v116 );
1165 if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
1166 {
1167 do
1168 v20 = terrain_76DDC8[v17-- + 127];
1169 while ( v20 == terrain_76DDC8[v17 + 127] );
1170 }
1171 v16 = v126;
1172 --v17;
1173 }
1174 if ( v17 < 0 )
1175 v17 = 0;
1176 v21 = terrain_76DFC8[v17];
1177 while ( 1 )
1178 {
1179 v125 = v21;
1180 if ( v21 < SLODWORD(v124) )
1181 break;
1182 terrain_76DBC8[LODWORD(v16)] = v21;
1183 v22 = terrain_76DDC8[v17] == 65535;
1184 terrain_76D9C8[LODWORD(v16)] = terrain_76DDC8[v17] + 1;
1185 if ( v22 )
1186 {
1187 terrain_76D9C8[LODWORD(v16)] = v123 + 1;
1188 break;
1189 }
1190 if ( !v17 )
1191 break;
1192 if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
1193 {
1194 do
1195 v23 = terrain_76DDC8[v17-- + 127];
1196 while ( v23 == terrain_76DDC8[v17 + 127] );
1197 }
1198 --v17;
1199 v21 = v125 - 1;
1200 ++LODWORD(v16);
1201 }
1202 LODWORD(v16) = 0;
1203 v24 = terrain_76E3C8[v18];
1204 LODWORD(v126) = 0;
1205 if ( v120 > v24 )
1206 {
1207 v125 = v120;
1208 memset32(terrain_76D5C8, v122, v120 - v24 + 1);
1209 do
1210 {
1211 v25 = v126;
1212 v26 = v125--;
1213 ++LODWORD(v126);
1214 terrain_76D7C8[LODWORD(v25)] = v26;
1215 }
1216 while ( v125 >= terrain_76E3C8[v18] );
1217 if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
1218 {
1219 do
1220 v27 = terrain_76E1C8[v18-- + 127];
1221 while ( v27 == terrain_76E1C8[v18 + 127] );
1222 }
1223 v16 = v126;
1224 --v18;
1225 }
1226 if ( v18 < 0 )
1227 v18 = 0;
1228 v28 = terrain_76E3C8[v18];
1229 while ( v28 >= SLODWORD(v124) )
1230 {
1231 v29 = terrain_76E1C8[v18];
1232 terrain_76D7C8[LODWORD(v16)] = v28;
1233 terrain_76D5C8[LODWORD(v16)] = v29;
1234 if ( v29 == 65535 )
1235 {
1236 v31 = v123;
1237 goto LABEL_172;
1238 }
1239 if ( !v18 )
1240 break;
1241 if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
1242 {
1243 do
1244 v30 = terrain_76E1C8[v18-- + 127];
1245 while ( v30 == terrain_76E1C8[v18 + 127] );
1246 }
1247 --v18;
1248 --v28;
1249 ++LODWORD(v16);
1250 }
1251 break;
1252 case 1:
1253 case 2:
1254 v116 = terrain_76DDC8[v17];
1255 if ( v122 < v116 )
1256 {
1257 v106 = v122;
1258 memset32(terrain_76DBC8, v120 + 1, v116 - v122 + 1);
1259 v32 = v122;
1260 do
1261 {
1262 v33 = LODWORD(v126)++;
1263 terrain_76D9C8[v33] = v32++;
1264 }
1265 while ( v32 <= v116 );
1266 if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
1267 {
1268 do
1269 v34 = terrain_76DBC8[v17-- + 127];
1270 while ( v34 == terrain_76DBC8[v17 + 127] );
1271 }
1272 v16 = v126;
1273 --v17;
1274 }
1275 if ( v17 < 0 )
1276 v17 = 0;
1277 v35 = terrain_76DDC8[v17];
1278 v125 = terrain_76DDC8[v17];
1279 while ( v35 <= v123 )
1280 {
1281 v22 = terrain_76DFC8[v17] == 65535;
1282 terrain_76DBC8[LODWORD(v16)] = terrain_76DFC8[v17] + 1;
1283 terrain_76D9C8[LODWORD(v16)] = v125;
1284 if ( v22 )
1285 {
1286 terrain_76DBC8[LODWORD(v16)] = LODWORD(v124) + 1;
1287 break;
1288 }
1289 if ( !v17 )
1290 break;
1291 if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
1292 {
1293 do
1294 v36 = terrain_76DBC8[v17-- + 127];
1295 while ( v36 == terrain_76DBC8[v17 + 127] );
1296 }
1297 --v17;
1298 ++v125;
1299 v35 = v125;
1300 ++LODWORD(v16);
1301 }
1302 LODWORD(v16) = 0;
1303 LODWORD(v126) = 0;
1304 v37 = terrain_76E1C8[v18];
1305 if ( v122 < v37 )
1306 {
1307 a1 = (IndoorCameraD3D *)v122;
1308 memset32(terrain_76D7C8, i, v37 - v122 + 1);
1309 do
1310 {
1311 v38 = v126;
1312 v39 = a1;
1313 ++LODWORD(v126);
1314 a1 = (IndoorCameraD3D *)((char *)a1 + 1);
1315 terrain_76D5C8[LODWORD(v38)] = (int)v39;
1316 }
1317 while ( (signed int)a1 <= terrain_76E1C8[v18] );
1318 if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
1319 {
1320 do
1321 v40 = terrain_76DFC8[v18-- + 127];
1322 while ( v40 == terrain_76DFC8[v18 + 127] );
1323 }
1324 v16 = v126;
1325 --v18;
1326 }
1327 if ( v18 < 0 )
1328 v18 = 0;
1329 v41 = terrain_76E1C8[v18];
1330 while ( v41 <= v123 )
1331 {
1332 v42 = terrain_76E3C8[v18];
1333 terrain_76D5C8[LODWORD(v16)] = v41;
1334 terrain_76D7C8[LODWORD(v16)] = v42;
1335 if ( v42 == 65535 )
1336 {
1337 v44 = LODWORD(v124);
1338 goto LABEL_137;
1339 }
1340 if ( !v18 )
1341 break;
1342 if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
1343 {
1344 do
1345 v43 = terrain_76DFC8[v18-- + 127];
1346 while ( v43 == terrain_76DFC8[v18 + 127] );
1347 }
1348 --v18;
1349 ++v41;
1350 ++LODWORD(v16);
1351 }
1352 break;
1353 case 5:
1354 case 6:
1355 v116 = terrain_76DDC8[v17];
1356 if ( v119 > v116 )
1357 {
1358 v106 = v119;
1359 memset32(terrain_76DBC8, i, v119 - v116 + 1);
1360 v45 = v119;
1361 do
1362 terrain_76D9C8[LODWORD(v126)++] = v45--;
1363 while ( v45 >= v116 );
1364 if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
1365 {
1366 do
1367 v46 = terrain_76DBC8[v17-- + 127];
1368 while ( v46 == terrain_76DBC8[v17 + 127] );
1369 }
1370 v16 = v126;
1371 --v17;
1372 }
1373 if ( v17 < 0 )
1374 v17 = 0;
1375 v47 = terrain_76DDC8[v17];
1376 v125 = terrain_76DDC8[v17];
1377 while ( v47 >= v123 )
1378 {
1379 v22 = terrain_76DFC8[v17] == 65535;
1380 terrain_76DBC8[LODWORD(v16)] = terrain_76DFC8[v17];
1381 terrain_76D9C8[LODWORD(v16)] = v125;
1382 if ( v22 )
1383 {
1384 terrain_76DBC8[LODWORD(v16)] = LODWORD(v124);
1385 break;
1386 }
1387 if ( !v17 )
1388 break;
1389 if ( terrain_76DDC8[v17] == terrain_76DBC8[v17 + 127] )
1390 {
1391 do
1392 v48 = terrain_76DBC8[v17-- + 127];
1393 while ( v48 == terrain_76DBC8[v17 + 127] );
1394 }
1395 --v17;
1396 --v125;
1397 v47 = v125;
1398 ++LODWORD(v16);
1399 }
1400 LODWORD(v16) = 0;
1401 v49 = terrain_76E1C8[v18];
1402 LODWORD(v126) = 0;
1403 if ( v119 > v49 )
1404 {
1405 v125 = v119;
1406 memset32(terrain_76D7C8, v120 + 1, v119 - v49 + 1);
1407 do
1408 {
1409 v50 = v126;
1410 v51 = v125--;
1411 ++LODWORD(v126);
1412 terrain_76D5C8[LODWORD(v50)] = v51;
1413 }
1414 while ( v125 >= terrain_76E1C8[v18] );
1415 if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
1416 {
1417 do
1418 v52 = terrain_76DFC8[v18-- + 127];
1419 while ( v52 == terrain_76DFC8[v18 + 127] );
1420 }
1421 v16 = v126;
1422 --v18;
1423 }
1424 if ( v18 < 0 )
1425 v18 = 0;
1426 v53 = terrain_76E1C8[v18];
1427 while ( v53 >= v123 )
1428 {
1429 v54 = terrain_76E3C8[v18];
1430 terrain_76D5C8[LODWORD(v16)] = v53;
1431 terrain_76D7C8[LODWORD(v16)] = v54 + 1;
1432 if ( v54 == 65535 )
1433 {
1434 v44 = LODWORD(v124) + 1;
1435 LABEL_137:
1436 terrain_76D7C8[LODWORD(v16)] = v44;
1437 goto LABEL_173;
1438 }
1439 if ( !v18 )
1440 goto LABEL_173;
1441 if ( terrain_76E1C8[v18] == terrain_76DFC8[v18 + 127] )
1442 {
1443 do
1444 v55 = terrain_76DFC8[v18-- + 127];
1445 while ( v55 == terrain_76DFC8[v18 + 127] );
1446 }
1447 --v18;
1448 --v53;
1449 ++LODWORD(v16);
1450 }
1451 break;
1452 case 3:
1453 case 4:
1454 v116 = terrain_76DFC8[v17];
1455 if ( i < v116 )
1456 {
1457 v106 = i;
1458 memset32(terrain_76D9C8, v122, v116 - i + 1);
1459 v56 = i;
1460 do
1461 {
1462 v57 = LODWORD(v126)++;
1463 terrain_76DBC8[v57] = v56++;
1464 }
1465 while ( v56 <= v116 );
1466 if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
1467 {
1468 do
1469 v58 = terrain_76DDC8[v17-- + 127];
1470 while ( v58 == terrain_76DDC8[v17 + 127] );
1471 }
1472 v16 = v126;
1473 --v17;
1474 }
1475 if ( v17 < 0 )
1476 v17 = 0;
1477 v59 = terrain_76DFC8[v17];
1478 while ( 1 )
1479 {
1480 v125 = v59;
1481 if ( v59 > SLODWORD(v124) )
1482 break;
1483 terrain_76DBC8[LODWORD(v16)] = v59;
1484 v60 = terrain_76DDC8[v17];
1485 terrain_76D9C8[LODWORD(v16)] = v60;
1486 if ( v60 == 65535 )
1487 {
1488 terrain_76D9C8[LODWORD(v16)] = v123;
1489 break;
1490 }
1491 if ( !v17 )
1492 break;
1493 if ( terrain_76DFC8[v17] == terrain_76DDC8[v17 + 127] )
1494 {
1495 do
1496 v61 = terrain_76DDC8[v17-- + 127];
1497 while ( v61 == terrain_76DDC8[v17 + 127] );
1498 }
1499 --v17;
1500 v59 = v125 + 1;
1501 ++LODWORD(v16);
1502 }
1503 LODWORD(v16) = 0;
1504 LODWORD(v126) = 0;
1505 v62 = terrain_76E3C8[v18];
1506 if ( i < v62 )
1507 {
1508 a1 = (IndoorCameraD3D *)i;
1509 memset32(terrain_76D5C8, v119 + 1, v62 - i + 1);
1510 do
1511 {
1512 v63 = v126;
1513 v64 = a1;
1514 ++LODWORD(v126);
1515 a1 = (IndoorCameraD3D *)((char *)a1 + 1);
1516 terrain_76D7C8[LODWORD(v63)] = (int)v64;
1517 }
1518 while ( (signed int)a1 <= terrain_76E3C8[v18] );
1519 if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
1520 {
1521 do
1522 v65 = terrain_76E1C8[v18-- + 127];
1523 while ( v65 == terrain_76E1C8[v18 + 127] );
1524 }
1525 v16 = v126;
1526 --v18;
1527 }
1528 if ( v18 < 0 )
1529 v18 = 0;
1530 v66 = terrain_76E3C8[v18];
1531 while ( v66 <= SLODWORD(v124) )
1532 {
1533 v67 = terrain_76E1C8[v18];
1534 terrain_76D7C8[LODWORD(v16)] = v66;
1535 terrain_76D5C8[LODWORD(v16)] = v67 + 1;
1536 if ( v67 == 65535 )
1537 {
1538 v31 = v123 + 1;
1539 LABEL_172:
1540 terrain_76D5C8[LODWORD(v16)] = v31;
1541 goto LABEL_173;
1542 }
1543 if ( !v18 )
1544 goto LABEL_173;
1545 if ( terrain_76E3C8[v18] == terrain_76E1C8[v18 + 127] )
1546 {
1547 do
1548 v68 = terrain_76E1C8[v18-- + 127];
1549 while ( v68 == terrain_76E1C8[v18 + 127] );
1550 }
1551 --v18;
1552 ++v66;
1553 ++LODWORD(v16);
1554 }
1555 break;
1556 default:
1557 break;
1558 }
1559 LABEL_173:
1560 v69 = LODWORD(v16) - 1;
1561 ptr_801A08 = pVerticesSR_806210;
1562 ptr_801A04 = pVerticesSR_801A10;
1563 LODWORD(v126) = v69;
1564 if ( v105 && v105 != 7 && v105 != 3 && v105 != 4 )
1565 {
1566 for ( i = v69; i >= 1; --i )
1567 {
1568 v70 = i;
1569 v71 = terrain_76D7C8[i];
1570 v72 = terrain_76DBC8[i];
1571 if ( v71 < v72 )
1572 {
1573 terrain_76DBC8[v70] = v71;
1574 terrain_76D7C8[v70] = v72;
1575 }
1576 v73 = terrain_76DBC8[v70];
1577 v111 = 0;
1578 if ( v73 <= 0 )
1579 v73 = -v73;
1580 v74 = terrain_76D7C8[v70];
1581 if ( v74 <= 0 )
1582 v74 = -v74;
1583 v75 = v74 + 2;
1584 v76 = pGame->pIndoorCameraD3D;
1585 v107 = v75;
1586 a1 = v76;
1587 v77 = v73 - 2;
1588 if ( v73 - 2 < v75 )
1589 {
1590 v127 = 0;
1591 v79 = (v73 - 66) << 9;
1592 v116 = v77;
1593 v105 = v79;
1594 v111 = v75 - v77;
1595 do
1596 {
1597 *(float *)&v106 = (double)v105;
1598 *(float *)((char *)&ptr_801A08->vWorldPosition.x + v127) = *(float *)&v106;
1599 v105 = (64 - *(int *)((char *)terrain_76D9C8 + v70)) << 9;
1600 *(float *)((char *)&ptr_801A08->vWorldPosition.y + v127) = (double)v105;
1601 v105 = pOutdoor->GetHeightOnTerrain(v112, *(int *)((char *)terrain_76D9C8 + v70));
1602 *(float *)((char *)&ptr_801A08->vWorldPosition.z + v127) = (double)v105;
1603 *(float *)((char *)&ptr_801A04->vWorldPosition.x + v127) = *(float *)&v106;
1604 v105 = (63 - *(int *)((char *)terrain_76D9C8 + v70)) << 9;
1605 *(float *)((char *)&ptr_801A04->vWorldPosition.y + v127) = (double)v105;
1606 v105 = pOutdoor->GetHeightOnTerrain(v112, *(int *)((char *)terrain_76D9C8 + v70) + 1);
1607 *(float *)((char *)&ptr_801A04->vWorldPosition.z + v127) = (double)v105;
1608 if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
1609 {
1610 a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A08 + v127, 1);
1611 a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A04 + v127, 1);
1612 a1->Project((RenderVertexSoft *)(char *)ptr_801A08 + v127, 1, 0);
1613 a1->Project((RenderVertexSoft *)(char *)ptr_801A04 + v127, 1, 0);
1614 }
1615 v79 += 512;
1616 v127 += 48;
1617 ++v116;
1618 v105 = v79;
1619 }
1620 while ( v116 < v107 );
1621 }
1622 v103 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[v70]);
1623 v104 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[v70]);
1624 if ( pRenderer->pRenderD3D )
1625 Render::DrawTerrainD3D(v111, 0, (int)&v102);
1626 else
1627 Render::DrawTerrainSW(v111, 0, (int)&v102);
1628 }
1629 }
1630 else
1631 {
1632 for ( i = v69; i >= 1; --i )
1633 {
1634 v86 = i;
1635 v87 = terrain_76D5C8[i];
1636 v88 = terrain_76D9C8[i];
1637 if ( v87 < v88 )
1638 {
1639 terrain_76D9C8[v86] = v87;
1640 terrain_76D5C8[v86] = v88;
1641 }
1642 v89 = terrain_76D9C8[v86];
1643 v111 = 0;
1644 if ( v89 <= 0 )
1645 v89 = -v89;
1646 v90 = terrain_76D5C8[v86];
1647 if ( v90 <= 0 )
1648 v90 = -v90;
1649 a1 = pGame->pIndoorCameraD3D;
1650 v107 = v90 + 2;
1651 if ( v89 - 2 < v90 + 2 )
1652 {
1653 v86 = 0;
1654 v116 = v89 - 2;
1655 v92 = (66 - v89) << 9;
1656 v105 = (66 - v89) << 9;
1657 v111 = v90 + 2 - (v89 - 2);
1658 do
1659 {
1660 v93 = v116;
1661 v106 = (*(int *)((char *)terrain_76DBC8 + v86) - 64) << 9;
1662 *(float *)((char *)&ptr_801A08->vWorldPosition.x + v86) = (double)v106;
1663 *(float *)&v105 = (double)v105;
1664 *(float *)((char *)&ptr_801A08->vWorldPosition.y + v86) = *(float *)&v105;
1665 v106 = pOutdoor->GetHeightOnTerrain(*(int *)((char *)terrain_76DBC8 + v86), v93);
1666 v97 = v116;
1667 *(float *)((char *)&ptr_801A08->vWorldPosition.z + v86) = (double)v106;
1668 v106 = (*(int *)((char *)terrain_76DBC8 + v86) - 63) << 9;
1669 *(float *)((char *)&ptr_801A04->vWorldPosition.x + v86) = (double)v106;
1670 *(float *)((char *)&ptr_801A04->vWorldPosition.y + v86) = *(float *)&v105;
1671 v105 = pOutdoor->GetHeightOnTerrain(*(int *)((char *)terrain_76DBC8 + v86) + 1, v97);
1672 *(float *)((char *)&ptr_801A04->vWorldPosition.z + v86) = (double)v105;
1673 if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
1674 {
1675 a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1);
1676 a1->ViewTransform((RenderVertexSoft *)(char *)ptr_801A04 + v86, 1);
1677 a1->Project((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1, 0);
1678 a1->Project((RenderVertexSoft *)(char *)ptr_801A04 + v86, 1, 0);
1679 }
1680 v92 -= 512;
1681 v86 += 48;
1682 ++v116;
1683 v105 = v92;
1684 }
1685 while ( v116 < v107 );
1686 }
1687 v103 = abs((int)pIndoorCamera->uMapGridCellX - terrain_76DBC8[v86]);
1688 v104 = abs((int)pIndoorCamera->uMapGridCellZ - terrain_76D9C8[v86]);
1689 if ( pRenderer->pRenderD3D )
1690 Render::DrawTerrainD3D(v111, 1, (int)&v102);
1691 else
1692 Render::DrawTerrainSW(v111, 1, (int)&v102);
1693 }
1694 }
1695 result = v126;
1696 pOutdoorCamera->field_40 = v126;
1697 return result;
1698 }
1699 // 47FFC4: inconsistent fpu stack
1700 // 4D864C: using guessed type char byte_4D864C;
1701
1702
1703
1704 //----- (0048034E) --------------------------------------------------------
1705 void Render::DrawTerrainD3D(int a1, int edx0, int a3)
1706 {
1707 int v3; // esi@1
1708 int v4; // edi@1
1709 int v5; // ebx@2
1710 int v6; // eax@2
1711 int v7; // eax@3
1712 RenderVertexSoft *v8; // edi@3
1713 RenderVertexSoft *v9; // ebx@4
1714 RenderVertexSoft *v10; // ecx@4
1715 float v11; // eax@6
1716 double v12; // ST5C_8@6
1717 double v13; // ST2C_8@6
1718 int v14; // eax@6
1719 double v15; // st7@6
1720 stru148 *v16; // ebx@12
1721 unsigned __int16 v17; // ax@12
1722 int v18; // eax@13
1723 LightmapBuilder *v19; // ecx@13
1724 stru220 *v20; // eax@13
1725 int v21; // eax@13
1726 signed int v22; // eax@13
1727 Vec3_float_ *v23; // eax@15
1728 double v24; // st6@17
1729 double v25; // ST54_8@17
1730 unsigned __int8 v26; // sf@17
1731 unsigned __int8 v27; // of@17
1732 double v28; // st5@19
1733 double v29; // st5@19
1734 double v30; // st5@19
1735 double v31; // st5@19
1736 double v32; // st7@32
1737 int v33; // edi@38
1738 unsigned int v34; // ecx@47
1739 char v35; // zf@47
1740 unsigned int v36; // eax@50
1741 int v37; // eax@54
1742 stru148 *v38; // ecx@55
1743 unsigned int v39; // eax@59
1744 stru148 *v40; // ebx@62
1745 unsigned __int16 v41; // ax@62
1746 int v42; // eax@63
1747 LightmapBuilder *v43; // ecx@63
1748 stru220 *v44; // eax@63
1749 int v45; // eax@63
1750 int v46; // eax@63
1751 signed int v47; // eax@63
1752 Vec3_float_ *v48; // eax@65
1753 double v49; // st6@67
1754 double v50; // ST4C_8@67
1755 double v51; // st5@71
1756 double v52; // st5@71
1757 double v53; // st5@71
1758 double v54; // st7@84
1759 unsigned int v55; // ecx@98
1760 unsigned int v56; // eax@101
1761 int v57; // eax@105
1762 unsigned int v58; // eax@109
1763 stru148 *v59; // esi@112
1764 unsigned __int16 v60; // ax@112
1765 stru220 *v61; // eax@113
1766 signed int v62; // eax@113
1767 Vec3_float_ *v63; // eax@114
1768 double v64; // st6@116
1769 double v65; // ST3C_8@116
1770 double v66; // st5@120
1771 double v67; // st5@120
1772 double v68; // st5@120
1773 double v69; // st7@133
1774 int v70; // edi@138
1775 RenderVertexSoft *v71; // esi@147
1776 unsigned int v72; // ecx@147
1777 unsigned int v73; // eax@150
1778 float v74; // eax@154
1779 unsigned int v75; // eax@158
1780 unsigned int v76; // [sp-10h] [bp-E0h]@61
1781 stru148 *v77; // [sp-Ch] [bp-DCh]@61
1782 IDirect3DTexture2 *v78; // [sp-8h] [bp-D8h]@61
1783 int v79; // [sp-4h] [bp-D4h]@61
1784 int v80; // [sp+0h] [bp-D0h]@59
1785 int v81; // [sp+0h] [bp-D0h]@109
1786 int v82; // [sp+54h] [bp-7Ch]@1
1787 int v83; // [sp+60h] [bp-70h]@1
1788 int v84; // [sp+6Ch] [bp-64h]@1
1789 int v85; // [sp+70h] [bp-60h]@63
1790 int a4; // [sp+74h] [bp-5Ch]@73
1791 float v87; // [sp+78h] [bp-58h]@122
1792 int v88; // [sp+7Ch] [bp-54h]@1
1793 int v89; // [sp+80h] [bp-50h]@6
1794 float v90; // [sp+84h] [bp-4Ch]@1
1795 float v91; // [sp+88h] [bp-48h]@1
1796 float v92; // [sp+8Ch] [bp-44h]@1
1797 stru220 *v93; // [sp+90h] [bp-40h]@2
1798 int X; // [sp+94h] [bp-3Ch]@1
1799 float v95; // [sp+98h] [bp-38h]@21
1800 LightmapBuilder *v96; // [sp+9Ch] [bp-34h]@73
1801 LightmapBuilder *_this; // [sp+A0h] [bp-30h]@6
1802 int sX; // [sp+A4h] [bp-2Ch]@6
1803 unsigned int uNumVertices; // [sp+A8h] [bp-28h]@73
1804 int v100; // [sp+ACh] [bp-24h]@122
1805 int sY; // [sp+B0h] [bp-20h]@6
1806 RenderVertexSoft *a2; // [sp+B4h] [bp-1Ch]@3
1807 unsigned int a5; // [sp+B8h] [bp-18h]@21
1808 RenderVertexSoft *v101; // [sp+BCh] [bp-14h]@6
1809 Vec3_float_ *v99; // [sp+C0h] [bp-10h]@17
1810 RenderVertexSoft *pVertices; // [sp+C4h] [bp-Ch]@6
1811 RenderVertexSoft *a8; // [sp+C8h] [bp-8h]@6
1812 char v108; // [sp+CFh] [bp-1h]@36
1813 float thisd; // [sp+D8h] [bp+8h]@6
1814 float thise; // [sp+D8h] [bp+8h]@6
1815 float thisf; // [sp+D8h] [bp+8h]@17
1816 IndoorCameraD3D *thisa; // [sp+D8h] [bp+8h]@23
1817 float thisg; // [sp+D8h] [bp+8h]@67
1818 IndoorCameraD3D *thisb; // [sp+D8h] [bp+8h]@75
1819 float thish; // [sp+D8h] [bp+8h]@116
1820 IndoorCameraD3D *thisc; // [sp+D8h] [bp+8h]@124
1821 char this_3; // [sp+DBh] [bp+Bh]@30
1822 char this_3a; // [sp+DBh] [bp+Bh]@82
1823 char this_3b; // [sp+DBh] [bp+Bh]@131
1824
1825 v3 = a1;
1826 v82 = edx0;
1827 v83 = *(/*short **/_WORD *)(a3 + 4);
1828 X = abs(*(/*short **/_WORD *)(a3 + 6));
1829 v4 = 0;
1830 v88 = 0;
1831 v84 = v3 - 1;
1832 v90 = (double)pOutdoor->vSunlight.x * 0.000015258789;
1833 v91 = (double)pOutdoor->vSunlight.y * 0.000015258789;
1834 v92 = (double)pOutdoor->vSunlight.z * 0.000015258789;
1835 if ( v3 - 1 > 0 )
1836 {
1837 while ( 1 )
1838 {
1839 v5 = abs(X);//v5 = 13108
1840 v6 = abs(v83);//v6 = 13108
1841 --X;
1842 v93 = &stru_76E5C8[(v5 << 7) + v6];
1843 if ( !v93->field_0 || ((v7 = 48 * v4, v8 = &pVerticesSR_806210[v4], a2 = v8, !v82) ? (v9 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7),
1844 v10 = &pVerticesSR_806210[1] + v7) : (v9 = &pVerticesSR_806210[1] + v7, v10 = (RenderVertexSoft *)((char *)&pVerticesSR_801A10 + v7)),
1845 ((a8 = v9,
1846 pVertices = &pVerticesSR_801A10[1] + v7,
1847 v11 = v8->vWorldPosition.x,
1848 v101 = v10,
1849 v12 = v11 + 6.755399441055744e15,
1850 sX = LODWORD(v12),
1851 v13 = v8->vWorldPosition.y + 6.755399441055744e15,
1852 sY = LODWORD(v13),
1853 thisd = (v10->vWorldPosition.x + v8->vWorldPosition.x) * 0.5,
1854 v14 = WorldPosToGridCellX(floorf(thisd + 0.5f)),
1855 v15 = v9->vWorldPosition.y + v8->vWorldPosition.y,
1856 v89 = v14,
1857 thise = v15 * 0.5,
1858 _this = (LightmapBuilder *)WorldPosToGridCellZ(floorf(thisd + 0.5f)),
1859 WorldPosToGridCellX(sX),
1860 WorldPosToGridCellZ(sY),
1861 !byte_4D864C)
1862 || !(pGame->uFlags & 0x80))
1863 && !sub_481EFA(v8, v9, v101, pVertices, 1)) )
1864 goto LABEL_162;
1865 if ( v8->vWorldPosition.z != v9->vWorldPosition.z || v9->vWorldPosition.z != pVertices->vWorldPosition.z || pVertices->vWorldPosition.z != v101->vWorldPosition.z )
1866 break;
1867 v16 = &array_77EC08[pOutdoorCamera->numStru148s];
1868 v17 = pOutdoor->GetTileTexture(sX, sY);
1869 v16->uTileBitmapID = v17;
1870 if ( v17 != -1 )
1871 {
1872 v18 = pOutdoor->GetSomeOtherTileInfo(sX, sY);
1873 LOWORD(v18) = v18 | 0x8010;
1874 v19 = _this;
1875 *(int *)&v16->flags = v18;
1876 v20 = v93;
1877 v16->field_59 = 1;
1878 v16->field_5D = (char)v19;
1879 v16->field_34 = v20->distance;
1880 v21 = v89;
1881 v16->field_5C = v89;
1882 v22 = pTerrainNormalIndices[2 * (signed int)((char *)v19 + 128 * v21) + 1];
1883 if ( v22 < 0 || v22 > (signed int)(uNumTerrainNormals - 1) )
1884 v23 = 0;
1885 else
1886 v23 = &pTerrainNormals[v22];
1887 v24 = v92 * v23->z;
1888 v99 = v23;
1889 thisf = 20.0 - (-v24 - v91 * v23->y - v90 * v23->x) * 20.0;
1890 v25 = thisf + 6.7553994e15;
1891 v27 = pOutdoorCamera->numStru148s > 1999;
1892 v26 = pOutdoorCamera->numStru148s - 1999 < 0;
1893 v16->field_58 = LOBYTE(v25);
1894 if ( !(v26 ^ v27) )
1895 return;
1896 ++pOutdoorCamera->numStru148s;
1897 if ( !sub_481FC9(v8, a8, v101, v16) )
1898 goto LABEL_126;
1899 v28 = 1.0 / (a2->vWorldViewPosition.x + 0.0000001);
1900 memcpy(array_50AC10, a2, 0x30u);
1901 array_50AC10[0].flt_20 = v28;
1902 array_50AC10[0].u = 0.0;
1903 array_50AC10[0].v = 0.0;
1904 v29 = a8->vWorldViewPosition.x + 0.0000001;
1905 memcpy(&array_50AC10[1], a8, sizeof(array_50AC10[1]));
1906 array_50AC10[1].flt_20 = 1.0 / v29;
1907 array_50AC10[1].u = 0.0;
1908 array_50AC10[1].v = 1.0;
1909 v30 = pVertices->vWorldViewPosition.x + 0.0000001;
1910 memcpy(&array_50AC10[2], pVertices, sizeof(array_50AC10[2]));
1911 array_50AC10[2].flt_20 = 1.0 / v30;
1912 array_50AC10[2].u = 1.0;
1913 array_50AC10[2].v = 1.0;
1914 v31 = v101->vWorldViewPosition.x + 0.0000001;
1915 memcpy(&array_50AC10[3], v101, sizeof(array_50AC10[3]));
1916 array_50AC10[3].flt_20 = 1.0 / v31;
1917 array_50AC10[3].u = 1.0;
1918 array_50AC10[3].v = 0.0;
1919
1920 static stru154 static_sub_0048034E_stru_154;
1921 /*static bool __init_flag3 = false;
1922 if (!__init_flag3)
1923 {
1924 __init_flag3 = true;
1925
1926 stru154::stru154(&static_sub_0048034E_stru_154);
1927 }*/
1928
1929 _this = pGame->pLightmapBuilder;
1930 pGame->pLightmapBuilder->StackLights_TerrainFace(v99, &v95, array_50AC10, 4u, 1);
1931 pDecalBuilder->_49BE8A(v16, *(float *)&v99, (int)&v95, array_50AC10, 4u, 1);
1932 a5 = 4;
1933 if ( byte_4D864C && pGame->uFlags & 0x80 )
1934 {
1935 thisa = pGame->pIndoorCameraD3D;
1936 if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 )
1937 goto LABEL_162;
1938 thisa->ViewTransform(array_50AC10, a5);
1939 thisa->Project(array_50AC10, a5, 0);
1940 }
1941 this_3 = a2->vWorldViewPosition.x < 8.0
1942 || a8->vWorldViewPosition.x < 8.0
1943 || v101->vWorldViewPosition.x < 8.0
1944 || pVertices->vWorldViewPosition.x < 8.0;
1945 v32 = (double)pOutdoorCamera->shading_dist_mist;
1946 v108 = v32 < a2->vWorldViewPosition.x
1947 || v32 < a8->vWorldViewPosition.x
1948 || v32 < v101->vWorldViewPosition.x
1949 || v32 < pVertices->vWorldViewPosition.x;
1950 LOBYTE(v33) = 0;
1951 pGame->pLightmapBuilder->std__vector_000004_size = 0;
1952 if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
1953 {
1954 if ( this_3 )
1955 LOBYTE(v33) = 3;
1956 else
1957 v33 = v108 != 0 ? 5 : 0;
1958 static_sub_0048034E_stru_154._49B0C9(v99, v95);
1959 if ( pDecalBuilder->uNumDecals > 0 )
1960 pDecalBuilder->ApplyDecals(
1961 31 - v16->field_58,
1962 4,
1963 &static_sub_0048034E_stru_154,
1964 a5,
1965 array_50AC10,
1966 0,
1967 v33,
1968 -1);
1969 }
1970 if ( stru_F8AD28.uNumLightsApplied > 0 )
1971 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33);
1972 v34 = a5;
1973 v35 = byte_4D864C == 0;
1974 v16->uNumVertices = a5;
1975 if ( v35 || !(pGame->uFlags & 0x80) )
1976 {
1977 if ( this_3 )
1978 {
1979 v36 = sr_424CD7(v34);
1980 goto LABEL_53;
1981 }
1982 if ( v108 )
1983 {
1984 v36 = sr_424EE0_MakeFanFromTriangle(v34);
1985 LABEL_53:
1986 v16->uNumVertices = v36;
1987 OutdoorCamera::Project(v36);
1988 }
1989 }
1990 v37 = *(int *)&v16->flags;
1991 if ( !(BYTE1(v37) & 1) )
1992 {
1993 if ( v37 & 2 && v16->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
1994 {
1995 v80 = 0;
1996 v39 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
1997 }
1998 else
1999 {
2000 v39 = v16->uTileBitmapID;
2001 v80 = 1;
2002 }
2003 v79 = 0;
2004 v78 = pBitmaps_LOD->pHardwareTextures[v39];
2005 v77 = v16;
2006 v76 = v16->uNumVertices;
2007 LABEL_161:
2008 pRenderer->DrawTerrainPolygon(v76, v77, v78, v79, v80);
2009 goto LABEL_162;
2010 }
2011 v38 = v16;
2012 LABEL_56:
2013 v38->_4811A3();
2014 }
2015 LABEL_162:
2016 v4 = v88++ + 1;
2017 if ( v88 >= v84 )
2018 return;
2019 }
2020 v40 = &array_77EC08[pOutdoorCamera->numStru148s];
2021 v41 = pOutdoor->GetTileTexture(sX, sY);
2022 v40->uTileBitmapID = v41;
2023 if ( v41 == -1 )
2024 goto LABEL_162;
2025 v42 = pOutdoor->GetSomeOtherTileInfo(sX, sY);
2026 BYTE1(v42) |= 0x80u;
2027 v43 = pGame->pLightmapBuilder;
2028 *(int *)&v40->flags = v42;
2029 v44 = v93;
2030 v40->field_59 = 1;
2031 v40->field_5D = (char)v43;
2032 v40->field_34 = v44->distance;
2033 v45 = v89;
2034 v40->field_5C = v89;
2035 v46 = 2 * (int)((char *)v43 + 128 * v45);
2036 v85 = v46 * 2;
2037 v47 = pTerrainNormalIndices[v46 + 1];
2038 if ( v47 < 0 || v47 > (signed int)(uNumTerrainNormals - 1) )
2039 v48 = 0;
2040 else
2041 v48 = &pTerrainNormals[v47];
2042 v49 = v92 * v48->z;
2043 v99 = v48;
2044 thisg = 20.0 - (-v49 - v91 * v48->y - v90 * v48->x) * 20.0;
2045 v50 = thisg + 6.7553994e15;
2046 v40->field_58 = LOBYTE(v50);
2047 if ( SLOBYTE(v50) < 0 )
2048 v40->field_58 = 0;
2049 if ( pOutdoorCamera->numStru148s >= 1999 )
2050 return;
2051 ++pOutdoorCamera->numStru148s;
2052 if ( !sub_481FC9(a8, pVertices, v8, v40) )
2053 goto LABEL_77;
2054 v51 = 1.0 / (a2->vWorldViewPosition.x + 0.0000001);
2055 memcpy(array_50AC10, a2, 0x30u);
2056 array_50AC10[0].flt_20 = v51;
2057 array_50AC10[0].u = 0.0;
2058 array_50AC10[0].v = 0.0;
2059 v52 = a8->vWorldViewPosition.x + 0.0000001;
2060 memcpy(&array_50AC10[1], a8, sizeof(array_50AC10[1]));
2061 array_50AC10[1].flt_20 = 1.0 / v52;
2062 array_50AC10[1].u = 0.0;
2063 array_50AC10[1].v = 1.0;
2064 v53 = pVertices->vWorldViewPosition.x + 0.0000001;
2065 memcpy(&array_50AC10[2], pVertices, sizeof(array_50AC10[2]));
2066 array_50AC10[2].flt_20 = 1.0 / v53;
2067 array_50AC10[2].u = 1.0;
2068 array_50AC10[2].v = 1.0;
2069
2070 static stru154 static_sub_0048034E_stru_76D590;
2071 /*static bool __init_flag2 = false;
2072 if (!__init_flag2)
2073 {
2074 __init_flag2 = true;
2075
2076 stru154::stru154(&static_sub_0048034E_stru_76D590);
2077 }*/
2078
2079 v96 = pGame->pLightmapBuilder;
2080 pGame->pLightmapBuilder->StackLights_TerrainFace(v99, (float *)&a4, array_50AC10, 3u, 0);
2081 pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&a4, array_50AC10, 3u, 0);
2082 uNumVertices = 3;
2083 if ( byte_4D864C && pGame->uFlags & 0x80 )
2084 {
2085 thisb = pGame->pIndoorCameraD3D;
2086 if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &uNumVertices, 0) == 1 && !uNumVertices )
2087 {
2088 LABEL_77:
2089 --pOutdoorCamera->numStru148s;
2090 goto LABEL_112;
2091 }
2092 thisb->ViewTransform(array_50AC10, uNumVertices);
2093 thisb->Project(array_50AC10, uNumVertices, 0);
2094 }
2095 this_3a = a2->vWorldViewPosition.x < 8.0 || a8->vWorldViewPosition.x < 8.0 || pVertices->vWorldViewPosition.x < 8.0;
2096 v54 = (double)pOutdoorCamera->shading_dist_mist;
2097 v108 = v54 < a2->vWorldViewPosition.x || v54 < a8->vWorldViewPosition.x || v54 < pVertices->vWorldViewPosition.x;
2098 a8 = 0;
2099 v96->std__vector_000004_size = 0;
2100 if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
2101 {
2102 a8 = (RenderVertexSoft *)(this_3a ? 3 : v108 != 0 ? 5 : 0);
2103 static_sub_0048034E_stru_76D590._49B0C9(v99, *(float *)&a4);
2104 if ( pDecalBuilder->uNumDecals > 0 )
2105 pDecalBuilder->ApplyDecals(
2106 31 - v40->field_58,
2107 4,
2108 &static_sub_0048034E_stru_76D590,
2109 uNumVertices,
2110 array_50AC10,
2111 0,
2112 (char)a8,
2113 -1);
2114 }
2115 if ( stru_F8AD28.uNumLightsApplied > 0 )
2116 v96->ApplyLights(
2117 &stru_F8AD28,
2118 &static_sub_0048034E_stru_76D590,
2119 uNumVertices,
2120 array_50AC10,
2121 0,
2122 (char)a8);
2123 v55 = uNumVertices;
2124 v35 = byte_4D864C == 0;
2125 v40->uNumVertices = uNumVertices;
2126 if ( v35 || !(pGame->uFlags & 0x80) )
2127 {
2128 if ( this_3a )
2129 {
2130 v56 = sr_424CD7(v55);
2131 }
2132 else
2133 {
2134 if ( !v108 )
2135 goto LABEL_105;
2136 v56 = sr_424EE0_MakeFanFromTriangle(v55);
2137 }
2138 v40->uNumVertices = v56;
2139 OutdoorCamera::Project(v56);
2140 }
2141 LABEL_105:
2142 v57 = *(int *)&v40->flags;
2143 if ( BYTE1(v57) & 1 )
2144 {
2145 v40->_4811A3();
2146 }
2147 else
2148 {
2149 if ( v57 & 2 && v40->uTileBitmapID == pRenderer->field_1036AC_bitmapid )
2150 {
2151 v81 = 0;
2152 v58 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
2153 }
2154 else
2155 {
2156 v58 = v40->uTileBitmapID;
2157 v81 = 1;
2158 }
2159 pRenderer->DrawTerrainPolygon(v40->uNumVertices, v40, pBitmaps_LOD->pHardwareTextures[v58], 0, v81);
2160 }
2161 LABEL_112:
2162 v59 = &array_77EC08[pOutdoorCamera->numStru148s];
2163 a8 = (RenderVertexSoft *)&array_77EC08[pOutdoorCamera->numStru148s];
2164 v60 = pOutdoor->GetTileTexture(sX, sY);
2165 v59->uTileBitmapID = v60;
2166 if ( v60 == -1 )
2167 goto LABEL_162;
2168 *(int *)&v59->flags = pOutdoor->GetSomeOtherTileInfo(sX, sY);
2169 v61 = v93;
2170 v59->field_59 = 1;
2171 v59->field_34 = v61->distance;
2172 v59->field_5C = v89;
2173 v59->field_5D = (char)_this;
2174 v62 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + v85);
2175 if ( v62 > (signed int)(uNumTerrainNormals - 1) )
2176 v63 = 0;
2177 else
2178 v63 = &pTerrainNormals[v62];
2179 v64 = v92 * v63->z;
2180 v99 = v63;
2181 thish = 20.0 - (-v64 - v91 * v63->y - v90 * v63->x) * 20.0;
2182 v65 = thish + 6.7553994e15;
2183 v59->field_58 = LOBYTE(v65);
2184 if ( SLOBYTE(v65) < 0 )
2185 v59->field_58 = 0;
2186 if ( pOutdoorCamera->numStru148s >= 1999 )
2187 return;
2188 ++pOutdoorCamera->numStru148s;
2189 if ( !sub_481FC9(v101, a2, pVertices, v59) )
2190 {
2191 LABEL_126:
2192 --pOutdoorCamera->numStru148s;
2193 goto LABEL_162;
2194 }
2195 v66 = 1.0 / (a2->vWorldViewPosition.x + 0.0000001);
2196 memcpy(array_50AC10, a2, 0x30u);
2197 array_50AC10[0].flt_20 = v66;
2198 array_50AC10[0].u = 0.0;
2199 array_50AC10[0].v = 0.0;
2200 v67 = pVertices->vWorldViewPosition.x + 0.0000001;
2201 memcpy(&array_50AC10[1], pVertices, sizeof(array_50AC10[1]));
2202 array_50AC10[1].flt_20 = 1.0 / v67;
2203 array_50AC10[1].u = 1.0;
2204 array_50AC10[1].v = 1.0;
2205 v68 = v101->vWorldViewPosition.x + 0.0000001;
2206 memcpy(&array_50AC10[2], v101, sizeof(array_50AC10[2]));
2207 array_50AC10[2].flt_20 = 1.0 / v68;
2208 array_50AC10[2].u = 1.0;
2209 array_50AC10[2].v = 0.0;
2210
2211 static stru154 static_sub_0048034E_stru_76D578;
2212 /*static bool __init_flag1 = false;
2213 if (!__init_flag1)
2214 {
2215 __init_flag1 = true;
2216
2217 stru154::stru154(&static_sub_0048034E_stru_76D578);
2218 }*/
2219
2220 v96 = pGame->pLightmapBuilder;
2221 pGame->pLightmapBuilder->StackLights_TerrainFace(v99, &v87, array_50AC10, 3u, 1);
2222 pDecalBuilder->_49BE8A(v40, *(float *)&v99, (int)&v87, array_50AC10, 3u, 1);
2223 v100 = 3;
2224 if ( byte_4D864C && pGame->uFlags & 0x80 )
2225 {
2226 thisc = pGame->pIndoorCameraD3D;
2227 if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, (unsigned int *)&v100, 0) == 1 && !v100 )
2228 goto LABEL_126;
2229 thisc->ViewTransform(array_50AC10, v100);
2230 thisc->Project(array_50AC10, v100, 0);
2231 }
2232 this_3b = a2->vWorldViewPosition.x < 8.0
2233 || pVertices->vWorldViewPosition.x < 8.0
2234 || v101->vWorldViewPosition.x < 8.0;
2235 v69 = (double)pOutdoorCamera->shading_dist_mist;
2236 v108 = v69 < a2->vWorldViewPosition.x || v69 < pVertices->vWorldViewPosition.x || v69 < v101->vWorldViewPosition.x;
2237 LOBYTE(v70) = 0;
2238 v96->std__vector_000004_size = 0;
2239 if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
2240 {
2241 if ( this_3b )
2242 LOBYTE(v70) = 3;
2243 else
2244 v70 = v108 != 0 ? 5 : 0;
2245 static_sub_0048034E_stru_76D578._49B0C9(v99, v87);
2246 if ( pDecalBuilder->uNumDecals > 0 )
2247 pDecalBuilder->ApplyDecals(
2248 31 - v40->field_58,
2249 4,
2250 &static_sub_0048034E_stru_76D578,
2251 v100,
2252 array_50AC10,
2253 0,
2254 v70,
2255 -1);
2256 }
2257 if ( stru_F8AD28.uNumLightsApplied > 0 )
2258 v96->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_76D578, v100, array_50AC10, 0, v70);
2259 v71 = a8;
2260 v72 = v100;
2261 v35 = byte_4D864C == 0;
2262 LODWORD(a8->vWorldViewPosition.z) = v100;
2263 if ( !v35 && pGame->uFlags & 0x80 )
2264 goto LABEL_154;
2265 if ( this_3b )
2266 {
2267 v73 = sr_424CD7(v72);
2268 }
2269 else
2270 {
2271 if ( !v108 )
2272 {
2273 LABEL_154:
2274 v74 = v71[1].vWorldPosition.x;
2275 if ( !(BYTE1(v74) & 1) )
2276 {
2277 if ( LOBYTE(v74) & 2 && LOWORD(v71[1].vWorldViewProjY) == pRenderer->field_1036AC_bitmapid )
2278 {
2279 v80 = 0;
2280 v75 = pRenderer->pHDWaterBitmapIDs[pRenderer->field_1036A8_bitmapid];
2281 }
2282 else
2283 {
2284 v75 = LOWORD(v71[1].vWorldViewProjY);
2285 v80 = 1;
2286 }
2287 v79 = 0;
2288 v78 = pBitmaps_LOD->pHardwareTextures[v75];
2289 v77 = (stru148 *)v71;
2290 v76 = LODWORD(v71->vWorldViewPosition.z);
2291 goto LABEL_161;
2292 }
2293 v38 = (stru148 *)v71;
2294 goto LABEL_56;
2295 }
2296 v73 = sr_424EE0_MakeFanFromTriangle(v72);
2297 }
2298 LODWORD(v71->vWorldViewPosition.z) = v73;
2299 OutdoorCamera::Project(v73);
2300 goto LABEL_154;
2301 }
2302 }
2303 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
2304 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
2305 // 4D864C: using guessed type char byte_4D864C;
2306 // 76D5C0: using guessed type char static_sub_0048034E_byte_76D5C0__init_flag;
2307
2308
2309
2310 //----- (00481212) --------------------------------------------------------
2311 void Render::DrawTerrainSW(int a1, int a2, int a3)
2312 {
2313 int v3; // esi@1
2314 int v4; // ecx@1
2315 int v5; // ST10_4@1
2316 int v6; // edi@1
2317 int v7; // ebx@2
2318 int v8; // eax@2
2319 int v9; // eax@3
2320 RenderVertexSoft *v10; // edi@3
2321 RenderVertexSoft *v11; // ebx@4
2322 RenderVertexSoft *v12; // ecx@4
2323 float v13; // eax@6
2324 int v14; // eax@6
2325 double v15; // st7@6
2326 double v16; // st7@6
2327 stru148 *v17; // ebx@12
2328 unsigned __int16 v18; // ax@12
2329 int v19; // eax@13
2330 float v20; // ecx@13
2331 stru220 *v21; // eax@13
2332 int v22; // eax@13
2333 signed int v23; // eax@13
2334 Vec3_float_ *v24; // eax@15
2335 double v25; // st7@18
2336 double v26; // st5@24
2337 double v27; // st5@24
2338 double v28; // st5@24
2339 double v29; // st5@24
2340 Game *v30; // eax@25
2341 RenderVertexSoft *v31; // edi@29
2342 double v32; // st7@31
2343 int v33; // esi@35
2344 RenderVertexSoft *v34; // edx@36
2345 RenderVertexSoft *v35; // ecx@36
2346 signed int v36; // eax@39
2347 signed int v37; // esi@40
2348 stru148 *v38; // ebx@43
2349 unsigned __int16 v39; // ax@43
2350 int v40; // eax@44
2351 float v41; // ecx@44
2352 stru220 *v42; // eax@44
2353 int v43; // eax@44
2354 int v44; // eax@44
2355 signed int v45; // eax@44
2356 Vec3_float_ *v46; // eax@46
2357 double v47; // st7@49
2358 double v48; // st5@57
2359 double v49; // st5@57
2360 double v50; // st5@57
2361 Game *v51; // eax@58
2362 RenderVertexSoft *v52; // edi@62
2363 double v53; // st7@63
2364 int v54; // esi@66
2365 signed int v55; // eax@69
2366 signed int v56; // esi@71
2367 unsigned __int16 v57; // ax@75
2368 stru220 *v58; // eax@76
2369 signed int v59; // eax@76
2370 Vec3_float_ *v60; // eax@77
2371 double v61; // st7@80
2372 double v62; // st5@88
2373 double v63; // st5@88
2374 double v64; // st5@88
2375 Game *v65; // eax@89
2376 double v66; // st7@94
2377 RenderVertexSoft *v67; // [sp-Ch] [bp-C4h]@36
2378 stru148 *v68; // [sp-8h] [bp-C0h]@36
2379 int v69; // [sp-4h] [bp-BCh]@36
2380 float v70; // [sp+Ch] [bp-ACh]@88
2381 double v71; // [sp+10h] [bp-A8h]@6
2382 double v72; // [sp+18h] [bp-A0h]@82
2383 double v73; // [sp+20h] [bp-98h]@6
2384 double v74; // [sp+28h] [bp-90h]@51
2385 double v75; // [sp+30h] [bp-88h]@6
2386 double v76; // [sp+38h] [bp-80h]@20
2387 double v77; // [sp+40h] [bp-78h]@6
2388 float v78; // [sp+48h] [bp-70h]@57
2389 float v79; // [sp+4Ch] [bp-6Ch]@6
2390 float v80; // [sp+50h] [bp-68h]@6
2391 int v81; // [sp+54h] [bp-64h]@1
2392 int v82; // [sp+58h] [bp-60h]@6
2393 int v83; // [sp+5Ch] [bp-5Ch]@82
2394 int v84; // [sp+60h] [bp-58h]@20
2395 int v85; // [sp+64h] [bp-54h]@1
2396 int v86; // [sp+68h] [bp-50h]@1
2397 int v87; // [sp+6Ch] [bp-4Ch]@51
2398 float v88; // [sp+70h] [bp-48h]@51
2399 int v89; // [sp+74h] [bp-44h]@6
2400 int v90; // [sp+78h] [bp-40h]@1
2401 float a3a; // [sp+7Ch] [bp-3Ch]@24
2402 stru220 *v92; // [sp+80h] [bp-38h]@2
2403 float v93; // [sp+84h] [bp-34h]@44
2404 int v94; // [sp+88h] [bp-30h]@6
2405 float v95; // [sp+8Ch] [bp-2Ch]@1
2406 float v96; // [sp+90h] [bp-28h]@1
2407 float v97; // [sp+94h] [bp-24h]@1
2408 int X; // [sp+98h] [bp-20h]@1
2409 float v99; // [sp+9Ch] [bp-1Ch]@6
2410 int v100; // [sp+A0h] [bp-18h]@6
2411 unsigned __int64 v101; // [sp+A4h] [bp-14h]@6
2412 RenderVertexSoft *v102; // [sp+ACh] [bp-Ch]@6
2413 RenderVertexSoft *v103; // [sp+B0h] [bp-8h]@6
2414 RenderVertexSoft *v104; // [sp+B4h] [bp-4h]@3
2415 float pNormalc; // [sp+C0h] [bp+8h]@6
2416 float pNormald; // [sp+C0h] [bp+8h]@6
2417 Vec3_float_ *pNormal; // [sp+C0h] [bp+8h]@17
2418 Vec3_float_ *pNormala; // [sp+C0h] [bp+8h]@48
2419 Vec3_float_ *pNormalb; // [sp+C0h] [bp+8h]@77
2420
2421 v3 = a1;
2422 //v4 = *(short *)(a3 + 4);
2423 //v5 = *(short *)(a3 + 6);
2424 v85 = a2;
2425 v86 = *(_WORD *)(a3 + 4); //v4;
2426 X = abs(*(_WORD *)(a3 + 6)); //v5
2427 v6 = 0;
2428 v90 = 0;
2429 v81 = v3 - 1;
2430 v95 = (double)pOutdoor->vSunlight.x * 0.000015258789;
2431 v96 = (double)pOutdoor->vSunlight.y * 0.000015258789;
2432 v97 = (double)pOutdoor->vSunlight.z * 0.000015258789;
2433 if ( v3 - 1 > 0 )
2434 {
2435 while ( 1 )
2436 {
2437 v7 = abs(X);
2438 v8 = abs(v86);
2439 --X;
2440 v92 = &stru_76E5C8[(v7 << 7) + v8];
2441 if ( !v92->field_0
2442 || ((v9 = v6, v10 = &pVerticesSR_806210[v6], v104 = v10, !v85) ? (v11 = &pVerticesSR_801A10[v9],
2443 v12 = &pVerticesSR_806210[v9 + 1]) : (v11 = &pVerticesSR_806210[v9 + 1], v12 = &pVerticesSR_801A10[v9]),
2444 ((v103 = &pVerticesSR_801A10[v9 + 1],
2445 v13 = v10->vWorldPosition.x,
2446 v102 = v12,
2447 v80 = v13,
2448 v73 = v13 + 6.7553994e15,
2449 v101 = __PAIR__((unsigned int)v11, LODWORD(v73)),
2450 v79 = v10->vWorldPosition.y,
2451 v75 = v79 + 6.7553994e15,
2452 v100 = LODWORD(v75),
2453 pNormalc = (v12->vWorldPosition.x + v10->vWorldPosition.x) * 0.5,
2454 v71 = pNormalc + 6.7553994e15,
2455 v89 = LODWORD(v71),
2456 v14 = WorldPosToGridCellX(COERCE_UNSIGNED_INT64(pNormalc + 6.7553994e15)),
2457 v15 = v11->vWorldPosition.y + v10->vWorldPosition.y,
2458 v94 = v14,
2459 pNormald = v15 * 0.5,
2460 v16 = pNormald + 6.7553994e15,
2461 v77 = v16,
2462 v82 = LODWORD(v77),
2463 LODWORD(v99) = WorldPosToGridCellZ(LODWORD(v16)),
2464 WorldPosToGridCellX(v101),
2465 WorldPosToGridCellZ(v100),
2466 !byte_4D864C)
2467 || !(pGame->uFlags & 0x80))
2468 && !sub_481EFA(v10, v11, v102, v103, 1)) )
2469 goto LABEL_105;
2470 if ( v10->vWorldPosition.z != v11->vWorldPosition.z
2471 || v11->vWorldPosition.z != v103->vWorldPosition.z
2472 || v103->vWorldPosition.z != v102->vWorldPosition.z )
2473 break;
2474 v17 = &array_77EC08[pOutdoorCamera->numStru148s];
2475 v18 = pOutdoor->GetTileTexture(v101, v100);
2476 v17->uTileBitmapID = v18;
2477 if ( v18 != -1 )
2478 {
2479 v19 = pOutdoor->GetSomeOtherTileInfo(v101, v100);
2480 LOWORD(v19) = v19 | 0x8010;
2481 v20 = v99;
2482 *(int *)&v17->flags = v19;
2483 v21 = v92;
2484 v17->field_59 = 1;
2485 v17->field_5D = LOBYTE(v20);
2486 v17->field_34 = v21->distance;
2487 v22 = v94;
2488 v17->field_5C = v94;
2489 v23 = pTerrainNormalIndices[2 * (LODWORD(v20) + (v22 << 7)) + 1];
2490 if ( v23 < 0 || v23 > (signed int)(uNumTerrainNormals - 1) )
2491 v24 = 0;
2492 else
2493 v24 = &pTerrainNormals[v23];
2494 pNormal = v24;
2495 if ( v24 )
2496 {
2497 v25 = -(v97 * v24->z + v96 * v24->y + v95 * v24->x);
2498 if ( v25 < 0.0 )
2499 v25 = 0.0;
2500 v99 = v25 * 31.0;
2501 v76 = v99 + 6.7553994e15;
2502 v84 = LODWORD(v76);
2503 v17->field_58 = 31 - LOBYTE(v76);
2504 }
2505 else
2506 {
2507 v17->field_58 = 0;
2508 }
2509 if ( pOutdoorCamera->numStru148s >= 1999 )
2510 return;
2511 ++pOutdoorCamera->numStru148s;
2512 if ( !sub_481FC9(v10, (RenderVertexSoft *)HIDWORD(v101), v102, v17) )
2513 goto LABEL_104;
2514 v26 = 1.0 / (v104->vWorldViewPosition.x + 0.0000001);
2515 memcpy(array_50AC10, v104, 0x30u);
2516 array_50AC10[0].flt_20 = v26;
2517 array_50AC10[0].u = 0.0;
2518 array_50AC10[0].v = 0.0;
2519 v27 = *(float *)(HIDWORD(v101) + 12) + 0.0000001;
2520 memcpy(&array_50AC10[1], (void *)HIDWORD(v101), sizeof(array_50AC10[1]));
2521 array_50AC10[1].flt_20 = 1.0 / v27;
2522 array_50AC10[1].u = 0.0;
2523 array_50AC10[1].v = 1.0;
2524 v28 = v103->vWorldViewPosition.x + 0.0000001;
2525 memcpy(&array_50AC10[2], v103, sizeof(array_50AC10[2]));
2526 array_50AC10[2].flt_20 = 1.0 / v28;
2527 array_50AC10[2].u = 1.0;
2528 array_50AC10[2].v = 1.0;
2529 v29 = v102->vWorldViewPosition.x + 0.0000001;
2530 memcpy(&array_50AC10[3], v102, sizeof(array_50AC10[3]));
2531 array_50AC10[3].flt_20 = 1.0 / v29;
2532 array_50AC10[3].u = 1.0;
2533 array_50AC10[3].v = 0.0;
2534 pGame->pLightmapBuilder->StackLights_TerrainFace(pNormal, &a3a, array_50AC10, 4u, 1);
2535 if ( stru_F8AD28.uNumLightsApplied <= 0 )
2536 {
2537 v17->field_108 = 0;
2538 }
2539 else
2540 {
2541 v30 = pGame;
2542 v17->field_108 = 1;
2543 pGame->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 4, pNormal);
2544 }
2545 if ( v104->vWorldViewPosition.x < 8.0
2546 || *(float *)(HIDWORD(v101) + 12) < 8.0
2547 || (v31 = v102, v102->vWorldViewPosition.x < 8.0)
2548 || v103->vWorldViewPosition.x < 8.0 )
2549 {
2550 v36 = sr_4250FE(4u);
2551 }
2552 else
2553 {
2554 v32 = (double)pOutdoorCamera->shading_dist_mist;
2555 if ( v32 >= v104->vWorldViewPosition.x
2556 && v32 >= *(float *)(HIDWORD(v101) + 12)
2557 && v32 >= v102->vWorldViewPosition.x
2558 && v32 >= v103->vWorldViewPosition.x )
2559 {
2560 v33 = sr_4254D2(4);
2561 v17->uNumVertices = v33;
2562 if ( !v33 )
2563 goto LABEL_104;
2564 v34 = (RenderVertexSoft *)HIDWORD(v101);
2565 v35 = v104;
2566 v69 = 0;
2567 v68 = v17;
2568 v67 = v31;
2569 goto LABEL_37;
2570 }
2571 v36 = sr_4252E8(4u);
2572 }
2573 v37 = v36;
2574 if ( !v36 )
2575 goto LABEL_104;
2576 LABEL_41:
2577 OutdoorCamera::Project(v37);
2578 LABEL_102:
2579 v33 = sr_4254D2(v37);
2580 v17->uNumVertices = v33;
2581 if ( !v33 )
2582 goto LABEL_104;
2583 v17->_48276F_sr();
2584 goto LABEL_38;
2585 }
2586 LABEL_105:
2587 v6 = v90++ + 1;
2588 if ( v90 >= v81 )
2589 return;
2590 }
2591 v38 = &array_77EC08[pOutdoorCamera->numStru148s];
2592 v39 = pOutdoor->GetTileTexture(v101, v100);
2593 v38->uTileBitmapID = v39;
2594 if ( v39 == -1 )
2595 goto LABEL_105;
2596 v40 = pOutdoor->GetSomeOtherTileInfo(v101, v100);
2597 BYTE1(v40) |= 0x80u;
2598 v41 = v99;
2599 *(int *)&v38->flags = v40;
2600 v42 = v92;
2601 v38->field_59 = 1;
2602 v38->field_5D = LOBYTE(v41);
2603 v38->field_34 = v42->distance;
2604 v43 = v94;
2605 v38->field_5C = v94;
2606 v44 = 2 * (LODWORD(v41) + (v43 << 7));
2607 LODWORD(v93) = v44 * 2;
2608 v45 = pTerrainNormalIndices[v44 + 1];
2609 if ( v45 < 0 || v45 > (signed int)(uNumTerrainNormals - 1) )
2610 v46 = 0;
2611 else
2612 v46 = &pTerrainNormals[v45];
2613 pNormala = v46;
2614 if ( v46 )
2615 {
2616 v47 = -(v97 * v46->z + v96 * v46->y + v95 * v46->x);
2617 if ( v47 < 0.0 )
2618 v47 = 0.0;
2619 v88 = v47 * 31.0;
2620 v74 = v88 + 6.7553994e15;
2621 v87 = LODWORD(v74);
2622 v38->field_58 = 31 - LOBYTE(v74);
2623 }
2624 else
2625 {
2626 v38->field_58 = 0;
2627 }
2628 if ( v38->field_58 < 0 )
2629 v38->field_58 = 0;
2630 if ( pOutdoorCamera->numStru148s >= 1999 )
2631 return;
2632 ++pOutdoorCamera->numStru148s;
2633 if ( !sub_481FC9((RenderVertexSoft *)HIDWORD(v101), v103, v104, v38) )
2634 goto LABEL_74;
2635 v48 = 1.0 / (v104->vWorldViewPosition.x + 0.0000001);
2636 memcpy(array_50AC10, v104, 0x30u);
2637 array_50AC10[0].flt_20 = v48;
2638 array_50AC10[0].u = 0.0;
2639 array_50AC10[0].v = 0.0;
2640 v49 = *(float *)(HIDWORD(v101) + 12) + 0.0000001;
2641 memcpy(&array_50AC10[1], (void *)HIDWORD(v101), sizeof(array_50AC10[1]));
2642 array_50AC10[1].flt_20 = 1.0 / v49;
2643 array_50AC10[1].u = 0.0;
2644 array_50AC10[1].v = 1.0;
2645 v50 = v103->vWorldViewPosition.x + 0.0000001;
2646 memcpy(&array_50AC10[2], v103, sizeof(array_50AC10[2]));
2647 array_50AC10[2].flt_20 = 1.0 / v50;
2648 array_50AC10[2].u = 1.0;
2649 array_50AC10[2].v = 1.0;
2650 pGame->pLightmapBuilder->StackLights_TerrainFace(pNormala, &v78, array_50AC10, 3u, 0);
2651 if ( stru_F8AD28.uNumLightsApplied <= 0 )
2652 {
2653 v38->field_108 = 0;
2654 }
2655 else
2656 {
2657 v51 = pGame;
2658 v38->field_108 = 1;
2659 pGame->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 3, pNormala);
2660 }
2661 if ( v104->vWorldViewPosition.x < 8.0
2662 || *(float *)(HIDWORD(v101) + 12) < 8.0
2663 || (v52 = v103, v103->vWorldViewPosition.x < 8.0) )
2664 {
2665 v55 = sr_4250FE(3u);
2666 }
2667 else
2668 {
2669 v53 = (double)pOutdoorCamera->shading_dist_mist;
2670 if ( v53 >= v104->vWorldViewPosition.x
2671 && v53 >= *(float *)(HIDWORD(v101) + 12)
2672 && v53 >= v103->vWorldViewPosition.x )
2673 {
2674 v54 = sr_4254D2(3);
2675 v38->uNumVertices = v54;
2676 if ( v54 )
2677 {
2678 sr_sub_4829B9((RenderVertexSoft *)HIDWORD(v101), v52, v104, v38, 0);
2679 LABEL_68:
2680 sr_sub_481DB2(array_508690, v54, v38);
2681 LABEL_75:
2682 v17 = &array_77EC08[pOutdoorCamera->numStru148s];
2683 v57 = pOutdoor->GetTileTexture(v101, v100);
2684 v17->uTileBitmapID = v57;
2685 if ( v57 == -1 )
2686 goto LABEL_105;
2687 *(int *)&v17->flags = pOutdoor->GetSomeOtherTileInfo(v101, v100);
2688 v58 = v92;
2689 v17->field_59 = 1;
2690 v17->field_34 = v58->distance;
2691 v17->field_5C = v94;
2692 v17->field_5D = LOBYTE(v99);
2693 v59 = *(unsigned __int16 *)((char *)pTerrainNormalIndices + LODWORD(v93));
2694 if ( v59 > (signed int)(uNumTerrainNormals - 1) )
2695 {
2696 pNormalb = 0;
2697 v60 = 0;
2698 }
2699 else
2700 {
2701 v60 = &pTerrainNormals[v59];
2702 pNormalb = v60;
2703 }
2704 if ( v60 )
2705 {
2706 v61 = -(v97 * v60->z + v96 * v60->y + v95 * v60->x);
2707 if ( v61 < 0.0 )
2708 v61 = 0.0;
2709 v93 = v61 * 31.0;
2710 v72 = v93 + 6.7553994e15;
2711 v83 = LODWORD(v72);
2712 v17->field_58 = 31 - LOBYTE(v72);
2713 }
2714 else
2715 {
2716 v17->field_58 = 0;
2717 }
2718 if ( v17->field_58 < 0 )
2719 v17->field_58 = 0;
2720 if ( pOutdoorCamera->numStru148s >= 1999 )
2721 return;
2722 ++pOutdoorCamera->numStru148s;
2723 if ( !sub_481FC9(v102, v104, v103, v17) )
2724 {
2725 LABEL_104:
2726 --pOutdoorCamera->numStru148s;
2727 goto LABEL_105;
2728 }
2729 v62 = 1.0 / (v104->vWorldViewPosition.x + 0.0000001);
2730 memcpy(array_50AC10, v104, 0x30u);
2731 array_50AC10[0].flt_20 = v62;
2732 array_50AC10[0].u = 0.0;
2733 array_50AC10[0].v = 0.0;
2734 v63 = v103->vWorldViewPosition.x + 0.0000001;
2735 memcpy(&array_50AC10[1], v103, sizeof(array_50AC10[1]));
2736 array_50AC10[1].flt_20 = 1.0 / v63;
2737 array_50AC10[1].u = 1.0;
2738 array_50AC10[1].v = 1.0;
2739 v64 = v102->vWorldViewPosition.x + 0.0000001;
2740 memcpy(&array_50AC10[2], v102, sizeof(array_50AC10[2]));
2741 array_50AC10[2].flt_20 = 1.0 / v64;
2742 array_50AC10[2].u = 1.0;
2743 array_50AC10[2].v = 0.0;
2744 pGame->pLightmapBuilder->StackLights_TerrainFace(pNormalb, &v70, array_50AC10, 3u, 1);
2745 if ( stru_F8AD28.uNumLightsApplied <= 0 )
2746 {
2747 v17->field_108 = 0;
2748 }
2749 else
2750 {
2751 v65 = pGame;
2752 v17->field_108 = 1;
2753 pGame->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 3, pNormalb);
2754 }
2755 if ( v104->vWorldViewPosition.x < 8.0 || v103->vWorldViewPosition.x < 8.0 || v102->vWorldViewPosition.x < 8.0 )
2756 {
2757 v37 = sr_4250FE(3u);
2758 OutdoorCamera::Project(v37);
2759 if ( !v37 )
2760 goto LABEL_104;
2761 goto LABEL_102;
2762 }
2763 v66 = (double)pOutdoorCamera->shading_dist_mist;
2764 if ( v66 < v104->vWorldViewPosition.x || v66 < v103->vWorldViewPosition.x || v66 < v102->vWorldViewPosition.x )
2765 {
2766 v37 = sr_4252E8(3u);
2767 if ( !v37 )
2768 goto LABEL_105;
2769 goto LABEL_41;
2770 }
2771 v33 = sr_4254D2(3);
2772 v17->uNumVertices = v33;
2773 if ( !v33 )
2774 goto LABEL_104;
2775 v34 = v104;
2776 v35 = v102;
2777 v69 = 0;
2778 v68 = v17;
2779 v67 = v103;
2780 LABEL_37:
2781 sr_sub_4829B9(v35, v34, v67, v68, v69);
2782 LABEL_38:
2783 sr_sub_481DB2(array_508690, v33, v17);
2784 goto LABEL_105;
2785 }
2786 goto LABEL_74;
2787 }
2788 v55 = sr_4252E8(3u);
2789 }
2790 v56 = v55;
2791 if ( v55 )
2792 {
2793 OutdoorCamera::Project(v55);
2794 v54 = sr_4254D2(v56);
2795 v38->uNumVertices = v54;
2796 if ( v54 )
2797 {
2798 v38->_48276F_sr();
2799 goto LABEL_68;
2800 }
2801 }
2802 LABEL_74:
2803 --pOutdoorCamera->numStru148s;
2804 goto LABEL_75;
2805 }
2806 }
2807 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
2808 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
2809 // 4D864C: using guessed type char byte_4D864C;
2810
2811
2812 //----- (0047BACF) --------------------------------------------------------
2813 void Render::TransformBillboardsAndSetPalettesODM()
2814 {
2815 int v0; // edi@1
2816 char *v1; // esi@2
2817 unsigned int v2; // edx@3
2818 int v3; // eax@3
2819 int v4; // edi@3
2820 int v5; // eax@3
2821 __int16 v6; // di@3
2822 int v7; // eax@3
2823 int v8; // ebx@4
2824 unsigned __int16 *v9; // eax@7
2825 char v10; // zf@9
2826 DWORD v11; // eax@13
2827 int v12; // eax@13
2828 int v13; // eax@14
2829 RenderBillboardTransform_local0 billboard; // [sp+4h] [bp-60h]@1
2830 int v15; // [sp+54h] [bp-10h]@13
2831 int v16; // [sp+58h] [bp-Ch]@1
2832 int v17; // [sp+5Ch] [bp-8h]@2
2833 int v18; // [sp+60h] [bp-4h]@13
2834
2835 billboard.uParentBillboardID = -1;
2836 billboard.pTarget = pRenderer->pTargetSurface;
2837 billboard.pTargetZ = pRenderer->pActiveZBuffer;
2838 billboard.uTargetPitch = pRenderer->uTargetSurfacePitch;
2839 billboard.uViewportX = pViewport->uViewportX;
2840 billboard.uViewportY = pViewport->uViewportY;
2841 billboard.uViewportZ = pViewport->uViewportZ - 1;
2842 billboard.uViewportW = pViewport->uViewportW;
2843 v0 = 0;
2844 pOutdoorCamera->uNumBillboards = uNumBillboardsToDraw;
2845 v16 = 0;
2846 if ( (signed int)uNumBillboardsToDraw > 0 )
2847 {
2848 v17 = 0;
2849 v1 = (char *)&pBillboardRenderList[0].uScreenSpaceY;
2850 do
2851 {
2852 billboard.uScreenSpaceX = *((short *)v1 - 1);
2853 v2 = *((short *)v1 - 5);
2854 billboard.uScreenSpaceY = *(short *)v1;
2855 v3 = *((int *)v1 - 10);
2856 billboard.uParentBillboardID = v0;
2857 v4 = *((int *)v1 + 1);
2858 billboard.field_10 = v3;
2859 v5 = *((int *)v1 - 9);
2860 billboard.uTintColor = v4;
2861 v6 = *((short *)v1 - 8);
2862 billboard.field_14 = v5;
2863 v7 = *((int *)v1 - 6);
2864 billboard.sZValue = *((int *)v1 - 6);
2865 billboard.uFlags = v2;
2866 if ( v6 != -1 )
2867 {
2868 v8 = *((short *)v1 + 1);
2869 if ( pRenderer->pRenderD3D )
2870 {
2871 billboard.sZValue = v7;
2872 billboard.uFlags = v2;
2873 pRenderer->TransformBillboard(
2874 &billboard,
2875 &pSprites_LOD->pHardwareSprites[v6],
2876 v8,
2877 (RenderBillboard *)(v1 - 40));
2878 }
2879 else
2880 {
2881 if ( *(v1 - 10) & 2 )
2882 v9 = PaletteManager::Get_Dark_or_Red_LUT(*((short *)v1 - 7), 0, 1);
2883 else
2884 v9 = GetBillboardPalette((RenderBillboard *)(v1 - 40), *((short *)v1 - 7), v7, *((short *)v1 + 1));
2885 v10 = (*(v1 - 9) & 1) == 0;
2886 billboard.pPalette = v9;
2887 if ( !v10 )
2888 billboard.pPalette = pPaletteManager->field_261600[*((short *)v1 - 7)];
2889 if ( !(billboard.uFlags & 0x40) && billboard.uFlags & 0x80 )
2890 {
2891 v11 = GetTickCount();
2892 v12 = stru_5C6E00->SinCos(v17 + v11);
2893 v15 = abs(v12);
2894 v18 = (unsigned __int64)(15i64 * v15) >> 16;
2895 billboard.pPalette2 = PaletteManager::Get_Dark_or_Red_LUT(*((short *)v1 - 7), 15 - v18, 1);
2896 }
2897 v13 = *((short *)v1 - 8);
2898 if ( v13 >= 0 )
2899 pSprites_LOD->pSpriteHeaders[v13]._4ACC38(&billboard, 1);
2900 }
2901 }
2902 v17 += 5;
2903 v0 = v16 + 1;
2904 v1 += 52;
2905 ++v16;
2906 }
2907 while ( v16 < (signed int)uNumBillboardsToDraw );
2908 }
2909 }
2910
2911
2912 //----- (0047AF11) --------------------------------------------------------
2913 void Render::DrawLayingItems_Shooting_Magic_ODM()
2914 {
2915 char *v0; // edi@2
2916 ObjectDesc *v1; // ebx@4
2917 __int16 v2; // cx@5
2918 RenderBillboard *v3; // esi@10
2919 SpriteFrame *v4; // eax@10
2920 SpriteFrame *v5; // ebx@10
2921 unsigned int v6; // eax@10
2922 int v7; // ecx@10
2923 int v8; // edx@10
2924 int v9; // ecx@10
2925 unsigned __int16 v10; // ax@10
2926 int *v11; // eax@14
2927 int v12; // eax@22
2928 int v13; // ST3C_4@23
2929 int v14; // eax@23
2930 int v15; // ecx@23
2931 int v16; // ebx@23
2932 int v17; // ecx@25
2933 int v18; // eax@25
2934 int v19; // ST40_4@26
2935 int v20; // ecx@26
2936 int v21; // ST44_4@28
2937 int v22; // ST3C_4@29
2938 signed __int64 v23; // qtt@30
2939 int v24; // ebx@30
2940 int v25; // ST3C_4@30
2941 int v26; // eax@31
2942 char v27; // zf@31
2943 SpriteFrame *v28; // [sp+Ch] [bp-34h]@10
2944 __int16 a5; // [sp+10h] [bp-30h]@10
2945 int v30; // [sp+14h] [bp-2Ch]@23
2946 int v31; // [sp+14h] [bp-2Ch]@29
2947 __int16 v32; // [sp+14h] [bp-2Ch]@30
2948 int v33; // [sp+18h] [bp-28h]@23
2949 int v34; // [sp+18h] [bp-28h]@26
2950 int v35; // [sp+18h] [bp-28h]@30
2951 int v36; // [sp+1Ch] [bp-24h]@10
2952 int v37; // [sp+1Ch] [bp-24h]@23
2953 int a6; // [sp+20h] [bp-20h]@10
2954 int a6a; // [sp+20h] [bp-20h]@23
2955 int v40; // [sp+24h] [bp-1Ch]@25
2956 signed int v41; // [sp+28h] [bp-18h]@1
2957 int v42; // [sp+2Ch] [bp-14h]@23
2958 int y; // [sp+30h] [bp-10h]@10
2959 int x; // [sp+34h] [bp-Ch]@10
2960 int z; // [sp+38h] [bp-8h]@10
2961 signed __int16 v46; // [sp+3Ch] [bp-4h]@12
2962
2963 v41 = 0;
2964 if ( (signed int)uNumLayingItems > 0 )
2965 {
2966 v0 = (char *)&pLayingItems[0].uSectorID;
2967 do
2968 {
2969 if ( *((short *)v0 - 13) )
2970 {
2971 v1 = &pObjectList->pObjects[*((short *)v0 - 13)];
2972 if ( !(v1->uFlags & 1) )
2973 {
2974 if ( ((v2 = *((short *)v0 - 14), v2 < 1000) || v2 >= 10000) && (v2 < 500 || v2 >= 600)
2975 || pGame->pStru6Instance->_4A81CA((LayingItem *)(v0 - 28)) )
2976 {
2977 a5 = *(short *)v0;
2978 x = *((int *)v0 - 6);
2979 y = *((int *)v0 - 5);
2980 z = *((int *)v0 - 4);
2981 v3 = &pBillboardRenderList[uNumBillboardsToDraw];
2982 v4 = pSpriteFrameTable->GetFrame(v1->uSpriteID, *((short *)v0 + 1));
2983 v5 = v4;
2984 v28 = v4;
2985 v36 = v4->uFlags;
2986 a6 = v4->uGlowRadius * *((short *)v0 + 3);
2987 v6 = stru_5C6E00->Atan2(
2988 *((int *)v0 - 6) - pIndoorCamera->pos.x,
2989 *((int *)v0 - 5) - pIndoorCamera->pos.y);
2990 LOWORD(v7) = *((short *)v0 - 3);
2991 v8 = v36;
2992 v9 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v7 - v6) >> 8) & 7;
2993 v10 = v5->pHwSpriteIDs[v9];
2994 v3->uHwSpriteID = v10;
2995 if ( v36 & 0x20 )
2996 {
2997 v8 = v36;
2998 z -= (signed int)((unsigned __int64)(v5->scale
2999 * (signed __int64)pSprites_LOD->pSpriteHeaders[(signed __int16)v10].uHeight) >> 16) >> 1;
3000 }
3001 v46 = 0;
3002 if ( v8 & 2 )
3003 v46 = 2;
3004 v11 = (int *)(256 << v9);
3005 if ( (256 << v9) & v8 )
3006 v46 |= 4u;
3007 if ( v8 & 0x40000 )
3008 v46 |= 0x40u;
3009 if ( v8 & 0x20000 )
3010 LOBYTE(v46) = v46 | 0x80;
3011 if ( a6 )
3012 {
3013 LOBYTE(v11) = byte_4E94D3;
3014 pMobileLightsStack->AddLight(x, y, z, a5, a6, 0xFFu, 0xFFu, 0xFFu, byte_4E94D3);
3015 }
3016 v12 = (x - pIndoorCamera->pos.x) << 16;
3017 if ( pIndoorCamera->sRotationX )
3018 {
3019 v13 = (y - pIndoorCamera->pos.y) << 16;
3020 v30 = ((unsigned __int64)(v12 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16)
3021 + ((unsigned __int64)(v13 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16);
3022 v37 = (unsigned __int64)(v12 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
3023 a6a = (unsigned __int64)(v13 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16;
3024 v33 = (z - pIndoorCamera->pos.z) << 16;
3025 v14 = (unsigned __int64)(v30 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16;
3026 v15 = (unsigned __int64)(v33 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16;
3027 v16 = v15 + v14;
3028 v42 = v15 + v14;
3029 if ( v15 + v14 >= 262144 && v16 <= pOutdoorCamera->shading_dist_mist << 16 )
3030 {
3031 v17 = a6a - v37;
3032 v40 = a6a - v37;
3033 v18 = ((unsigned __int64)(v33 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16)
3034 - ((unsigned __int64)(v30 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16);
3035 goto LABEL_29;
3036 }
3037 }
3038 else
3039 {
3040 v34 = (y - pIndoorCamera->pos.y) << 16;
3041 v19 = (unsigned __int64)(v12 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16;
3042 v20 = (unsigned __int64)(v34 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
3043 v16 = v20 + v19;
3044 v42 = v20 + v19;
3045 if ( v20 + v19 >= 262144 && v16 <= pOutdoorCamera->shading_dist_mist << 16 )
3046 {
3047 v21 = (unsigned __int64)(((x - pIndoorCamera->pos.x) << 16)
3048 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
3049 v17 = ((unsigned __int64)(v34 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16)
3050 - v21;
3051 v40 = ((unsigned __int64)(v34 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16)
3052 - v21;
3053 v18 = (z - pIndoorCamera->pos.z) << 16;
3054 LABEL_29:
3055 v31 = v18;
3056 v22 = abs(v17);
3057 if ( abs(v16) >= v22 )
3058 {
3059 LODWORD(v23) = 0;
3060 HIDWORD(v23) = SLOWORD(pOutdoorCamera->int_fov_rad);
3061 v24 = v23 / v42;
3062 v25 = v23 / v42;
3063 LODWORD(v23) = 0;
3064 HIDWORD(v23) = SLOWORD(pOutdoorCamera->int_fov_rad);
3065 v35 = pViewport->uScreenCenterX
3066 - ((signed int)(((unsigned __int64)(v25 * (signed __int64)v40) >> 16) + 32768) >> 16);
3067 v32 = LOWORD(pViewport->uScreenCenterY)
3068 - (((unsigned int)((unsigned __int64)(v23 / v42 * v31) >> 16) + 32768) >> 16);
3069 if ( (signed int)uNumBillboardsToDraw >= 500 )
3070 return;
3071 ++uNumBillboardsToDraw;
3072 ++uNumSpritesDrawnThisFrame;
3073 *(v0 - 2) |= 1u;
3074 v3->uPalette = v28->uPaletteIndex;
3075 v3->uIndoorSectorID = a5;
3076 v3->field_0 = (unsigned __int64)(v28->scale * (signed __int64)v24) >> 16;
3077 v26 = (unsigned __int64)(v28->scale * (signed __int64)v24) >> 16;
3078 v3->pSpriteFrame = v28;
3079 v3->field_4 = v26;
3080 v3->field_1E = v46;
3081 v3->some_x = x;
3082 v3->some_y = y;
3083 v3->some_z = z;
3084 v3->uScreenSpaceX = v35;
3085 v3->uScreenSpaceY = v32;
3086 HIWORD(v26) = HIWORD(v42);
3087 LOWORD(v26) = 0;
3088 v27 = (*(v0 - 2) & 0x20) == 0;
3089 v3->sZValue = v26 + (8 * v41 | 2);
3090 v3->uPaletteSubindex = 0;
3091 v3->uTintColor = 0;
3092 if ( !v27 )
3093 {
3094 if ( !pRenderer->pRenderD3D )
3095 v3->sZValue = 0;
3096 }
3097 }
3098 goto LABEL_34;
3099 }
3100 }
3101 }
3102 }
3103 }
3104 LABEL_34:
3105 ++v41;
3106 v0 += 112;
3107 }
3108 while ( v41 < (signed int)uNumLayingItems );
3109 }
3110 }
3111 // 4E94D3: using guessed type char byte_4E94D3;
3112 // 5187E4: using guessed type int uNumSpritesDrawnThisFrame;
3113
3114
3115 //----- (0049D9BC) --------------------------------------------------------
3116 signed int __stdcall RenderD3D__DeviceEnumerator(GUID *lpGUID, const char *lpDevDesc, const char *lpDriverName, RenderD3D__DevInfo *pOut)
3117 {
3118 size_t v4; // eax@1
3119 size_t v5; // eax@1
3120 IUnknown *v6; // eax@10
3121 size_t v7; // eax@13
3122 DDDEVICEIDENTIFIER ddDevId; // [sp+4h] [bp-4F8h]@11
3123 DDSURFACEDESC2 v10;/*int v10; // [sp+42Ch] [bp-D0h]@16
3124 int v11; // [sp+430h] [bp-CCh]@16
3125 int v12; // [sp+434h] [bp-C8h]@16
3126 int v13; // [sp+438h] [bp-C4h]@16
3127 int v14; // [sp+474h] [bp-88h]@16*/
3128 DDSCAPS2 ddsCaps; // [sp+4A8h] [bp-54h]@14
3129 unsigned int uFreeVideoMem; // [sp+4B8h] [bp-44h]@14
3130 RenderD3D_aux aux; // [sp+4BCh] [bp-40h]@19
3131 IDirect3D3 *pDirect3D3; // [sp+4C4h] [bp-38h]@18
3132 int v19; // [sp+4C8h] [bp-34h]@16
3133 RenderD3D_D3DDevDesc v20; // [sp+4CCh] [bp-30h]@1
3134 LPDIRECTDRAW pDirectDraw; // [sp+4F4h] [bp-8h]@4
3135 IDirectDraw4 *pDirectDraw4; // [sp+4F8h] [bp-4h]@7
3136
3137 v4 = strlen(lpDriverName);
3138 v20.pDriverName = new char[v4 + 1];
3139 v5 = strlen(lpDevDesc);
3140 v20.pDeviceDesc = new char[v5 + 1];
3141 strcpy(v20.pDriverName, lpDriverName);
3142 strcpy(v20.pDeviceDesc, lpDevDesc);
3143 if ( lpGUID )
3144 {
3145 v20.pGUID = new GUID;
3146 memcpy(v20.pGUID, lpGUID, 0x10u);
3147 }
3148 else
3149 {
3150 v20.pGUID = 0;
3151 }
3152
3153 if (FAILED(DirectDrawCreate(v20.pGUID, &pDirectDraw, 0)))
3154 {
3155 delete [] v20.pDriverName;
3156 delete [] v20.pDeviceDesc;
3157 if ( v20.pGUID )
3158 delete v20.pGUID;
3159 }
3160 else
3161 {
3162 if (FAILED(pDirectDraw->QueryInterface(IID_IDirectDraw4, (LPVOID *)&pDirectDraw4)))
3163 {
3164 delete [] v20.pDriverName;
3165 delete [] v20.pDeviceDesc;
3166 if ( v20.pGUID )
3167 delete v20.pGUID;
3168 v6 = (IUnknown *)pDirectDraw;
3169 }
3170 else
3171 {
3172 pDirectDraw->Release();
3173 if (FAILED( pDirectDraw4->GetDeviceIdentifier(&ddDevId, 1u)))
3174 {
3175 v20.pDDraw4DevDesc = 0;
3176 }
3177 else
3178 {
3179 v7 = strlen(ddDevId.szDescription);
3180 v20.pDDraw4DevDesc = new char[v7 + 1];
3181 strcpy(v20.pDDraw4DevDesc, ddDevId.szDescription);
3182 }
3183 memset(&ddsCaps, 0, 0x10u);
3184 if (FAILED(pDirectDraw4->GetAvailableVidMem(
3185 &ddsCaps,
3186 (LPDWORD)&v20.uVideoMem,
3187 (LPDWORD)&uFreeVideoMem)))
3188 v20.uVideoMem = 0;
3189 memset(&v10, 0, 0x7Cu);
3190 v10.dwSize = 124;
3191 v10.dwFlags = 6;
3192 v10.dwHeight = 640;
3193 v10.dwWidth = 480;
3194 v10.ddpfPixelFormat.dwSize = 32;
3195
3196 v19 = 0;
3197 if ( FAILED(pDirectDraw4->EnumDisplayModes(
3198 0,
3199 0,
3200 &v19,
3201 (LPDDENUMMODESCALLBACK2)DDrawDisplayModesEnumerator))
3202 || !v19
3203 || FAILED(pDirectDraw4->QueryInterface(IID_IDirect3D3, (LPVOID *)&pDirect3D3)))
3204 {
3205 delete [] v20.pDriverName;
3206 delete [] v20.pDeviceDesc;
3207 if ( v20.pDDraw4DevDesc )
3208 free(v20.pDDraw4DevDesc);
3209 if ( v20.pGUID )
3210 delete v20.pGUID;
3211 v6 = (IUnknown *)pDirectDraw4;
3212 }
3213 else
3214 {
3215 aux.pInfo = pOut;
3216 aux.ptr_4 = &v20;
3217 pDirect3D3->EnumDevices((LPD3DENUMDEVICESCALLBACK)D3DDeviceEnumerator, &aux);
3218 delete [] v20.pDriverName;
3219 delete [] v20.pDeviceDesc;
3220 if ( v20.pDDraw4DevDesc )
3221 free(v20.pDDraw4DevDesc);
3222 if ( v20.pGUID )
3223 delete v20.pGUID;
3224 pDirectDraw4->Release();
3225 v6 = (IUnknown *)pDirect3D3;
3226 pDirectDraw4 = 0;
3227 }
3228 }
3229 v6->Release();
3230 }
3231 return 1;
3232 }
3233
3234
3235 //----- (0049D784) --------------------------------------------------------
3236 HRESULT __stdcall D3DDeviceEnumerator(const GUID *lpGUID, const char *lpDeviceDesc, const char *lpDeviceName, D3DDEVICEDESC *pHWDesc, D3DDEVICEDESC *pSWDesc, RenderD3D_aux *a6)
3237 {
3238 int v6; // eax@1
3239 signed int v7; // edi@1
3240 signed int v8; // edi@14
3241 size_t v9; // eax@30
3242 size_t v10; // eax@30
3243 size_t v11; // eax@30
3244 size_t v12; // eax@30
3245 size_t v13; // eax@30
3246
3247 v6 = pHWDesc->dwFlags;
3248 v7 = -1;
3249 if ( v6 )
3250 {
3251 if ( !a6->ptr_4->pGUID )
3252 v7 = 0;
3253 if ( v6 && a6->ptr_4->pGUID )
3254 v7 = 1;
3255 }
3256 if ( !strcmp(lpDeviceName, "RGB Emulation") && !a6->ptr_4->pGUID )
3257 v7 = 2;
3258 if ( !strcmp(lpDeviceName, "Reference Rasterizer") && !a6->ptr_4->pGUID )
3259 v7 = 3;
3260 if ( v7 != -1 )
3261 {
3262 v8 = v7;
3263 a6->pInfo[v8].bIsDeviceCompatible = 1;
3264 a6->pInfo[v8].uCaps = 0;
3265 if ( !(pHWDesc->dpcTriCaps.dwSrcBlendCaps & 0x10) )
3266 a6->pInfo[v8].uCaps |= 2u;
3267 if ( !(pHWDesc->dpcTriCaps.dwSrcBlendCaps & 2) )
3268 a6->pInfo[v8].uCaps |= 4u;
3269 if ( !(pHWDesc->dpcTriCaps.dwSrcBlendCaps & 1) )
3270 a6->pInfo[v8].uCaps |= 8u;
3271 if ( !(pHWDesc->dpcTriCaps.dwDestBlendCaps & 0x20) )
3272 a6->pInfo[v8].uCaps |= 0x10u;
3273 if ( !(pHWDesc->dpcTriCaps.dwDestBlendCaps & 2) )
3274 a6->pInfo[v8].uCaps |= 0x20u;
3275 if ( !(pHWDesc->dpcTriCaps.dwDestBlendCaps & 4) )
3276 a6->pInfo[v8].uCaps |= 0x40u;
3277 if ( !(BYTE1(pHWDesc->dwDevCaps) & 0x10) )
3278 BYTE1(a6->pInfo[v8].uCaps) |= 1u;
3279 if ( pHWDesc->dpcTriCaps.dwTextureCaps & 0x20 )
3280 LOBYTE(a6->pInfo[v8].uCaps) |= 0x80u;
3281 v9 = strlen(lpDeviceName);
3282 a6->pInfo[v8].pName = new char[v9 + 1];
3283 strcpy(a6->pInfo[v8].pName, lpDeviceName);
3284 v10 = strlen(lpDeviceDesc);
3285 a6->pInfo[v8].pDescription = new char[v10 + 1];
3286 strcpy(a6->pInfo[v8].pDescription, lpDeviceDesc);
3287 a6->pInfo[v8].pGUID = (GUID *)operator new(0x10u);
3288 memcpy(a6->pInfo[v8].pGUID, lpGUID, 0x10u);
3289 v11 = strlen(a6->ptr_4->pDriverName);
3290 a6->pInfo[v8].pDriverName = new char[v11 + 1];
3291 strcpy(a6->pInfo[v8].pDriverName, a6->ptr_4->pDriverName);
3292 v12 = strlen(a6->ptr_4->pDeviceDesc);
3293 a6->pInfo[v8].pDeviceDesc = new char[v12 + 1];
3294 strcpy(a6->pInfo[v8].pDeviceDesc, a6->ptr_4->pDeviceDesc);
3295 v13 = strlen(a6->ptr_4->pDDraw4DevDesc);
3296 a6->pInfo[v8].pDDraw4DevDesc = new char[v13 + 1];
3297 strcpy(a6->pInfo[v8].pDDraw4DevDesc, a6->ptr_4->pDDraw4DevDesc);
3298 if ( a6->ptr_4->pGUID )
3299 {
3300 a6->pInfo[v8].pDirectDrawGUID = new GUID;
3301 memcpy(a6->pInfo[v8].pDirectDrawGUID, a6->ptr_4->pGUID, 0x10u);
3302 }
3303 else
3304 {
3305 a6->pInfo[v8].pDirectDrawGUID = 0;
3306 }
3307 a6->pInfo[v8].uVideoMem = a6->ptr_4->uVideoMem;
3308 }
3309 return 1;
3310 }
3311
3312
3313 //----- (0049D75C) --------------------------------------------------------
3314 HRESULT __stdcall DDrawDisplayModesEnumerator(DDSURFACEDESC2 *pSurfaceDesc, __int16 *a2)
3315 {
3316 HRESULT result; // eax@3
3317
3318 if ( pSurfaceDesc->ddsCaps.dwCaps | 0x2000 && pSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 16 )
3319 {
3320 *a2 = 1;
3321 result = 0;
3322 }
3323 else
3324 {
3325 result = 1;
3326 }
3327 return result;
3328 }
3329
3330
3331
3332 //----- (0047A95E) --------------------------------------------------------
3333 void Render::DrawDecorations()
3334 {
3335 char *v0; // esi@2
3336 DecorationDesc *v1; // ebx@6
3337 __int16 v2; // ax@6
3338 double v3; // st7@7
3339 int v4; // eax@9
3340 int v5; // edx@9
3341 unsigned int v6; // edi@9
3342 int v7; // eax@9
3343 SpriteFrame *v8; // eax@9
3344 SpriteFrame *v9; // edi@9
3345 unsigned __int16 *v10; // eax@9
3346 int v11; // ecx@9
3347 int v12; // eax@9
3348 int v13; // ecx@9
3349 int v14; // ecx@20
3350 char v15; // dl@20
3351 signed int v16; // eax@20
3352 int v17; // eax@23
3353 int v18; // ecx@24
3354 int v19; // eax@24
3355 int v20; // ecx@24
3356 int v21; // ebx@26
3357 int v22; // eax@26
3358 int v23; // eax@30
3359 signed __int64 v24; // qtt@31
3360 int v25; // ebx@31
3361 int v26; // ecx@32
3362 RenderBillboard *v27; // eax@37
3363 __int16 v28; // dx@37
3364 __int16 v29; // cx@37
3365 int v30; // ecx@37
3366 int v31; // ebx@37
3367 Particle_ local_0; // [sp+Ch] [bp-98h]@7
3368 int x; // [sp+74h] [bp-30h]@9
3369 int y; // [sp+78h] [bp-2Ch]@9
3370 int v35; // [sp+7Ch] [bp-28h]@1
3371 int v36; // [sp+80h] [bp-24h]@9
3372 unsigned __int16 *v37; // [sp+84h] [bp-20h]@9
3373 int v38; // [sp+88h] [bp-1Ch]@9
3374 int v39; // [sp+8Ch] [bp-18h]@24
3375 int v40; // [sp+90h] [bp-14h]@24
3376 int v41; // [sp+94h] [bp-10h]@24
3377 int v42; // [sp+98h] [bp-Ch]@9
3378 int a5; // [sp+9Ch] [bp-8h]@9
3379 int b; // [sp+A0h] [bp-4h]@22
3380
3381 v35 = 0;
3382 if ( (signed int)uNumLevelDecorations > 0 )
3383 {
3384 v0 = (char *)&pLevelDecorations[0].vPosition.y;
3385 do
3386 {
3387 if ( (!(*(v0 - 6) & 0x40) || ((LevelDecoration *)(v0 - 8))->_47A825()) && !(*(v0 - 6) & 0x20) )
3388 {
3389 v1 = &pDecorationList->pDecorations[*((short *)v0 - 4)];
3390 v2 = v1->uFlags;
3391 if ( (char)v2 >= 0 )
3392 {
3393 if ( !(v2 & 0x22) )
3394 {
3395 v4 = *((int *)v0 - 1);
3396 v5 = *((int *)v0 + 1);
3397 v6 = pMiscTimer->uTotalGameTimeElapsed;
3398 y = *(int *)v0;
3399 x = v4;
3400 v36 = v5;
3401 v7 = abs(v4 + y);
3402 v8 = pSpriteFrameTable->GetFrame(v1->uSpriteID, v6 + v7);
3403 v9 = v8;
3404 v42 = v8->uFlags;
3405 a5 = v8->uGlowRadius;
3406 v10 = (unsigned __int16 *)stru_5C6E00->Atan2(
3407 *((int *)v0 - 1) - pIndoorCamera->pos.x,
3408 *(int *)v0 - pIndoorCamera->pos.y);
3409 v11 = *((int *)v0 + 2);
3410 v37 = v10;
3411 v12 = v42;
3412 v38 = 0;
3413 v13 = ((signed int)(stru_5C6E00->uIntegerPi
3414 + ((signed int)stru_5C6E00->uIntegerPi >> 3)
3415 + v11
3416 - (signed int)v37) >> 8) & 7;
3417 v37 = (unsigned __int16 *)v13;
3418 if ( v42 & 2 )
3419 v38 = 2;
3420 if ( (256 << v13) & v42 )
3421 v38 |= 4u;
3422 if ( v12 & 0x40000 )
3423 v38 |= 0x40u;
3424 if ( v12 & 0x20000 )
3425 LOBYTE(v38) = v38 | 0x80;
3426 if ( a5 )
3427 {
3428 if ( pRenderer->pRenderD3D && pRenderer->bUseColoredLights )
3429 {
3430 v14 = v1->uColoredLightRed;
3431 v15 = v1->uColoredLightGreen;
3432 v16 = v1->uColoredLightBlue;
3433 }
3434 else
3435 {
3436 v16 = 255;
3437 v14 = 255;
3438 v15 = 255;
3439 }
3440 b = v16;
3441 pStationaryLightsStack->AddLight(
3442 x,
3443 y,
3444 v36 + v1->uDecorationHeight / 2,
3445 a5,
3446 v14,
3447 v15,
3448 v16,
3449 byte_4E94D0);
3450 }
3451 v17 = (x - pIndoorCamera->pos.x) << 16;
3452 if ( pIndoorCamera->sRotationX )
3453 {
3454 v40 = (y - pIndoorCamera->pos.y) << 16;
3455 v18 = ((unsigned __int64)(v17 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16)
3456 + ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16);
3457 v42 = v18;
3458 b = (unsigned __int64)(v17 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
3459 a5 = (unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16;
3460 v40 = (v36 - pIndoorCamera->pos.z) << 16;
3461 v41 = (unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16;
3462 v19 = (unsigned __int64)(v18 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16;
3463 v20 = v19 + ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16);
3464 v39 = v19 + ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16);
3465 if ( v20 >= 262144 && v20 <= pOutdoorCamera->shading_dist_mist << 16 )
3466 {
3467 v21 = a5 - b;
3468 v41 = a5 - b;
3469 a5 = (unsigned __int64)(v42 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_sine) >> 16;
3470 b = (unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16;
3471 v22 = ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_x_int_cosine) >> 16) - a5;
3472 LABEL_30:
3473 v42 = v22;
3474 v40 = 2 * abs(v20);
3475 v23 = abs(v21);
3476 if ( v40 >= v23 )
3477 {
3478 LODWORD(v24) = 0;
3479 HIDWORD(v24) = SLOWORD(pOutdoorCamera->int_fov_rad);
3480 a5 = v24 / v39;
3481 v25 = pViewport->uScreenCenterX
3482 - ((signed int)(((unsigned __int64)(v24 / v39 * v41) >> 16) + 32768) >> 16);
3483 b = (unsigned __int64)(a5 * (signed __int64)v42) >> 16;
3484 v41 = v24 / v39;
3485 v40 = pViewport->uScreenCenterY
3486 - ((signed int)(((unsigned __int64)(a5 * (signed __int64)v42) >> 16) + 32768) >> 16);
3487 v42 = v9->scale;
3488 v41 = (unsigned __int64)(v42 * v24 / v39) >> 16;
3489 v37 = (unsigned __int16 *)&v9->pHwSpriteIDs[(int)v37];
3490 if ( pRenderer->pRenderD3D )
3491 {
3492 v26 = v41;
3493 v42 = pSprites_LOD->pHardwareSprites[(signed __int16)*v37].uBufferWidth >> 1;
3494 b = (unsigned __int64)(v42 * (signed __int64)v41) >> 16;
3495 }
3496 else
3497 {
3498 v26 = v41;
3499 v42 = pSprites_LOD->pSpriteHeaders[(signed __int16)*v37].uWidth >> 1;
3500 b = (unsigned __int64)(v42 * (signed __int64)v41) >> 16;
3501 }
3502 if ( b + v25 >= (signed int)pViewport->uViewportX && v25 - b <= (signed int)pViewport->uViewportZ )
3503 {
3504 if ( (signed int)uNumBillboardsToDraw >= 500 )
3505 return;
3506 v27 = &pBillboardRenderList[uNumBillboardsToDraw++];
3507 ++uNumDecorationsDrawnThisFrame;
3508 v27->uHwSpriteID = *v37;
3509 v28 = v9->uPaletteIndex;
3510 v27->field_0 = v26;
3511 v27->field_4 = v26;
3512 v29 = v38;
3513 v27->uScreenSpaceX = v25;
3514 HIBYTE(v29) |= 2u;
3515 v27->uPalette = v28;
3516 v27->field_1E = v29;
3517 v27->some_x = x;
3518 v27->some_y = y;
3519 v27->some_z = v36;
3520 v27->uScreenSpaceY = v40;
3521 HIWORD(v30) = HIWORD(v39);
3522 v31 = 8 * v35 | 5;
3523 LOWORD(v30) = 0;
3524 v27->uIndoorSectorID = 0;
3525 v27->sZValue = v30 + v31;
3526 v27->uPaletteSubindex = 0;
3527 v27->pSpriteFrame = v9;
3528 v27->uTintColor = 0;
3529 }
3530 }
3531 goto LABEL_38;
3532 }
3533 }
3534 else
3535 {
3536 v42 = (x - pIndoorCamera->pos.x) << 16;
3537 v40 = (y - pIndoorCamera->pos.y) << 16;
3538 b = (unsigned __int64)(v17 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16;
3539 a5 = (unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
3540 v20 = b + ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16);
3541 v39 = b + ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16);
3542 if ( v20 >= 262144 && v20 <= pOutdoorCamera->shading_dist_mist << 16 )
3543 {
3544 a5 = (unsigned __int64)(v42 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_sine) >> 16;
3545 b = (unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16;
3546 v21 = ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16) - a5;
3547 v41 = ((unsigned __int64)(v40 * (signed __int64)pOutdoorCamera->camera_rotation_y_int_cosine) >> 16) - a5;
3548 v22 = (v36 - pIndoorCamera->pos.z) << 16;
3549 goto LABEL_30;
3550 }
3551 }
3552 }
3553 }
3554 else
3555 {
3556 memset(&local_0, 0, 0x68u);
3557 v3 = (double)*((signed int *)v0 - 1);
3558 local_0.bFree = 1036;
3559 local_0.uDiffuse = 0xFF3C1Eu;
3560 local_0.x = v3;
3561 local_0.y = (double)*(signed int *)v0;
3562 local_0.z = (double)*((signed int *)v0 + 1);
3563 local_0.flt_10 = 0.0;
3564 local_0.flt_14 = 0.0;
3565 local_0.flt_18 = 0.0;
3566 local_0.flt_28 = 1.0;
3567 local_0.timeToLive = (rand() & 0x80) + 128;
3568 local_0.uTextureID = pBitmaps_LOD->LoadTexture("effpar01");
3569 pGame->pParticleEngine->AddParticle(&local_0);
3570 }
3571 }
3572 LABEL_38:
3573 ++v35;
3574 v0 += 32;
3575 }
3576 while ( v35 < (signed int)uNumLevelDecorations );
3577 }
3578 }
3579 // 4E94D0: using guessed type char byte_4E94D0;
3580 // 5187EC: using guessed type int uNumDecorationsDrawnThisFrame;
3581
3582
3583 //----- (0049D717) --------------------------------------------------------
3584 HRESULT __stdcall D3DZBufferFormatEnumerator(DDPIXELFORMAT *Src, DDPIXELFORMAT *Dst)
3585 {
3586 HRESULT v2; // esi@2
3587
3588 if ( Src->dwFlags & 0x400 | 0x2000 )
3589 {
3590 v2 = 0;
3591 if ( Src->dwRGBBitCount == 16 && !Src->dwRBitMask )
3592 goto LABEL_6;
3593 if ( !Dst->dwSize )
3594 {
3595 v2 = 1;
3596 LABEL_6:
3597 memcpy(Dst, Src, 0x20u);
3598 return v2;
3599 }
3600 }
3601 return 1;
3602 }
3603
3604 //----- (0049DC28) --------------------------------------------------------
3605 void RenderD3D::GetAvailableDevices(RenderD3D__DevInfo **pOutDevices)
3606 {
3607 RenderD3D__DevInfo *v2; // eax@1
3608
3609 v2 = new RenderD3D__DevInfo[4];// 4 items
3610 *pOutDevices = v2;
3611 memset(v2, 0, 0xA0u);
3612 DirectDrawEnumerateA((LPDDENUMCALLBACKA)RenderD3D__DeviceEnumerator, *pOutDevices);
3613 }
3614
3615
3616 //----- (0049DC58) --------------------------------------------------------
3617 RenderD3D::RenderD3D()
3618 {
3619 RenderD3D *v1; // esi@1
3620
3621 v1 = this;
3622 this->pHost = 0;
3623 this->pDirect3D = 0;
3624 this->pUnk = 0;
3625 this->pBackBuffer = 0;
3626 this->pFrontBuffer = 0;
3627 this->pZBuffer = 0;
3628 this->pDevice = 0;
3629 this->pViewport = 0;
3630 this->field_40 = 1;
3631 this->field_44 = 10;
3632 GetAvailableDevices(&this->pAvailableDevices);
3633 }
3634
3635 //----- (0049DC90) --------------------------------------------------------
3636 void RenderD3D::Release()
3637 {
3638 RenderD3D *v1; // esi@1
3639 IDirectDraw4 *v2; // eax@2
3640 signed int v3; // edi@4
3641 IDirect3DViewport3 *v4; // eax@22
3642 IUnknown *v5; // eax@24
3643 IDirectDrawSurface4 *v6; // eax@26
3644 IDirect3DDevice3 *v7; // eax@28
3645 IDirect3D3 *v8; // eax@30
3646 IDirectDrawSurface4 *v9; // eax@32
3647 IDirectDrawSurface4 *v10; // eax@34
3648 IDirectDraw4 *v11; // eax@36
3649
3650 v1 = this;
3651 if ( !this->bWindowed )
3652 {
3653 v2 = this->pHost;
3654 if ( v2 )
3655 {
3656 v2->RestoreDisplayMode();
3657 v1->pHost->SetCooperativeLevel(v1->hWindow, 8u);
3658 v1->pHost->FlipToGDISurface();
3659 }
3660 }
3661 v3 = 0;
3662 do
3663 {
3664 if ( v1->pAvailableDevices[v3].pDriverName )
3665 {
3666 free(v1->pAvailableDevices[v3].pDriverName);
3667 v1->pAvailableDevices[v3].pDriverName = 0;
3668 }
3669 if ( v1->pAvailableDevices[v3].pDeviceDesc )
3670 {
3671 free(v1->pAvailableDevices[v3].pDeviceDesc);
3672 v1->pAvailableDevices[v3].pDeviceDesc = 0;
3673 }
3674 if ( v1->pAvailableDevices[v3].pDDraw4DevDesc )
3675 {
3676 free(v1->pAvailableDevices[v3].pDDraw4DevDesc);
3677 v1->pAvailableDevices[v3].pDDraw4DevDesc = 0;
3678 }
3679 if ( v1->pAvailableDevices[v3].pDirectDrawGUID )
3680 {
3681 free(v1->pAvailableDevices[v3].pDirectDrawGUID);
3682 v1->pAvailableDevices[v3].pDirectDrawGUID = 0;
3683 }
3684 if ( v1->pAvailableDevices[v3].pName )
3685 {
3686 free(v1->pAvailableDevices[v3].pName);
3687 v1->pAvailableDevices[v3].pName = 0;
3688 }
3689 if ( v1->pAvailableDevices[v3].pDescription )
3690 {
3691 free(v1->pAvailableDevices[v3].pDescription);
3692 v1->pAvailableDevices[v3].pDescription = 0;
3693 }
3694 if ( v1->pAvailableDevices[v3].pGUID )
3695 {
3696 free(v1->pAvailableDevices[v3].pGUID);
3697 v1->pAvailableDevices[v3].pGUID = 0;
3698 }
3699 ++v3;
3700 }
3701 while ( v3 < 4 );
3702 if ( v1->pAvailableDevices )
3703 {
3704 free(v1->pAvailableDevices);
3705 v1->pAvailableDevices = 0;
3706 }
3707 v4 = v1->pViewport;
3708 if ( v4 )
3709 {
3710 v4->Release();
3711 v1->pViewport = 0;
3712 }
3713 v5 = v1->pUnk;
3714 if ( v5 )
3715 {
3716 v5->Release();
3717 v1->pUnk = 0;
3718 }
3719 v6 = v1->pZBuffer;
3720 if ( v6 )
3721 {
3722 v6->Release();
3723 v1->pZBuffer = 0;
3724 }
3725 v7 = v1->pDevice;
3726 if ( v7 )
3727 {
3728 v7->Release();
3729 v1->pDevice = 0;
3730 }
3731 v8 = v1->pDirect3D;
3732 if ( v8 )
3733 {
3734 v8->Release();
3735 v1->pDirect3D = 0;
3736 }
3737 v9 = v1->pBackBuffer;
3738 if ( v9 )
3739 {
3740 v9->Release();
3741 v1->pBackBuffer = 0;
3742 }
3743 v10 = v1->pFrontBuffer;
3744 if ( v10 )
3745 {
3746 v10->Release();
3747 v1->pFrontBuffer = 0;
3748 }
3749 v11 = v1->pHost;
3750 if ( v11 )
3751 {
3752 v11->Release();
3753 v1->pHost = 0;
3754 }
3755 }
3756
3757
3758 //----- (0049DE14) --------------------------------------------------------
3759 bool RenderD3D::CreateDevice(unsigned int uDeviceID, int bWindowed, HWND hWnd)
3760 {
3761 //IDirectDraw4 *v8; // eax@12
3762 //IDirectDraw4 *v9; // eax@16
3763 //IDirectDraw4 *v10; // eax@20
3764 //IDirectDraw4 *v13; // eax@35
3765 const char *v23; // [sp-4h] [bp-DCh]@9
3766 const char *v24; // [sp-4h] [bp-DCh]@13
3767 const char *v25; // [sp-4h] [bp-DCh]@19
3768 DWORD v26; // [sp-4h] [bp-DCh]@30
3769 DDSCAPS2 v27; // [sp+Ch] [bp-CCh]@37
3770 DDSURFACEDESC2 ddsd2; // [sp+1Ch] [bp-BCh]@11
3771 D3DVIEWPORT2 d3dvp2; // [sp+98h] [bp-40h]@28
3772 IDirectDrawClipper *v30; // [sp+C4h] [bp-14h]@18
3773 LPDIRECTDRAW lpDD; // [sp+C8h] [bp-10h]@1
3774
3775 this->bWindowed = bWindowed;
3776 this->hWindow = hWnd;
3777
3778 if (FAILED(DirectDrawCreate(pAvailableDevices[uDeviceID].pDirectDrawGUID, &lpDD, 0)))
3779 {
3780 sprintf(pErrorMessage, "Init - Failed to create DirectDraw interface.\n");
3781 return 0;
3782 }
3783
3784 if (FAILED(lpDD->QueryInterface(IID_IDirectDraw4, (LPVOID *)&pHost)))
3785 {
3786 sprintf(pErrorMessage, "Init - Failed to create DirectDraw4 interface.\n");
3787 if (lpDD)
3788 lpDD->Release();
3789 return 0;
3790 }
3791 lpDD->Release();
3792 lpDD = 0;
3793
3794 if (bWindowed && !pAvailableDevices[uDeviceID].pDirectDrawGUID)
3795 {
3796 if (FAILED(pHost->SetCooperativeLevel(hWnd, DDSCL_MULTITHREADED | DDSCL_NORMAL)))
3797 {
3798 v23 = "Init - Failed to set cooperative level.\n";
3799 sprintf(pErrorMessage, v23);
3800 LABEL_65:
3801 if (pHost)
3802 {
3803 pHost->Release();
3804 pHost = 0;
3805 }
3806 return 0;
3807 }
3808 memset(&ddsd2, 0, sizeof(DDSURFACEDESC2));
3809 ddsd2.dwSize = sizeof(DDSURFACEDESC2);
3810 ddsd2.dwFlags = DDSD_CAPS;
3811 ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3812 if ( !pHost->CreateSurface(&ddsd2, &pFrontBuffer, 0) )
3813 {
3814 ddsd2.dwSize = sizeof(DDSURFACEDESC2);
3815 pHost->GetDisplayMode(&ddsd2);
3816 if ( ddsd2.ddpfPixelFormat.dwRGBBitCount != 16 )
3817 {
3818 v24 = "Init - Desktop isn't in 16 bit mode.\n";
3819 goto LABEL_14;
3820 }
3821
3822 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3823 ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3824 ddsd2.dwWidth = 640;
3825 ddsd2.dwHeight = 480;
3826 if (pHost->CreateSurface(&ddsd2, &pBackBuffer, 0) )
3827 {
3828 v24 = "Init - Failed to create back buffer.\n";
3829 LABEL_14:
3830 sprintf(pErrorMessage, v24);
3831 if (pFrontBuffer)
3832 {
3833 pFrontBuffer->Release();
3834 pFrontBuffer = 0;
3835 }
3836 goto LABEL_65;
3837 }
3838 if ( pHost->CreateClipper(0, &v30, 0) )
3839 {
3840 v25 = "Init - Failed to create clipper.\n";
3841 goto LABEL_45;
3842 }
3843 v30->SetHWnd(0, hWnd);
3844 pFrontBuffer->SetClipper(v30);
3845
3846 v30->Release();
3847 v30 = 0;
3848
3849 pHost->QueryInterface(IID_IDirect3D3, (LPVOID *)&pDirect3D);
3850
3851 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
3852 ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
3853 ddsd2.dwWidth = 640;
3854 ddsd2.dwHeight = 480;
3855
3856 if ( pDirect3D->EnumZBufferFormats(*pAvailableDevices[uDeviceID].pGUID,
3857 (HRESULT (__stdcall *)(DDPIXELFORMAT *, void *))D3DZBufferFormatEnumerator,
3858 &ddsd2.ddpfPixelFormat) )
3859 goto LABEL_21;
3860 if ( uDeviceID == 2 || uDeviceID == 3 )
3861 ddsd2.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
3862
3863 if ( !pHost->CreateSurface(&ddsd2, &pZBuffer, 0) )
3864 {
3865 if ( !pBackBuffer->AddAttachedSurface(pZBuffer) )
3866 {
3867 if ( !pDirect3D->CreateDevice(*pAvailableDevices[uDeviceID].pGUID,
3868 pBackBuffer,
3869 &pDevice,
3870 0) )
3871 {
3872 memset(&d3dvp2, 0, sizeof(D3DVIEWPORT2));
3873 d3dvp2.dvClipWidth = 2.0;
3874 d3dvp2.dvClipY = 1.0;
3875 d3dvp2.dvClipHeight = 2.0;
3876 d3dvp2.dvMaxZ = 1.0;
3877 d3dvp2.dvMinZ = 0.0;
3878 goto LABEL_54;
3879 }
3880 LABEL_51:
3881 sprintf(pErrorMessage, "Init - Failed to create D3D device.\n");
3882 if (pDirect3D)
3883 {
3884 pDirect3D->Release();
3885 pDirect3D = 0;
3886 }
3887 goto LABEL_59;
3888 }
3889 LABEL_48:
3890 sprintf(pErrorMessage, "Init - Failed to attach z-buffer to back buffer.\n");
3891 if (pZBuffer)
3892 {
3893 pZBuffer->Release();
3894 pZBuffer = 0;
3895 }
3896 goto LABEL_61;
3897 }
3898 goto LABEL_44;
3899 }
3900 LABEL_36:
3901 v23 = "Init - Failed to create front buffer.\n";
3902 sprintf(pErrorMessage, v23);
3903 goto LABEL_65;
3904 }
3905 if ( uDeviceID == 1 )
3906 v26 = 1045;
3907 else
3908 v26 = 1041;
3909 if (pHost->SetCooperativeLevel(hWnd, v26) )
3910 {
3911 v23 = "Init - Failed to set cooperative level.\n";
3912 sprintf(pErrorMessage, v23);
3913 goto LABEL_65;
3914 }
3915 if (pHost->SetDisplayMode(640u, 480u, 16u, 0, 0) )
3916 {
3917 v23 = "Init - Failed to set display mode.\n";
3918 sprintf(pErrorMessage, v23);
3919 goto LABEL_65;
3920 }
3921
3922 memset(&ddsd2, 0, sizeof(DDSURFACEDESC2));
3923 ddsd2.dwSize = sizeof(DDSURFACEDESC2);
3924 ddsd2.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3925 ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
3926 ddsd2.dwBackBufferCount = 1;
3927 if ( pHost->CreateSurface(&ddsd2, &pFrontBuffer, 0) )
3928 goto LABEL_36;
3929 //a3a = &pBackBuffer;
3930 //v14 = *v34;
3931 memset(&v27, 0, sizeof(DDSCAPS2));
3932 v27.dwCaps = DDSCAPS_BACKBUFFER;
3933 //v33 = (IDirect3DDevice3 **)v14->GetAttachedSurface(&v27, &pBackBuffer);
3934 //hWnda = &pDirect3D;
3935 pHost->QueryInterface(IID_IDirect3D3, (LPVOID *)&pDirect3D);
3936 if (FAILED(pFrontBuffer->GetAttachedSurface(&v27, &pBackBuffer)))
3937 {
3938 v25 = "Init - Failed to get D3D interface.\n";
3939 goto LABEL_45;
3940 }
3941
3942 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
3943 ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
3944 ddsd2.dwWidth = 640;
3945 ddsd2.dwHeight = 480;
3946 if ( pDirect3D->EnumZBufferFormats(*pAvailableDevices[uDeviceID].pGUID,
3947 (HRESULT (__stdcall *)(DDPIXELFORMAT *, void *))D3DZBufferFormatEnumerator,
3948 &ddsd2.ddpfPixelFormat) )
3949 {
3950 LABEL_21:
3951 v25 = "Init - Failed to enumerate Z buffer formats.\n";
3952 goto LABEL_45;
3953 }
3954 if ( uDeviceID == 2 || uDeviceID == 3 )
3955 BYTE1(ddsd2.ddsCaps.dwCaps) |= 8u;
3956 //uDeviceIDa = &pZBuffer;
3957 if (pHost->CreateSurface(&ddsd2, &pZBuffer, 0) )
3958 {
3959 LABEL_44:
3960 v25 = "Init - Failed to create z-buffer.\n";
3961 LABEL_45:
3962 sprintf(pErrorMessage, v25);
3963 if (pBackBuffer)
3964 {
3965 pBackBuffer->Release();
3966 pBackBuffer = 0;
3967 }
3968 LABEL_63:
3969 //v19 = &pFrontBuffer;
3970 if (pFrontBuffer)
3971 {
3972 pFrontBuffer->Release();
3973 pFrontBuffer= 0;
3974 }
3975 goto LABEL_65;
3976 }
3977 if (pBackBuffer->AddAttachedSurface(pZBuffer))
3978 goto LABEL_48;
3979 //v33 = &pDevice;
3980 if (pDirect3D->CreateDevice(*pAvailableDevices[uDeviceID].pGUID,
3981 pBackBuffer,
3982 &pDevice,
3983 0) )
3984 goto LABEL_51;
3985 memset(&d3dvp2, 0, sizeof(D3DVIEWPORT2));
3986 d3dvp2.dvClipWidth = 2.0;
3987 d3dvp2.dvClipY = 1.0;
3988 d3dvp2.dvClipHeight = 2.0;
3989 d3dvp2.dvMaxZ = 1.0;
3990
3991 LABEL_54:
3992 d3dvp2.dwSize = sizeof(D3DVIEWPORT2);
3993 //v17 = *hWnda;
3994 d3dvp2.dwWidth = 640;
3995 d3dvp2.dwHeight = 480;
3996 d3dvp2.dvClipX = -1.0;
3997 //v18 = v17->lpVtbl;
3998 //v32 = &v4->pViewport;
3999 if (pDirect3D->CreateViewport(&pViewport, 0))
4000 {
4001 sprintf(pErrorMessage, "Init - Failed to create viewport.\n");
4002 if (pDevice)
4003 {
4004 pDevice->Release();
4005 pDevice = 0;
4006 }
4007 if (pDirect3D)
4008 {
4009 pDirect3D->Release();
4010 pDirect3D = 0;
4011 }
4012 LABEL_59:
4013 if (pZBuffer)
4014 {
4015 pZBuffer->Release();
4016 pZBuffer = 0;
4017 }
4018 LABEL_61:
4019 if (pBackBuffer)
4020 {
4021 pBackBuffer->Release();
4022 pBackBuffer = 0;
4023 }
4024 goto LABEL_63;
4025 }
4026
4027 pDevice->AddViewport(pViewport);
4028 pViewport->SetViewport2(&d3dvp2);
4029 pDevice->SetCurrentViewport(pViewport);
4030 return 1;
4031 }
4032
4033
4034 //----- (0049E444) --------------------------------------------------------
4035 unsigned int RenderD3D::GetDeviceCaps()
4036 {
4037 unsigned int v1; // ebx@1
4038 RenderD3D *v2; // edi@1
4039 IDirect3DDevice3 *v3; // eax@1
4040 unsigned int result; // eax@2
4041 D3DDEVICEDESC refCaps; // [sp+Ch] [bp-1F8h]@1
4042 D3DDEVICEDESC halCaps; // [sp+108h] [bp-FCh]@1
4043
4044 v1 = 0;
4045 v2 = this;
4046 memset(&halCaps, 0, 0xFCu);
4047 halCaps.dwSize = 252;
4048 memset(&refCaps, 0, 0xFCu);
4049 v3 = v2->pDevice;
4050 refCaps.dwSize = 252;
4051 if ( v3->GetCaps(&halCaps, &refCaps) )
4052 {
4053 result = 1;
4054 }
4055 else
4056 {
4057 if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & 0x10) )
4058 v1 = 2;
4059 if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & 2) )
4060 v1 |= 4u;
4061 if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & 1) )
4062 v1 |= 8u;
4063 if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & 0x20) )
4064 v1 |= 0x10u;
4065 if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & 2) )
4066 v1 |= 0x20u;
4067 if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & 4) )
4068 v1 |= 0x40u;
4069 if ( halCaps.dpcTriCaps.dwTextureCaps & 0x20 )
4070 LOBYTE(v1) = v1 | 0x80;
4071 result = v1;
4072 }
4073 return result;
4074 }
4075
4076
4077 //----- (0049E4FC) --------------------------------------------------------
4078 void RenderD3D::ClearTarget(unsigned int bClearColor, unsigned int uClearColor, unsigned int bClearDepth, float z_clear)
4079 {
4080 uint uClearFlags = 0;
4081
4082 if (bClearColor)
4083 uClearFlags |= D3DCLEAR_TARGET;
4084 if (bClearDepth)
4085 uClearFlags |= D3DCLEAR_ZBUFFER;
4086
4087 D3DRECT rects[] = {{0, 0, 640, 480}};
4088 if (uClearFlags)
4089 pViewport->Clear2(1, rects, uClearFlags, uClearColor, z_clear, 0);
4090 }
4091
4092
4093 //----- (0049E54D) --------------------------------------------------------
4094 void RenderD3D::Present(bool bForceBlit)
4095 {
4096 RECT v5; // [sp+18h] [bp-18h]@1
4097 struct tagPOINT Point; // [sp+28h] [bp-8h]@4
4098
4099 v5.left = 0;
4100 v5.top = 0;
4101 v5.bottom = 480;
4102 v5.right = 640;
4103
4104 if (bWindowed || bForceBlit)
4105 {
4106 RECT rc;
4107 GetClientRect(hWindow, &rc);
4108 Point.y = 0;
4109 Point.x = 0;
4110 ClientToScreen(hWindow, &Point);
4111 OffsetRect(&rc, Point.x, Point.y);
4112 pFrontBuffer->Blt(&rc, pBackBuffer, &v5, DDBLT_WAIT, 0);
4113 }
4114 else
4115 pFrontBuffer->Flip(0, 1);
4116 }
4117
4118
4119 //----- (0049E5D4) --------------------------------------------------------
4120 bool RenderD3D::CreateTexture(unsigned int uTextureWidth, unsigned int uTextureHeight, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture, bool bAlphaChannel, bool bMipmaps, unsigned int uMinDeviceTexDim)
4121 {
4122 unsigned int v8; // edx@4
4123 unsigned int v9; // ebx@5
4124 unsigned int v10; // eax@5
4125 DWORD v11; // edx@5
4126 //int v12; // edx@7
4127 DDSURFACEDESC2 ddsd2; // [sp+Ch] [bp-80h]@1
4128 //RenderD3D *v15; // [sp+88h] [bp-4h]@1
4129
4130 //v15 = this;
4131 memset(&ddsd2, 0, 0x7Cu);
4132 ddsd2.dwSize = 0x7Cu;
4133 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4134 ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
4135 ddsd2.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
4136 ddsd2.dwHeight = uTextureHeight;
4137 ddsd2.dwWidth = uTextureWidth;
4138 if ( bMipmaps )
4139 {
4140 if ( (signed int)uTextureHeight <= (signed int)uTextureWidth )
4141 {
4142 v8 = GetMaxMipLevels(uTextureHeight) - GetMaxMipLevels(uMinDeviceTexDim);
4143 LABEL_8:
4144 ddsd2.dwMipMapCount = v8;
4145 if ( !v8 )
4146 goto LABEL_12;
4147 goto LABEL_11;
4148 }
4149 if ( (signed int)uTextureWidth < (signed int)uMinDeviceTexDim )
4150 {
4151 v8 = GetMaxMipLevels(uMinDeviceTexDim);
4152 goto LABEL_8;
4153 }
4154 v9 = GetMaxMipLevels(uTextureWidth);
4155 v10 = GetMaxMipLevels(uMinDeviceTexDim);
4156 ddsd2.dwMipMapCount = v9 - v10;
4157 if ( v9 == v10 )
4158 {
4159 ddsd2.dwFlags = 0x1007u;
4160 ddsd2.ddsCaps.dwCaps = v11;
4161 goto LABEL_12;
4162 }
4163 }
4164 else
4165 {
4166 ddsd2.dwMipMapCount = 1;
4167 }
4168 LABEL_11:
4169 ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT;
4170 ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
4171 LABEL_12:
4172 ddsd2.ddpfPixelFormat.dwRGBBitCount = 16;
4173 ddsd2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
4174 if (bAlphaChannel)
4175 {
4176 ddsd2.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
4177 ddsd2.ddpfPixelFormat.dwRBitMask = 0x7C00;
4178 ddsd2.ddpfPixelFormat.dwGBitMask = 0x03E0;
4179 ddsd2.ddpfPixelFormat.dwBBitMask = 0x001F;
4180 ddsd2.ddpfPixelFormat.dwRGBAlphaBitMask = 0x8000u;
4181 }
4182 else
4183 {
4184 ddsd2.ddpfPixelFormat.dwFlags = DDPF_RGB;
4185 ddsd2.ddpfPixelFormat.dwRBitMask = 0xF800;
4186 ddsd2.ddpfPixelFormat.dwGBitMask = 0x07E0;
4187 ddsd2.ddpfPixelFormat.dwBBitMask = 0x001F;
4188 ddsd2.ddpfPixelFormat.dwRGBAlphaBitMask = 0;
4189 }
4190 if (FAILED(pHost->CreateSurface(&ddsd2, pOutSurface, 0)))
4191 return false;
4192 if (FAILED((*pOutSurface)->QueryInterface(IID_IDirect3DTexture2, (void **)pOutTexture)))
4193 {
4194 (*pOutSurface)->Release();
4195 *pOutSurface = 0;
4196 return false;
4197 }
4198 return true;
4199 }
4200
4201 //----- (004A5190) --------------------------------------------------------
4202 void RenderD3D::HandleLostResources()
4203 {
4204 pBitmaps_LOD->ReleaseLostHardwareTextures();
4205 pBitmaps_LOD->_410423_move_textures_to_device();
4206 pSprites_LOD->ReleaseLostHardwareSprites();
4207 }
4208
4209
4210
4211 //----- (004A2050) --------------------------------------------------------
4212 void Render::DrawPolygon(unsigned int uNumVertices, stru148 *a3, ODMFace *a4, IDirect3DTexture2 *pTexture)
4213 {
4214 Render *v5; // edi@1
4215 unsigned int v6; // ebx@1
4216 LightmapBuilder *v7; // esi@3
4217 int v8; // eax@7
4218 ODMFace *v9; // eax@12
4219 char *v10; // esi@12
4220 double v11; // st7@14
4221 double v12; // st7@14
4222 int v13; // eax@14
4223 ODMFace *v14; // ecx@14
4224 double v15; // st7@14
4225 float v16; // ST48_4@15
4226 int v17; // eax@15
4227 char v18; // zf@17
4228 HRESULT v19; // eax@18
4229 HRESULT v20; // eax@18
4230 HRESULT v21; // eax@20
4231 HRESULT v22; // eax@20
4232 unsigned int v23; // ecx@20
4233 char *v24; // eax@21
4234 HRESULT v25; // eax@23
4235 HRESULT v26; // eax@23
4236 HRESULT v27; // eax@24
4237 HRESULT v28; // eax@25
4238 HRESULT v29; // eax@25
4239 HRESULT v30; // eax@25
4240 HRESULT v31; // eax@25
4241 HRESULT v32; // eax@26
4242 unsigned int v33; // ecx@26
4243 char *v34; // eax@27
4244 int v35; // edx@28
4245 HRESULT v36; // eax@29
4246 HRESULT v37; // eax@29
4247 HRESULT v38; // eax@29
4248 HRESULT v39; // eax@29
4249 //IDirect3DDevice3Vtbl *v40; // ebx@29
4250 unsigned int v41; // eax@29
4251 HRESULT v42; // eax@30
4252 HRESULT v43; // eax@30
4253 HRESULT v44; // eax@30
4254 char *v45; // esi@34
4255 int v46; // ecx@35
4256 double v47; // st6@35
4257 int v48; // eax@36
4258 const char *v49; // [sp+4Ch] [bp-1Ch]@0
4259 const char *v50; // [sp+4Ch] [bp-1Ch]@20
4260 int v51; // [sp+50h] [bp-18h]@0
4261 unsigned int v52; // [sp+54h] [bp-14h]@0
4262 LightmapBuilder *v53; // [sp+58h] [bp-10h]@3
4263 unsigned int v54; // [sp+5Ch] [bp-Ch]@3
4264 unsigned int v55; // [sp+5Ch] [bp-Ch]@34
4265 unsigned int v56; // [sp+60h] [bp-8h]@12
4266 int v57; // [sp+60h] [bp-8h]@34
4267 HRESULT a2; // [sp+64h] [bp-4h]@4
4268
4269 v5 = this;
4270 v6 = 0;
4271 if ( this->uNumD3DSceneBegins && (signed int)uNumVertices >= 3 )
4272 {
4273 v7 = pGame->pLightmapBuilder;
4274 v53 = v7;
4275 v54 = v7->std__vector_000004_size;
4276 if ( v7->std__vector_000004_size)
4277 a2 = -1;
4278 pGame->_44EE30(a4, (int)&a2);
4279 if ( byte_4D864C && pGame->uFlags & 1 )
4280 {
4281 v8 = GetActorTintColor(a3->field_58, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
4282 v7->_45D74F_MessWithLight(v8, 0);
4283 }
4284 else
4285 {
4286 if ( !v54 || byte_4D864C && pGame->uFlags & 2 )
4287 {
4288 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
4289 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
4290 if (bUsingSpecular)
4291 {
4292 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
4293 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
4294 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1));
4295 }
4296 if ( (signed int)uNumVertices > 0 )
4297 {
4298 v45 = (char *)&array_50AC10[0].vWorldViewPosition;
4299 v57 = (int)&arary_77E5C8[0].pos.y;
4300 v55 = uNumVertices;
4301 do
4302 {
4303 a2 = GetActorTintColor(a3->field_58, 0, *(float *)v45, 0, 0);
4304 pGame->_44EE30(a4, (int)&a2);
4305 v46 = v57;
4306 v47 = *(float *)v45 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist;
4307 *(int *)(v57 - 4) = *((int *)v45 + 3);
4308 *(int *)v57 = *((int *)v45 + 4);
4309 *(int *)(v57 + 12) = a2;
4310 *(float *)(v57 + 4) = 1.0 - 1.0 / v47;
4311 *(float *)(v57 + 8) = 1.0 / (*(float *)v45 + 0.0000001);
4312 if ( v5->bUsingSpecular )
4313 {
4314 v48 = sub_47C3D7_get_fog_related_stuff(0, 0, *(float *)v45);
4315 v46 = v57;
4316 }
4317 else
4318 {
4319 v48 = 0;
4320 }
4321 *(int *)(v46 + 16) = v48;
4322 *(int *)(v46 + 20) = *((int *)v45 + 6);
4323 *(int *)(v46 + 24) = *((int *)v45 + 7);
4324 v45 += 48;
4325 v18 = v55-- == 1;
4326 v57 = v46 + 32;
4327 }
4328 while ( !v18 );
4329 }
4330 pRenderD3D->pDevice->SetTexture(0, pTexture);
4331 pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
4332 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
4333 arary_77E5C8,
4334 uNumVertices,
4335 D3DDP_DONOTLIGHT);
4336 }
4337 else
4338 {
4339 if ( (signed int)uNumVertices > 0 )
4340 {
4341 v9 = (ODMFace *)&arary_77E5C8[0].pos.y;
4342 v10 = (char *)&array_50AC10[0].vWorldViewPosition;
4343 a4 = (ODMFace *)&arary_77E5C8[0].pos.y;
4344 v56 = uNumVertices;
4345 while ( 1 )
4346 {
4347 v11 = *(float *)v10 * 1000.0;
4348 *((int *)v9 - 1) = *((int *)v10 + 3);
4349 v12 = v11 / (double)pOutdoorCamera->shading_dist_mist;
4350 v9->pFacePlane.vNormal.x = *((int *)v10 + 4);
4351 *(float *)&v9->pFacePlane.vNormal.y = 1.0 - 1.0 / v12;
4352 *(float *)&v9->pFacePlane.vNormal.z = 1.0 / (*(float *)v10 + 0.0000001);
4353 v13 = GetActorTintColor(a3->field_58, 0, *(float *)v10, 0, 0);
4354 v14 = a4;
4355 v15 = *(float *)v10;
4356 a4->pFacePlane.dist = v13;
4357 if ( v5->bUsingSpecular )
4358 {
4359 v16 = v15;
4360 v17 = sub_47C3D7_get_fog_related_stuff(0, 0, v16);
4361 v14 = a4;
4362 }
4363 else
4364 {
4365 v17 = 0;
4366 }
4367 v14->zCalc1 = v17;
4368 v14->zCalc2 = *((int *)v10 + 6);
4369 v14->zCalc3 = *((int *)v10 + 7);
4370 v10 += 48;
4371 v18 = v56-- == 1;
4372 a4 = (ODMFace *)((char *)v14 + 32);
4373 if ( v18 )
4374 break;
4375 v9 = a4;
4376 }
4377 }
4378 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
4379 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
4380 if (bUsingSpecular)
4381 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
4382
4383 ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
4384 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
4385 D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
4386 arary_77E5C8,
4387 uNumVertices,
4388 D3DDP_DONOTLIGHT));
4389 //v50 = (const char *)v5->pRenderD3D->pDevice;
4390 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
4391 //(*(void (**)(void))(*(int *)v50 + 88))();
4392 v53->_45D74F_MessWithLight(-1, 0);
4393 v23 = uNumVertices;
4394 if ( (signed int)uNumVertices > 0 )
4395 {
4396 v24 = (char *)&arary_77E5C8[0].diffuse;
4397 do
4398 {
4399 *(int *)v24 = a2;
4400 v24 += 32;
4401 --v23;
4402 }
4403 while ( v23 );
4404 }
4405 ErrD3D(pRenderD3D->pDevice->SetTexture(0, pTexture));
4406 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
4407 if ( !pRenderer->bUsingSpecular )
4408 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true));
4409
4410 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
4411 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 1));
4412 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3));
4413 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
4414 D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
4415 arary_77E5C8,
4416 uNumVertices,
4417 D3DDP_DONOTLIGHT));
4418 if (bUsingSpecular)
4419 {
4420 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true));
4421
4422 v33 = uNumVertices;
4423 if ( (signed int)uNumVertices > 0 )
4424 {
4425 v34 = (char *)&arary_77E5C8[0].specular;
4426 do
4427 {
4428 v35 = *(int *)v34;
4429 *(int *)v34 = 0;
4430 v34 += 32;
4431 --v33;
4432 *((int *)v34 - 9) = pRenderer->uFogColor | v35 & 0xFF000000;
4433 }
4434 while ( v33 );
4435 }
4436 ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
4437 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 6));
4438 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 5));
4439 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
4440 D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_SPECULAR,
4441 arary_77E5C8,
4442 uNumVertices,
4443 D3DDP_DONOTLIGHT));
4444 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, true));
4445 //v40 = pRenderer->pRenderD3D->pDevice->lpVtbl;
4446 v41 = GetLevelFogColor();
4447 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF);
4448 v6 = 0;
4449 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0);
4450 }
4451 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
4452 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1));
4453 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, v6));
4454 }
4455 }
4456 }
4457 }
4458 // 4D864C: using guessed type char byte_4D864C;
4459
4460
4461 //----- (0049EB79) --------------------------------------------------------
4462 Render::~Render()
4463 {
4464 Render *v1; // esi@1
4465
4466 v1 = this;
4467 pAllocator->FreeChunk(this->pDefaultZBuffer);
4468 v1->pD3DBitmaps.Release();
4469 v1->pD3DSprites.Release();
4470 Release();
4471 v1->bWindowMode = 1;
4472 //nullsub_1();
4473 //nullsub_1();
4474 }
4475
4476
4477
4478 //----- (0049E756) --------------------------------------------------------
4479 bool Render::IsColorKeySupported(IDirectDraw4 *this_)
4480 {
4481 DDCAPS refCaps; // [sp+0h] [bp-2F8h]@1
4482 DDCAPS halCaps; // [sp+17Ch] [bp-17Ch]@1
4483
4484 halCaps.dwSize = 380;
4485 refCaps.dwSize = 380;
4486 this_->GetCaps(&halCaps, &refCaps);
4487 return halCaps.dwSVBCaps & 0x40 && BYTE1(halCaps.dwSVBCKeyCaps) & 2;
4488 }
4489
4490 //----- (0049E992) --------------------------------------------------------
4491 Render::Render()
4492 {
4493 Render *v1; // esi@1
4494 int v2; // eax@1
4495 char v3; // zf@1
4496
4497 v1 = this;
4498 this->pDirectDraw4 = 0;
4499 this->pFrontBuffer4 = 0;
4500 this->pBackBuffer4 = 0;
4501 this->pColorKeySurface4 = 0;
4502 this->pDirectDraw2 = 0;
4503 this->pFrontBuffer2 = 0;
4504 this->pBackBuffer2 = 0;
4505 this->pSomeSurface2 = 0;
4506 //RenderHWLContainer::RenderHWLContainer(&this->pD3DBitmaps);
4507 //RenderHWLContainer::RenderHWLContainer(&v1->pD3DSprites);
4508 v1->bWindowMode = 1;
4509 v1->field_40054 = 0;
4510 v1->field_10 = 640;
4511 v1->field_14 = 480;
4512 v1->field_40030 = 0;
4513 v1->field_4002C = 0;
4514 v1->pActiveZBuffer = 0;
4515 v1->pDefaultZBuffer = 0;
4516 v1->field_20_clipy = 0;
4517 v1->field_1C_clipx = 0;
4518 v1->field_24_clipz = 639;
4519 v1->field_28_clipw = 479;
4520 v1->field_4003C = (int)&unk_4EED80;
4521 v1->field_40040 = dword_4EED78;
4522 v1->uClipZ = 640;
4523 v1->field_40044 = 2;
4524 v1->field_40048 = 6;
4525 v1->pFrontBuffer4 = 0;
4526 v1->pBackBuffer4 = 0;
4527 v1->pColorKeySurface4 = 0;
4528 v1->pDirectDraw4 = 0;
4529 v1->pRenderD3D = 0;
4530 v1->uNumSceneBegins = 0;
4531 v1->uNumD3DSceneBegins = 0;
4532 v1->field_40110 = 0;
4533 v1->pTargetSurface = 0;
4534 v1->uTargetSurfacePitch = 0;
4535 v1->uClipY = 0;
4536 v1->uClipX = 0;
4537 v1->uClipW = 480;
4538 v1->bClip = 1;
4539 v1->bColorKeySupported = 0;
4540 v1->bRequiredTextureStagesAvailable = 0;
4541 v1->bTinting = 1;
4542 LOBYTE(v1->field_103668) = 0;
4543 v1->field_1036B8 = 0;
4544 v1->_gpu_memory_used = 0;
4545 uNumBillboardsToDraw = 0;
4546 bFogEnabled = false;
4547 }
4548
4549 bool Render::Initialize(bool bWindowed, uint uDefaultDevice,
4550 bool bColoredLights, uint uDetailLevel, uint bTinting)
4551 {
4552 bUserDirect3D = true;//ReadWindowsRegistryInt("Use D3D", 0);
4553 bStartInWindow = bWindowed;
4554
4555 uDesiredDirect3DDevice = uDefaultDevice;//ReadWindowsRegistryInt("D3D Device", 1);
4556
4557 bUseColoredLights = bColoredLights;//ReadWindowsRegistryInt("Colored Lights", 0);
4558 uLevelOfDetail = uDetailLevel;//ReadWindowsRegistryInt("Detail Level", 1);
4559
4560 this->bTinting = bTinting;
4561
4562 auto r1 = pD3DBitmaps.Load(L"data\\d3dbitmap.hwl");
4563 auto r2 = pD3DSprites.Load(L"data\\d3dsprite.hwl");
4564
4565 return r1 && r2;
4566 }
4567
4568
4569
4570 //----- (0049EBF1) --------------------------------------------------------
4571 void Render::_49EBF1()
4572 {
4573 signed int uNumRedBits; // edx@1
4574 signed int uNuGreenBits; // edi@1
4575 signed int uNumBlueBits; // esi@1
4576 unsigned int v4; // edx@4
4577 unsigned int v5; // edi@4
4578 int v6; // ebx@4
4579 int v7; // edx@4
4580 signed int v8; // [sp+8h] [bp-24h]@1
4581 signed int v9; // [sp+Ch] [bp-20h]@1
4582 signed int v10; // [sp+20h] [bp-Ch]@1
4583 signed int i; // [sp+24h] [bp-8h]@2
4584 signed int v12; // [sp+28h] [bp-4h]@3
4585
4586 v10 = 0;
4587 uNumRedBits = 1 << this->uTargetRBits;
4588 uNuGreenBits = 1 << this->uTargetGBits;
4589 uNumBlueBits = 1 << this->uTargetBBits;
4590 v9 = 1 << this->uTargetRBits;
4591 v8 = 1 << this->uTargetGBits;
4592 if ( uNumRedBits > 0 )
4593 {
4594 do
4595 {
4596 for ( i = 0; i < uNuGreenBits; ++i )
4597 {
4598 v12 = 0;
4599 if ( uNumBlueBits > 0 )
4600 {
4601 do
4602 {
4603 v4 = this->uTargetBBits;
4604 v5 = v4 + this->uTargetGBits;
4605 v6 = (v12 >> 1) + (v10 >> 1 << v5) + (i >> 1 << this->uTargetBBits);
4606 v7 = (v10 << v5) + v12++ + (i << v4);
4607 this->field_2C[v7] = v6;
4608 }
4609 while ( v12 < uNumBlueBits );
4610 uNumRedBits = v9;
4611 uNuGreenBits = v8;
4612 }
4613 }
4614 ++v10;
4615 }
4616 while ( v10 < uNumRedBits );
4617 }
4618 }
4619
4620
4621 //----- (0049ECC4) --------------------------------------------------------
4622 void Render::ClearBlack()
4623 {
4624 if (pRenderD3D)
4625 {
4626 if (field_40110)
4627 pRenderD3D->ClearTarget(true, 0, false, 0.0);
4628 }
4629 else
4630 memset(pRenderer->pTargetSurface, 0, 4 * (field_10 * field_14 / 2));
4631 }
4632
4633
4634 //----- (0049ED18) --------------------------------------------------------
4635 void Render::PresentBlackScreen()
4636 {
4637 LONG w; // edx@3
4638 IDirectDrawSurface *v2; // eax@3
4639 DDBLTFX v3; // [sp+4h] [bp-74h]@5
4640 RECT x; // [sp+68h] [bp-10h]@3
4641
4642 memset(&v3, 0, sizeof(DDBLTFX));
4643 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4644 pVersion->pVersionInfo.dwMajorVersion >= 5)
4645 {
4646 x.left = uWindowX;
4647 x.right = uWindowX + uWindowHeight;
4648 x.top = uWindowY;
4649 w = uWindowY + uWindowWidth;
4650 v2 = (IDirectDrawSurface *)this->pBackBuffer4;
4651 }
4652 else
4653 {
4654 x.left = uWindowX;
4655 x.right = uWindowX + uWindowHeight;
4656 x.top = uWindowY;
4657 w = uWindowY + uWindowWidth;
4658 v2 = (IDirectDrawSurface *)this->pBackBuffer2;
4659 }
4660 x.bottom = w;
4661 v3.dwFillColor = 0;
4662 v3.dwSize = 100;
4663 v2->Blt(&x, 0, 0, DDBLT_COLORFILL, &v3);
4664 pRenderer->Present();
4665 }
4666
4667
4668 //----- (0049EDB6) --------------------------------------------------------
4669 void Render::SavePCXScreenshot()
4670 {
4671 Render *v1; // esi@1
4672 __int16 v2; // di@1
4673 int v3; // eax@4
4674 int v4; // ecx@4
4675 int v5; // eax@8
4676 FILE *v6; // edi@10
4677 int v7; // ecx@11
4678 int v8; // eax@11
4679 int v9; // eax@13
4680 int v10; // ecx@15
4681 unsigned __int8 v11; // dl@15
4682 signed int v12; // eax@18
4683 char v13; // zf@27
4684 HRESULT v14; // eax@29
4685 char v15[56]; // [sp+Ch] [bp-158h]@10
4686 __int16 v16; // [sp+44h] [bp-120h]@10
4687 DDSURFACEDESC2 Dst; // [sp+48h] [bp-11Ch]@7
4688 char color_map[48]; // [sp+C4h] [bp-A0h]@10
4689 char Filename[40]; // [sp+F4h] [bp-70h]@3
4690 char *v20; // [sp+11Ch] [bp-48h]@14
4691 char *v21; // [sp+120h] [bp-44h]@14
4692 int v24; // [sp+124h] [bp-40h]@11
4693 FILE *File; // [sp+128h] [bp-3Ch]@3
4694 int var38; // [sp+12Ch] [bp-38h]@4
4695 PCXHeader_1 header1; // [sp+130h] [bp-34h]@10
4696 PCXHeader_2 header2; // [sp+140h] [bp-24h]@10
4697 void *ptr; // [sp+148h] [bp-1Ch]@10
4698 void *v28; // [sp+14Ch] [bp-18h]@8
4699 int v29; // [sp+150h] [bp-14h]@4
4700 int v30; // [sp+154h] [bp-10h]@4
4701 char v31; // [sp+15Ah] [bp-Ah]@25
4702 unsigned __int8 v32; // [sp+15Bh] [bp-9h]@17
4703 int i; // [sp+15Ch] [bp-8h]@10
4704 unsigned __int8 v34; // [sp+163h] [bp-1h]@17
4705
4706 v1 = this;
4707 v2 = 0;
4708 if ( !this->pRenderD3D || this->field_40110 )
4709 {
4710 sprintf(Filename, "screen%0.2i.pcx", dword_4EFA80++ % 100);
4711 File = fopen(Filename, "wb");
4712 if ( File )
4713 {
4714 v3 = v1->field_10;
4715 v4 = v1->field_14;
4716 var38 = v3;
4717 v29 = v4;
4718 v30 = v3;
4719 if ( v3 & 1 )
4720 v30 = v3 + 1;
4721 if ( v1->pRenderD3D )
4722 {
4723 memset(&Dst, 0, 0x7Cu);
4724 Dst.dwSize = 124;
4725 if ( !pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &Dst, 1u) )
4726 return;
4727 v28 = Dst.lpSurface;
4728 v5 = Dst.lPitch >> 1;
4729 v2 = 0;
4730 }
4731 else
4732 {
4733 pRenderer->BeginScene();
4734 v28 = pRenderer->pTargetSurface;
4735 v5 = pRenderer->uTargetSurfacePitch;
4736 }
4737 i = v5;
4738 header1.right = var38 - 1;
4739 header1.left = v2;
4740 header1.bottom = v29 - 1;
4741 header1.up = v2;
4742 header2.pitch = v30;
4743 memset(color_map, 0, sizeof(color_map));
4744 memset(v15, 0, sizeof(v15));
4745 header2.reserved = 0;
4746 header1.manufacturer = 10;
4747 v16 = 0;
4748 v6 = File;
4749 header1.version = 5;
4750 header1.encoding = 1;
4751 header1.bpp = 8;
4752 header1.hdpi = 75;
4753 header1.vdpi = 75;
4754 header2.planes = 3;
4755 header2.palette_info = 1;
4756 fwrite(&header1, 1u, 1u, File);
4757 fwrite(&header1.version, 1u, 1u, v6);
4758 fwrite(&header1.encoding, 1u, 1u, v6);
4759 fwrite(&header1.bpp, 1u, 1u, v6);
4760 fwrite(&header1.left, 2u, 1u, v6);
4761 fwrite(&header1.up, 2u, 1u, v6);
4762 fwrite(&header1.right, 2u, 1u, v6);
4763 fwrite(&header1.bottom, 2u, 1u, v6);
4764 fwrite(&header1.hdpi, 2u, 1u, v6);
4765 fwrite(&header1.vdpi, 2u, 1u, v6);
4766 fwrite(color_map, 0x30u, 1u, v6);
4767 fwrite(&header2, 1u, 1u, v6);
4768 fwrite(&header2.planes, 1u, 1u, v6);
4769 fwrite(&header2.pitch, 2u, 1u, v6);
4770 fwrite(&header2.palette_info, 2u, 1u, v6);
4771 fwrite(v15, 0x3Au, 1u, v6);
4772 ptr = pAllocator->AllocNamedChunk(0, 3 * var38 + 6, 0);
4773 if ( v29 > 0 )
4774 {
4775 v7 = v30;
4776 File = (FILE *)v29;
4777 v29 = 3 * v30;
4778 v24 = 2 * i;
4779 v8 = (int)v28;
4780 while ( 1 )
4781 {
4782 i = v8;
4783 v9 = 0;
4784 if ( var38 > 0 )
4785 {
4786 v21 = (char *)ptr + v7;
4787 v20 = (char *)ptr + 2 * v30;
4788 do
4789 {
4790 *((char *)ptr + v9) = (signed int)(v1->uTargetRMask & *(short *)i) >> (LOBYTE(v1->uTargetGBits)
4791 + LOBYTE(v1->uTargetBBits)
4792 + v1->uTargetRBits
4793 - 8);
4794 v21[v9] = (signed int)(v1->uTargetGMask & *(short *)i) >> (LOBYTE(v1->uTargetBBits)
4795 + LOBYTE(v1->uTargetGBits)
4796 - 8);
4797 v10 = i;
4798 v11 = LOBYTE(v1->uTargetBMask);
4799 i += 2;
4800 v20[v9++] = (*(char *)v10 & v11) << (8 - LOBYTE(v1->uTargetBBits));
4801 }
4802 while ( v9 < var38 );
4803 }
4804 for ( i = 0; i < v29; i += v34 )
4805 {
4806 v34 = 1;
4807 v32 = *((char *)ptr + i);
4808 do
4809 {
4810 v12 = i + v34;
4811 if ( *((char *)ptr + v12) != v32 )
4812 break;
4813 if ( !(v12 % v30) )
4814 break;
4815 ++v34;
4816 }
4817 while ( v34 < 0x3Fu );
4818 if ( i + v34 > v29 )
4819 v34 = 3 * v30 - i;
4820 if ( v34 > 1u || v32 >= 0xC0u )
4821 {
4822 v31 = v34 | 0xC0;
4823 fwrite(&v31, 1u, 1u, v6);
4824 }
4825 fwrite(&v32, 1u, 1u, v6);
4826 }
4827 v8 = (int)((char *)v28 + v24);
4828 v13 = File == (FILE *)1;
4829 File = (FILE *)((char *)File - 1);
4830 v28 = (char *)v28 + v24;
4831 if ( v13 )
4832 break;
4833 v7 = v30;
4834 }
4835 }
4836 if ( v1->pRenderD3D )
4837 {
4838 ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
4839 }
4840 else
4841 {
4842 pRenderer->EndScene();
4843 }
4844
4845 pAllocator->FreeChunk(ptr);
4846 fclose(v6);
4847 }
4848 }
4849 }
4850 // 4EFA80: using guessed type int dword_4EFA80;
4851
4852
4853 //----- (0049F1BC) --------------------------------------------------------
4854 void Render::_49F1BC(const char *a1)
4855 {
4856 Render *v2; // esi@1
4857 __int16 v3; // di@1
4858 int v4; // eax@4
4859 char *v5; // ecx@4
4860 unsigned int v6; // eax@8
4861 FILE *v7; // edi@10
4862 int v8; // ecx@11
4863 int v9; // eax@11
4864 int v10; // eax@13
4865 const char *v11; // ecx@15
4866 unsigned __int8 v12; // dl@15
4867 signed int v13; // eax@18
4868 char v14; // zf@27
4869 HRESULT v15; // eax@29
4870 char v16; // [sp+Ch] [bp-12Ch]@10
4871 __int16 v17; // [sp+44h] [bp-F4h]@10
4872 int Dst; // [sp+48h] [bp-F0h]@7
4873 int v19; // [sp+58h] [bp-E0h]@8
4874 unsigned __int16 *v20; // [sp+6Ch] [bp-CCh]@8
4875 char v21; // [sp+C4h] [bp-74h]@10
4876 unsigned int v22; // [sp+F4h] [bp-44h]@11
4877 char *v23; // [sp+F8h] [bp-40h]@14
4878 int v24; // [sp+FCh] [bp-3Ch]@11
4879 int v25; // [sp+100h] [bp-38h]@4
4880 FILE *File; // [sp+104h] [bp-34h]@3
4881 char Str; // [sp+108h] [bp-30h]@10
4882 char v28; // [sp+109h] [bp-2Fh]@10
4883 char v29; // [sp+10Ah] [bp-2Eh]@10
4884 char v30; // [sp+10Bh] [bp-2Dh]@10
4885 __int16 v31; // [sp+10Ch] [bp-2Ch]@10
4886 __int16 v32; // [sp+10Eh] [bp-2Ah]@10
4887 __int16 v33; // [sp+110h] [bp-28h]@10
4888 __int16 v34; // [sp+112h] [bp-26h]@10
4889 __int16 v35; // [sp+114h] [bp-24h]@10
4890 __int16 v36; // [sp+116h] [bp-22h]@10
4891 char v37; // [sp+118h] [bp-20h]@10
4892 char v38; // [sp+119h] [bp-1Fh]@10
4893 __int16 v39; // [sp+11Ah] [bp-1Eh]@10
4894 __int16 v40; // [sp+11Ch] [bp-1Ch]@10
4895 void *ptr; // [sp+120h] [bp-18h]@10
4896 unsigned __int16 *v42; // [sp+124h] [bp-14h]@8
4897 int v43; // [sp+128h] [bp-10h]@4
4898 char v44; // [sp+12Fh] [bp-9h]@25
4899 char *i; // [sp+130h] [bp-8h]@10
4900 unsigned __int8 v46; // [sp+137h] [bp-1h]@17
4901
4902 v2 = this;
4903 v3 = 0;
4904 if ( !this->pRenderD3D || this->field_40110 )
4905 {
4906 ++dword_4EFA84;
4907 File = fopen(a1, "wb");
4908 if ( File )
4909 {
4910 v4 = v2->field_10;
4911 v5 = (char *)v2->field_14;
4912 v25 = v4;
4913 a1 = v5;
4914 v43 = v4;
4915 if ( v4 & 1 )
4916 v43 = v4 + 1;
4917 if ( v2->pRenderD3D )
4918 {
4919 memset(&Dst, 0, 0x7Cu);
4920 Dst = 124;
4921 if ( !pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, (DDSURFACEDESC2 *)&Dst, 1u) )
4922 return;
4923 v42 = v20;
4924 v6 = v19 >> 1;
4925 v3 = 0;
4926 }
4927 else
4928 {
4929 pRenderer->BeginScene();
4930 v42 = pRenderer->pTargetSurface;
4931 v6 = pRenderer->uTargetSurfacePitch;
4932 }
4933 i = (char *)v6;
4934 v33 = v25 - 1;
4935 v31 = v3;
4936 v34 = (short)a1 - 1;
4937 v32 = v3;
4938 v39 = v43;
4939 memset(&v21, 0, 0x30u);
4940 memset(&v16, 0, 0x38u);
4941 v37 = 0;
4942 Str = 10;
4943 v17 = 0;
4944 v7 = File;
4945 v28 = 5;
4946 v29 = 1;
4947 v30 = 8;
4948 v35 = 75;
4949 v36 = 75;
4950 v38 = 3;
4951 v40 = 1;
4952 fwrite(&Str, 1u, 1u, File);
4953 fwrite(&v28, 1u, 1u, v7);
4954 fwrite(&v29, 1u, 1u, v7);
4955 fwrite(&v30, 1u, 1u, v7);
4956 fwrite(&v31, 2u, 1u, v7);
4957 fwrite(&v32, 2u, 1u, v7);
4958 fwrite(&v33, 2u, 1u, v7);
4959 fwrite(&v34, 2u, 1u, v7);
4960 fwrite(&v35, 2u, 1u, v7);
4961 fwrite(&v36, 2u, 1u, v7);
4962 fwrite(&v21, 0x30u, 1u, v7);
4963 fwrite(&v37, 1u, 1u, v7);
4964 fwrite(&v38, 1u, 1u, v7);
4965 fwrite(&v39, 2u, 1u, v7);
4966 fwrite(&v40, 2u, 1u, v7);
4967 fwrite(&v16, 0x3Au, 1u, v7);
4968 ptr = pAllocator->AllocNamedChunk(0, 3 * v25 + 6, 0);
4969 if ( (signed int)a1 > 0 )
4970 {
4971 v8 = v43;
4972 File = (FILE *)a1;
4973 v24 = 3 * v43;
4974 v22 = 2 * (int)i;
4975 v9 = (int)v42;
4976 while ( 1 )
4977 {
4978 a1 = (const char *)v9;
4979 v10 = 0;
4980 if ( v25 > 0 )
4981 {
4982 i = (char *)ptr + v8;
4983 v23 = (char *)ptr + 2 * v43;
4984 do
4985 {
4986 *((char *)ptr + v10) = (signed int)(v2->uTargetRMask & *(short *)a1) >> (LOBYTE(v2->uTargetGBits)
4987 + LOBYTE(v2->uTargetBBits)
4988 + v2->uTargetRBits
4989 - 8);
4990 i[v10] = (signed int)(v2->uTargetGMask & *(short *)a1) >> (LOBYTE(v2->uTargetBBits)
4991 + LOBYTE(v2->uTargetGBits)
4992 - 8);
4993 v11 = a1;
4994 v12 = LOBYTE(v2->uTargetBMask);
4995 a1 += 2;
4996 v23[v10++] = ((unsigned __int8)*v11 & v12) << (8 - LOBYTE(v2->uTargetBBits));
4997 }
4998 while ( v10 < v25 );
4999 }
5000 for ( i = 0; (signed int)i < v24; i += BYTE3(a1) )
5001 {
5002 BYTE3(a1) = 1;
5003 v46 = *((char *)ptr + (int)i);
5004 do
5005 {
5006 v13 = (signed int)&i[BYTE3(a1)];
5007 if ( *((char *)ptr + v13) != v46 )
5008 break;
5009 if ( !(v13 % v43) )
5010 break;
5011 ++BYTE3(a1);
5012 }
5013 while ( BYTE3(a1) < 0x3Fu );
5014 if ( (signed int)&i[BYTE3(a1)] > v24 )
5015 BYTE3(a1) = 3 * v43 - (char)i;
5016 if ( BYTE3(a1) > 1u || v46 >= 0xC0u )
5017 {
5018 v44 = BYTE3(a1) | 0xC0;
5019 fwrite(&v44, 1u, 1u, v7);
5020 }
5021 fwrite(&v46, 1u, 1u, v7);
5022 }
5023 v9 = (int)&v42[v22 / 2];
5024 v14 = File == (FILE *)1;
5025 File = (FILE *)((char *)File - 1);
5026 v42 = (unsigned __int16 *)((char *)v42 + v22);
5027 if ( v14 )
5028 break;
5029 v8 = v43;
5030 }
5031 }
5032 if ( v2->pRenderD3D )
5033 {
5034 ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
5035 }
5036 else
5037 {
5038 pRenderer->EndScene();
5039 }
5040 pAllocator->FreeChunk(ptr);
5041 fclose(v7);
5042 }
5043 }
5044 }
5045 // 4EFA84: using guessed type int dword_4EFA84;
5046
5047
5048
5049 //----- (0049F5A2) --------------------------------------------------------
5050 int Render::_49F5A2(int a2, int a3, int a4, void *Dst, int a6, int a7)
5051 {
5052 Render *v7; // ebx@1
5053 void *v8; // esi@3
5054 void *v9; // esi@3
5055 int v10; // ecx@4
5056 int v11; // eax@4
5057 int v12; // eax@6
5058 int v13; // eax@8
5059 int v14; // ecx@8
5060 signed int v15; // eax@11
5061 char v16; // zf@20
5062 int result; // eax@21
5063 char v18[58]; // [sp+Ch] [bp-ACh]@3
5064 // __int16 v19; // [sp+44h] [bp-74h]@3
5065 char v20[48]; // [sp+48h] [bp-70h]@3
5066 char *v21; // [sp+78h] [bp-40h]@7
5067 char *v22; // [sp+7Ch] [bp-3Ch]@7
5068 int v23; // [sp+80h] [bp-38h]@4
5069 int v24; // [sp+84h] [bp-34h]@4
5070 int v25; // [sp+88h] [bp-30h]@4
5071 int v26; // [sp+8Ch] [bp-2Ch]@4
5072 char Src; // [sp+90h] [bp-28h]@3
5073 char v28; // [sp+91h] [bp-27h]@3
5074 char v29; // [sp+92h] [bp-26h]@3
5075 char v30; // [sp+93h] [bp-25h]@3
5076 __int16 v31; // [sp+94h] [bp-24h]@3
5077 __int16 v32; // [sp+96h] [bp-22h]@3
5078 __int16 v33; // [sp+98h] [bp-20h]@3
5079 __int16 v34; // [sp+9Ah] [bp-1Eh]@3
5080 __int16 v35; // [sp+9Ch] [bp-1Ch]@3
5081 __int16 v36; // [sp+9Eh] [bp-1Ah]@3
5082 char v37; // [sp+A0h] [bp-18h]@3
5083 char v38; // [sp+A1h] [bp-17h]@3
5084 __int16 v39; // [sp+A2h] [bp-16h]@3
5085 __int16 v40; // [sp+A4h] [bp-14h]@3
5086 void *ptr; // [sp+A8h] [bp-10h]@3
5087 int v42; // [sp+ACh] [bp-Ch]@1
5088 char v43; // [sp+B3h] [bp-5h]@18
5089 int i; // [sp+B4h] [bp-4h]@6
5090
5091 v7 = this;
5092 v42 = a3;
5093 if ( a3 & 1 )
5094 v42 = a3 + 1;
5095 v31 = 0;
5096 v32 = 0;
5097 v33 = a3 - 1;
5098 v34 = a4 - 1;
5099 v39 = v42;
5100 memset(&v20, 0, 0x30u);
5101 memset(&v18, 0, 0x38u);
5102 v8 = Dst;
5103 v37 = 0;
5104 *(_WORD *)&v18[56] = 0;
5105 Src = 10;
5106 v28 = 5;
5107 v29 = 1;
5108 v30 = 8;
5109 v35 = 75;
5110 v36 = 75;
5111 v38 = 3;
5112 v40 = 1;
5113 memcpy(Dst, &Src, 1u);
5114 v8 = (char *)v8 + 1;
5115 memcpy(v8, &v28, 1u);
5116 v8 = (char *)v8 + 1;
5117 memcpy(v8, &v29, 1u);
5118 v8 = (char *)v8 + 1;
5119 memcpy(v8, &v30, 1u);
5120 v8 = (char *)v8 + 1;
5121 memcpy(v8, &v31, 2u);
5122 v8 = (char *)v8 + 2;
5123 memcpy(v8, &v32, 2u);
5124 v8 = (char *)v8 + 2;
5125 memcpy(v8, &v33, 2u);
5126 v8 = (char *)v8 + 2;
5127 memcpy(v8, &v34, 2u);
5128 v8 = (char *)v8 + 2;
5129 memcpy(v8, &v35, 2u);
5130 v8 = (char *)v8 + 2;
5131 memcpy(v8, &v36, 2u);
5132 v8 = (char *)v8 + 2;
5133 memcpy(v8, &v20, 0x30u);
5134 v8 = (char *)v8 + 48;
5135 memcpy(v8, &v37, 1u);
5136 v8 = (char *)v8 + 1;
5137 memcpy(v8, &v38, 1u);
5138 v8 = (char *)v8 + 1;
5139 memcpy(v8, &v39, 2u);
5140 v8 = (char *)v8 + 2;
5141 memcpy(v8, &v40, 2u);
5142 v8 = (char *)v8 + 2;
5143 memcpy(v8, &v18, 0x3Au);
5144 v9 = (char *)v8 + 58;
5145 ptr = pAllocator->AllocNamedChunk(0, 3 * a3 + 6, 0);
5146 if ( a4 > 0 )
5147 {
5148 v10 = v42;
5149 v25 = a4;
5150 v26 = 3 * v42;
5151 v23 = 2 * a3;
5152 v11 = a2;
5153 v24 = a2;
5154 while ( 1 )
5155 {
5156 a4 = v11;
5157 v12 = 0;
5158 i = 0;
5159 if ( a3 > 0 )
5160 {
5161 v21 = (char *)ptr + v10;
5162 v22 = (char *)ptr + 2 * v42;
5163 do
5164 {
5165 *((char *)ptr + v12) = (signed int)(v7->uTargetRMask & *(short *)a4) >> (LOBYTE(v7->uTargetGBits)
5166 + LOBYTE(v7->uTargetBBits)
5167 + v7->uTargetRBits
5168 - 8);
5169 v13 = i;
5170 v21[i] = (signed int)(v7->uTargetGMask & *(short *)a4) >> (LOBYTE(v7->uTargetBBits)
5171 + LOBYTE(v7->uTargetGBits)
5172 - 8);
5173 v14 = a4;
5174 a4 += 2;
5175 v22[v13] = (v7->uTargetBMask & *(char *)v14) << (8 - LOBYTE(v7->uTargetBBits));
5176 v12 = v13 + 1;
5177 i = v12;
5178 }
5179 while ( v12 < a3 );
5180 }
5181 for ( i = 0; i < v26; v9 = (char *)v9 + 1 )
5182 {
5183 BYTE3(a4) = 1;
5184 BYTE3(a2) = *((char *)ptr + i);
5185 do
5186 {
5187 v15 = i + BYTE3(a4);
5188 if ( *((char *)ptr + v15) != BYTE3(a2) )
5189 break;
5190 if ( !(v15 % v42) )
5191 break;
5192 ++BYTE3(a4);
5193 }
5194 while ( BYTE3(a4) < 0x3Fu );
5195 if ( i + BYTE3(a4) > v26 )
5196 BYTE3(a4) = 3 * v42 - i;
5197 if ( BYTE3(a4) > 1u || BYTE3(a2) >= 0xC0u )
5198 {
5199 v43 = BYTE3(a4) | 0xC0;
5200 memcpy(v9, &v43, 1u);
5201 v9 = (char *)v9 + 1;
5202 }
5203 memcpy(v9, (char *)&a2 + 3, 1u);
5204 i += BYTE3(a4);
5205 }
5206 v11 = v23 + v24;
5207 v16 = v25-- == 1;
5208 v24 += v23;
5209 if ( v16 )
5210 break;
5211 v10 = v42;
5212 }
5213 }
5214 pAllocator->FreeChunk(ptr);
5215 result = a7;
5216 *(int *)a7 = (char *)v9 - Dst;
5217 return result;
5218 }
5219
5220
5221 //----- (0049F8B5) --------------------------------------------------------
5222 FILE *Render::SavePCXImage(const char *Filename, char *a3, int a4, int a5)
5223 {
5224 Render *v5; // esi@1
5225 FILE *result; // eax@1
5226 FILE *v7; // edi@4
5227 int v8; // ecx@5
5228 int v9; // eax@5
5229 int v10; // eax@7
5230 int v11; // ecx@9
5231 signed int v12; // eax@12
5232 char v13; // zf@21
5233 char v14[56]; // [sp+4h] [bp-A0h]@4
5234 __int16 v15; // [sp+3Ch] [bp-68h]@4
5235 char color_map[48]; // [sp+40h] [bp-64h]@4
5236 int v17; // [sp+70h] [bp-34h]@5
5237 int v18; // [sp+74h] [bp-30h]@5
5238 char *v19; // [sp+78h] [bp-2Ch]@5
5239 int v20; // [sp+7Ch] [bp-28h]@5
5240 PCXHeader_1 header1; // [sp+80h] [bp-24h]@4
5241 PCXHeader_2 header2; // [sp+90h] [bp-14h]@4
5242 void *ptr; // [sp+98h] [bp-Ch]@4
5243 int v24; // [sp+9Ch] [bp-8h]@2
5244 char *i; // [sp+A0h] [bp-4h]@8
5245
5246 v5 = this;
5247 result = fopen(Filename, "wb");
5248 Filename = (const char *)result;
5249 if ( result )
5250 {
5251 v24 = a4;
5252 if ( a4 & 1 )
5253 v24 = a4 + 1;
5254 header1.left = 0;
5255 header1.up = 0;
5256 header1.right = a4 - 1;
5257 header1.bottom = a5 - 1;
5258 header2.pitch = v24;
5259 memset(color_map, 0, sizeof(color_map));
5260 header2.reserved = 0;
5261 memset(v14, 0, sizeof(v14));
5262 v15 = 0;
5263 header1.manufacturer = 10;
5264 header1.version = 5;
5265 header1.encoding = 1;
5266 header1.bpp = 8;
5267 header1.hdpi = 75;
5268 header1.vdpi = 75;
5269 header2.planes = 3;
5270 header2.palette_info = 1;
5271 fwrite(&header1, 1u, 1u, (FILE *)Filename);
5272 v7 = (FILE *)Filename;
5273 fwrite(&header1.version, 1u, 1u, (FILE *)Filename);
5274 fwrite(&header1.encoding, 1u, 1u, v7);
5275 fwrite(&header1.bpp, 1u, 1u, v7);
5276 fwrite(&header1.left, 2u, 1u, v7);
5277 fwrite(&header1.up, 2u, 1u, v7);
5278 fwrite(&header1.right, 2u, 1u, v7);
5279 fwrite(&header1.bottom, 2u, 1u, v7);
5280 fwrite(&header1.hdpi, 2u, 1u, v7);
5281 fwrite(&header1.vdpi, 2u, 1u, v7);
5282 fwrite(color_map, 0x30u, 1u, v7);
5283 fwrite(&header2, 1u, 1u, v7);
5284 fwrite(&header2.planes, 1u, 1u, v7);
5285 fwrite(&header2.pitch, 2u, 1u, v7);
5286 fwrite(&header2.palette_info, 2u, 1u, v7);
5287 fwrite(v14, 0x3Au, 1u, v7);
5288 ptr = pAllocator->AllocNamedChunk(0, 3 * a4 + 6, 0);
5289 if ( a5 > 0 )
5290 {
5291 v8 = v24;
5292 v18 = a5;
5293 v20 = 3 * v24;
5294 v17 = 2 * a4;
5295 v9 = (int)a3;
5296 v19 = a3;
5297 while ( 1 )
5298 {
5299 a5 = v9;
5300 v10 = 0;
5301 if ( a4 > 0 )
5302 {
5303 a3 = (char *)ptr + v8;
5304 i = (char *)ptr + 2 * v24;
5305 do
5306 {
5307 *((char *)ptr + v10) = (signed int)(v5->uTargetRMask & *(short *)a5) >> (LOBYTE(v5->uTargetGBits)
5308 + LOBYTE(v5->uTargetBBits)
5309 + v5->uTargetRBits
5310 - 8);
5311 a3[v10] = (signed int)(v5->uTargetGMask & *(short *)a5) >> (LOBYTE(v5->uTargetBBits)
5312 + LOBYTE(v5->uTargetGBits)
5313 - 8);
5314 v11 = a5;
5315 a5 += 2;
5316 i[v10++] = (v5->uTargetBMask & *(char *)v11) << (8 - LOBYTE(v5->uTargetBBits));
5317 }
5318 while ( v10 < a4 );
5319 }
5320 for ( i = 0; (signed int)i < v20; i += BYTE3(a5) )
5321 {
5322 BYTE3(a5) = 1;
5323 BYTE3(Filename) = *((char *)ptr + (int)i);
5324 do
5325 {
5326 v12 = (signed int)&i[BYTE3(a5)];
5327 if ( *((char *)ptr + v12) != BYTE3(Filename) )
5328 break;
5329 if ( !(v12 % v24) )
5330 break;
5331 ++BYTE3(a5);
5332 }
5333 while ( BYTE3(a5) < 0x3Fu );
5334 if ( (signed int)&i[BYTE3(a5)] > v20 )
5335 BYTE3(a5) = 3 * v24 - (char)i;
5336 if ( BYTE3(a5) > 1u || BYTE3(Filename) >= 0xC0u )
5337 {
5338 BYTE3(a3) = BYTE3(a5) | 0xC0;
5339 fwrite((char *)&a3 + 3, 1u, 1u, v7);
5340 }
5341 fwrite((char *)&Filename + 3, 1u, 1u, v7);
5342 }
5343 v9 = (int)&v19[v17];
5344 v13 = v18-- == 1;
5345 v19 += v17;
5346 if ( v13 )
5347 break;
5348 v8 = v24;
5349 }
5350 }
5351 pAllocator->FreeChunk(ptr);
5352 result = (FILE *)fclose(v7);
5353 }
5354 return result;
5355 }
5356
5357
5358 //----- (0049FBCD) --------------------------------------------------------
5359 void Render::ClearTarget(unsigned int uColor)
5360 {
5361 if (pRenderD3D)
5362 {
5363 if (field_40110)
5364 pRenderD3D->ClearTarget(true, uColor, false, 0.0);
5365 }
5366 else
5367 memset32(pTargetSurface, uColor, field_10 * field_14 / 2);
5368 }
5369
5370
5371
5372 //----- (0049FC23) --------------------------------------------------------
5373 void Render::Release2()
5374 {
5375 Release();
5376 bWindowMode = 1;
5377 }
5378
5379
5380 //----- (0049FC37) --------------------------------------------------------
5381 void Render::Present()
5382 {
5383 Render *v1; // esi@1
5384 struct tagRECT Rect; // [sp+8h] [bp-28h]@11
5385 RECT a4; // [sp+18h] [bp-18h]@11
5386 struct tagPOINT Point; // [sp+28h] [bp-8h]@11
5387
5388 v1 = this;
5389 if ( !pRenderer->pRenderD3D || this->field_40110 )
5390 {
5391 this->pBeforePresentFunction();
5392 if ( v1->pRenderD3D )
5393 {
5394 if ( v1->field_40110 )
5395 {
5396 if (pAsyncMouse)
5397 pAsyncMouse->_46BAEC();
5398 pRenderD3D->Present(false);
5399 if (pAsyncMouse)
5400 pAsyncMouse->_46BB0A();
5401 }
5402 }
5403 else
5404 {
5405 if ( v1->bWindowMode )
5406 {
5407 RestoreFrontBuffer();
5408 GetClientRect(v1->hWnd, &Rect);
5409 Point.y = 0;
5410 Point.x = 0;
5411 ClientToScreen(v1->hWnd, &Point);
5412 OffsetRect(&Rect, Point.x, Point.y);
5413 a4.top = 0;
5414 a4.bottom = 480;
5415 a4.left = 0;
5416 a4.right = 640;
5417 PresentRect(&Rect, &a4);
5418 }
5419 else
5420 {
5421 RestoreFrontBuffer();
5422 a4.top = 0;
5423 a4.bottom = 480;
5424 a4.left = 0;
5425 a4.right = 640;
5426 BltBackToFontFast(0, 0, &a4);
5427 }
5428 }
5429 }
5430 }
5431
5432 //----- (0049FD3A) --------------------------------------------------------
5433 void Render::_49FD3A()
5434 {
5435 Render *v2; // esi@1
5436 IDirectDrawSurface4 *v3; // eax@6
5437 IDirectDrawSurface4 *v4; // ST0C_4@6
5438 RECT v5; // [sp+8h] [bp-10h]@6
5439
5440 auto a1 = this;
5441 v2 = a1;
5442 if ( a1->pRenderD3D )
5443 {
5444 if (pFrontBuffer4->IsLost() == DDERR_SURFACELOST)
5445 pFrontBuffer4->Restore();
5446 if (pBackBuffer4->IsLost() == DDERR_SURFACELOST)
5447 pBackBuffer4->Restore();
5448 v3 = v2->pBackBuffer4;
5449 v4 = v2->pFrontBuffer4;
5450 v5.top = 0;
5451 v5.bottom = 480;
5452 v5.left = 0;
5453 v5.right = 640;
5454 v3->BltFast(0, 0, v4, &v5, 16u);
5455 }
5456 }
5457
5458
5459 //----- (0049FDBF) --------------------------------------------------------
5460 void Render::CreateZBuffer()
5461 {
5462 if (!pDefaultZBuffer)
5463 {
5464 pDefaultZBuffer = pActiveZBuffer = nullptr;
5465 pDefaultZBuffer = pActiveZBuffer = (int *)pAllocator->AllocNamedChunk(0, 0x12C000, "Z Buf.");
5466 memset32(pActiveZBuffer, 0xFFFF0000u, 0x4B000u);
5467 }
5468 }
5469
5470
5471 //----- (0049FE05) --------------------------------------------------------
5472 void Render::Release()
5473 {
5474 Render *v1; // esi@1
5475 RenderD3D *v2; // ecx@1
5476 char v3; // zf@4
5477 void *v4; // ebx@6
5478 IDirectDraw *v5; // eax@10
5479 IDirectDrawSurface2 *v6; // eax@11
5480 IDirectDrawSurface2 *v7; // eax@13
5481 IDirectDrawSurface2 *v8; // eax@15
5482 IDirectDraw2 *v9; // eax@17
5483 IDirectDraw4 *v10; // eax@19
5484 IDirectDrawSurface4 *v11; // eax@20
5485 IDirectDrawSurface4 *v12; // eax@22
5486 IDirectDrawSurface4 *v13; // eax@24
5487 IDirectDraw4 *v14; // eax@26
5488 unsigned __int16 **v15; // ebx@28
5489 void **v16; // esi@29
5490
5491 v1 = this;
5492 v2 = this->pRenderD3D;
5493 if ( v2 )
5494 {
5495 if ( v1->field_40110 )
5496 {
5497 pRenderD3D->ClearTarget(1u, 0, 0, 1.0);
5498 pRenderD3D->Present(0);
5499 pRenderD3D->ClearTarget(1u, 0, 0, 1.0);
5500 }
5501 v1->pColorKeySurface4 = 0;
5502 v1->pBackBuffer4 = 0;
5503 v3 = v1->pTargetSurface == 0;
5504 v1->pFrontBuffer4 = 0;
5505 v1->pDirectDraw4 = 0;
5506 if ( !v3 )
5507 {
5508 free(v1->ptr_400E8);
5509 v1->pTargetSurface = 0;
5510 v1->ptr_400E8 = 0;
5511 }
5512 v4 = v1->pRenderD3D;
5513 if ( v4 )
5514 {
5515 pRenderD3D->Release();
5516 free(v4);
5517 }
5518 v1->pRenderD3D = 0;
5519 }
5520 else
5521 {
5522 if ( bWinNT4_0 == 1 )
5523 {
5524 v5 = (IDirectDraw *)v1->pDirectDraw2;
5525 if ( !v5 )
5526 return;
5527 v5->SetCooperativeLevel(v1->hWnd, 8u);
5528 v1->pDirectDraw2->FlipToGDISurface();
5529 v6 = v1->pSomeSurface2;
5530 if ( v6 )
5531 {
5532 v6->Release();
5533 v1->pSomeSurface2 = 0;
5534 }
5535 v7 = v1->pBackBuffer2;
5536 if ( v7 )
5537 {
5538 v7->Release();
5539 v1->pBackBuffer2 = 0;
5540 }
5541 v8 = v1->pFrontBuffer2;
5542 if ( v8 )
5543 {
5544 v8->Release();
5545 v1->pFrontBuffer2 = 0;
5546 }
5547 v9 = v1->pDirectDraw2;
5548 if ( v9 )
5549 {
5550 v9->Release();
5551 v1->pDirectDraw2 = 0;
5552 }
5553 }
5554 else
5555 {
5556 v10 = v1->pDirectDraw4;
5557 if ( !v10 )
5558 return;
5559 v10->SetCooperativeLevel(v1->hWnd, 1032u);
5560 v1->pDirectDraw4->FlipToGDISurface();
5561 v11 = v1->pColorKeySurface4;
5562 if ( v11 )
5563 {
5564 v11->Release();
5565 v1->pColorKeySurface4 = 0;
5566 }
5567 v12 = v1->pBackBuffer4;
5568 if ( v12 )
5569 {
5570 v12->Release();
5571 v1->pBackBuffer4 = 0;
5572 }
5573 v13 = v1->pFrontBuffer4;
5574 if ( v13 )
5575 {
5576 v13->Release();
5577 v1->pFrontBuffer4 = 0;
5578 }
5579 v14 = v1->pDirectDraw4;
5580 if ( v14 )
5581 {
5582 v14->Release();
5583 v1->pDirectDraw4 = 0;
5584 }
5585 }
5586 v15 = &v1->pTargetSurface;
5587 if ( v1->pTargetSurface )
5588 {
5589 v16 = (void **)&v1->ptr_400E8;
5590 free(*v16);
5591 *v15 = 0;
5592 *v16 = 0;
5593 }
5594 }
5595 }
5596
5597 //----- (0049FFD7) --------------------------------------------------------
5598 void Render::CreateSomeTexture()
5599 {
5600 pRenderD3D->CreateTexture(64, 64, &pSurface, &pTexture, true, false, 32);
5601 }
5602
5603 //----- (0049FFFB) --------------------------------------------------------
5604 bool Render::InitializeFullscreen(HWND hWnd)
5605 {
5606 //Render *v2; // esi@1
5607 //HWND v3; // ebx@1
5608 //void *v4; // eax@2
5609 //RenderD3D *v5; // eax@3
5610 unsigned int v6; // edx@5
5611 RenderD3D__DevInfo *v7; // ecx@5
5612 bool v8; // eax@6
5613 RenderD3D *v9; // ecx@13
5614 unsigned int v10; // eax@13
5615 RenderD3D *v11; // eax@25
5616 HRESULT v12; // eax@25
5617 int v13; // ecx@25
5618 int v14; // eax@27
5619 signed int v15; // ebx@31
5620 bool v16; // eax@35
5621 char v17; // zf@35
5622 IDirectDraw4 *v18; // eax@38
5623 HRESULT v19; // eax@38
5624 int *v20; // eax@39
5625 int *v22; // eax@42
5626 int v23; // ecx@42
5627 D3DDEVICEDESC refCaps; // [sp+Ch] [bp-300h]@25
5628 DDSURFACEDESC2 pDesc; // [sp+108h] [bp-204h]@40
5629 D3DDEVICEDESC halCaps; // [sp+184h] [bp-188h]@25
5630 DDSURFACEDESC2 ddsd2; // [sp+280h] [bp-8Ch]@38
5631 void *v28; // [sp+2FCh] [bp-10h]@2
5632 int v29; // [sp+308h] [bp-4h]@2
5633
5634 //v2 = this;
5635 this->field_40110 = 0;
5636 this->pColorKeySurface4 = 0;
5637 this->pBackBuffer4 = 0;
5638 this->pFrontBuffer4 = 0;
5639 this->pDirectDraw4 = 0;
5640 this->bColorKeySupported = 0;
5641 Release();
5642 //v3 = hWnd;
5643 this->hWnd = hWnd;
5644 CreateZBuffer();
5645 if ( bUserDirect3D )
5646 {
5647 pRenderD3D = new RenderD3D;
5648 v28 = pRenderD3D;
5649 v6 = uDesiredDirect3DDevice;
5650 v29 = -1;
5651 v7 = pRenderD3D->pAvailableDevices;
5652 if ( v7[v6].bIsDeviceCompatible )
5653 {
5654 v8 = pRenderD3D->CreateDevice(v6, 0, hWnd);
5655 uAcquiredDirect3DDevice = uDesiredDirect3DDevice;
5656 }
5657 else
5658 {
5659 if ( v7[1].bIsDeviceCompatible )
5660 {
5661 v8 = pRenderD3D->CreateDevice(1u, 0, hWnd);
5662 uAcquiredDirect3DDevice = 1;
5663 }
5664 else
5665 {
5666 if ( !v7->bIsDeviceCompatible )
5667 Abortf("There aren't any D3D devices to create.");
5668 v8 = pRenderD3D->CreateDevice(0, 0, hWnd);
5669 uAcquiredDirect3DDevice = 0;
5670 }
5671 }
5672 if ( !v8 )
5673 Abortf("D3Drend->Init failed.");
5674 v9 = pRenderD3D;
5675 pBackBuffer4 = v9->pBackBuffer;
5676 pFrontBuffer4 = v9->pFrontBuffer;
5677 pDirectDraw4 = v9->pHost;
5678 v10 = pRenderD3D->GetDeviceCaps();
5679 if ( v10 & 1 )
5680 {
5681 if ( pRenderD3D )
5682 {
5683 pRenderD3D->Release();
5684 delete pRenderD3D;
5685 }
5686 pRenderD3D = 0;
5687 pBackBuffer4 = 0;
5688 pFrontBuffer4 = 0;
5689 pDirectDraw4 = 0;
5690 Abortf("Direct3D renderer: The device failed to return capabilities.");
5691 }
5692 if ( v10 & 0x3E )
5693 {
5694 if ( pRenderD3D )
5695 {
5696 pRenderD3D->Release();
5697 delete pRenderD3D;
5698 }
5699 pColorKeySurface4 = 0;
5700 pRenderD3D = 0;
5701 pBackBuffer4 = 0;
5702 pFrontBuffer4 = 0;
5703 pDirectDraw4 = 0;
5704 Abortf("Direct3D renderer: The device doesn't support the necessary alpha blending modes.");
5705 }
5706 if ( (v10 & 0x80u) != 0 )
5707 {
5708 if ( pRenderD3D )
5709 {
5710 pRenderD3D->Release();
5711 delete pRenderD3D;
5712 }
5713 pRenderD3D = 0;
5714 pBackBuffer4 = 0;
5715 pFrontBuffer4 = 0;
5716 pDirectDraw4 = 0;
5717 Abortf("Direct3D renderer: The device doesn't support non-square textures.");
5718 }
5719 LOBYTE(field_10365C) = ~(unsigned __int8)(v10 >> 6) & 1;
5720 bRequiredTextureStagesAvailable = CheckTextureStages();
5721 memset(&halCaps, 0, 0xFCu);
5722 halCaps.dwSize = 252;
5723 memset(&refCaps, 0, 0xFCu);
5724 v11 = pRenderD3D;
5725 refCaps.dwSize = 252;
5726 ErrD3D(v11->pDevice->GetCaps(&halCaps, &refCaps));
5727 v13 = halCaps.dwMinTextureWidth;
5728 if ( (unsigned int)halCaps.dwMinTextureWidth >= halCaps.dwMinTextureHeight )
5729 v13 = halCaps.dwMinTextureHeight;
5730 v14 = halCaps.dwMaxTextureWidth;
5731 uMinDeviceTextureDim = v13;
5732 if ( (unsigned int)v14 < halCaps.dwMaxTextureHeight )
5733 v14 = halCaps.dwMaxTextureHeight;
5734 uMaxDeviceTextureDim = v14;
5735 if ( (unsigned int)v13 < 4 )
5736 uMinDeviceTextureDim = 4;
5737 CreateSomeTexture();
5738 v15 = 1;
5739 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, true));
5740 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true));
5741 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2u));
5742 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, false));
5743 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, false));
5744 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, false));
5745 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u));
5746 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2u));
5747 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2u));
5748 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 3u));
5749 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2u));
5750 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0));
5751 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2u));
5752 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
5753 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0));
5754 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u));
5755 }
5756 else
5757 {
5758 CreateDirectDraw();
5759 SetDirectDrawCooperationMode(hWnd, 1);
5760 SetDirectDrawDisplayMode(640u, 480u, 16u);
5761 CreateDirectDrawPrimarySurface();
5762 v15 = 1;
5763 }
5764 ddpfPrimareSuface.dwSize = 32;
5765 GetTargetPixelFormat(&ddpfPrimareSuface);
5766 ParseTargetPixelFormat();
5767 _49EBF1();
5768 if ( pRenderD3D )
5769 {
5770 v16 = IsColorKeySupported(pDirectDraw4);
5771 v17 = uAcquiredDirect3DDevice == v15;
5772 bColorKeySupported = v16;
5773 if ( !v17 )
5774 bColorKeySupported = 0;
5775 if ( bColorKeySupported )
5776 {
5777 memset(&ddsd2, 0, 0x7Cu);
5778 ddsd2.ddckCKSrcBlt.dwColorSpaceLowValue = uTargetGMask | uTargetBMask;
5779 ddsd2.ddckCKSrcBlt.dwColorSpaceHighValue = ddsd2.ddckCKSrcBlt.dwColorSpaceLowValue;
5780 v18 = pDirectDraw4;
5781 ddsd2.dwSize = 124;
5782 ddsd2.dwFlags = 65543;
5783 ddsd2.ddsCaps.dwCaps = 2112;
5784 ddsd2.dwWidth = 640;
5785 ddsd2.dwHeight = 480;
5786 ErrD3D(v18->CreateSurface(&ddsd2, &pColorKeySurface4, 0));
5787 pBeforePresentFunction = Present_ColorKey;
5788 }
5789 else
5790 {
5791 pTargetSurface = 0;
5792 ptr_400E8 = 0;
5793 v20 = (int *)operator new(0x96020u);
5794 ptr_400E8 = v20;
5795 if ( !v20
5796 || (memset(&pDesc, 0, 0x7Cu),
5797 pDesc.dwSize = 124,
5798 !pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &pDesc, v15)) )
5799 return 0;
5800 pBackBuffer4->Unlock(0);
5801 v22 = ptr_400E8 + 4;
5802 v23 = (unsigned int)pDesc.lpSurface & 7;
5803 LOBYTE(v22) = (unsigned __int8)v22 & 0xF8;
5804 uTargetSurfacePitch = 640;
5805 pBeforePresentFunction = Present_NoColorKey;
5806 v15 = 1;
5807 pTargetSurface = (unsigned __int16 *)((char *)v22 + 2 * v23);
5808 }
5809 field_40110 = v15;
5810 }
5811 else
5812 {
5813 pBeforePresentFunction = 0;//nullsub_1;
5814 }
5815 bWindowMode = 0;
5816 pParty->uFlags |= 2u;
5817 LODWORD(flt_6BE3A0) = 0x3F0CCCCDu;
5818 pViewport->_4C02F8(36044);
5819 return v15;
5820 }
5821 // 6BE3A0: using guessed type float flt_6BE3A0;
5822
5823
5824 //----- (004A05F3) --------------------------------------------------------
5825 bool Render::SwitchToWindow(HWND hWnd)
5826 {
5827 //Render *v2; // esi@1
5828 //void *v3; // eax@2
5829 //RenderD3D *v4; // eax@3
5830 //unsigned int v5; // edx@5
5831 //RenderD3D__DevInfo *v6; // ecx@5
5832 bool v7; // eax@7
5833 //RenderD3D *v8; // ecx@12
5834 unsigned int v9; // eax@12
5835 RenderD3D *v10; // eax@24
5836 HRESULT v11; // eax@24
5837 int v12; // eax@24
5838 int v13; // eax@26
5839 bool v14; // eax@32
5840 char v15; // zf@32
5841 IDirectDraw4 *v16; // eax@35
5842 HRESULT v17; // eax@35
5843 int *v18; // eax@36
5844 int *v19; // edx@38
5845 int v20; // eax@38
5846 unsigned int v21; // ecx@38
5847 int v22; // eax@41
5848 D3DDEVICEDESC refCaps; // [sp+Ch] [bp-300h]@24
5849 DDSURFACEDESC2 pDesc; // [sp+108h] [bp-204h]@37
5850 D3DDEVICEDESC halCaps; // [sp+184h] [bp-188h]@24
5851 DDSURFACEDESC2 ddsd2; // [sp+280h] [bp-8Ch]@35
5852 //RenderD3D *thisa; // [sp+2FCh] [bp-10h]@2
5853 int v29; // [sp+308h] [bp-4h]@2
5854
5855 pParty->uFlags |= 2u;
5856 //v2 = this;
5857 flt_6BE3A0 = 0.55000001f;
5858 pViewport->_4C02F8(36044);
5859 field_40110 = 0;
5860 Release();
5861 pColorKeySurface4 = 0;
5862 pBackBuffer4 = 0;
5863 pFrontBuffer4 = 0;
5864 pDirectDraw4 = 0;
5865 bColorKeySupported = 0;
5866 CreateZBuffer();
5867 if ( bUserDirect3D )
5868 {
5869 /*v3 = operator new(0x148u);
5870 thisa = (RenderD3D *)v3;
5871 v29 = 0;
5872 if ( v3 )
5873 v4 = RenderD3D::RenderD3D((RenderD3D *)v3);
5874 else
5875 v4 = 0;*/
5876 pRenderD3D = new RenderD3D;
5877 //v4 = pRenderD3D;
5878 //v5 = uDesiredDirect3DDevice;
5879 v29 = -1;
5880 //v6 = pRenderD3D->pAvailableDevices;
5881 if (pRenderD3D->pAvailableDevices[uDesiredDirect3DDevice].bIsDeviceCompatible &&
5882 uDesiredDirect3DDevice != 1 )
5883 {
5884 v7 = pRenderD3D->CreateDevice(uDesiredDirect3DDevice, 1, hWnd);
5885 uAcquiredDirect3DDevice = uDesiredDirect3DDevice;
5886 }
5887 else
5888 {
5889 if ( !pRenderD3D->pAvailableDevices[0].bIsDeviceCompatible )
5890 Abortf("There aren't any D3D devices to init.");
5891 v7 = pRenderD3D->CreateDevice(0, 1, hWnd);
5892 uAcquiredDirect3DDevice = 0;
5893 }
5894 if ( !v7 )
5895 Abortf("D3Drend->Init failed.");
5896
5897 //v8 = pRenderD3D;
5898 pColorKeySurface4 = 0;
5899 pBackBuffer4 = pRenderD3D->pBackBuffer;
5900 pFrontBuffer4 = pRenderD3D->pFrontBuffer;
5901 pDirectDraw4 = pRenderD3D->pHost;
5902 v9 = pRenderD3D->GetDeviceCaps();
5903 if ( v9 & 1 )
5904 {
5905 if (pRenderD3D)
5906 {
5907 pRenderD3D->Release();
5908 delete pRenderD3D;
5909 }
5910 pRenderD3D = 0;
5911 pBackBuffer4 = 0;
5912 pFrontBuffer4 = 0;
5913 pDirectDraw4 = 0;
5914 Abortf("Direct3D renderer: The device failed to return capabilities.");
5915 }
5916 if ( v9 & 0x3E )
5917 {
5918 if (pRenderD3D)
5919 {
5920 pRenderD3D->Release();
5921 delete pRenderD3D;
5922 }
5923 pColorKeySurface4 = 0;
5924 pRenderD3D = 0;
5925 pBackBuffer4 = 0;
5926 pFrontBuffer4 = 0;
5927 pDirectDraw4 = 0;
5928 Abortf("Direct3D renderer: The device doesn't support the necessary alpha blending modes.");
5929 }
5930 if ( (v9 & 0x80u) != 0 )
5931 {
5932 if (pRenderD3D)
5933 {
5934 pRenderD3D->Release();
5935 delete pRenderD3D;
5936 }
5937 pRenderD3D = 0;
5938 pBackBuffer4 = 0;
5939 pFrontBuffer4 = 0;
5940 pDirectDraw4 = 0;
5941 Abortf("Direct3D renderer: The device doesn't support non-square textures.");
5942 }
5943 LOBYTE(field_10365C) = ~(unsigned __int8)(v9 >> 6) & 1;
5944 bRequiredTextureStagesAvailable = CheckTextureStages();
5945 memset(&halCaps, 0, 0xFCu);
5946 halCaps.dwSize = 252;
5947 memset(&refCaps, 0, 0xFCu);
5948 //v10 = v2->pRenderD3D;
5949 refCaps.dwSize = 252;
5950 ErrD3D(pRenderD3D->pDevice->GetCaps(&halCaps, &refCaps));
5951 v12 = halCaps.dwMinTextureWidth;
5952 if ( (unsigned int)halCaps.dwMinTextureWidth >= halCaps.dwMinTextureHeight )
5953 v12 = halCaps.dwMinTextureHeight;
5954 uMinDeviceTextureDim = v12;
5955 v13 = halCaps.dwMaxTextureWidth;
5956 if ( (unsigned int)halCaps.dwMaxTextureWidth < halCaps.dwMaxTextureHeight )
5957 v13 = halCaps.dwMaxTextureHeight;
5958 uMaxDeviceTextureDim = v13;
5959 CreateSomeTexture();
5960 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, 1u));
5961 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
5962 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2u));
5963 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, 0));
5964 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, 0));
5965 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u));
5966 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2u));
5967 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2u));
5968 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 3u));
5969 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2u));
5970 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0));
5971 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2u));
5972 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
5973 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0));
5974 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u));
5975 }
5976 else
5977 {
5978 CreateDirectDraw();
5979 SetDirectDrawCooperationMode(hWnd, 0);
5980 field_4004C = 1;
5981 CreateFrontBuffer();
5982 CreateClipper(hWnd);
5983 CreateBackBuffer();
5984 field_40030 = 0;
5985 field_18_locked_pitch = 0;
5986 }
5987 ddpfPrimareSuface.dwSize = 32;
5988 GetTargetPixelFormat(&ddpfPrimareSuface);
5989 ParseTargetPixelFormat();
5990 _49EBF1();
5991 if ( !pRenderD3D )
5992 {
5993 pBeforePresentFunction = 0;//nullsub_1;
5994 goto LABEL_47;
5995 }
5996 v14 = IsColorKeySupported(pDirectDraw4);
5997 v15 = uAcquiredDirect3DDevice == 1;
5998 bColorKeySupported = v14;
5999 if ( !v15 )
6000 bColorKeySupported = 0;
6001 if ( bColorKeySupported )
6002 {
6003 memset(&ddsd2, 0, 0x7Cu);
6004 ddsd2.ddckCKSrcBlt.dwColorSpaceLowValue = uTargetGMask | uTargetBMask;
6005 ddsd2.ddckCKSrcBlt.dwColorSpaceHighValue = ddsd2.ddckCKSrcBlt.dwColorSpaceLowValue;
6006 v16 = pDirectDraw4;
6007 ddsd2.dwSize = 124;
6008 ddsd2.dwFlags = 65543;
6009 ddsd2.ddsCaps.dwCaps = 2112;
6010 ddsd2.dwWidth = 640;
6011 ddsd2.dwHeight = 480;
6012 ErrD3D(v16->CreateSurface(&ddsd2, &pColorKeySurface4, 0));
6013 pBeforePresentFunction = Present_ColorKey;
6014 LABEL_45:
6015 field_40110 = 1;
6016 LABEL_47:
6017 bWindowMode = 1;
6018 hWnd = hWnd;
6019 return 0;
6020 }
6021 pTargetSurface = 0;
6022 ptr_400E8 = 0;
6023 v18 = (int *)new char[0x96020];
6024 memset(v18, -1, 0x96020);
6025 ptr_400E8 = v18;
6026 if ( v18 )
6027 {
6028 memset(&pDesc, 0, 0x7Cu);
6029 pDesc.dwSize = 124;
6030 if ( pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &pDesc, 1u) )
6031 {
6032 pRenderer->pBackBuffer4->Unlock(0);
6033 v19 = ptr_400E8;
6034 v20 = (unsigned int)pDesc.lpSurface & 7;
6035 v21 = (unsigned int)ptr_400E8 & 7;
6036 if ( v21 == v20 )
6037 {
6038 pTargetSurface = (unsigned __int16 *)v19;
6039 }
6040 else
6041 {
6042 if ( (signed int)v21 >= v20 )
6043 v22 = (int)((char *)v19 + 2 * (v21 - v20) + 16);
6044 else
6045 v22 = (int)((char *)v19 + 2 * (v20 - v21) + 16);
6046 pTargetSurface = (unsigned __int16 *)v22;
6047 }
6048 uTargetSurfacePitch = 640;
6049 pBeforePresentFunction = Present_NoColorKey;
6050 goto LABEL_45;
6051 }
6052 }
6053 return 0;
6054 }
6055
6056
6057 //----- (004A0BEE) --------------------------------------------------------
6058 char Render::Line2D(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW, unsigned __int16 uColor)
6059 {
6060 int v6; // edi@1
6061 int v7; // edx@5
6062 unsigned int v8; // ebx@5
6063 int v9; // eax@7
6064 unsigned int v10; // ecx@9
6065 unsigned int v11; // esi@13
6066 int v12; // eax@17
6067 int v13; // eax@21
6068 Render *v14; // edi@21
6069 int v15; // eax@25
6070 int v16; // eax@27
6071 signed int v17; // eax@28
6072 signed int v18; // edi@30
6073 signed __int64 v19; // qax@41
6074 int v20; // edi@41
6075 unsigned int v21; // edi@46
6076 int v22; // esi@47
6077 int v23; // ebx@47
6078 signed int v24; // edx@50
6079 signed int v25; // esi@52
6080 unsigned __int16 *v26; // ecx@52
6081 int v27; // ebx@54
6082 int v28; // edi@55
6083 int v29; // edx@55
6084 int v30; // ebx@60
6085 int v31; // edx@61
6086 int v32; // edi@61
6087 int v34; // [sp+Ch] [bp-10h]@3
6088 Render *v35; // [sp+10h] [bp-Ch]@1
6089 __int64 v36; // [sp+14h] [bp-8h]@1
6090 signed int v37; // [sp+18h] [bp-4h]@28
6091 unsigned int uXa; // [sp+24h] [bp+8h]@49
6092 unsigned int uYa; // [sp+28h] [bp+Ch]@28
6093 int uYb; // [sp+28h] [bp+Ch]@47
6094 int uZa; // [sp+2Ch] [bp+10h]@38
6095
6096 v36 = 0i64;
6097 v6 = this->field_1C_clipx;
6098 v35 = this;
6099 if ( (signed int)uX < v6 )
6100 HIDWORD(v36) = 8;
6101 v34 = this->field_24_clipz;
6102 if ( (signed int)uX > this->field_24_clipz )
6103 HIDWORD(v36) |= 4u;
6104 v7 = this->field_20_clipy;
6105 v8 = uY;
6106 if ( (signed int)uY < v7 )
6107 HIDWORD(v36) |= 2u;
6108 v9 = this->field_28_clipw;
6109 if ( (signed int)uY > v9 )
6110 HIDWORD(v36) |= 1u;
6111 v10 = uZ;
6112 if ( (signed int)uZ < v6 )
6113 LODWORD(v36) = 8;
6114 if ( (signed int)uZ > v34 )
6115 LODWORD(v36) = v36 | 4;
6116 v11 = uW;
6117 if ( (signed int)uW < v7 )
6118 LODWORD(v36) = v36 | 2;
6119 if ( (signed int)uW > v9 )
6120 LODWORD(v36) = v36 | 1;
6121 LOBYTE(v12) = v36;
6122 if ( (unsigned int)v36 & HIDWORD(v36) )
6123 return v12;
6124 if ( !v36 )
6125 {
6126 LABEL_46:
6127 v21 = pRenderer->uTargetSurfacePitch;
6128 if ( pRenderer->uTargetSurfacePitch )
6129 {
6130 v12 = uX + v8 * pRenderer->uTargetSurfacePitch;
6131 v22 = v11 - v8;
6132 v23 = v22;
6133 uYb = v22;
6134 if ( v22 < 0 )
6135 {
6136 v23 = -v22;
6137 uYb = -v22;
6138 v21 = -pRenderer->uTargetSurfacePitch;
6139 }
6140 uXa = v10 - uX;
6141 if ( (uXa & 0x80000000u) == 0 )
6142 {
6143 v24 = 1;
6144 }
6145 else
6146 {
6147 uXa = -uXa;
6148 v24 = -1;
6149 }
6150 v25 = 0;
6151 v26 = v35->pTargetSurface;
6152 if ( v26 )
6153 {
6154 if ( (signed int)uXa <= v23 )
6155 {
6156 v30 = v23 + 1;
6157 if ( v30 > 0 )
6158 {
6159 v31 = 2 * v24;
6160 v32 = 2 * v21;
6161 v12 = (int)&v26[v12];
6162 do
6163 {
6164 v25 += uXa;
6165 *(short *)v12 = uColor;
6166 v12 += v32;
6167 if ( v25 > 0 )
6168 {
6169 v25 -= uYb;
6170 v12 += v31;
6171 }
6172 --v30;
6173 }
6174 while ( v30 );
6175 }
6176 }
6177 else
6178 {
6179 v27 = uXa + 1;
6180 if ( (signed int)(uXa + 1) > 0 )
6181 {
6182 v28 = 2 * v21;
6183 v29 = 2 * v24;
6184 v12 = (int)&v26[v12];
6185 do
6186 {
6187 v25 += uYb;
6188 *(short *)v12 = uColor;
6189 v12 += v29;
6190 if ( v25 > (signed int)uXa )
6191 {
6192 v25 -= uXa;
6193 v12 += v28;
6194 }
6195 --v27;
6196 }
6197 while ( v27 );
6198 }
6199 }
6200 }
6201 }
6202 return v12;
6203 }
6204 if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 8 )
6205 {
6206 if ( BYTE4(v36) & 8 )
6207 {
6208 v13 = (signed int)((uW - uY) * (v6 - uX)) / (signed int)(uZ - uX);
6209 v14 = v35;
6210 v8 = v13 + uY;
6211 uX = v35->field_1C_clipx;
6212 goto LABEL_24;
6213 }
6214 v10 = v6;
6215 v11 = (signed int)((uY - uW) * (v6 - uZ)) / (signed int)(uX - uZ) + uW;
6216 }
6217 v14 = v35;
6218 LABEL_24:
6219 if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 4 )
6220 {
6221 v15 = v14->field_24_clipz;
6222 if ( BYTE4(v36) & 4 )
6223 {
6224 v14 = v35;
6225 v8 += (signed int)((v11 - v8) * (v15 - uX)) / (signed int)(v10 - uX);
6226 uX = v35->field_24_clipz;
6227 }
6228 else
6229 {
6230 v16 = (signed int)((v8 - v11) * (v15 - v10)) / (signed int)(uX - v10);
6231 v10 = v14->field_24_clipz;
6232 v11 += v16;
6233 }
6234 }
6235 v17 = v14->field_20_clipy;
6236 v37 = 0;
6237 uYa = v14->field_20_clipy;
6238 if ( (signed int)v8 < v17 )
6239 v37 = 2;
6240 v18 = v14->field_28_clipw;
6241 if ( (signed int)v8 > v18 )
6242 v37 |= 1u;
6243 if ( (signed int)v11 >= v17 )
6244 v12 = 0;
6245 else
6246 v12 = 2;
6247 if ( (signed int)v11 > v18 )
6248 LOBYTE(v12) = v12 | 1;
6249 if ( !(v12 & v37) )
6250 {
6251 v12 ^= v37;
6252 uZa = v12;
6253 if ( v12 & 2 )
6254 {
6255 if ( v37 & 2 )
6256 {
6257 uX += (signed int)((v10 - uX) * (uYa - v8)) / (signed int)(v11 - v8);
6258 LOBYTE(v12) = (char)v35;
6259 v8 = v35->field_20_clipy;
6260 }
6261 else
6262 {
6263 v19 = (signed int)((uX - v10) * (uYa - v11));
6264 v20 = v8 - v11;
6265 v11 = uYa;
6266 v12 = v19 / v20;
6267 v10 += v12;
6268 }
6269 }
6270 if ( uZa & 1 )
6271 {
6272 if ( v37 & 1 )
6273 {
6274 uX += (signed int)((v10 - uX) * (v35->field_28_clipw - v8)) / (signed int)(v11 - v8);
6275 LOBYTE(v12) = (char)v35;
6276 v8 = v35->field_28_clipw;
6277 }
6278 else
6279 {
6280 v12 = (signed int)((uX - v10) * (v35->field_28_clipw - v11)) / (signed int)(v8 - v11);
6281 v11 = v35->field_28_clipw;
6282 v10 += v12;
6283 }
6284 }
6285 goto LABEL_46;
6286 }
6287 return v12;
6288 }
6289
6290
6291
6292 //----- (004A0E80) --------------------------------------------------------
6293 void Render::ClearZBuffer(int a2, int a3)
6294 {
6295 memset32(this->pActiveZBuffer, -65536, 0x4B000u);
6296 }
6297
6298
6299
6300 //----- (004A0E97) --------------------------------------------------------
6301 void Render::Clip_v2(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW)
6302 {
6303 this->field_1C_clipx = uX;
6304 this->field_20_clipy = uY;
6305 this->field_24_clipz = uZ;
6306 this->field_28_clipw = uW;
6307 }
6308
6309
6310 //----- (004A0EB6) --------------------------------------------------------
6311 void Render::ParseTargetPixelFormat()
6312 {
6313 Render *v1; // eax@1
6314 signed int v2; // ecx@1
6315 DWORD uRedMask; // edx@1
6316 unsigned int uGreenMask; // esi@5
6317 signed int v5; // ecx@5
6318 unsigned int uBlueMask; // edx@9
6319 signed int v7; // ecx@9
6320 unsigned int v8; // ecx@13
6321
6322 v1 = this;
6323 v2 = 0;
6324 uRedMask = v1->ddpfPrimareSuface.dwRBitMask;
6325 v1->uTargetBBits = 0;
6326 v1->uTargetGBits = 0;
6327 v1->uTargetRBits = 0;
6328 do
6329 {
6330 if ( (1 << v2) & uRedMask )
6331 ++v1->uTargetRBits;
6332 ++v2;
6333 }
6334 while ( v2 < 16 );
6335 uGreenMask = v1->ddpfPrimareSuface.dwGBitMask;
6336 v5 = 0;
6337 do
6338 {
6339 if ( (1 << v5) & uGreenMask )
6340 ++v1->uTargetGBits;
6341 ++v5;
6342 }
6343 while ( v5 < 16 );
6344 uBlueMask = v1->ddpfPrimareSuface.dwBBitMask;
6345 v7 = 0;
6346 do
6347 {
6348 if ( (1 << v7) & uBlueMask )
6349 ++v1->uTargetBBits;
6350 ++v7;
6351 }
6352 while ( v7 < 16 );
6353 v8 = v1->ddpfPrimareSuface.dwRBitMask;
6354 v1->uTargetGMask = uGreenMask;
6355 v1->uTargetRMask = v8;
6356 v1->uTargetBMask = uBlueMask;
6357 }
6358
6359 //----- (004A0F40) --------------------------------------------------------
6360 bool Render::LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags)
6361 {
6362 IDirectDrawSurface4 *v4; // esi@1
6363 bool result; // eax@1
6364 HRESULT v6; // eax@4
6365 int v7; // [sp-8h] [bp-14h]@10
6366 unsigned int v8; // [sp-4h] [bp-10h]@10
6367 char v9; // [sp+Bh] [bp-1h]@1
6368
6369 v4 = pSurface;
6370 v9 = 1;
6371 result = pSurface->Lock(0, pDesc, uLockFlags, 0);
6372 if ( result == DDERR_SURFACELOST )
6373 {
6374 if (pAsyncMouse)
6375 pAsyncMouse->Suspend();
6376 v6 = v4->Restore();
6377 if ( v6 )
6378 {
6379 if ( v6 != DDERR_IMPLICITLYCREATED )
6380 {
6381 LABEL_20:
6382 v9 = 0;
6383 result = (bool)memset(pDesc, 0, 4u);
6384 goto LABEL_21;
6385 }
6386 pRenderer->pFrontBuffer4->Restore();
6387 v4->Restore();
6388 }
6389 result = v4->Lock(0, pDesc, DDLOCK_WAIT, 0);
6390 if ( result == DDERR_INVALIDRECT || result == DDERR_SURFACEBUSY )
6391 goto LABEL_20;
6392 ErrD3D(result);
6393 if ( result )
6394 {
6395 //v8 = 0;
6396 //v7 = 2161;
6397 LABEL_19:
6398 //CheckHRESULT((CheckHRESULT_stru0 *)&pSurface, result, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Screen16.cpp", v7, v8);
6399 goto LABEL_20;
6400 }
6401 if ( pRenderer->pRenderD3D )
6402 pRenderD3D->HandleLostResources();
6403 result = pRenderer->pDirectDraw4->RestoreAllSurfaces();
6404 if (pAsyncMouse)
6405 pAsyncMouse->Resume();
6406 }
6407 else
6408 {
6409 if ( result )
6410 {
6411 if ( result == DDERR_INVALIDRECT || result == DDERR_SURFACEBUSY )
6412 goto LABEL_20;
6413 ErrD3D(result);
6414 //v8 = 0;
6415 //v7 = 2199;
6416 //goto LABEL_19;
6417 }
6418 }
6419 LABEL_21:
6420 LOBYTE(result) = v9;
6421 return result;
6422 }
6423
6424
6425 //----- (004A1032) --------------------------------------------------------
6426 bool Render::LockSurface_DDraw2(IDirectDrawSurface2 *pSurface, DDSURFACEDESC *pDesc, unsigned int uLockFlags)
6427 {
6428 IDirectDrawSurface2 *v4; // esi@1
6429 bool v5; // eax@1
6430 HRESULT v6; // eax@2
6431 int v7; // [sp-8h] [bp-10h]@8
6432 unsigned int v8; // [sp-4h] [bp-Ch]@8
6433
6434 v4 = pSurface;
6435 v5 = pSurface->Lock(
6436 0,
6437 pDesc,
6438 uLockFlags,
6439 0);
6440 BYTE3(pSurface) = 1;
6441 if ( v5 == DDERR_SURFACELOST )
6442 {
6443 v6 = v4->Restore();
6444 if ( !v6 )
6445 goto LABEL_5;
6446 if ( v6 == DDERR_IMPLICITLYCREATED )
6447 {
6448 pRenderer->pFrontBuffer2->Restore();
6449 v4->Restore();
6450 LABEL_5:
6451 v5 = v4->Lock(0, pDesc, 1u, 0) != 0;
6452 if ( v5 == DDERR_INVALIDRECT || v5 == DDERR_SURFACEBUSY )
6453 goto LABEL_14;
6454 if ( !v5 )
6455 return true;
6456 ErrD3D(v5);
6457 //v8 = 0;
6458 //v7 = 2247;
6459 goto LABEL_13;
6460 }
6461 else
6462 {
6463 pDesc->dwSize = 0;
6464 return false;
6465 }
6466 }
6467 else
6468 {
6469 if ( !v5 )
6470 return true;
6471 if ( v5 != DDERR_INVALIDRECT && v5 != DDERR_SURFACEBUSY )
6472 {
6473 //v8 = 0;
6474 //v7 = 2269;
6475 ErrD3D(v5);
6476 pDesc->dwSize = 0;
6477 return false;
6478 LABEL_13:
6479 //CheckHRESULT((CheckHRESULT_stru0 *)&pSurface, v5, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Screen16.cpp", v7, v8);
6480 goto LABEL_14;
6481 }
6482 }
6483 LABEL_14:
6484 return true;
6485 }
6486
6487 //----- (004A10E4) --------------------------------------------------------
6488 void Render::CreateDirectDraw()
6489 {
6490 Render *v1; // edi@1
6491 HRESULT v2; // eax@1
6492 HRESULT v3; // eax@5
6493 int v6; // [sp-Ch] [bp-20h]@3
6494 unsigned int v9; // [sp+0h] [bp-14h]@0
6495 IDirectDraw *lpDD; // [sp+10h] [bp-4h]@1
6496
6497 v1 = this;
6498 ErrD3D(DirectDrawCreate(0, &lpDD, 0));
6499
6500 pDirectDraw2 = nullptr;
6501 pDirectDraw4 = nullptr;
6502
6503 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6504 ErrD3D(lpDD->QueryInterface(IID_IDirectDraw4, (void **)&pDirectDraw4));
6505 else
6506 ErrD3D(lpDD->QueryInterface(IID_IDirectDraw2, (void **)&pDirectDraw2));
6507
6508 lpDD->Release();
6509 lpDD = nullptr;
6510 }
6511
6512 //----- (004A1169) --------------------------------------------------------
6513 void Render::SetDirectDrawCooperationMode(HWND hWnd, bool bFullscreen)
6514 {
6515 DWORD flags; // eax@1
6516 IDirectDraw *v4; // ecx@3
6517 HRESULT v5; // eax@5
6518 int v6; // [sp-8h] [bp-8h]@3
6519 unsigned int v7; // [sp-4h] [bp-4h]@3
6520
6521 flags = bFullscreen ? DDSCL_NORMAL | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN :
6522 DDSCL_NORMAL;
6523
6524 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6525 ErrD3D(pDirectDraw4->SetCooperativeLevel(hWnd, flags | DDSCL_MULTITHREADED));
6526 else
6527 ErrD3D(pDirectDraw2->SetCooperativeLevel(hWnd, flags));
6528 }
6529
6530 //----- (004A11C6) --------------------------------------------------------
6531 void Render::SetDirectDrawDisplayMode(unsigned int uWidth, unsigned int uHeight, unsigned int uBPP)
6532 {
6533 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6534 ErrD3D(pDirectDraw4->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0));
6535 else
6536 ErrD3D(pDirectDraw2->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0));
6537 }
6538
6539 //----- (004A121C) --------------------------------------------------------
6540 void Render::CreateFrontBuffer()
6541 {
6542 Render *v1; // esi@1
6543 IDirectDraw *pDD; // eax@3
6544 IDirectDrawSurface **pOutSurf; // esi@3
6545 struct _DDSURFACEDESC *v4; // edx@3
6546 HRESULT v5; // eax@5
6547 int v6; // [sp-8h] [bp-8Ch]@3
6548 unsigned int v7; // [sp-4h] [bp-88h]@3
6549 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3
6550
6551 v1 = this;
6552 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6553 {
6554 memset(&a2, 0, 0x7Cu);
6555 pDD = (IDirectDraw *)v1->pDirectDraw4;
6556 a2.dwSize = 124;
6557 a2.dwFlags = 1;
6558 v7 = 0;
6559 a2.ddsCaps.dwCaps = 512;
6560 v6 = 2357;
6561 pOutSurf = (IDirectDrawSurface **)&v1->pFrontBuffer4;
6562 v4 = (struct _DDSURFACEDESC *)&a2;
6563 }
6564 else
6565 {
6566 memset(&a2.lPitch, 0, 0x6Cu); // DDSURFACEDESC here
6567 pDD = (IDirectDraw *)v1->pDirectDraw2;
6568 a2.lPitch = 108;
6569 a2.dwBackBufferCount = 1;
6570 v7 = 0;
6571 a2.dwTextureStage = 512;
6572 v6 = 2346;
6573 pOutSurf = (IDirectDrawSurface **)&v1->pFrontBuffer2;
6574 v4 = (struct _DDSURFACEDESC *)&a2.lPitch;
6575 }
6576 ErrD3D(pDD->CreateSurface(v4, pOutSurf, 0));
6577 }
6578
6579 //----- (004A12CD) --------------------------------------------------------
6580 void Render::CreateBackBuffer()
6581 {
6582 Render *v1; // esi@1
6583 IDirectDraw *v2; // eax@3
6584 IDirectDrawSurface **ppBackBuffer; // esi@3
6585 struct _DDSURFACEDESC *v4; // edx@3
6586 HRESULT v5; // eax@5
6587 int v6; // [sp-8h] [bp-8Ch]@3
6588 unsigned int v7; // [sp-4h] [bp-88h]@3
6589 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3
6590
6591 v1 = this;
6592 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6593 {
6594 memset(&a2, 0, 0x7Cu);
6595 v2 = (IDirectDraw *)v1->pDirectDraw4;
6596 a2.dwSize = 124;
6597 a2.dwFlags = 7;
6598 v7 = 0;
6599 a2.ddsCaps.dwCaps = 2112;
6600 a2.dwWidth = 640;
6601 a2.dwHeight = 480;
6602 v6 = 2387;
6603 ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer4;
6604 v4 = (struct _DDSURFACEDESC *)&a2;
6605 }
6606 else
6607 {
6608 memset(&a2.lPitch, 0, 0x6Cu);
6609 v2 = (IDirectDraw *)v1->pDirectDraw2;
6610 a2.lPitch = 108;
6611 a2.dwBackBufferCount = 7;
6612 v7 = 0;
6613 a2.dwTextureStage = 2112;
6614 a2.dwAlphaBitDepth = 640;
6615 a2.dwMipMapCount = 480;
6616 v6 = 2374;
6617 ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer2;
6618 v4 = (struct _DDSURFACEDESC *)&a2.lPitch; // //DDSURFACEDESC here fo ddraw2
6619 }
6620 ErrD3D(v2->CreateSurface(v4, ppBackBuffer, 0));
6621 }
6622
6623 //----- (004A139A) --------------------------------------------------------
6624 void Render::CreateDirectDrawPrimarySurface()
6625 {
6626 Render *v1; // esi@1
6627 int v2; // ebx@3
6628 IDirectDraw2 *v3; // eax@3
6629 HRESULT v4; // eax@3
6630 IDirectDrawSurface *pFrontBuffer; // eax@3
6631 DDSCAPS2 *v6; // edx@3
6632 IDirectDraw4 *v7; // eax@4
6633 HRESULT v8; // eax@4
6634 int v9; // ST14_4@5
6635 IDirectDrawSurface *v10; // ST10_4@5
6636 HRESULT v11; // eax@5
6637 IDirectDrawSurface **ppBackBuffer; // [sp-4h] [bp-A4h]@3
6638 const char *v13; // [sp+0h] [bp-A0h]@0
6639 int v14; // [sp+4h] [bp-9Ch]@0
6640 unsigned int v15; // [sp+8h] [bp-98h]@0
6641 DDSURFACEDESC2 ddsd2; // [sp+Ch] [bp-94h]@3
6642 DDSCAPS2 v17; // [sp+88h] [bp-18h]@4
6643 int a4; // [sp+98h] [bp-8h]@3
6644
6645 v1 = this;
6646 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6647 {
6648 v2 = 0;
6649 this->field_4004C = 1;
6650 memset(&ddsd2, 0, 0x7Cu);
6651 v7 = v1->pDirectDraw4;
6652 ddsd2.dwBackBufferCount = 1;
6653 ddsd2.dwSize = 0x7Cu;
6654 ddsd2.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6655 ddsd2.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_3DDEVICE | DDSCAPS_PRIMARYSURFACE;
6656 ErrD3D(v7->CreateSurface(
6657 &ddsd2,
6658 &pFrontBuffer4,
6659 0));
6660 pFrontBuffer = (IDirectDrawSurface *)v1->pFrontBuffer4;
6661 ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer4;
6662 }
6663 else
6664 {
6665 v2 = 0;
6666 this->field_4004C = 1;
6667
6668 DDSURFACEDESC ddsd;
6669 memset(&ddsd, 0, sizeof(DDSURFACEDESC));
6670
6671 ddsd.lpSurface = (LPVOID)1;
6672 ddsd.lPitch = 108;
6673 ddsd.dwBackBufferCount = 33;
6674 ddsd.ddsCaps.dwCaps = 8728;
6675 ErrD3D(pDirectDraw2->CreateSurface(
6676 &ddsd,
6677 (IDirectDrawSurface **)&pFrontBuffer2,
6678 0));
6679
6680 pFrontBuffer = (IDirectDrawSurface *)v1->pFrontBuffer2;
6681 ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer2;
6682 }
6683 v9 = (int)v6;
6684 v10 = pFrontBuffer; // BUG
6685
6686 v17.dwCaps = 4;
6687 ErrD3D(pFrontBuffer->GetAttachedSurface((DDSCAPS *)&v17, ppBackBuffer));// hr = this->pFrontBuffer->GetAttachedSurface(&ddsCaps2, ppBackBuffer);
6688 //CheckHRESULT(&thisa, v11, (const char *)v10, v9, (unsigned int)ppBackBuffer);
6689 v1->field_40030 = v2;
6690 v1->field_18_locked_pitch = v2;
6691 }
6692
6693 //----- (004A14F4) --------------------------------------------------------
6694 void Render::CreateClipper(HWND a2)
6695 {
6696 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6697 {
6698 ErrD3D(pDirectDraw4->CreateClipper(0, &pDDrawClipper, 0));
6699 ErrD3D(pDDrawClipper->SetHWnd(0, a2));
6700 ErrD3D(pFrontBuffer4->SetClipper(pDDrawClipper));
6701 }
6702 else
6703 {
6704 ErrD3D(pDirectDraw2->CreateClipper(0, &pDDrawClipper, 0));
6705 ErrD3D(pDDrawClipper->SetHWnd(0, a2));
6706 }
6707 }
6708
6709 //----- (004A15D8) --------------------------------------------------------
6710 void Render::GetTargetPixelFormat(DDPIXELFORMAT *pOut)
6711 {
6712 IDirectDrawSurface *v2; // eax@3
6713
6714 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6715 v2 = (IDirectDrawSurface *)this->pFrontBuffer4;
6716 else
6717 v2 = (IDirectDrawSurface *)this->pFrontBuffer2;
6718 v2->GetPixelFormat(pOut);
6719 }
6720
6721 //----- (004A1605) --------------------------------------------------------
6722 void Render::LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow)
6723 {
6724 Render *v3; // esi@1
6725 signed int v4; // eax@3
6726
6727 v3 = this;
6728 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6729 {
6730 DDSURFACEDESC2 pDesc; // [sp+4h] [bp-7Ch]@3
6731 memset(&pDesc, 0, 0x7Cu);
6732 pDesc.dwSize = 124;
6733 LockSurface_DDraw4(v3->pBackBuffer4, &pDesc, 1u);
6734 *pOutSurfacePtr = pDesc.lpSurface;
6735 v4 = pDesc.lPitch;
6736 }
6737 else
6738 {
6739 DDSURFACEDESC pDesc; // [sp+4h] [bp-7Ch]@3
6740 memset(&pDesc.lPitch, 0, 0x6Cu);
6741 pDesc.lPitch = 108;
6742 LockSurface_DDraw2(v3->pBackBuffer2, &pDesc, 1u);
6743 *pOutSurfacePtr = (void *)pDesc.lpSurface;
6744 v4 = pDesc.dwReserved;
6745 }
6746 *pOutPixelsPerRow = v4 >> 1;
6747 }
6748
6749 //----- (004A169E) --------------------------------------------------------
6750 bool Render::UsingDirect3D()
6751 {
6752 return bUserDirect3D == 0;
6753 }
6754
6755
6756 //----- (004A16E1) --------------------------------------------------------
6757 void Render::UnlockBackBuffer()
6758 {
6759 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6760 ErrD3D(pBackBuffer4->Unlock(0));
6761 else
6762 ErrD3D(pBackBuffer2->Unlock(0));
6763 }
6764
6765
6766 //----- (004A172E) --------------------------------------------------------
6767 void Render::LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow)
6768 {
6769 Render *v3; // esi@1
6770 signed int v4; // eax@3
6771
6772 v3 = this;
6773 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6774 {
6775 DDSURFACEDESC2 pDesc; // [sp+4h] [bp-7Ch]@3
6776 memset(&pDesc, 0, 0x7Cu);
6777 pDesc.dwSize = 124;
6778 LockSurface_DDraw4(v3->pFrontBuffer4, &pDesc, 1u);
6779 *pOutSurface = pDesc.lpSurface;
6780 v4 = pDesc.lPitch;
6781 }
6782 else
6783 {
6784 DDSURFACEDESC pDesc; // [sp+4h] [bp-7Ch]@3
6785 memset(&pDesc.lPitch, 0, 0x6Cu);
6786 pDesc.lPitch = 108;
6787 LockSurface_DDraw2(v3->pFrontBuffer2, &pDesc, 1u);
6788 *pOutSurface = (void *)pDesc.lpSurface;
6789 v4 = pDesc.dwReserved;
6790 }
6791 *pOutPixelsPerRow = v4 >> 1;
6792 }
6793
6794 //----- (004A17C7) --------------------------------------------------------
6795 void Render::UnlockFrontBuffer()
6796 {
6797 IDirectDrawSurface *pFront; // eax@3
6798 HRESULT v2; // eax@5
6799 signed int v3; // [sp-8h] [bp-Ch]@3
6800 int v4; // [sp-4h] [bp-8h]@3
6801
6802 auto a5 = this;
6803 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6804 {
6805 pFront = (IDirectDrawSurface *)a5->pFrontBuffer4;
6806 v4 = 0;
6807 v3 = 2615;
6808 }
6809 else
6810 {
6811 pFront = (IDirectDrawSurface *)a5->pFrontBuffer2;
6812 v4 = 0;
6813 v3 = 2611;
6814 }
6815 ErrD3D(pFront->Unlock(0));
6816 }
6817
6818
6819 //----- (004A1814) --------------------------------------------------------
6820 void Render::RestoreFrontBuffer()
6821 {
6822 IDirectDrawSurface **v1; // esi@2
6823
6824 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT
6825 || (v1 = (IDirectDrawSurface **)&this->pFrontBuffer2, pVersion->pVersionInfo.dwMajorVersion >= 5u) )
6826 v1 = (IDirectDrawSurface **)&this->pFrontBuffer4;
6827 if ( (*v1)->IsLost() == DDERR_SURFACELOST )
6828 (*v1)->Restore();
6829 }
6830
6831
6832 //----- (004A184C) --------------------------------------------------------
6833 HRESULT Render::_4A184C()
6834 {
6835 IDirectDrawSurface **pBack; // esi@2
6836 HRESULT result; // eax@4
6837
6838 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT
6839 || (pBack = (IDirectDrawSurface **)&this->pBackBuffer2, pVersion->pVersionInfo.dwMajorVersion != 4) )
6840 pBack = (IDirectDrawSurface **)&this->pBackBuffer4;
6841 result = (*pBack)->IsLost();
6842 if ( result == DDERR_SURFACELOST )
6843 result = (*pBack)->Restore();
6844 return result;
6845 }
6846
6847 //----- (004A1884) --------------------------------------------------------
6848 void Render::PresentRect(RECT *a2, RECT *a3)
6849 {
6850 IDirectDrawSurface *pFront; // eax@3
6851 HRESULT v4; // eax@5
6852 IDirectDrawSurface *pBack; // [sp-1Ch] [bp-1Ch]@3
6853 struct tagRECT *v6; // [sp-18h] [bp-18h]@3
6854 DWORD v7; // [sp-14h] [bp-14h]@3
6855 DDBLTFX *v8; // [sp-10h] [bp-10h]@3
6856 const char *v9; // [sp-Ch] [bp-Ch]@3
6857 int v10; // [sp-8h] [bp-8h]@3
6858 unsigned int v11; // [sp-4h] [bp-4h]@3
6859
6860 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6861 {
6862 v11 = 0;
6863 pFront = (IDirectDrawSurface *)this->pFrontBuffer4;
6864 v10 = 2657;
6865 v9 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Screen16.cpp";
6866 v8 = 0;
6867 v7 = DDBLT_WAIT;
6868 v6 = a3;
6869 pBack = (IDirectDrawSurface *)this->pBackBuffer4;
6870 }
6871 else
6872 {
6873 v11 = 0;
6874 pFront = (IDirectDrawSurface *)this->pFrontBuffer2;
6875 v10 = 2653;
6876 v9 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Screen16.cpp";
6877 v8 = 0;
6878 v7 = DDBLT_WAIT;
6879 v6 = a3;
6880 pBack = (IDirectDrawSurface *)this->pBackBuffer2;
6881 }
6882 ErrD3D(pFront->Blt(a2, pBack, v6, v7, v8));
6883 }
6884
6885
6886 //----- (004A18F5) --------------------------------------------------------
6887 void Render::BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags)
6888 {
6889 IDirectDrawSurface *pFront; // eax@3
6890 HRESULT v6; // eax@5
6891 int v7; // [sp-8h] [bp-8h]@3
6892 unsigned int v8; // [sp-4h] [bp-4h]@3
6893
6894 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion >= 5u )
6895 ErrD3D(pFrontBuffer4->Blt(pDstRect, (IDirectDrawSurface4 *)pSrcSurface, pSrcRect, uBltFlags, nullptr));
6896 else
6897 ErrD3D(pFrontBuffer2->Blt(pDstRect, (IDirectDrawSurface2 *)pSrcSurface, pSrcRect, uBltFlags, nullptr));
6898 }
6899
6900 //----- (004A194A) --------------------------------------------------------
6901 void Render::BltBackToFontFast(int a2, int a3, RECT *a4)
6902 {
6903 IDirectDrawSurface *pFront; // eax@3
6904 IDirectDrawSurface *pBack; // [sp-Ch] [bp-Ch]@3
6905 RECT *v6; // [sp-8h] [bp-8h]@3
6906 DWORD v7; // [sp-4h] [bp-4h]@3
6907
6908 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
6909 {
6910 pFront = (IDirectDrawSurface *)this->pFrontBuffer4;
6911 v7 = DDBLTFAST_WAIT;
6912 v6 = a4;
6913 pBack = (IDirectDrawSurface *)this->pBackBuffer4;
6914 }
6915 else
6916 {
6917 pFront = (IDirectDrawSurface *)this->pFrontBuffer2;
6918 v7 = DDBLTFAST_WAIT;
6919 v6 = a4;
6920 pBack = (IDirectDrawSurface *)this->pBackBuffer2;
6921 }
6922 pFront->BltFast(0, 0, pBack, v6, v7);
6923 }
6924
6925 //----- (004A1B22) --------------------------------------------------------
6926 unsigned int Render::Billboard_ProbablyAddToListAndSortByZOrder(unsigned int a1)
6927 {
6928 unsigned int v2; // ebx@1
6929 double v4; // st7@5
6930 unsigned int v5; // esi@5
6931 int v6; // ecx@5
6932 unsigned int v7; // edx@6
6933 char *v8; // ecx@12
6934 void *v9; // edi@16
6935 unsigned int v10; // eax@16
6936 void *v11; // edi@21
6937 unsigned int v12; // eax@21
6938
6939 v2 = pRenderer->uNumBillboardsToDraw;
6940 if ( (signed int)pRenderer->uNumBillboardsToDraw >= 999 )
6941 return 0;
6942 if ( !pRenderer->uNumBillboardsToDraw )
6943 {
6944 pRenderer->uNumBillboardsToDraw = 1;
6945 return 0;
6946 }
6947 v4 = *(float *)&a1;
6948 v5 = pRenderer->uNumBillboardsToDraw;
6949 v6 = 0;
6950 if ( (signed int)pRenderer->uNumBillboardsToDraw <= 0 )
6951 {
6952 v7 = a1;
6953 }
6954 else
6955 {
6956 do
6957 {
6958 v7 = v6 + (signed int)(v5 - v6) / 2;
6959 if ( v4 <= pRenderer->pBillboardRenderListD3D[v6 + (signed int)(v5 - v6) / 2].flt_88 )
6960 v5 = v6 + (signed int)(v5 - v6) / 2;
6961 else
6962 v6 = v7 + 1;
6963 }
6964 while ( v6 < (signed int)v5 );
6965 }
6966 v8 = (char *)&pRenderer->pBillboardRenderListD3D[v7].flt_88;
6967 if ( v4 > *(float *)v8 )
6968 {
6969 if ( v7 == pRenderer->uNumBillboardsToDraw - 1 )
6970 {
6971 v7 = pRenderer->uNumBillboardsToDraw;
6972 }
6973 else
6974 {
6975 if ( (signed int)pRenderer->uNumBillboardsToDraw > (signed int)v7 )
6976 {
6977 v9 = &pRenderer->pBillboardRenderListD3D[pRenderer->uNumBillboardsToDraw];
6978 v10 = pRenderer->uNumBillboardsToDraw - v7;
6979 do
6980 {
6981 memcpy(v9, (char *)v9 - 156, 0x9Cu);
6982 v9 = (char *)v9 - 156;
6983 --v10;
6984 }
6985 while ( v10 );
6986 }
6987 ++v7;
6988 }
6989 LABEL_23:
6990 pRenderer->uNumBillboardsToDraw = v2 + 1;
6991 return v7;
6992 }
6993 if ( v4 <= *(float *)v8 )
6994 {
6995 if ( (signed int)pRenderer->uNumBillboardsToDraw > (signed int)v7 )
6996 {
6997 v11 = &pRenderer->pBillboardRenderListD3D[pRenderer->uNumBillboardsToDraw];
6998 v12 = pRenderer->uNumBillboardsToDraw - v7;
6999 do
7000 {
7001 memcpy(v11, (char *)v11 - 156, 0x9Cu);
7002 v11 = (char *)v11 - 156;
7003 --v12;
7004 }
7005 while ( v12 );
7006 }
7007 goto LABEL_23;
7008 }
7009 return v7;
7010 }
7011
7012
7013 //----- (004A1E9D) --------------------------------------------------------
7014 unsigned int Render::GetBillboardDrawListSize()
7015 {
7016 return pRenderer->uNumBillboardsToDraw;
7017 }
7018
7019 //----- (004A1EA3) --------------------------------------------------------
7020 unsigned int Render::GetParentBillboardID(unsigned int uBillboardID)
7021 {
7022 return pRenderer->pBillboardRenderListD3D[uBillboardID].uParentBillboardID;
7023 }
7024
7025 //----- (004A1EB6) --------------------------------------------------------
7026 void Render::BeginSceneD3D()
7027 {
7028 if (!uNumD3DSceneBegins++)
7029 {
7030 if (pRenderD3D)
7031 {
7032 pRenderD3D->ClearTarget(true, 0x00F08020, true, 1.0);
7033 pRenderer->uNumBillboardsToDraw = 0;
7034 pRenderD3D->pDevice->BeginScene();
7035 if (!pRenderD3D->DoesRaiseExceptions())
7036 {
7037 MessageBoxW(nullptr, L"Error executing scratch 3D operations", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\screen16_3d.cpp:360", 0);
7038 }
7039 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
7040 uFogColor = GetLevelFogColor();
7041 else
7042 uFogColor = 0;
7043
7044 if ( uFogColor & 0xFF000000 )
7045 {
7046 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1);
7047 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, uFogColor & 0xFFFFFF);
7048 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0);
7049 bUsingSpecular = true;
7050 }
7051 else
7052 {
7053 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0);
7054 bUsingSpecular = 0;
7055 }
7056 }
7057 else
7058 {
7059 LockRenderSurface((void **)&pTargetSurface, &uTargetSurfacePitch);
7060 if (pTargetSurface)
7061 field_18_locked_pitch = uTargetSurfacePitch;
7062 else
7063 --uNumD3DSceneBegins;
7064 }
7065 }
7066 }
7067
7068 //----- (004A1FE1) --------------------------------------------------------
7069 void Render::DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene()
7070 {
7071 --uNumD3DSceneBegins;
7072 if (uNumD3DSceneBegins)
7073 return;
7074
7075 if (pRenderD3D)
7076 {
7077 pGame->draw_debug_outlines();
7078 //DoRenderBillboards_D3D(); Ritor1: it's temporarily
7079 pGame->pStru6Instance->RenderSpecialEffects();
7080 pRenderD3D->pDevice->EndScene();
7081 }
7082 else
7083 pGame->pStru6Instance->RenderSpecialEffects();
7084 }
7085
7086
7087
7088 //----- (004A2031) --------------------------------------------------------
7089 unsigned int Render::GetActorTintColor(float a2, int a3, int a4, int a5, RenderBillboard *a6)
7090 {
7091 return ::GetActorTintColor(a3, a4, a2, a5, a6);
7092 }
7093
7094
7095 //----- (004A26BC) --------------------------------------------------------
7096 void Render::DrawTerrainPolygon(unsigned int uNumVertices, stru148 *a4, IDirect3DTexture2 *a5, int a6, int a7)
7097 {
7098 RenderVertexSoft *pVertices; // esi@0
7099 Render *v7; // edi@1
7100 unsigned int v8; // ebx@1
7101 LightmapBuilder *v9; // esi@3
7102 unsigned int v10; // edx@3
7103 int v11; // eax@5
7104 int v12; // eax@11
7105 char *v13; // esi@11
7106 double v14; // st7@13
7107 double v15; // st7@13
7108 signed int v16; // eax@13
7109 int v17; // ecx@13
7110 double v18; // st7@13
7111 float v19; // ST78_4@14
7112 int v20; // eax@14
7113 char v21; // zf@16
7114 HRESULT v22; // eax@17
7115 HRESULT v23; // eax@17
7116 HRESULT v24; // eax@19
7117 HRESULT v25; // eax@19
7118 unsigned int v26; // ecx@19
7119 char *v27; // eax@20
7120 HRESULT v28; // eax@22
7121 HRESULT v29; // eax@22
7122 HRESULT v30; // eax@23
7123 HRESULT v31; // eax@24
7124 HRESULT v32; // eax@24
7125 HRESULT v33; // eax@24
7126 HRESULT v34; // eax@24
7127 HRESULT v35; // eax@25
7128 HRESULT v36; // eax@25
7129 unsigned int v37; // ecx@25
7130 char *v38; // eax@26
7131 int v39; // edx@27
7132 HRESULT v40; // eax@28
7133 HRESULT v41; // eax@28
7134 HRESULT v42; // eax@28
7135 HRESULT v43; // eax@28
7136 //IDirect3DDevice3Vtbl *v44; // ebx@28
7137 unsigned int v45; // eax@28
7138 HRESULT v46; // eax@29
7139 HRESULT v47; // eax@29
7140 HRESULT v48; // eax@29
7141 IDirect3DDevice3 *v49; // eax@35
7142 //IDirect3DDevice3Vtbl *v50; // ecx@35
7143 int v51; // eax@40
7144 char *v52; // esi@40
7145 double v53; // st7@42
7146 double v54; // st7@42
7147 signed int v55; // eax@42
7148 int v56; // ecx@42
7149 double v57; // st7@42
7150 float v58; // ST7C_4@43
7151 int v59; // eax@43
7152 signed int v60; // [sp+78h] [bp-14h]@31
7153 RenderVertexSoft *v61; // [sp+7Ch] [bp-10h]@3
7154 const char *v62; // [sp+80h] [bp-Ch]@0
7155 const char *v63; // [sp+80h] [bp-Ch]@19
7156 int v64; // [sp+84h] [bp-8h]@0
7157 LightmapBuilder *v65; // [sp+88h] [bp-4h]@3
7158 unsigned int v66; // [sp+88h] [bp-4h]@40
7159 unsigned int a6a; // [sp+A0h] [bp+14h]@11
7160
7161 v7 = this;
7162 v8 = 0;
7163 if ( this->uNumD3DSceneBegins && (signed int)uNumVertices >= 3 )
7164 {
7165 v61 = pVertices;
7166 v9 = pGame->pLightmapBuilder;
7167 v65 = v9;
7168 v10 = v9->std__vector_000004_size;
7169 if ( byte_4D864C && pGame->uFlags & 1 )
7170 {
7171 v11 = GetActorTintColor(a4->field_58, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
7172 v9->_45D74F_MessWithLight(v11, 0);
7173 }
7174 else
7175 {
7176 if ( a6 || !v10 || byte_4D864C && pGame->uFlags & 2 )
7177 {
7178 if ( (char)a7 )
7179 v60 = 3;
7180 else
7181 v60 = 1;
7182 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, v60));
7183 if ( a6 || v7->bUsingSpecular )
7184 {
7185 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
7186 //v49 = v7->pRenderD3D->pDevice;
7187 //v50 = v49->lpVtbl;
7188 if ( a6 )
7189 {
7190 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 5));
7191 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 6));
7192 }
7193 else
7194 {
7195 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
7196 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1));
7197 }
7198
7199 }
7200 if ( (signed int)uNumVertices > 0 )
7201 {
7202 v51 = (int)&arary_77E5C8[0].pos.y;
7203 v52 = (char *)&array_50AC10[0].vWorldViewPosition;
7204 a7 = (int)&arary_77E5C8[0].pos.y;
7205 v66 = uNumVertices;
7206 while ( 1 )
7207 {
7208 v53 = *(float *)v52 * 1000.0;
7209 *(int *)(v51 - 4) = *((int *)v52 + 3);
7210 v54 = v53 / (double)pOutdoorCamera->shading_dist_mist;
7211 *(int *)v51 = *((int *)v52 + 4);
7212 *(float *)(v51 + 4) = 1.0 - 1.0 / v54;
7213 *(float *)(v51 + 8) = 1.0 / (*(float *)v52 + 0.0000001);
7214 v55 = GetActorTintColor(a4->field_58, 0, *(float *)v52, 0, 0);
7215 v56 = a7;
7216 v57 = *(float *)v52;
7217 *(int *)(a7 + 12) = v55;
7218 if ( v7->bUsingSpecular )
7219 {
7220 v58 = v57;
7221 v59 = sub_47C3D7_get_fog_related_stuff(0, 0, v58);
7222 v56 = a7;
7223 }
7224 else
7225 {
7226 v59 = 0;
7227 }
7228 *(int *)(v56 + 16) = v59;
7229 *(int *)(v56 + 20) = *((int *)v52 + 6);
7230 *(int *)(v56 + 24) = *((int *)v52 + 7);
7231 v52 += 48;
7232 v21 = v66-- == 1;
7233 a7 = v56 + 32;
7234 if ( v21 )
7235 break;
7236 v51 = a7;
7237 }
7238 }
7239 ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5));
7240 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7241 D3DPT_TRIANGLEFAN,
7242 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7243 arary_77E5C8,
7244 uNumVertices,
7245 16));
7246 if ( a6 )
7247 {
7248 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
7249 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
7250 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
7251 }
7252 }
7253 else
7254 {
7255 if ( (signed int)uNumVertices > 0 )
7256 {
7257 v12 = (int)&arary_77E5C8[0].pos.y;
7258 v13 = (char *)&array_50AC10[0].vWorldViewPosition;
7259 a7 = (int)&arary_77E5C8[0].pos.y;
7260 a6a = uNumVertices;
7261 while ( 1 )
7262 {
7263 v14 = *(float *)v13 * 1000.0;
7264 *(int *)(v12 - 4) = *((int *)v13 + 3);
7265 v15 = v14 / (double)pOutdoorCamera->shading_dist_mist;
7266 *(int *)v12 = *((int *)v13 + 4);
7267 *(float *)(v12 + 4) = 1.0 - 1.0 / v15;
7268 *(float *)(v12 + 8) = 1.0 / (*(float *)v13 + 0.0000001);
7269 v16 = GetActorTintColor(a4->field_58, 0, *(float *)v13, 0, 0);
7270 v17 = a7;
7271 v18 = *(float *)v13;
7272 *(int *)(a7 + 12) = v16;
7273 if ( v7->bUsingSpecular )
7274 {
7275 v19 = v18;
7276 v20 = sub_47C3D7_get_fog_related_stuff(0, 0, v19);
7277 v17 = a7;
7278 }
7279 else
7280 {
7281 v20 = 0;
7282 }
7283 *(int *)(v17 + 16) = v20;
7284 *(int *)(v17 + 20) = *((int *)v13 + 6);
7285 *(int *)(v17 + 24) = *((int *)v13 + 7);
7286 v13 += 48;
7287 v21 = a6a-- == 1;
7288 a7 = v17 + 32;
7289 if ( v21 )
7290 break;
7291 v12 = a7;
7292 }
7293 }
7294 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
7295 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
7296 if ( pRenderer->bUsingSpecular )
7297 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
7298
7299 ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));
7300 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7301 D3DPT_TRIANGLEFAN,
7302 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7303 arary_77E5C8,
7304 uNumVertices,
7305 16));
7306 //v63 = (const char *)v7->pRenderD3D->pDevice;
7307 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1));
7308 //(*(void (**)(void))(*(int *)v63 + 88))();
7309 pGame->pLightmapBuilder->_45D74F_MessWithLight(-1, 0);
7310 v26 = uNumVertices;
7311 if ( (signed int)uNumVertices > 0 )
7312 {
7313 v27 = (char *)&arary_77E5C8[0].diffuse;
7314 do
7315 {
7316 *(int *)v27 = -1;
7317 v27 += 32;
7318 --v26;
7319 }
7320 while ( v26 );
7321 }
7322 ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5));
7323 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
7324 if ( !pRenderer->bUsingSpecular )
7325 {
7326 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
7327 }
7328 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
7329 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 1u));
7330 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3u));
7331 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7332 D3DPT_TRIANGLEFAN,
7333 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7334 arary_77E5C8,
7335 uNumVertices,
7336 16));
7337 if ( pRenderer->bUsingSpecular )
7338 {
7339 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
7340 ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));
7341 v37 = uNumVertices;
7342 if ( (signed int)uNumVertices > 0 )
7343 {
7344 v38 = (char *)&arary_77E5C8[0].specular;
7345 do
7346 {
7347 v39 = *(int *)v38;
7348 *(int *)v38 = 0;
7349 v38 += 32;
7350 --v37;
7351 *((int *)v38 - 9) = pRenderer->uFogColor | v39 & 0xFF000000;
7352 }
7353 while ( v37 );
7354 }
7355 ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));
7356 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 6u));
7357 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 5u));
7358 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7359 D3DPT_TRIANGLEFAN,
7360 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7361 arary_77E5C8,
7362 uNumVertices,
7363 16));
7364 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1));
7365 //v44 = pRenderer->pRenderD3D->pDevice;
7366 v45 = GetLevelFogColor();
7367 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, v45 & 0xFFFFFF));
7368 v8 = 0;
7369 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
7370 }
7371 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
7372 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
7373 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, v8));
7374 }
7375 }
7376 if ( pIndoorCamera->field_4C & 2 || pBLVRenderParams->uFlags & 2 )
7377 pGame->pIndoorCameraD3D->debug_outline_d3d(arary_77E5C8, uNumVertices, 0xFFFFFFu, 0.0);
7378 }
7379 }
7380 // 4A26BC: could not find valid save-restore pair for esi
7381 // 4D864C: using guessed type char byte_4D864C;
7382
7383
7384 //----- (004A2DA3) --------------------------------------------------------
7385 void Render::DrawFan(unsigned int uNumVertices, stru148 *a3, IDirect3DTexture2 *a4)
7386 {
7387 Render *v4; // ebx@1
7388 char *v5; // esi@6
7389 char *v6; // edi@6
7390 double v7; // st7@7
7391 float v8; // ST34_4@7
7392 int v9; // eax@7
7393 signed int v10; // eax@7
7394 double v11; // st7@7
7395 int v12; // eax@7
7396 float v13; // ST3C_4@8
7397 unsigned int v14; // [sp+4Ch] [bp-4h]@6
7398
7399 v4 = this;
7400 if ( this->uNumD3DSceneBegins && (signed int)uNumVertices >= 3 )
7401 {
7402 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
7403 if ( v4->bUsingSpecular )
7404 {
7405 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
7406 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
7407 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
7408 }
7409 if ( (signed int)uNumVertices > 0 )
7410 {
7411 v5 = (char *)&arary_77E5C8[0].pos.y;
7412 v6 = (char *)&array_50AC10[0].vWorldViewProjY;
7413 v14 = uNumVertices;
7414 do
7415 {
7416 v7 = *((float *)v6 - 4);
7417 *((int *)v5 - 1) = *((int *)v6 - 1);
7418 v8 = v7;
7419 *(int *)v5 = *(int *)v6;
7420 v9 = *((int *)v6 + 1);
7421 *((int *)v5 + 1) = 0x3F7FF972u;
7422 *((int *)v5 + 2) = v9;
7423 v10 = GetActorTintColor(31, 0, v8, 1, 0);
7424 v11 = *((float *)v6 - 4);
7425 *((int *)v5 + 3) = v10;
7426 v12 = 0;
7427 if ( v4->bUsingSpecular )
7428 {
7429 v13 = v11;
7430 v12 = sub_47C3D7_get_fog_related_stuff(0, 1, v13);
7431 }
7432 *((int *)v5 + 4) = v12;
7433 *((int *)v5 + 5) = *((int *)v6 + 2);
7434 *((int *)v5 + 6) = *((int *)v6 + 3);
7435 v6 += 48;
7436 v5 += 32;
7437 --v14;
7438 }
7439 while ( v14 );
7440 }
7441 ErrD3D(pRenderD3D->pDevice->SetTexture(0, a4));
7442 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7443 D3DPT_TRIANGLEFAN,
7444 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7445 arary_77E5C8,
7446 uNumVertices,
7447 24));
7448 }
7449 }
7450
7451
7452 //----- (004A2ED5) --------------------------------------------------------
7453 void Render::_4A2ED5(signed int a2, stru148 *a3, IDirect3DTexture2 *pHwTex)
7454 {
7455 signed int v4; // edi@2
7456 int v5; // eax@3
7457 int v6; // edx@5
7458 char *v7; // eax@6
7459 char *v8; // ecx@6
7460 double v9; // st6@7
7461 int v10; // ebx@7
7462 int v11; // ebx@7
7463
7464 if ( this->uNumD3DSceneBegins )
7465 {
7466 v4 = a2;
7467 if ( a2 >= 3 )
7468 {
7469 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
7470 v5 = 31 - (a3->field_58 & 0x1F);
7471 if ( v5 < pOutdoor->field_CBC_terrain_triangles_shade_type )
7472 v5 = pOutdoor->field_CBC_terrain_triangles_shade_type;
7473 v6 = 8 * v5 | ((8 * v5 | (v5 << 11)) << 8);
7474 if ( a2 > 0 )
7475 {
7476 v7 = (char *)&arary_77E5C8[0].pos.y;
7477 v8 = (char *)&array_507D30[0].vWorldViewProjY;
7478 do
7479 {
7480 v9 = *((float *)v8 - 4) * 0.061758894;
7481 v10 = *((int *)v8 - 1);
7482 *((int *)v7 + 4) = 0;
7483 *((int *)v7 - 1) = v10;
7484 *(int *)v7 = *(int *)v8;
7485 *((int *)v7 + 2) = *((int *)v8 + 1);
7486 *((int *)v7 + 5) = *((int *)v8 + 2);
7487 v11 = *((int *)v8 + 3);
7488 *((int *)v7 + 3) = v6;
7489 *((int *)v7 + 6) = v11;
7490 v8 += 48;
7491 v7 += 32;
7492 --v4;
7493 *((float *)v7 - 7) = 1.0 - 1.0 / v9;
7494 }
7495 while ( v4 );
7496 }
7497 ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
7498 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7499 D3DPT_TRIANGLEFAN,
7500 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7501 arary_77E5C8,
7502 a2,
7503 28));
7504 }
7505 }
7506 }
7507
7508
7509
7510 //----- (004A2FC0) --------------------------------------------------------
7511 void Render::DrawIndoorPolygon(unsigned int uNumVertices, BLVFace *pFace, IDirect3DTexture2 *pHwTex, Texture *pTex, int uPackedID, unsigned int uColor, int a8)
7512 {
7513 //Render *v8; // edi@1
7514 //unsigned int v9; // esi@3
7515 char *v12; // ecx@9
7516 char *v13; // eax@9
7517 double v14; // st6@10
7518 int v15; // edx@10
7519 Texture *v16; // edx@10
7520 double v17; // st6@10
7521 //char v18; // zf@10
7522 Texture *v19; // edx@10
7523 Texture *v23; // edx@16
7524 char *v24; // ecx@16
7525 char *v25; // eax@16
7526 double v26; // st6@17
7527 int v27; // esi@17
7528 double v28; // st6@17
7529 unsigned int v33; // ecx@18
7530 char *v34; // eax@19
7531 //Texture *v45; // edx@23
7532 //char *v46; // ecx@23
7533 //char *v47; // eax@23
7534 //double v48; // st6@24
7535 //int v49; // esi@24
7536 //double v50; // st6@24
7537 const char *v53; // [sp-Ch] [bp-20h]@21
7538 //int v54; // [sp-8h] [bp-1Ch]@21
7539 //unsigned int v55; // [sp-4h] [bp-18h]@21
7540 const char *v56; // [sp+0h] [bp-14h]@0
7541 int v57; // [sp+4h] [bp-10h]@0
7542 unsigned int v58; // [sp+8h] [bp-Ch]@0
7543 //LightmapBuilder *v59; // [sp+Ch] [bp-8h]@3
7544 //int a3a; // [sp+10h] [bp-4h]@4
7545
7546 //v8 = this;
7547 if (!uNumD3DSceneBegins || uNumVertices < 3)
7548 return;
7549
7550 //auto a3 = pFace;
7551 //auto a6 = uPackedID;
7552 //v59 = pGame->pLightmapBuilder;
7553 //v9 = v59->std__vector_000004_size;
7554
7555 auto uCorrectedColor = uColor;
7556 if (pGame->pLightmapBuilder->std__vector_000004_size)
7557 uCorrectedColor = 0xFFFFFFFF;
7558 pGame->AlterGamma(pFace, &uCorrectedColor);
7559
7560 if (byte_4D864C && pGame->uFlags & 1)
7561 {
7562 __debugbreak();
7563 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
7564 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
7565 if ( (signed int)uNumVertices > 0 )
7566 {
7567 v12 = (char *)&array_507D30[0].vWorldViewPosition;
7568 v13 = (char *)&arary_77E5C8[0].pos.y;
7569 auto a7 = uNumVertices;
7570 uint v18;
7571 do
7572 {
7573 v14 = *(float *)v12 * 0.061758894;
7574 v15 = *((int *)v12 + 3);
7575 *((int *)v13 + 4) = 0;
7576 *((int *)v13 - 1) = v15;
7577 *(int *)v13 = *((int *)v12 + 4);
7578 *((int *)v13 + 3) = uCorrectedColor;
7579 v16 = pTex;
7580 v13 += 32;
7581 *((float *)v13 - 7) = 1.0 - 1.0 / v14;
7582 v17 = 1.0 / *(float *)v12;
7583 v12 += 48;
7584 v18 = a7-- == 1;
7585 *((float *)v13 - 6) = v17;
7586 pHwTex = (IDirect3DTexture2 *)v16->uTextureWidth;
7587 v19 = pTex;
7588 *((float *)v13 - 3) = *((float *)v12 - 6) / (double)(signed int)pHwTex;
7589 pHwTex = (IDirect3DTexture2 *)v19->uTextureHeight;
7590 *((float *)v13 - 2) = *((float *)v12 - 5) / (double)(signed int)pHwTex;
7591 }
7592 while ( !v18 );
7593 }
7594 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
7595 ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
7596 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7597 D3DPT_TRIANGLEFAN,
7598 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7599 arary_77E5C8,
7600 uNumVertices,
7601 28));
7602 pGame->pLightmapBuilder->_45D74F_MessWithLight(-1, 0);
7603 }
7604 else
7605 {
7606 if (!pGame->pLightmapBuilder->std__vector_000004_size ||
7607 byte_4D864C && pGame->uFlags & 2)
7608 {
7609 for (uint i = 0; i < uNumVertices; ++i)
7610 {
7611 arary_77E5C8[i].pos.x = array_507D30[i].vWorldViewProjX;
7612 arary_77E5C8[i].pos.y = array_507D30[i].vWorldViewProjY;
7613 arary_77E5C8[i].pos.z = 1.0 - 1.0 / (array_507D30[i].vWorldViewPosition.x * 0.061758894);
7614 arary_77E5C8[i].rhw = 1.0 / array_507D30[i].vWorldViewPosition.x;
7615 arary_77E5C8[i].diffuse = uCorrectedColor;
7616 arary_77E5C8[i].specular = 0;
7617 arary_77E5C8[i].texcoord.x = array_507D30[i].u / (double)pTex->uTextureWidth;
7618 arary_77E5C8[i].texcoord.y = array_507D30[i].v / (double)pTex->uTextureHeight;
7619 }
7620
7621 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
7622 ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
7623 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
7624 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7625 arary_77E5C8,
7626 uNumVertices,
7627 28));
7628 }
7629 else
7630 {
7631 __debugbreak();
7632 if ( (signed int)uNumVertices > 0 )
7633 {
7634 v23 = pTex;
7635 v24 = (char *)&array_507D30[0].vWorldViewPosition;
7636 v25 = (char *)&arary_77E5C8[0].pos.y;
7637 pTex = (Texture *)uNumVertices;
7638 uint v18;
7639 do
7640 {
7641 v26 = *(float *)v24 * 0.061758894;
7642 v27 = *((int *)v24 + 3);
7643 *((int *)v25 + 4) = 0;
7644 *((int *)v25 - 1) = v27;
7645 *(int *)v25 = *((int *)v24 + 4);
7646 *((int *)v25 + 3) = uColor;
7647 v25 += 32;
7648 *((float *)v25 - 7) = 1.0 - 1.0 / v26;
7649 v28 = 1.0 / *(float *)v24;
7650 v24 += 48;
7651 v18 = pTex == (Texture *)1;
7652 pTex = (Texture *)((char *)pTex - 1);
7653 *((float *)v25 - 6) = v28;
7654 //a3 = (BLVFace *)v23->uTextureWidth;
7655 *((float *)v25 - 3) = *((float *)v24 - 6) / (double)(signed int)v23->uTextureWidth;
7656 //a3 = (BLVFace *)v23->uTextureHeight;
7657 *((float *)v25 - 2) = *((float *)v24 - 5) / (double)(signed int)v23->uTextureHeight;
7658 }
7659 while ( !v18 );
7660 }
7661 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
7662 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
7663 ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
7664 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7665 D3DPT_TRIANGLEFAN,
7666 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7667 arary_77E5C8,
7668 uNumVertices,
7669 28));
7670 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1));
7671 pGame->pLightmapBuilder->_45D74F_MessWithLight(-1, 0);
7672 v33 = uNumVertices;
7673 if ( (signed int)uNumVertices > 0 )
7674 {
7675 v34 = (char *)&arary_77E5C8[0].diffuse;
7676 do
7677 {
7678 *(int *)v34 = uCorrectedColor;
7679 v34 += 32;
7680 --v33;
7681 }
7682 while ( v33 );
7683 }
7684 ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
7685 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1));
7686 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
7687 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
7688 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 1));
7689 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3));
7690 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
7691 D3DPT_TRIANGLEFAN,
7692 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
7693 arary_77E5C8,
7694 uNumVertices,
7695 28));
7696 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
7697 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1));
7698 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false));
7699 }
7700 }
7701 }
7702 // 4D864C: using guessed type char byte_4D864C;
7703
7704
7705 //----- (004A43B1) --------------------------------------------------------
7706 void Render::DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *a3, int uPaletteSubindex)
7707 {
7708 RenderBillboardTransform_local0 *v4; // ebx@2
7709 double v5; // st7@2
7710 float v6; // ST08_4@2
7711 unsigned int v7; // eax@2
7712 int v8; // ecx@2
7713 unsigned int v9; // esi@2
7714 Sprite *v10; // edi@5
7715 signed int v11; // eax@9
7716 signed int v12; // eax@9
7717 double v13; // st7@12
7718 double v14; // st6@12
7719 double v15; // st5@12
7720 double v16; // st4@12
7721 double v17; // st3@12
7722 double v18; // st2@12
7723 int v19; // ecx@14
7724 double v20; // st3@14
7725 int v21; // ecx@16
7726 double v22; // st3@16
7727 IDirect3DTexture2 *v23; // eax@18
7728 signed int v24; // [sp+18h] [bp-18h]@5
7729 signed int v25; // [sp+1Ch] [bp-14h]@5
7730 Render *v26; // [sp+20h] [bp-10h]@1
7731 float v27; // [sp+24h] [bp-Ch]@5
7732 int v28; // [sp+28h] [bp-8h]@2
7733 float v29; // [sp+2Ch] [bp-4h]@5
7734 float pSoftBillboarda; // [sp+38h] [bp+8h]@2
7735 float v31; // [sp+3Ch] [bp+Ch]@5
7736 float v32; // [sp+3Ch] [bp+Ch]@12
7737 float a1; // [sp+40h] [bp+10h]@5
7738
7739 v26 = this;
7740 if ( this->uNumD3DSceneBegins )
7741 {
7742 v4 = pSoftBillboard;
7743 v5 = (double)HIWORD(pSoftBillboard->sZValue);
7744 pSoftBillboarda = v5;
7745 v6 = v5;
7746 v7 = Billboard_ProbablyAddToListAndSortByZOrder(LODWORD(v6));
7747 v8 = uPaletteSubindex;
7748 v9 = v7;
7749 v28 = uPaletteSubindex & 0xFF000000;
7750 if ( uPaletteSubindex & 0xFF000000 )
7751 pBillboardRenderListD3D[v9].uOpacity = RenderBillboardD3D::Opaque_3;
7752 else
7753 pBillboardRenderListD3D[v9].uOpacity = RenderBillboardD3D::Transparent;
7754 v10 = a3;
7755 pBillboardRenderListD3D[v9].field_90 = v4->field_44;
7756 pBillboardRenderListD3D[v9].sZValue = v4->sZValue;
7757 pBillboardRenderListD3D[v9].uParentBillboardID = v4->uParentBillboardID;
7758 v25 = v4->uScreenSpaceX;
7759 v24 = v4->uScreenSpaceY;
7760 a1 = (double)(v4->field_10 & 0xFFFF) * 0.000015260186 + (double)HIWORD(v4->field_10);
7761 v29 = (double)(v4->field_14 & 0xFFFF) * 0.000015260186 + (double)HIWORD(v4->field_14);
7762 v31 = (double)((v10->uBufferWidth >> 1) - v10->uAreaX);
7763 v27 = (double)(v10->uBufferHeight - v10->uAreaY);
7764 if ( v4->uFlags & 4 )
7765 v31 = v31 * -1.0;
7766 if ( v4->uTintColor && v26->bTinting )
7767 {
7768 v11 = GetActorTintColor(v8, 0, pSoftBillboarda, 0, 0);
7769 v12 = sub_4A19D8(v4->uTintColor, v11);
7770 if ( v28 )
7771 v12 = (unsigned int)((char *)&array_77EC08[1852].pEdgeList1[17] + 3) & ((unsigned int)v12 >> 1);
7772 }
7773 else
7774 {
7775 v12 = GetActorTintColor(v8, 0, pSoftBillboarda, 0, 0);
7776 }
7777 v13 = (double)v25;
7778 pBillboardRenderListD3D[v9].pQuards[0].specular = 0;
7779 pBillboardRenderListD3D[v9].pQuards[0].diffuse = v12;
7780 pBillboardRenderListD3D[v9].pQuards[0].pos.x = v13 - v31 * a1;
7781 v14 = (double)v24;
7782 v32 = v14;
7783 pBillboardRenderListD3D[v9].pQuards[0].pos.y = v14 - v27 * v29;
7784 v15 = 1.0 - 1.0 / (pSoftBillboarda * 0.061758894);
7785 pBillboardRenderListD3D[v9].pQuards[0].pos.z = v15;
7786 v16 = 1.0 / pSoftBillboarda;
7787 pBillboardRenderListD3D[v9].pQuards[0].rhw = 1.0 / pSoftBillboarda;
7788 pBillboardRenderListD3D[v9].pQuards[0].texcoord.x = 0.0;
7789 pBillboardRenderListD3D[v9].pQuards[0].texcoord.y = 0.0;
7790 v17 = (double)((v10->uBufferWidth >> 1) - v10->uAreaX);
7791 v18 = (double)(v10->uBufferHeight - v10->uAreaY - v10->uAreaHeight);
7792 if ( v4->uFlags & 4 )
7793 v17 = v17 * -1.0;
7794 pBillboardRenderListD3D[v9].pQuards[1].specular = 0;
7795 pBillboardRenderListD3D[v9].pQuards[1].diffuse = v12;
7796 pBillboardRenderListD3D[v9].pQuards[1].pos.x = v13 - v17 * a1;
7797 pBillboardRenderListD3D[v9].pQuards[1].pos.y = v32 - v18 * v29;
7798 pBillboardRenderListD3D[v9].pQuards[1].pos.z = v15;
7799 pBillboardRenderListD3D[v9].pQuards[1].rhw = v16;
7800 pBillboardRenderListD3D[v9].pQuards[1].texcoord.x = 0.0;
7801 pBillboardRenderListD3D[v9].pQuards[1].texcoord.y = 1.0;
7802 v19 = v10->uBufferHeight - v10->uAreaY - v10->uAreaHeight;
7803 v20 = (double)(v10->uAreaX + v10->uAreaWidth + (v10->uBufferWidth >> 1) - v10->uBufferWidth);
7804 if ( v4->uFlags & 4 )
7805 v20 = v20 * -1.0;
7806 pBillboardRenderListD3D[v9].pQuards[2].specular = 0;
7807 pBillboardRenderListD3D[v9].pQuards[2].diffuse = v12;
7808 pBillboardRenderListD3D[v9].pQuards[2].pos.x = v20 * a1 + v13;
7809 pBillboardRenderListD3D[v9].pQuards[2].pos.y = v32 - (double)v19 * v29;
7810 pBillboardRenderListD3D[v9].pQuards[2].pos.z = v15;
7811 pBillboardRenderListD3D[v9].pQuards[2].rhw = v16;
7812 pBillboardRenderListD3D[v9].pQuards[2].texcoord.x = 1.0;
7813 pBillboardRenderListD3D[v9].pQuards[2].texcoord.y = 1.0;
7814 v21 = v10->uBufferHeight - v10->uAreaY;
7815 v22 = (double)(v10->uAreaX + v10->uAreaWidth + (v10->uBufferWidth >> 1) - v10->uBufferWidth);
7816 if ( v4->uFlags & 4 )
7817 v22 = v22 * -1.0;
7818 pBillboardRenderListD3D[v9].pQuards[3].specular = 0;
7819 pBillboardRenderListD3D[v9].pQuards[3].diffuse = v12;
7820 pBillboardRenderListD3D[v9].pQuards[3].pos.x = v22 * a1 + v13;
7821 pBillboardRenderListD3D[v9].pQuards[3].pos.y = v32 - (double)v21 * v29;
7822 pBillboardRenderListD3D[v9].pQuards[3].pos.z = v15;
7823 pBillboardRenderListD3D[v9].pQuards[3].rhw = v16;
7824 pBillboardRenderListD3D[v9].pQuards[3].texcoord.x = 1.0;
7825 pBillboardRenderListD3D[v9].pQuards[3].texcoord.y = 0.0;
7826 v23 = v10->pTexture;
7827 pBillboardRenderListD3D[v9].uNumVertices = 4;
7828 pBillboardRenderListD3D[v9].flt_88 = pSoftBillboarda;
7829 pBillboardRenderListD3D[v9].pTexture = v23;
7830 }
7831 }
7832
7833
7834
7835 //----- (004A354F) --------------------------------------------------------
7836 void Render::MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle)
7837 {
7838 double v5; // st7@3
7839 float v6; // ST20_4@3
7840 float v7; // ST00_4@3
7841 unsigned int v8; // esi@3
7842 int v9; // eax@3
7843 int v10; // ebx@3
7844 float v11; // ST28_4@3
7845 double v12; // st7@3
7846 float v13; // ST24_4@3
7847 double v14; // st6@3
7848 float v15; // ST1C_4@3
7849 float v16; // ST2C_4@3
7850 float v17; // ST30_4@3
7851 signed int v18; // ST18_4@3
7852 signed int v19; // ST14_4@3
7853 signed int v20; // ST10_4@3
7854 signed int v21; // eax@3
7855 double v22; // st6@3
7856 float v23; // ST2C_4@3
7857 float v24; // ST30_4@3
7858 signed int v25; // ST10_4@3
7859 signed int v26; // ST14_4@3
7860 signed int v27; // ST18_4@3
7861 signed int v28; // eax@3
7862 double v29; // st6@3
7863 float v30; // ecx@3
7864 float v31; // ST2C_4@3
7865 float v32; // ST30_4@3
7866 signed int v33; // ST10_4@3
7867 signed int v34; // ST14_4@3
7868 signed int v35; // ST18_4@3
7869 signed int v36; // eax@3
7870 float v37; // ecx@3
7871 double v38; // st6@3
7872 float v39; // ST2C_4@3
7873 float v40; // ST30_4@3
7874 signed int v41; // ST10_4@3
7875 signed int v42; // ST14_4@3
7876 signed int v43; // ST18_4@3
7877 signed int v44; // eax@3
7878 double v45; // st6@3
7879 float v46; // eax@3
7880
7881 if ( this->uNumD3DSceneBegins )
7882 {
7883 if ( HIWORD(a2->sZValue) )
7884 {
7885 v5 = (double)HIWORD(a2->sZValue);
7886 v6 = v5;
7887 v7 = v5;
7888 v8 = Billboard_ProbablyAddToListAndSortByZOrder(LODWORD(v7));
7889 pBillboardRenderListD3D[v8].uOpacity = RenderBillboardD3D::Opaque_1;
7890 pBillboardRenderListD3D[v8].field_90 = a2->field_44;
7891 pBillboardRenderListD3D[v8].sZValue = a2->sZValue;
7892 pBillboardRenderListD3D[v8].uParentBillboardID = a2->uParentBillboardID;
7893 v9 = a2->uScreenSpaceX;
7894 v10 = a2->uScreenSpaceY;
7895 v11 = (double)(a2->field_10 & 0xFFFF) * 0.000015260186 + (double)HIWORD(a2->field_10);
7896 v12 = (double)v9;
7897 v13 = v12;
7898 v14 = (double)(v10 - 12);
7899 v15 = v14;
7900 v16 = (double)(v9 - 12) - v12;
7901 v17 = (double)(v10 - 25) - v14;
7902 v18 = stru_5C6E00->SinCos(angle);
7903 v19 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7904 v20 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7905 v21 = stru_5C6E00->SinCos(angle);
7906 pBillboardRenderListD3D[v8].pQuards[0].pos.x = (((double)(unsigned __int16)v18 * 0.000015259022
7907 + (double)(v18 >> 16))
7908 * v16
7909 - ((double)(unsigned __int16)v19 * 0.000015259022
7910 + (double)(v19 >> 16))
7911 * v17)
7912 * v11 + v13;
7913 v22 = (((double)(unsigned __int16)v21 * 0.000015259022 + (double)(v21 >> 16)) * v17
7914 + ((double)(unsigned __int16)v20 * 0.000015259022 + (double)(v20 >> 16)) * v16
7915 - 12.0)
7916 * v11
7917 + (double)a2->uScreenSpaceY;
7918 pBillboardRenderListD3D[v8].pQuards[0].specular = 0;
7919 pBillboardRenderListD3D[v8].pQuards[0].diffuse = uDiffuse;
7920 pBillboardRenderListD3D[v8].pQuards[0].pos.y = v22;
7921 pBillboardRenderListD3D[v8].pQuards[0].pos.z = 1.0 - 1.0 / (v6 * 0.061758894);
7922 pBillboardRenderListD3D[v8].pQuards[0].rhw = 1.0 / v6;
7923 pBillboardRenderListD3D[v8].pQuards[0].texcoord.x = 0.0;
7924 pBillboardRenderListD3D[v8].pQuards[0].texcoord.y = 0.0;
7925 v31 = (double)(a2->uScreenSpaceX + 12) - v13;
7926 v32 = (double)a2->uScreenSpaceY - v15;
7927 v25 = stru_5C6E00->SinCos(angle);
7928 v26 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7929 v27 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7930 v28 = stru_5C6E00->SinCos(angle);
7931 pBillboardRenderListD3D[v8].pQuards[1].pos.x = (((double)(unsigned __int16)v25 * 0.000015259022
7932 + (double)(v25 >> 16))
7933 * v23
7934 - ((double)(unsigned __int16)v26 * 0.000015259022
7935 + (double)(v26 >> 16))
7936 * v24)
7937 * v11 + v13;
7938 v29 = (((double)(unsigned __int16)v28 * 0.000015259022 + (double)(v28 >> 16)) * v24
7939 + ((double)(unsigned __int16)v27 * 0.000015259022 + (double)(v27 >> 16)) * v23
7940 - 12.0)
7941 * v11
7942 + (double)a2->uScreenSpaceY;
7943 pBillboardRenderListD3D[v8].pQuards[1].pos.z = pRenderer->pBillboardRenderListD3D[v8].pQuards[0].pos.z;
7944 v30 = pBillboardRenderListD3D[v8].pQuards[0].rhw;
7945 pBillboardRenderListD3D[v8].pQuards[1].pos.y = v29;
7946 pBillboardRenderListD3D[v8].pQuards[1].specular = 0;
7947 pBillboardRenderListD3D[v8].pQuards[1].rhw = v30;
7948 pBillboardRenderListD3D[v8].pQuards[1].diffuse = uDiffuse;
7949 pBillboardRenderListD3D[v8].pQuards[1].texcoord.x = 0.0;
7950 pBillboardRenderListD3D[v8].pQuards[1].texcoord.y = 1.0;
7951 v23 = (double)(a2->uScreenSpaceX - 12) - v13;
7952 v24 = (double)a2->uScreenSpaceY - v15;
7953 v33 = stru_5C6E00->SinCos(angle);
7954 v34 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7955 v35 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7956 v36 = stru_5C6E00->SinCos(angle);
7957 pBillboardRenderListD3D[v8].pQuards[2].pos.x = (((double)(unsigned __int16)v33 * 0.000015259022
7958 + (double)(v33 >> 16))
7959 * v31
7960 - ((double)(unsigned __int16)v34 * 0.000015259022
7961 + (double)(v34 >> 16))
7962 * v32)
7963 * v11 + v13;
7964 v37 = pBillboardRenderListD3D[v8].pQuards[0].pos.z;
7965 v38 = (((double)(unsigned __int16)v36 * 0.000015259022 + (double)(v36 >> 16)) * v32
7966 + ((double)(unsigned __int16)v35 * 0.000015259022 + (double)(v35 >> 16)) * v31
7967 - 12.0)
7968 * v11
7969 + (double)a2->uScreenSpaceY;
7970 pBillboardRenderListD3D[v8].pQuards[2].specular = 0;
7971 pBillboardRenderListD3D[v8].pQuards[2].pos.z = v37;
7972 pBillboardRenderListD3D[v8].pQuards[2].rhw = pBillboardRenderListD3D[v8].pQuards[0].rhw;
7973 pBillboardRenderListD3D[v8].pQuards[2].diffuse = uDiffuse;
7974 pBillboardRenderListD3D[v8].pQuards[2].pos.y = v38;
7975 pBillboardRenderListD3D[v8].pQuards[2].texcoord.x = 1.0;
7976 pBillboardRenderListD3D[v8].pQuards[2].texcoord.y = 1.0;
7977 v39 = (double)(a2->uScreenSpaceX + 12) - v13;
7978 v40 = (double)(a2->uScreenSpaceY - 25) - v15;
7979 v41 = stru_5C6E00->SinCos(angle);
7980 v42 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7981 v43 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
7982 v44 = stru_5C6E00->SinCos(angle);
7983 pBillboardRenderListD3D[v8].pQuards[3].pos.x = (((double)(unsigned __int16)v41 * 0.000015259022
7984 + (double)(v41 >> 16))
7985 * v39
7986 - ((double)(unsigned __int16)v42 * 0.000015259022
7987 + (double)(v42 >> 16))
7988 * v40)
7989 * v11 + v13;
7990 v45 = (((double)(unsigned __int16)v44 * 0.000015259022 + (double)(v44 >> 16)) * v40
7991 + ((double)(unsigned __int16)v43 * 0.000015259022 + (double)(v43 >> 16)) * v39
7992 - 12.0)
7993 * v11
7994 + (double)a2->uScreenSpaceY;
7995 v46 = pBillboardRenderListD3D[v8].pQuards[0].pos.z;
7996 pBillboardRenderListD3D[v8].pQuards[3].specular = 0;
7997 pBillboardRenderListD3D[v8].pQuards[3].pos.z = v46;
7998 pBillboardRenderListD3D[v8].pQuards[3].rhw = pBillboardRenderListD3D[v8].pQuards[0].rhw;
7999 pBillboardRenderListD3D[v8].pQuards[3].diffuse = uDiffuse;
8000 pBillboardRenderListD3D[v8].pTexture = a3;
8001 pBillboardRenderListD3D[v8].flt_88 = v6;
8002 pBillboardRenderListD3D[v8].uNumVertices = 4;
8003 pBillboardRenderListD3D[v8].pQuards[3].pos.y = v45;
8004 pBillboardRenderListD3D[v8].pQuards[3].texcoord.x = 1.0;
8005 pBillboardRenderListD3D[v8].pQuards[3].texcoord.y = 0.0;
8006 }
8007 }
8008 }
8009
8010
8011 //----- (004A3AD9) --------------------------------------------------------
8012 void Render::MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle)
8013 {
8014 double v5; // st7@2
8015 float v6; // ST28_4@2
8016 float v7; // ST00_4@2
8017 unsigned int v8; // esi@2
8018 int v9; // eax@2
8019 int v10; // ebx@2
8020 float v11; // ST34_4@2
8021 double v12; // st7@2
8022 float v13; // ST2C_4@2
8023 double v14; // st6@2
8024 float v15; // ST24_4@2
8025 float v16; // ST38_4@2
8026 float v17; // ST3C_4@2
8027 signed int v18; // ST1C_4@2
8028 int v19; // ST30_4@2
8029 signed int v20; // ST20_4@2
8030 signed int v21; // ST18_4@2
8031 signed int v22; // eax@2
8032 double v23; // st6@2
8033 float v24; // ST20_4@2
8034 float v25; // ST1C_4@2
8035 float v26; // ST38_4@2
8036 float v27; // ST3C_4@2
8037 signed int v28; // ST18_4@2
8038 signed int v29; // ST14_4@2
8039 signed int v30; // ST10_4@2
8040 signed int v31; // eax@2
8041 double v32; // st6@2
8042 float v33; // ST38_4@2
8043 float v34; // ST3C_4@2
8044 signed int v35; // ST10_4@2
8045 signed int v36; // ST14_4@2
8046 signed int v37; // ST18_4@2
8047 signed int v38; // eax@2
8048 double v39; // st6@2
8049 float v40; // ST38_4@2
8050 float v41; // ST3C_4@2
8051 signed int v42; // ST10_4@2
8052 signed int v43; // ST14_4@2
8053 signed int v44; // ST18_4@2
8054 signed int v45; // eax@2
8055 double v46; // st6@2
8056
8057 if ( this->uNumD3DSceneBegins )
8058 {
8059 v5 = (double)HIWORD(a2->sZValue);
8060 v6 = v5;
8061 v7 = v5;
8062 v8 = Billboard_ProbablyAddToListAndSortByZOrder(LODWORD(v7));
8063 pBillboardRenderListD3D[v8].uOpacity = RenderBillboardD3D::Opaque_1;
8064 pBillboardRenderListD3D[v8].field_90 = a2->field_44;
8065 pBillboardRenderListD3D[v8].sZValue = a2->sZValue;
8066 pBillboardRenderListD3D[v8].uParentBillboardID = a2->uParentBillboardID;
8067 v9 = a2->uScreenSpaceX;
8068 v10 = a2->uScreenSpaceY;
8069 v11 = (double)(a2->field_10 & 0xFFFF) * 0.000015260186 + (double)HIWORD(a2->field_10);
8070 v12 = (double)v9;
8071 v13 = v12;
8072 v14 = (double)(v10 - 12);
8073 v15 = v14;
8074 v16 = (double)(v9 - 12) - v12;
8075 v17 = (double)(v10 - 25) - v14;
8076 v18 = stru_5C6E00->SinCos(angle);
8077 v19 = angle - stru_5C6E00->uIntegerHalfPi;
8078 v20 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
8079 v21 = stru_5C6E00->SinCos(v19);
8080 v22 = stru_5C6E00->SinCos(angle);
8081 pBillboardRenderListD3D[v8].pQuards[0].pos.x = (((double)(unsigned __int16)v18 * 0.000015259022
8082 + (double)(v18 >> 16))
8083 * v16
8084 - ((double)(unsigned __int16)v20 * 0.000015259022
8085 + (double)(v20 >> 16))
8086 * v17)
8087 * v11 + v13;
8088 v23 = (((double)(unsigned __int16)v22 * 0.000015259022 + (double)(v22 >> 16)) * v17
8089 + ((double)(unsigned __int16)v21 * 0.000015259022 + (double)(v21 >> 16)) * v16
8090 - 12.0)
8091 * v11
8092 + (double)a2->uScreenSpaceY;
8093 pBillboardRenderListD3D[v8].pQuards[0].specular = 0;
8094 pBillboardRenderListD3D[v8].pQuards[0].diffuse = uDiffuse;
8095 pBillboardRenderListD3D[v8].pQuards[0].pos.y = v23;
8096 v24 = 1.0 - 1.0 / (v6 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist);
8097 pBillboardRenderListD3D[v8].pQuards[0].pos.z = v24;
8098 v25 = 1.0 / v6;
8099 pBillboardRenderListD3D[v8].pQuards[0].rhw = v25;
8100 pBillboardRenderListD3D[v8].pQuards[0].texcoord.x = 0.0;
8101 pBillboardRenderListD3D[v8].pQuards[0].texcoord.y = 0.0;
8102 v26 = (double)(a2->uScreenSpaceX - 12) - v13;
8103 v27 = (double)a2->uScreenSpaceY - v15;
8104 v28 = stru_5C6E00->SinCos(angle);
8105 v29 = stru_5C6E00->SinCos(v19);
8106 v30 = stru_5C6E00->SinCos(v19);
8107 v31 = stru_5C6E00->SinCos(angle);
8108 pBillboardRenderListD3D[v8].pQuards[1].pos.x = (((double)(unsigned __int16)v28 * 0.000015259022
8109 + (double)(v28 >> 16))
8110 * v26
8111 - ((double)(unsigned __int16)v29 * 0.000015259022
8112 + (double)(v29 >> 16))
8113 * v27)
8114 * v11 + v13;
8115 v32 = (((double)(unsigned __int16)v31 * 0.000015259022 + (double)(v31 >> 16)) * v27
8116 + ((double)(unsigned __int16)v30 * 0.000015259022 + (double)(v30 >> 16)) * v26
8117 - 12.0)
8118 * v11
8119 + (double)a2->uScreenSpaceY;
8120 pBillboardRenderListD3D[v8].pQuards[1].pos.z = v24;
8121 pBillboardRenderListD3D[v8].pQuards[1].pos.y = v32;
8122 pBillboardRenderListD3D[v8].pQuards[1].specular = 0;
8123 pBillboardRenderListD3D[v8].pQuards[1].rhw = v25;
8124 pBillboardRenderListD3D[v8].pQuards[1].diffuse = uDiffuse;
8125 pBillboardRenderListD3D[v8].pQuards[1].texcoord.x = 0.0;
8126 pBillboardRenderListD3D[v8].pQuards[1].texcoord.y = 1.0;
8127 v33 = (double)(a2->uScreenSpaceX + 12) - v13;
8128 v34 = (double)a2->uScreenSpaceY - v15;
8129 v35 = stru_5C6E00->SinCos(angle);
8130 v36 = stru_5C6E00->SinCos(v19);
8131 v37 = stru_5C6E00->SinCos(v19);
8132 v38 = stru_5C6E00->SinCos(angle);
8133 pBillboardRenderListD3D[v8].pQuards[2].pos.x = (((double)(unsigned __int16)v35 * 0.000015259022
8134 + (double)(v35 >> 16))
8135 * v33
8136 - ((double)(unsigned __int16)v36 * 0.000015259022
8137 + (double)(v36 >> 16))
8138 * v34)
8139 * v11 + v13;
8140 v39 = (((double)(unsigned __int16)v38 * 0.000015259022 + (double)(v38 >> 16)) * v34
8141 + ((double)(unsigned __int16)v37 * 0.000015259022 + (double)(v37 >> 16)) * v33
8142 - 12.0)
8143 * v11
8144 + (double)a2->uScreenSpaceY;
8145 pBillboardRenderListD3D[v8].pQuards[2].specular = 0;
8146 pBillboardRenderListD3D[v8].pQuards[2].pos.z = v24;
8147 pBillboardRenderListD3D[v8].pQuards[2].rhw = v25;
8148 pBillboardRenderListD3D[v8].pQuards[2].diffuse = uDiffuse;
8149 pBillboardRenderListD3D[v8].pQuards[2].pos.y = v39;
8150 pBillboardRenderListD3D[v8].pQuards[2].texcoord.x = 1.0;
8151 pBillboardRenderListD3D[v8].pQuards[2].texcoord.y = 1.0;
8152 v40 = (double)(a2->uScreenSpaceX + 12) - v13;
8153 v41 = (double)(a2->uScreenSpaceY - 25) - v15;
8154 v42 = stru_5C6E00->SinCos(angle);
8155 v43 = stru_5C6E00->SinCos(v19);
8156 v44 = stru_5C6E00->SinCos(v19);
8157 v45 = stru_5C6E00->SinCos(angle);
8158 pBillboardRenderListD3D[v8].pQuards[3].pos.x = (((double)(unsigned __int16)v42 * 0.000015259022
8159 + (double)(v42 >> 16))
8160 * v40
8161 - ((double)(unsigned __int16)v43 * 0.000015259022
8162 + (double)(v43 >> 16))
8163 * v41)
8164 * v11 + v13;
8165 v46 = (((double)(unsigned __int16)v45 * 0.000015259022 + (double)(v45 >> 16)) * v41
8166 + ((double)(unsigned __int16)v44 * 0.000015259022 + (double)(v44 >> 16)) * v40
8167 - 12.0)
8168 * v11
8169 + (double)a2->uScreenSpaceY;
8170 pBillboardRenderListD3D[v8].pQuards[3].specular = 0;
8171 pBillboardRenderListD3D[v8].pQuards[3].pos.z = v24;
8172 pBillboardRenderListD3D[v8].pQuards[3].rhw = v25;
8173 pBillboardRenderListD3D[v8].pQuards[3].diffuse = uDiffuse;
8174 pBillboardRenderListD3D[v8].pTexture = a3;
8175 pBillboardRenderListD3D[v8].flt_88 = v6;
8176 pBillboardRenderListD3D[v8].uNumVertices = 4;
8177 pBillboardRenderListD3D[v8].pQuards[3].pos.y = v46;
8178 pBillboardRenderListD3D[v8].pQuards[3].texcoord.x = 1.0;
8179 pBillboardRenderListD3D[v8].pQuards[3].texcoord.y = 0.0;
8180 }
8181 }
8182
8183
8184 //----- (004A4023) --------------------------------------------------------
8185 void Render::TransformBillboard(RenderBillboardTransform_local0 *a2, Sprite *pSprite, int a1a, RenderBillboard *pBillboard)
8186 {
8187 RenderBillboardTransform_local0 *v5; // ebx@2
8188 double v6; // st7@2
8189 float v7; // ST08_4@2
8190 unsigned int v8; // esi@2
8191 Sprite *v9; // edi@5
8192 signed int v10; // eax@9
8193 signed int v11; // eax@9
8194 int v12; // eax@12
8195 double v13; // st7@12
8196 double v14; // st6@14
8197 double v15; // st5@14
8198 unsigned int v16; // ecx@16
8199 double v17; // st7@16
8200 double v18; // st5@16
8201 double v19; // st4@16
8202 double v20; // st5@18
8203 double v21; // st4@18
8204 IDirect3DTexture2 *v22; // eax@20
8205 signed int v23; // [sp+18h] [bp-18h]@5
8206 signed int v24; // [sp+1Ch] [bp-14h]@5
8207 float v25; // [sp+1Ch] [bp-14h]@12
8208 float v26; // [sp+20h] [bp-10h]@5
8209 float v27; // [sp+20h] [bp-10h]@12
8210 Render *a3; // [sp+24h] [bp-Ch]@1
8211 float v29; // [sp+28h] [bp-8h]@5
8212 float v30; // [sp+2Ch] [bp-4h]@5
8213 float v31; // [sp+38h] [bp+8h]@2
8214 float pSpritea; // [sp+3Ch] [bp+Ch]@5
8215 float a1b; // [sp+40h] [bp+10h]@12
8216 float pBillboarda; // [sp+44h] [bp+14h]@12
8217
8218 auto a1 = this;
8219 a3 = a1;
8220 if ( a1->uNumD3DSceneBegins )
8221 {
8222 v5 = a2;
8223 v6 = (double)HIWORD(a2->sZValue);
8224 v31 = v6;
8225 v7 = v6;
8226 v8 = Billboard_ProbablyAddToListAndSortByZOrder(LODWORD(v7));
8227 if ( BYTE3(v5->uTintColor) )
8228 pBillboardRenderListD3D[v8].uOpacity = RenderBillboardD3D::Opaque_3;
8229 else
8230 pBillboardRenderListD3D[v8].uOpacity = RenderBillboardD3D::Transparent;
8231 v9 = pSprite;
8232 pBillboardRenderListD3D[v8].field_90 = v5->field_44;
8233 pBillboardRenderListD3D[v8].sZValue = v5->sZValue;
8234 pBillboardRenderListD3D[v8].uParentBillboardID = v5->uParentBillboardID;
8235 v24 = v5->uScreenSpaceX;
8236 v23 = v5->uScreenSpaceY;
8237 v30 = (double)(v5->field_10 & 0xFFFF) * 0.000015260186 + (double)HIWORD(v5->field_10);
8238 v29 = (double)(v5->field_14 & 0xFFFF) * 0.000015260186 + (double)HIWORD(v5->field_14);
8239 pSpritea = (double)((v9->uBufferWidth >> 1) - v9->uAreaX);
8240 v26 = (double)(v9->uBufferHeight - v9->uAreaY);
8241 if ( v5->uFlags & 4 )
8242 pSpritea = pSpritea * -1.0;
8243 if ( v5->uTintColor & 0xFFFFFF && a3->bTinting )
8244 {
8245 v10 = GetActorTintColor(a1a, 0, v31, 0, pBillboard);
8246 v11 = sub_4A19D8(v5->uTintColor, v10);
8247 if ( BYTE3(v5->uTintColor) )
8248 v11 = (unsigned int)((char *)&array_77EC08[1852].pEdgeList1[17] + 3) & ((unsigned int)v11 >> 1);
8249 }
8250 else
8251 {
8252 v11 = GetActorTintColor(a1a, 0, v31, 0, pBillboard);
8253 }
8254 pBillboardRenderListD3D[v8].pQuards[0].diffuse = v11;
8255 v12 = 0;
8256 pBillboarda = (double)v24;
8257 pBillboardRenderListD3D[v8].pQuards[0].pos.x = pBillboarda - pSpritea * v30;
8258 a1b = (double)v23;
8259 pBillboardRenderListD3D[v8].pQuards[0].pos.y = a1b - v26 * v29;
8260 v27 = v31 * 1000.0;
8261 v13 = 1.0;
8262 pBillboardRenderListD3D[v8].pQuards[0].pos.z = 1.0
8263 - 1.0 / (v27 / (double)pOutdoorCamera->shading_dist_mist);
8264 v25 = 1.0 / v31;
8265 pBillboardRenderListD3D[v8].pQuards[0].rhw = v25;
8266 if ( a3->bUsingSpecular )
8267 {
8268 v12 = sub_47C3D7_get_fog_related_stuff(0, 0, v31);
8269 v13 = 1.0;
8270 }
8271 pBillboardRenderListD3D[v8].pQuards[0].specular = v12;
8272 pBillboardRenderListD3D[v8].pQuards[0].texcoord.x = 0.0;
8273 pBillboardRenderListD3D[v8].pQuards[0].texcoord.y = 0.0;
8274 v14 = (double)((v9->uBufferWidth >> 1) - v9->uAreaX);
8275 v15 = (double)(v9->uBufferHeight - v9->uAreaHeight - v9->uAreaY);
8276 if ( v5->uFlags & 4 )
8277 v14 = v14 * -1.0;
8278 v16 = pBillboardRenderListD3D[v8].pQuards[0].diffuse;
8279 pBillboardRenderListD3D[v8].pQuards[1].specular = v12;
8280 pBillboardRenderListD3D[v8].pQuards[1].diffuse = v16;
8281 pBillboardRenderListD3D[v8].pQuards[1].pos.x = pBillboarda - v14 * v30;
8282 pBillboardRenderListD3D[v8].pQuards[1].pos.y = a1b - v15 * v29;
8283 v17 = v13 - v13 / (v27 / (double)pOutdoorCamera->shading_dist_mist);
8284 pBillboardRenderListD3D[v8].pQuards[1].pos.z = v17;
8285 pBillboardRenderListD3D[v8].pQuards[1].rhw = v25;
8286 pBillboardRenderListD3D[v8].pQuards[1].texcoord.x = 0.0;
8287 pBillboardRenderListD3D[v8].pQuards[1].texcoord.y = 1.0;
8288 v18 = (double)(v9->uAreaWidth + v9->uAreaX + (v9->uBufferWidth >> 1) - v9->uBufferWidth);
8289 v19 = (double)(v9->uBufferHeight - v9->uAreaHeight - v9->uAreaY);
8290 if ( v5->uFlags & 4 )
8291 v18 = v18 * -1.0;
8292 pBillboardRenderListD3D[v8].pQuards[2].diffuse = v16;
8293 pBillboardRenderListD3D[v8].pQuards[2].specular = v12;
8294 pBillboardRenderListD3D[v8].pQuards[2].pos.x = v18 * v30 + pBillboarda;
8295 pBillboardRenderListD3D[v8].pQuards[2].pos.y = a1b - v19 * v29;
8296 pBillboardRenderListD3D[v8].pQuards[2].pos.z = v17;
8297 pBillboardRenderListD3D[v8].pQuards[2].rhw = v25;
8298 pBillboardRenderListD3D[v8].pQuards[2].texcoord.x = 1.0;
8299 pBillboardRenderListD3D[v8].pQuards[2].texcoord.y = 1.0;
8300 v20 = (double)(v9->uAreaWidth + v9->uAreaX + (v9->uBufferWidth >> 1) - v9->uBufferWidth);
8301 v21 = (double)(v9->uBufferHeight - v9->uAreaY);
8302 if ( v5->uFlags & 4 )
8303 v20 = v20 * -1.0;
8304 pBillboardRenderListD3D[v8].pQuards[3].diffuse = v16;
8305 pBillboardRenderListD3D[v8].pQuards[3].specular = v12;
8306 pBillboardRenderListD3D[v8].pQuards[3].pos.x = v20 * v30 + pBillboarda;
8307 pBillboardRenderListD3D[v8].pQuards[3].pos.y = a1b - v21 * v29;
8308 pBillboardRenderListD3D[v8].pQuards[3].pos.z = v17;
8309 pBillboardRenderListD3D[v8].pQuards[3].rhw = v25;
8310 pBillboardRenderListD3D[v8].pQuards[3].texcoord.x = 1.0;
8311 pBillboardRenderListD3D[v8].pQuards[3].texcoord.y = 0.0;
8312 v22 = v9->pTexture;
8313 pBillboardRenderListD3D[v8].uNumVertices = 4;
8314 pBillboardRenderListD3D[v8].pTexture = v22;
8315 pBillboardRenderListD3D[v8].flt_88 = v31;
8316 }
8317 }
8318
8319
8320 //----- (004A48E4) --------------------------------------------------------
8321 int Render::MakeParticleBillboardAndPush_BLV_Software(int screenSpaceX, int screenSpaceY, int z, int lightColor, int a6)
8322 {
8323 int v6; // ecx@1
8324 int v7; // ebx@1
8325 int v8; // ecx@1
8326 int v9; // edx@1
8327 int v10; // edi@1
8328 unsigned int x; // esi@1
8329 int result; // eax@8
8330 int v13; // [sp+Ch] [bp-10h]@1
8331 int v14; // [sp+10h] [bp-Ch]@1
8332 int v15; // [sp+14h] [bp-8h]@1
8333 int v16; // [sp+18h] [bp-4h]@1
8334 int v17; // [sp+24h] [bp+8h]@1
8335 unsigned int v18; // [sp+28h] [bp+Ch]@1
8336 int v19; // [sp+34h] [bp+18h]@1
8337
8338 v6 = screenSpaceX;
8339 v7 = (a6 >> 1) + screenSpaceY;
8340 v17 = 0;
8341 v15 = 0;
8342 v8 = (a6 >> 1) + v6;
8343 v14 = (a6 >> 1) * (a6 >> 1);
8344 v9 = 2 * (a6 >> 1);
8345 v10 = (a6 >> 1) * ((a6 >> 1) - 1);
8346 x = v8 - (a6 >> 1);
8347 v16 = (a6 >> 1) + screenSpaceY - v8;
8348 v19 = a6 >> 1;
8349 v13 = v9;
8350 v18 = v8;
8351 do
8352 {
8353 sr_4A46E6_draw_particle_segment(x, v16 + v18, z, 2 * v19, lightColor);
8354 if ( v15 )
8355 sr_4A46E6_draw_particle_segment(x, v17 + v7, z, 2 * v19, lightColor);
8356 v14 -= v15;
8357 if ( v14 <= v10 )
8358 {
8359 if ( v19 != v17 )
8360 {
8361 sr_4A46E6_draw_particle_segment(v18, v16 + x, z, 2 * v17, lightColor);
8362 sr_4A46E6_draw_particle_segment(v18, v19 + v7, z, 2 * v17, lightColor);
8363 }
8364 --v19;
8365 v13 -= 2;
8366 ++x;
8367 v10 -= v13;
8368 }
8369 result = v17++;
8370 v15 += 2;
8371 --v18;
8372 }
8373 while ( result < v19 );
8374 return result;
8375 }
8376
8377 //----- (004A49D0) --------------------------------------------------------
8378 void Render::DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9)
8379 {
8380 int v10; // eax@1
8381 unsigned int v11; // ebx@1
8382 unsigned int v12; // ecx@1
8383 int v13; // edx@2
8384 int v14; // edx@4
8385 unsigned int v15; // edx@6
8386 double v16; // st7@7
8387 double v17; // st7@7
8388 double v18; // st6@7
8389 double v19; // st4@7
8390 double v20; // st4@8
8391 double v21; // st4@10
8392 double v22; // st4@10
8393 double v23; // st4@10
8394 double v24; // st4@10
8395 double v25; // st4@11
8396 double v26; // st4@13
8397 double v27; // st5@13
8398 double v28; // st4@13
8399 RenderVertexD3D3 v29[4]; // [sp+0h] [bp-94h]@7
8400 double v30; // [sp+80h] [bp-14h]@1
8401 int v31; // [sp+88h] [bp-Ch]@1
8402 signed int v32; // [sp+8Ch] [bp-8h]@1
8403 int X; // [sp+90h] [bp-4h]@1
8404 float a3a; // [sp+A4h] [bp+10h]@10
8405 float a4a; // [sp+A8h] [bp+14h]@10
8406
8407 *(float *)&X = dstX - srcX;
8408 v30 = *(float *)&X + 6.7553994e15;
8409 v31 = LODWORD(v30);
8410 *(float *)&v32 = dstY - srcY;
8411 v30 = *(float *)&v32 + 6.7553994e15;
8412 X = LODWORD(v30);
8413 HIDWORD(v30) = abs(COERCE_UNSIGNED_INT64(*(float *)&v32 + 6.7553994e15));
8414 v10 = abs(v31);
8415 v32 = v10;
8416 v11 = HIDWORD(v30);
8417 v12 = 0;
8418 if ( v10 < SHIDWORD(v30) )
8419 {
8420 v13 = v10;
8421 v10 = HIDWORD(v30);
8422 v11 = v13;
8423 }
8424 if ( v10 < 0 )
8425 {
8426 v14 = v10;
8427 v10 = 0;
8428 v12 = v14;
8429 }
8430 if ( (signed int)v11 < (signed int)v12 )
8431 {
8432 v15 = v12;
8433 v12 = v11;
8434 v11 = v15;
8435 }
8436 v32 = (11 * v11 >> 5) + (v12 >> 2) + v10;
8437 v16 = 1.0 / (double)v32;
8438 *(float *)&v31 = (double)v31 * v16;
8439 *(float *)&X = (double)X * v16;
8440 v17 = *(float *)&X * a4;
8441 v29[0].pos.x = srcX + v17;
8442 v18 = *(float *)&v31 * a4;
8443 v29[0].pos.y = srcY - v18;
8444 v19 = a3;
8445 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
8446 v20 = v19 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist;
8447 else
8448 v20 = v19 * 0.061758894;
8449 v29[0].diffuse = -1;
8450 v29[0].specular = 0;
8451 v29[0].pos.z = 1.0 - 1.0 / v20;
8452 v21 = 1.0 / a3;
8453 *((float *)&v30 + 1) = v21;
8454 v29[0].rhw = v21;
8455 v29[0].texcoord.x = 1.0;
8456 v29[0].texcoord.y = 0.0;
8457 v22 = *(float *)&X * a8;
8458 a3a = v22;
8459 v29[1].pos.x = v22 + dstX;
8460 v23 = *(float *)&v31 * a8;
8461 a4a = v23;
8462 v29[1].pos.y = dstY - v23;
8463 v24 = a7;
8464 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
8465 v25 = v24 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist;
8466 else
8467 v25 = v24 * 0.061758894;
8468 v29[2].diffuse = -1;
8469 v29[3].diffuse = -1;
8470 *(_QWORD *)&v29[3].pos.z = __PAIR__(HIDWORD(v30), LODWORD(v29[0].pos.z));
8471 v29[1].diffuse = -16711936;
8472 v29[1].specular = 0;
8473 v29[2].specular = 0;
8474 v29[3].specular = 0;
8475 v26 = 1.0 - 1.0 / v25;
8476 v29[1].pos.z = v26;
8477 v27 = v26;
8478 v28 = 1.0 / a7;
8479 v29[1].rhw = v28;
8480 v29[1].texcoord.x = 1.0;
8481 v29[1].texcoord.y = 1.0;
8482 v29[2].pos.x = dstX - a3a;
8483 v29[2].pos.y = a4a + dstY;
8484 v29[2].pos.z = v27;
8485 v29[2].rhw = v28;
8486 v29[2].texcoord.x = 0.0;
8487 v29[2].texcoord.y = 1.0;
8488 v29[3].pos.x = srcX - v17;
8489 v29[3].pos.y = v18 + srcY;
8490 v29[3].texcoord.x = 0.0;
8491 v29[3].texcoord.y = 0.0;
8492 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
8493 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
8494 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
8495 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
8496 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
8497 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u));
8498 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, a9));
8499 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(
8500 D3DPT_TRIANGLEFAN,
8501 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
8502 v29,
8503 4,
8504 24));
8505 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
8506 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
8507 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
8508 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
8509 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
8510 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2u));
8511 }
8512
8513
8514 //----- (004A4CC9) --------------------------------------------------------
8515 void Render::_4A4CC9(stru6_stru1_indoor_sw_billboard *a1, int a2)
8516 {
8517 int v3; // eax@1
8518 int v4; // edx@3
8519 unsigned int v5; // eax@7
8520 int v6; // edi@7
8521 char *v7; // edx@8
8522 char *v8; // ecx@8
8523 char v9; // zf@9
8524 double v10; // st6@9
8525 double v11; // st6@10
8526 int v12; // ebx@13
8527 int v13; // ecx@16
8528 unsigned int v14; // [sp+Ch] [bp-4h]@1
8529
8530 auto _this = this;
8531
8532 *(float *)&v14 = 1000000.0;
8533 v3 = a1->field_10;
8534 if ( v3 >= 3 )
8535 {
8536 if ( v3 > 0 )
8537 {
8538 _this = (Render *)&a1->field_14[62];
8539 v4 = a1->field_10;
8540 do
8541 {
8542 if ( *(float *)&this->bUserDirect3D < (double)*(float *)&v14 )
8543 v14 = this->bUserDirect3D;
8544 _this = (Render *)((char *)_this + 16);
8545 --v4;
8546 }
8547 while ( v4 );
8548 }
8549 v5 = Billboard_ProbablyAddToListAndSortByZOrder(v14);
8550 v6 = 0;
8551 pBillboardRenderListD3D[v5].field_90 = 0;
8552 pBillboardRenderListD3D[v5].uParentBillboardID = -1;
8553 pBillboardRenderListD3D[v5].uOpacity = RenderBillboardD3D::Opaque_2;
8554 if ( a1->field_10 > 0 )
8555 {
8556 v7 = (char *)&a1->field_14[62];
8557 v8 = (char *)&pBillboardRenderListD3D[v5].pQuards[0].pos.z;
8558 do
8559 {
8560 v9 = uCurrentlyLoadedLevelType == LEVEL_Indoor;
8561 *((int *)v8 - 2) = *((int *)v7 - 2);
8562 *((int *)v8 - 1) = *((int *)v7 - 1);
8563 v10 = *(float *)v7;
8564 if ( v9 )
8565 v11 = v10 * 0.061758894;
8566 else
8567 v11 = v10 * 1000.0 / (double)pOutdoorCamera->shading_dist_mist;
8568 *(float *)v8 = 1.0 - 1.0 / v11;
8569 *((float *)v8 + 1) = 1.0 / *(float *)v7;
8570 if ( a2 & 0xFF000000 )
8571 v12 = *((int *)v7 + 1);
8572 else
8573 v12 = a2;
8574 *((int *)v8 + 3) = 0;
8575 *((int *)v8 + 2) = v12;
8576 ++v6;
8577 v7 += 16;
8578 *((float *)v8 + 4) = 0.0;
8579 *((float *)v8 + 5) = 0.0;
8580 v8 += 32;
8581 }
8582 while ( v6 < a1->field_10 );
8583 }
8584 v13 = a1->field_10;
8585 pBillboardRenderListD3D[v5].pTexture = 0;
8586 pBillboardRenderListD3D[v5].uNumVertices = v13;
8587 LODWORD(pBillboardRenderListD3D[v5].flt_88) = v14;
8588 }
8589 }
8590
8591
8592 //----- (004A4DE1) --------------------------------------------------------
8593 bool Render::LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture)
8594 {
8595 HRESULT v12; // eax@14
8596 unsigned __int16 *v13; // ecx@19
8597 unsigned __int16 *v14; // eax@19
8598 DWORD v15; // edx@20
8599 HRESULT v16; // eax@23
8600 stru350 Dst; // [sp+Ch] [bp-F8h]@12
8601
8602 auto pHWLTexture = pD3DBitmaps.LoadTexture(pName, bMipMaps);
8603 if ( pHWLTexture )
8604 {
8605 bMipMaps = !strncmp(pName, "HDWTR", 5);
8606 if ( !pRenderD3D->CreateTexture(
8607 pHWLTexture->uWidth,
8608 pHWLTexture->uHeight,
8609 pOutSurface,
8610 pOutTexture,
8611 true,
8612 bMipMaps,
8613 uMinDeviceTextureDim) )
8614 Abortf("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0);
8615 //v10 = *pOutSurface;
8616 //v11 = 0;
8617 if ( bMipMaps )
8618 {
8619 Dst._450DDE();
8620 //v20 = 0;
8621 Dst._450DF1(&stru_4EFCBC, &stru_4EFCBC);
8622
8623 IDirectDrawSurface4 *pNextSurf = *pOutSurface;
8624 while ( 1 )
8625 {
8626 DDSCAPS2 v19;
8627 memset(&v19, 0, sizeof(DDSCAPS2));
8628 v19.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
8629
8630 DDSURFACEDESC2 desc;
8631 memset(&desc, 0, sizeof(DDSURFACEDESC2));
8632 desc.dwSize = sizeof(DDSURFACEDESC2);
8633
8634 if ( LockSurface_DDraw4(pNextSurf, &desc, 0x21u) )
8635 {
8636 Dst.sub_451007_scale_image_bicubic(
8637 pHWLTexture->pPixels,
8638 pHWLTexture->uWidth,
8639 pHWLTexture->uHeight,
8640 pHWLTexture->uWidth,
8641 (unsigned short *)desc.lpSurface,
8642 desc.dwWidth,
8643 desc.dwHeight,
8644 desc.lPitch >> 1,
8645 0,
8646 0);
8647 ErrD3D(pNextSurf->Unlock(0));
8648 //bMipMaps = 0x4D86ACu;
8649 }
8650 if (FAILED(pNextSurf->GetAttachedSurface(&v19, &pNextSurf)))
8651 break;
8652 //v10 = (IDirectDrawSurface4 *)pName;
8653 //v11 = 0;
8654 }
8655 //v20 = -1;
8656 //nullsub_1();
8657 }
8658 else
8659 {
8660 DDSCAPS2 v19;
8661 memset(&v19, 0, sizeof(DDSCAPS2));
8662 v19.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
8663
8664 DDSURFACEDESC2 desc;
8665 memset(&desc, 0, sizeof(DDSURFACEDESC2));
8666 desc.dwSize = sizeof(DDSURFACEDESC2);
8667
8668 if ( LockSurface_DDraw4(*pOutSurface, &desc, 0x21u) )
8669 {
8670 bMipMaps = 0;
8671 v13 = pHWLTexture->pPixels;
8672 v14 = (unsigned __int16 *)desc.lpSurface;
8673 if ( desc.dwHeight )
8674 {
8675 do
8676 {
8677 v15 = 0;
8678 if ( desc.dwWidth )
8679 {
8680 do
8681 {
8682 ++v15;
8683 *v14 = *v13;
8684 ++v14;
8685 ++v13;
8686 }
8687 while ( v15 < desc.dwWidth );
8688 }
8689 ++bMipMaps;
8690 v14 += (desc.lPitch >> 1) - desc.dwWidth;
8691 }
8692 while ( bMipMaps < desc.dwHeight );
8693 }
8694 ErrD3D((*pOutSurface)->Unlock(0));
8695 }
8696 }
8697 delete [] pHWLTexture->pPixels;
8698 delete pHWLTexture;
8699 return true;
8700 }
8701 return false;
8702 }
8703
8704 //----- (004A5048) --------------------------------------------------------
8705 HWLTexture *Render::MoveSpriteToDevice(Sprite *pSprite)
8706 {
8707 Sprite *v2; // edi@1
8708 Render *v3; // ebx@1
8709 HWLTexture *result; // eax@1
8710 HWLTexture *v5; // esi@1
8711 unsigned int v6; // ST18_4@2
8712 RenderD3D *v7; // ecx@2
8713 Sprite *v8; // ebx@4
8714 unsigned __int16 *v9; // edx@5
8715 LPVOID v10; // eax@5
8716 signed int v11; // ebx@5
8717 signed int v12; // ecx@6
8718 signed int v13; // edi@7
8719 HRESULT v14; // eax@10
8720 DDSURFACEDESC2 Dst; // [sp+Ch] [bp-7Ch]@4
8721
8722 v2 = pSprite;
8723 v3 = this;
8724 result = pD3DSprites.LoadTexture(pSprite->pName, pSprite->uPaletteID);
8725 v5 = result;
8726 if ( result )
8727 {
8728 v3->_gpu_memory_used += 2 * result->uWidth * result->uHeight;
8729 v2->uAreaX = result->field_30;
8730 v2->uAreaY = result->field_34;
8731 v2->uBufferWidth = result->field_18;
8732 v2->uBufferHeight = result->field_1C;
8733 v2->uAreaWidth = result->field_20;
8734 v2->uAreaHeight = result->field_24;
8735 v6 = v3->uMinDeviceTextureDim;
8736 v7 = v3->pRenderD3D;
8737 if ( !v7->CreateTexture(result->uWidth, result->uHeight, &v2->pTextureSurface, &v2->pTexture, 1u, 0, v6) )
8738 Abortf("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0);
8739 //pSprite = v2->pTextureSurface;
8740 //pSprite = (Sprite *)pSprite->pName;
8741 //v8 = pSprite;
8742 memset(&Dst, 0, 0x7Cu);
8743 Dst.dwSize = 124;
8744 if ( LockSurface_DDraw4((IDirectDrawSurface4 *)v2->pTextureSurface, &Dst, 0x21u) )
8745 {
8746 v9 = v5->pPixels;
8747 v10 = Dst.lpSurface;
8748 v11 = 0;
8749 if ( (signed int)v5->uHeight > 0 )
8750 {
8751 v12 = (signed int)v5->uWidth >> 1;
8752 do
8753 {
8754 v13 = 0;
8755 if ( v12 > 0 )
8756 {
8757 do
8758 {
8759 ++v13;
8760 *(int *)v10 = *(int *)v9;
8761 v9 += 2;
8762 v10 = (char *)v10 + 4;
8763 }
8764 while ( v13 < (signed int)v5->uWidth >> 1 );
8765 }
8766 v12 = (signed int)v5->uWidth >> 1;
8767 ++v11;
8768 v10 = (char *)v10 + 4 * ((Dst.lPitch >> 2) - v12);
8769 }
8770 while ( v11 < (signed int)v5->uHeight );
8771 }
8772 ErrD3D(v2->pTextureSurface->Unlock(0));
8773 }
8774 free(v5->pPixels);
8775 free(v5);
8776 result = (HWLTexture *)1;
8777 }
8778 return result;
8779 }
8780
8781 //----- (004A51CB) --------------------------------------------------------
8782 void Render::BeginScene()
8783 {
8784 Render *v1; // esi@1
8785 unsigned int v2; // eax@1
8786 int v3; // eax@5
8787 unsigned __int16 **v4; // edi@6
8788 char *v5; // ebx@7
8789 DDSURFACEDESC2 Dst; // [sp+Ch] [bp-7Ch]@4
8790
8791 v1 = this;
8792 v2 = this->uNumSceneBegins;
8793 this->uNumSceneBegins = v2 + 1;
8794 if ( !v2 )
8795 {
8796 if ( this->pRenderD3D )
8797 {
8798 if ( this->bColorKeySupported )
8799 {
8800 memset(&Dst, 0, 0x7Cu);
8801 Dst.dwSize = 124;
8802 if ( LockSurface_DDraw4(v1->pColorKeySurface4, &Dst, 0x801u) )
8803 {
8804 v1->pTargetSurface = (unsigned __int16 *)Dst.lpSurface;
8805 v3 = Dst.lPitch >> 1;
8806 v1->uTargetSurfacePitch = Dst.lPitch >> 1;
8807 LABEL_10:
8808 v1->field_18_locked_pitch = v3;
8809 goto LABEL_11;
8810 }
8811 goto LABEL_8;
8812 }
8813 }
8814 else
8815 {
8816 v4 = &this->pTargetSurface;
8817 if ( !this->pTargetSurface )
8818 {
8819 v5 = (char *)&this->uTargetSurfacePitch;
8820 LockRenderSurface((void **)&this->pTargetSurface, &this->uTargetSurfacePitch);
8821 if ( *v4 )
8822 {
8823 v3 = *(int *)v5;
8824 goto LABEL_10;
8825 }
8826 LABEL_8:
8827 --v1->uNumSceneBegins;
8828 return;
8829 }
8830 }
8831 LABEL_11:
8832 RestoreFrontBuffer();
8833 }
8834 }
8835
8836 //----- (004A527D) --------------------------------------------------------
8837 void Render::EndScene()
8838 {
8839 unsigned int v1; // edx@1
8840 unsigned int v2; // edx@2
8841 HRESULT v3; // eax@5
8842
8843 v1 = this->uNumSceneBegins;
8844 if ( v1 )
8845 {
8846 v2 = v1 - 1;
8847 this->uNumSceneBegins = v2;
8848 if ( !v2 )
8849 {
8850 if ( this->pRenderD3D )
8851 {
8852 if ( this->bColorKeySupported )
8853 {
8854 this->pTargetSurface = 0;
8855 this->uTargetSurfacePitch = 0;
8856 this->field_18_locked_pitch = 0;
8857 ErrD3D(this->pColorKeySurface4->Unlock(0));
8858 }
8859 }
8860 else
8861 {
8862 this->pTargetSurface = 0;
8863 this->uTargetSurfacePitch = 0;
8864 this->field_18_locked_pitch = 0;
8865 UnlockBackBuffer();
8866 }
8867 }
8868 }
8869 }
8870
8871
8872 //----- ( ) --------------------------------------------------------
8873 unsigned int Render::_4A52F1(unsigned int this_, float a3)
8874 {
8875 unsigned int v3; // esi@1
8876 double v4; // st7@2
8877 double v5; // st7@6
8878 double v6; // st6@6
8879 unsigned int v7; // eax@6
8880 double v8; // st5@6
8881 double v9; // st4@6
8882 HRESULT v10; // eax@6
8883 HRESULT v11; // eax@6
8884 unsigned int result; // eax@6
8885 unsigned int v13; // eax@7
8886 unsigned __int16 *v14; // ecx@7
8887 int *v15; // eax@7
8888 unsigned int v16; // ecx@8
8889 __int16 v17; // ax@10
8890 int v18; // esi@10
8891 float v19; // edi@10
8892 void *v20; // esi@10
8893 int v21; // edx@10
8894 int v22; // ecx@11
8895 int v23; // edx@12
8896 __int16 v24; // ax@15
8897 int v25; // esi@15
8898 float v26; // edi@15
8899 char *v27; // esi@15
8900 int v28; // edx@15
8901 int v29; // ecx@16
8902 int v30; // edx@17
8903 int v31; // [sp-Ch] [bp-ACh]@11
8904 int v32; // [sp-Ch] [bp-ACh]@16
8905 const char *v33; // [sp+0h] [bp-A0h]@0
8906 int v34; // [sp+4h] [bp-9Ch]@0
8907 unsigned int v35; // [sp+8h] [bp-98h]@0
8908 RenderVertexD3D3 v36[4]; // [sp+Ch] [bp-94h]@6
8909 unsigned int v37; // [sp+8Ch] [bp-14h]@7
8910 int v38; // [sp+90h] [bp-10h]@7
8911 double v39; // [sp+94h] [bp-Ch]@6
8912 float v40; // [sp+9Ch] [bp-4h]@6
8913
8914 auto ecx0 = this;
8915 v3 = 0;
8916 if ( ecx0->pRenderD3D )
8917 {
8918 v4 = a3;
8919 if ( a3 <= 1.0 )
8920 {
8921 if ( v4 < 0.0 )
8922 v4 = 0.0;
8923 }
8924 else
8925 {
8926 v4 = 1.0;
8927 }
8928 a3 = v4 * 255.0;
8929 v39 = a3 + 6.7553994e15;
8930 LODWORD(v40) = LODWORD(v39);
8931 v5 = (double)(signed int)pViewport->uViewportX;
8932 v36[0].pos.x = v5;
8933 v6 = (double)(signed int)pViewport->uViewportY;
8934 v7 = this_ | (LODWORD(v39) << 24);
8935 this_ = pViewport->uViewportW + 1;
8936 v36[0].specular = 0;
8937 v36[0].pos.y = v6;
8938 v36[0].diffuse = v7;
8939 v36[1].diffuse = v7;
8940 v36[0].pos.z = 0.0;
8941 v36[2].diffuse = v7;
8942 v36[3].diffuse = v7;
8943 v36[0].rhw = 1.0;
8944 v36[1].specular = 0;
8945 v36[0].texcoord.x = 0.0;
8946 v36[2].specular = 0;
8947 v36[3].specular = 0;
8948 v36[0].texcoord.y = 0.0;
8949 v36[1].pos.x = v5;
8950 v8 = (double)(pViewport->uViewportW + 1);
8951 v36[1].pos.y = v8;
8952 v36[1].pos.z = 0.0;
8953 v36[1].rhw = 1.0;
8954 v36[1].texcoord.x = 0.0;
8955 v36[1].texcoord.y = 0.0;
8956 v9 = (double)(signed int)pViewport->uViewportZ;
8957 v36[2].pos.x = v9;
8958 v36[2].pos.y = v8;
8959 v36[2].pos.z = 0.0;
8960 v36[2].rhw = 1.0;
8961 v36[2].texcoord.x = 0.0;
8962 v36[2].texcoord.y = 0.0;
8963 v36[3].pos.x = v9;
8964 v36[3].pos.y = v6;
8965 v36[3].pos.z = 0.0;
8966 v36[3].rhw = 1.0;
8967 v36[3].texcoord.x = 0.0;
8968 v36[3].texcoord.y = 0.0;
8969 ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0));
8970 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
8971 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
8972 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
8973 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 5u));
8974 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 6u));
8975 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
8976 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 8u));
8977 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
8978 D3DPT_TRIANGLEFAN,
8979 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
8980 v36,
8981 4,
8982 28));
8983 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
8984 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
8985 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
8986 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u));
8987 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
8988 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2u));
8989 }
8990 else
8991 {
8992 v40 = (1.0 - a3) * 65536.0;
8993 v39 = v40 + 6.7553994e15;
8994 LODWORD(a3) = LODWORD(v39);
8995 v38 = (signed int)(pViewport->uViewportZ - pViewport->uViewportX) >> 1;
8996 HIDWORD(v39) = pViewport->uViewportW - pViewport->uViewportY + 1;
8997 v13 = pViewport->uViewportX + ecx0->uTargetSurfacePitch - pViewport->uViewportZ;
8998 v14 = &ecx0->pTargetSurface[pViewport->uViewportX + pViewport->uViewportY * ecx0->uTargetSurfacePitch];
8999 v37 = 2 * v13;
9000 LODWORD(v40) = (int)v14;
9001
9002 int __i = 0;
9003 v15 = dword_F1B430;
9004 do
9005 {
9006 v16 = v3;
9007 v3 += LODWORD(a3);
9008 dword_F1B430[__i++] = v16 >> 16;
9009 }
9010 //while ( (signed int)v15 < (signed int)&Aureal3D_SplashScreen );
9011 while (__i < 32);
9012
9013 if ( pRenderer->uTargetGBits == 6 )
9014 {
9015 v17 = _42690D_colors_cvt(this_);
9016 v18 = (65536 - LODWORD(a3)) * (v17 & 0x1F);
9017 this_ = (((65536 - LODWORD(a3)) * (unsigned __int16)(v17 & 0xF800) & 0xF800FFFF | v18 & 0x1F0000 | (65536 - LODWORD(a3)) * (v17 & 0x7E0) & 0x7E00000u) >> 16 << 16) | (((65536 - LODWORD(a3)) * (unsigned __int16)(v17 & 0xF800) & 0xF800FFFF | v18 & 0x1F0000 | (65536 - LODWORD(a3)) * (v17 & 0x7E0) & 0x7E00000u) >> 16);
9018 v19 = v40;
9019 v20 = off_4EFDB0;
9020 v21 = HIDWORD(v39);
9021 do
9022 {
9023 v22 = v38;
9024 v31 = v21;
9025 do
9026 {
9027 v23 = (*(int *)((char *)v20
9028 + ((((unsigned __int16)(*(short *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF800u) >> 9)) << 11) | *(unsigned int *)LODWORD(v19) & 0x7FF) & 0x7C0u) >> 4)) << 6) | (*(int *)((char *)v20 + ((((*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF800u) >> 9)) << 11) | (*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF8000000u) >> 25)) << 27) | *(unsigned int *)LODWORD(v19) & 0x7FF07FF) & 0x7C00000u) >> 20)) << 22) | ((*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF800u) >> 9)) << 11) | (*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF8000000u) >> 25)) << 27) | *(unsigned int *)LODWORD(v19) & 0x7FF07FF) & 0xF81FF81F;
9029 result = this_
9030 + (*((int *)v20
9031 + (((unsigned __int8)(*((char *)v20
9032 + ((((unsigned __int16)(*(short *)((char *)v20
9033 + ((*(unsigned int *)LODWORD(v19) & 0xF800u) >> 9)) << 11) | *(unsigned int *)LODWORD(v19) & 0x7FF) & 0x7C0u) >> 4)) << 6) | *(unsigned int *)LODWORD(v19) & 0x1F) & 0x1F)) | (*(int *)((char *)v20 + ((v23 & 0x1F0000u) >> 14)) << 16) | ((*(int *)((char *)v20 + ((((unsigned __int16)(*(short *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF800u) >> 9)) << 11) | *(unsigned int *)LODWORD(v19) & 0x7FF) & 0x7C0u) >> 4)) << 6) | (*(int *)((char *)v20 + ((((*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF800u) >> 9)) << 11) | (*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF8000000u) >> 25)) << 27) | *(unsigned int *)LODWORD(v19) & 0x7FF07FF) & 0x7C00000u) >> 20)) << 22) | ((*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF800u) >> 9)) << 11) | (*(int *)((char *)v20 + ((*(unsigned int *)LODWORD(v19) & 0xF8000000u) >> 25)) << 27) | *(unsigned int *)LODWORD(v19) & 0x7FF07FF) & 0xF81FF81F) & 0xFFE0FFE0);
9034 *(unsigned int *)LODWORD(v19) = result;
9035 LODWORD(v19) += 4;
9036 --v22;
9037 }
9038 while ( v22 );
9039 LODWORD(v19) += v37;
9040 v21 = v31 - 1;
9041 }
9042 while ( v31 != 1 );
9043 }
9044 else
9045 {
9046 v24 = _4268E3_smthn_to_a1r5g5b5(this_);
9047 v25 = (65536 - LODWORD(a3)) * (v24 & 0x1F);
9048 this_ = (((65536 - LODWORD(a3)) * (v24 & 0x7C00) & 0x7C000000 | v25 & 0x1F0000 | (65536 - LODWORD(a3))
9049 * (v24 & 0x3E0) & 0x3E00000u) >> 16 << 16) | (((65536 - LODWORD(a3)) * (v24 & 0x7C00) & 0x7C000000 | v25 & 0x1F0000 | (65536 - LODWORD(a3)) * (v24 & 0x3E0) & 0x3E00000u) >> 16);
9050 v26 = v40;
9051 v27 = (char *)off_4EFDB0;
9052 v28 = HIDWORD(v39);
9053 do
9054 {
9055 v29 = v38;
9056 v32 = v28;
9057 do
9058 {
9059 v30 = 32
9060 * *(int *)&v27[(((unsigned __int16)(*(short *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C00u) >> 8] << 10) | *(unsigned int *)LODWORD(v26) & 0x3FF) & 0x3E0u) >> 3] | (*(int *)&v27[(((*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C00u) >> 8] << 10) | (*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C000000u) >> 24] << 26) | *(unsigned int *)LODWORD(v26) & 0x3FF03FF) & 0x3E00000u) >> 19] << 21) | ((*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C00u) >> 8] << 10) | (*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C000000u) >> 24] << 26) | *(unsigned int *)LODWORD(v26) & 0x3FF03FF) & 0x7C1F7C1F;
9061 result = this_
9062 + (*(int *)&v27[4
9063 * (((unsigned __int8)(32
9064 * v27[(((unsigned __int16)(*(short *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C00u) >> 8] << 10) | *(unsigned int *)LODWORD(v26) & 0x3FF) & 0x3E0u) >> 3]) | *(unsigned int *)LODWORD(v26) & 0x1F) & 0x1F)] | (*(int *)&v27[(v30 & 0x1F0000u) >> 14] << 16) | (32 * *(int *)&v27[(((unsigned __int16)(*(short *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C00u) >> 8] << 10) | *(unsigned int *)LODWORD(v26) & 0x3FF) & 0x3E0u) >> 3] | (*(int *)&v27[(((*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C00u) >> 8] << 10) | (*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C000000u) >> 24] << 26) | *(unsigned int *)LODWORD(v26) & 0x3FF03FF) & 0x3E00000u) >> 19] << 21) | ((*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C00u) >> 8] << 10) | (*(int *)&v27[(*(unsigned int *)LODWORD(v26) & 0x7C000000u) >> 24] << 26) | *(unsigned int *)LODWORD(v26) & 0x3FF03FF) & 0x7C1F7C1F) & 0xFFE0FFE0);
9065 *(unsigned int *)LODWORD(v26) = result;
9066 LODWORD(v26) += 4;
9067 --v29;
9068 }
9069 while ( v29 );
9070 LODWORD(v26) += v37;
9071 v28 = v32 - 1;
9072 }
9073 while ( v32 != 1 );
9074 }
9075 }
9076 return result;
9077 }
9078
9079
9080
9081 //----- (004A5B81) --------------------------------------------------------
9082 void Render::Clip(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW)
9083 {
9084 this->bClip = 1;
9085 this->uClipY = uY;
9086 this->uClipX = uX;
9087 this->uClipW = uW;
9088 this->uClipZ = uZ;
9089 }
9090
9091
9092 //----- (004A5BB6) --------------------------------------------------------
9093 void Render::ResetClip()
9094 {
9095 this->uClipY = 0;
9096 this->uClipX = 0;
9097 this->bClip = 1;
9098 this->uClipW = 480;
9099 this->uClipZ = 640;
9100 }
9101
9102
9103 //----- (004A5BE3) --------------------------------------------------------
9104 void Render::DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4)
9105 {
9106 int v4; // edi@3
9107 unsigned __int16 *v5; // edx@3
9108 unsigned __int16 *v6; // esi@3
9109 unsigned int v7; // ebx@4
9110 unsigned int v8; // eax@5
9111 unsigned int v9; // ebx@5
9112 unsigned int v10; // eax@6
9113 unsigned int v11; // eax@7
9114 unsigned int v12; // ebx@8
9115 unsigned int v13; // eax@10
9116 unsigned int v14; // edi@11
9117 unsigned int v15; // eax@14
9118 unsigned int v16; // ebx@17
9119 int v17; // eax@23
9120 char v18; // zf@25
9121 int v19; // [sp+10h] [bp-8h]@3
9122 int v20; // [sp+14h] [bp-4h]@3
9123 unsigned int uOutXa; // [sp+20h] [bp+8h]@16
9124 int uOutXb; // [sp+20h] [bp+8h]@21
9125 int v23; // [sp+28h] [bp+10h]@3
9126
9127 if ( this->uNumSceneBegins && a4 )
9128 {
9129 v4 = a4->uWidth;
9130 v5 = &this->pTargetSurface[uOutX + uOutY * this->uTargetSurfacePitch];
9131 v6 = a4->pPixels;
9132 v20 = v4;
9133 v23 = a4->uHeight;
9134 v19 = v4;
9135 if ( this->bClip )
9136 {
9137 v7 = this->uClipX;
9138 if ( (signed int)uOutX < (signed int)v7 )
9139 {
9140 v8 = v7 - uOutX;
9141 v9 = uOutX - v7;
9142 v8 *= 2;
9143 v4 += v9;
9144 v6 = (unsigned __int16 *)((char *)v6 + v8);
9145 v20 += v9;
9146 v5 = (unsigned __int16 *)((char *)v5 + v8);
9147 }
9148 v10 = this->uClipY;
9149 if ( (signed int)uOutY < (signed int)v10 )
9150 {
9151 v11 = v10 - uOutY;
9152 v6 += v19 * v11;
9153 v23 += uOutY - this->uClipY;
9154 v4 = v20;
9155 v5 += this->uTargetSurfacePitch * v11;
9156 }
9157 v12 = this->uClipX;
9158 if ( (signed int)v12 < (signed int)uOutX )
9159 v12 = uOutX;
9160 v13 = this->uClipZ;
9161 if ( (signed int)(v4 + v12) > (signed int)v13 )
9162 {
9163 v14 = this->uClipX;
9164 if ( (signed int)v14 < (signed int)uOutX )
9165 v14 = uOutX;
9166 v4 = v13 - v14;
9167 }
9168 v15 = this->uClipY;
9169 if ( (signed int)v15 < (signed int)uOutY )
9170 v15 = uOutY;
9171 uOutXa = this->uClipW;
9172 if ( (signed int)(v15 + v23) > (signed int)uOutXa )
9173 {
9174 v16 = this->uClipY;
9175 if ( (signed int)v16 < (signed int)uOutY )
9176 v16 = uOutY;
9177 v23 = uOutXa - v16;
9178 }
9179 }
9180 if ( v23 > 0 )
9181 {
9182 uOutXb = v23;
9183 do
9184 {
9185 if ( v4 > 0 )
9186 {
9187 v17 = v4;
9188 do
9189 {
9190 *v5 = *v6;
9191 ++v5;
9192 ++v6;
9193 --v17;
9194 }
9195 while ( v17 );
9196 }
9197 v6 += v19 - v4;
9198 v18 = uOutXb-- == 1;
9199 v5 += this->uTargetSurfacePitch - v4;
9200 }
9201 while ( !v18 );
9202 }
9203 }
9204 }
9205
9206
9207 //----- (004A5D33) --------------------------------------------------------
9208 void Render::_4A5D33(unsigned int pX, unsigned int pY, int a4, int a5, RGBTexture *pTexture)
9209 {
9210 Render *v6; // esi@1
9211 unsigned __int16 *v7; // ebx@3
9212 int v8; // ecx@3
9213 int v9; // edx@3
9214 int v10; // ecx@3
9215 int v11; // edi@3
9216 signed int v12; // eax@4
9217 unsigned int v13; // eax@5
9218 signed int v14; // eax@6
9219 unsigned int v15; // eax@7
9220 unsigned int v16; // edx@8
9221 int v17; // eax@10
9222 unsigned int v18; // ecx@11
9223 unsigned int v19; // ecx@14
9224 int v20; // eax@16
9225 unsigned int v21; // ecx@17
9226 int v22; // eax@21
9227 int v23; // edi@23
9228 int v24; // [sp+Ch] [bp-4h]@3
9229 int a2a; // [sp+18h] [bp+8h]@21
9230 unsigned int teal; // [sp+1Ch] [bp+Ch]@20
9231 int a4a; // [sp+20h] [bp+10h]@3
9232 int a4b; // [sp+20h] [bp+10h]@21
9233 unsigned __int16 *pTexturea; // [sp+28h] [bp+18h]@3
9234
9235 v6 = this;
9236 if ( this->uNumSceneBegins && pTexture )
9237 {
9238 v7 = &this->pTargetSurface[pX + pY * this->uTargetSurfacePitch];
9239 v8 = pTexture->uWidth;
9240 v24 = pTexture->uWidth;
9241 v9 = a4 + a5 * v8;
9242 v10 = v8 - a4;
9243 a4a = v10;
9244 v11 = pTexture->uHeight - a5;
9245 pTexturea = &pTexture->pPixels[v9];
9246 if ( v6->bClip )
9247 {
9248 v12 = v6->uClipX;
9249 if ( (signed int)pX < v12 )
9250 {
9251 v13 = 2 * (v12 - pX);
9252 pTexturea = (unsigned __int16 *)((char *)pTexturea + v13);
9253 v10 += pX - v6->uClipX;
9254 v7 = (unsigned __int16 *)((char *)v7 + v13);
9255 a4a = v10;
9256 }
9257 v14 = v6->uClipY;
9258 if ( (signed int)pY < v14 )
9259 {
9260 v15 = v14 - pY;
9261 pTexturea += v24 * v15;
9262 v11 += pY - v6->uClipY;
9263 v10 = a4a;
9264 v7 += v6->uTargetSurfacePitch * v15;
9265 }
9266 v16 = v6->uClipX;
9267 if ( (signed int)v16 < (signed int)pX )
9268 v16 = pX;
9269 v17 = v6->uClipZ;
9270 if ( (signed int)(v10 + v16) > v17 )
9271 {
9272 v18 = v6->uClipX;
9273 if ( (signed int)v18 < (signed int)pX )
9274 v18 = pX;
9275 a4a = v17 - v18;
9276 }
9277 v19 = v6->uClipY;
9278 if ( (signed int)v19 < (signed int)pY )
9279 v19 = pY;
9280 v20 = v6->uClipW;
9281 if ( (signed int)(v11 + v19) > v20 )
9282 {
9283 v21 = v6->uClipY;
9284 if ( (signed int)v21 < (signed int)pY )
9285 v21 = pY;
9286 v11 = v20 - v21;
9287 }
9288 }
9289 teal = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0, 0xFFu, 0xFFu);
9290 if ( v11 > 0 )
9291 {
9292 v22 = a4a;
9293 a2a = v11;
9294 a4b = 2 * (v24 - a4a);
9295 do
9296 {
9297 if ( v22 > 0 )
9298 {
9299 v23 = v22;
9300 do
9301 {
9302 if ( *pTexturea != teal )
9303 *v7 = *pTexturea;
9304 ++pTexturea;
9305 ++v7;
9306 --v23;
9307 }
9308 while ( v23 );
9309 }
9310 v7 += v6->uTargetSurfacePitch - v22;
9311 pTexturea = (unsigned __int16 *)((char *)pTexturea + a4b);
9312 --a2a;
9313 }
9314 while ( a2a );
9315 }
9316 }
9317 }
9318
9319
9320
9321 //----- (004A6E7E) --------------------------------------------------------
9322 void Render::_4A6E7E(unsigned int a2, unsigned int a3, Texture *a4)
9323 {
9324 unsigned __int16 *v4; // eax@4
9325 int v5; // edx@4
9326 unsigned int v6; // edi@4
9327 unsigned int v7; // edx@5
9328 unsigned int v8; // edx@6
9329 unsigned int v9; // edx@7
9330 unsigned int v10; // edx@8
9331 unsigned int v11; // ebx@9
9332 unsigned int v12; // esi@11
9333 unsigned int v13; // edx@12
9334 unsigned int v14; // ebx@15
9335 unsigned int v15; // esi@17
9336 unsigned int v16; // edi@18
9337 char v17; // zf@29
9338 int v18; // [sp+14h] [bp-Ch]@4
9339 int v19; // [sp+18h] [bp-8h]@4
9340 unsigned __int8 *v20; // [sp+1Ch] [bp-4h]@4
9341 int v21; // [sp+28h] [bp+8h]@25
9342 int v22; // [sp+28h] [bp+8h]@34
9343 unsigned int v23; // [sp+2Ch] [bp+Ch]@23
9344 unsigned int v24; // [sp+2Ch] [bp+Ch]@32
9345
9346 if ( this->uNumSceneBegins && a4 && a4->pPalette16 )
9347 {
9348 v4 = &this->pTargetSurface[a2 + a3 * this->uTargetSurfacePitch];
9349 v20 = a4->pLevelOfDetail0;
9350 v5 = a4->uTextureWidth;
9351 v6 = a4->uTextureHeight;
9352 v19 = a4->uTextureWidth;
9353 v18 = a4->uTextureWidth;
9354 if ( this->bClip )
9355 {
9356 v7 = this->uClipX;
9357 if ( (signed int)a2 < (signed int)v7 )
9358 {
9359 v8 = v7 - a2;
9360 v20 += v8;
9361 v19 += a2 - this->uClipX;
9362 v4 += v8;
9363 }
9364 v9 = this->uClipY;
9365 if ( (signed int)a3 < (signed int)v9 )
9366 {
9367 v10 = v9 - a3;
9368 v20 += v18 * v10;
9369 v6 = a3 - this->uClipY + a4->uTextureHeight;
9370 v4 += this->uTargetSurfacePitch * v10;
9371 }
9372 v11 = this->uClipX;
9373 v5 = v19;
9374 if ( (signed int)v11 < (signed int)a2 )
9375 v11 = a2;
9376 v12 = this->uClipZ;
9377 if ( (signed int)(v19 + v11) > (signed int)v12 )
9378 {
9379 v13 = this->uClipX;
9380 if ( (signed int)v13 < (signed int)a2 )
9381 v13 = a2;
9382 v5 = v12 - v13;
9383 }
9384 v14 = this->uClipY;
9385 if ( (signed int)v14 < (signed int)a3 )
9386 v14 = a3;
9387 v15 = this->uClipW;
9388 if ( (signed int)(v6 + v14) > (signed int)v15 )
9389 {
9390 v16 = this->uClipY;
9391 if ( (signed int)v16 < (signed int)a3 )
9392 v16 = a3;
9393 v6 = v15 - v16;
9394 }
9395 }
9396 if ( pRenderer->uTargetGBits == 5 )
9397 {
9398 if ( (signed int)v6 > 0 )
9399 {
9400 v23 = v6;
9401 do
9402 {
9403 if ( v5 > 0 )
9404 {
9405 v21 = v5;
9406 do
9407 {
9408 if ( *v20 )
9409 *v4 = ((unsigned int)a4->pPalette16[*v20] >> 1) & 0x3DEF;
9410 ++v4;
9411 ++v20;
9412 --v21;
9413 }
9414 while ( v21 );
9415 }
9416 v20 += v18 - v5;
9417 v17 = v23-- == 1;
9418 v4 += this->uTargetSurfacePitch - v5;
9419 }
9420 while ( !v17 );
9421 }
9422 }
9423 else
9424 {
9425 if ( (signed int)v6 > 0 )
9426 {
9427 v24 = v6;
9428 do
9429 {
9430 if ( v5 > 0 )
9431 {
9432 v22 = v5;
9433 do
9434 {
9435 if ( *v20 )
9436 *v4 = ((unsigned int)a4->pPalette16[*v20] >> 1) & 0x7BEF;
9437 ++v4;
9438 ++v20;
9439 --v22;
9440 }
9441 while ( v22 );
9442 }
9443 v20 += v18 - v5;
9444 v17 = v24-- == 1;
9445 v4 += this->uTargetSurfacePitch - v5;
9446 }
9447 while ( !v17 );
9448 }
9449 }
9450 }
9451 }
9452
9453
9454 //----- (004A6DF5) --------------------------------------------------------
9455 int Render::_4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, Vec2_int_ *pBitmapXY, unsigned __int16 *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7)
9456 {
9457 int result; // eax@0
9458 int v8; // ecx@3
9459 unsigned __int16 *v9; // edi@4
9460 unsigned __int16 *v10; // ebx@4
9461 int v11; // esi@4
9462 unsigned __int16 *pBitmapa; // [sp+14h] [bp+8h]@3
9463 unsigned __int16 *pTargeta; // [sp+20h] [bp+14h]@3
9464
9465 if ( pBitmap )
9466 {
9467 if ( pTarget )
9468 {
9469 pBitmapa = &pBitmap[pBitmapXY->x + uBitmapPitch * pBitmapXY->y];
9470 pTargeta = &pTarget[a7->x + uTargetPitch * a7->y];
9471 v8 = a7->z - a7->x;
9472 result = a7->w - a7->y;
9473 if ( result > 0 )
9474 {
9475 v9 = pBitmapa;
9476 v10 = pTargeta;
9477 v11 = a7->w - a7->y;
9478 do
9479 {
9480 if ( v8 > 0 )
9481 {
9482 result = v8;
9483 do
9484 {
9485 *v9 = *v10;
9486 ++v9;
9487 ++v10;
9488 --result;
9489 }
9490 while ( result );
9491 }
9492 v9 += uBitmapPitch - v8;
9493 v10 += uTargetPitch - v8;
9494 --v11;
9495 }
9496 while ( v11 );
9497 }
9498 }
9499 }
9500 return result;
9501 }
9502
9503
9504 //----- (004A6D87) --------------------------------------------------------
9505 void Render::FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16)
9506 {
9507 if (!uNumSceneBegins)
9508 return;
9509
9510 unsigned __int32 twoColors = (uColor16 << 16) | uColor16;
9511 for (uint y = 0; y < uHeight; ++y)
9512 {
9513 auto pDst = &pTargetSurface[uX + (y + uY) * uTargetSurfacePitch];
9514
9515 memset32(pDst, twoColors, uWidth / 2);
9516 if (uWidth & 1)
9517 pDst[uWidth - 1] = uColor16;
9518 }
9519 }
9520
9521
9522
9523 //----- (004A6C4F) --------------------------------------------------------
9524 void Render::DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor)
9525 {
9526 unsigned int v9; // edi@2
9527 unsigned int v10; // esi@2
9528 unsigned __int16 *v11; // eax@2
9529 unsigned int v12; // ebx@3
9530 signed int v13; // edx@5
9531 int v14; // edx@6
9532 signed int v15; // ebx@7
9533 unsigned int v16; // edx@9
9534 signed int v17; // edi@10
9535 signed int v18; // ebx@13
9536 unsigned int v19; // edx@15
9537 signed int v20; // esi@16
9538 unsigned int v21; // esi@22
9539 unsigned __int16 v22; // dx@24
9540 char v23; // zf@28
9541 unsigned __int8 *v24; // [sp+Ch] [bp-4h]@2
9542 unsigned int uOutXa; // [sp+18h] [bp+8h]@20
9543
9544 if ( this->uNumSceneBegins )
9545 {
9546 v9 = uCharWidth;
9547 v10 = uCharHeight;
9548 v11 = &this->pTargetSurface[uOutX + uOutY * this->uTargetSurfacePitch];
9549 v24 = pFontPixels;
9550 if ( this->bClip )
9551 {
9552 v12 = this->uClipX;
9553 if ( uOutX < (signed int)v12 )
9554 {
9555 v24 = &pFontPixels[v12 - uOutX];
9556 v11 += v12 - uOutX;
9557 v9 = uCharWidth + uOutX - v12;
9558 }
9559 v13 = this->uClipY;
9560 if ( uOutY < v13 )
9561 {
9562 v14 = v13 - uOutY;
9563 v24 += uCharWidth * v14;
9564 v10 = uCharHeight + uOutY - this->uClipY;
9565 v11 += this->uTargetSurfacePitch * v14;
9566 }
9567 v15 = this->uClipX;
9568 if ( v15 < uOutX )
9569 v15 = uOutX;
9570 v16 = this->uClipZ;
9571 if ( (signed int)(v9 + v15) > (signed int)v16 )
9572 {
9573 v17 = this->uClipX;
9574 if ( v17 < uOutX )
9575 v17 = uOutX;
9576 v9 = v16 - v17;
9577 }
9578 v18 = this->uClipY;
9579 if ( v18 < uOutY )
9580 v18 = uOutY;
9581 v19 = this->uClipW;
9582 if ( (signed int)(v10 + v18) > (signed int)v19 )
9583 {
9584 v20 = this->uClipY;
9585 if ( v20 < uOutY )
9586 v20 = uOutY;
9587 v10 = v19 - v20;
9588 }
9589 }
9590 if ( (signed int)v10 > 0 )
9591 {
9592 uOutXa = v10;
9593 do
9594 {
9595 if ( (signed int)v9 > 0 )
9596 {
9597 v21 = v9;
9598 do
9599 {
9600 if ( *v24 )
9601 {
9602 v22 = uShadowColor;
9603 if ( *v24 != 1 )
9604 v22 = uFaceColor;
9605 *v11 = v22;
9606 }
9607 ++v11;
9608 ++v24;
9609 --v21;
9610 }
9611 while ( v21 );
9612 }
9613 v24 += uCharWidth - v9;
9614 v23 = uOutXa-- == 1;
9615 v11 += this->uTargetSurfacePitch - v9;
9616 }
9617 while ( !v23 );
9618 }
9619 }
9620 }
9621
9622
9623
9624 //----- (004A6A68) --------------------------------------------------------
9625 void Render::_4A6A68(unsigned int a2, unsigned int a3, Texture *a4, __int16 height)
9626 {
9627 Render *v5; // ebx@1
9628 unsigned __int16 v6; // ax@1
9629
9630 v5 = this;
9631
9632 Texture tex; // [sp+Ch] [bp-48h]@1
9633 //Texture::Texture(&tex);
9634
9635 v6 = a4->uTextureHeight - height;
9636 memcpy(&tex, a4, sizeof(tex));
9637 tex.uTextureHeight = v6;
9638 if ( (signed __int16)v6 > 0 )
9639 DrawTextureIndexed(a2, a3, &tex);
9640 }
9641
9642
9643
9644 //----- (004A6AB1) --------------------------------------------------------
9645 void Render::DrawTextPalette(int x, int y, int a4, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8)
9646 {
9647 int v8; // edi@2
9648 unsigned int v9; // esi@2
9649 unsigned __int16 *v10; // eax@2
9650 unsigned char *v11; // edx@2
9651 unsigned int v12; // ebx@3
9652 signed int v13; // edx@5
9653 int v14; // edx@6
9654 signed int v15; // ebx@7
9655 unsigned int v16; // edx@9
9656 signed int v17; // edi@10
9657 signed int v18; // ebx@13
9658 unsigned int v19; // edx@15
9659 signed int v20; // esi@16
9660 int v21; // ebx@22
9661 char v22; // zf@28
9662 int v23; // ebx@31
9663 unsigned __int16 v24; // si@35
9664 int v25; // [sp+Ch] [bp-4h]@2
9665 int v26; // [sp+1Ch] [bp+Ch]@24
9666 int v27; // [sp+1Ch] [bp+Ch]@33
9667 unsigned int v28; // [sp+20h] [bp+10h]@30
9668 unsigned int v29; // [sp+24h] [bp+14h]@22
9669 unsigned int v30; // [sp+24h] [bp+14h]@31
9670
9671 auto a2 = x;
9672 auto a3 = y;
9673 auto a6 = uFontHeight;
9674 if ( this->uNumSceneBegins )
9675 {
9676 v8 = a5;
9677 v9 = a6;
9678 v10 = &pTargetSurface[x + y * uTargetSurfacePitch];
9679 v11 = (unsigned char *)a4;
9680 v25 = a4;
9681 if ( this->bClip )
9682 {
9683 v12 = this->uClipX;
9684 if ( a2 < (signed int)v12 )
9685 {
9686 v25 = v12 - a2 + a4;
9687 v10 += v12 - a2;
9688 v8 = a5 + a2 - v12;
9689 }
9690 v13 = this->uClipY;
9691 if ( a3 < v13 )
9692 {
9693 v14 = v13 - a3;
9694 v25 += a5 * v14;
9695 v9 = a6 + a3 - this->uClipY;
9696 v10 += this->uTargetSurfacePitch * v14;
9697 }
9698 v15 = this->uClipX;
9699 if ( v15 < a2 )
9700 v15 = a2;
9701 v16 = this->uClipZ;
9702 if ( v8 + v15 > (signed int)v16 )
9703 {
9704 v17 = this->uClipX;
9705 if ( v17 < a2 )
9706 v17 = a2;
9707 v8 = v16 - v17;
9708 }
9709 v18 = this->uClipY;
9710 if ( v18 < a3 )
9711 v18 = a3;
9712 v19 = this->uClipW;
9713 if ( (signed int)(v9 + v18) > (signed int)v19 )
9714 {
9715 v20 = this->uClipY;
9716 if ( v20 < a3 )
9717 v20 = a3;
9718 v9 = v19 - v20;
9719 }
9720 v11 = (unsigned char *)v25;
9721 }
9722 if ( a8 )
9723 {
9724 v28 = pRenderer->uTargetGMask | pRenderer->uTargetBMask;
9725 if ( (signed int)v9 > 0 )
9726 {
9727 v23 = a5;
9728 v30 = v9;
9729 do
9730 {
9731 if ( v8 > 0 )
9732 {
9733 v27 = v8;
9734 do
9735 {
9736 if ( *v11 )
9737 v24 = pPalette[*v11];
9738 else
9739 v24 = v28;
9740 *v10 = v24;
9741 ++v10;
9742 ++v11;
9743 --v27;
9744 }
9745 while ( v27 );
9746 }
9747 v11 += v23 - v8;
9748 v22 = v30-- == 1;
9749 v10 += this->uTargetSurfacePitch - v8;
9750 }
9751 while ( !v22 );
9752 }
9753 }
9754 else
9755 {
9756 if ( (signed int)v9 > 0 )
9757 {
9758 v21 = a5;
9759 v29 = v9;
9760 do
9761 {
9762 if ( v8 > 0 )
9763 {
9764 v26 = v8;
9765 do
9766 {
9767 if ( *v11 )
9768 *v10 = pPalette[*v11];
9769 ++v10;
9770 ++v11;
9771 --v26;
9772 }
9773 while ( v26 );
9774 }
9775 v11 += v21 - v8;
9776 v22 = v29-- == 1;
9777 v10 += this->uTargetSurfacePitch - v8;
9778 }
9779 while ( !v22 );
9780 }
9781 }
9782 }
9783 }
9784
9785 //----- (004A68EF) --------------------------------------------------------
9786 void Render::DrawTransparentGreenShade(signed int a2, signed int a3, Texture *pTexture)
9787 {
9788 Texture *v4; // edi@2
9789 unsigned int v5; // ebx@4
9790 unsigned __int16 *v6; // eax@4
9791 signed int v7; // edx@5
9792 int v8; // edx@6
9793 signed int v9; // edx@7
9794 int v10; // edx@8
9795 signed int v11; // edx@9
9796 signed int v12; // esi@12
9797 signed int v13; // esi@15
9798 unsigned int v14; // edx@17
9799 signed int v15; // esi@18
9800 unsigned __int8 *v16; // ebx@22
9801 char v17; // zf@28
9802 int v18; // [sp+10h] [bp-10h]@4
9803 unsigned __int8 *v19; // [sp+18h] [bp-8h]@4
9804 int v20; // [sp+1Ch] [bp-4h]@4
9805 int v21; // [sp+28h] [bp+8h]@24
9806 unsigned int v22; // [sp+2Ch] [bp+Ch]@22
9807 unsigned int pTexturea; // [sp+30h] [bp+10h]@11
9808
9809 if ( this->uNumSceneBegins )
9810 {
9811 v4 = pTexture;
9812 if ( pTexture )
9813 {
9814 if ( pTexture->pPalette16 )
9815 {
9816 v5 = pTexture->uTextureHeight;
9817 v6 = &this->pTargetSurface[a2 + a3 * this->uTargetSurfacePitch];
9818 v19 = pTexture->pLevelOfDetail0;
9819 v20 = pTexture->uTextureWidth;
9820 v18 = pTexture->uTextureWidth;
9821 if ( this->bClip )
9822 {
9823 v7 = this->uClipX;
9824 if ( a2 < v7 )
9825 {
9826 v8 = v7 - a2;
9827 v19 += v8;
9828 v20 += a2 - this->uClipX;
9829 v6 += v8;
9830 }
9831 v9 = this->uClipY;
9832 v5 = pTexture->uTextureHeight;
9833 if ( a3 < v9 )
9834 {
9835 v10 = v9 - a3;
9836 v19 += v18 * v10;
9837 v5 = a3 - this->uClipY + pTexture->uTextureHeight;
9838 v4 = pTexture;
9839 v6 += this->uTargetSurfacePitch * v10;
9840 }
9841 v11 = this->uClipX;
9842 if ( v11 < a2 )
9843 v11 = a2;
9844 pTexturea = this->uClipZ;
9845 if ( v11 + v20 > (signed int)pTexturea )
9846 {
9847 v12 = this->uClipX;
9848 if ( v12 < a2 )
9849 v12 = a2;
9850 v20 = pTexturea - v12;
9851 }
9852 v13 = this->uClipY;
9853 if ( v13 < a3 )
9854 v13 = a3;
9855 v14 = this->uClipW;
9856 if ( (signed int)(v5 + v13) > (signed int)v14 )
9857 {
9858 v15 = this->uClipY;
9859 if ( v15 < a3 )
9860 v15 = a3;
9861 v5 = v14 - v15;
9862 }
9863 }
9864 if ( (signed int)v5 > 0 )
9865 {
9866 v22 = v5;
9867 v16 = v19;
9868 do
9869 {
9870 if ( v20 > 0 )
9871 {
9872 v21 = v20;
9873 do
9874 {
9875 if ( *v16 )
9876 *v6 = this->uTargetGMask & v4->pPalette16[*v16];
9877 ++v6;
9878 ++v16;
9879 --v21;
9880 }
9881 while ( v21 );
9882 }
9883 v16 += v18 - v20;
9884 v17 = v22-- == 1;
9885 v6 += this->uTargetSurfacePitch - v20;
9886 }
9887 while ( !v17 );
9888 }
9889 }
9890 }
9891 }
9892 }
9893
9894
9895 //----- (004A6776) --------------------------------------------------------
9896 void Render::_4A6776(unsigned int a2, unsigned int a3, Texture *a4)
9897 {
9898 Texture *v4; // edi@2
9899 unsigned int v5; // ebx@4
9900 unsigned __int16 *v6; // eax@4
9901 unsigned int v7; // edx@5
9902 unsigned int v8; // edx@6
9903 unsigned int v9; // edx@7
9904 unsigned int v10; // edx@8
9905 unsigned int v11; // edx@9
9906 unsigned int v12; // esi@12
9907 unsigned int v13; // esi@15
9908 unsigned int v14; // edx@17
9909 unsigned int v15; // esi@18
9910 unsigned __int8 *v16; // ebx@22
9911 char v17; // zf@28
9912 int v18; // [sp+10h] [bp-10h]@4
9913 unsigned __int8 *v19; // [sp+18h] [bp-8h]@4
9914 int v20; // [sp+1Ch] [bp-4h]@4
9915 int a2a; // [sp+28h] [bp+8h]@24
9916 unsigned int a3a; // [sp+2Ch] [bp+Ch]@22
9917 unsigned int a4a; // [sp+30h] [bp+10h]@11
9918
9919 if ( this->uNumSceneBegins )
9920 {
9921 v4 = a4;
9922 if ( a4 )
9923 {
9924 if ( a4->pPalette16 )
9925 {
9926 v5 = a4->uTextureHeight;
9927 v6 = &this->pTargetSurface[a2 + a3 * this->uTargetSurfacePitch];
9928 v19 = a4->pLevelOfDetail0;
9929 v20 = a4->uTextureWidth;
9930 v18 = a4->uTextureWidth;
9931 if ( this->bClip )
9932 {
9933 v7 = this->uClipX;
9934 if ( (signed int)a2 < (signed int)v7 )
9935 {
9936 v8 = v7 - a2;
9937 v19 += v8;
9938 v20 += a2 - this->uClipX;
9939 v6 += v8;
9940 }
9941 v9 = this->uClipY;
9942 v5 = a4->uTextureHeight;
9943 if ( (signed int)a3 < (signed int)v9 )
9944 {
9945 v10 = v9 - a3;
9946 v19 += v18 * v10;
9947 v5 = a3 - this->uClipY + a4->uTextureHeight;
9948 v4 = a4;
9949 v6 += this->uTargetSurfacePitch * v10;
9950 }
9951 v11 = this->uClipX;
9952 if ( (signed int)v11 < (signed int)a2 )
9953 v11 = a2;
9954 a4a = this->uClipZ;
9955 if ( (signed int)(v11 + v20) > (signed int)a4a )
9956 {
9957 v12 = this->uClipX;
9958 if ( (signed int)v12 < (signed int)a2 )
9959 v12 = a2;
9960 v20 = a4a - v12;
9961 }
9962 v13 = this->uClipY;
9963 if ( (signed int)v13 < (signed int)a3 )
9964 v13 = a3;
9965 v14 = this->uClipW;
9966 if ( (signed int)(v5 + v13) > (signed int)v14 )
9967 {
9968 v15 = this->uClipY;
9969 if ( (signed int)v15 < (signed int)a3 )
9970 v15 = a3;
9971 v5 = v14 - v15;
9972 }
9973 }
9974 if ( (signed int)v5 > 0 )
9975 {
9976 a3a = v5;
9977 v16 = v19;
9978 do
9979 {
9980 if ( v20 > 0 )
9981 {
9982 a2a = v20;
9983 do
9984 {
9985 if ( *v16 )
9986 *v6 = this->uTargetRMask & v4->pPalette16[*v16];
9987 ++v6;
9988 ++v16;
9989 --a2a;
9990 }
9991 while ( a2a );
9992 }
9993 v16 += v18 - v20;
9994 v17 = a3a-- == 1;
9995 v6 += this->uTargetSurfacePitch - v20;
9996 }
9997 while ( !v17 );
9998 }
9999 }
10000 }
10001 }
10002 }
10003
10004 //----- (004A65CC) --------------------------------------------------------
10005 void Render::_4A65CC(unsigned int x, unsigned int y, Texture *a4, Texture *a5, int a6, int a7, int a8)
10006 {
10007 unsigned __int16 *v8; // esi@6
10008 unsigned int v9; // edi@6
10009 unsigned int v10; // eax@7
10010 unsigned int v11; // eax@8
10011 unsigned int v12; // eax@9
10012 unsigned int v13; // eax@10
10013 unsigned int v14; // edx@11
10014 unsigned int v15; // eax@13
10015 unsigned int v16; // edx@14
10016 unsigned int v17; // edx@17
10017 unsigned int v18; // eax@19
10018 unsigned int v19; // edx@20
10019 int v20; // eax@27
10020 int v21; // edx@29
10021 int v22; // [sp+Ch] [bp-Ch]@6
10022 int v23; // [sp+Ch] [bp-Ch]@24
10023 unsigned __int8 *v24; // [sp+14h] [bp-4h]@6
10024 int xa; // [sp+20h] [bp+8h]@26
10025 unsigned int ya; // [sp+24h] [bp+Ch]@24
10026 int v27; // [sp+2Ch] [bp+14h]@6
10027
10028 if ( this->uNumSceneBegins && a4 && a4->pPalette16 && a5 && a5->pPalette16 )
10029 {
10030 v8 = &this->pTargetSurface[x + y * this->uTargetSurfacePitch];
10031 v24 = a4->pLevelOfDetail0;
10032 v27 = a4->uTextureWidth;
10033 v9 = a4->uTextureHeight;
10034 v22 = a4->uTextureWidth;
10035 if ( this->bClip )
10036 {
10037 v10 = this->uClipX;
10038 if ( (signed int)x < (signed int)v10 )
10039 {
10040 v11 = v10 - x;
10041 v24 += v11;
10042 v27 += x - this->uClipX;
10043 v8 += v11;
10044 }
10045 v12 = this->uClipY;
10046 if ( (signed int)y < (signed int)v12 )
10047 {
10048 v13 = v12 - y;
10049 v24 += v22 * v13;
10050 v9 = y - this->uClipY + a4->uTextureHeight;
10051 v8 += this->uTargetSurfacePitch * v13;
10052 }
10053 v14 = this->uClipX;
10054 if ( (signed int)v14 < (signed int)x )
10055 v14 = x;
10056 v15 = this->uClipZ;
10057 if ( (signed int)(v27 + v14) > (signed int)v15 )
10058 {
10059 v16 = this->uClipX;
10060 if ( (signed int)v16 < (signed int)x )
10061 v16 = x;
10062 v27 = v15 - v16;
10063 }
10064 v17 = this->uClipY;
10065 if ( (signed int)v17 < (signed int)y )
10066 v17 = y;
10067 v18 = this->uClipW;
10068 if ( (signed int)(v9 + v17) > (signed int)v18 )
10069 {
10070 v19 = this->uClipY;
10071 if ( (signed int)v19 < (signed int)y )
10072 v19 = y;
10073 v9 = v18 - v19;
10074 }
10075 }
10076 if ( (signed int)v9 > 0 )
10077 {
10078 ya = v9;
10079 v23 = v22 - v27;
10080 do
10081 {
10082 if ( v27 > 0 )
10083 {
10084 xa = v27;
10085 do
10086 {
10087 v20 = *v24;
10088 if ( v20 >= a7 && v20 <= a8 )
10089 {
10090 v21 = a7 + (a6 + v20) % (2 * (a8 - a7));
10091 if ( (a6 + v20) % (2 * (a8 - a7)) >= a8 - a7 )
10092 v21 = 2 * a8 - v21 - a7;
10093 *v8 = a4->pPalette16[v21];
10094 }
10095 ++v8;
10096 ++v24;
10097 --xa;
10098 }
10099 while ( xa );
10100 }
10101 v8 += this->uTargetSurfacePitch - v27;
10102 v24 += v23;
10103 --ya;
10104 }
10105 while ( ya );
10106 }
10107 }
10108 }
10109
10110
10111 //----- (004A63E6) --------------------------------------------------------
10112 void Render::_4A63E6(unsigned int a2, unsigned int a3, Texture *a4, Texture *a5, int a6, int a7, int a8)
10113 {
10114 Texture *v8; // eax@2
10115 Texture *v9; // ebx@4
10116 unsigned __int16 *v10; // esi@6
10117 unsigned int v11; // edi@7
10118 unsigned int v12; // eax@9
10119 unsigned int v13; // eax@10
10120 unsigned int v14; // edx@11
10121 unsigned int v15; // eax@13
10122 unsigned int v16; // edx@14
10123 unsigned int v17; // edx@17
10124 unsigned int v18; // eax@19
10125 unsigned int v19; // edx@20
10126 int v20; // eax@27
10127 int v21; // edx@29
10128 int v22; // [sp+Ch] [bp-Ch]@6
10129 int v23; // [sp+Ch] [bp-Ch]@24
10130 int v24; // [sp+10h] [bp-8h]@6
10131 int v25; // [sp+14h] [bp-4h]@6
10132 int i; // [sp+20h] [bp+8h]@25
10133 int v27; // [sp+24h] [bp+Ch]@23
10134 unsigned __int8 *v28; // [sp+28h] [bp+10h]@6
10135
10136 if ( this->uNumSceneBegins )
10137 {
10138 v8 = a4;
10139 if ( a4 )
10140 {
10141 if ( a4->pPalette16 )
10142 {
10143 v9 = a5;
10144 if ( a5 )
10145 {
10146 if ( a5->pPalette16 )
10147 {
10148 v10 = &this->pTargetSurface[a2 + a3 * this->uTargetSurfacePitch];
10149 v28 = a4->pLevelOfDetail0;
10150 v25 = v8->uTextureWidth;
10151 v24 = v8->uTextureHeight;
10152 v22 = v8->uTextureWidth;
10153 if ( this->bClip )
10154 {
10155 v11 = this->uClipX;
10156 if ( (signed int)a2 < (signed int)v11 )
10157 {
10158 v28 += v11 - a2;
10159 v25 += a2 - v11;
10160 v9 = a5;
10161 v10 += v11 - a2;
10162 }
10163 v12 = this->uClipY;
10164 if ( (signed int)a3 < (signed int)v12 )
10165 {
10166 v13 = v12 - a3;
10167 v9 = a5;
10168 v28 += v22 * v13;
10169 v24 += a3 - this->uClipY;
10170 v10 += this->uTargetSurfacePitch * v13;
10171 }
10172 v14 = this->uClipX;
10173 if ( (signed int)v14 < (signed int)a2 )
10174 v14 = a2;
10175 v15 = this->uClipZ;
10176 if ( (signed int)(v25 + v14) > (signed int)v15 )
10177 {
10178 v16 = this->uClipX;
10179 if ( (signed int)v16 < (signed int)a2 )
10180 v16 = a2;
10181 v25 = v15 - v16;
10182 }
10183 v17 = this->uClipY;
10184 if ( (signed int)v17 < (signed int)a3 )
10185 v17 = a3;
10186 v18 = this->uClipW;
10187 if ( (signed int)(v24 + v17) > (signed int)v18 )
10188 {
10189 v19 = this->uClipY;
10190 if ( (signed int)v19 < (signed int)a3 )
10191 v19 = a3;
10192 v24 = v18 - v19;
10193 }
10194 }
10195 v27 = 0;
10196 if ( v24 > 0 )
10197 {
10198 v23 = v22 - v25;
10199 do
10200 {
10201 for ( i = 0; i < v25; ++v28 )
10202 {
10203 if ( *v28 )
10204 {
10205 v20 = *(&v9->pLevelOfDetail0[i & v9->uWidthMinus1] + v9->uTextureWidth * (v27 & v9->uHeightMinus1));
10206 if ( v20 >= a7 )
10207 {
10208 if ( v20 <= a8 )
10209 {
10210 v21 = a7 + (a6 + v20) % (2 * (a8 - a7));
10211 if ( (a6 + v20) % (2 * (a8 - a7)) >= a8 - a7 )
10212 v21 = 2 * a8 - v21 - a7;
10213 v9 = a5;
10214 *v10 = a5->pPalette16[v21];
10215 }
10216 }
10217 }
10218 ++i;
10219 ++v10;
10220 }
10221 ++v27;
10222 v10 += this->uTargetSurfacePitch - v25;
10223 v28 += v23;
10224 }
10225 while ( v27 < v24 );
10226 }
10227 }
10228 }
10229 }
10230 }
10231 }
10232 }
10233
10234
10235 //----- (004A6274) --------------------------------------------------------
10236 void Render::DrawTextureTransparent(unsigned int uX, unsigned int uY, Texture *pTexture)
10237 {
10238 Texture *pCurrentTexture; // edi@2
10239 int uHeight; // ebx@4
10240 unsigned __int16 *v6; // eax@4
10241 unsigned int v7; // edx@5
10242 unsigned int v8; // edx@6
10243 unsigned int v9; // edx@7
10244 unsigned int v10; // edx@8
10245 unsigned int v11; // edx@9
10246 unsigned int v12; // esi@12
10247 unsigned int v13; // esi@15
10248 unsigned int v14; // edx@17
10249 unsigned int v15; // esi@18
10250 unsigned __int8 *v16; // ebx@22
10251 char uFlag; // zf@28
10252 int v18; // [sp+10h] [bp-10h]@4
10253 unsigned __int8 *v19; // [sp+18h] [bp-8h]@4
10254 int uWidth; // [sp+1Ch] [bp-4h]@4
10255 int uXa; // [sp+28h] [bp+8h]@24
10256 unsigned int uYa; // [sp+2Ch] [bp+Ch]@22
10257 unsigned int pTexturea; // [sp+30h] [bp+10h]@11
10258
10259 if ( this->uNumSceneBegins )
10260 {
10261 pCurrentTexture = pTexture;
10262 if ( pTexture )
10263 {
10264 if ( pTexture->pPalette16 )
10265 {
10266 uHeight = pTexture->uTextureHeight;
10267 v6 = &this->pTargetSurface[uX + uY * this->uTargetSurfacePitch];
10268 v19 = pTexture->pLevelOfDetail0;
10269 uWidth = pTexture->uTextureWidth;
10270 v18 = pTexture->uTextureWidth;
10271 if ( this->bClip )
10272 {
10273 v7 = this->uClipX;
10274 if ( (signed int)uX < (signed int)v7 )
10275 {
10276 v8 = v7 - uX;
10277 v19 += v8;
10278 uWidth += uX - this->uClipX;
10279 v6 += v8;
10280 }
10281 v9 = this->uClipY;
10282 uHeight = pTexture->uTextureHeight;
10283 if ( (signed int)uY < (signed int)v9 )
10284 {
10285 v10 = v9 - uY;
10286 v19 += v18 * v10;
10287 uHeight = uY - this->uClipY + pTexture->uTextureHeight;
10288 pCurrentTexture = pTexture;
10289 v6 += this->uTargetSurfacePitch * v10;
10290 }
10291 v11 = this->uClipX;
10292 if ( (signed int)v11 < (signed int)uX )
10293 v11 = uX;
10294 pTexturea = this->uClipZ;
10295 if ( (signed int)(v11 + uWidth) > (signed int)pTexturea )
10296 {
10297 v12 = this->uClipX;
10298 if ( (signed int)v12 < (signed int)uX )
10299 v12 = uX;
10300 uWidth = pTexturea - v12;
10301 }
10302 v13 = this->uClipY;
10303 if ( (signed int)v13 < (signed int)uY )
10304 v13 = uY;
10305 v14 = this->uClipW;
10306 if ( (signed int)(uHeight + v13) > (signed int)v14 )
10307 {
10308 v15 = this->uClipY;
10309 if ( (signed int)v15 < (signed int)uY )
10310 v15 = uY;
10311 uHeight = v14 - v15;
10312 }
10313 }
10314 if ( (signed int)uHeight > 0 )
10315 {
10316 uYa = uHeight;
10317 v16 = v19;
10318 do
10319 {
10320 if ( uWidth > 0 )
10321 {
10322 uXa = uWidth;
10323 do
10324 {
10325 if ( *v16 )
10326 *v6 = pCurrentTexture->pPalette16[*v16];
10327 ++v6;
10328 ++v16;
10329 }
10330 while ( uXa-- !=1 );
10331 }
10332 v16 += v18 - uWidth;
10333 uFlag = uYa-- == 1;
10334 v6 += this->uTargetSurfacePitch - uWidth;
10335 }
10336 while ( !uFlag );
10337 }
10338 }
10339 }
10340 }
10341 }
10342
10343
10344 //----- (004A612A) --------------------------------------------------------
10345 void Render::_4A612A(signed int uOutX, unsigned int uOutY, Texture *pTexture, int zVal)
10346 {
10347 Texture *v5; // eax@2
10348 unsigned int v6; // edx@3
10349 int v7; // ebx@3
10350 int v8; // edi@3
10351 signed int v9; // eax@4
10352 int v10; // eax@5
10353 unsigned int v11; // esi@6
10354 signed int v12; // esi@8
10355 unsigned int v13; // eax@10
10356 signed int v14; // esi@11
10357 unsigned int v15; // esi@14
10358 unsigned int v16; // eax@16
10359 unsigned int v17; // ecx@17
10360 int v18; // edx@23
10361 int v19; // [sp+Ch] [bp-Ch]@3
10362 int v20; // [sp+10h] [bp-8h]@3
10363 int uOutXa; // [sp+20h] [bp+8h]@21
10364 unsigned __int8 *uOutYa; // [sp+24h] [bp+Ch]@3
10365 int *pZBuffer; // [sp+28h] [bp+10h]@3
10366
10367 if ( this->uNumSceneBegins )
10368 {
10369 v5 = pTexture;
10370 if ( pTexture )
10371 {
10372 v6 = uOutY;
10373 v7 = pTexture->uTextureHeight;
10374 pZBuffer = &this->pActiveZBuffer[uOutX + 640 * uOutY];
10375 uOutYa = v5->pLevelOfDetail0;
10376 v8 = v5->uTextureWidth;
10377 v20 = v5->uTextureWidth;
10378 v19 = v5->uTextureWidth;
10379 if ( this->bClip )
10380 {
10381 v9 = this->uClipX;
10382 if ( uOutX < v9 )
10383 {
10384 v10 = v9 - uOutX;
10385 uOutYa += v10;
10386 v8 += uOutX - this->uClipX;
10387 v20 = v8;
10388 pZBuffer += v10;
10389 }
10390 v11 = this->uClipY;
10391 if ( (signed int)v6 < (signed int)v11 )
10392 {
10393 uOutYa += v19 * (v11 - v6);
10394 v7 += v6 - v11;
10395 pZBuffer += 640 * (v11 - v6);
10396 v8 = v20;
10397 }
10398 v12 = this->uClipX;
10399 if ( v12 < uOutX )
10400 v12 = uOutX;
10401 v13 = this->uClipZ;
10402 if ( v8 + v12 > (signed int)v13 )
10403 {
10404 v14 = this->uClipX;
10405 if ( v14 < uOutX )
10406 v14 = uOutX;
10407 v8 = v13 - v14;
10408 }
10409 v15 = this->uClipY;
10410 if ( (signed int)v15 < (signed int)v6 )
10411 v15 = v6;
10412 v16 = this->uClipW;
10413 if ( (signed int)(v7 + v15) > (signed int)v16 )
10414 {
10415 v17 = this->uClipY;
10416 if ( (signed int)v17 >= (signed int)v6 )
10417 v6 = v17;
10418 v7 = v16 - v6;
10419 }
10420 }
10421 if ( v7 > 0 )
10422 {
10423 uOutXa = v7;
10424 do
10425 {
10426 if ( v8 > 0 )
10427 {
10428 v18 = v8;
10429 do
10430 {
10431 if ( *uOutYa )
10432 *pZBuffer = zVal;
10433 ++pZBuffer;
10434 ++uOutYa;
10435 --v18;
10436 }
10437 while ( v18 );
10438 }
10439 pZBuffer += 640 - v8;
10440 uOutYa += v19 - v8;
10441 --uOutXa;
10442 }
10443 while ( uOutXa );
10444 }
10445 }
10446 }
10447 }
10448
10449
10450 //----- (004A601E) --------------------------------------------------------
10451 void Render::_4A601E(signed int a2, signed int a3, Texture *pTexture, int a5)
10452 {
10453 signed int v5; // edx@3
10454 int v6; // ebx@3
10455 int v7; // esi@3
10456 void *v8; // esi@3
10457 unsigned int v9; // eax@4
10458 unsigned int v10; // eax@6
10459 signed int v11; // edi@8
10460 unsigned int v12; // eax@10
10461 signed int v13; // edi@11
10462 unsigned int v14; // edi@14
10463 unsigned int v15; // eax@16
10464 unsigned int v16; // ecx@17
10465 int v17; // [sp+18h] [bp+Ch]@3
10466 unsigned int pTexturea; // [sp+1Ch] [bp+10h]@3
10467
10468 if ( this->uNumSceneBegins && pTexture )
10469 {
10470 v5 = a3;
10471 v6 = pTexture->uTextureHeight;
10472 v7 = 5 * a3;
10473 v17 = pTexture->uTextureHeight;
10474 v8 = &this->pActiveZBuffer[a2 + (v7 << 7)];
10475 pTexturea = pTexture->uTextureWidth;
10476 if ( this->bClip )
10477 {
10478 v9 = this->uClipX;
10479 if ( a2 < (signed int)v9 )
10480 {
10481 pTexturea += a2 - v9;
10482 v8 = (char *)v8 + 4 * (v9 - a2);
10483 }
10484 v10 = this->uClipY;
10485 if ( v5 < (signed int)v10 )
10486 {
10487 v17 += v5 - v10;
10488 v8 = (char *)v8 + 2560 * (v10 - v5);
10489 }
10490 v11 = this->uClipX;
10491 if ( v11 < a2 )
10492 v11 = a2;
10493 v12 = this->uClipZ;
10494 if ( (signed int)(pTexturea + v11) > (signed int)v12 )
10495 {
10496 v13 = this->uClipX;
10497 if ( v13 < a2 )
10498 v13 = a2;
10499 pTexturea = v12 - v13;
10500 }
10501 v14 = this->uClipY;
10502 if ( (signed int)v14 < v5 )
10503 v14 = v5;
10504 v6 = v17;
10505 v15 = this->uClipW;
10506 if ( (signed int)(v17 + v14) > (signed int)v15 )
10507 {
10508 v16 = this->uClipY;
10509 if ( (signed int)v16 < v5 )
10510 v16 = v5;
10511 v6 = v15 - v16;
10512 }
10513 }
10514 if ( v6 > 0 )
10515 {
10516 do
10517 {
10518 if ( (signed int)pTexturea > 0 )
10519 {
10520 memset32(v8, a5, pTexturea);
10521 v8 = (char *)v8 + 4 * pTexturea;
10522 }
10523 v8 = (char *)v8 + 4 * (640 - pTexturea);
10524 --v6;
10525 }
10526 while ( v6 );
10527 }
10528 }
10529 }
10530
10531 //----- (004A5EB2) --------------------------------------------------------
10532 void Render::DrawTextureIndexed(unsigned int uX, unsigned int uY, Texture *a4)
10533 {
10534 Texture *v4; // edi@2
10535 unsigned int v5; // ebx@4
10536 unsigned __int16 *pTarget; // eax@4
10537 unsigned int v7; // edx@5
10538 unsigned int v8; // edx@6
10539 unsigned int v9; // edx@7
10540 unsigned int v10; // edx@8
10541 unsigned int v11; // edx@9
10542 unsigned int v12; // esi@12
10543 unsigned int v13; // esi@15
10544 unsigned int v14; // edx@17
10545 unsigned int v15; // esi@18
10546 unsigned __int8 *v16; // edx@22
10547 char v17; // zf@26
10548 int v18; // [sp+10h] [bp-10h]@4
10549 unsigned __int8 *v19; // [sp+18h] [bp-8h]@4
10550 int v20; // [sp+1Ch] [bp-4h]@4
10551 int uXa; // [sp+28h] [bp+8h]@24
10552 unsigned int uYa; // [sp+2Ch] [bp+Ch]@22
10553 unsigned int v23; // [sp+30h] [bp+10h]@11
10554
10555 if ( this->uNumSceneBegins )
10556 {
10557 v4 = a4;
10558 if ( a4 )
10559 {
10560 if ( a4->pPalette16 )
10561 {
10562 v5 = a4->uTextureHeight;
10563 pTarget = &this->pTargetSurface[uX + uY * this->uTargetSurfacePitch];
10564 v19 = a4->pLevelOfDetail0;
10565 v20 = a4->uTextureWidth;
10566 v18 = a4->uTextureWidth;
10567 if ( this->bClip )
10568 {
10569 v7 = this->uClipX;
10570 if ( (signed int)uX < (signed int)v7 )
10571 {
10572 v8 = v7 - uX;
10573 v19 += v8;
10574 v20 += uX - this->uClipX;
10575 pTarget += v8;
10576 }
10577 v9 = this->uClipY;
10578 v5 = a4->uTextureHeight;
10579 if ( (signed int)uY < (signed int)v9 )
10580 {
10581 v10 = v9 - uY;
10582 v19 += v18 * v10;
10583 v5 = uY - this->uClipY + a4->uTextureHeight;
10584 v4 = a4;
10585 pTarget += this->uTargetSurfacePitch * v10;
10586 }
10587 v11 = this->uClipX;
10588 if ( (signed int)v11 < (signed int)uX )
10589 v11 = uX;
10590 v23 = this->uClipZ;
10591 if ( (signed int)(v11 + v20) > (signed int)v23 )
10592 {
10593 v12 = this->uClipX;
10594 if ( (signed int)v12 < (signed int)uX )
10595 v12 = uX;
10596 v20 = v23 - v12;
10597 }
10598 v13 = this->uClipY;
10599 if ( (signed int)v13 < (signed int)uY )
10600 v13 = uY;
10601 v14 = this->uClipW;
10602 if ( (signed int)(v5 + v13) > (signed int)v14 )
10603 {
10604 v15 = this->uClipY;
10605 if ( (signed int)v15 < (signed int)uY )
10606 v15 = uY;
10607 v5 = v14 - v15;
10608 }
10609 }
10610 if ( (signed int)v5 > 0 )
10611 {
10612 uYa = v5;
10613 v16 = v19;
10614 do
10615 {
10616 if ( v20 > 0 )
10617 {
10618 uXa = v20;
10619 do
10620 {
10621 *pTarget = v4->pPalette16[*v16];
10622 ++pTarget;
10623 ++v16;
10624 --uXa;
10625 }
10626 while ( uXa );
10627 }
10628 v16 += v18 - v20;
10629 v17 = uYa-- == 1;
10630 pTarget += this->uTargetSurfacePitch - v20;
10631 }
10632 while ( !v17 );
10633 }
10634 }
10635 }
10636 }
10637 }
10638
10639 //----- (004667E9) --------------------------------------------------------
10640 void Render::ChangeBetweenWinFullscreenModes()
10641 {
10642 float v0; // ST14_4@17
10643 int v1; // edx@24
10644 signed int v2; // ecx@24
10645 int v3; // esi@25
10646 int v4; // edx@26
10647 ObjectDesc *v5; // eax@26
10648 RGBTexture *v6; // esi@33
10649 const char *v7; // eax@34
10650 const char *v8; // [sp-4h] [bp-28h]@33
10651 int v9; // [sp+0h] [bp-24h]@33
10652 struct tagRECT Rect; // [sp+14h] [bp-10h]@15
10653
10654 if ( pRenderer->bWindowMode )
10655 goto LABEL_52;
10656 if ( dword_6BE364_game_settings_1 & 2 )
10657 {
10658 ModalWindow(pGlobalTXT_LocalizationStrings[62], 0);// "Might and Magic VII requires your desktop to be in 16bit (32k or 65k) Color mode in order to operate in a window."
10659 return;
10660 }
10661 if ( !pRenderer->pRenderD3D || pRenderer->pRenderD3D->pAvailableDevices->bIsDeviceCompatible )
10662 {
10663 LABEL_52:
10664 if ( pEventTimer->bPaused )
10665 BYTE1(dword_6BE364_game_settings_1) |= 8u;
10666 else
10667 pEventTimer->Pause();
10668 if ( pMiscTimer->bPaused )
10669 BYTE1(dword_6BE364_game_settings_1) |= 0x10u;
10670 else
10671 pMiscTimer->Pause();
10672 pMouse->bActive = 0;
10673 if ( pRenderer->pRenderD3D )
10674 {
10675 pBitmaps_LOD->ReleaseHardwareTextures();
10676 pSprites_LOD->ReleaseAll();
10677 }
10678 if ( pRenderer->bWindowMode )
10679 {
10680 if ( GetWindowRect(hWnd, &Rect) )
10681 {
10682 WriteWindowsRegistryInt("window X", Rect.left);
10683 WriteWindowsRegistryInt("window Y", Rect.top);
10684 uWindowX = Rect.left;
10685 uWindowY = Rect.top;
10686 }
10687 SetMenu(hWnd, 0);
10688 SetWindowLongA(hWnd, -20, 0);
10689 SetWindowLongA(hWnd, -16, 0x10000000u);
10690 pRenderer->InitializeFullscreen(hWnd);
10691 v0 = (double)(signed int)uGammaPos * 0.1 + 0.6;
10692 pGame->pGammaController->Initialize(v0);
10693 }
10694 else
10695 {
10696 ClipCursor(0);
10697 pRenderer->SwitchToWindow(hWnd);
10698 SetWindowLongA(hWnd, -16, uWindowStyle);
10699 SetMenu(hWnd, hOSMenu);
10700 }
10701 if ( pRenderer->pRenderD3D )
10702 {
10703 pBitmaps_LOD->_410423_move_textures_to_device();
10704 pSprites_LOD->MoveSpritesToVideoMemory();
10705 }
10706 if ( pPaletteManager->uNumTargetBBits == pRenderer->uTargetBBits
10707 && pPaletteManager->uNumTargetGBits == pRenderer->uTargetGBits
10708 && pPaletteManager->uNumTargetRBits == pRenderer->uTargetRBits )
10709 goto LABEL_38;
10710 pPaletteManager->SetColorChannelInfo(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
10711 pPaletteManager->RecalculateAll();
10712 pBitmaps_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
10713 pIcons_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
10714 v2 = 0;
10715 if ( (signed int)pObjectList->uNumObjects > 0 )
10716 {
10717 v3 = 0;
10718 do
10719 {
10720 BYTE3(v4) = 0;
10721 v5 = &pObjectList->pObjects[v3];
10722 ++v3;
10723 *(short *)((char *)&v4 + 1) = v5->uParticleTrailColorR;
10724 LOBYTE(v4) = v5->uParticleTrailColorG;
10725 v1 = v5->uParticleTrailColorB | (v4 << 8);
10726 ++v2;
10727 v5->uParticleTrailColor = v1;
10728 }
10729 while ( v2 < (signed int)pObjectList->uNumObjects );
10730 }
10731 LOBYTE(v1) = 1;
10732 SetUserInterface(pParty->uAlignment, v1);
10733 if ( pVideoPlayer->pVideoFrame.pPixels )
10734 pVideoPlayer->pVideoFrame.Load(pVideoPlayer->pVideoFrameTextureFilename, 1);
10735 if ( uCurrentMenuID )
10736 {
10737 if ( uCurrentMenuID != 6 )
10738 {
10739 if ( uCurrentMenuID == 8 )
10740 dword_A74C88 = 1;
10741 goto LABEL_38;
10742 }
10743 v6 = &pTexture_PCX;
10744 pTexture_PCX.Release();
10745 v9 = 0;
10746 v8 = "makeme.pcx";
10747 }
10748 else
10749 {
10750 v6 = &pTexture_PCX;
10751 pTexture_PCX.Release();
10752 v7 = "title.pcx";
10753 if ( uCurrentMenuID )
10754 v7 = "lsave640.pcx";
10755 v9 = 0;
10756 v8 = v7;
10757 }
10758 v6->Load(v8, v9);
10759 LABEL_38:
10760 viewparams->bRedrawGameUI = 1;
10761 viewparams->_443343();
10762 pMouse->SetCurrentCursorBitmap();
10763 if ( pRenderer->bWindowMode )
10764 {
10765 InvalidateRect(0, 0, 0);
10766 MoveWindow(hWnd, uWindowX, uWindowY, uWindowWidth, uWindowHeight, 0);
10767 ShowWindow(hWnd, 1);
10768 }
10769 pMouse->bActive = 1;
10770 if ( pVideoPlayer->AnyMovieLoaded() )
10771 pVideoPlayer->_4BF73A();
10772 if ( BYTE1(dword_6BE364_game_settings_1) & 8 )
10773 BYTE1(dword_6BE364_game_settings_1) &= 0xF7u;
10774 else
10775 pEventTimer->Resume();
10776 if ( BYTE1(dword_6BE364_game_settings_1) & 0x10 )
10777 BYTE1(dword_6BE364_game_settings_1) &= 0xEFu;
10778 else
10779 pMiscTimer->Resume();
10780 pAsyncMouse->Release();
10781 CreateAsyncMouse();
10782 if (pAsyncMouse)
10783 pAsyncMouse->Clip();
10784 }
10785 }
10786 // 6BE364: using guessed type int dword_6BE364_game_settings_1;
10787 // A74C88: using guessed type int dword_A74C88;
10788
10789
10790 //----- (0044EC20) --------------------------------------------------------
10791 bool RenderD3D::DoesRaiseExceptions()
10792 {
10793 return true;
10794 }
10795
10796
10797 //----- (0040DBD3) --------------------------------------------------------
10798 void __fastcall Render::SetPixel(Vec2_int_ *pTargetXY, unsigned __int16 uColor)
10799 {
10800 Vec2_int_ *pTargetXY_; // esi@1
10801 unsigned __int16 v3; // di@1
10802 signed int v4; // ecx@2
10803 signed int v5; // eax@4
10804
10805 pTargetXY_ = pTargetXY;
10806 v3 = uColor;
10807 pRenderer->BeginScene();
10808 if ( pRenderer->uNumSceneBegins )
10809 {
10810 v4 = pTargetXY_->x;
10811 if ( pTargetXY_->x >= 0 )
10812 {
10813 if ( v4 <= 639 )
10814 {
10815 v5 = pTargetXY_->y;
10816 if ( v5 >= 0 )
10817 {
10818 if ( v5 <= 479 )
10819 pRenderer->pTargetSurface[v4 + pRenderer->uTargetSurfacePitch * v5] = v3;
10820 }
10821 }
10822 }
10823 pRenderer->EndScene();
10824 }
10825 }
10826
10827
10828 //----- (004524D8) --------------------------------------------------------
10829 HWLTexture *RenderHWLContainer::LoadTexture(const char *pName, int bMipMaps)
10830 {
10831 int v11; // eax@13
10832 int v12; // ecx@13
10833 void *v13; // eax@13
10834 unsigned __int8 v14; // zf@13
10835 unsigned __int8 v15; // sf@13
10836 int v16; // esi@14
10837 int v17; // ecx@16
10838 int v18; // esi@16
10839 unsigned __int16 *v19; // eax@16
10840 int v20; // edx@16
10841 int v21; // ecx@16
10842 int v22; // eax@16
10843 int v23; // esi@16
10844 unsigned __int16 *v26; // [sp+24h] [bp-10h]@13
10845 int v27; // [sp+28h] [bp-Ch]@14
10846 int v28; // [sp+2Ch] [bp-8h]@13
10847 int pDestb; // [sp+3Ch] [bp+8h]@15
10848
10849 //v3 = this;
10850 //sprintf(Str1, "%s", pName);
10851 //v4 = uNumItems;
10852 if (!uNumItems)
10853 return nullptr;
10854
10855 //{
10856 //v5 = 0, pDesta = uNumItems;
10857 uint idx1 = 0,
10858 idx2 = uNumItems;
10859 while (true)
10860 {
10861 auto i = idx1 + (idx2 - idx1) / 2;
10862
10863 auto res = strcmpi(pName, pSpriteNames[i]);
10864 if (!res)
10865 {
10866 fseek(pFile, pSpriteOffsets[i], SEEK_SET);
10867 break;
10868 }
10869 else if (res < 0)
10870 idx2 = idx1 + (idx2 - idx1) / 2;
10871 else
10872 idx1 = i + 1;
10873
10874 if ( idx1 >= idx2 )
10875 return false;
10876 }
10877
10878
10879 uint uCompressedSize = 0;
10880 fread(&uCompressedSize, 4, 1, pFile);
10881
10882 auto pTex = new HWLTexture;
10883 fread(&pTex->field_18, 4, 1, pFile);
10884 fread(&pTex->field_1C, 4, 1, pFile);
10885 fread(&pTex->field_20, 4, 1, pFile);
10886 fread(&pTex->field_24, 4, 1, pFile);
10887 fread(&pTex->uWidth, 4, 1, pFile);
10888 fread(&pTex->uHeight, 4, 1, pFile);
10889 fread(&pTex->field_30, 4, 1, pFile);
10890 fread(&pTex->field_34, 4, 1, pFile);
10891
10892 pTex->pPixels = new unsigned __int16[pTex->uWidth * pTex->uHeight];
10893 if (uCompressedSize)
10894 {
10895 auto pCompressedData = new char[uCompressedSize];
10896 {
10897 fread(pCompressedData, 1, uCompressedSize, pFile);
10898 auto uDecompressedSize = pTex->uWidth * pTex->uHeight * sizeof(short);
10899 zlib::MemUnzip(pTex->pPixels, &uDecompressedSize, pCompressedData, uCompressedSize);
10900 }
10901 delete [] pCompressedData;
10902 }
10903 else
10904 fread(pTex->pPixels, 2, pTex->uWidth * pTex->uHeight, pFile);
10905
10906 if ( field_61A94_scale_hwls_to_half )
10907 {
10908 v11 = pTex->uHeight / 2;
10909 v12 = pTex->uWidth / 2;
10910 pTex->uHeight = v11;
10911 pTex->uWidth = v12;
10912 v13 = new unsigned __int16[v12 * v11];
10913 v28 = 0;
10914 v14 = pTex->uHeight == 0;
10915 v15 = (pTex->uHeight & 0x80000000u) != 0;
10916 v26 = (unsigned __int16 *)v13;
10917 if ( !(v15 | v14) )
10918 {
10919 v16 = pTex->uWidth;
10920 v27 = 1;
10921 do
10922 {
10923 pDestb = 0;
10924 if ( v16 > 0 )
10925 {
10926 do
10927 {
10928 v17 = v16 * v27;
10929 v18 = v28 * v16;
10930 v19 = pTex->pPixels;
10931 v20 = pDestb + 2 * v18;
10932 v21 = (int)&v19[2 * (pDestb + v17)];
10933 v22 = (int)&v19[2 * v20];
10934 LOWORD(v20) = *(unsigned short *)(v21 + 2);
10935 LOWORD(v21) = *(unsigned short *)v21;
10936 v23 = pDestb++ + v18;
10937 v26[v23] = sub_452442(*(unsigned short *)v22, *(unsigned short *)(v22 + 2), v21, v20);
10938 v16 = pTex->uWidth;
10939 }
10940 while (pDestb < pTex->uWidth);
10941 }
10942 ++v28;
10943 v27 += 2;
10944 }
10945 while ( v28 < (signed int)pTex->uHeight );
10946 }
10947 delete [] pTex->pPixels;
10948 pTex->pPixels = v26;
10949 }
10950 return pTex;
10951 //result = pTex;
10952 // }
10953 // else
10954 // {
10955 //LABEL_8:
10956 // return nullptr;
10957 // }
10958 }
10959
10960 //----- (0045271F) --------------------------------------------------------
10961 bool RenderHWLContainer::Release()
10962 {
10963 RenderHWLContainer *v1; // esi@1
10964 int v2; // ebx@1
10965 void **v3; // edi@3
10966 __int32 v4; // eax@6
10967 FILE *v5; // ST24_4@6
10968 size_t *v6; // edi@6
10969 int v7; // ebx@7
10970 signed int v9; // [sp+0h] [bp-8h]@6
10971 FILE *File; // [sp+4h] [bp-4h]@6
10972
10973 v1 = this;
10974 v2 = 0;
10975 if ( this->bDumpDebug )
10976 {
10977 File = fopen("logd3d.txt", "w");
10978 v4 = ftell(v1->pFile);
10979 v5 = v1->pFile;
10980 v6 = &v1->uNumItems;
10981 v1->uDataOffset = v4;
10982 fwrite(&v1->uNumItems, 4u, 1u, v5);
10983 v9 = 0;
10984 if ( (signed int)v1->uNumItems > 0 )
10985 {
10986 v7 = (int)v1->pSpriteNames;
10987 do
10988 {
10989 fwrite(*(const void **)v7, 1u, 0x14u, v1->pFile);
10990 fprintf(File, "D3D texture name: %s\t\toffset: %x\n", *(unsigned int *)v7, *(unsigned int *)(v7 + 200000));
10991 ++v9;
10992 v7 += 4;
10993 }
10994 while ( v9 < (signed int)*v6 );
10995 v2 = 0;
10996 }
10997 fwrite(v1->pSpriteOffsets, 4u, *v6, v1->pFile);
10998 fseek(v1->pFile, 4, v2);
10999 fwrite(&v1->uDataOffset, 4u, 1u, v1->pFile);
11000 fclose(v1->pFile);
11001 fclose(File);
11002 }
11003 else
11004 {
11005 fclose(this->pFile);
11006 if ( (signed int)v1->uNumItems > 0 )
11007 {
11008 v3 = (void **)v1->pSpriteNames;
11009 do
11010 {
11011 free(*v3);
11012 ++v2;
11013 ++v3;
11014 }
11015 while ( v2 < (signed int)v1->uNumItems );
11016 }
11017 }
11018 return 1;
11019 }
11020
11021 //----- (00452347) --------------------------------------------------------
11022 RenderHWLContainer::RenderHWLContainer():
11023 bDumpDebug(false)
11024 {
11025 RenderHWLContainer *v1; // esi@1
11026
11027 v1 = this;
11028 this->pFile = 0;
11029 uSignature = 0;
11030 v1->uDataOffset = 0;
11031 memset(&v1->uNumItems, 0, 0x61A84u);
11032 v1->uNumItems = 0;
11033 v1->field_61A94_scale_hwls_to_half = 0;
11034 }
11035
11036 //----- (0045237F) --------------------------------------------------------
11037 bool RenderHWLContainer::Load(const wchar_t *pFilename)
11038 {
11039 pFile = _wfopen(pFilename, L"rb");
11040 if (!pFile)
11041 {
11042 Log::Warning(L"Failed to open file: %s", pFilename);
11043 return false;
11044 }
11045
11046 fread(&uSignature, 1, 4, pFile);
11047 if (uSignature != 'TD3D')
11048 {
11049 Log::Warning(L"Invalid format: %s", pFilename);
11050 return false;
11051 }
11052
11053 fread(&uDataOffset, 4, 1, pFile);
11054 fseek(pFile, uDataOffset, SEEK_SET);
11055 fread(&uNumItems, 4, 1, pFile);
11056
11057 memset(pSpriteNames, 0, 50000 * sizeof(char *));
11058 for (uint i = 0; i < uNumItems; ++i)
11059 {
11060 pSpriteNames[i] = new char[20];
11061 fread(pSpriteNames[i], 1, 20, pFile);
11062 }
11063 fread(pSpriteOffsets, 4, uNumItems, pFile);
11064
11065 return true;
11066 }
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076 //----- (004A1C1E) --------------------------------------------------------
11077 void DoRenderBillboards_D3D()
11078 {
11079 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 3u));
11080 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 1u));
11081 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 0));
11082 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u));
11083
11084 for (uint i = pRenderer->uNumBillboardsToDraw - 1; i != (uint)-1; --i)
11085 {
11086 auto p = pRenderer->pBillboardRenderListD3D + i;
11087
11088 if (p->uOpacity != RenderBillboardD3D::InvalidOpacity)
11089 SetBillboardBlendOptions(p->uOpacity);
11090
11091 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, p->pTexture));
11092 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
11093 p->pQuards, p->uNumVertices, D3DDP_DONOTLIGHT | D3DDP_DONOTUPDATEEXTENTS));
11094 }
11095
11096 if (pRenderer->bFogEnabled)
11097 {
11098 pRenderer->bFogEnabled = false;
11099 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1));
11100 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF));
11101 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
11102 }
11103 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 2));
11104 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1));
11105 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, 0));
11106 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2u));
11107 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1u));
11108 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1u));
11109 }
11110
11111
11112
11113
11114
11115 //----- (004A1DA8) --------------------------------------------------------
11116 void SetBillboardBlendOptions(RenderBillboardD3D::OpacityType a1)
11117 {
11118 switch (a1)
11119 {
11120 case RenderBillboardD3D::Transparent:
11121 {
11122 if (pRenderer->bFogEnabled)
11123 {
11124 pRenderer->bFogEnabled = false;
11125 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1u));
11126 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF));
11127 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
11128 }
11129
11130 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 5));
11131 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 6u));
11132 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 1));
11133 }
11134 break;
11135
11136 case RenderBillboardD3D::Opaque_1:
11137 case RenderBillboardD3D::Opaque_2:
11138 case RenderBillboardD3D::Opaque_3:
11139 {
11140 if (pRenderer->bUsingSpecular)
11141 {
11142 if (!pRenderer->bFogEnabled)
11143 {
11144 pRenderer->bFogEnabled = true;
11145 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0));
11146 }
11147 }
11148
11149 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2));
11150 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 2u));
11151 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, 0));
11152 }
11153 break;
11154
11155 default:
11156 Log::Warning(L"SetBillboardBlendOptions: invalid opacity type (%u)", a1);
11157 break;
11158 }
11159 }
11160