view stru9.cpp @ 110:430786d916d6

6.11.12 SaveLoad
author Ritor1
date Tue, 06 Nov 2012 17:30:24 +0600
parents fdacbc653945
children
line wrap: on
line source

#include "stru9.h"
#include "IndoorCameraD3D.h"

#include "mm7_data.h"



//----- (00498377) --------------------------------------------------------
bool stru9::_498377(struct RenderVertexSoft *a1, unsigned int uNumVertices, struct IndoorCameraD3D_Vec4 *a3, struct RenderVertexSoft *pVertices, unsigned int *pOutNumVertices)
{
  bool result; // eax@7
  unsigned int *v7; // ebx@7
  char *v8; // esi@8
  RenderVertexSoft *v9; // ecx@9
  double v10; // st7@12
  double v11; // st6@12
  RenderVertexSoft *v12; // esi@13
  int v13; // ecx@25
  VertexBuffer *v14; // edx@26
  char *v15; // eax@26
  unsigned int i; // ecx@26
  bool v17; // [sp+0h] [bp-28h]@9
  char *v18; // [sp+10h] [bp-18h]@8
  RenderVertexSoft *v19; // [sp+14h] [bp-14h]@0
  RenderVertexSoft *v20; // [sp+18h] [bp-10h]@0
  signed int v21; // [sp+1Ch] [bp-Ch]@7
  RenderVertexSoft *a2; // [sp+20h] [bp-8h]@8
  stru9 *thisa; // [sp+24h] [bp-4h]@1
  signed int a3a; // [sp+38h] [bp+10h]@12
  int a3b; // [sp+38h] [bp+10h]@25

  __debugbreak();

  thisa = this;

  static RenderVertexSoft static_AE3FB4;
  static bool __init_flag1 = false;
  if (!__init_flag1)
  {
    __init_flag1 = true;

    static_AE3FB4.flt_2C = 0.0;
  }

  static stru312 static_AE3FA4; // idb
  static bool __init_flag2 = false;
  if (!__init_flag2)
  {
    __init_flag2 = true;

    //stru312::stru312(&static_AE3FA4);
  }

  static VertexBuffer static_AE33A0; // idb
  static bool __init_flag3 = false;
  if (!__init_flag3)
  {
    __init_flag3 = true;

    //VertexBuffer::VertexBuffer(&static_AE33A0);
  }

  result = 0;
  v7 = pOutNumVertices;
  v21 = 0;
  if ( (signed int)uNumVertices <= 0 )
    goto LABEL_32;
  a2 = a1;
  v8 = (char *)&a3->y;
  v18 = (char *)&a3->y;
  do
  {
    v17 = result + 1;
    v9 = &a1[(result + 1) % (signed int)uNumVertices];
    if ( a2->vWorldPosition.x != v9->vWorldPosition.x
      || a2->vWorldPosition.y != v9->vWorldPosition.y
      || a2->vWorldPosition.z != v9->vWorldPosition.z )
    {
      v10 = *((float *)v8 + 1);
      v11 = *(float *)v8;
      ++v21;
      result = 0;
      static_AE3FA4.x = *((float *)v8 - 1);
      static_AE33A0.uNumVertices = 0;
      a3a = 0;
      static_AE3FA4.y = v11;
      static_AE3FA4.z = v10;
      if ( (signed int)*v7 <= 0 )
        goto LABEL_32;
      do
      {
        v12 = &pVertices[result];
        if ( result )
        {
          if ( _4989E1(v20, &pVertices[result], a2, &static_AE3FA4)
            && _498774(v20, v12, a2, &static_AE3FA4, &static_AE3FB4) )
            AddVertex(&static_AE33A0, &static_AE3FB4);
        }
        else
        {
          v19 = &pVertices[result];
        }
        v20 = v12;
        if ( AreVectorsCollinear(v12, a2, &static_AE3FA4) )
          AddVertex(&static_AE33A0, v12);
        v7 = pOutNumVertices;
        result = a3a++ + 1;
      }
      while ( a3a < (signed int)*pOutNumVertices );
      if ( !static_AE33A0.uNumVertices )
        goto LABEL_32;
      if ( _4989E1(v12, v19, a2, &static_AE3FA4)
        && _498774(v12, v19, a2, &static_AE3FA4, &static_AE3FB4) )
        AddVertex(&static_AE33A0, &static_AE3FB4);
      v13 = static_AE33A0.uNumVertices;
      a3b = 0;
      if ( static_AE33A0.uNumVertices > 0 )
      {
        v14 = &static_AE33A0;
        v15 = (char *)&pVertices->vWorldPosition.y;
        for ( i = (char *)&static_AE33A0.pVertices[0].vWorldPosition.y - (char *)pVertices;
              ;
              i = (char *)&static_AE33A0.pVertices[0].vWorldPosition.y - (char *)pVertices )
        {
          ++a3b;
          *((int *)v15 - 1) = *(unsigned int *)(&v14->pVertices[0].vWorldPosition.x);
          v14 = (VertexBuffer *)((char *)v14 + 48);
          *(float *)v15 = *(float *)&v15[(char *)&static_AE33A0 - (char *)pVertices];
          *((float *)v15 + 1) = *(float *)&v15[i];
          *((float *)v15 + 8) = *(float *)&v15[(char *)&static_AE33A0.pVertices[0].flt_20 - (char *)pVertices];
          *((float *)v15 + 9) = *(float *)&v15[(char *)&static_AE33A0.pVertices[0].u - (char *)pVertices];
          v13 = static_AE33A0.uNumVertices;
          v15 += 48;
          if ( a3b >= static_AE33A0.uNumVertices )
            break;
        }
      }
      v7 = pOutNumVertices;
      v8 = v18;
      *pOutNumVertices = v13;
    }
    result = v17;
    ++a2;
    v8 += 24;
    v18 = v8;
  }
  while ( v17 < (signed int)uNumVertices );
  if ( v21 < 3 )
LABEL_32:
    *v7 = 0;
  return 1;
}
// AE3FE4: using guessed type char static_init_flag__AE3FB4_bit1__AE3FA4_bit2__AE33A0_bit3;

