diff Render.cpp @ 1:ac0fb48cd27a

Texture, hwl loading, video player
author Nomad
date Tue, 09 Oct 2012 13:09:08 +0200
parents 8b8875f5b359
children 2ca04ccb612a
line wrap: on
line diff
--- a/Render.cpp	Fri Oct 05 16:07:14 2012 +0200
+++ b/Render.cpp	Tue Oct 09 13:09:08 2012 +0200
@@ -127,8 +127,8 @@
   IDirect3DTexture2 *pTexture1; // [sp+1Ch] [bp-4h]@1
 
   v0 = false;
-  pRenderer->pRenderD3D->CreateTexture(64u, 64u, (IDirectDrawSurface **)&pSurface1, &pTexture1, 1u, 0, 32u);
-  pRenderer->pRenderD3D->CreateTexture(64u, 64u, (IDirectDrawSurface **)&pSurface2, &pTexture2, 1u, 0, 32u);
+  pRenderer->pRenderD3D->CreateTexture(64u, 64u, &pSurface1, &pTexture1, true, false, 32u);
+  pRenderer->pRenderD3D->CreateTexture(64u, 64u, &pSurface2, &pTexture2, true, false, 32u);
 
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture1));
   ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1u));
@@ -647,7 +647,7 @@
     && pParty->uCurrentHour < 0x15
     || bUnderwater )
   {
-    v2 = (stru148 *)*(short *)PaletteManager::Get_Mist_or_Red_LUT(HIWORD(array_77EC08[1999].pTexture->palette), 31, 1);
+    v2 = (stru148 *)*(short *)PaletteManager::Get_Mist_or_Red_LUT(array_77EC08[1999].pTexture->palette_id2, 31, 1);
     a1b = (unsigned int)v2;
     if ( (signed int)v9 <= 0 )
       return (signed __int16)v2;
@@ -4199,30 +4199,29 @@
 
 
 //----- (0049E5D4) --------------------------------------------------------
-bool RenderD3D::CreateTexture(unsigned int uTextureWidth, unsigned int uTextureHeight, IDirectDrawSurface **pOutSurface, IDirect3DTexture2 **pOutTexture, unsigned int bAlphaChannel, unsigned int bMipmaps, unsigned int uMinDeviceTexDim)
+bool RenderD3D::CreateTexture(unsigned int uTextureWidth, unsigned int uTextureHeight, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture, bool bAlphaChannel, bool bMipmaps, unsigned int uMinDeviceTexDim)
 {
   unsigned int v8; // edx@4
   unsigned int v9; // ebx@5
   unsigned int v10; // eax@5
   DWORD v11; // edx@5
-  int v12; // edx@7
+  //int v12; // edx@7
   DDSURFACEDESC2 ddsd2; // [sp+Ch] [bp-80h]@1
-  RenderD3D *v15; // [sp+88h] [bp-4h]@1
-
-  v15 = this;
+  //RenderD3D *v15; // [sp+88h] [bp-4h]@1
+
+  //v15 = this;
   memset(&ddsd2, 0, 0x7Cu);
   ddsd2.dwSize = 0x7Cu;
-  ddsd2.dwFlags = 0x1007u;                      // DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT
-  ddsd2.ddsCaps.dwCaps = 0x1000u;               // DDSCAPS_TEXTURE
-  ddsd2.ddsCaps.dwCaps2 = 0x10u;                // DDSCAPS2_TEXTUREMANAGE
+  ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+  ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
+  ddsd2.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
   ddsd2.dwHeight = uTextureHeight;
   ddsd2.dwWidth = uTextureWidth;
   if ( bMipmaps )
   {
     if ( (signed int)uTextureHeight <= (signed int)uTextureWidth )
     {
-      GetMaxMipLevels(uTextureHeight);          // BUG  actually v12 = GetMaxMipLevels
-      v8 = v12 - GetMaxMipLevels(uMinDeviceTexDim);
+      v8 = GetMaxMipLevels(uTextureHeight) - GetMaxMipLevels(uMinDeviceTexDim);
 LABEL_8:
       ddsd2.dwMipMapCount = v8;
       if ( !v8 )
@@ -4249,36 +4248,36 @@
     ddsd2.dwMipMapCount = 1;
   }
 LABEL_11:
-  ddsd2.dwFlags = 0x21007u;                     // DDSD_MIPMAPCOUNT
-  ddsd2.ddsCaps.dwCaps = 0x401008u;             // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
+  ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT;
+  ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
 LABEL_12:
-  ddsd2.ddpfPixelFormat.dwBBitMask = 0x1Fu;
-  ddsd2.ddpfPixelFormat.dwRGBBitCount = 0x10u;
-  ddsd2.ddpfPixelFormat.dwSize = 32;
-  if ( bAlphaChannel )
-  {
-    ddsd2.ddpfPixelFormat.dwFlags = 0x41u;      // DDPF_RGB | DDPF_ALPHAPIXELS
-    *(_QWORD *)&ddsd2.ddpfPixelFormat.dwRBitMask = 0x3E000007C00ui64;
+  ddsd2.ddpfPixelFormat.dwRGBBitCount = 16;
+  ddsd2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
+  if (bAlphaChannel)
+  {
+    ddsd2.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
+    ddsd2.ddpfPixelFormat.dwRBitMask = 0x7C00;
+    ddsd2.ddpfPixelFormat.dwGBitMask = 0x03E0;
+    ddsd2.ddpfPixelFormat.dwBBitMask = 0x001F;
     ddsd2.ddpfPixelFormat.dwRGBAlphaBitMask = 0x8000u;
   }
   else
   {
-    ddsd2.ddpfPixelFormat.dwFlags = 0x40u;      // DDPF_RGB
-    *(_QWORD *)&ddsd2.ddpfPixelFormat.dwRBitMask = 0x7E00000F800ui64;
+    ddsd2.ddpfPixelFormat.dwFlags = DDPF_RGB;
+    ddsd2.ddpfPixelFormat.dwRBitMask = 0xF800;
+    ddsd2.ddpfPixelFormat.dwGBitMask = 0x07E0;
+    ddsd2.ddpfPixelFormat.dwBBitMask = 0x001F;
     ddsd2.ddpfPixelFormat.dwRGBAlphaBitMask = 0;
   }
-  if ( v15->pHost->CreateSurface(&ddsd2, (LPDIRECTDRAWSURFACE4 *)pOutSurface, 0) )
-    return 0;
-  if ( (*pOutSurface)->QueryInterface(IID_IDirect3DTexture2, (LPVOID *)pOutTexture) )
-  {
-    if ( *pOutSurface )
-    {
-      (*pOutSurface)->Release();
-      *pOutSurface = 0;
-    }
-    return 0;
-  }
-  return 1;
+  if (FAILED(pHost->CreateSurface(&ddsd2, pOutSurface, 0)))
+    return false;
+  if (FAILED((*pOutSurface)->QueryInterface(IID_IDirect3DTexture2, (void **)pOutTexture)))
+  {
+    (*pOutSurface)->Release();
+    *pOutSurface = 0;
+    return false;
+  }
+  return true;
 }
 
 //----- (004A5190) --------------------------------------------------------
@@ -5686,19 +5685,11 @@
     }
   }
 }
