changeset 1373:87155494292c

Слияние
author Ritor1
date Mon, 15 Jul 2013 17:09:48 +0600
parents 5572e7b02f45 (diff) 6b4a1c44a56f (current diff)
children 270134611caf 78671379d8da
files
diffstat 4 files changed, 109 insertions(+), 170 deletions(-) [+]
line wrap: on
line diff
--- a/Indoor.cpp	Mon Jul 15 08:20:28 2013 +0400
+++ b/Indoor.cpp	Mon Jul 15 17:09:48 2013 +0600
@@ -771,7 +771,7 @@
             v7 = GetPortalScreenCoord(v1);
             if ( v7 )
             {
-              if ( sub_424829(v7, &stru_F8A590, pBLVRenderParams->field_7C, v1) )
+              if ( PortalFrustrum(v7, &stru_F8A590, pBLVRenderParams->field_7C, v1) )
               {
                 if ( v2->uPolygonType == 1 )
                 {
@@ -1379,7 +1379,7 @@
       face_min_screenspace_x <= nodes[node_id].uViewportZ &&
       face_max_screenspace_y >= nodes[node_id].uViewportY &&
       face_min_screenspace_y <= nodes[node_id].uViewportW &&
-      sub_424829(num_vertices, &nodes[num_nodes].field_C, &nodes[node_id].field_C, uFaceID))
+      PortalFrustrum(num_vertices, &nodes[num_nodes].field_C, &nodes[node_id].field_C, uFaceID))
   {
     pTransitionSector = pFace->uSectorID;
     if (nodes[node_id].uSectorID == pTransitionSector )
@@ -1532,7 +1532,7 @@
           && v23 <= *((short *)v20 + 2007)
           && v12 >= *((short *)v20 + 2006)
           && v22 <= *((short *)v20 + 2008)
-          && sub_424829(v10, &v3->nodes[v3->num_nodes].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) )
+          && PortalFrustrum(v10, &v3->nodes[v3->num_nodes].field_C, (BspRenderer_stru2 *)(v20 + 4020), uFaceID) )
         {
           v16 = v21->uSectorID;
           if ( *((short *)v20 + 2004) == v16 )
@@ -1591,7 +1591,7 @@
         v3 = GetPortalScreenCoord(v2);
         if ( v3 )
         {
-          if ( sub_424829(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1) )
+          if ( PortalFrustrum(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1) )
           {
             v4 = stru_F8A590._viewport_space_y;
             v5 = pBLVRenderParams->pRenderTarget;
@@ -6831,139 +6831,106 @@
   check_event_triggers();
 }
 //----- (00424829) --------------------------------------------------------
-bool sub_424829(int pNumVertices, BspRenderer_stru2 *a2, BspRenderer_stru2 *a3, int uFaceID)
+bool PortalFrustrum(int pNumVertices, BspRenderer_stru2 *a2, BspRenderer_stru2 *a3, int uFaceID)
 {
-  //int v4; // edi@1
-  //BspRenderer_stru2 *v5; // ebx@1
-  int v6; // eax@3
+  //int v6; // eax@3
   int min_y; // esi@5
   int max_y; // edx@5
-  //int v9; // ecx@6
-  int v10; // eax@12
-  //int v11; // edi@13
-  //int v12; // edx@18
+  int current_ID; // eax@12
   int v13; // eax@22
-  //int v14; // edi@28
   int v15; // ecx@29
-  //int v16; // edi@30
-  //int v17; // edx@35
   int v18; // eax@39
   int v19; // eax@44
   int v20; // ecx@44
-  //int v21; // edi@45
   int v22; // edi@46
-  //__int16 *v23; // ecx@47
   int v24; // edx@48
-  //int v25; // eax@50
   int v26; // eax@55
   signed int v27; // edi@55
-  //int v28; // edx@56
   int v29; // edx@57
-  //int v30; // eax@59
   int v31; // eax@64
   signed int v32; // edi@64
-  //int v33; // edx@65
   int v34; // eax@66
   int v35; // dx@66
   __int16 v36; // dx@67
   __int16 v37; // di@67
   __int16 v38; // dx@67
-  //BspRenderer_stru2 *v39; // ecx@69
-  //int v40; // edx@69
-  //int v41; // edi@70
-  //__int16 *v42; // eax@76
-  //__int16 *v43; // eax@81
-  //__int16 *v45; // eax@87
   int v46; // edx@87
-  //__int16 v47; // cx@88
-  //int v48; // eax@93
   int v49; // esi@93
-  //__int16 *v50; // ecx@94
-  //int v51; // eax@95
-  //int v52; // eax@97
   int v53; // [sp+Ch] [bp-34h]@44
   int v54; // [sp+10h] [bp-30h]@0
-  int v55; // [sp+14h] [bp-2Ch]@12
-  //__int16 *v56; // [sp+14h] [bp-2Ch]@47
-  //__int16 v57; // [sp+14h] [bp-2Ch]@76
-  //__int16 v58; // [sp+14h] [bp-2Ch]@81
+  int min_y_ID2; // [sp+14h] [bp-2Ch]@12
   int v59; // [sp+14h] [bp-2Ch]@87
-  //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
-  signed int v64; // [sp+28h] [bp-18h]@3
-  int v65; // [sp+2Ch] [bp-14h]@5
-  //int v66; // [sp+2Ch] [bp-14h]@39
-  //int v67; // [sp+30h] [bp-10h]@22
-  int v68; // [sp+34h] [bp-Ch]@12
+  signed int direction1; // [sp+24h] [bp-1Ch]@3
+  signed int direction2; // [sp+28h] [bp-18h]@3
+  int min_y_ID; // [sp+2Ch] [bp-14h]@5
+  //int v68; // [sp+34h] [bp-Ch]@12
   int v69; // [sp+34h] [bp-Ch]@29
   int v70; // [sp+34h] [bp-Ch]@46
   int v71; // [sp+34h] [bp-Ch]@75
   int v72; // [sp+34h] [bp-Ch]@80
-  //int v73; // [sp+38h] [bp-8h]@11
-  //int v74; // [sp+3Ch] [bp-4h]@1
-  //int a3a; // [sp+48h] [bp+8h]@76
-  //int a3b; // [sp+48h] [bp+8h]@87
-
-  //try graphic engine with function returning 1 always, and without
-  //return true;
+
   if ( pNumVertices <= 1 )
     return false;
   min_y = PortalFace._screen_space_y[0];
-  v65 = 0;
+  min_y_ID = 0;
   max_y = PortalFace._screen_space_y[0];
+  //face direction( )
   if ( !PortalFace.direction )
   {
-    v63 = 1;
-    v64 = -1;
+    direction1 = 1;
+    direction2 = -1;
   }
   else 
   {
-    v63 = -1;
-    v64 = 1;
-  }
-
-  for ( v6 = 1; v6 < pNumVertices; ++v6 )
-  {
-    if ( PortalFace._screen_space_y[v6] >= min_y )
+    direction1 = -1;
+    direction2 = 1;
+  }
+
+  //get min and max y for portal(     y  )
+  for ( uint i = 1; i < pNumVertices; ++i )
+  {
+    if ( PortalFace._screen_space_y[i] >= min_y )
     {
-      if ( PortalFace._screen_space_y[v6] > max_y )
-        max_y = PortalFace._screen_space_y[v6];
+      if ( PortalFace._screen_space_y[i] > max_y )
+        max_y = PortalFace._screen_space_y[i];
     }
-    if ( PortalFace._screen_space_y[v6] < min_y )
+    else
     {
-      v65 = v6;
-      min_y = PortalFace._screen_space_y[v6];
+      min_y_ID = i;
+      min_y = PortalFace._screen_space_y[i];
     }
   }
   if ( max_y == min_y )
     return false;
 
-  v10 = v65;
+  //*****************************************************************************************************************************
   a2->_viewport_space_y = min_y;
   a2->_viewport_space_w = max_y;
-  v55 = v65;
-
-  for ( v68 = 0; v68 < pNumVertices; ++v68 )
-  {
-    v10 += v64;
-    if ( v10 < pNumVertices )
+  current_ID = min_y_ID;
+  min_y_ID2 = min_y_ID;
+
+  for ( uint i = 0; i < pNumVertices; ++i )
+  {
+    current_ID += direction2;
+    if ( current_ID < pNumVertices )
     {
-      if ( v10 < 0 )
-        v10 += pNumVertices;
+      if ( current_ID < 0 )
+        current_ID += pNumVertices;
     }
     else
-      v10 -= pNumVertices;
-    if ( PortalFace._screen_space_y[v10] <= PortalFace._screen_space_y[v65] )
+      current_ID -= pNumVertices;
+    if ( PortalFace._screen_space_y[current_ID] <= PortalFace._screen_space_y[min_y_ID] )//  
     {
-      v55 = v10;
-      v65 = v10;
+      min_y_ID2 = current_ID;
+      min_y_ID = current_ID;
     }
-    if ( PortalFace._screen_space_y[v10] == max_y )
+    if ( PortalFace._screen_space_y[current_ID] == max_y )
       break;
   }
-  v13 = v55 + v64;
+
+  v13 = min_y_ID2 + direction2;
   if ( v13 < pNumVertices )
   {
     if ( v13 < 0 )
@@ -6971,18 +6938,19 @@
   }
   else
     v13 -= pNumVertices;
-  if ( PortalFace._screen_space_y[v13] != PortalFace._screen_space_y[v55] )
-  {
-    v62 = PortalFace._screen_space_x[v55] << 16;
-    v54 = ((PortalFace._screen_space_x[v13] - PortalFace._screen_space_x[v55]) << 16) / (PortalFace._screen_space_y[v13] - PortalFace._screen_space_y[v55]);
-    a2->viewport_left_side[min_y] = LOWORD(PortalFace._screen_space_x[v55]);
-  }
-  v15 = v65;
-  v61 = v65;
-
+  if ( PortalFace._screen_space_y[v13] != PortalFace._screen_space_y[min_y_ID2] )
+  {
+    v62 = PortalFace._screen_space_x[min_y_ID2] << 16;
+    v54 = ((PortalFace._screen_space_x[v13] - PortalFace._screen_space_x[min_y_ID2]) << 16) / (PortalFace._screen_space_y[v13] - PortalFace._screen_space_y[min_y_ID2]);
+    a2->viewport_left_side[min_y] = PortalFace._screen_space_x[min_y_ID2];
+  }
+  //****************************************************************************************************************************************
+  //
+  v15 = min_y_ID;
+  v61 = min_y_ID;
   for ( v69 = 0; v69 < pNumVertices; ++v69 )
   {
-    v15 += v63;
+    v15 += direction1;
     if ( v15 < pNumVertices )
     {
       if ( v15 < 0 )
@@ -6990,15 +6958,15 @@
     }
     else
       v15 -= pNumVertices;
-    if ( PortalFace._screen_space_y[v15] <= PortalFace._screen_space_y[v65] )
+    if ( PortalFace._screen_space_y[v15] <= PortalFace._screen_space_y[min_y_ID] )
     {
       v61 = v15;
-      v65 = v15;
+      min_y_ID = v15;
     }
     if ( PortalFace._screen_space_y[v15] == max_y )
       break;
   }
-  v18 = v63 + v61;
+  v18 = direction1 + v61;
   if ( v18 < pNumVertices )
   {
     if ( v18 < 0 )
@@ -7012,8 +6980,9 @@
   {
     v61 = PortalFace._screen_space_x[v20] << 16;
     v53 = ((PortalFace._screen_space_x[v19] - PortalFace._screen_space_x[v20]) << 16) / PortalFace._screen_space_y[v19] - PortalFace._screen_space_y[v20];
-    a2->viewport_right_side[max_y] = LOWORD(PortalFace._screen_space_x[v20]);
-  }
+    a2->viewport_right_side[max_y] = PortalFace._screen_space_x[v20];
+  }
+  //****************************************************************************************************************************************
   v22 = min_y;
   if ( min_y <= max_y )
   {
@@ -7024,7 +6993,7 @@
       v24 = v13;
       if ( v22 >= PortalFace._screen_space_y[v13] && v22 != max_y )
       {
-        v13 = v64 + v13;
+        v13 = direction2 + v13;
         if ( v13 < pNumVertices )
         {
           if ( v13 < 0 )
@@ -7043,7 +7012,7 @@
       v29 = v18;
       if ( v70 >= PortalFace._screen_space_y[v18] && v70 != max_y )
       {
-        v18 += v63;
+        v18 += direction1;
         if ( v18 < pNumVertices )
         {
           if ( v18 < 0 )
@@ -7169,16 +7138,8 @@
   BLVFace *pFace; // ebx@1
   int pNextVertices; // edx@11
   int t; // ST28_4@12
-  signed int v13; // edx@12
-  signed __int64 v14; // qtt@12
-  signed int v17; // eax@14
-  signed __int64 v18; // qtt@14
-  signed int v20; // edx@17
-  int v25; // eax@22
   int pScreenX; // eax@22
-  int v31; // eax@27
   int pScreenY; // eax@27
-  int v35; // ST30_4@30
   signed int left_num_vertices; // edi@31
   signed int right_num_vertices; // ebx@41
   signed int top_num_vertices; // edi@51
@@ -7189,12 +7150,10 @@
   int v65; // ecx@83
   signed int v71; // [sp+14h] [bp-14h]@75
   bool current_vertices_flag; // [sp+18h] [bp-10h]@9
-  int thisb; // [sp+18h] [bp-10h]@12
   int thisf; // [sp+18h] [bp-10h]@74
   signed int depth_num_vertices; // [sp+1Ch] [bp-Ch]@9
   int v80; // [sp+1Ch] [bp-Ch]@76
   bool next_vertices_flag; // [sp+20h] [bp-8h]@10
-  signed int v90; // [sp+24h] [bp-4h]@51
 
   pFace = &pIndoor->pFaces[uFaceID];
   memset(&PortalFace, 0, sizeof(stru367));
@@ -7241,8 +7200,6 @@
         &PortalFace._view_transformed_z[i + 3], &PortalFace._view_transformed_x[i + 3], &PortalFace._view_transformed_y[i + 3], 0);
     }
   }
-  //: 55681665, 55681665, 53050369, 47787777, 45156481, 45156481
-  //x: 0x0351 a281,0x0351 a281,0x0329 7c01,0x02d9 2f01,0x02b1 0881,0x02b1 0881
   //*****************************************************************************************************************************************
   //check vertices for the nearest plane(        )
   if ( pFace->uNumVertices <= 0 )
@@ -7287,11 +7244,8 @@
       {
         if ( next_vertices_flag )//    
         {
-          v13 = 524288 - PortalFace._view_transformed_z[i + 2];
-          LODWORD(v14) = v13 << 16;
-          HIDWORD(v14) = v13 >> 16;
           //t = near_clip - v0.z / v1.z - v0.z
-          t = v14 / PortalFace._view_transformed_z[i + 3] - PortalFace._view_transformed_z[i + 2];
+          t = fixpoint_div(524288 - PortalFace._view_transformed_z[i + 2], PortalFace._view_transformed_z[i + 3] - PortalFace._view_transformed_z[i + 2]);
           //New_x = (v1.x - v0.x)*t + v0.x
           PortalFace._view_transformed_x[depth_num_vertices] = ((unsigned __int64)((PortalFace._view_transformed_x[i + 3]
                                                            - PortalFace._view_transformed_x[i + 2]) * t) >> 16) + PortalFace._view_transformed_x[i + 2];
@@ -7303,11 +7257,8 @@
         }
         else//     
         {
-          v17 = 524288 - PortalFace._view_transformed_z[i + 3];
-          LODWORD(v18) = v17 << 16;
-          HIDWORD(v18) = v17 >> 16;
           //t = near_clip - v1.z / v0.z - v1.z
-          t = v18 / PortalFace._view_transformed_z[i + 2] - PortalFace._view_transformed_z[i + 3];
+          t = fixpoint_div(524288 - PortalFace._view_transformed_z[i + 3], PortalFace._view_transformed_z[i + 2] - PortalFace._view_transformed_z[i + 3]);
           //New_x = (v0.x - v1.x)*t + v1.x
           PortalFace._view_transformed_x[depth_num_vertices] = ((unsigned __int64)((PortalFace._view_transformed_x[i + 2]
                                                    - PortalFace._view_transformed_x[i + 3]) * t) >> 16) + PortalFace._view_transformed_x[i + 3];
@@ -7379,15 +7330,13 @@
     PortalFace._screen_space_x[i + 12] = pBLVRenderParams->uViewportCenterX - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenX) >> 16);
     PortalFace._screen_space_y[i + 12] = pBLVRenderParams->uViewportCenterY - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenY) >> 16);
   }
-  // -34, 4, 61, 83, 83, -34
-  //y 211, 152, 172, 216, 273, 293
   // :   ,       ,   ()
   //******************************************************************************************************************************************
   //check for left_clip plane(   )
   left_num_vertices = 0;
   PortalFace._screen_space_x[depth_num_vertices + 12] = PortalFace._screen_space_x[12];
   PortalFace._screen_space_y[depth_num_vertices + 12] = PortalFace._screen_space_y[12];
-  current_vertices_flag = PortalFace._screen_space_x[12] >= (signed int)pBLVRenderParams->uViewportX;
+  current_vertices_flag = PortalFace._screen_space_x[12] >= (signed int)pBLVRenderParams->uViewportX;//8.0
   if ( depth_num_vertices < 1 )
     return 0;
   for ( uint i = 1; i <= depth_num_vertices; ++i )
@@ -7398,22 +7347,20 @@
       if ( next_vertices_flag )
       {
         //t = left_clip - v0.x / v1.x - v0.x
-        t = (signed __int64)(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 11])
-                          / (PortalFace._screen_space_x[i + 12] - PortalFace._screen_space_x[i + 11]);
+        t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 11], PortalFace._screen_space_x[i + 12] - PortalFace._screen_space_x[i + 11]);
         //New_y = (v1.y - v0.y)*t + v0.y
-        PortalFace._screen_space_y[left_num_vertices + 9] = (signed int)(PortalFace._screen_space_y[i + 12]- PortalFace._screen_space_y[i + 11])
-                                                            * t + PortalFace._screen_space_y[i + 11];
+        PortalFace._screen_space_y[left_num_vertices + 9] = ((signed int)((PortalFace._screen_space_y[i + 12]- PortalFace._screen_space_y[i + 11])
+                                                            * t) >> 16) + PortalFace._screen_space_y[i + 11];
         //New_x = left_clip
         PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX;
       }
       else
       {
         //t = left_clip - v1.x / v0.x - v1.x
-        t = (signed __int64)(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 12])
-                          / (PortalFace._screen_space_x[i + 11] - PortalFace._screen_space_x[i + 12]);
+        t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 12], PortalFace._screen_space_x[i + 11] - PortalFace._screen_space_x[i + 12]);
         //New_y = (v0.y - v1.y)*t + v1.y
