diff Indoor.cpp @ 59:5159d2e6f559

BLV render
author Nomad
date Fri, 26 Oct 2012 02:38:26 +0200
parents 41cbaabde2cb
children fdacbc653945
line wrap: on
line diff
--- a/Indoor.cpp	Thu Oct 25 02:05:16 2012 +0200
+++ b/Indoor.cpp	Fri Oct 26 02:38:26 2012 +0200
@@ -69,7 +69,7 @@
 //----- (0043F39E) --------------------------------------------------------
 void __fastcall sub_43F39E(IndoorLocation_drawstru *_this)
 {
-  int *v1; // ecx@1
+  //int *v1; // ecx@1
   //double v2; // ST30_8@3
   //double v3; // ST30_8@6
   //double v4; // ST28_8@6
@@ -82,13 +82,14 @@
   //unsigned __int8 v11; // [sp+1Ch] [bp-4h]@3
   signed int v12; // [sp+1Ch] [bp-4h]@8
 
-  pBLVRenderParams->Set(_this);
-  uNumMobileLightsApplied = 0;
+  pBLVRenderParams->Reset(_this);
+  pMobileLightsStack->uNumLightsActive = 0;
+  //uNumMobileLightsApplied = 0;
   uNumDecorationsDrawnThisFrame = 0;
   _unused000 = 0;
   uNumSpritesDrawnThisFrame = 0;
   uNumBillboardsToDraw = 0;
-  if ( !byte_4D864C || !(BYTE1(pGame->uFlags) & 0x10) )
+  if ( !byte_4D864C || !(pGame->uFlags & 0x1000) )
   {
     //v2 = pParty->flt_TorchlightColorB + 6.7553994e15;
     //v11 = LOBYTE(v2);
@@ -96,7 +97,7 @@
       v5 = 800;
     else
       v5 = 800 * pParty->pPartyBuffs[16].uPower;
-    LOBYTE(v1) = byte_4E94D0;
+    //LOBYTE(v1) = byte_4E94D0;
     //v4 = pParty->flt_TorchlightColorR + 6.7553994e15;
     //v3 = pParty->flt_TorchlightColorG + 6.7553994e15;
     pMobileLightsStack->AddLight(
@@ -108,7 +109,7 @@
       floorf(pParty->flt_TorchlightColorR + 0.5f),
       floorf(pParty->flt_TorchlightColorG + 0.5f),
       floorf(pParty->flt_TorchlightColorB + 0.5f),
-      v1);
+      byte_4E94D0);
   }
   PrepareWallsRenderList_BLV();
   PrepareItemsRenderList_BLV();
@@ -135,7 +136,7 @@
 
 
 //----- (004407D9) --------------------------------------------------------
-int BLVRenderParams::Set(IndoorLocation_drawstru *a2)
+int BLVRenderParams::Reset(IndoorLocation_drawstru *a2)
 {
   IndoorLocation_drawstru *v2; // ebx@1
   BLVRenderParams *v3; // esi@1
@@ -253,7 +254,7 @@
   result = 0;
   v3->field_8C = 0;
   v3->field_84 = 0;
-  v3->field_80 = 0;
+  v3->uNumFacesRenderedThisFrame = 0;
   v3->field_88 = 0;
   pBLVRenderParams->field_90 = 64;
   pBLVRenderParams->field_94 = 6;
@@ -284,7 +285,7 @@
         v3 = pStru170->field_FA8[v2].std__vector_0007AC;
         v6 = pStru170->field_FA8[v2].pVertices;
       }
-      IndoorLocation::ExecDraw_d3d(pStru170->pFaceIDs[2 * i], v3, 4u, v6);
+      IndoorLocation::ExecDraw_d3d(pStru170->pFaceIDs[2 * i], v3, 4, v6);
     }
   }
   else
@@ -410,7 +411,7 @@
   this->pFacePlane.vNormal.z = (double)(a2->pFacePlane.vNormal.z & 0xFFFF) * 0.000015259022
                              + (double)(a2->pFacePlane.vNormal.z >> 16);
   this->pFacePlane.dist = (double)(a2->pFacePlane.dist & 0xFFFF) * 0.000015259022 + (double)(a2->pFacePlane.dist >> 16);
-  this->uAttributes = a2->uFaceAttributes;
+  this->uAttributes = a2->uAttributes;
   this->pBounding.x1 = a2->pBoundingBox.x1;
   this->pBounding.y1 = a2->pBoundingBox.y1;
   this->pBounding.z1 = a2->pBoundingBox.z1;
@@ -446,10 +447,10 @@
   //unsigned __int8 v15; // sf@19
   //unsigned __int8 v16; // of@19
   int v17; // ebx@25
-  double v18; // st7@27
-  double v19; // st6@27
-  double v20; // st5@27
-  char v21; // dl@27
+  //double v18; // st7@27
+  //double v19; // st6@27
+  //double v20; // st5@27
+  //char v21; // dl@27
   unsigned int v22; // eax@44
   unsigned int v23; // eax@35
   DWORD v24; // eax@37
