view stru9.cpp @ 67:476145dc3441

Слияние
author Ritor1
date Fri, 26 Oct 2012 23:22:41 +0600
parents 5159d2e6f559
children fdacbc653945
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

  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.flt_0 = *((float *)v8 - 1);
      static_AE33A0.uNumVertices = 0;
      a3a = 0;
      static_AE3FA4.flt_4 = v11;
      static_AE3FA4.flt_8 = 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 ( _49895A(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)
{
  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
  
  static stru312 static_AE3388;
  /*if ( !(static_init_flag__AE3388_bit1__AE3378_bit2 & 1) )
  {
    static_init_flag__AE3388_bit1__AE3378_bit2 |= 1u;
    stru312::stru312(&static_AE3388);
    atexit(nullsub_16);
  }*/
  static stru312 static_AE3378;
  /*if ( !(static_init_flag__AE3388_bit1__AE3378_bit2 & 2) )
  {
    static_init_flag__AE3388_bit1__AE3378_bit2 |= 2u;
    stru312::stru312(&static_AE3378);
    atexit(nullsub_15);
  }*/
  v6 = a1;
  static_AE3378.flt_0 = a1->vWorldPosition.x - a3->vWorldPosition.x;
  static_AE3378.flt_4 = a1->vWorldPosition.y - a3->vWorldPosition.y;
  HIWORD(result) = HIWORD(a4);
  static_AE3378.flt_8 = a1->vWorldPosition.z - a3->vWorldPosition.z;
  static_AE3388.flt_0 = a2->vWorldPosition.x - a1->vWorldPosition.x;
  static_AE3388.flt_4 = a2->vWorldPosition.y - a1->vWorldPosition.y;
  static_AE3388.flt_8 = a2->vWorldPosition.z - a1->vWorldPosition.z;
  a1a = static_AE3388.flt_0 * a4->flt_0 + static_AE3388.flt_8 * a4->flt_8 + static_AE3388.flt_4 * a4->flt_4;
  v8 = static_AE3378.flt_0 * a4->flt_0 + static_AE3378.flt_8 * a4->flt_8 + static_AE3378.flt_4 * a4->flt_4;
  //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::_49895A(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct stru312 *a3)
{
  double v4; // st7@3
  double v5; // st7@3
  __int16 v6; // fps@3
  char v7; // c0@3
  char v8; // c2@3
  char v9; // c3@3
  bool result; // eax@3
  
  static stru312 static_F942A0;
  /*static bool __init_flag1 = false;
  if (!__init_flag1)
  {
    __init_flag1 = true;

    stru312::stru312(&static_F942A0);
  }*/

  static_F942A0.flt_0 = a1->vWorldPosition.x - a2->vWorldPosition.x;
  static_F942A0.flt_4 = a1->vWorldPosition.y - a2->vWorldPosition.y;
  v4 = a1->vWorldPosition.z - a2->vWorldPosition.z;
  HIWORD(result) = HIWORD(a3);
  static_F942A0.flt_8 = v4;
  v5 = v4 * a3->flt_8 + static_F942A0.flt_4 * a3->flt_4 + static_F942A0.flt_0 * a3->flt_0;
  //UNDEF(v6);
  flt_F942B0 = v5;
  v7 = v5 < 0.0;
  v8 = 0;
  v9 = v5 == 0.0;
  BYTE1(result) = HIBYTE(v6);
  LOBYTE(result) = v5 >= 0.0;
  return result;
}


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

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

//----- (004980B9) --------------------------------------------------------
bool stru9::_4980B9(RenderVertexSoft *a1, signed int a2, float a3, float a4, float a5, RenderVertexSoft *a6, unsigned int *pOutNumVertices)
{
  bool result; // eax@7
  unsigned int *v9; // ebx@7
  char *v10; // edi@8
  RenderVertexSoft *v11; // esi@9
  RenderVertexSoft *v12; // ecx@9
  double v13; // st7@12
  double v14; // st6@12
  double v15; // st5@12
  RenderVertexSoft *v16; // edi@13
  int v17; // ecx@25
  VertexBuffer *v18; // edx@26
  char *v19; // eax@26
  unsigned int i; // ecx@26
  bool v21; // [sp+0h] [bp-24h]@9
  char *v22; // [sp+Ch] [bp-18h]@8
  RenderVertexSoft *a2a; // [sp+10h] [bp-14h]@0
  RenderVertexSoft *a1a; // [sp+14h] [bp-10h]@0
  signed int v25; // [sp+18h] [bp-Ch]@7
  signed int v26; // [sp+1Ch] [bp-8h]@12
  int v27; // [sp+1Ch] [bp-8h]@25
  stru9 *thisa; // [sp+20h] [bp-4h]@1

  __debugbreak();
  thisa = this;

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

    stru_AE4BFC.flt_2C = 0.0;
  }

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

    //stru312::stru312(&static_sub_4980B9_stru_AE4BEC);
  }
  
  static VertexBuffer static_sub_4980B9_stru_AE3FE8; // idb
  static bool __init_flag3 = false;
  if (!__init_flag3)
  {
    __init_flag3 = true;

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

  result = 0;
  v9 = pOutNumVertices;
  v25 = 0;
  if ( a2 <= 0 )
    goto LABEL_32;
  v10 = (char *)&a1->vWorldPosition.z;
  v22 = (char *)&a1->vWorldPosition.z;
  do
  {
    v11 = (RenderVertexSoft *)(v10 - 8);
    v21 = result + 1;
    v12 = &a1[(result + 1) % a2];
    if ( *((float *)v10 - 2) != v12->vWorldPosition.x
      || *((float *)v10 - 1) != v12->vWorldPosition.y
      || *(float *)v10 != v12->vWorldPosition.z )
    {
      v13 = v12->vWorldPosition.x - v11->vWorldPosition.x;
      v14 = v12->vWorldPosition.y - *((float *)v10 - 1);
      v15 = v12->vWorldPosition.z - *(float *)v10;
      ++v25;
      result = 0;
      static_sub_4980B9_stru_AE3FE8.uNumVertices = 0;
      v26 = 0;
      static_sub_4980B9_stru_AE4BEC.flt_0 = a4 * v15 - v14 * a5;
      static_sub_4980B9_stru_AE4BEC.flt_4 = v13 * a5 - v15 * a3;
      static_sub_4980B9_stru_AE4BEC.flt_8 = v14 * a3 - v13 * a4;
      if ( (signed int)*v9 <= 0 )
        goto LABEL_32;
      do
      {
        v16 = &a6[result];
        if ( result )
        {
          if ( _4989E1(a1a, &a6[result], v11, &static_sub_4980B9_stru_AE4BEC)
            && _498774(a1a, v16, v11, &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC) )
            AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);
        }
        else
        {
          a2a = &a6[result];
        }
        a1a = v16;
        if ( _49895A(v16, v11, &static_sub_4980B9_stru_AE4BEC) )
          AddVertex(&static_sub_4980B9_stru_AE3FE8, v16);
        v9 = pOutNumVertices;
        result = v26++ + 1;
      }
      while ( v26 < (signed int)*pOutNumVertices );
      if ( !static_sub_4980B9_stru_AE3FE8.uNumVertices )
        goto LABEL_32;
      if ( _4989E1(v16, a2a, v11, &static_sub_4980B9_stru_AE4BEC)
        && _498774(v16, a2a, v11, &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC) )
        AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);
      v17 = static_sub_4980B9_stru_AE3FE8.uNumVertices;
      v27 = 0;
      if ( static_sub_4980B9_stru_AE3FE8.uNumVertices > 0 )
      {
        v18 = &static_sub_4980B9_stru_AE3FE8;
        v19 = (char *)&a6->vWorldPosition.y;
        for ( i = (char *)&static_sub_4980B9_stru_AE3FE8.pVertices[0].flt_20 - (char *)a6;
              ;
              i = (char *)&static_sub_4980B9_stru_AE3FE8.pVertices[0].flt_20 - (char *)a6 )
        {
          ++v27;
          *((int *)v19 - 1) = LODWORD(v18->pVertices[0].vWorldPosition.x);
          v18 = (VertexBuffer *)((char *)v18 + 48);
          *(float *)v19 = *(float *)&v19[(char *)&static_sub_4980B9_stru_AE3FE8 - (char *)a6];
          *((float *)v19 + 1) = *(float *)&v19[(char *)&static_sub_4980B9_stru_AE3FE8.pVertices[0].vWorldPosition.y
                                             - (char *)a6];
          *((float *)v19 + 8) = *(float *)&v19[i];
          *((float *)v19 + 9) = *(float *)&v19[(char *)&static_sub_4980B9_stru_AE3FE8.pVertices[0].u - (char *)a6];
          v17 = static_sub_4980B9_stru_AE3FE8.uNumVertices;
          v19 += 48;
          if ( v27 >= static_sub_4980B9_stru_AE3FE8.uNumVertices )
            break;
        }
      }
      v9 = pOutNumVertices;
      v10 = v22;
      *pOutNumVertices = v17;
    }
    result = v21;
    v10 += 48;
    v22 = v10;
  }
  while ( v21 < a2 );
  if ( v25 < 3 )
LABEL_32:
    *v9 = 0;
  return 1;
}
// AE4C2C: using guessed type char static_sub_4980B9_byte_AE4C2C_init_flag;