-        PortalFace._screen_space_y[left_num_vertices + 9] = (signed int)( PortalFace._screen_space_y[i + 11] - PortalFace._screen_space_y[i + 12])
-                                                            * t + PortalFace._screen_space_y[i + 12];
+        PortalFace._screen_space_y[left_num_vertices + 9] = ((signed int)(( PortalFace._screen_space_y[i + 11] - PortalFace._screen_space_y[i + 12])
+                                                            * t) >> 16) + PortalFace._screen_space_y[i + 12];
         //New_x = left_clip
         PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX;
       }
@@ -7432,7 +7379,7 @@
   right_num_vertices = 0;
   PortalFace._screen_space_x[left_num_vertices + 9] = PortalFace._screen_space_x[9];
   PortalFace._screen_space_y[left_num_vertices + 9] = PortalFace._screen_space_y[9];
-  current_vertices_flag = PortalFace._screen_space_x[9] <= (signed int)pBLVRenderParams->uViewportZ;
+  current_vertices_flag = PortalFace._screen_space_x[9] <= (signed int)pBLVRenderParams->uViewportZ;//468.0
   if (left_num_vertices < 1)
     return 0;
   for ( uint i = 1; i <= left_num_vertices; ++i )
@@ -7443,22 +7390,20 @@
       if ( next_vertices_flag )
       {
         //t = right_clip - v1.x / v0.x - v1.x
-        t = (signed __int64)(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 9])
-                          / (PortalFace._screen_space_x[i + 8] - PortalFace._screen_space_x[i + 9]);
+        t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 8], PortalFace._screen_space_x[i + 9] - PortalFace._screen_space_x[i + 8]);
         //New_y = (v0.y - v1.y)*t + v1.y