//----- (004985FB) --------------------------------------------------------
bool stru9::_4985FB(struct RenderVertexSoft *a1, signed int a2, struct RenderVertexSoft *a3, unsigned int *pOutNumVertices, struct Vec3_float_ *a5, float a6, char *a7, int unused)
{
  RenderVertexSoft *v9; // ecx@1
  Vec3_float_ *v10; // esi@1
  //char *v11; // ebx@1
  RenderVertexSoft *v12; // edi@1
  double v13; // st7@1
  //bool result; // eax@4
  signed int v15; // edx@9
  RenderVertexSoft *v16; // ecx@9
  double v17; // st7@9
  double v18; // st6@12
  signed int v19; // [sp+Ch] [bp-Ch]@7
  float v20; // [sp+10h] [bp-8h]@1
  bool v21; // [sp+14h] [bp-4h]@2

  v9 = a1;
  v10 = a5;
  //v11 = (char *)&a1->vWorldPosition.z;
  auto v11 = a1;
  v12 = a3;
  v13 = a1->vWorldPosition.y * a5->y + a5->x * a1->vWorldPosition.x + a1->vWorldPosition.z * a5->z;
  v20 = v13;
  v21 = v13 >= a6;

  *pOutNumVertices = 0;
  if ( a2 <= 0 )
    return false;
  v19 = 1;
  while ( 1 )
  {
    if ( v21 )
    {
      ++a3;
      memcpy(v12, v11, sizeof(RenderVertexSoft));
      ++*pOutNumVertices;
      v10 = a5;
      v12 = a3;
      v9 = a1;
    }
    v15 = 0;
    v16 = &v9[v19 % a2];
    v17 = v16->vWorldPosition.z * v10->z + v16->vWorldPosition.y * v10->y + v10->x * v16->vWorldPosition.x;
    if ( v17 >= a6 )
      v15 = 1;
    if ( v21 != v15 )
    {
      v18 = (a6 - v20) / (v17 - v20);
      v12->vWorldPosition.x = (v16->vWorldPosition.x - v11->vWorldPosition.x) * v18 + v11->vWorldPosition.x;
      v12->vWorldPosition.y = (v16->vWorldPosition.y - v11->vWorldPosition.y) * v18 + v11->vWorldPosition.y;
      v12->vWorldPosition.z = (v16->vWorldPosition.z - v11->vWorldPosition.z) * v18 + v11->vWorldPosition.z;
      v12->u = (v16->u - v11->u) * v18 + v11->u;
      v12->v = (v16->v - v11->v) * v18 + v11->v;
      ++v12;
      a3 = v12;
      ++*pOutNumVertices;
      *a7 = 1;
    }

    v11++;
    v21 = v15;
    v20 = v17;
    if ( v19 >= a2 )
      break;
    v9 = a1;
    v19++;
  }

  return *pOutNumVertices >= 3;
}

