diff Render.cpp @ 2215:e9625ad08541

fog fix and change 640,480 - window->GetWidth(), window->GetHeight()
author Ritor1
date Fri, 14 Feb 2014 18:08:30 +0600
parents ff8920a40c21
children 3f375342de12
line wrap: on
line diff
--- a/Render.cpp	Thu Feb 13 23:02:32 2014 +0600
+++ b/Render.cpp	Fri Feb 14 18:08:30 2014 +0600
@@ -666,9 +666,7 @@
     memcpy(v20.pGUID, lpGUID, 0x10u);
   }
   else
-  {
     v20.pGUID = 0;
-  }
 
   if (FAILED(DirectDrawCreate(v20.pGUID, &pDirectDraw, 0)))
   {
@@ -690,10 +688,8 @@
     else
     {
       pDirectDraw->Release();
-      if (FAILED( pDirectDraw4->GetDeviceIdentifier(&ddDevId, 1u)))
-      {
+      if (FAILED( pDirectDraw4->GetDeviceIdentifier(&ddDevId, 1)))
         v20.pDDraw4DevDesc = 0;
-      }
       else
       {
         v7 = strlen(ddDevId.szDescription);
@@ -701,24 +697,17 @@
         strcpy(v20.pDDraw4DevDesc, ddDevId.szDescription);
       }
       memset(&ddsCaps, 0, 0x10u);
-      if (FAILED(pDirectDraw4->GetAvailableVidMem(
-             &ddsCaps,
-             (LPDWORD)&v20.uVideoMem,
-             (LPDWORD)&uFreeVideoMem)))
+      if (FAILED(pDirectDraw4->GetAvailableVidMem(&ddsCaps, (LPDWORD)&v20.uVideoMem, (LPDWORD)&uFreeVideoMem)))
         v20.uVideoMem = 0;
       memset(&v10, 0, 0x7Cu);
       v10.dwSize = 124;
       v10.dwFlags = 6;
-      v10.dwHeight = 640;
-      v10.dwWidth = 480;
+      v10.dwHeight = window->GetWidth();
+      v10.dwWidth = window->GetHeight();
       v10.ddpfPixelFormat.dwSize = 32;
 
       v19 = 0;
-      if ( FAILED(pDirectDraw4->EnumDisplayModes(
-             0,
-             0,
-             &v19,
-             (LPDDENUMMODESCALLBACK2)DDrawDisplayModesEnumerator))
+      if ( FAILED(pDirectDraw4->EnumDisplayModes(0, 0, &v19, (LPDDENUMMODESCALLBACK2)DDrawDisplayModesEnumerator))
         || !v19
         || FAILED(pDirectDraw4->QueryInterface(IID_IDirect3D3, (LPVOID *)&pDirect3D3)))
       {
@@ -839,28 +828,17 @@
     result = 0;
   }
   else
-  {
     result = 1;
-  }
   return result;
 }
 
 //----- (0047A95E) --------------------------------------------------------
 void Render::PrepareDecorationsRenderList_ODM()
 {
-  //char *v0; // esi@2
-  //DecorationDesc *v1; // ebx@6
-  __int16 v2; // ax@6
-  double v3; // st7@7
-  //int v4; // eax@9
-  //int v5; // edx@9
   unsigned int v6; // edi@9
   int v7; // eax@9
   SpriteFrame *v8; // eax@9
-  //SpriteFrame *v9; // edi@9
   unsigned __int16 *v10; // eax@9
-  int v11; // ecx@9
-  int v12; // eax@9
   int v13; // ecx@9
   int v14; // ecx@20
   char v15; // dl@20
@@ -871,57 +849,32 @@
   int v20; // ecx@24
   int v21; // ebx@26
   int v22; // eax@26
-  int v23; // eax@30
   signed __int64 v24; // qtt@31
   int v25; // ebx@31
-  int v26; // ecx@32
-  RenderBillboard *v27; // eax@37
-  __int16 v28; // dx@37
   __int16 v29; // cx@37
   int v30; // ecx@37
   int v31; // ebx@37
   Particle_sw local_0; // [sp+Ch] [bp-98h]@7
-  //int x; // [sp+74h] [bp-30h]@9
-  //int y; // [sp+78h] [bp-2Ch]@9
-  //int v35; // [sp+7Ch] [bp-28h]@1
-  //int v36; // [sp+80h] [bp-24h]@9
   unsigned __int16 *v37; // [sp+84h] [bp-20h]@9
   int v38; // [sp+88h] [bp-1Ch]@9
-  int v39; // [sp+8Ch] [bp-18h]@24
   int v40; // [sp+90h] [bp-14h]@24
   int v41; // [sp+94h] [bp-10h]@24
   int v42; // [sp+98h] [bp-Ch]@9
-  int a5; // [sp+9Ch] [bp-8h]@9
   int b; // [sp+A0h] [bp-4h]@22
 
-  //v35 = 0;
-  //if ( (signed int)uNumLevelDecorations > 0 )
-  //{
-    //v0 = (char *)&pLevelDecorations[0].vPosition.y;
-    //do
   for (int i = 0; i < uNumLevelDecorations; ++i)
   {
     LevelDecoration* decor = &pLevelDecorations[i];
-    char* v0 = (char *)&pLevelDecorations[i].vPosition.y;
-
     if ((!(decor->uFlags & LEVEL_DECORATION_OBELISK_CHEST) || decor->IsObeliskChestActive()) && !(decor->uFlags & LEVEL_DECORATION_INVISIBLE))
     {
-      //v1 = &pDecorationList->pDecorations[decor->uDecorationDescID];
       DecorationDesc* decor_desc = pDecorationList->pDecorations + decor->uDecorationDescID;
-      v2 = decor_desc->uFlags;
-      if ( (char)v2 >= 0 )
-      {
-        if ( !(v2 & 0x22) )
+      if ( (char)decor_desc->uFlags >= 0 )
+      {
+        if ( !(decor_desc->uFlags & 0x22) )
         {
-          //v4 = decor->vPosition.x;
-          //v5 = decor->vPosition.z;
           v6 = pMiscTimer->uTotalGameTimeElapsed;
-          //y = decor->vPosition.y;
-          //x = decor->vPosition.x;
-          //v36 = decor->vPosition.z;
           v7 = abs(decor->vPosition.x + decor->vPosition.y);
 
-
           #pragma region "New: seasons change"
           extern bool change_seasons;
           if (change_seasons)
@@ -989,26 +942,20 @@
           #pragma endregion
           //v8 = pSpriteFrameTable->GetFrame(decor_desc->uSpriteID, v6 + v7);
 
-          //v9 = v8;
-          v42 = v8->uFlags;
-          a5 = v8->uGlowRadius;
           v10 = (unsigned __int16 *)stru_5C6E00->Atan2(decor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
                                                        decor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
-          v11 = *((int *)v0 + 2);
-          v37 = v10;
-          v12 = v42;
           v38 = 0;
-          v13 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v11 - (signed int)v37) >> 8) & 7;
+          v13 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + decor->field_10_y_rot - (signed int)v10) >> 8) & 7;
           v37 = (unsigned __int16 *)v13;
-          if ( v42 & 2 )
+          if ( v8->uFlags & 2 )
             v38 = 2;
-          if ( (256 << v13) & v42 )
-            v38 |= 4u;
-          if ( v12 & 0x40000 )
-            v38 |= 0x40u;
-          if ( v12 & 0x20000 )
+          if ( (256 << v13) & v8->uFlags )
+            v38 |= 4;
+          if ( v8->uFlags & 0x40000 )
+            v38 |= 0x40;
+          if ( v8->uFlags & 0x20000 )
             LOBYTE(v38) = v38 | 0x80;
-          if ( a5 )
+          if ( v8->uGlowRadius )
           {
             if ( pRenderer->pRenderD3D && pRenderer->bUseColoredLights )
             {
@@ -1022,119 +969,125 @@
               v14 = 255;
               v15 = 255;
             }
-            b = v16;
             pStationaryLightsStack->AddLight(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z + decor_desc->uDecorationHeight / 2,
-              a5, v14, v15, v16, _4E94D0_light_type);
+              v8->uGlowRadius, v14, v15, v16, _4E94D0_light_type);
           }
           v17 = (decor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
           if (pGame->pIndoorCameraD3D->sRotationX)
           {
             v40 = (decor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
             v18 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
-            v42 = v18;
-            b = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_sine_y);
-            a5 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y);
-            v40 = (decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-            v41 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_x);
+            v41 = fixpoint_mul((decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x);
             v19 = fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_cosine_x);
-            v20 = v19 + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_x);
-            v39 = v19 + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_x);
+            v20 = v19 + fixpoint_mul((decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x);
             if ( v20 >= 0x40000 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
             {
-              v21 = a5 - b;
-              v41 = a5 - b;
-              //a5 = fixpoint_mul(v42, pGame->pIndoorCameraD3D->int_sine_x);
-              b = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_x);
-              v22 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v42, pGame->pIndoorCameraD3D->int_sine_x);
-LABEL_30:
-              v42 = v22;
-              v40 = 2 * abs(v20);
-              v23 = abs(v21);
-              if ( v40 >= v23 )
+              v21 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_sine_y);
+              v22 = fixpoint_mul((decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_sine_x);
+              if ( 2 * abs(v20) >= abs(v21) )
               {
                 LODWORD(v24) = 0;
                 HIDWORD(v24) = SLOWORD(pODMRenderParams->int_fov_rad);
-                a5 = v24 / v39;
-                v25 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v24 / v39, v41) + 0x8000) >> 16);
-                b = fixpoint_mul(a5, v42);
-                v41 = v24 / v39;
-                v40 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(a5, v42) + 0x8000) >> 16);
-                //v42 = v8->scale;
-                v41 = fixpoint_mul(v8->scale, v24 / v39);
-                v37 = (unsigned __int16 *)&v8->pHwSpriteIDs[(int)v37];
+                v25 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v24 / v20, v21) + 0x8000) >> 16);
+                v40 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(v24 / v20, v22) + 0x8000) >> 16);
+                v41 = fixpoint_mul(v8->scale, v24 / v20);
                 if ( pRenderer->pRenderD3D )