@@ -482,41 +483,28 @@
     return;
 
 
-      if ( !(pFace->uAttributes & 0x2000) )
-      {
-        ++pBLVRenderParams->field_80;
-        LOBYTE(pFace->uAttributes) |= 0x80u;
-        v28 = pFace->GetTexture();
-        if ( v28 )
-        {
-          //v10 = pGame->pIndoorCameraD3D;
-          //v31 = pGame->pIndoorCameraD3D;
-          //pStru4 = pGame->pLightmapBuilder;
-          if ( !pGame->pIndoorCameraD3D->IsFaceFacedTowardsCamera(pFace) )
-          {
-            //v11 = 0;
-            //uNumVerticesa = pFace->uNumVertices;
-              //v12 = pIndoor->pVertices;
-              //v13 = (char *)&static_vertices_F7C228[0].vWorldPosition.z;
-            for (uint i = 0; i < pFace->uNumVertices; ++i)
-            {
-              static_vertices_F7C228[i].vWorldPosition.x = pIndoor->pVertices[pFace->pVertexIDs[i]].x;
-              static_vertices_F7C228[i].vWorldPosition.y = pIndoor->pVertices[pFace->pVertexIDs[i]].y;
-              static_vertices_F7C228[i].vWorldPosition.z = pIndoor->pVertices[pFace->pVertexIDs[i]].z;
-              static_vertices_F7C228[i].u = pFace->pVertexUIDs[i];
-              static_vertices_F7C228[i].v = pFace->pVertexUIDs[i];
-                //v14 = v11++;
-                //*((float *)v13 - 2) = (double)v12[v9->pVertexIDs[v14]].x;
-                //*((float *)v13 - 1) = (double)v12[v9->pVertexIDs[v14]].y;
-                //*(float *)v13 = (double)v12[v9->pVertexIDs[v14]].z;
-                //v13 += 48;
-                //v16 = __OFSUB__(v11, uNumVerticesa);
-                //v15 = ((v11 - uNumVerticesa) & 0x80000000u) != 0;
-                //*((float *)v13 - 5) = (double)v9->pVertexUIDs[v14];
-                //*((float *)v13 - 4) = (double)v9->pVertexVIDs[v14];
-              //while ( v15 ^ v16 );
-              //v10 = v31;
-            }
+  if (pFace->Invisible())
+    return;
+  
+  ++pBLVRenderParams->uNumFacesRenderedThisFrame;
+  pFace->uAttributes |= 0x80u;
+
+  if (!pFace->GetTexture())
+    return;
+
+  v28 = pFace->GetTexture();
+
+  if (!pGame->pIndoorCameraD3D->IsCulled(pFace))
+  {
+    uNumVerticesa = pFace->uNumVertices;
+    for (uint i = 0; i < pFace->uNumVertices; ++i)
+    {
+      static_vertices_F7C228[i].vWorldPosition.x = pIndoor->pVertices[pFace->pVertexIDs[i]].x;
+      static_vertices_F7C228[i].vWorldPosition.y = pIndoor->pVertices[pFace->pVertexIDs[i]].y;
+      static_vertices_F7C228[i].vWorldPosition.z = pIndoor->pVertices[pFace->pVertexIDs[i]].z;
+      static_vertices_F7C228[i].u = (signed)pFace->pVertexUIDs[i];
+      static_vertices_F7C228[i].v = (signed)pFace->pVertexUIDs[i];
+    }
             if ( !pVertices
               || (pGame->pStru9Instance->_498377(a4, 4u, pVertices, static_vertices_F7C228, &uNumVerticesa), uNumVerticesa) )
             {
@@ -526,31 +514,29 @@
                      static_vertices_F7B628,
                      pGame->pIndoorCameraD3D->std__vector_000034_prolly_frustrum,
                      4,
-                     0,
+                     false,
                      0) != 1
                 || uNumVerticesa )
               {
-                a4a = SHIWORD(stru_F8AD28.field_2C);
-                v17 = (248 - 8 * SHIWORD(stru_F8AD28.field_2C)) | (((248 - 8 * SHIWORD(stru_F8AD28.field_2C)) | ((248 - 8 * SHIWORD(stru_F8AD28.field_2C)) << 8)) << 8);
+                a4a = SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel);
+                v17 = (248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) | (((248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) | ((248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) << 8)) << 8);
                 sub_4B0E07(uFaceID);
                 pGame->pLightmapBuilder->ApplyLights_IndoorFace(uFaceID);
                 pDecalBuilder->ApplyBloodsplatDecals_IndoorFace(uFaceID);
-                pGame->pIndoorCameraD3D->_4364C5(static_vertices_F7B628, uNumVerticesa, array_507D30, &stru_F8AD28);
-                pGame->pIndoorCameraD3D->_436BB7_project_and_stuff(array_507D30, uNumVerticesa, 0);
+                pGame->pIndoorCameraD3D->ViewTransfrom_OffsetUV(static_vertices_F7B628, uNumVerticesa, array_507D30, &stru_F8AD28);
+                pGame->pIndoorCameraD3D->Project(array_507D30, uNumVerticesa, 0);
                 pGame->pLightmapBuilder->std__vector_000004_size = 0;
-                if ( stru_F8AD28.field_AC > 0 || pDecalBuilder->uNumDecals > 0 )
+                if (stru_F8AD28.uNumLightsApplied > 0 ||
+                    pDecalBuilder->uNumDecals > 0)
                 {
-                  v18 = pFace->pFacePlane.dist;
-                  v19 = pFace->pFacePlane.vNormal.z;
-                  v20 = pFace->pFacePlane.vNormal.y;
-                  v21 = pFace->uPolygonType;
-                  stru_F7B60C.vNormal.x = pFace->pFacePlane.vNormal.x;
-                  stru_F7B60C.field_14 = v21;
-                  stru_F7B60C.vNormal.y = v20;
-                  stru_F7B60C.vNormal.z = v19;
-                  stru_F7B60C.field_10 = v18;
+                  stru_F7B60C.face_plane.vNormal.x = pFace->pFacePlane.vNormal.x;
+                  stru_F7B60C.polygonType = pFace->uPolygonType;
+                  stru_F7B60C.face_plane.vNormal.y = pFace->pFacePlane.vNormal.y;
+                  stru_F7B60C.face_plane.vNormal.z = pFace->pFacePlane.vNormal.z;
+                  stru_F7B60C.face_plane.dist = pFace->pFacePlane.dist;
                 }
-                if ( stru_F8AD28.field_AC > 0 && !(BYTE2(pFace->uAttributes) & 0x40) )
+                if (stru_F8AD28.uNumLightsApplied > 0 &&
+                    !(pFace->uAttributes & 0x400000))
                   pGame->pLightmapBuilder->ApplyLights(
                     &stru_F8AD28,
                     &stru_F7B60C,
@@ -558,7 +544,8 @@
                     array_507D30,
                     pVertices,
                     0);
-                if ( pDecalBuilder->uNumDecals > 0 )
+
+                if (pDecalBuilder->uNumDecals > 0)
                   pDecalBuilder->ApplyDecals(
                     a4a,
                     1,
@@ -614,9 +601,7 @@
                 goto LABEL_42;
               }
             }
-          }
-        }
-      }
+  }
 }
 
 //----- (004AFF79) --------------------------------------------------------
