diff stru10.cpp @ 795:472ca68386d4

more stru10 & stru9
author Nomad
date Mon, 25 Mar 2013 14:23:40 +0200
parents 4a00901e063c
children 39eaa6b00141
line wrap: on
line diff
--- a/stru10.cpp	Mon Mar 25 11:58:38 2013 +0200
+++ b/stru10.cpp	Mon Mar 25 14:23:40 2013 +0200
@@ -10,412 +10,103 @@
 
 
 
+int _49CE9E_sub0_x(RenderVertexSoft *pVertices, unsigned int uNumVertices, float test_val)
+{
+  float max_val = FLT_MAX;
+  int   idx = -1;
+
+  float temp_val;
+  for (uint i = 0; i < uNumVertices; ++i)
+  {
+    if (pVertices[i].vWorldPosition.x <= test_val)
+      temp_val = test_val - pVertices[i].vWorldPosition.x;
+    else
+      temp_val = pVertices[i].vWorldPosition.x - test_val;
+
+    if (temp_val < max_val)
+    {
+      max_val = temp_val;
+      idx = i;
+    }
+  }
+  return idx;
+}
+
+
+int _49CE9E_sub0_y(RenderVertexSoft *pVertices, unsigned int uNumVertices, float test_val)
+{
+  float max_val = FLT_MAX;
+  int   idx = -1;
+
+  float temp_val;
+  for (uint i = 0; i < uNumVertices; ++i)
+  {
+    if (pVertices[i].vWorldPosition.y <= test_val)
+      temp_val = test_val - pVertices[i].vWorldPosition.y;
+    else
+      temp_val = pVertices[i].vWorldPosition.y - test_val;
+
+    if (temp_val < max_val)
+    {
+      max_val = temp_val;
+      idx = i;
+    }
+  }
+  return idx;
+}
+
+
+int _49CE9E_sub0_z(RenderVertexSoft *pVertices, unsigned int uNumVertices, float test_val)
+{
+  float max_val = FLT_MAX;
+  int   idx = -1;
+
+  float temp_val;
+  for (uint i = 0; i < uNumVertices; ++i)
+  {
+    if (pVertices[i].vWorldPosition.z <= test_val)
+      temp_val = test_val - pVertices[i].vWorldPosition.z;
+    else
+      temp_val = pVertices[i].vWorldPosition.z - test_val;
+
+    if (temp_val < max_val)
+    {
+      max_val = temp_val;
+      idx = i;
+    }
+  }
+  return idx;
+}
 
 //----- (0049CE9E) --------------------------------------------------------