-// 4E800C: using guessed type int bWinNT4_0;
 
 //----- (0049FFD7) --------------------------------------------------------
 void Render::CreateSomeTexture()
 {
-  pRenderD3D->CreateTexture(
-    64u,
-    64u,
-    (IDirectDrawSurface **)&this->pSurface,
-    &this->pTexture,
-    1u,
-    0,
-    32u);
+  pRenderD3D->CreateTexture(64, 64, &pSurface, &pTexture, true, false, 32);
 }
 
 //----- (0049FFFB) --------------------------------------------------------
@@ -8761,15 +8752,15 @@
 
 
 //----- (004A4DE1) --------------------------------------------------------
-int Render::LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface **pOutSurface, IDirect3DTexture2 **pOutTexture)
-{
-  const char *v5; // ebx@1
-  Render *v6; // edi@1
-  HWLTexture *pHWLTexture; // esi@1
-  signed int result; // eax@1
-  IDirectDrawSurface **v9; // ebx@9
+bool Render::LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture)
+{
+  //const char *v5; // ebx@1
+  //Render *v6; // edi@1
+  //HWLTexture *pHWLTexture; // esi@1
+  //signed int result; // eax@1
+  //IDirectDrawSurface **v9; // ebx@9
   IDirectDrawSurface4 *v10; // edi@11
-  int v11; // ebx@11
+  //int v11; // ebx@11
   HRESULT v12; // eax@14
   unsigned __int16 *v13; // ecx@19
   unsigned __int16 *v14; // eax@19
@@ -8780,25 +8771,21 @@
   DDSCAPS2 v19; // [sp+E8h] [bp-1Ch]@13
   int v20; // [sp+100h] [bp-4h]@12
 
-  v5 = pName;
-  v6 = this;
-  pHWLTexture = pD3DBitmaps.LoadTexture(pName, bMipMaps);
-  result = 0;
+  auto pHWLTexture = pD3DBitmaps.LoadTexture(pName, bMipMaps);
   if ( pHWLTexture )
   {
-    bMipMaps = *v5 == 72 && v5[1] == 68 && v5[2] == 87 && v5[3] == 84 && v5[4] == 82;
-    v9 = pOutSurface;
+    bMipMaps = !strncmp(pName, "HDWTR", 5);
     if ( !pRenderD3D->CreateTexture(
             pHWLTexture->uWidth,
             pHWLTexture->uHeight,
             pOutSurface,
             pOutTexture,
-            1u,
+            true,
             bMipMaps,
-            v6->uMinDeviceTextureDim) )
+            uMinDeviceTextureDim) )
       Abortf("HiScreen16::LoadTexture - D3Drend->CreateTexture() failed: %x", 0);
