changeset 120:7b4725cdb74e

Слияние
author Ritor1
date Thu, 08 Nov 2012 09:27:41 +0600
parents 6e0346bc7014 (current diff) 918dca162239 (diff)
children 6c67511e2f71
files LOD.cpp
diffstat 12 files changed, 216 insertions(+), 381 deletions(-) [+]
line wrap: on
line diff
--- a/Indoor.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/Indoor.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -47,8 +47,8 @@
 stru320 stru_F8AD28; // idb
 stru337 stru_F81018;
 stru167_wrap array_5118E8;
-stru170_stru2 stru_F8A590;
-stru170 *pStru170 = new stru170; // idb
+BspRenderer_stru2 stru_F8A590;
+BspRenderer *pBspRenderer = new BspRenderer; // idb
 stru141 stru_721530;
 stru352 stru_F83B80[480];
 
@@ -110,15 +110,15 @@
       floorf(pParty->flt_TorchlightColorB + 0.5f),
       byte_4E94D0);
   }
-  PrepareWallsRenderList_BLV();
+  PrepareBspRenderList_BLV();
   PrepareItemsRenderList_BLV();
   PrepareActorRenderList_BLV();
   v6 = 0;
-  for ( i = 0; i < pStru170->uNumVisibleNotEmptySectors; ++i )
+  for ( i = 0; i < pBspRenderer->uNumVisibleNotEmptySectors; ++i )
   {
-    v7 = pStru170->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6];
+    v7 = pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6];
     v12 = 0;
