diff Indoor.cpp @ 676:ecfb1b3c9a39

BLV: when standing right on the portal (orange wall) everything looks fine
author Nomad
date Fri, 15 Mar 2013 04:13:24 +0200
parents a5750c94b022
children 35a97ce58790 08b6d89d6a10
line wrap: on
line diff
--- a/Indoor.cpp	Thu Mar 14 23:44:03 2013 +0200
+++ b/Indoor.cpp	Fri Mar 15 04:13:24 2013 +0200
@@ -272,28 +272,28 @@
   if (bD3D)
   {
     pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-    for (uint i = 0; i < pBspRenderer->uNumFaceIDs; ++i)
+    for (uint i = 0; i < pBspRenderer->num_faces; ++i)
     {
-      v2 = pBspRenderer->pFaceIDs[2 * i + 1];
-      if ( pBspRenderer->pSectors[v2].std__vector_0007A8 == -1 )
+      v2 = pBspRenderer->faces[i].uNodeID;
+      if ( pBspRenderer->nodes[v2].std__vector_0007A8 == -1 )
       {
         v6 = 0;
         v3 = 0;
       }
       else
       {
-        v3 = pBspRenderer->pSectors[v2].std__vector_0007AC;
-        v6 = pBspRenderer->pSectors[v2].pVertices;
+        v3 = pBspRenderer->nodes[v2].std__vector_0007AC;
+        v6 = pBspRenderer->nodes[v2].pVertices;
       }
-      IndoorLocation::ExecDraw_d3d(pBspRenderer->pFaceIDs[2 * i], v3, 4, v6);
+      IndoorLocation::ExecDraw_d3d(pBspRenderer->faces[i].uFaceID, v3, 4, v6);
     }
   }
   else
   {
-    for (uint j = 0; j < pBspRenderer->uNumFaceIDs; ++j )
+    for (uint j = 0; j < pBspRenderer->num_faces; ++j )
     {
-      v5 = pBspRenderer->pFaceIDs[2 * j];
-      pBLVRenderParams->field_7C = &pBspRenderer->pSectors[pBspRenderer->pFaceIDs[2 * j + 1]].field_C;
+      v5 = pBspRenderer->faces[j].uFaceID;
+      pBLVRenderParams->field_7C = &pBspRenderer->nodes[pBspRenderer->faces[j].uNodeID].field_C;
       IndoorLocation::ExecDraw_sw(v5);
     }
   }
@@ -314,6 +314,7 @@
   if (pBLVRenderParams->uPartySectorID)
     IndoorLocation::ExecDraw(pRenderer->pRenderD3D != 0);
   pRenderer->DrawBillboardList_BLV();
+
   if ( !pRenderer->pRenderD3D )
   {
     if (pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_D3D_OUTLINES)
@@ -322,17 +323,17 @@
     {
       v1 = pBLVRenderParams->pRenderTarget;
       v6 = 0;
-      if ( (signed int)pBspRenderer->pNumSectors > 0 )
+      if ( (signed int)pBspRenderer->num_nodes > 0 )
       {
         v7 = 0;
-        v2 = (char *)&pBspRenderer->pSectors[0].field_C._viewport_space_w;
+        v2 = (char *)&pBspRenderer->nodes[0].field_C._viewport_space_w;
         do
         {
           v3 = *((int *)v2 - 1);
           v4 = pRenderer->uTargetSurfacePitch * *((int *)v2 - 1);
           if ( v3 <= *(int *)v2 )
           {
-            v5 = (char *)&pBspRenderer->pSectors[0].field_C.array_3D8[v3 + v7];
+            v5 = (char *)&pBspRenderer->nodes[0].field_C.array_3D8[v3 + v7];
             do
             {
               v1[v4 + *((short *)v5 - 480)] = 255;
@@ -347,7 +348,7 @@
           v7 += 1126;
           v2 += 2252;
         }
-        while ( v6 < (signed int)pBspRenderer->pNumSectors );
+        while ( v6 < (signed int)pBspRenderer->num_nodes );
       }
     }
   }
@@ -527,7 +528,7 @@
           stru_F7B60C.face_plane.dist = pFace->pFacePlane.dist;
         }
 
-        if (stru_F8AD28.uNumLightsApplied > 0 && !(pFace->uAttributes & 0x400000))
+        if (stru_F8AD28.uNumLightsApplied > 0 && !(pFace->uAttributes & FACE_DO_NOT_LIGHT))
           pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0);
 
         if (pDecalBuilder->uNumDecals > 0)
