diff Vis.cpp @ 1322:65d301bce717

some vis clean
author Gloval
date Mon, 01 Jul 2013 00:00:49 +0400
parents 0aeac0b9ca30
children 613c77e51e38
line wrap: on
line diff
--- a/Vis.cpp	Fri Jun 28 16:51:01 2013 +0600
+++ b/Vis.cpp	Mon Jul 01 00:00:49 2013 +0400
@@ -133,7 +133,8 @@
     {
       if (v13 == -1)
         v13 = i;
-      else  if ((unsigned int)pBillboardRenderList[billboard->uParentBillboardID].sZValue < pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue)
+      else  if ((unsigned int)pBillboardRenderList[billboard->uParentBillboardID].sZValue < 
+                  pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue)
         v13 = i;
     }
   }
@@ -421,9 +422,9 @@
   
   v8.object_type = VisObjectType_Sprite;
   v8.object_id = object_id;
-  v8.field_8 = a6;
-  v8.field_C = a5;
-  v8.field_10 = a4;
+  v8.at_ai_state = a6;
+  v8.no_at_ai_state = a5;
+  v8.select_flags = a4;
   Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers = 0;
   PickBillboards_Keyboard(pick_depth, &Vis_static_sub_4C1944_stru_F8BDE8, &v8);
   Vis_static_sub_4C1944_stru_F8BDE8.create_object_pointers(Vis_SelectionList::Unique);
@@ -731,7 +732,9 @@
 }
 
 //----- (004C1EE5) --------------------------------------------------------
-void Vis::BLV_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a, __int16 *intersect_face_vertex_coords_list_b, Vec3_short_ *IntersectPoint, BLVFace *pFace)
+void Vis::BLV_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a,
+                                                                  __int16 *intersect_face_vertex_coords_list_b, 
+                                                                  Vec3_short_ *IntersectPoint, BLVFace *pFace)
 {
   if (pFace->uAttributes & FACE_XY_PLANE)
   {
@@ -779,7 +782,9 @@
 }
 
 //----- (004C2186) --------------------------------------------------------
-void Vis::ODM_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a, __int16 *intersect_face_vertex_coords_list_b, Vec3_short_ *IntersectPoint, BLVFace *pFace, unsigned int uModelID)
+void Vis::ODM_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a, 
+                                                                  __int16 *intersect_face_vertex_coords_list_b, 
+                                                                    Vec3_short_ *IntersectPoint, BLVFace *pFace, unsigned int uModelID)
 {
   if (pFace->uAttributes & FACE_XY_PLANE)
   {
@@ -894,8 +899,8 @@
   v11[1].vWorldPosition.y = (double)pIndoorCamera->pos.y;
   v11[1].vWorldPosition.z = (double)pIndoorCamera->pos.z;
 
-  memcpy(pRay, &v11[1], 0x30u);
-  memcpy(&pRay[1], v11, sizeof(pRay[1]));
+  memcpy(pRay, &v11[1], sizeof(RenderVertexSoft));
+  memcpy(&pRay[1], &v11[0], sizeof(RenderVertexSoft));
 }
 
 //----- (004C2551) --------------------------------------------------------
@@ -915,7 +920,7 @@
         return &this->object_pool[i];
     }
   }
