diff Engine/Graphics/Render.cpp @ 2532:9ec6b8be16fe

Mobile light
author Ritor1
date Mon, 19 Jan 2015 22:39:03 +0600
parents f6de3e15d4a5
children 1bcadc6dd203
line wrap: on
line diff
--- a/Engine/Graphics/Render.cpp	Sun Nov 23 15:30:17 2014 +0600
+++ b/Engine/Graphics/Render.cpp	Mon Jan 19 22:39:03 2015 +0600
@@ -925,9 +925,9 @@
   SpriteFrame *frame; // eax@9
   unsigned __int16 *v10; // eax@9
   int v13; // ecx@9
-  int v14; // ecx@20
-  char v15; // dl@20
-  signed int v16; // eax@20
+  char r; // ecx@20
+  char g; // dl@20
+  char b_; // eax@20
   int v17; // eax@23
   int v18; // ecx@24
   int v19; // eax@24
@@ -1041,23 +1041,25 @@
             v38 |= 0x40;
           if ( frame->uFlags & 0x20000 )
             LOBYTE(v38) = v38 | 0x80;
+
+		  //for light
           if ( frame->uGlowRadius )
           {
-            if ( pRenderD3D && bUseColoredLights )
-            {
-              v14 = /*255;//*/decor_desc->uColoredLightRed;
-              v15 = /*255;//*/decor_desc->uColoredLightGreen;
-              v16 = /*255;//*/decor_desc->uColoredLightBlue;
-            }
-            else
+            r = 255;
+            g = 255;
+            b_ = 255;
+            if ( /*pRenderD3D &&*/ bUseColoredLights )
             {
-              v16 = 255;
-              v14 = 255;
-              v15 = 255;
+              r = /*255;//*/decor_desc->uColoredLightRed;
+              g = /*255;//*/decor_desc->uColoredLightGreen;
+              b_ = /*255;//*/decor_desc->uColoredLightBlue;
             }
-            pStationaryLightsStack->AddLight(pLevelDecorations[i].vPosition.x, pLevelDecorations[i].vPosition.y, pLevelDecorations[i].vPosition.z + decor_desc->uDecorationHeight / 2,
-              frame->uGlowRadius, v14, v15, v16, _4E94D0_light_type);
-          }
+            pStationaryLightsStack->AddLight(pLevelDecorations[i].vPosition.x,
+				                             pLevelDecorations[i].vPosition.y,
+											 pLevelDecorations[i].vPosition.z + decor_desc->uDecorationHeight / 2,
+                                             frame->uGlowRadius, r, g, b_, _4E94D0_light_type);
+          }//for light
+
           v17 = (pLevelDecorations[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
           if (pGame->pIndoorCameraD3D->sRotationX)
           {
@@ -5148,30 +5150,24 @@
   pRenderer->DrawIndoorSkyPolygon(pNumVertices, &pSkyPolygon, pBitmaps_LOD->pHardwareTextures[(signed __int16)pSkyPolygon.uTileBitmapID]);
 }
 
-
 //----- (004A2FC0) --------------------------------------------------------
 void Render::DrawIndoorPolygon(unsigned int uNumVertices, BLVFace *pFace, IDirect3DTexture2 *pHwTex, Texture *pTex, int uPackedID, unsigned int uColor, int a8)
 {
   if (!uNumD3DSceneBegins || uNumVertices < 3)
     return;
 
-  //auto a3 = pFace;
-  //auto a6 = uPackedID;
-    //v59 = pGame->pLightmapBuilder;
-    //v9 = v59->std__vector_000004_size;
-
   int sCorrectedColor = uColor;
+
   if (pGame->pLightmapBuilder->std__vector_000004_size)
     sCorrectedColor = -1;
   pGame->AlterGamma_BLV(pFace, &sCorrectedColor);
 
-
   if (pFace->uAttributes & FACE_OUTLINED)
   {
-//    int color;
     if (GetTickCount() % 300 >= 150)
       uColor = sCorrectedColor = 0xFF20FF20;
-    else uColor = sCorrectedColor = 0xFF109010;
+    else 
+	  uColor = sCorrectedColor = 0xFF109010;
   }
 
   if (byte_4D864C && pGame->uFlags & GAME_FLAGS_1_01_lightmap_related)
@@ -5193,18 +5189,14 @@
 
       ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
       ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
-      ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-              D3DPT_TRIANGLEFAN,
+      ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
               D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-              d3d_vertex_buffer,
-              uNumVertices,
-              28));
+              d3d_vertex_buffer, uNumVertices, 28));
       pGame->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
   }
   else
   {
-    if (!pGame->pLightmapBuilder->std__vector_000004_size ||
-        byte_4D864C && pGame->uFlags & 2)
+    if (!pGame->pLightmapBuilder->std__vector_000004_size || byte_4D864C && pGame->uFlags & 2)
     {
       for (uint i = 0; i < uNumVertices; ++i)
       {
@@ -5222,9 +5214,7 @@
       ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
       ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                d3d_vertex_buffer,
-                uNumVertices,
-                28));
+                d3d_vertex_buffer, uNumVertices, 28));
     }
     else
     {
@@ -5239,76 +5229,31 @@
         d3d_vertex_buffer[i].texcoord.x = array_507D30[i].u / (double)pTex->uTextureWidth;
         d3d_vertex_buffer[i].texcoord.y = array_507D30[i].v / (double)pTex->uTextureHeight;
       }