-        PortalFace._screen_space_y[right_num_vertices + 6] = (signed int)(PortalFace._screen_space_y[i + 8] - PortalFace._screen_space_y[i + 9])
-                                                           * t + PortalFace._screen_space_y[i + 9];
+        PortalFace._screen_space_y[right_num_vertices + 6] = ((signed int)((PortalFace._screen_space_y[i + 9] - PortalFace._screen_space_y[i + 8])
+                                                           * t) >> 16) + PortalFace._screen_space_y[i + 8];
         //New_x = right_clip
         PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ;
       }
       else
       {
         //t = right_clip - v0.x / v1.x - v0.x
-        t = (signed __int64)(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 8])
-                          / (PortalFace._screen_space_x[i + 9] - PortalFace._screen_space_x[i + 8]);
+        t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 9], PortalFace._screen_space_x[i + 8] - PortalFace._screen_space_x[i + 9]);
         //New_y = (v1.y - v0.y)*t + v0.y
-        PortalFace._screen_space_y[right_num_vertices + 6] = (signed int)(PortalFace._screen_space_y[i + 9] - PortalFace._screen_space_y[i + 8])
-                                                           * t + PortalFace._screen_space_y[i + 8];
+        PortalFace._screen_space_y[right_num_vertices + 6] = ((signed int)((PortalFace._screen_space_y[i + 8] - PortalFace._screen_space_y[i + 9])
+                                                           * t) >> 16) + PortalFace._screen_space_y[i + 9];
         //New_x = right_clip
         PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ;
       }