-void stru10::_49CE9E(BLVFace *pFace, RenderVertexSoft *a2, signed int a3, RenderVertexSoft *a4)
+void stru10::_49CE9E(BLVFace *pFace, RenderVertexSoft *pVertices, unsigned int uNumVertices, RenderVertexSoft *pOutLimits)
 {
-  char *v5; // eax@1
-  signed int v6; // edx@1
-  unsigned int v7; // eax@3
-  signed int v8; // ecx@11
-  signed int v9; // esi@11
-  RenderVertexSoft *v10; // edx@12
-  double v11; // st6@14
-  RenderVertexSoft *v12; // edx@19
-  signed int v13; // ecx@19
-  signed int v14; // esi@19
-  RenderVertexSoft *v15; // edi@20
-  double v16; // st6@22
-  signed int v17; // ecx@27
-  signed int v18; // edi@27
-  char *v19; // esi@28
-  double v20; // st6@30
-  signed int v21; // ecx@35
-  signed int v22; // edi@35
-  char *v23; // esi@36
-  double v24; // st7@38
-  signed int v25; // ecx@45
-  signed int v26; // esi@45
-  RenderVertexSoft *v27; // edx@46
-  double v28; // st6@48
-  signed int v29; // ecx@53
-  signed int v30; // esi@53
-  RenderVertexSoft *v31; // edi@54
-  double v32; // st6@56
-  signed int v33; // ecx@61
-  signed int v34; // edi@61
-  char *v35; // esi@62
-  double v36; // st6@64
-  signed int v37; // edi@69
-  char *v38; // esi@70
-  double v39; // st7@72
-  RenderVertexSoft *v40; // esi@77
-  signed int v41; // ecx@79
-  signed int v42; // esi@79
-  char *v43; // edx@80
-  double v44; // st6@82
-  RenderVertexSoft *v45; // eax@87
-  signed int v46; // ecx@87
-  signed int v47; // edi@87
-  char *v48; // esi@88
-  double v49; // st6@90
-  signed int v50; // ecx@96
-  signed int v51; // edi@96
-  char *v52; // esi@97
-  double v53; // st6@99
-  signed int v54; // ecx@105
-  signed int v55; // edi@105
-  char *v56; // esi@106
-  double v57; // st7@108
-  RenderVertexSoft a2a[64]; // [sp+0h] [bp-C18h]@1
-  float v59; // [sp+C00h] [bp-18h]@4
-  float v60; // [sp+C04h] [bp-14h]@9
-  float v61; // [sp+C08h] [bp-10h]@4
-  float v62; // [sp+C0Ch] [bp-Ch]@9
-  float v63; // [sp+C10h] [bp-8h]@4
-  float v64; // [sp+C14h] [bp-4h]@4
-  float a1a; // [sp+C20h] [bp+8h]@11
-  float a1b; // [sp+C20h] [bp+8h]@19
-  float a1c; // [sp+C20h] [bp+8h]@27
-  float a1d; // [sp+C20h] [bp+8h]@35
-  float a1e; // [sp+C20h] [bp+8h]@45
-  float a1f; // [sp+C20h] [bp+8h]@53
-  float a1g; // [sp+C20h] [bp+8h]@61
-  float a1h; // [sp+C20h] [bp+8h]@69
-  float a1i; // [sp+C20h] [bp+8h]@79
-  float a1j; // [sp+C20h] [bp+8h]@87
-  float a1k; // [sp+C20h] [bp+8h]@96
-  float a1l; // [sp+C20h] [bp+8h]@105
+  assert(sizeof(RenderVertexSoft) == 0x30);
+  
+  RenderVertexSoft pLimits[64];
+  stru10::CalcPolygonLimits(pFace, pLimits);
 
-  v5 = (char *)&a2a[0].flt_2C;
-  v6 = 64;
-  do
-  {
-    *(float *)v5 = 0.0;
-    v5 += 48;
-    --v6;
-  }
-  while ( v6 );
-  stru10::CalcPolygonLimits(pFace, a2a);
-  v7 = pFace->uAttributes;
-  if ( v7 & 0x100 )
-  {
-    v63 = a2a[0].vWorldPosition.x;
-    v59 = a2a[2].vWorldPosition.x;
-    v61 = a2a[1].vWorldPosition.y;
-    v64 = a2a[3].vWorldPosition.y;
-    goto LABEL_10;
-  }
-  if ( v7 & 0x200 )
-  {
-    v63 = a2a[0].vWorldPosition.x;
-    v59 = a2a[2].vWorldPosition.x;
-  }
-  else
-  {
-    if ( !(v7 & 0x400) )
-      goto LABEL_10;
-    v61 = a2a[0].vWorldPosition.y;
-    v64 = a2a[2].vWorldPosition.y;
-  }
-  v62 = a2a[1].vWorldPosition.z;
-  v60 = a2a[3].vWorldPosition.z;
-LABEL_10:
-  if ( v7 & 0x100 )
+  if (pFace->uAttributes & FACE_XY_PLANE)
   {
-    v8 = -1;
-    a1a = 3.4028235e38;
-    v9 = 0;
-    if ( a3 > 0 )
-    {
-      v10 = a2;
-      do
-      {
-        if ( v10->vWorldPosition.x <= (double)v63 )
-          v11 = v63 - v10->vWorldPosition.x;
-        else
-          v11 = v10->vWorldPosition.x - v63;
-        if ( v11 < a1a )
-        {
-          a1a = v11;
-          v8 = v9;
-        }
-        ++v9;
-        ++v10;
-      }
-      while ( v9 < a3 );
-    }
-    v12 = a4;
-    a1b = 3.4028235e38;
-    memcpy(a4, &a2[v8], 0x30u);
-    v13 = -1;
-    v14 = 0;
-    if ( a3 > 0 )
-    {
-      v15 = a2;
-      do
-      {
-        if ( v15->vWorldPosition.x <= (double)v59 )
-          v16 = v59 - v15->vWorldPosition.x;
-        else
-          v16 = v15->vWorldPosition.x - v59;
-        if ( v16 < a1b )
-        {
-          a1b = v16;
-          v13 = v14;
-        }
-        ++v14;
-        ++v15;
-      }
-      while ( v14 < a3 );
-    }
-    a1c = 3.4028235e38;
-    memcpy(&a4[2], &a2[v13], sizeof(a4[2]));
-    v17 = -1;
-    v18 = 0;
-    if ( a3 > 0 )
-    {
-      v19 = (char *)&a2->vWorldPosition.y;
-      do
-      {
-        if ( *(float *)v19 <= (double)v61 )
-          v20 = v61 - *(float *)v19;
-        else
-          v20 = *(float *)v19 - v61;
-        if ( v20 < a1c )
-        {
-          a1c = v20;
-          v17 = v18;
-        }
-        ++v18;
-        v19 += 48;
-      }
-      while ( v18 < a3 );
-    }
-    a1d = 3.4028235e38;
-    memcpy(&a4[1], &a2[v17], sizeof(a4[1]));
-    v21 = -1;
-    v22 = 0;
-    if ( a3 > 0 )
-    {
-      v23 = (char *)&a2->vWorldPosition.y;
-      do
-      {
-        if ( *(float *)v23 <= (double)v64 )
-          v24 = v64 - *(float *)v23;
-        else
-          v24 = *(float *)v23 - v64;
-        if ( v24 < a1d )
-        {
-          a1d = v24;
-          v21 = v22;
-        }
-        ++v22;
-        v23 += 48;
-      }
-      while ( v22 < a3 );
-    }
-LABEL_77:
-    v40 = &a2[v21];
-    goto LABEL_115;
+    memcpy(&pOutLimits[0], &pVertices[_49CE9E_sub0_x(pVertices, uNumVertices, pLimits[0].vWorldPosition.x)], 0x30);
+    memcpy(&pOutLimits[2], &pVertices[_49CE9E_sub0_x(pVertices, uNumVertices, pLimits[2].vWorldPosition.x)], 0x30);
+    memcpy(&pOutLimits[1], &pVertices[_49CE9E_sub0_y(pVertices, uNumVertices, pLimits[1].vWorldPosition.y)], 0x30);
+    memcpy(&pOutLimits[3], &pVertices[_49CE9E_sub0_y(pVertices, uNumVertices, pLimits[3].vWorldPosition.y)], 0x30);
   }
-  if ( v7 & 0x200 )
+  else if (pFace->uAttributes & FACE_XZ_PLANE)
+  {    
+    memcpy(&pOutLimits[0], &pVertices[_49CE9E_sub0_x(pVertices, uNumVertices, pLimits[0].vWorldPosition.x)], 0x30);
+    memcpy(&pOutLimits[2], &pVertices[_49CE9E_sub0_x(pVertices, uNumVertices, pLimits[2].vWorldPosition.x)], 0x30);
+    memcpy(&pOutLimits[1], &pVertices[_49CE9E_sub0_z(pVertices, uNumVertices, pLimits[1].vWorldPosition.z)], 0x30);
+    memcpy(&pOutLimits[3], &pVertices[_49CE9E_sub0_z(pVertices, uNumVertices, pLimits[3].vWorldPosition.z)], 0x30);
+  }
+  else if (pFace->uAttributes & FACE_YZ_PLANE)
   {
-    v25 = -1;
-    a1e = 3.4028235e38;
-    v26 = 0;
-    if ( a3 > 0 )
-    {
-      v27 = a2;
-      do
-      {
-        if ( v27->vWorldPosition.x <= (double)v63 )
-          v28 = v63 - v27->vWorldPosition.x;
-        else
-          v28 = v27->vWorldPosition.x - v63;
-        if ( v28 < a1e )
-        {
-          a1e = v28;
-          v25 = v26;
-        }
-        ++v26;
-        ++v27;
-      }
-      while ( v26 < a3 );
-    }
-    v12 = a4;
-    a1f = 3.4028235e38;
-    memcpy(a4, &a2[v25], 0x30u);
-    v29 = -1;
-    v30 = 0;
-    if ( a3 > 0 )
-    {
-      v31 = a2;
-      do
-      {
-        if ( v31->vWorldPosition.x <= (double)v59 )
-          v32 = v59 - v31->vWorldPosition.x;
-        else
-          v32 = v31->vWorldPosition.x - v59;
-        if ( v32 < a1f )
-        {
-          a1f = v32;
-          v29 = v30;
-        }
-        ++v30;
-        ++v31;
-      }
-      while ( v30 < a3 );
-    }
-    a1g = 3.4028235e38;
-    memcpy(&a4[2], &a2[v29], sizeof(a4[2]));
-    v33 = -1;
-    v34 = 0;
-    if ( a3 > 0 )
-    {
-      v35 = (char *)&a2->vWorldPosition.z;
-      do
-      {
-        if ( *(float *)v35 <= (double)v62 )
-          v36 = v62 - *(float *)v35;
-        else
-          v36 = *(float *)v35 - v62;
-        if ( v36 < a1g )
-        {
-          a1g = v36;
-          v33 = v34;
-        }
-        ++v34;
-        v35 += 48;
-      }
-      while ( v34 < a3 );
-    }
-    a1h = 3.4028235e38;
-    memcpy(&a4[1], &a2[v33], sizeof(a4[1]));
-    v21 = -1;
-    v37 = 0;
-    if ( a3 > 0 )
-    {
-      v38 = (char *)&a2->vWorldPosition.z;
-      do
-      {
-        if ( *(float *)v38 <= (double)v60 )
-          v39 = v60 - *(float *)v38;
-        else
-          v39 = *(float *)v38 - v60;
-        if ( v39 < a1h )
-        {
-          a1h = v39;
-          v21 = v37;
-        }
-        ++v37;
-        v38 += 48;
-      }
-      while ( v37 < a3 );
-    }
-    goto LABEL_77;
+    memcpy(&pOutLimits[0], &pVertices[_49CE9E_sub0_y(pVertices, uNumVertices, pLimits[0].vWorldPosition.y)], 0x30);
+    memcpy(&pOutLimits[2], &pVertices[_49CE9E_sub0_y(pVertices, uNumVertices, pLimits[2].vWorldPosition.y)], 0x30);
+    memcpy(&pOutLimits[1], &pVertices[_49CE9E_sub0_z(pVertices, uNumVertices, pLimits[1].vWorldPosition.z)], 0x30);
+    memcpy(&pOutLimits[3], &pVertices[_49CE9E_sub0_z(pVertices, uNumVertices, pLimits[3].vWorldPosition.z)], 0x30);
   }
-  if ( !(v7 & 0x400) )
-    return;
-  v41 = -1;
-  a1i = 3.4028235e38;
-  v42 = 0;
-  if ( a3 > 0 )
-  {
-    v43 = (char *)&a2->vWorldPosition.y;
-    do
-    {
-      if ( *(float *)v43 <= (double)v61 )
-        v44 = v61 - *(float *)v43;
-      else
-        v44 = *(float *)v43 - v61;
-      if ( v44 < a1i )
-      {
-        a1i = v44;
-        v41 = v42;
-      }
-      ++v42;
-      v43 += 48;
-    }
-    while ( v42 < a3 );
-  }
-  v45 = a2;
-  v12 = a4;
-  a1j = 3.4028235e38;
-  memcpy(a4, &a2[v41], 0x30u);
-  v46 = -1;
-  v47 = 0;
-  if ( a3 > 0 )
-  {
-    v48 = (char *)&a2->vWorldPosition.y;
-    do
-    {
-      if ( *(float *)v48 <= (double)v64 )
-        v49 = v64 - *(float *)v48;
-      else
-        v49 = *(float *)v48 - v64;
-      if ( v49 < a1j )
-      {
-        a1j = v49;
-        v46 = v47;
-      }
-      ++v47;
-      v48 += 48;
-    }
-    while ( v47 < a3 );
-    v45 = a2;
-  }
-  a1k = 3.4028235e38;
-  memcpy(&a4[2], &v45[v46], sizeof(a4[2]));
-  v50 = -1;
-  v51 = 0;
-  if ( a3 > 0 )
-  {
-    v52 = (char *)&v45->vWorldPosition.z;
-    do
-    {
-      if ( *(float *)v52 <= (double)v62 )
-        v53 = v62 - *(float *)v52;
-      else
-        v53 = *(float *)v52 - v62;
-      if ( v53 < a1k )
-      {
-        a1k = v53;
-        v50 = v51;
-      }
-      ++v51;
-      v52 += 48;
-    }
-    while ( v51 < a3 );
-    v45 = a2;
-  }
-  a1l = 3.4028235e38;
-  memcpy(&a4[1], &v45[v50], sizeof(a4[1]));
-  v54 = -1;
-  v55 = 0;
-  if ( a3 > 0 )
-  {
-    v56 = (char *)&v45->vWorldPosition.z;
-    do
-    {
-      if ( *(float *)v56 <= (double)v60 )
-        v57 = v60 - *(float *)v56;
-      else
-        v57 = *(float *)v56 - v60;
-      if ( v57 < a1l )
-      {
-        a1l = v57;
-        v54 = v55;
-      }
-      ++v55;
-      v56 += 48;
-    }
-    while ( v55 < a3 );
-    v45 = a2;
-  }
-  v40 = &v45[v54];
-LABEL_115:
-  memcpy(&v12[3], v40, sizeof(v12[3]));
 }
 
 //----- (0049D379) --------------------------------------------------------