-    v8 = &pIndoor->pSectors[pStru170->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6]];
+    v8 = &pIndoor->pSectors[pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6]];
     v9 = v8->pDecorationIDs;
     if ( v8->uNumDecorations > 0 )
     {
@@ -271,28 +271,28 @@
   if (bD3D)
   {
     pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-    for (uint i = 0; i < pStru170->uNumFaceIDs; ++i)
+    for (uint i = 0; i < pBspRenderer->uNumFaceIDs; ++i)
     {
-      v2 = pStru170->pFaceIDs[2 * i + 1];
-      if ( pStru170->field_FA8[v2].std__vector_0007A8 == -1 )
+      v2 = pBspRenderer->pFaceIDs[2 * i + 1];
+      if ( pBspRenderer->field_FA8[v2].std__vector_0007A8 == -1 )
       {
         v6 = 0;
         v3 = 0;
       }
       else
       {
-        v3 = pStru170->field_FA8[v2].std__vector_0007AC;
-        v6 = pStru170->field_FA8[v2].pVertices;
+        v3 = pBspRenderer->field_FA8[v2].std__vector_0007AC;
+        v6 = pBspRenderer->field_FA8[v2].pVertices;
       }
-      IndoorLocation::ExecDraw_d3d(pStru170->pFaceIDs[2 * i], v3, 4, v6);
+      IndoorLocation::ExecDraw_d3d(pBspRenderer->pFaceIDs[2 * i], v3, 4, v6);
     }
   }
   else
   {
-    for (uint j = 0; j < pStru170->uNumFaceIDs; ++j )
+    for (uint j = 0; j < pBspRenderer->uNumFaceIDs; ++j )
     {
-      v5 = pStru170->pFaceIDs[2 * j];
-      pBLVRenderParams->field_7C = &pStru170->field_FA8[pStru170->pFaceIDs[2 * j + 1]].field_C;
+      v5 = pBspRenderer->pFaceIDs[2 * j];
+      pBLVRenderParams->field_7C = &pBspRenderer->field_FA8[pBspRenderer->pFaceIDs[2 * j + 1]].field_C;
       IndoorLocation::ExecDraw_sw(v5);
     }
   }
@@ -321,17 +321,17 @@
     {
       v1 = pBLVRenderParams->pRenderTarget;
       v6 = 0;
-      if ( (signed int)pStru170->std__vector_000FA8 > 0 )
+      if ( (signed int)pBspRenderer->std__vector_000FA8 > 0 )
       {
         v7 = 0;
-        v2 = (char *)&pStru170->field_FA8[0].field_C._viewport_space_w;
+        v2 = (char *)&pBspRenderer->field_FA8[0].field_C._viewport_space_w;
         do
         {
           v3 = *((int *)v2 - 1);
           v4 = pRenderer->uTargetSurfacePitch * *((int *)v2 - 1);
           if ( v3 <= *(int *)v2 )
           {
-            v5 = (char *)&pStru170->field_FA8[0].field_C.array_3D8[v3 + v7];
+            v5 = (char *)&pBspRenderer->field_FA8[0].field_C.array_3D8[v3 + v7];
             do
             {
               v1[v4 + *((short *)v5 - 480)] = 255;
@@ -346,7 +346,7 @@
           v7 += 1126;
           v2 += 2252;
         }
-        while ( v6 < (signed int)pStru170->std__vector_000FA8 );
+        while ( v6 < (signed int)pBspRenderer->std__vector_000FA8 );
       }
     }
   }
@@ -1259,7 +1259,7 @@
 
 
 //----- (004B0EA8) --------------------------------------------------------
-void stru170::PrepareFaceRenderList_d3d(int a2, unsigned int uFaceID)
+void BspRenderer::PrepareFaceRenderList_d3d(int a2, unsigned int uFaceID)
 {
   //unsigned int v3; // edx@1
   //stru170 *v4; // ebx@1
@@ -1477,9 +1477,9 @@
 
 
 //----- (004AFB86) --------------------------------------------------------
-void stru170::PrepareFaceRenderList_sw(int a2, unsigned int uFaceID)
+void BspRenderer::PrepareFaceRenderList_sw(int a2, unsigned int uFaceID)
 {
-  stru170 *v3; // ebx@1
+  BspRenderer *v3; // ebx@1
   BLVFace *v4; // eax@1
   char *v5; // ecx@2
   unsigned __int16 v6; // ax@11
@@ -1582,7 +1582,7 @@
           && v23 <= *((short *)v20 + 2007)
           && v12 >= *((short *)v20 + 2006)
           && v22 <= *((short *)v20 + 2008)
-          && sub_424829(v10, &v3->field_FA8[v3->std__vector_000FA8].field_C, (stru170_stru2 *)(v20 + 4020), uFaceID) )
+          && sub_424829(v10, &v3->field_FA8[v3->std__vector_000FA8].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) )
         {
           v16 = v21->uSectorID;
           if ( *((short *)v20 + 2004) == v16 )
@@ -1629,15 +1629,15 @@
   int v6; // ecx@7
   int v7; // esi@8
 
-  for ( i = 0; i < (signed int)pStru170->uNumFaceIDs; ++i )
+  for ( i = 0; i < (signed int)pBspRenderer->uNumFaceIDs; ++i )
   {
-    v1 = pStru170->pFaceIDs[2 * i];
+    v1 = pBspRenderer->pFaceIDs[2 * i];
     if ( v1 >= 0 )
     {
       if ( v1 < (signed int)pIndoor->uNumFaces )
       {
-        v2 = pStru170->pFaceIDs[2 * i];
-        pBLVRenderParams->field_7C = &pStru170->field_FA8[pStru170->pFaceIDs[2 * i + 1]].field_C;
+        v2 = pBspRenderer->pFaceIDs[2 * i];
+        pBLVRenderParams->field_7C = &pBspRenderer->field_FA8[pBspRenderer->pFaceIDs[2 * i + 1]].field_C;
         v3 = sub_423B5D(v2);
         if ( v3 )
         {
--- a/Indoor.h	Thu Nov 08 09:27:19 2012 +0600
+++ b/Indoor.h	Thu Nov 08 09:27:41 2012 +0600
@@ -556,7 +556,7 @@
   int field_70;
   int uViewportCenterX;
   int uViewportCenterY;
-  struct stru170_stru2 *field_7C;
+  struct BspRenderer_stru2 *field_7C;
   unsigned int uNumFacesRenderedThisFrame;
   int field_84;
   int field_88;
--- a/Indoor_stuff.h	Thu Nov 08 09:27:19 2012 +0600
+++ b/Indoor_stuff.h	Thu Nov 08 09:27:41 2012 +0600
@@ -6,7 +6,7 @@
 
 /*  165 */
 #pragma pack(push, 1)
-struct stru170_stru2
+struct BspRenderer_stru2
 {
   void _43F9E1(__int16 x, int y, __int16 z, int w);
 
@@ -20,27 +20,27 @@
   __int16 array_3D8[480];
 };
 #pragma pack(pop)
-extern stru170_stru2 stru_F8A590;
+extern BspRenderer_stru2 stru_F8A590;
 
 
 
 
 /*  164 */
 #pragma pack(push, 1)
-struct stru170_stru0
+struct BspRenderer_stru0
 {
   //----- (0043F2BF) --------------------------------------------------------
-  inline stru170_stru0()
+  inline BspRenderer_stru0()
   {
     //_eh_vector_constructor_iterator_(std__vector_0007AC, 24, 4,
     //    (void (__thiscall *)(void *))IndoorCameraD3D_Vec4::IndoorCameraD3D_Vec4,
     //    (void (__thiscall *)(void *))IndoorCameraD3D_Vec4::dtor);
-    for (int i = 0; i < 4; ++i)
-      pVertices[i].flt_2C = 0.0f;
+    //for (int i = 0; i < 4; ++i)
+    //  pVertices[i].flt_2C = 0.0f;
   }
 
   //----- (0043F2A9) --------------------------------------------------------
-  ~stru170_stru0()
+  ~BspRenderer_stru0()
   {
     //_eh_vector_destructor_iterator_(this->std__vector_0007AC, 24, 4, IndoorCameraD3D_Vec4::dtor);
   }
@@ -51,7 +51,7 @@
   unsigned __int16 uViewportZ;
   unsigned __int16 uViewportW;
   __int16 field_A;
-  stru170_stru2 field_C;
+  BspRenderer_stru2 field_C;
   unsigned __int16 uFaceID;
   __int16 field_7A6;
   unsigned int std__vector_0007A8;
@@ -66,10 +66,10 @@
 
 /*  163 */
 #pragma pack(push, 1)
-struct stru170
+struct BspRenderer
 {
   //----- (0043F282) --------------------------------------------------------
-  inline stru170()
+  inline BspRenderer()
   {
    // _eh_vector_constructor_iterator_(field_FA8, 2252, 150,
    //    (void (__thiscall *)(void *))stru170_stru0::stru170_stru0,
@@ -87,14 +87,14 @@
   __int16 pFaceIDs[150];
   char field_130[3700];
   unsigned int std__vector_000FA8;
-  stru170_stru0 field_FA8[150];
+  BspRenderer_stru0 field_FA8[150];
   unsigned int uNumVisibleNotEmptySectors;
   unsigned __int16 pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[6];
 };
 #pragma pack(pop)
 
 
-extern struct stru170 *pStru170; // idb
+extern struct BspRenderer *pBspRenderer; // idb
 
 
 
--- a/LOD.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/LOD.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -1644,16 +1644,16 @@
 }
 // 6A0CA8: using guessed type int 6A0CA8_lod_unused;
 
-//----- (00461B48) --------------------------------------------------------
-/*unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4)
+
+unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4)
 {
-  LODWriteableFile *v4; // ebx@1
+  //LODWriteableFile *v4; // ebx@1
   int v5; // esi@1
-  unsigned __int8 v7; // zf@7
-  unsigned __int8 v8; // sf@7
+  //unsigned __int8 v7; // zf@7
+  //unsigned __int8 v8; // sf@7
   const LOD::Directory *v9; // edi@9
   int v10; // eax@9
-  unsigned __int8 v11; // of@15
+  //unsigned __int8 v11; // of@15
   unsigned __int16 v12; // dx@17
   LOD::Directory *v13; // eax@17
   unsigned __int16 v14; // cx@17
@@ -1675,7 +1675,7 @@
   char NewFilename[256]; // [sp+10Ch] [bp-130h]@51
   //LOD::Directory Str; // [sp+20Ch] [bp-30h]@27
   size_t v33; // [sp+22Ch] [bp-10h]@27
-  int v34; // [sp+230h] [bp-Ch]@7
+  //int v34; // [sp+230h] [bp-Ch]@7
   __int32 v35; // [sp+234h] [bp-8h]@8
   int v36; // [sp+238h] [bp-4h]@7
   size_t Count; // [sp+244h] [bp+8h]@40
@@ -1683,63 +1683,81 @@
   size_t Countb; // [sp+244h] [bp+8h]@47
   FILE *pFile; // [sp+24Ch] [bp+10h]@22
 
-  v4 = this;
-  v5 = 0;
-  if ( !this->isFileOpened )
+  //v4 = this;
+  //v5 = 0;
+
+  if (!isFileOpened)
     return 1;
-  if ( !this->pSubIndices )
+  if (!pSubIndices)
     return 2;
-  if ( !this->pIOBuffer || !this->uIOBufferSize )
+  if (!pIOBuffer || !uIOBufferSize)
     return 3;
-  v7 = this->uNumSubIndices == 0;
-  v8 = (this->uNumSubIndices & 0x80000000u) != 0;
+
+  //v7 = this->uNumSubIndices == 0;
+  //v8 = (this->uNumSubIndices & 0x80000000u) != 0;
+  v35 = 0;
   v36 = 0;
-  v34 = 0;
-  if ( v8 | v7 )
+  //v34 = 0;
+  for (v5 = 0; v5 < uNumSubIndices; ++v5)
+  /*if ( v8 | v7 )
   {
     v9 = pDir;
     goto LABEL_22;
   }
-  v35 = 0;
-  while ( 1 )
+  while ( 1 )*/
   {
     v9 = pDir;
-    v10 = _strcmpi((const char *)v4->pSubIndices + v35, (const char *)pDir);
-    if ( v10 )
+    v10 = _strcmpi(pSubIndices[v5].pFilename, pDir->pFilename);
+    if (v10 > 0)
+      break;
+    else if (v10 < 0)
+      continue;
+    /*if ( v10 )
     {
       if ( v10 > 0 )
         goto LABEL_22;
       goto LABEL_15;
-    }
+    }*/
     if ( !a4 )
-      goto LABEL_20;
+    {
+      v36 = 1;
+      break;
+    }
     if ( a4 == 1 )
+    {
+      v12 = pDir->uNumSubIndices;
+      v13 = &pSubIndices[v5];
+      v14 = v13->uNumSubIndices;
+      if ( v14 >= v12 && (v14 != v12 || (unsigned __int16)v13->word_00001E >= pDir->word_00001E) )
+        return 4;
+      v36 = 1;
       break;
+    }
     if ( a4 == 2 )
       return 4;
-LABEL_15:
-    v35 += 32;
-    ++v5;
-    v11 = __OFSUB__(v5, v4->uNumSubIndices);
-    v8 = ((v5 - v4->uNumSubIndices) & 0x80000000u) != 0;
-    v34 = v5;
-    if ( !(v8 ^ v11) )
-      goto LABEL_22;
+//LABEL_15:
+    //v35 += 32;
+    //++v5;
+    //v11 = __OFSUB__(v5, v4->uNumSubIndices);
+    //v8 = ((v5 - v4->uNumSubIndices) & 0x80000000u) != 0;
+    //v34 = v5;
+    //if ( !(v8 ^ v11) )
+      //goto LABEL_22;
   }
-  v12 = pDir->uNumSubIndices;
+/*  v12 = pDir->uNumSubIndices;
   v13 = &v4->pSubIndices[v5];
   v14 = v13->uNumSubIndices;
   if ( v14 >= v12 && (v14 != v12 || (unsigned __int16)v13->word_00001E >= pDir->word_00001E) )
     return 4;
 LABEL_20:
   v36 = 1;
-LABEL_22:
+LABEL_22:*/
   strcpy(pFilename, "lod.tmp");
   pFile = fopen(pFilename, "wb+");
   if ( !pFile )
     return 5;
   if ( v36 )
-    v35 = v4->pSubIndices[v5].uDataSize;
+    v35 = pSubIndices[v5].uDataSize;
   else
     v35 = 0;
   v33 = v9->uDataSize;
@@ -1748,9 +1766,9 @@
   LOD::Directory Str; // [sp+20Ch] [bp-30h]@27
   //LOD::Directory::LOD::Directory(&Str);
 
-  strcpy((char *)&Str, "chapter");
-  v16 = v4->uLODDataSize;
-  Str.uNumSubIndices = LOWORD(v4->uNumSubIndices);
+  strcpy(Str.pFilename, "chapter");
+  v16 = uLODDataSize;
+  Str.uNumSubIndices = uNumSubIndices;
   Str.dword_000018 = 0;
   Str.word_00001E = 0;
   if ( !v36 )
@@ -1758,262 +1776,76 @@
     ++Str.uNumSubIndices;
     v15 += 32;
   }
-  v7 = v36 == 0;
+  //v7 = v36 == 0;
   Str.uDataSize = v15 + v16;
   Str.uOfsetFromSubindicesStart = 288;
   v17 = (signed __int16)Str.uNumSubIndices;
-  v4->uNumSubIndices = (signed __int16)Str.uNumSubIndices;
-  if ( v7 && v17 > v5 )
+  uNumSubIndices = (signed __int16)Str.uNumSubIndices;
+  if ( !v36 && v17 > v5 )
   {
     v18 = v17;
     v19 = v17 - v5;
     do
     {
-      v20 = &v4->pSubIndices[v18];
+      v20 = &pSubIndices[v18];
       --v18;
       --v19;
       memcpy(v20, (char *)v20 - 32, 0x20u);
     }
     while ( v19 );
-    v5 = v34;
+    //v5 = v34;
   }
-  v34 = 32 * v5;
-  memcpy(&v4->pSubIndices[v5], pDir, sizeof(v4->pSubIndices[v5]));
-  v23 = 32 * v4->uNumSubIndices;
-  if ( (signed int)v4->uNumSubIndices > 0 )
+  //v34 = 32 * v5;
+  memcpy(&pSubIndices[v5], pDir, sizeof(LOD::Directory));
+  v23 = 32 * uNumSubIndices;
+  if ( (signed int)uNumSubIndices > 0 )
   {
-    for (int i =  0; i < (signed int)v4->uNumSubIndices; ++i)
+    for (int i =  0; i < (signed int)uNumSubIndices; ++i)
     {
-      v4->pSubIndices[i].uOfsetFromSubindicesStart = v23;
-      v23 += v4->pSubIndices[i].uDataSize;
+      pSubIndices[i].uOfsetFromSubindicesStart = v23;
+      v23 += pSubIndices[i].uDataSize;
     }
   }
-  fwrite(&v4->header, 0x100, 1, pFile);
+  fwrite(&header, 0x100, 1, pFile);
   fwrite(&Str, 0x20, 1, pFile);
-  fseek(v4->pFile, Str.uOfsetFromSubindicesStart, 0);
-  fwrite(v4->pSubIndices, 0x20u, v4->uNumSubIndices, pFile);
-  v26 = 32 * v4->uNumSubIndices;
+  fseek(pFile, Str.uOfsetFromSubindicesStart, 0);
+  fwrite(pSubIndices, 0x20u, uNumSubIndices, pFile);
+  v26 = 32 * uNumSubIndices;
   if ( !v36 )
     v26 -= 32;
-  fseek(v4->pFile, v26, 1);
-  for ( i = *(unsigned int *)((char *)&v4->pSubIndices->uOfsetFromSubindicesStart + v34)
-          - v4->pSubIndices->uOfsetFromSubindicesStart; i > 0; i -= Count )
+  fseek(pFile, v26, 1);
+  for ( i = pSubIndices[v5].uOfsetFromSubindicesStart
+          - pSubIndices->uOfsetFromSubindicesStart; i > 0; i -= Count )
   {
-    Count = v4->uIOBufferSize;
-    if ( i <= (signed int)v4->uIOBufferSize )
+    Count = uIOBufferSize;
+    if ( i <= (signed int)uIOBufferSize )
       Count = i;
-    fread(v4->pIOBuffer, 1u, Count, v4->pFile);
-    fwrite(v4->pIOBuffer, 1u, Count, pFile);
+    fread(pIOBuffer, 1u, Count, pFile);
+    fwrite(pIOBuffer, 1u, Count, pFile);
   }
   fwrite(pDirData, 1u, v33, pFile);
   if ( v36 )
-    fseek(v4->pFile, v35, 1);
-  Countc = ftell(v4->pFile);
-  fseek(v4->pFile, 0, 2);
-  v28 = ftell(v4->pFile) - Countc;
-  fseek(v4->pFile, Countc, 0);
+    fseek(pFile, v35, 1);
+  Countc = ftell(pFile);
+  fseek(pFile, 0, 2);
+  v28 = ftell(pFile) - Countc;
+  fseek(pFile, Countc, 0);
   while ( v28 > 0 )
   {
-    Countb = v4->uIOBufferSize;
-    if ( v28 <= (signed int)v4->uIOBufferSize )
+    Countb = uIOBufferSize;
+    if ( v28 <= (signed int)uIOBufferSize )
       Countb = v28;
-    fread(v4->pIOBuffer, 1u, Countb, v4->pFile);
-    fwrite(v4->pIOBuffer, 1u, Countb, pFile);
+    fread(pIOBuffer, 1u, Countb, pFile);
+    fwrite(pIOBuffer, 1u, Countb, pFile);
     v28 -= Countb;
   }
-  strcpy(NewFilename, (const char *)v4->pLODName);
+  strcpy(NewFilename, (const char *)pLODName);
   fclose(pFile);
-  v4->CloseWriteFile();
+  CloseWriteFile();
   remove(NewFilename);
   rename(pFilename, NewFilename);
-  v4->CloseWriteFile();
-  v4->LoadFile(v4->pLODName, 0);
-  return 0;
-}
-*/
-
-unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4)
-{
-  LODWriteableFile *v4; // ebx@1
-  int v5; // esi@1
-  unsigned __int8 v7; // zf@7
-  unsigned __int8 v8; // sf@7
-  const LOD::Directory *v9; // edi@9
-  int v10; // eax@9
-  unsigned __int8 v11; // of@15
-  unsigned __int16 v12; // dx@17
-  LOD::Directory *v13; // eax@17
-  unsigned __int16 v14; // cx@17
-  int v15; // edi@27
-  unsigned int v16; // eax@27
-  int v17; // eax@29
-  int v18; // edx@31
-  int v19; // eax@31
-  void *v20; // edi@32
-  LOD::Directory *v21; // edi@34
-  signed int v22; // esi@34
-  int v23; // eax@34
-  LOD::Directory *v24; // ecx@35
-  int v25; // edx@35
-  __int32 v26; // eax@37
-  int i; // esi@39
-  __int32 v28; // esi@46
-  char pFilename[256]; // [sp+Ch] [bp-230h]@22
-  char NewFilename[256]; // [sp+10Ch] [bp-130h]@51
-  //LOD::Directory Str; // [sp+20Ch] [bp-30h]@27
-  size_t v33; // [sp+22Ch] [bp-10h]@27
-  int v34; // [sp+230h] [bp-Ch]@7
-  __int32 v35; // [sp+234h] [bp-8h]@8
-  int v36; // [sp+238h] [bp-4h]@7
-  size_t Count; // [sp+244h] [bp+8h]@40
-  __int32 Countc; // [sp+244h] [bp+8h]@46
-  size_t Countb; // [sp+244h] [bp+8h]@47
-  FILE *pFile; // [sp+24Ch] [bp+10h]@22
-
-  v4 = this;
-  v5 = 0;
-  if ( !this->isFileOpened )
-    return 1;
-  if ( !this->pSubIndices )
-    return 2;
-  if ( !this->pIOBuffer || !this->uIOBufferSize )
-    return 3;
-  v7 = this->uNumSubIndices == 0;
-  v8 = (this->uNumSubIndices & 0x80000000u) != 0;
-  v36 = 0;
-  v34 = 0;
-  if ( v8 | v7 )
-  {
-    v9 = pDir;
-    goto LABEL_22;
-  }
-  v35 = 0;
-  while ( 1 )
-  {
-    v9 = pDir;
-    v10 = _strcmpi((const char *)v4->pSubIndices + v35, (const char *)pDir);
-    if ( v10 )
-    {
-      if ( v10 > 0 )
-        goto LABEL_22;
-      goto LABEL_15;
-    }
-    if ( !a4 )
-      goto LABEL_20;
-    if ( a4 == 1 )
-      break;
-    if ( a4 == 2 )
-      return 4;
-LABEL_15:
-    v35 += 32;
-    ++v5;
-   v8 = ((v5 - v4->uNumSubIndices) & 0x80000000u) != 0;
-    v34 = v5;
-    if ( !(v8 ^ v11) )
-      goto LABEL_22;
-  }
-  v12 = pDir->uNumSubIndices;
-  v13 = &v4->pSubIndices[v5];
-  v14 = v13->uNumSubIndices;
-  if ( v14 >= v12 && (v14 != v12 || (unsigned __int16)v13->word_00001E >= pDir->word_00001E) )
-    return 4;
-LABEL_20:
-  v36 = 1;
-LABEL_22:
-  strcpy(pFilename, "lod.tmp");
-  pFile = fopen(pFilename, "wb+");
-  if ( !pFile )
-    return 5;
-  if ( v36 )
-    v35 = v4->pSubIndices[v5].uDataSize;
-  else
-    v35 = 0;
-  v33 = v9->uDataSize;
-  v15 = v33 - v35;
-
-  LOD::Directory Str; // [sp+20Ch] [bp-30h]@27
-  //LOD::Directory::LOD::Directory(&Str);
-
-  strcpy((char *)&Str, "chapter");
-  v16 = v4->uLODDataSize;
-  Str.uNumSubIndices = LOWORD(v4->uNumSubIndices);
-  Str.dword_000018 = 0;
-  Str.word_00001E = 0;
-  if ( !v36 )
-  {
-    ++Str.uNumSubIndices;
-    v15 += 32;
-  }
-  v7 = v36 == 0;
-  Str.uDataSize = v15 + v16;
-  Str.uOfsetFromSubindicesStart = 288;
-  v17 = (signed __int16)Str.uNumSubIndices;
-  v4->uNumSubIndices = (signed __int16)Str.uNumSubIndices;
-  if ( v7 && v17 > v5 )
-  {
-    v18 = v17;
-    v19 = v17 - v5;
-    do
-    {
-      v20 = &v4->pSubIndices[v18];
-      --v18;
-      --v19;
-      memcpy(v20, (char *)v20 - 32, 0x20u);
-    }
-    while ( v19 );
-    v5 = v34;
-  }
-  v34 = 32 * v5;
-  memcpy(&v4->pSubIndices[v5], pDir, sizeof(v4->pSubIndices[v5]));
-  v23 = 32 * v4->uNumSubIndices;
-  if ( (signed int)v4->uNumSubIndices > 0 )
-  {
-    for (int i =  0; i < (signed int)v4->uNumSubIndices; ++i)
-    {
-      v4->pSubIndices[i].uOfsetFromSubindicesStart = v23;
-      v23 += v4->pSubIndices[i].uDataSize;
-    }
-  }
-  fwrite(&v4->header, 0x100, 1, pFile);
-  fwrite(&Str, 0x20, 1, pFile);
-  fseek(v4->pFile, Str.uOfsetFromSubindicesStart, 0);
-  fwrite(v4->pSubIndices, 0x20u, v4->uNumSubIndices, pFile);
-  v26 = 32 * v4->uNumSubIndices;
-  if ( !v36 )
-    v26 -= 32;
-  fseek(v4->pFile, v26, 1);
-  for ( i = *(unsigned int *)((char *)&v4->pSubIndices->uOfsetFromSubindicesStart + v34)
-          - v4->pSubIndices->uOfsetFromSubindicesStart; i > 0; i -= Count )
-  {
-    Count = v4->uIOBufferSize;
-    if ( i <= (signed int)v4->uIOBufferSize )
-      Count = i;
-    fread(v4->pIOBuffer, 1u, Count, v4->pFile);
-    fwrite(v4->pIOBuffer, 1u, Count, pFile);
-  }
-  fwrite(pDirData, 1u, v33, pFile);
-  if ( v36 )
-    fseek(v4->pFile, v35, 1);
-  Countc = ftell(v4->pFile);
-  fseek(v4->pFile, 0, 2);
-  v28 = ftell(v4->pFile) - Countc;
-  fseek(v4->pFile, Countc, 0);
-  while ( v28 > 0 )
-  {
-    Countb = v4->uIOBufferSize;
-    if ( v28 <= (signed int)v4->uIOBufferSize )
-      Countb = v28;
-    fread(v4->pIOBuffer, 1u, Countb, v4->pFile);
-    fwrite(v4->pIOBuffer, 1u, Countb, pFile);
-    v28 -= Countb;
-  }
-  strcpy(NewFilename, (const char *)v4->pLODName);
-  fclose(pFile);
-  v4->CloseWriteFile();
-  remove(NewFilename);
-  rename(pFilename, NewFilename);
-  v4->CloseWriteFile();
-  v4->LoadFile(v4->pLODName, 0);
+  CloseWriteFile();
+  LoadFile(pLODName, 0);
   return 0;
 }
 
--- a/LOD.h	Thu Nov 08 09:27:19 2012 +0600
+++ b/LOD.h	Thu Nov 08 09:27:41 2012 +0600
@@ -1,7 +1,8 @@
 #pragma once
 #include <stdio.h>
+#include <memory.h>
+
 #include "Texture.h"
-#include <memory.h>
 
 
 /*  354 */
--- a/OSAPI.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/OSAPI.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -5,6 +5,7 @@
 
 OSVersion *pVersion = nullptr;
 
+
 //----- (00462C94) --------------------------------------------------------
 int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE, wchar_t *lpCmdLine, int nShowCmd)
 {
--- a/Vis.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/Vis.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -359,9 +359,9 @@
   v5 = 0;
   thisa = this;
   v17 = 0;
-  for ( a1.flt_2C = 0.0; v17 < (signed int)pStru170->uNumFaceIDs; ++v17 )
+  for ( a1.flt_2C = 0.0; v17 < (signed int)pBspRenderer->uNumFaceIDs; ++v17 )
   {
-    v6 = pStru170->pFaceIDs[2 * v5];
+    v6 = pBspRenderer->pFaceIDs[2 * v5];
     if ( v6 >= 0 )
     {
       if ( v6 < (signed int)pIndoor->uNumFaces )
@@ -1991,9 +1991,9 @@
 
   result = 0;
   thisa = this;
-  for ( i = 0; i < (signed int)pStru170->uNumFaceIDs; ++i )
+  for ( i = 0; i < (signed int)pBspRenderer->uNumFaceIDs; ++i )
   {
-    v5 = pStru170->pFaceIDs[2 * result];
+    v5 = pBspRenderer->pFaceIDs[2 * result];
     if ( v5 >= 0 )
     {
       if ( v5 < (signed int)pIndoor->uNumFaces )
--- a/mm7_1.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/mm7_1.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -7153,10 +7153,10 @@
 
 
 //----- (00424829) --------------------------------------------------------
-bool __fastcall sub_424829(int a1, stru170_stru2 *a2, stru170_stru2 *a3, int a4)
+bool sub_424829(int a1, BspRenderer_stru2 *a2, BspRenderer_stru2 *a3, int a4)
 {
   int v4; // edi@1
-  stru170_stru2 *v5; // ebx@1
+  BspRenderer_stru2 *v5; // ebx@1
   int v6; // eax@3
   int v7; // esi@5
   int v8; // edx@5
@@ -7190,7 +7190,7 @@
   __int16 v36; // dx@67
   __int16 v37; // di@67
   __int16 v38; // dx@67
-  stru170_stru2 *v39; // ecx@69
+  BspRenderer_stru2 *v39; // ecx@69
   int v40; // edx@69
   int v41; // edi@70
   __int16 *v42; // eax@76
@@ -7210,7 +7210,7 @@
   __int16 *v57; // [sp+14h] [bp-2Ch]@76
   __int16 *v58; // [sp+14h] [bp-2Ch]@81
   __int16 *v59; // [sp+14h] [bp-2Ch]@87
-  stru170_stru2 *v60; // [sp+18h] [bp-28h]@1
+  BspRenderer_stru2 *v60; // [sp+18h] [bp-28h]@1
   int v61; // [sp+1Ch] [bp-24h]@29
   int v62; // [sp+20h] [bp-20h]@0
   signed int v63; // [sp+24h] [bp-1Ch]@3
--- a/mm7_3.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/mm7_3.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -2178,12 +2178,12 @@
 
 
 //----- (0047253E) --------------------------------------------------------
-void __cdecl UpdateObjects()
+void UpdateObjects()
 {
   unsigned int v0; // ebx@0
-  unsigned int v1; // edi@1
+  //unsigned int v1; // edi@1
   char *v2; // esi@2
-  __int16 v3; // dx@5
+  //__int16 v3; // dx@5
   ObjectDesc *v4; // eax@5
   int v5; // ecx@6
   __int16 v6; // cx@7
@@ -2200,68 +2200,66 @@
   unsigned int v17; // edx@32
   int v18; // [sp+4h] [bp-10h]@27
   int v19; // [sp+8h] [bp-Ch]@27
-  signed int v20; // [sp+10h] [bp-4h]@1
-
-  v1 = 0;
-  v20 = 0;
-  if ( (signed int)uNumLayingItems > 0 )
-  {
-    __debugbreak();
-    v2 = (char *)&pLayingItems[0].uSpriteFrameID;
-    do
-    {
-      LOWORD(v0) = *((short *)v2 - 2);
-      if ( v0 & 0x40 )
-      {
-        v0 &= 0xFFFFFFBFu;
-        *((short *)v2 - 2) = v0;
-      }
-      else
-      {
-        v3 = *((short *)v2 - 14);
-        v4 = &pObjectList->pObjects[*((short *)v2 - 14)];
-        if ( (v0 & 0x80u) != 0 )
-        {
+  //signed int v20; // [sp+10h] [bp-4h]@1
+
+  //v1 = 0;
+  //v20 = 0;
+  for (uint i = 0; i < uNumLayingItems; ++i)
+  {
+    auto item = pLayingItems + i;
+    v2 = (char *)&item->uSpriteFrameID;
+    //do
+    //{
+      //LOWORD(v0) = item->uAttributes;
+    if (item->uAttributes & 0x40)
+      item->uAttributes &= 0xFFBF;
+    else
+    {
+              //v3 = item->uObjectDescID;
+      v4 = &pObjectList->pObjects[item->uObjectDescID];
+      if (item->uAttributes)
+      {
           v5 = *(int *)(v2 + 62) >> 3;
           *(int *)(v2 - 26) = pActors[v5].vPosition.x;
           *(int *)(v2 - 22) = pActors[v5].vPosition.y;
           *(int *)(v2 - 18) = pActors[v5].vPosition.z + pActors[v5].uActorHeight;
-          if ( !v3 || (v6 = LOWORD(pEventTimer->uTimeElapsed) + *(short *)v2, *(short *)v2 = v6, !(v4->uFlags & 4)) )
+          if ( !item->uObjectDescID || (v6 = LOWORD(pEventTimer->uTimeElapsed) + *(short *)v2, *(short *)v2 = v6, !(v4->uFlags & 4)) )
             goto LABEL_36;
           if ( v6 >= 0 )
           {
             v7 = v4->uLifetime;
-            if ( v0 & 2 )
+            if (item->uAttributes & 2)
               v7 = *((short *)v2 + 1);
             if ( v6 < v7 )
               goto LABEL_36;
           }
           goto LABEL_34;
-        }
-        if ( v3 )
-        {
-          v8 = LOWORD(pEventTimer->uTimeElapsed) + *(short *)v2;
-          *(short *)v2 = v8;
+      }
+
+        if ( item->uObjectDescID )
+        {
+          v8 = LOWORD(pEventTimer->uTimeElapsed) + item->uSpriteFrameID;
+          item->uSpriteFrameID = v8;
           v9 = v4->uFlags;
           if ( !(v9 & 4) )
             goto LABEL_22;
           if ( v8 < 0 )
           {
-            v10 = v1;
+            v10 = i;
 LABEL_35:
             LayingItem::_42F933(v10);
             goto LABEL_36;
           }
           v11 = v4->uLifetime;
-          if ( v0 & 2 )
+          if ( item->uAttributes & 2 )
             v11 = *((short *)v2 + 1);
           if ( v8 < v11 )
           {
 LABEL_22:
             if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
-              LayingItem::UpdateObject_fn0_BLV(v1);
+              LayingItem::UpdateObject_fn0_BLV(i);
             else
-              LayingItem::UpdateObject_fn0_ODM(v1);
+              LayingItem::UpdateObject_fn0_ODM(i);
             if ( pParty->bTurnBasedModeOn != 1 || !(*(v2 - 4) & 4) )
               goto LABEL_36;
             v12 = abs(pParty->vPosition.x - *(int *)(v2 - 26));
@@ -2291,20 +2289,21 @@
             if ( (signed int)(v0 + (v15 >> 2) + v13) <= 5120 )
               goto LABEL_36;
 LABEL_34:
-            v10 = v20;
+            v10 = i;
             goto LABEL_35;
           }
-          v10 = v1;
+          v10 = i;
           if ( !(v9 & 0x40) )
             goto LABEL_35;
-          _46BFFA_check_object_intercept(v1, 8 * v1 | OBJECT_Item);
-        }
-      }
+          _46BFFA_check_object_intercept(i, 8 * i | OBJECT_Item);
+        }
+    }
 LABEL_36:
-      v2 += 112;
-      v1 = v20++ + 1;
-    }
-    while ( v20 < (signed int)uNumLayingItems );
+    ;
+      //v2 += 112;
+      //v1 = v20++ + 1;
+    //}
+    //while ( v20 < (signed int)uNumLayingItems );
   }
 }
 
@@ -12881,31 +12880,33 @@
 
 
 //----- (0043F953) --------------------------------------------------------
-void PrepareWallsRenderList_BLV()
-{
-  pStru170->uNumFaceIDs = 0;
-  if ( pBLVRenderParams->uPartySectorID )
-  {
-    pStru170->field_FA8[0].uSectorID = pBLVRenderParams->uPartySectorID;
-    pStru170->field_FA8[0].uViewportW = pBLVRenderParams->uViewportW;
-    pStru170->field_FA8[0].uViewportZ = pBLVRenderParams->uViewportZ;
-    pStru170->field_FA8[0].uViewportY = pBLVRenderParams->uViewportY;
-    pStru170->field_FA8[0].uViewportX = pBLVRenderParams->uViewportX;
-    pStru170->field_FA8[0].field_C._43F9E1(
+void PrepareBspRenderList_BLV()
+{
+  pBspRenderer->uNumFaceIDs = 0;
+
+  if (pBLVRenderParams->uPartySectorID)
+  {
+    pBspRenderer->field_FA8[0].uSectorID = pBLVRenderParams->uPartySectorID;
+    pBspRenderer->field_FA8[0].uViewportW = pBLVRenderParams->uViewportW;
+    pBspRenderer->field_FA8[0].uViewportZ = pBLVRenderParams->uViewportZ;
+    pBspRenderer->field_FA8[0].uViewportY = pBLVRenderParams->uViewportY;
+    pBspRenderer->field_FA8[0].uViewportX = pBLVRenderParams->uViewportX;
+    pBspRenderer->field_FA8[0].field_C._43F9E1(
       pBLVRenderParams->uViewportX,
       pBLVRenderParams->uViewportY,
       pBLVRenderParams->uViewportZ,
       pBLVRenderParams->uViewportW);
-    pStru170->field_FA8[0].uFaceID = -1;
-    pStru170->field_FA8[0].std__vector_0007A8 = -1;
-    pStru170->std__vector_000FA8 = 1;
+    pBspRenderer->field_FA8[0].uFaceID = -1;
+    pBspRenderer->field_FA8[0].std__vector_0007A8 = -1;
+    pBspRenderer->std__vector_000FA8 = 1;
     sub_440639(0);
   }
-  pStru170->MakeVisibleSectorList();
+
+  pBspRenderer->MakeVisibleSectorList();
 }
 
 //----- (0043F9E1) --------------------------------------------------------
-void stru170_stru2::_43F9E1(__int16 x, int y, __int16 z, int w)
+void BspRenderer_stru2::_43F9E1(__int16 x, int y, __int16 z, int w)
 {
   _viewport_space_y = y;
   _viewport_space_w = w;
@@ -13258,7 +13259,7 @@
 
   v1 = a1;
   v2 = 0;
-  v3 = &pIndoor->pSectors[pStru170->field_FA8[a1].uSectorID];
+  v3 = &pIndoor->pSectors[pBspRenderer->field_FA8[a1].uSectorID];
   if ( pRenderer->pRenderD3D )
   {
     if ( v3->uNumNonBSPFaces > 0 )
@@ -13266,7 +13267,7 @@
       do
       {
         Log::Warning(L"Non-BSP face: %X", v3->pFaceIDs[v2]);
-        pStru170->PrepareFaceRenderList_d3d(v1, v3->pFaceIDs[v2++]);
+        pBspRenderer->PrepareFaceRenderList_d3d(v1, v3->pFaceIDs[v2++]);
       }
       while ( v2 < v3->uNumNonBSPFaces );
     }
@@ -13276,7 +13277,7 @@
     if ( v3->uNumNonBSPFaces > 0 )
     {
       do
-        pStru170->PrepareFaceRenderList_sw(v1, v3->pFaceIDs[v2++]);
+        pBspRenderer->PrepareFaceRenderList_sw(v1, v3->pFaceIDs[v2++]);
       while ( v2 < v3->uNumNonBSPFaces );
     }
   }
@@ -13297,12 +13298,12 @@
   __int16 v9; // di@18
   int v10; // [sp+10h] [bp-Ch]@1
   bool v11; // [sp+14h] [bp-8h]@5
-  stru170_stru0 *v12; // [sp+18h] [bp-4h]@1
+  BspRenderer_stru0 *v12; // [sp+18h] [bp-4h]@1
 
   Log::Warning(L"sub_4406BC(%u, %u)", a1, uFirstNode);
 
   v10 = a1;
-  v12 = &pStru170->field_FA8[a1];
+  v12 = &pBspRenderer->field_FA8[a1];
   while ( 1 )
   {
     v2 = &pIndoor->pSectors[v12->uSectorID];
@@ -13329,12 +13330,12 @@
     if ( pRenderer->pRenderD3D )
     {
       while ( v7 < v8 )
-        pStru170->PrepareFaceRenderList_d3d(v10, v2->pFaceIDs[v7++]);
+        pBspRenderer->PrepareFaceRenderList_d3d(v10, v2->pFaceIDs[v7++]);
     }
     else
     {
       while ( v7 < v8 )
-        pStru170->PrepareFaceRenderList_sw(v10, v2->pFaceIDs[v7++]);
+        pBspRenderer->PrepareFaceRenderList_sw(v10, v2->pFaceIDs[v7++]);
     }
     v9 = v11 ? v3->uFront : v3->uBack;
     if ( v9 == -1 )
--- a/mm7_4.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/mm7_4.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -15158,12 +15158,12 @@
         byte_4E94D3);
     }
     v12 = 0;
-    if ( pStru170->uNumVisibleNotEmptySectors <= 0 )
+    if ( pBspRenderer->uNumVisibleNotEmptySectors <= 0 )
       continue;
-    while (pStru170->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v12] != p->uSectorID)
+    while (pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v12] != p->uSectorID)
     {
       ++v12;
-      if ( v12 >= pStru170->uNumVisibleNotEmptySectors )
+      if ( v12 >= pBspRenderer->uNumVisibleNotEmptySectors )
         goto _continue;
     }
     if ( !pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible(a1a, a2, a3, &x, &y, &z, 1)
--- a/mm7_5.cpp	Thu Nov 08 09:27:19 2012 +0600
+++ b/mm7_5.cpp	Thu Nov 08 09:27:41 2012 +0600
@@ -8901,7 +8901,7 @@
 
 
 //----- (0043F333) --------------------------------------------------------
-void stru170::MakeVisibleSectorList()
+void BspRenderer::MakeVisibleSectorList()
 {
   int v6; // ebx@3
 
--- a/mm7_data.h	Thu Nov 08 09:27:19 2012 +0600
+++ b/mm7_data.h	Thu Nov 08 09:27:41 2012 +0600
@@ -1908,7 +1908,7 @@
 void __cdecl sub_423B4A();
 int __fastcall sub_423B5D(unsigned int uFaceID);
 signed int __fastcall sub_424579(int uFaceID, struct stru320 *a2);
-bool __fastcall sub_424829(int a1, struct stru170_stru2 *a2, struct stru170_stru2 *a3, int a4);
+bool sub_424829(int a1, struct BspRenderer_stru2 *a2, struct BspRenderer_stru2 *a3, int a4);
 signed int __fastcall sr_424CD7(unsigned int uVertexID); // idb
 signed int __fastcall sr_424EE0_MakeFanFromTriangle(unsigned int uVertexID); // idb
 signed int __fastcall sr_4250FE(unsigned int uVertexID); // idb
@@ -1974,7 +1974,7 @@
 void __cdecl MessWithBillboards_BLV();
 int __fastcall _43F55F_get_billboard_light_level(struct RenderBillboard *a1, int uBaseLightLevel);
 int __fastcall _43F5C8_get_point_light_level_with_respect_to_lights(unsigned int uBaseLightLevel, int uSectorID, float x, float y, float z);
-void PrepareWallsRenderList_BLV();
+void PrepareBspRenderList_BLV();
 void __fastcall PrepareDecorationsRenderList_BLV(unsigned int uDecorationID, unsigned int uSectorID);
 void PrepareActorRenderList_BLV();
 void PrepareItemsRenderList_BLV();