@@ -564,7 +565,7 @@
           if (pFace->uAttributes & FACE_DO_NOT_LIGHT)
             _479A53_draw_some_blv_poly(uNumVerticesa, uFaceID);
           else
-            pRenderer->DrawIndoorPolygon(uNumVerticesa, pFace, v27, v28, 8 * uFaceID | 6, v17, 0);
+            pRenderer->DrawIndoorPolygon(uNumVerticesa, pFace, v27, v28, 8 * uFaceID | OBJECT_BModel, v17, 0);
           return;
         }
         //v17 = 0xFFFFFFFF;
@@ -1233,7 +1234,7 @@
 }
 
 //----- (004B0EA8) --------------------------------------------------------
-void BspRenderer::AddFaceToRenderList_d3d(int a2, unsigned int uFaceID)
+void BspRenderer::AddFaceToRenderList_d3d(unsigned int node_id, unsigned int uFaceID)
 {
   //unsigned int v3; // edx@1
   //stru170 *v4; // ebx@1
@@ -1242,10 +1243,10 @@
   unsigned __int16 v7; // ax@11
   Vec3_short_ *v8; // esi@15
   int v9; // edx@15
-  signed int v10; // eax@18
-  signed int v11; // edi@19
-  signed int v12; // ecx@19
-  signed int v13; // esi@19
+  //signed int v10; // eax@18
+  //signed int v11; // edi@19
+  //signed int v12; // ecx@19
+  //signed int v13; // esi@19
   signed int v14; // edx@20
   int v15; // edx@24
   //int v16; // esi@29
@@ -1263,33 +1264,41 @@
   //signed int v28; // ST28_4@47
   char v29; // al@48
   signed int v30; // eax@51
-  int v31; // eax@52
+  //int v31; // eax@52
   //unsigned int v32; // eax@55
   //__int16 v33; // cx@56
-  signed int v34; // [sp+Ch] [bp-14h]@18
+  //signed int v34; // [sp+Ch] [bp-14h]@18
   //int a0; // [sp+14h] [bp-Ch]@2
   //IndoorCameraD3D *a0a; // [sp+14h] [bp-Ch]@36
-  signed int v37; // [sp+18h] [bp-8h]@19
+  //signed int v37; // [sp+18h] [bp-8h]@19
   //stru10 *v38; // [sp+18h] [bp-8h]@36
   //BLVFace *v39; // [sp+1Ch] [bp-4h]@1
 
   //v3 = uFaceID;
   //v4 = this;
   //v5 = &pIndoor->pFaces[uFaceID];
-  pSectors[pNumSectors].std__vector_0007A8 = -1;
+  nodes[num_nodes].std__vector_0007A8 = -1;
   //v39 = &pIndoor->pFaces[uFaceID];
 
   auto pFace = &pIndoor->pFaces[uFaceID];
 
-  if (pFace->TwoSided())
+  if (!pFace->Portal())
   {
-    auto p = &pSectors[a2];
+    if (num_faces < 1000)
+    {
+      faces[num_faces].uFaceID = uFaceID;
+      faces[num_faces++].uNodeID = node_id;
+    }
+    return;
+  }
+
+    auto p = &nodes[node_id];
     //v6 = (int)((char *)this + 2252 * a2);
     //a0 = v6;
     if (p->uFaceID == uFaceID)
       return;
-    if (!a2 &&
-        pBLVRenderParams->vPartyPos.x >= pFace->pBounding.x1 - 16 &&
+    if (!node_id &&
+        pBLVRenderParams->vPartyPos.x >= pFace->pBounding.x1 - 16 &&  // we are probably standing at the portal plane
         pBLVRenderParams->vPartyPos.x <= pFace->pBounding.x2 + 16 &&
         pBLVRenderParams->vPartyPos.y >= pFace->pBounding.y1 - 16 &&
         pBLVRenderParams->vPartyPos.y <= pFace->pBounding.y2 + 16 &&
@@ -1298,59 +1307,80 @@
     {
       if ( abs(pFace->pFacePlane_old.dist + pBLVRenderParams->vPartyPos.x * pFace->pFacePlane_old.vNormal.x
                                        + pBLVRenderParams->vPartyPos.y * pFace->pFacePlane_old.vNormal.y
-                                       + pBLVRenderParams->vPartyPos.z * pFace->pFacePlane_old.vNormal.z) <= 589824 )
+                                       + pBLVRenderParams->vPartyPos.z * pFace->pFacePlane_old.vNormal.z) <= 589824 ) // we sure are standing at the portal plane
       {
         v7 = pFace->uSectorID;
-        if ( pSectors[0].uSectorID == v7 )
+        if ( nodes[0].uSectorID == v7 )  // draw back sector
           v7 = pFace->uBackSectorID;
-        pSectors[pNumSectors].uSectorID = v7;
-        pSectors[pNumSectors].uFaceID = uFaceID;
-        pSectors[pNumSectors].uViewportX = pBLVRenderParams->uViewportX;
-        pSectors[pNumSectors].uViewportZ = pBLVRenderParams->uViewportZ;
-        pSectors[pNumSectors].uViewportY = pBLVRenderParams->uViewportY;
-        pSectors[pNumSectors].uViewportW = pBLVRenderParams->uViewportW;
-        pSectors[pNumSectors++].field_C._43F9E1(
-          pBLVRenderParams->uViewportX,
-          pBLVRenderParams->uViewportY,
-          pBLVRenderParams->uViewportZ,
-          pBLVRenderParams->uViewportW);
-        sub_440639(pNumSectors - 1);
+        nodes[num_nodes].uSectorID = v7;
+        nodes[num_nodes].uFaceID = uFaceID;
+        nodes[num_nodes].uViewportX = pBLVRenderParams->uViewportX;
+        nodes[num_nodes].uViewportZ = pBLVRenderParams->uViewportZ;
+        nodes[num_nodes].uViewportY = pBLVRenderParams->uViewportY;
+        nodes[num_nodes].uViewportW = pBLVRenderParams->uViewportW;
+        nodes[num_nodes++].field_C._43F9E1(pBLVRenderParams->uViewportX,
+                                             pBLVRenderParams->uViewportY,
+                                             pBLVRenderParams->uViewportZ,
+                                             pBLVRenderParams->uViewportW);
+        AddBspNodeToRenderList(num_nodes - 1);
         return;
       }
       //v5 = v39;
       //v6 = a0;
     }
+
     v8 = &pIndoor->pVertices[pFace->pVertexIDs[0]];
     v9 = pFace->pFacePlane_old.vNormal.x * (v8->x - pBLVRenderParams->vPartyPos.x)
        + pFace->pFacePlane_old.vNormal.y * (v8->y - pBLVRenderParams->vPartyPos.y)
        + pFace->pFacePlane_old.vNormal.z * (v8->z - pBLVRenderParams->vPartyPos.z);
     if (p->uSectorID != pFace->uSectorID)
       v9 = -v9;
-    if ( v9 < 0 )
+    if (v9 >= 0)
+      return;
+
+    auto num_vertices = sub_423B5D(uFaceID);
+    if (num_vertices < 2)
+      return;
+
+    auto face_min_screenspace_x = _50BAC8_screen_space_x[0],
+         face_max_screenspace_x = _50BAC8_screen_space_x[0];
+    auto face_min_screenspace_y = _50B9D8_screen_space_y[0],
+         face_max_screenspace_y = _50B9D8_screen_space_y[0];
+    for (uint i = 1; i < num_vertices; ++i)
     {
-      v10 = sub_423B5D(uFaceID);
-      v34 = v10;
-      if ( v10 )
-      {
-        v11 = dword_50BAC8[0];
-        v12 = dword_50B9D8_ys[0];
-        a2 = dword_50BAC8[0];
+      if (face_min_screenspace_x > _50BAC8_screen_space_x[i])
+        face_min_screenspace_x = _50BAC8_screen_space_x[i];
+      if (face_max_screenspace_x < _50BAC8_screen_space_x[i])
+        face_max_screenspace_x = _50BAC8_screen_space_x[i];
+
+      if (face_min_screenspace_y > _50B9D8_screen_space_y[i])
+        face_min_screenspace_y = _50B9D8_screen_space_y[i];
+      if (face_max_screenspace_y < _50B9D8_screen_space_y[i])
+        face_max_screenspace_y = _50B9D8_screen_space_y[i];
+    }
+      //v10 = sub_423B5D(uFaceID);
+      //v34 = v10;
+      //if ( v10 )
+      //{
+       /* v11 = _50BAC8_screen_space_x[0];
+        v12 = _50B9D8_screen_space_y[0];
+        a2 = _50BAC8_screen_space_x[0];
         v13 = 1;
-        v37 = dword_50B9D8_ys[0];
+        v37 = _50B9D8_screen_space_y[0];
         if ( v10 > 1 )
         {
           do
           {
-            v14 = dword_50BAC8[v13];
+            v14 = _50BAC8_screen_space_x[v13];
             if ( v14 < a2 )
-              a2 = dword_50BAC8[v13];
+              a2 = _50BAC8_screen_space_x[v13];
             if ( v14 > v11 )
               v11 = v14;
-            v15 = dword_50B9D8_ys[v13];
+            v15 = _50B9D8_screen_space_y[v13];
             if ( v15 < v37 )
-              v37 = dword_50B9D8_ys[v13];
+              v37 = _50B9D8_screen_space_y[v13];
             if ( v15 > v12 )
-              v12 = dword_50B9D8_ys[v13];
+              v12 = _50B9D8_screen_space_y[v13];
             v10 = v34;
             ++v13;
           }
@@ -1361,24 +1391,28 @@
             a2 <= p->uViewportZ &&
             v12 >= p->uViewportY &&
             v37 <= p->uViewportW &&
-            sub_424829(v10, &pSectors[pNumSectors].field_C, &p->field_C, uFaceID))
+            sub_424829(v10, &nodes[num_nodes].field_C, &p->field_C, uFaceID))*/
+      if (face_max_screenspace_x >= p->uViewportX &&
+          face_min_screenspace_x <= p->uViewportZ &&
+          face_max_screenspace_y >= p->uViewportY &&
+          face_min_screenspace_y <= p->uViewportW &&
+          sub_424829(num_vertices, &nodes[num_nodes].field_C, &p->field_C, uFaceID))
         {
           //v17 = v39;
           v18 = pFace->uSectorID;
           if (p->uSectorID == v18 )
             v18 = pFace->uBackSectorID;
-          pSectors[pNumSectors].uSectorID = v18;
-          pSectors[pNumSectors].uFaceID = uFaceID;
-          pSectors[pNumSectors].uViewportX = pBLVRenderParams->uViewportX;
-          pSectors[pNumSectors].uViewportZ = pBLVRenderParams->uViewportZ;
-          pSectors[pNumSectors].uViewportY = pBLVRenderParams->uViewportY;
-          pSectors[pNumSectors].uViewportW = pBLVRenderParams->uViewportW;
+          nodes[num_nodes].uSectorID = v18;
+          nodes[num_nodes].uFaceID = uFaceID;
+          nodes[num_nodes].uViewportX = pBLVRenderParams->uViewportX;
+          nodes[num_nodes].uViewportZ = pBLVRenderParams->uViewportZ;
+          nodes[num_nodes].uViewportY = pBLVRenderParams->uViewportY;
+          nodes[num_nodes].uViewportW = pBLVRenderParams->uViewportW;
           //v38 = pGame->pStru10Instance;
           //a0a = pGame->pIndoorCameraD3D;
           if (p->std__vector_0007A8 == -1 )
           {
-            v29 = pGame->pStru10Instance->_49C681_DrawDebugStuff(pFace, pSectors[pNumSectors].std__vector_0007AC,
-                    pSectors[pNumSectors].pVertices);
+            v29 = pGame->pStru10Instance->_49C681_DrawDebugStuff(pFace, nodes[num_nodes].std__vector_0007AC, nodes[num_nodes].pVertices);
           }
           else
           {
@@ -1386,7 +1420,7 @@
             static RenderVertexSoft static_subAddFaceToRenderList_d3d_stru_F79E08[64];
 
             //v23 = 0;
-            a2 = pFace->uNumVertices;
+            unsigned int a2 = pFace->uNumVertices;
             for (uint k = 0; k < pFace->uNumVertices; ++k)
             {
               //v24 = (char *)&static_subAddFaceToRenderList_d3d_stru_F7AA08[0].vWorldPosition.z;
@@ -1407,46 +1441,35 @@
             }
             pGame->pIndoorCameraD3D->_437285_prolly_colide_vertices_against_frustrum(
               static_subAddFaceToRenderList_d3d_stru_F7AA08,
-              (unsigned int *)&a2,
+              &a2,
               static_subAddFaceToRenderList_d3d_stru_F79E08,
               p->std__vector_0007AC,
               4,
               0,
               0);
-            v29 = pGame->pStru10Instance->_49C5DA(pFace, static_subAddFaceToRenderList_d3d_stru_F79E08, &a2,
-                    pSectors[pNumSectors].std__vector_0007AC,
-                    pSectors[pNumSectors].pVertices);
+            v29 = pGame->pStru10Instance->_49C5DA(pFace, static_subAddFaceToRenderList_d3d_stru_F79E08, (int *)&a2,
+                    nodes[num_nodes].std__vector_0007AC,
+                    nodes[num_nodes].pVertices);
           }
           if ( v29 )
           {
-            pSectors[pNumSectors].std__vector_0007A8 = uFaceID;
-            v30 = pNumSectors;
+            nodes[num_nodes].std__vector_0007A8 = uFaceID;
+            v30 = num_nodes;
             if ( v30 < 150 )
             {
-              v31 = v30 + 1;
-              pNumSectors = v31;
-              sub_440639(v31 - 1);
+              //v31 = v30 + 1;
+              num_nodes = v30 + 1;
+              AddBspNodeToRenderList(v30);
             }
           }
           if (pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_SW_OUTLINES)
             pGame->pIndoorCameraD3D->PrepareAndDrawDebugOutline(pFace, 0x1E1EFF);
         }
-      }
-    }
-  }
-  else
-  {
-    if (uNumFaceIDs < 1000 )
-    {
-      pFaceIDs[2 * uNumFaceIDs] = uFaceID;
-      pFaceIDs[2 * uNumFaceIDs++ + 1] = a2;
-    }
-  }
 }
 
 
 //----- (004AFB86) --------------------------------------------------------
