diff Render.cpp @ 1832:f3b106aff057

Merge
author Ritor1
date Mon, 07 Oct 2013 21:57:01 +0600
parents d7791af42deb 6de366add757
children f017f8e79aa1
line wrap: on
line diff
--- a/Render.cpp	Mon Oct 07 21:56:47 2013 +0600
+++ b/Render.cpp	Mon Oct 07 21:57:01 2013 +0600
@@ -177,11 +177,13 @@
 }
 
 //----- (004A16A5) --------------------------------------------------------
-bool  AreRenderSurfacesOk()
+bool AreRenderSurfacesOk()
 {
   char v0; // zf@4
   bool result; // eax@8
 
+  if (!pRenderer)
+    return true;
   if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
     if ( !pRenderer->pBackBuffer4 )
@@ -2094,16 +2096,16 @@
   hd_water_current_frame = 0;
 }
 
-bool Render::Initialize(bool bWindowed, int windowed_width, int windowed_height, uint32_t uDefaultDevice,
-                        bool bColoredLights, uint32_t uDetailLevel, bool bTinting)
-{
-  bUserDirect3D = true;//ReadWindowsRegistryInt("Use D3D", 0);
-
+bool Render::Initialize(bool bWindowed, OSWindow *window, bool bColoredLights, uint32_t uDetailLevel, bool bTinting)
+{
+  //bUserDirect3D = true;//ReadWindowsRegistryInt("Use D3D", 0);
+
+  this->window = window;
   bStartInWindow = bWindowed;
-  windowed_mode_width = windowed_width;
-  windowed_mode_height = windowed_height;
-
-  uDesiredDirect3DDevice = uDefaultDevice;//ReadWindowsRegistryInt("D3D Device", 1);
+  //windowed_mode_width = windowed_width;
+  //windowed_mode_height = windowed_height;
+
+  uDesiredDirect3DDevice = 0;//ReadWindowsRegistryInt("D3D Device", 1);
 
   bUseColoredLights = bColoredLights;//ReadWindowsRegistryInt("Colored Lights", 0);
   uLevelOfDetail = uDetailLevel;//ReadWindowsRegistryInt("Detail Level", 1);
@@ -2186,7 +2188,7 @@
   RECT x; // [sp+68h] [bp-10h]@3
 
   memset(&v3, 0, sizeof(DDBLTFX));
-  GetWindowRect(hWnd, &x);
+  GetWindowRect(window->GetApiHandle(), &x);
   if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
       pVersion->pVersionInfo.dwMajorVersion >= 5)
   {
@@ -2909,8 +2911,8 @@
         pRenderD3D->Present(false);
       }
     }
-    else
-    {
+    else __debugbreak(); // no sr
+    /*{
       if ( v1->bWindowMode )
       {
         RestoreFrontBuffer();
@@ -2934,7 +2936,7 @@
         a4.right = 640;
         BltBackToFontFast(0, 0, &a4);
       }
-    }
+    }*/
   }
 }
 
@@ -2979,9 +2981,9 @@
 void Render::Release()
 {
   Render *v1; // esi@1
-  RenderD3D *v2; // ecx@1
-  char v3; // zf@4
-  void *v4; // ebx@6
+  //RenderD3D *v2; // ecx@1
+  //char v3; // zf@4
+  //void *v4; // ebx@6
   IDirectDraw *v5; // eax@10
   IDirectDrawSurface2 *v6; // eax@11
   IDirectDrawSurface2 *v7; // eax@13
@@ -2996,36 +2998,34 @@
   void **v16; // esi@29
 
   v1 = this;
-  v2 = this->pRenderD3D;
-  if ( v2 )
+  if (pRenderD3D)
   {
     if ( v1->field_40110 )
     {
-      pRenderD3D->ClearTarget(1u, 0, 0, 1.0);
+      pRenderD3D->ClearTarget(true, 0, false, 1.0);
       pRenderD3D->Present(0);
-      pRenderD3D->ClearTarget(1u, 0, 0, 1.0);
+      pRenderD3D->ClearTarget(true, 0, false, 1.0);
     }
     v1->pColorKeySurface4 = 0;
     v1->pBackBuffer4 = 0;
-    v3 = v1->pTargetSurface == 0;
     v1->pFrontBuffer4 = 0;
     v1->pDirectDraw4 = 0;
-    if ( !v3 )
+    if (v1->pTargetSurface)
     {
       free(v1->ptr_400E8);
       v1->pTargetSurface = 0;
       v1->ptr_400E8 = 0;
     }
-    v4 = v1->pRenderD3D;
-    if ( v4 )
+    if (pRenderD3D)
     {
       pRenderD3D->Release();
-      free(v4);
-    }
-    v1->pRenderD3D = 0;
+      delete pRenderD3D;
+    }
+    pRenderD3D = 0;
   }
   else