-                {
-                  v26 = v41;
-                  //v42 = pSprites_LOD->pHardwareSprites[(signed __int16)*v37].uBufferWidth / 2;
-                  b = fixpoint_mul(pSprites_LOD->pHardwareSprites[(signed __int16)*v37].uBufferWidth / 2, v41);
-                }
+                  b = fixpoint_mul(pSprites_LOD->pHardwareSprites[v8->pHwSpriteIDs[(int)v37]].uBufferWidth / 2, v41);
                 else
-                {
-                  v26 = v41;
-                  //v42 = pSprites_LOD->pSpriteHeaders[(signed __int16)*v37].uWidth / 2;
-                  b = fixpoint_mul(pSprites_LOD->pSpriteHeaders[(signed __int16)*v37].uWidth / 2, v41);
-                }
+                  b = fixpoint_mul(pSprites_LOD->pSpriteHeaders[v8->pHwSpriteIDs[(int)v37]].uWidth / 2, v41);
                 if ( b + v25 >= (signed int)pViewport->uViewportTL_X && v25 - b <= (signed int)pViewport->uViewportBR_X )
                 {
                   if (::uNumBillboardsToDraw >= 500)
                     return;
-                  v27 = &pBillboardRenderList[::uNumBillboardsToDraw++];
-                  ++uNumDecorationsDrawnThisFrame;
-                  v27->uHwSpriteID = *v37;
-                  v28 = v8->uPaletteIndex;
-                  v27->_screenspace_x_scaler_packedfloat = v26;
-                  v27->_screenspace_y_scaler_packedfloat = v26;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uHwSpriteID = v8->pHwSpriteIDs[(int)v37];
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_x_scaler_packedfloat = v41;
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_y_scaler_packedfloat = v41;
                   v29 = v38;
-                  v27->uScreenSpaceX = v25;
-                  HIBYTE(v29) |= 2u;
-                  v27->uPalette = v28;
-                  v27->field_1E = v29;
-                  v27->world_x = decor->vPosition.x;
-                  v27->world_y = decor->vPosition.y;
-                  v27->world_z = decor->vPosition.z;
-                  v27->uScreenSpaceY = v40;
-                  HIWORD(v30) = HIWORD(v39);
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceX = v25;
+                  HIBYTE(v29) |= 2;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uPalette = v8->uPaletteIndex;
+                  pBillboardRenderList[::uNumBillboardsToDraw].field_1E = v29;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_x = decor->vPosition.x;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_y = decor->vPosition.y;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_z = decor->vPosition.z;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceY = v40;
+                  HIWORD(v30) = HIWORD(v20);
                   v31 = PID(OBJECT_Decoration,i);
                   LOWORD(v30) = 0;
-                  v27->uIndoorSectorID = 0;
-                  v27->sZValue = v30 + v31;
-                  v27->dimming_level = 0;
-                  v27->pSpriteFrame = v8;
-                  v27->sTintColor = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uIndoorSectorID = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sZValue = v30 + v31;
+                  pBillboardRenderList[::uNumBillboardsToDraw].dimming_level = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].pSpriteFrame = v8;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
+                  ::uNumBillboardsToDraw++;
+                  ++uNumDecorationsDrawnThisFrame;
                 }
               }