@@ -1061,38 +752,22 @@
 }
 
 //----- (0049C5DA) --------------------------------------------------------
-char stru10::_49C5DA(BLVFace *a2, RenderVertexSoft *a3, int *a4, IndoorCameraD3D_Vec4 *a5, RenderVertexSoft *a6)
+char stru10::_49C5DA(BLVFace *pFace, RenderVertexSoft *pVertices, unsigned int *pNumVertices, IndoorCameraD3D_Vec4 *a5, RenderVertexSoft *pOutBounding)
 {
-  //stru10 *v6; // edi@1
-  //char *v7; // eax@1
-  //signed int v8; // ecx@1
-  //IndoorCameraD3D *v9; // esi@3
-  char result; // al@6
-  RenderVertexSoft a4a[4]; // [sp+Ch] [bp-C0h]@1
+  RenderVertexSoft pLimits[4]; // [sp+Ch] [bp-C0h]@1
+
+  _49CE9E(pFace, pVertices, *pNumVertices, pLimits);
 
-  /*v6 = this;
-  v7 = (char *)&a4a[0].flt_2C;
-  v8 = 4;
-  do
-  {
-    *(float *)v7 = 0.0;
-    v7 += 48;
-    --v8;
-  }
-  while ( v8 );
-  v9 = pGame->pIndoorCameraD3D;*/
-  _49CE9E(a2, a3, *a4, a4a);
-  if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
-    pGame->pIndoorCameraD3D->debug_outline_sw(a4a, 4u, 0xFF1E1Eu, 0.000099999997);
-  result = CalcFaceBounding(a2, a4a, 4u, a6);
-  if ( result )
-    result = _49C720(a6, a5);
-  return result;
+  //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
+  //  pGame->pIndoorCameraD3D->debug_outline_sw(a4a, 4u, 0xFF1E1Eu, 0.000099999997);
+  if (CalcFaceBounding(pFace, pLimits, 4, pOutBounding))
+    return _49C720(pOutBounding, a5);
+  return false;
 }
 // 4D864C: using guessed type char byte_4D864C;
 
 //----- (0049C681) --------------------------------------------------------