-  {
+    ;//__debugbreak(); // no sr
+  /*{
     if ( bWinNT4_0 == 1 )
     {
       v5 = (IDirectDraw *)v1->pDirectDraw2;
@@ -3098,7 +3098,7 @@
       *v15 = 0;
       *v16 = 0;
     }
-  }
+  }*/
 }
 
 //----- (0049FFD7) --------------------------------------------------------
@@ -3108,7 +3108,7 @@
 }
 
 //----- (0049FFFB) --------------------------------------------------------
-bool Render::InitializeFullscreen(HWND hWnd)
+bool Render::InitializeFullscreen()
 {
   //Render *v2; // esi@1
   //HWND v3; // ebx@1
@@ -3147,10 +3147,19 @@
   this->bColorKeySupported = 0;
   Release();
   //v3 = hWnd;
-  this->hWnd = hWnd;
+  this->window = window;
   CreateZBuffer();
-  if ( bUserDirect3D )
-  {
+
+  /*if (!bUserDirect3D)
+  {
+    CreateDirectDraw();
+    SetDirectDrawCooperationMode(hWnd, 1);
+    SetDirectDrawDisplayMode(640u, 480u, 16u);
+    CreateDirectDrawPrimarySurface();
+    v15 = 1;
+  }
+  else
+  {*/
     pRenderD3D = new RenderD3D;
     v28 = pRenderD3D;
     v6 = uDesiredDirect3DDevice;
@@ -3158,14 +3167,14 @@
     v7 = pRenderD3D->pAvailableDevices;
     if ( v7[v6].bIsDeviceCompatible )
     {
-      v8 = pRenderD3D->CreateDevice(v6, 0, hWnd);
+      v8 = pRenderD3D->CreateDevice(v6, 0, window->GetApiHandle());
       uAcquiredDirect3DDevice = uDesiredDirect3DDevice;
     }
     else
     {
       if ( v7[1].bIsDeviceCompatible )
       {
-        v8 = pRenderD3D->CreateDevice(1u, 0, hWnd);
+        v8 = pRenderD3D->CreateDevice(1u, 0, window->GetApiHandle());
         uAcquiredDirect3DDevice = 1;
       }
       else
@@ -3173,7 +3182,7 @@
         if ( !v7->bIsDeviceCompatible )
           Error("There aren't any D3D devices to create.");
 
-        v8 = pRenderD3D->CreateDevice(0, 0, hWnd);
+        v8 = pRenderD3D->CreateDevice(0, 0, window->GetApiHandle());
         uAcquiredDirect3DDevice = 0;
       }
     }
@@ -3261,15 +3270,7 @@
     ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
     ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0));
     ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u));
-  }
-  else
-  {
-    CreateDirectDraw();
-    SetDirectDrawCooperationMode(hWnd, 1);
-    SetDirectDrawDisplayMode(640u, 480u, 16u);
-    CreateDirectDrawPrimarySurface();
-    v15 = 1;
-  }
+  //}
   ddpfPrimareSuface.dwSize = 32;
   GetTargetPixelFormat(&ddpfPrimareSuface);
   ParseTargetPixelFormat();