-              goto LABEL_38;
+              continue;
             }
           }
           else
           {
             v42 = (decor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
             v40 = (decor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-            b = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y);
-            a5 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
-            v20 = b + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
-            v39 = b + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
+            v20 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
             if ( v20 >= 0x40000 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
             {
-              a5 = fixpoint_mul(v42, pGame->pIndoorCameraD3D->int_sine_y);
-              b = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y);
-              v21 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - a5;
-              v41 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - a5;
+              v21 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v42, pGame->pIndoorCameraD3D->int_sine_y);
               v22 = (decor->vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-              goto LABEL_30;
+              v42 = v22;
+              if ( 2 * abs(v20) >= abs(v21) )
+              {
+                LODWORD(v24) = 0;
+                HIDWORD(v24) = SLOWORD(pODMRenderParams->int_fov_rad);
+                v25 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v24 / v20, v21) + 0x8000) >> 16);
+                v40 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(v24 / v20, v42) + 0x8000) >> 16);
+                v41 = fixpoint_mul(v8->scale, v24 / v20);
+                if ( pRenderer->pRenderD3D )
+                  b = fixpoint_mul(pSprites_LOD->pHardwareSprites[v8->pHwSpriteIDs[(int)v37]].uBufferWidth / 2, v41);
+                else
+                  b = fixpoint_mul(pSprites_LOD->pSpriteHeaders[v8->pHwSpriteIDs[(int)v37]].uWidth / 2, v41);
+                if ( b + v25 >= (signed int)pViewport->uViewportTL_X && v25 - b <= (signed int)pViewport->uViewportBR_X )
+                {
+                  if (::uNumBillboardsToDraw >= 500)
+                    return;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uHwSpriteID = v8->pHwSpriteIDs[(int)v37];
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_x_scaler_packedfloat = v41;
+                  pBillboardRenderList[::uNumBillboardsToDraw]._screenspace_y_scaler_packedfloat = v41;
+                  v29 = v38;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceX = v25;
+                  HIBYTE(v29) |= 2;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uPalette = v8->uPaletteIndex;
+                  pBillboardRenderList[::uNumBillboardsToDraw].field_1E = v29;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_x = decor->vPosition.x;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_y = decor->vPosition.y;
+                  pBillboardRenderList[::uNumBillboardsToDraw].world_z = decor->vPosition.z;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uScreenSpaceY = v40;
+                  HIWORD(v30) = HIWORD(v20);
+                  v31 = PID(OBJECT_Decoration,i);
+                  LOWORD(v30) = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].uIndoorSectorID = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sZValue = v30 + v31;
+                  pBillboardRenderList[::uNumBillboardsToDraw].dimming_level = 0;
+                  pBillboardRenderList[::uNumBillboardsToDraw].pSpriteFrame = v8;
+                  pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
+                  ::uNumBillboardsToDraw++;
+                  ++uNumDecorationsDrawnThisFrame;
+                }
+              }
+              continue;
             }
           }
         }
       }
       else
       {
-        memset(&local_0, 0, 0x68u);
-        v3 = (double)*((signed int *)v0 - 1);
+        memset(&local_0, 0, 0x68);
         local_0.type = ParticleType_Bitmap | ParticleType_Rotating | ParticleType_8;
         local_0.uDiffuse = 0xFF3C1E;
-        local_0.x = v3;
-        local_0.y = (double)*(signed int *)v0;
-        local_0.z = (double)*((signed int *)v0 + 1);
+        local_0.x = (double)decor->vPosition.x;
+        local_0.y = (double)decor->vPosition.y;
+        local_0.z = (double)decor->vPosition.z;
         local_0.r = 0.0;
         local_0.g = 0.0;
         local_0.b = 0.0;
@@ -1144,30 +1097,23 @@
         pGame->pParticleEngine->AddParticle(&local_0);
       }
     }