@@ -7478,7 +7423,7 @@
   PortalFace._screen_space_x[right_num_vertices + 6] = PortalFace._screen_space_x[6];
   PortalFace._screen_space_y[right_num_vertices + 6] = PortalFace._screen_space_y[6];
 
-  current_vertices_flag = PortalFace._screen_space_y[6] >= (signed int)pBLVRenderParams->uViewportY;
+  current_vertices_flag = PortalFace._screen_space_y[6] >= (signed int)pBLVRenderParams->uViewportY;//8.0
   if ( right_num_vertices < 1 )
     return 0;
   for ( uint i = 1; i <= right_num_vertices; ++i )
@@ -7488,18 +7433,16 @@
     {
       if ( next_vertices_flag )
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportY  - PortalFace._screen_space_y[i + 5])
-                          / (PortalFace._screen_space_y[i + 6] - PortalFace._screen_space_y[i + 5]);
-        PortalFace._screen_space_x[top_num_vertices + 3] = (signed int)(PortalFace._screen_space_x[i + 6] - PortalFace._screen_space_x[i + 5])
-            * t + PortalFace._screen_space_x[i + 5];
+        t = fixpoint_div(pBLVRenderParams->uViewportY  - PortalFace._screen_space_y[i + 5], PortalFace._screen_space_y[i + 6] - PortalFace._screen_space_y[i + 5]);
+        PortalFace._screen_space_x[top_num_vertices + 3] = ((signed int)((PortalFace._screen_space_x[i + 6] - PortalFace._screen_space_x[i + 5])
+            * t) >> 16) + PortalFace._screen_space_x[i + 5];
         PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY;
       }
       else
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 6])
-                          / (PortalFace._screen_space_y[i + 5] - PortalFace._screen_space_y[i + 6]);
-        PortalFace._screen_space_x[top_num_vertices + 3] = (signed int)(PortalFace._screen_space_x[i + 5]- PortalFace._screen_space_x[i + 6])
-            * t + PortalFace._screen_space_x[i + 6];
+        t = fixpoint_div(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 6], PortalFace._screen_space_y[i + 5] - PortalFace._screen_space_y[i + 6]);
+        PortalFace._screen_space_x[top_num_vertices + 3] = ((signed int)((PortalFace._screen_space_x[i + 5]- PortalFace._screen_space_x[i + 6])
+            * t) >> 16) + PortalFace._screen_space_x[i + 6];
         PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY;
       }
       top_num_vertices++;