-void BspRenderer::AddFaceToRenderList_sw(int a2, unsigned int uFaceID)
+void BspRenderer::AddFaceToRenderList_sw(unsigned int node_id, unsigned int uFaceID)
 {
   BspRenderer *v3; // ebx@1
   BLVFace *v4; // eax@1
@@ -1473,13 +1496,13 @@
   v3 = this;
   v4 = &pIndoor->pFaces[uFaceID];
   v21 = v4;
-  if (v4->TwoSided())
+  if (v4->Portal())
   {
-    v5 = (char *)this + 2252 * a2;
+    v5 = (char *)this + 2252 * node_id;
     v20 = v5;
     if ( uFaceID == *((short *)v5 + 2982) )
       return;
-    if ( !a2
+    if (!node_id
       && pBLVRenderParams->vPartyPos.x >= v4->pBounding.x1 - 16
       && pBLVRenderParams->vPartyPos.x <= v4->pBounding.x2 + 16
       && pBLVRenderParams->vPartyPos.y >= v4->pBounding.y1 - 16
@@ -1492,20 +1515,20 @@
                                        + pBLVRenderParams->vPartyPos.z * v4->pFacePlane_old.vNormal.z) <= 589824 )
       {
         v6 = v21->uSectorID;
-        if ( v3->pSectors[0].uSectorID == v6 )
+        if ( v3->nodes[0].uSectorID == v6 )
           v6 = v21->uBackSectorID;
-        v3->pSectors[v3->pNumSectors].uSectorID = v6;
-        v3->pSectors[v3->pNumSectors].uFaceID = uFaceID;
-        v3->pSectors[v3->pNumSectors].uViewportX = LOWORD(pBLVRenderParams->uViewportX);
-        v3->pSectors[v3->pNumSectors].uViewportZ = LOWORD(pBLVRenderParams->uViewportZ);
-        v3->pSectors[v3->pNumSectors].uViewportY = LOWORD(pBLVRenderParams->uViewportY);
-        v3->pSectors[v3->pNumSectors].uViewportW = LOWORD(pBLVRenderParams->uViewportW);
-        v3->pSectors[v3->pNumSectors++].field_C._43F9E1(
+        v3->nodes[v3->num_nodes].uSectorID = v6;
+        v3->nodes[v3->num_nodes].uFaceID = uFaceID;
+        v3->nodes[v3->num_nodes].uViewportX = LOWORD(pBLVRenderParams->uViewportX);
+        v3->nodes[v3->num_nodes].uViewportZ = LOWORD(pBLVRenderParams->uViewportZ);
+        v3->nodes[v3->num_nodes].uViewportY = LOWORD(pBLVRenderParams->uViewportY);
+        v3->nodes[v3->num_nodes].uViewportW = LOWORD(pBLVRenderParams->uViewportW);
+        v3->nodes[v3->num_nodes++].field_C._43F9E1(
           SLOWORD(pBLVRenderParams->uViewportX),
           pBLVRenderParams->uViewportY,
           SLOWORD(pBLVRenderParams->uViewportZ),
           pBLVRenderParams->uViewportW);
-        v7 = v3->pNumSectors - 1;
+        v7 = v3->num_nodes - 1;
         goto LABEL_14;
       }
       v4 = v21;
@@ -1523,25 +1546,25 @@
       v19 = v10;
       if ( v10 )
       {
-        v11 = dword_50BAC8[0];
-        v12 = dword_50B9D8_ys[0];
-        v23 = dword_50BAC8[0];
+        v11 = _50BAC8_screen_space_x[0];
+        v12 = _50B9D8_screen_space_y[0];
+        v23 = _50BAC8_screen_space_x[0];
         v13 = 1;
-        v22 = dword_50B9D8_ys[0];
+        v22 = _50B9D8_screen_space_y[0];
         if ( v10 > 1 )
         {
           do
           {
-            v14 = dword_50BAC8[v13];
+            v14 = _50BAC8_screen_space_x[v13];
             if ( v14 < v23 )
-              v23 = dword_50BAC8[v13];
+              v23 = _50BAC8_screen_space_x[v13];
             if ( v14 > v11 )
-              v11 = dword_50BAC8[v13];
-            v15 = dword_50B9D8_ys[v13];
+              v11 = _50BAC8_screen_space_x[v13];
+            v15 = _50B9D8_screen_space_y[v13];
             if ( v15 < v22 )
-              v22 = dword_50B9D8_ys[v13];
+              v22 = _50B9D8_screen_space_y[v13];
             if ( v15 > v12 )
-              v12 = dword_50B9D8_ys[v13];
+              v12 = _50B9D8_screen_space_y[v13];
             v10 = v19;
             ++v13;
           }
@@ -1551,25 +1574,25 @@
           && v23 <= *((short *)v20 + 2007)
           && v12 >= *((short *)v20 + 2006)
           && v22 <= *((short *)v20 + 2008)
-          && sub_424829(v10, &v3->pSectors[v3->pNumSectors].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) )
+          && sub_424829(v10, &v3->nodes[v3->num_nodes].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) )
         {
           v16 = v21->uSectorID;
           if ( *((short *)v20 + 2004) == v16 )
             v16 = v21->uBackSectorID;
-          v3->pSectors[v3->pNumSectors].uSectorID = v16;
-          v3->pSectors[v3->pNumSectors].uFaceID = uFaceID;
-          v3->pSectors[v3->pNumSectors].uViewportX = LOWORD(pBLVRenderParams->uViewportX);
-          v3->pSectors[v3->pNumSectors].uViewportZ = LOWORD(pBLVRenderParams->uViewportZ);
-          v3->pSectors[v3->pNumSectors].uViewportY = LOWORD(pBLVRenderParams->uViewportY);
-          v3->pSectors[v3->pNumSectors].uViewportW = LOWORD(pBLVRenderParams->uViewportW);
-          v17 = v3->pNumSectors;
+          v3->nodes[v3->num_nodes].uSectorID = v16;
+          v3->nodes[v3->num_nodes].uFaceID = uFaceID;
+          v3->nodes[v3->num_nodes].uViewportX = LOWORD(pBLVRenderParams->uViewportX);
+          v3->nodes[v3->num_nodes].uViewportZ = LOWORD(pBLVRenderParams->uViewportZ);
+          v3->nodes[v3->num_nodes].uViewportY = LOWORD(pBLVRenderParams->uViewportY);
+          v3->nodes[v3->num_nodes].uViewportW = LOWORD(pBLVRenderParams->uViewportW);
+          v17 = v3->num_nodes;
           if ( v17 < 150 )
           {
             v18 = v17 + 1;
-            v3->pNumSectors = v18;
+            v3->num_nodes = v18;
             v7 = v18 - 1;
 LABEL_14:
-            sub_440639(v7);
+            AddBspNodeToRenderList(v7);
             return;
           }
         }
@@ -1578,10 +1601,10 @@
   }
   else
   {
-    if ( (signed int)this->uNumFaceIDs < 1000 )
+    if (num_faces < 1000)
     {
-      this->pFaceIDs[2 * this->uNumFaceIDs] = uFaceID;
-      this->pFaceIDs[2 * this->uNumFaceIDs++ + 1] = a2;
+      faces[num_faces].uFaceID = uFaceID;
+      faces[num_faces++].uNodeID = node_id;
     }
   }
 }
@@ -1598,15 +1621,15 @@
   int v6; // ecx@7
   int v7; // esi@8
 
-  for ( i = 0; i < (signed int)pBspRenderer->uNumFaceIDs; ++i )
+  for ( i = 0; i < (signed int)pBspRenderer->num_faces; ++i )
   {
-    v1 = pBspRenderer->pFaceIDs[2 * i];
+    v1 = pBspRenderer->faces[i].uFaceID;
     if ( v1 >= 0 )
     {
       if ( v1 < (signed int)pIndoor->uNumFaces )
       {
-        v2 = pBspRenderer->pFaceIDs[2 * i];
-        pBLVRenderParams->field_7C = &pBspRenderer->pSectors[pBspRenderer->pFaceIDs[2 * i + 1]].field_C;
+        v2 = pBspRenderer->faces[i].uFaceID;
+        pBLVRenderParams->field_7C = &pBspRenderer->nodes[pBspRenderer->faces[i].uNodeID].field_C;
         v3 = sub_423B5D(v2);
         if ( v3 )
         {
@@ -2479,21 +2502,6 @@
     MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:803", 0);
     return 0;
   }
-
-  assert(sizeof(Vec3_short_) == 6);
-  assert(sizeof(BLVFace) == 96);
-  assert(sizeof(BLVFaceExtra) == 36);
-  assert(sizeof(BLVSector) == 116);
-  assert(sizeof(LevelDecoration) == 32);
-  assert(sizeof(BLVLightMM7) == 16);
-  assert(sizeof(BSPNode) == 8);
-  assert(sizeof(SpawnPointMM7) == 24);
-  assert(sizeof(DDM_DLV_Header) == 40);
-  assert(sizeof(Actor) == 836);
-  assert(sizeof(SpriteObject) == 112);
-  assert(sizeof(Chest) == 5324);
-  assert(sizeof(stru123) == 0xC8);
-  assert(sizeof(BLVMapOutline) == 12);
   
   bLoaded = true;
 
@@ -2523,13 +2531,13 @@
     pFace->pVertexIDs = ptr_2AC + j;
     
     j += pFace->uNumVertices + 1;
-    pFace->pXInterceptDisplacements = ptr_2AC + j;
+    pFace->pXInterceptDisplacements = (short *)(ptr_2AC + j);
 
     j += pFace->uNumVertices + 1;
-    pFace->pYInterceptDisplacements = ptr_2AC + j;
+    pFace->pYInterceptDisplacements = (short *)(ptr_2AC + j);
 
     j += pFace->uNumVertices + 1;
-    pFace->pZInterceptDisplacements = ptr_2AC + j;
+    pFace->pZInterceptDisplacements = (short *)(ptr_2AC + j);
 
     j += pFace->uNumVertices + 1;
     pFace->pVertexUIDs = (__int16 *)(ptr_2AC + j);