-LABEL_38:
-      ;
-      //++v35;
-      //v0 += 32;
-  }
-    //while ( v35 < (signed int)uNumLevelDecorations );
+  }
 }
 
 //----- (0049D717) --------------------------------------------------------
 HRESULT __stdcall D3DZBufferFormatEnumerator(DDPIXELFORMAT *Src, DDPIXELFORMAT *Dst)
 {
-  HRESULT v2; // esi@2
-
   if ( Src->dwFlags & (0x400 | 0x2000))
   {
-    v2 = 0;
     if ( Src->dwRGBBitCount == 16 && !Src->dwRBitMask )
-      goto LABEL_6;
+    {
+      memcpy(Dst, Src, sizeof(DDPIXELFORMAT));
+      return 0;
+    }
     if ( !Dst->dwSize )
     {
-      v2 = 1;
-LABEL_6:
       memcpy(Dst, Src, sizeof(DDPIXELFORMAT));
-      return v2;
+      return 1;
     }
   }
   return 1;
@@ -1483,7 +1429,7 @@
     sprintf(pErrorMessage, v23);
     goto LABEL_65;
   }
-  if (pHost->SetDisplayMode(640u, 480u, 16u, 0, 0) )
+  if (pHost->SetDisplayMode(window->GetWidth(), window->GetHeight(), 16, 0, 0) )
   {
     v23 = "Init - Failed to set display mode.\n";
     sprintf(pErrorMessage, v23);
@@ -1653,7 +1599,7 @@
   if (bClearDepth)
     uClearFlags |= D3DCLEAR_ZBUFFER;
   
-  D3DRECT rects[] = {{0, 0, 640, 480}};
+  D3DRECT rects[] = {{0, 0, window->GetWidth(), window->GetHeight()}};
   if (uClearFlags)
     pViewport->Clear2(1, rects, uClearFlags, uClearColor, z_clear, 0);
 }