@@ -7517,7 +7460,7 @@
   bottom_num_vertices = 0;
   PortalFace._screen_space_x[top_num_vertices + 3] = PortalFace._screen_space_x[3];
   PortalFace._screen_space_y[top_num_vertices + 3] = PortalFace._screen_space_y[3];
-  current_vertices_flag = PortalFace._screen_space_y[3] <= (signed int)pBLVRenderParams->uViewportW;
+  current_vertices_flag = PortalFace._screen_space_y[3] <= (signed int)pBLVRenderParams->uViewportW;//351.0
   if ( top_num_vertices < 1 )
     return 0;
   for ( uint i =1; i <= top_num_vertices; ++i )
@@ -7527,18 +7470,16 @@
     {
       if ( next_vertices_flag )
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 3])
-                          / (PortalFace._screen_space_y[i + 2] - PortalFace._screen_space_y[i + 3]);
-        PortalFace._screen_space_x[bottom_num_vertices] = (signed int)(PortalFace._screen_space_x[i + 2] - PortalFace._screen_space_x[i + 3])
-            * t + PortalFace._screen_space_x[i + 3];
+        t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 2], PortalFace._screen_space_y[i + 3] - PortalFace._screen_space_y[i + 2]);
+        PortalFace._screen_space_x[bottom_num_vertices] = ((signed int)((PortalFace._screen_space_x[i + 3] - PortalFace._screen_space_x[i + 2])
+            * t) >> 16) + PortalFace._screen_space_x[i + 2];
         PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW;
       }
       else
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 2])
-                          / (PortalFace._screen_space_y[i + 3] - PortalFace._screen_space_y[i + 2]);
-        PortalFace._screen_space_x[bottom_num_vertices] = (signed int)(PortalFace._screen_space_x[i + 3] - PortalFace._screen_space_x[i + 2])
-            * t + PortalFace._screen_space_x[i + 2];
+        t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 3], PortalFace._screen_space_y[i + 2] - PortalFace._screen_space_y[i + 3]);
+        PortalFace._screen_space_x[bottom_num_vertices] = ((signed int)((PortalFace._screen_space_x[i + 2] - PortalFace._screen_space_x[i + 3])
+            * t) >> 16) + PortalFace._screen_space_x[i + 3];
         PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW;
       }
       bottom_num_vertices++;