@@ -3329,7 +3330,7 @@
 }
 
 //----- (004A05F3) --------------------------------------------------------
-bool Render::SwitchToWindow(HWND hWnd)
+bool Render::SwitchToWindow()
 {
   //Render *v2; // esi@1
   //void *v3; // eax@2
@@ -3371,8 +3372,19 @@
   pDirectDraw4 = 0;
   bColorKeySupported = 0;
   CreateZBuffer();
-  if ( bUserDirect3D )
-  {
+  /*if (!bUserDirect3D)
+  {
+    CreateDirectDraw();
+    SetDirectDrawCooperationMode(hWnd, 0);
+    field_4004C = 1;
+    CreateFrontBuffer();
+    CreateClipper(hWnd);
+    CreateBackBuffer();
+    field_40030 = 0;
+    field_18_locked_pitch = 0;
+  }
+  else
+  {*/
     /*v3 = malloc(0x148u);
     thisa = (RenderD3D *)v3;
     v29 = 0;
@@ -3388,7 +3400,7 @@
     if (pRenderD3D->pAvailableDevices[uDesiredDirect3DDevice].bIsDeviceCompatible &&
         uDesiredDirect3DDevice != 1 )
     {
-      v7 = pRenderD3D->CreateDevice(uDesiredDirect3DDevice, 1, hWnd);
+      v7 = pRenderD3D->CreateDevice(uDesiredDirect3DDevice, 1, window->GetApiHandle());
       uAcquiredDirect3DDevice = uDesiredDirect3DDevice;
     }
     else
@@ -3396,7 +3408,7 @@
       if ( !pRenderD3D->pAvailableDevices[0].bIsDeviceCompatible )
         Error("There aren't any D3D devices to init.");
 
-      v7 = pRenderD3D->CreateDevice(0, 1, hWnd);
+      v7 = pRenderD3D->CreateDevice(0, 1, window->GetApiHandle());
       uAcquiredDirect3DDevice = 0;
     }
     if ( !v7 )
@@ -3480,18 +3492,8 @@
     ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
     ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0));
     ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u));
-  }
-  else
-  {
-    CreateDirectDraw();
-    SetDirectDrawCooperationMode(hWnd, 0);
-    field_4004C = 1;
-    CreateFrontBuffer();
-    CreateClipper(hWnd);
-    CreateBackBuffer();
-    field_40030 = 0;
-    field_18_locked_pitch = 0;
-  }
+  //}
+
   ddpfPrimareSuface.dwSize = 32;
   GetTargetPixelFormat(&ddpfPrimareSuface);
   ParseTargetPixelFormat();
@@ -3523,7 +3525,7 @@
     field_40110 = 1;
 LABEL_47:
     bWindowMode = 1;
-    hWnd = hWnd;
+    //hWnd = hWnd;
     return 0;
   }
   pTargetSurface = 0;
@@ -3997,7 +3999,8 @@
   pDirectDraw2 = nullptr;
   pDirectDraw4 = nullptr;
 
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
     ErrD3D(lpDD->QueryInterface(IID_IDirectDraw4, (void **)&pDirectDraw4));
   else
     ErrD3D(lpDD->QueryInterface(IID_IDirectDraw2, (void **)&pDirectDraw2));
@@ -4018,7 +4021,8 @@
   flags = bFullscreen ? DDSCL_NORMAL | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN :
                         DDSCL_NORMAL;
 
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
     ErrD3D(pDirectDraw4->SetCooperativeLevel(hWnd, flags | DDSCL_MULTITHREADED));
   else
     ErrD3D(pDirectDraw2->SetCooperativeLevel(hWnd, flags));
@@ -4027,7 +4031,8 @@
 //----- (004A11C6) --------------------------------------------------------
 void Render::SetDirectDrawDisplayMode(unsigned int uWidth, unsigned int uHeight, unsigned int uBPP)
 {
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
     ErrD3D(pDirectDraw4->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0));
   else
     ErrD3D(pDirectDraw2->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0));
@@ -4046,7 +4051,8 @@
   DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3
 
   v1 = this;
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
     memset(&a2, 0, 0x7Cu);
     pDD = (IDirectDraw *)v1->pDirectDraw4;
@@ -4086,7 +4092,8 @@
   DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3
 
   v1 = this;
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
     memset(&a2, 0, 0x7Cu);
     v2 = (IDirectDraw *)v1->pDirectDraw4;
@@ -4140,7 +4147,8 @@
   int a4; // [sp+98h] [bp-8h]@3
 
   v1 = this;
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
     v2 = 0;
     this->field_4004C = 1;
@@ -4191,7 +4199,8 @@
 //----- (004A14F4) --------------------------------------------------------
 void Render::CreateClipper(HWND a2)
 {
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
     ErrD3D(pDirectDraw4->CreateClipper(0, &pDDrawClipper, 0));
     ErrD3D(pDDrawClipper->SetHWnd(0, a2));
@@ -4209,7 +4218,8 @@
 {
   IDirectDrawSurface *v2; // eax@3
 
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
     v2 = (IDirectDrawSurface *)this->pFrontBuffer4;
   else
     v2 = (IDirectDrawSurface *)this->pFrontBuffer2;
@@ -4223,7 +4233,8 @@
   signed int v4; // eax@3
 
   v3 = this;
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
   {
   DDSURFACEDESC2 pDesc; // [sp+4h] [bp-7Ch]@3
     memset(&pDesc, 0, 0x7Cu);
@@ -4244,16 +4255,11 @@
   *pOutPixelsPerRow = v4 >> 1;
 }
 
-//----- (004A169E) --------------------------------------------------------
-bool Render::UsingDirect3D()
-{
-  return bUserDirect3D == 0;
-}
-
 //----- (004A16E1) --------------------------------------------------------
 void Render::UnlockBackBuffer()
 {
-  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
+  if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
+      pVersion->pVersionInfo.dwMajorVersion != 4 )
     ErrD3D(pBackBuffer4->Unlock(0));
   else
     ErrD3D(pBackBuffer2->Unlock(0));
@@ -5155,11 +5161,11 @@
   {
     v15 = (void *)(v72 * (v70 - (int)array_507D30[_507D30_idx].vWorldViewProjY));
     v77 = (unsigned __int64)(v62.ptr_38->field_14 * (signed __int64)(signed int)v15) >> 16;
-    v74 = v77 + v62.ptr_38->field_C;
+    v74 = v77 + v62.ptr_38->angle_from_north;
     v77 = (int)v15;
     v77 = (unsigned __int64)(v62.ptr_38->field_20 * (signed __int64)(signed int)v15) >> 16;
     v79 = v15;
-    v75 = (RenderVertexSoft *)(v77 + v62.ptr_38->field_18);
+    v75 = (RenderVertexSoft *)(v77 + v62.ptr_38->angle_from_east);
     v79 = (void *)((unsigned __int64)(v62.v_18.z * (signed __int64)(signed int)v15) >> 16);
     v17 = v72 * (pBLVRenderParams->uViewportCenterX - (int)array_507D30[_507D30_idx].vWorldViewProjX);
     v18 = array_507D30[_507D30_idx].vWorldViewProjY - 1.0;
@@ -5195,8 +5201,8 @@
       v79 = (void *)(v23 / X);
       v77 = v17;
       v77 = v17;
-      LODWORD(v76) = v74 + ((unsigned __int64)(v62.ptr_38->field_10 * (signed __int64)v17) >> 16);
-      v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(v62.ptr_38->field_1C * (signed __int64)v17) >> 16));
+      LODWORD(v76) = v74 + ((unsigned __int64)(v62.ptr_38->angle_from_west * (signed __int64)v17) >> 16);
+      v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(v62.ptr_38->angle_from_south * (signed __int64)v17) >> 16));
       v77 = (unsigned __int64)(SLODWORD(v76) * v23 / X) >> 16;
       LODWORD(v73) = (unsigned __int64)((signed int)v75 * v23 / X) >> 16;
       //v14 += 48;
@@ -5271,13 +5277,13 @@
     v35 = (const void *)(v72 * (v70 - (unsigned __int64)(signed __int64)*(float *)v34));
     v78 = v62.ptr_38->field_14;
     v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v35) >> 16);
-    v36 = (int)((char *)v81 + v62.ptr_38->field_C);
+    v36 = (int)((char *)v81 + v62.ptr_38->angle_from_north);
     v81 = v35;
     v74 = v36;
     v78 = v62.ptr_38->field_20;
     v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v35) >> 16);
     v78 = (int)v35;
-    v75 = (RenderVertexSoft *)((char *)v81 + v62.ptr_38->field_18);
+    v75 = (RenderVertexSoft *)((char *)v81 + v62.ptr_38->angle_from_east);
     v81 = (const void *)v62.v_18.z;
     v78 = (unsigned __int64)(v62.v_18.z * (signed __int64)(signed int)v35) >> 16;
     v37 = (const void *)(v72
@@ -5320,12 +5326,12 @@
     HIDWORD(v42) = v77 >> 16;
     v79 = (void *)(v42 / X);
     v81 = v37;
-    v78 = v62.ptr_38->field_10;
+    v78 = v62.ptr_38->angle_from_west;
     v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16);
     v43 = v74 + ((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16);
     v74 = (unsigned int)v37;
     LODWORD(v76) = v43;
-    v78 = v62.ptr_38->field_1C;
+    v78 = v62.ptr_38->angle_from_south;
     v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16));
     v74 = (unsigned __int64)(v43 * v42 / X) >> 16;
     v81 = (const void *)((unsigned __int64)((signed int)v75 * v42 / X) >> 16);
@@ -8316,17 +8322,19 @@
     }
     if ( pRenderer->bWindowMode )
     {
-      SetMenu(hWnd, 0);
-      SetWindowLongA(hWnd, -20, 0);
-      SetWindowLongA(hWnd, -16, 0x10000000u);
-      pRenderer->InitializeFullscreen(hWnd);
+      //SetMenu(hWnd, 0);
+      //SetWindowLongA(hWnd, -20, 0);
+      //SetWindowLongA(hWnd, -16, 0x10000000u);
+      window->SetFullscreenMode();
+      pRenderer->InitializeFullscreen();
       v0 = (double)(signed int)uGammaPos * 0.1 + 0.6;
       pGame->pGammaController->Initialize(v0);
     }
     else
     {
-      ClipCursor(0);
-      pRenderer->SwitchToWindow(hWnd);
+      //ClipCursor(0);
+      window->SetWindowedMode(window->GetWidth(), window->GetHeight());
+      pRenderer->SwitchToWindow();
     }
     if ( pRenderer->pRenderD3D )
     {
@@ -8379,13 +8387,13 @@
     viewparams->bRedrawGameUI = 1;
     viewparams->InitGrayPalette();
     pMouse->SetCurrentCursorBitmap();
-    if ( pRenderer->bWindowMode )
+    /*if ( pRenderer->bWindowMode )
     {
       //MoveWindow(hWnd, uWindowX, uWindowY, uWindowWidth, uWindowHeight, 0);
       CenterWindowAndAdjustSize(hWnd, windowed_mode_width, windowed_mode_height);
       ShowWindow(hWnd, SW_SHOWNORMAL);
-    }
-    pMouse->bActive = 1;
+    }*/
+    pMouse->bActive = true;
     if ( pVideoPlayer->AnyMovieLoaded() )
       pVideoPlayer->SelectMovieType();
     if (dword_6BE364_game_settings_1 & 0x0800 )