-    v10 = (IDirectDrawSurface4 *)*v9;
-    v11 = 0;
+    v10 = *pOutSurface;
+    //v11 = 0;
     if ( bMipMaps )
     {
       Dst._450DDE();
@@ -8806,9 +8793,9 @@
       Dst._450DF1((const char *)dword_4EFCBC, (const char *)dword_4EFCBC);
       while ( 1 )
       {
-        memset(&v19, v11, 0x10u);
+        memset(&v19, 0, 0x10u);
         v19.dwCaps = 0x401000u;                 // DDSCAPS_TEXTURE |  DDSCAPS_MIPMAP
-        memset(&desc, v11, 0x7Cu);
+        memset(&desc, 0, 0x7Cu);
         desc.dwSize = 124;
         if ( LockSurface_DDraw4(v10, &desc, 0x21u) )
         {
@@ -8829,7 +8816,7 @@
         if ( v10->GetAttachedSurface(&v19, (LPDIRECTDRAWSURFACE4 *)&pName) )
           break;
         v10 = (IDirectDrawSurface4 *)pName;
-        v11 = 0;
+        //v11 = 0;
       }
       v20 = -1;
       //nullsub_1();
@@ -8871,9 +8858,9 @@
     }
     free(pHWLTexture->pPixels);
     free(pHWLTexture);
-    result = 1;
-  }
-  return result;
+    return true;
+  }
+  return false;
 }
 
 //----- (004A5048) --------------------------------------------------------