@@ -1666,8 +1612,8 @@
 
   v5.left = 0;
   v5.top = 0;
-  v5.bottom = 480;
-  v5.right = 640;
+  v5.bottom = window->GetHeight();
+  v5.right = window->GetWidth();
 
   if (bWindowed || bForceBlit)
   {
@@ -2784,9 +2730,9 @@
     v3 = v2->pBackBuffer4;
     v4 = v2->pFrontBuffer4;
     v5.top = 0;
-    v5.bottom = 480;
+    v5.bottom = window->GetHeight();
     v5.left = 0;
-    v5.right = 640;
+    v5.right = window->GetWidth();
     v3->BltFast(0, 0, v4, &v5, 16u);
   }
 }
@@ -3027,22 +2973,22 @@
         for (uint y = 0; y < 8; ++y)
           memcpy(pDst + y * Dst.lPitch / 2,
 
-		  pSrc + y * 640, 640 * sizeof(__int16));
+		  pSrc + y * window->GetWidth(), window->GetWidth() * sizeof(__int16));
 
         for (uint y = 8; y < 352; ++y)
         {
           memcpy(pDst + y * Dst.lPitch / 2,
-                 pSrc + y * 640, 8 * sizeof(__int16));
+                 pSrc + y * window->GetWidth(), 8 * sizeof(__int16));
           memcpy(pDst + 8 + game_viewport_width/*462*/ + y * Dst.lPitch / 2,
-                 pSrc + 8 + game_viewport_width/*462*/ + y * 640, 174/*172*/ * sizeof(__int16));
+                 pSrc + 8 + game_viewport_width/*462*/ + y * window->GetWidth(), 174/*172*/ * sizeof(__int16));
         }
 
-        for (uint y = 352; y < 480; ++y)
+        for (uint y = 352; y < window->GetHeight(); ++y)
           memcpy(pDst + y * Dst.lPitch / 2,
-                 pSrc + y * 640, 640 * sizeof(__int16));
-
-
-        ushort* pSrc_x1y1 = pSrc + 640 * pViewport->uViewportTL_Y + pViewport->uViewportTL_X;
+                 pSrc + y * window->GetWidth(), window->GetWidth() * sizeof(__int16));
+
+
+        ushort* pSrc_x1y1 = pSrc + window->GetWidth() * pViewport->uViewportTL_Y + pViewport->uViewportTL_X;
         //_this = (unsigned int)&pSrc[2 * (((signed int)pViewport->uViewportX >> 1) + 320 * pViewport->uViewportY)];
         short* pDst_x1y1 = pDst + Dst.lPitch * pViewport->uViewportTL_Y + pViewport->uViewportTL_X;
         //v23 = (unsigned __int32)((char *)v26 + 4 * (((signed int)pViewport->uViewportX >> 1) + (Dst.lPitch >> 2) * pViewport->uViewportY));