@@ -7551,8 +7492,6 @@
     }
     current_vertices_flag = next_vertices_flag;
   }
-  //out_x: 83,8,8,61,83
-  //out_y: 273,293,152,172,216
 //***************************************************************************************************************************************
 
   if ( !bottom_num_vertices )
--- a/IndoorCameraD3D.cpp	Mon Jul 15 08:20:28 2013 +0400
+++ b/IndoorCameraD3D.cpp	Mon Jul 15 17:09:48 2013 +0600
@@ -136,17 +136,17 @@
   int a2b; // [sp+18h] [bp+Ch]@5
   int a3a; // [sp+1Ch] [bp+10h]@5
 
-  to_x = (x - pBLVRenderParams->vPartyPos.x) << 16;
-  to_y = (y - pBLVRenderParams->vPartyPos.y) << 16;
+  to_x = x - pBLVRenderParams->vPartyPos.x;
+  to_y = y - pBLVRenderParams->vPartyPos.y;
   if ( pBLVRenderParams->sPartyRotX )
   {
     to_z = (z - pBLVRenderParams->vPartyPos.z) << 16;
     if ( pRenderer->pRenderD3D )
     {
-      v14 = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
-          + ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
-      v9 = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
-         - ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
+      v14 = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY)
+          + (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY);
+      v9 = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY)
+         - (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY);
     }
     else
     {
@@ -169,10 +169,10 @@
     if ( pRenderer->pRenderD3D )
     {
       v10 = pOutX;
-      *pOutX = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY) >> 16)
-             + ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY) >> 16);
-      *pOutZ = ((unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY) >> 16)
-             - ((unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY) >> 16);
+      *pOutX = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sCosineY)
+             + (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sSineY);
+      *pOutZ = (unsigned __int64)(to_x * (signed __int64)pBLVRenderParams->sSineY)
+             - (unsigned __int64)(to_y * (signed __int64)pBLVRenderParams->sCosineY);
     }
     else
     {
--- a/mm7_4.cpp	Mon Jul 15 08:20:28 2013 +0400
+++ b/mm7_4.cpp	Mon Jul 15 17:09:48 2013 +0600
@@ -3497,7 +3497,7 @@
         result = GetPortalScreenCoord(sFaceID);
         if ( result )
         {
-          result = sub_424829(result, &stru_F8A590, pBLVRenderParams->field_7C, v2);
+          result = PortalFrustrum(result, &stru_F8A590, pBLVRenderParams->field_7C, v2);
           if ( result )
           {
             result = (int)v3->GetTexture();
@@ -3962,7 +3962,7 @@
       v59 = GetPortalScreenCoord(uFaceID);
       v3 = v59;
     }
-    if ( v3 && (pRenderer->pRenderD3D || sub_424829(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1)) )
+    if ( v3 && (pRenderer->pRenderD3D || PortalFrustrum(v3, &stru_F8A590, pBLVRenderParams->field_7C, v1)) )
     {
       v4 = v2->GetTexture();
       v5 = 0;
--- a/mm7_data.h	Mon Jul 15 08:20:28 2013 +0400
+++ b/mm7_data.h	Mon Jul 15 17:09:48 2013 +0600
@@ -1151,7 +1151,7 @@
 void __cdecl sub_423B4A();
 int __fastcall GetPortalScreenCoord(unsigned int uFaceID);
 signed int __fastcall sub_424579(int uFaceID, struct stru320 *a2);
-bool sub_424829(int pNumVertices, struct BspRenderer_stru2 *a2, struct BspRenderer_stru2 *a3, int uFaceID);
+bool PortalFrustrum(int pNumVertices, struct BspRenderer_stru2 *a2, struct BspRenderer_stru2 *a3, int uFaceID);
 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