-char stru10::MessWithPortal(BLVFace *pFace, IndoorCameraD3D_Vec4 *a3, RenderVertexSoft *pOutBounding)
+bool stru10::CalcPortalShape(BLVFace *pFace, IndoorCameraD3D_Vec4 *a3, RenderVertexSoft *pOutBounding)
 {
   RenderVertexSoft pLimits[4]; // [sp+Ch] [bp-C0h]@1
 
@@ -1106,25 +781,19 @@
 // 4D864C: using guessed type char byte_4D864C;
 
 //----- (0049C720) --------------------------------------------------------
-char stru10::_49C720(RenderVertexSoft *a2, IndoorCameraD3D_Vec4 *a4)
+char stru10::_49C720(RenderVertexSoft *pFaceBounding, IndoorCameraD3D_Vec4 *a4)
 {
-  char result; // al@2
   Vec3_float_ a3; // [sp+4h] [bp-34h]@1
-  float v5; // [sp+30h] [bp-8h]@1
-  stru10 *thisa; // [sp+34h] [bp-4h]@1
-
-  v5 = 0.0;
   a3.x = (double)pBLVRenderParams->vPartyPos.x;
   a3.y = (double)pBLVRenderParams->vPartyPos.y;
-  thisa = this;
   a3.z = (double)pBLVRenderParams->vPartyPos.z;
-  if ( FindFaceNormal(a2, a2 + 1, &a3, a4)
-    && FindFaceNormal(a2 + 1, a2 + 2, &a3, a4 + 1)
-    && FindFaceNormal(a2 + 2, a2 + 3, &a3, a4 + 2) )
-    result = FindFaceNormal(a2 + 3, a2, &a3, a4 + 3) != 0;
-  else
-    result = 0;
-  return result;
+
+  if (FindFaceNormal(pFaceBounding,     pFaceBounding + 1, &a3, a4) &&
+      FindFaceNormal(pFaceBounding + 1, pFaceBounding + 2, &a3, a4 + 1) &&
+      FindFaceNormal(pFaceBounding + 2, pFaceBounding + 3, &a3, a4 + 2) &&
+      FindFaceNormal(pFaceBounding + 3, pFaceBounding,     &a3, a4 + 3))
+    return true;
+  return false;
 }
 
 //----- (0049C7C5) --------------------------------------------------------