-      //__debugbreak();
-        //if ( (signed int)uNumVertices > 0 )
-        //{
-          //v23 = pTex;
-          //v24 = (char *)&array_507D30[0].vWorldViewPosition;
-          //v25 = (char *)&d3d_vertex_buffer[0].pos.y;
-          //pTex = (Texture *)uNumVertices;
-          //uint v18;
-          //do
-          //{
-            //v26 = *(float *)v24 * 0.061758894;
-            //v27 = *((int *)v24 + 3);
-            //*((int *)v25 + 4) = 0;
-            //*((int *)v25 - 1) = v27;
-            //*(int *)v25 = *((int *)v24 + 4);
-            //*((int *)v25 + 3) = uColor;
-            //v25 += 32;
-            //*((float *)v25 - 7) = 1.0 - 1.0 / v26;
-            //v28 = 1.0 / *(float *)v24;
-            //v24 += 48;
-            //v18 = pTex == (Texture *)1;
-            //pTex = (Texture *)((char *)pTex - 1);
-            //*((float *)v25 - 6) = v28;
-            //a3 = (BLVFace *)v23->uTextureWidth;
-            //*((float *)v25 - 3) = *((float *)v24 - 6) / (double)(signed int)v23->uTextureWidth;
-            //a3 = (BLVFace *)v23->uTextureHeight;
-            //*((float *)v25 - 2) = *((float *)v24 - 5) / (double)(signed int)v23->uTextureHeight;
-          //}
-          //while ( !v18 );
-        //}
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
-        ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
-        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
-                D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                d3d_vertex_buffer,
-                uNumVertices,
-                28));
-
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
-        pGame->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
-
-        for (uint i = 0; i < uNumVertices; ++i)
-          d3d_vertex_buffer[i].diffuse = sCorrectedColor;
-        /*v33 = uNumVertices;
-        if ( (signed int)uNumVertices > 0 )
-        {
-          v34 = (char *)&d3d_vertex_buffer[0].diffuse;
-          do
-          {
-            *(int *)v34 = uCorrectedColor;
-            v34 += 32;
-            --v33;
-          }
-          while ( v33 );
-        }*/
-        ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
-        ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR));
-        ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
-                D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                d3d_vertex_buffer,
-                uNumVertices,
-                28));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
-        ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
+      ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
+      ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
+              D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
+              d3d_vertex_buffer, uNumVertices, 28));
+
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
+      pGame->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
+
+      for (uint i = 0; i < uNumVertices; ++i)
+        d3d_vertex_buffer[i].diffuse = sCorrectedColor;
+
+      ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex));
+      ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR));
+      ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
+              D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
+              d3d_vertex_buffer, uNumVertices, 28));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+      ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
     }
   }
 }
@@ -8971,9 +8916,7 @@
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
-
   ErrD3D(pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
-
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
 }
@@ -9016,8 +8959,7 @@
     v13[0].diffuse = sDiffuseBegin;
     v13[1].diffuse = sDiffuseEnd;
     ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr));
-    ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
-           D3DPT_LINELIST,
+    ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_LINELIST,
            452,
            v13,
            2,
@@ -9096,7 +9038,7 @@
 //----- (0049C095) --------------------------------------------------------
 void Render::DrawDecal(Decal *pDecal, float z_bias)
 {
-  signed int v21; // [sp+Ch] [bp-864h]@15
+  signed int dwFlags; // [sp+Ch] [bp-864h]@15
   RenderVertexD3D3 pVerticesD3D[64]; // [sp+20h] [bp-850h]@6
 
   if (pDecal->uNumVertices < 3)
@@ -9127,38 +9069,36 @@
          uFinalG = floorf(uTintG / 255.0 * color_mult * uDecalColorMultG + 0.0f),
          uFinalB = floorf(uTintB / 255.0 * color_mult * uDecalColorMultB + 0.0f);
 
-
     float v15;
     if (fabs(z_bias) < 1e-5)
       v15 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0);
-     else
-     {
+    else
+    {
       v15 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias;
       if (v15 < 0.000099999997)
         v15 = 0.000099999997;
-     }
-
-    pVerticesD3D[i].pos.z = v15;
+    }
 
     pVerticesD3D[i].pos.x = pDecal->pVertices[i].vWorldViewProjX;
     pVerticesD3D[i].pos.y = pDecal->pVertices[i].vWorldViewProjY;
+    pVerticesD3D[i].pos.z = v15;
+
+    pVerticesD3D[i].rhw = 1.0 / pDecal->pVertices[i].vWorldViewPosition.x;
+    pVerticesD3D[i].diffuse = (uFinalR << 16) | (uFinalG << 8) | uFinalB;
+    pVerticesD3D[i].specular = 0;
+
     pVerticesD3D[i].texcoord.x = pDecal->pVertices[i].u;
     pVerticesD3D[i].texcoord.y = pDecal->pVertices[i].v;
-    pVerticesD3D[i].diffuse = (uFinalR << 16) | (uFinalG << 8) | uFinalB;
-    pVerticesD3D[i].specular = 0;
-    pVerticesD3D[i].rhw = 1.0 / pDecal->pVertices[i].vWorldViewPosition.x;
   }
 
   if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-    v21 = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS;
+    dwFlags = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS;
   else
-    v21 = D3DDP_DONOTLIGHT;
+    dwFlags = D3DDP_DONOTLIGHT;
 
   ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
             D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-            pVerticesD3D,
-            pDecal->uNumVertices,
-            v21));
+            pVerticesD3D, pDecal->uNumVertices, dwFlags));
 }