#include "CFTTPObject.h"
#include "CFTTPPrimitive.h"
#include "memctrl.h"
#include "sub.h"
#include <arm_neon.h>
//-------------------------------------------------------------------------------------------------
//0016A498 ^_-
//单元测试等级: 游戏运行正常
//单元测试内容: 启动游戏到第1关,会被多次调用
//单元测试结果: 正常
//编译无栈保护选项
CFTTPObject::CFTTPObject(ePhysicsObjectType ePhyObjType_r1,
                         EFreePropType eFreePropType_r2,
                         uchar uc_r3,
                         fpoint3<PointType_18> cfpoint3_arg0,
                         fpointQ<PointType_18> cfpointQ_arg4)
  : fpoint3_0(cfpoint3_arg0)
  , fpointQ_C(cfpointQ_arg4)
{
  memset(&fpoint3_1C.x_0, 0, 0x68);           //0016A4CA
  fpointQQ_54.fpointQ_24.field_C = 0x4000;
  this->field_8C = ePhyObjType_r1;      //0016A4DE
  this->field_90 = eFreePropType_r2;
  this->field_94 = 0;                        //0016A4E2
  this->pprimitive_98 = NULL;
  this->uc_9C = 0;    //0016A4E6
  this->field_9D = uc_r3;                   //0016A4EA
  this->pprimitive_98 = new CFTTPPrimitive* [uc_r3];  //0016A4EE
  memset(this->pprimitive_98, 0, this->field_9D * 4);  //0016A4FC
  this->field_A0 = -1;       //0016A504
  this->field_A4 = 0;       //0016A504
}
//-------------------------------------------------------------------------------------------------
//0016DA32 ^_^  
//单元测试等级: 游戏运行正常
//单元测试内容: 1-5关
//单元测试结果: 正常
CFTTPObject::~CFTTPObject() {
  LOGE("CFTTPObject::~CFTTPObject_0");
  //loc_16DA48
  //loc_16DA48
  for(int r5_i=0;r5_i<uc_9C;r5_i++){
    //loc_16DA3A
    if(pprimitive_98[r5_i]){//OK
      //0016DA40
      LOGE("CFTTPObject::~CFTTPObject_1");
      delete pprimitive_98[r5_i];
    }
  }
  if(pprimitive_98){//OK
    LOGE("CFTTPObject::~CFTTPObject_2");
    delete[] pprimitive_98;
  }
}
//-------------------------------------------------------------------------------------------------
//0016C584 ^_-  参数r1原汇编是个栈上的地址还原后汇编为fpoint.var_0
//单元测试等级: 游戏运行正常
//单元测试内容: 1-6
//单元测试结果: 正常
void CFTTPObject::Cache(fpoint<PointType_18> r1_pfpoint) {
  //sp2c=0
  //LOGE("CFTTPObject::Cache");
 fpointQ<PointType_18> fpointQ_sp20;

 fpointQ_sp20.field_0= ((uint64)fpoint3_28.x_0)*r1_pfpoint.var_0/0x40000;
 fpointQ_sp20.field_4= ((uint64)fpoint3_28.y_4)*r1_pfpoint.var_0/0x40000;
 fpointQ_sp20.field_8= ((uint64)fpoint3_28.z_8)*r1_pfpoint.var_0/0x40000;
 fpointQ_sp20.field_C=0;
 fpointQ<PointType_18> fpointQ_sp10;
 sub_16A88C(fpointQ_sp10,fpointQ_C);
 fpointQQ_54.fpointQ_24=fpointQ_sp10;
 fpointQ<PointType_18> fpointQ_sp0;
 sub_16C3E2(fpointQ_sp0,fpointQ_sp20,fpointQQ_54.fpointQ_24);
 int32x4_t d16d17_i32x4 ;//= vld1q_dup_s32((int32_t *)&fpointQ_sp0);
 ((int*)&d16d17_i32x4)[0]=fpointQ_sp0.field_0;
 
 ((int*)&d16d17_i32x4)[1]=fpointQ_sp0.field_4;
 
 ((int*)&d16d17_i32x4)[2]=fpointQ_sp0.field_8;
 
 ((int*)&d16d17_i32x4)[3]=fpointQ_sp0.field_C;
 
 d16d17_i32x4 =vshrq_n_s32(d16d17_i32x4,1);
 
 fpointQ_sp10.field_0=((int*)&d16d17_i32x4)[0];
 fpointQ_sp10.field_4=((int*)&d16d17_i32x4)[1];
 fpointQ_sp10.field_8=((int*)&d16d17_i32x4)[2];
 fpointQ_sp10.field_C=((int*)&d16d17_i32x4)[3];

 fpointQQ_54.fpointQ_24+=fpointQ_sp10;
 fpointQQ_54.Cache();
 fpoint3<PointType_18> fpoint3_sp10;
 sub_16C672(fpoint3_sp10,fpoint3_1C,&r1_pfpoint);
 fpoint3_48.x_0=fpoint3_0.x_0+fpoint3_sp10.x_0;
 fpoint3_48.y_4=fpoint3_0.y_4+fpoint3_sp10.y_4;
 fpoint3_48.z_8=fpoint3_0.z_8+fpoint3_sp10.z_8;
//  fpoint<PointType_18> r1_fpoint;
//  r1_fpoint.var_0=fpoint3_48.y_4;
 //loc_16C640
 for(uint r6_u=0;r6_u<uc_9C;r6_u++){
   //loc_16C632
   pprimitive_98[r6_u]->Cache(r1_pfpoint);
 }
 return ;

}
//-------------------------------------------------------------------------------------------------
//0016C6A4 ^_^
//单元测试等级: 游戏运行正常
//单元测试内容: 1-3
//单元测试结果: 正常
CFTTPCapsule CFTTPObject::GenerateSweptSphere() {
  LOGE("0016C6A4");
  CFTTPCapsule capsulr_r0;
  int r2_i=fpoint3_0.x_0;
  int r3_i=fpoint3_0.y_4;
  int r12_i=fpoint3_0.z_8;
  int lr_i=fpoint3_1C.x_0;
  int r4_i=fpoint3_1C.y_4;
  int r5_i=fpoint3_1C.z_8;

  capsulr_r0.field_0=(field_3C+0xA3D)>>4;
  capsulr_r0.field_4=r2_i>>4;
  capsulr_r0.field_8=r3_i>>4;
  capsulr_r0.field_c=r12_i>>4;
  capsulr_r0.field_10=(r2_i+lr_i)>>4;
  capsulr_r0.field_14=(r3_i+r4_i)>>4;
  capsulr_r0.field_18=(r12_i+r5_i)>>4;

  return capsulr_r0;

}
//-------------------------------------------------------------------------------------------------