-  return false;
+  return nullptr;
   /*v4 = 0;
   if ( this->uNumPointers <= 0 )
     return false;
@@ -973,58 +978,62 @@
 }
 
 //----- (004C264A) --------------------------------------------------------
-void Vis::sort_object_pointers(Vis_ObjectInfo **pPointers, int left, int right)
-{
-  int v4; // edx@1
-  int v5; // ebx@1
-  int v6; // esi@2
-  signed int i; // ecx@2
-  int v8; // eax@3
-  int v9; // ebx@4
-  int v10; // ebx@6
-  Vis_ObjectInfo *v11; // eax@7
+void Vis::sort_object_pointers( Vis_ObjectInfo **pPointers, int start, int end )
+    {
+  int sort_start; // edx@1
+  int forward_sort_index; // esi@2
+  signed int backward_sort_index; // ecx@2
+  unsigned int last_z_val; // eax@3
+  unsigned int more_lz_val; // ebx@4
+  unsigned int less_lz_val; // ebx@6
+  Vis_ObjectInfo *temp_pointer; // eax@7
   Vis_ObjectInfo *a3a; // [sp+14h] [bp+Ch]@2
 
-  v4 = left;
-  v5 = right;
-  if ( right > left )
+  sort_start = start;
+
+  if ( end > start )
   {
     do
     {
-      v6 = v4 - 1;
-      a3a = pPointers[v5];
-      for ( i = v5; ; pPointers[i] = v11 )
+      forward_sort_index = sort_start - 1;
+      backward_sort_index = end;
+      do
       {
-        v8 = a3a->sZValue;
-        LOWORD(v8) = 0;
+        last_z_val = pPointers[end]->sZValue&0xFFFF0000;
         do
         {
-          ++v6;
-          v9 = pPointers[v6]->sZValue;
-          LOWORD(v9) = 0;
+          ++forward_sort_index;
+          more_lz_val = pPointers[forward_sort_index]->sZValue&0xFFFF0000;
         }
-        while ( v9 < (unsigned int)v8 );
+        while ( more_lz_val < last_z_val );
+
         do
         {
-          if ( i < 1 )
+          if ( backward_sort_index < 1 )
             break;
-          --i;
-          v10 = pPointers[i]->sZValue;
-          LOWORD(v10) = 0;
+          --backward_sort_index;
+          less_lz_val = pPointers[backward_sort_index]->sZValue&0xFFFF0000;
         }
-        while ( v10 > (unsigned int)v8 );
-        v11 = pPointers[v6];
-        if ( v6 >= i )
-          break;
-        pPointers[v6] = pPointers[i];
-      }
-      v5 = right;
-      pPointers[v6] = pPointers[right];
-      pPointers[right] = v11;
-      sort_object_pointers(pPointers, v4, v6 - 1);
-      v4 = v6 + 1;
+        while ( less_lz_val > last_z_val );
+
+        temp_pointer = pPointers[forward_sort_index];
+        if ( forward_sort_index >= backward_sort_index )
+            {
+            pPointers[forward_sort_index] = pPointers[end];
+            pPointers[end] = temp_pointer;
+            }
+        else
+            {
+            pPointers[forward_sort_index] = pPointers[backward_sort_index];
+            pPointers[backward_sort_index] = temp_pointer;
+            }
+       
+      } while ( forward_sort_index < backward_sort_index );
+
+      sort_object_pointers(pPointers, sort_start, forward_sort_index - 1);
+      sort_start = forward_sort_index + 1;
     }
-    while ( right > v6 + 1 );
+    while ( end > forward_sort_index + 1 );
   }
 }
 
@@ -1403,7 +1412,7 @@
 
     case VisObjectType_Sprite:
     {
-      v5 = filter->field_10;
+      v5 = filter->select_flags;
       int object_idx = PID_ID(pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid);
       int object_type = PID_TYPE(pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid);
       if ( v5 & 2 )
@@ -1436,11 +1445,11 @@
 
         v10 = &pActors[object_idx];
         int result = 1 << LOBYTE(v10->uAIState);
-        if ( result & filter->field_C
-            || !(result & filter->field_8)
+        if ( result & filter->no_at_ai_state
+            || !(result & filter->at_ai_state)
             || v5 & 8 && (result = MonsterStats::BelongsToSupertype(v10->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD)) == 0 )
           return false;
-        if ( !(filter->field_10 & 1) )
+        if ( !(filter->select_flags & 1) )
           return true;
 
         result = v10->GetActorsRelation(nullptr);
@@ -1472,9 +1481,9 @@
 
       if (filter->object_id != OBJECT_BLVDoor)
         return true;
-      if (no_event || face_attrib & filter->field_C)
+      if (no_event || face_attrib & filter->no_at_ai_state)
         return false;
-      return (face_attrib & filter->field_8) != 0;
+      return (face_attrib & filter->at_ai_state) != 0;
     }
 
     default:
@@ -1515,31 +1524,32 @@
   struct RenderVertexSoft pPickingRay[2];
   //int v31; // [sp+20h] [bp-DCh]@5
   struct RenderVertexSoft local_80[2];
-  //int v32; // [sp+80h] [bp-7Ch]@22
-  float v33; // [sp+E0h] [bp-1Ch]@33
-  float v34; // [sp+E4h] [bp-18h]@32
-  int v35; // [sp+E8h] [bp-14h]@5
-  int v36; // [sp+ECh] [bp-10h]@5
+
+  float  test_x;
+  float  test_y;
+
+  float  t1_x;
+  float  t1_y;
+  float  t2_x;
+  float  t2_y;
+  float  swap_temp;
   int v37; // [sp+F0h] [bp-Ch]@5
-  float v38; // [sp+F4h] [bp-8h]@17
-  //void *v39; // [sp+F8h] [bp-4h]@1
+
   signed int v40; // [sp+108h] [bp+Ch]@17
-  float v41; // [sp+108h] [bp+Ch]@32
+
 
   static Vis_SelectionList Vis_static_stru_F91E10;
   Vis_static_stru_F91E10.uNumPointers = 0;
   v3 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].uParentBillboardID;
   if (v3 == -1)
     return false;
+
   if (pBillboardRenderList[v3].GetFloatZ() > fDepth)
-  {
-LABEL_49:
     return false;
-  }
+
 
-    v37 = pBillboardRenderList[v3].sZValue & 0xFFFF0000;
-    GetPolygonCenter(pRenderer->pBillboardRenderListD3D[v3].pQuards, 4, (float *)&v35, (float *)&v36);
-    CastPickRay(pPickingRay, *(float *)&v35, *(float *)&v36, fDepth);
+    GetPolygonCenter(pRenderer->pBillboardRenderListD3D[v3].pQuards, 4, &test_x, &test_y);
+    CastPickRay(pPickingRay, test_x, test_y, fDepth);
     if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
       PickIndoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter);
     else
@@ -1549,95 +1559,82 @@
     if (Vis_static_stru_F91E10.uNumPointers)
     {
        if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z)
-         return 1;
+         return true;
     }
-    else if ((double)(pViewport->uScreen_TL_X) <= *(float *)&v35 &&
-             (double)pViewport->uScreen_BR_X >= *(float *)&v35 &&
-             (double)pViewport->uScreen_TL_Y <= *(float *)&v36 &&
-             (double)pViewport->uScreen_BR_Y >= *(float *)&v36)
-      return 1;
-      v40 = 0;
-      v10 = (int)&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y;
-      LODWORD(v38) = (int)&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y;
-      while ( 1 )
-      {
-        v12 = *(float *)(v10 - 4);
-        v11 = *(float *)v10;
-        v13 = *(float *)(v10 - 4);
-        Vis_static_stru_F91E10.uNumPointers = 0;
-        if ( v13 >= (double)(pViewport->uScreen_TL_X))
+    else if ((double)(pViewport->uScreen_TL_X) <= test_x &&
+             (double)pViewport->uScreen_BR_X >= test_x &&
+             (double)pViewport->uScreen_TL_Y <= test_y &&
+             (double)pViewport->uScreen_BR_Y >= test_y)
+      return true;
+
+    for (v40 = 0; v40 < 4; ++v40)
         {
-          if ( v12 <= (double)pViewport->uScreen_BR_X )
-          {
-            if ( v11 >= (double)pViewport->uScreen_TL_Y )
+        test_x=pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[v40].pos.x;
+        test_y=  pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[v40].pos.y;
+        if ((double)(pViewport->uScreen_TL_X) <= test_x &&
+            (double)pViewport->uScreen_BR_X >= test_x &&
+            (double)pViewport->uScreen_TL_Y <= test_y &&
+            (double)pViewport->uScreen_BR_Y >= test_y)
             {
-              if ( v11 <= (double)pViewport->uScreen_BR_Y )
-              {
-                v14 = v11;
-                v15 = v12;
-                CastPickRay(local_80, SLODWORD(v15), v14, fDepth);
-                if ( uCurrentlyLoadedLevelType == 1 )
-                  PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter);
-                else
-                  PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false);
-                Vis_static_stru_F91E10.create_object_pointers();
-                sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1);
-                if ( !Vis_static_stru_F91E10.uNumPointers )
-                  break;
-                else
-                {
-                //v18 = Vis_static_stru_F91E10.uNumPointers <= 0 ? 0 : (int);
-                //v19 = *(_DWORD *)(v18 + 4);
-                //LOWORD(v19) = 0;
-                if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z)
-                  break;
-                }
-              }
+            CastPickRay(local_80, test_x, test_y, fDepth);
+            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+                PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter);
+            else
+                PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false);
+            Vis_static_stru_F91E10.create_object_pointers();
+            sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1);
+            if ( !Vis_static_stru_F91E10.uNumPointers )
+                return true;
+            if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z)
+                return true;
             }
-          }
+
         }
-        ++v40;
-        v10 = LODWORD(v38) + 32;
-        LODWORD(v38) += 32;
+  
         if ( v40 >= 4 )
         {
-          if ( uCurrentlyLoadedLevelType != 2 )
+          if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
             return false;
-          v21 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.x;
-          v20 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[3].pos.x;
-          v22 = *(int *)(&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y);
-          v34 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[3].pos.x;
-          LODWORD(v38) = v22;
-          v41 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[1].pos.y;
-          if ( v21 > v20 )
+          t1_x = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.x;
+          t2_x = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[3].pos.x;
+
+          t1_y = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y;
+          t2_y = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[1].pos.y;
+          if ( t1_x > t2_x )
           {
-            v33 = v21;
-            v21 = v34;
-            v20 = v33;
+            swap_temp = t1_x;
+            t1_x = t2_x;
+            t2_x = swap_temp;
           }
-          if ( v38 > (double)v41 )
-            v41 = v38;
+          if ( t1_y > t2_y )
+            test_y = t1_y;
+          else
+            test_y = t2_y;
+
           Vis_static_stru_F91E10.uNumPointers = 0;
-          v23 = (v20 - v21) * 0.5;
-          if ( v23 < (double)(pViewport->uScreen_TL_X)
-            || v23 > (double)pViewport->uScreen_BR_X
-            || (double)pViewport->uScreen_TL_Y > v41
-            || (double)pViewport->uScreen_BR_Y < v41
-            || ((v25 = v23, CastPickRay(local_80, SLODWORD(v25), v41, fDepth), uCurrentlyLoadedLevelType != 1) ? 
-             (PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false)) : 
-             (PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter)),
-             (Vis_static_stru_F91E10.create_object_pointers(),
-              sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1),
-              Vis_static_stru_F91E10.uNumPointers)
-             && (Vis_static_stru_F91E10.uNumPointers <= 0 ? (v28 = 0) : (v28 = (int)Vis_static_stru_F91E10.object_pointers),
-                 v29 = *(_DWORD *)(v28 + 4),
-                 LOWORD(v29) = 0,
-                 v29 <= v37)) )
-            return false;
-          break;
-        }
+
+          test_x = (t2_x - t1_x) * 0.5;
+          if ((double)(pViewport->uScreen_TL_X) <= test_x &&
+              (double)pViewport->uScreen_BR_X >= test_x &&
+              (double)pViewport->uScreen_TL_Y <= test_y &&
+              (double)pViewport->uScreen_BR_Y >= test_y)
+              {
+              CastPickRay(local_80, test_x, test_y, fDepth);
+              if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+                  PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter);
+              else
+                  PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false);
+              Vis_static_stru_F91E10.create_object_pointers();
+              sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1);
+              if ( !Vis_static_stru_F91E10.uNumPointers )
+                  return true;
+              if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z)
+                  return true;
+
+              }
+        
       }
-  return true;
+  return false;
 }
 // F93E18: using guessed type char static_byte_F93E18_init;