@@ -777,7 +762,7 @@
         if ( !(v3 & 0x10) || (sub_4AD504(uFaceID), pRenderer->pRenderD3D) )
         {
           v4 = v2->GetTexture();
-          ++pBLVRenderParams->field_80;
+          ++pBLVRenderParams->uNumFacesRenderedThisFrame;
           v5 = v4;
           v108 = v4;
           if ( v4 )
@@ -796,7 +781,7 @@
               {
                 if ( v2->uPolygonType == 1 )
                 {
-                  for ( i = 0; i < stru_F8AD28.field_AC; stru_F8AD28._blv_lights_ys[v18] = v20 )
+                  for ( i = 0; i < stru_F8AD28.uNumLightsApplied; stru_F8AD28._blv_lights_ys[v18] = v20 )
                   {
                     v18 = i;
                     v120 = stru_F8AD28._blv_lights_xs[i];
@@ -820,7 +805,7 @@
                     {
 LABEL_16:
                       a2 = 0;
-                      if ( stru_F8AD28.field_AC > 0 )
+                      if ( stru_F8AD28.uNumLightsApplied > 0 )
                       {
                         do
                         {
@@ -857,7 +842,7 @@
                           stru_F8AD28._blv_lights_ys[v8] += v128;
                           ++a2;
                         }
-                        while ( a2 < stru_F8AD28.field_AC );
+                        while ( a2 < stru_F8AD28.uNumLightsApplied );
                         v2 = v103;
                       }
                       goto LABEL_24;
@@ -869,7 +854,7 @@
                       goto LABEL_16;
                     }
                   }
-                  for ( j = 0; j < stru_F8AD28.field_AC; *(int *)v15 = v16 )
+                  for ( j = 0; j < stru_F8AD28.uNumLightsApplied; *(int *)v15 = v16 )
                   {
                     v14 = v128;
                     stru_F8AD28._blv_lights_xs[j] += v126;
@@ -2788,7 +2773,7 @@
 
   for (uint i = 0, j = 0; i < uNumSectors; ++i)
   {
-    pSectors->pLights = (BLVLightMM7 *)(ptr_0002B8_sector_lrdata + j);
+    pSectors->pLights = (unsigned __int16 *)(ptr_0002B8_sector_lrdata + j);
     j += pSectors->uNumLights;
   }
 
@@ -4489,7 +4474,7 @@
   ptr_6A0D08 = 0;
   _6A0D0C_txt_lod_loading = 0;
   TryLoadLevelFromLOD();
-  uNumStationaryLightsApplied = 0;
+  pStationaryLightsStack->uNumLightsActive = 0;
   v4 = pIndoor->Load(
          pCurrentMapName,
          (unsigned int)(signed __int64)((double)pParty->uTimePlayed * 0.234375) / 60 / 60 / 24 + 1,