//----- (00498737) --------------------------------------------------------
void stru9::AddVertex(struct VertexBuffer *pVertexBuffer, struct RenderVertexSoft *pVertex)
{
  __debugbreak();
  RenderVertexSoft *v3; // eax@1

  v3 = &pVertexBuffer->pVertices[pVertexBuffer->uNumVertices];
  v3->vWorldPosition.x = pVertex->vWorldPosition.x;
  v3->vWorldPosition.y = pVertex->vWorldPosition.y;
  v3->vWorldPosition.z = pVertex->vWorldPosition.z;
  v3->u = pVertex->u;
  v3->v = pVertex->v;
  ++pVertexBuffer->uNumVertices;
}

//----- (00498774) --------------------------------------------------------
bool stru9::_498774(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct RenderVertexSoft *a3, struct stru312 *a4, struct RenderVertexSoft *a5)
{
  RenderVertexSoft *v6; // ecx@5
  bool result; // eax@5
  double v8; // st7@5
  __int16 v9; // fps@5
  double v10; // st7@6
  double v11; // st6@8
  double v12; // st6@18
  char v13; // c0@24
  char v14; // c2@24
  char v15; // c3@24
  float a1a; // [sp+10h] [bp+8h]@5

  __debugbreak();
  
  static stru312 static_AE3388;
  static stru312 static_AE3378;

  v6 = a1;
  static_AE3378.x = a1->vWorldPosition.x - a3->vWorldPosition.x;
  static_AE3378.y = a1->vWorldPosition.y - a3->vWorldPosition.y;
  HIWORD(result) = HIWORD(a4);
  static_AE3378.z = a1->vWorldPosition.z - a3->vWorldPosition.z;
  static_AE3388.x = a2->vWorldPosition.x - a1->vWorldPosition.x;
  static_AE3388.y = a2->vWorldPosition.y - a1->vWorldPosition.y;
  static_AE3388.z = a2->vWorldPosition.z - a1->vWorldPosition.z;
  a1a = static_AE3388.x * a4->x + static_AE3388.z * a4->z + static_AE3388.y * a4->y;
  v8 = static_AE3378.x * a4->x + static_AE3378.z * a4->z + static_AE3378.y * a4->y;
  //UNDEF(v9);
  if ( a1a != 0.0 )
  {
    v10 = -(v8 / a1a);
    if ( a1a <= 0.0 )
    {
      if ( v10 <= 0.0 )
        v12 = 0.0;
      else
        v12 = v10;
      if ( v12 <= 1.0 )
      {
        if ( v10 <= 0.0 )
          v10 = (float)0.0;
      }
      else
      {
        v10 = 1.0;
      }
    }
    else
    {
      if ( v10 >= 1.0 )
        v11 = 1.0;
      else
        v11 = v10;
      if ( v11 >= 0.0 )
      {
        if ( v10 >= 1.0 )
          v10 = (float)1.0;
      }
      else
      {
        v10 = 0.0;
      }
    }
    result = (bool)a5;
    a5->vWorldPosition.x = (a2->vWorldPosition.x - v6->vWorldPosition.x) * v10 + v6->vWorldPosition.x;
    a5->vWorldPosition.y = (a2->vWorldPosition.y - v6->vWorldPosition.y) * v10 + v6->vWorldPosition.y;
    a5->vWorldPosition.z = (a2->vWorldPosition.z - v6->vWorldPosition.z) * v10 + v6->vWorldPosition.z;
    a5->u = (a2->u - v6->u) * v10 + v6->u;
    a5->v = (a2->v - v6->v) * v10 + v6->v;
    goto LABEL_15;
  }
  v13 = v8 < 0.0;
  v14 = 0;
  v15 = v8 == 0.0;
  BYTE1(result) = HIBYTE(v9);
  if ( v8 < 0.0 )
  {
LABEL_15:
    LOBYTE(result) = 1;
    return result;
  }
  LOBYTE(result) = 0;
  return result;
}
// AE3398: using guessed type char static_init_flag__AE3388_bit1__AE3378_bit2;

//----- (0049895A) --------------------------------------------------------
bool stru9::AreVectorsCollinear(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct stru312 *a3)
{
  static stru312 static_F942A0;

  static_F942A0.x = a1->vWorldPosition.x - a2->vWorldPosition.x;
  static_F942A0.y = a1->vWorldPosition.y - a2->vWorldPosition.y;
  static_F942A0.z = a1->vWorldPosition.z - a2->vWorldPosition.z;

  static float flt_F942B4 = static_F942A0.z * a3->z + static_F942A0.y * a3->y + static_F942A0.x * a3->x;
  if (flt_F942B4 >= 0)
    return true;
  return false;
}