@@ -11034,14 +11021,14 @@
 //----- (004524D8) --------------------------------------------------------
 HWLTexture *RenderHWLContainer::LoadTexture(const char *pName, int bMipMaps)
 {
-  RenderHWLContainer *v3; // esi@1
+  //RenderHWLContainer *v3; // esi@1
   unsigned int v4; // eax@1
   int v5; // ebx@2
   int v6; // edi@3
-  HWLTexture *result; // eax@8
-  HWLTexture *pTex; // edi@9
-  char *v9; // ebx@9
-  unsigned __int16 *v10; // eax@9
+  //HWLTexture *result; // eax@8
+  //HWLTexture *pTex; // edi@9
+  //char *v9; // ebx@9
+  //unsigned __int16 *v10; // eax@9
   int v11; // eax@13
   int v12; // ecx@13
   void *v13; // eax@13
@@ -11055,7 +11042,7 @@
   int v21; // ecx@16
   int v22; // eax@16
   int v23; // esi@16
-  char Str1[20]; // [sp+Ch] [bp-28h]@1
+  //char Str1[20]; // [sp+Ch] [bp-28h]@1
   unsigned int pSource; // [sp+20h] [bp-14h]@10
   unsigned __int16 *v26; // [sp+24h] [bp-10h]@13
   int v27; // [sp+28h] [bp-Ch]@14
@@ -11065,55 +11052,56 @@
   void *pDestc; // [sp+3Ch] [bp+8h]@10
   int pDestb; // [sp+3Ch] [bp+8h]@15
 
-  v3 = this;
-  sprintf(Str1, "%s", pName);
-  v4 = v3->uNumItems;
-  if ( v4 && (v5 = 0, pDesta = v3->uNumItems, (signed int)v4 > 0) )
+  //v3 = this;
+  //sprintf(Str1, "%s", pName);
+  v4 = uNumItems;
+  if ( v4 && (v5 = 0, pDesta = uNumItems, (signed int)v4 > 0) )
   {
     while ( 1 )
     {
       v6 = v5 + (pDesta - v5) / 2;
-      if ( !_strcmpi(Str1, v3->pSpriteNames[v6]) )
+      if ( !_strcmpi(pName, pSpriteNames[v6]) )
         break;
-      if ( _strcmpi(Str1, v3->pSpriteNames[v6]) <= 0 )
+      if ( _strcmpi(pName, pSpriteNames[v6]) <= 0 )
         pDesta = v5 + (pDesta - v5) / 2;
       else
         v5 = v6 + 1;
       if ( v5 >= pDesta )
-        goto LABEL_8;
+        return false;
     }
     fseek(pFile, pSpriteOffsets[v6], SEEK_SET);
-    pTex = new HWLTexture;
-    fread(&DstBuf, 4u, 1u, v3->pFile);
-    fread(&pTex->field_18, 4u, 1u, v3->pFile);
-    fread(&pTex->field_1C, 4u, 1u, v3->pFile);
-    fread(&pTex->field_20, 4u, 1u, v3->pFile);
-    fread(&pTex->field_24, 4u, 1u, v3->pFile);
-    v9 = (char *)&pTex->uWidth;
-    fread(&pTex->uWidth, 4u, 1u, v3->pFile);
-    fread(&pTex->uHeight, 4u, 1u, v3->pFile);
-    fread(&pTex->field_30, 4u, 1u, v3->pFile);
-    fread(&pTex->field_34, 4u, 1u, v3->pFile);
-    v10 = new unsigned __int16[pTex->uWidth * pTex->uHeight];
-    pTex->pPixels = v10;
+
+    auto pTex = new HWLTexture;
+    fread(&DstBuf, 4u, 1u, pFile);
+    fread(&pTex->field_18, 4u, 1u, pFile);
+    fread(&pTex->field_1C, 4u, 1u, pFile);
+    fread(&pTex->field_20, 4u, 1u, pFile);
+    fread(&pTex->field_24, 4u, 1u, pFile);
+    //v9 = (char *)&pTex->uWidth;
+    fread(&pTex->uWidth, 4u, 1u, pFile);
+    fread(&pTex->uHeight, 4u, 1u, pFile);
+    fread(&pTex->field_30, 4u, 1u, pFile);
+    fread(&pTex->field_34, 4u, 1u, pFile);
+    //v10 = new unsigned __int16[pTex->uWidth * pTex->uHeight];
+    pTex->pPixels = new unsigned __int16[pTex->uWidth * pTex->uHeight];
     if ( DstBuf )
     {
       pDestc = new char[DstBuf];
-      fread(pDestc, 1u, DstBuf, v3->pFile);
-      pSource = 2 * *(unsigned int *)v9 * pTex->uHeight;
+      fread(pDestc, 1u, DstBuf, pFile);
+      pSource = 2 * pTex->uWidth * pTex->uHeight;
       zlib::MemUnzip(pTex->pPixels, &pSource, pDestc, DstBuf);
       delete [] pDestc;
     }
     else
     {
-      fread(v10, 2u, *(unsigned int *)v9 * pTex->uHeight, v3->pFile);
-    }
-    if ( v3->field_61A94_scale_hwls_to_half )
-    {
-      v11 = (signed int)pTex->uHeight / 2;
-      v12 = *(unsigned int *)v9 / 2;
+      fread(pTex->pPixels, 2, pTex->uWidth * pTex->uHeight, pFile);
+    }
+    if ( field_61A94_scale_hwls_to_half )
+    {
+      v11 = pTex->uHeight / 2;
+      v12 = pTex->uWidth / 2;
       pTex->uHeight = v11;
-      *(unsigned int *)v9 = v12;
+      pTex->uWidth = v12;
       v13 = new unsigned __int16[v12 * v11];
       v28 = 0;
       v14 = pTex->uHeight == 0;
@@ -11121,7 +11109,7 @@
       v26 = (unsigned __int16 *)v13;
       if ( !(v15 | v14) )
       {
-        v16 = *(unsigned int *)v9;
+        v16 = pTex->uWidth;
         v27 = 1;
         do
         {
@@ -11140,26 +11128,26 @@
               LOWORD(v21) = *(unsigned short *)v21;
               v23 = pDestb++ + v18;
               v26[v23] = sub_452442(*(unsigned short *)v22, *(unsigned short *)(v22 + 2), v21, v20);
-              v16 = *(unsigned int *)v9;
+              v16 = pTex->uWidth;
             }
-            while ( pDestb < *(unsigned int *)v9 );
+            while (pDestb < pTex->uWidth);
           }
           ++v28;
           v27 += 2;
         }
         while ( v28 < (signed int)pTex->uHeight );
       }
-      free(pTex->pPixels);
+      delete [] pTex->pPixels;
       pTex->pPixels = v26;
     }
-    result = pTex;
+    return pTex;
+    //result = pTex;
   }
   else
   {
-LABEL_8:
-    result = 0;
-  }
-  return result;
+//LABEL_8:
+    return nullptr;
+  }
 }
 
 //----- (0045271F) --------------------------------------------------------