@@ -3064,8 +3010,8 @@
           //       pSrc + pViewport->uViewportX + y * 640, (pViewport->uViewportZ - pViewport->uViewportX) * sizeof(__int16));
           for (uint x = pViewport->uViewportTL_X; x < pViewport->uViewportBR_X; ++x)
           {
-            if (pSrc[y * 640 + x] != (g_mask | b_mask))
-              pDst[y * Dst.lPitch / 2 + x] = pSrc[y * 640 + x];
+            if (pSrc[y * window->GetWidth() + x] != (g_mask | b_mask))
+              pDst[y * Dst.lPitch / 2 + x] = pSrc[y * window->GetWidth() + x];
           }
         }
         }
@@ -3328,7 +3274,7 @@
     {
       pTargetSurface = 0;
       pTargetSurface_unaligned = 0;
-      pTargetSurface_unaligned = (unsigned int *)malloc(640 * 480 * 2 + 32);
+      pTargetSurface_unaligned = (unsigned int *)malloc(window->GetWidth() * window->GetHeight() * 2 + 32);
       if ( !pTargetSurface_unaligned
         || (memset(&pDesc, 0, 0x7Cu),
             pDesc.dwSize = 124,
@@ -3338,7 +3284,7 @@
       v22 = (int *)pTargetSurface_unaligned + 4;
       v23 = (unsigned int)pDesc.lpSurface & 7;
       LOBYTE(v22) = (unsigned __int8)v22 & 0xF8;
-      uTargetSurfacePitch = 640;
+      uTargetSurfacePitch = window->GetWidth();
       pBeforePresentFunction = Present_NoColorKey;
       v15 = 1;
       pTargetSurface = (unsigned __int32 *)((char *)v22 + 2 * v23);
@@ -4050,8 +3996,8 @@
     a2.dwFlags = 7;
     v7 = 0;
     a2.ddsCaps.dwCaps = 2112;
-    a2.dwWidth = 640;
-    a2.dwHeight = 480;
+    a2.dwWidth = window->GetWidth();
+    a2.dwHeight = window->GetHeight();
     v6 = 2387;
     ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer4;
     v4 = (struct _DDSURFACEDESC *)&a2;
@@ -6541,7 +6487,7 @@
   this->uClipX = 0;
   this->bClip = 1;
   this->uClipW = 480;
-  this->uClipZ = 640;
+  this->uClipZ = window->GetWidth();
 }
 
 unsigned __int32 Color32(unsigned __int16 color16)
@@ -7796,7 +7742,7 @@
     {
       v6 = uOutY;
       v7 = pTexture->uTextureHeight;
-      pZBuffer = &this->pActiveZBuffer[uOutX + 640 * uOutY];
+      pZBuffer = &this->pActiveZBuffer[uOutX + window->GetWidth() * uOutY];
       uOutYa = v5->pLevelOfDetail0_prolly_alpha_mask;
       v8 = v5->uTextureWidth;
       v20 = v5->uTextureWidth;
@@ -7817,7 +7763,7 @@
         {
           uOutYa += v19 * (v11 - v6);
           v7 += v6 - v11;
-          pZBuffer += 640 * (v11 - v6);
+          pZBuffer += window->GetWidth() * (v11 - v6);
           v8 = v20;
         }
         v12 = this->uClipX;
@@ -7861,7 +7807,7 @@
             }
             while ( v18 );
           }
-          pZBuffer += 640 - v8;
+          pZBuffer += window->GetWidth() - v8;
           uOutYa += v19 - v8;
           --uOutXa;
         }
@@ -7944,7 +7890,7 @@
           memset32(v8, a5, pTexturea);
           v8 = (char *)v8 + 4 * pTexturea;
         }
-        v8 = (char *)v8 + 4 * (640 - pTexturea);
+        v8 = (char *)v8 + 4 * (window->GetWidth() - pTexturea);
         --v6;
       }
       while ( v6 );