//----- (004989E1) --------------------------------------------------------
bool stru9::_4989E1(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct RenderVertexSoft *a3, struct stru312 *a4)
{
  bool r1;
  bool r2;

  r1 = AreVectorsCollinear(a1, a3, a4);
  r2 = AreVectorsCollinear(a2, a3, a4);
  return !r1 && r2 == 1 ||
         r1 == 1 && !r2;
}

//----- (004980B9) --------------------------------------------------------
bool stru9::_4980B9(RenderVertexSoft *a1, unsigned int uNumVertices, float a3, float a4, float a5, RenderVertexSoft *pOutVertices, unsigned int *pOutNumVertices)
{
  RenderVertexSoft *v12; // ecx@9
  double v13; // st7@12
  double v14; // st6@12
  double v15; // st5@12
  signed int v25; // [sp+18h] [bp-Ch]@7

  static RenderVertexSoft stru_AE4BFC;
  static stru312 static_sub_4980B9_stru_AE4BEC; // idb
  static VertexBuffer static_sub_4980B9_stru_AE3FE8; // idb

  v25 = 0;
  if (uNumVertices <= 0)
  {
    *pOutNumVertices = 0;
    return true;
  }

  for (uint i = 0; i < uNumVertices; ++i)
  {
    v12 = &a1[(i + 1) % uNumVertices];
    if (a1[i].vWorldPosition.x != v12->vWorldPosition.x ||
        a1[i].vWorldPosition.y != v12->vWorldPosition.y ||
        a1[i].vWorldPosition.z!= v12->vWorldPosition.z)
    {
      v13 = v12->vWorldPosition.x - a1[i].vWorldPosition.x;
      v14 = v12->vWorldPosition.y - a1[i].vWorldPosition.y;
      v15 = v12->vWorldPosition.z - a1[i].vWorldPosition.z;
      ++v25;

      static_sub_4980B9_stru_AE3FE8.uNumVertices = 0;
      static_sub_4980B9_stru_AE4BEC.x = a4 * v15 - v14 * a5;
      static_sub_4980B9_stru_AE4BEC.y = v13 * a5 - v15 * a3;
      static_sub_4980B9_stru_AE4BEC.z = v14 * a3 - v13 * a4;
      if (*pOutNumVertices == 0)
        return true;

      for (uint j = 0; j < *pOutNumVertices; ++j)
      {
        if (j)
        {
          if (_4989E1(&pOutVertices[j - 1], &pOutVertices[j], &a1[i], &static_sub_4980B9_stru_AE4BEC) &&
              _498774(&pOutVertices[j - 1], &pOutVertices[j], &a1[i], &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC))
              AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);
        }

        if (AreVectorsCollinear(&pOutVertices[j], &a1[i], &static_sub_4980B9_stru_AE4BEC))
          AddVertex(&static_sub_4980B9_stru_AE3FE8, &pOutVertices[j]);
      }

      if (!static_sub_4980B9_stru_AE3FE8.uNumVertices)
      {
        *pOutNumVertices = 0;
        return true;
      }
      if (_4989E1(&pOutVertices[*pOutNumVertices - 1], &pOutVertices[0], &a1[i], &static_sub_4980B9_stru_AE4BEC) &&
          _498774(&pOutVertices[*pOutNumVertices - 1], &pOutVertices[0], &a1[i], &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC) )
        AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);

      for (uint j = 0; j < static_sub_4980B9_stru_AE3FE8.uNumVertices; ++j)
      {
          pOutVertices[j].vWorldPosition.y = static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.x;
          pOutVertices[j].vWorldPosition.y = static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.y;
          pOutVertices[j].vWorldPosition.z = static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.z;
          pOutVertices[j].u = static_sub_4980B9_stru_AE3FE8.pVertices[j].u;
          pOutVertices[j].v = static_sub_4980B9_stru_AE3FE8.pVertices[j].v;
      }
      *pOutNumVertices = static_sub_4980B9_stru_AE3FE8.uNumVertices;
    }
  }

  if (v25 < 3)
    *pOutNumVertices = 0;

  return true;
}
// AE4C2C: using guessed type char static_sub_4980B9_byte_AE4C2C_init_flag;