// File: /workspace/github_cpp_makefile_star2_O1/wrighteagle2d[P]wrighteaglebase/Debug/../src/WorldState.cpp
// Function: WorldStateUpdater::UpdateSelfInfo()
void WorldStateUpdater::UpdateSelfInfo() {

  SelfState().SetIsAlive(true);
  SelfState().UpdateIsSensed(true); // “真正”的自己

  //=============================更新自己的sense========================
  UpdateSelfSense();
  /*
          //==========================according to speed of this cycle estimate
     position of this cycle======================= if
     (mpObserver->GetPlayerMoveTime() != mpObserver->CurrentTime())
          {
                  Vector vel = SelfState().GetVel();

                  if (mpObserver->Sense().IsCollideWithBall() ||
     mpObserver->Sense().IsCollideWithPlayer() ||
     mpObserver->Sense().IsCollideWithPost())
                  {
                          //when collided ,velocity should be changed to normal;
                          vel /= -0.1;
                  }

                  Vector last_pos =
     mpWorldState->GetHistory(1)->Teammate(GetSelfUnum()).GetPos();
                  SelfState().UpdatePos(last_pos + vel /
     ServerParam::instance().ballDecay() , SelfState().GetPosDelay()
     ,SelfState().GetPosConf());
          }
  */

  //到此为止自己的身体角度和脖子角度更新对了
  //计算公式见USTC_Material 第七章
  // playerVel = polar2vector(speedValue, neckGlobalAngle + speedAngle)
  Vector vec = Polar2Vector(mpObserver->Sense().GetSpeed(),
                            mpObserver->Sense().GetSpeedDir() +
                                GetSelf().GetNeckGlobalDir());
  SelfState().UpdateVel(vec);

  //用自己更新后的速度预测自己的位置,比之前的预测准.见08
  if (!mpObserver->Sense().IsCollideWithBall() &&
      !mpObserver->Sense().IsCollideWithPlayer() &&
      mpObserver->GetPlayerMoveTime() != mpObserver->CurrentTime()) {
    const Vector &pre_pos =
        mpWorldState->GetHistory(1)->GetTeammate(mSelfUnum).GetPos();
    double conf =
        mpWorldState->GetHistory(1)->GetTeammate(mSelfUnum).GetPosConf();

    if (conf > PlayerParam::instance().minValidConf()) {

      Vector pos = pre_pos + vec / SelfState().GetPlayerDecay();
      SelfState().UpdatePos(pos, SelfState().GetPosDelay(),
                            SelfState().GetPosConf());
    }
  }

  //评估自己位置误差
  //,目前最大问题是server移人,而人不知.目前处理是如果dropball以及playmode模式改变是将位置eps加到极大
  if (mpWorldState->GetPlayModeTime() == mpWorldState->CurrentTime() ||
      mpWorldState->IsBallDropped()) {
    SelfState().UpdatePosEps(10000);
  }

  //===============================更新自己的视觉======================
  if (mpObserver->IsNewSight()) {
    //更新自己的头部和身体角度
    double neck_globe_angle = 0.0;

    if (ComputeSelfDir(neck_globe_angle)) {
      //计算公式见USTC_Material 第七章
      // bodyGlobalAngle = neckGlobalAngle – head_angle
      if (mSightDelay <= HistoryState::HISTORY_SIZE) {
        const PlayerState &player =
            mpWorldState->GetHistory(mSightDelay)->GetTeammate(mSelfUnum);
        SelfState().UpdateBodyDir(neck_globe_angle - player.GetNeckDir(),
                                  mSightDelay, mPlayerConf);
      } else {
        PRINT_ERROR("mSightDelay too big!!" << mSightDelay);
        SelfState().UpdateBodyDir(neck_globe_angle - SelfState().GetNeckDir(),
                                  mSightDelay, mPlayerConf);
      }
    }

    if (mSightDelay == 0) {
      //修正自己的速度 当且仅当不出现视觉延迟时.
      Vector vec = Polar2Vector(mpObserver->Sense().GetSpeed(),
                                mpObserver->Sense().GetSpeedDir() +
                                    GetSelf().GetNeckGlobalDir());
      SelfState().UpdateVel(vec);
    }

    //更新自己的位置
    Vector pos;
    double eps = 0;
    if (ComputeSelfPos(pos, eps)) {
      if (eps > SelfState().GetPosEps()) {
        //根据统计值,x,y单个分量差值大于1基本不存在 因此取1
        if (pos.Dist2(SelfState().GetPos()) < 1) {
          pos = SelfState().GetPos();
          eps = SelfState().GetPosEps();
        }

      } else if (eps == SelfState().GetPosEps()) {
        if (pos.Dist2(SelfState().GetPos()) < 1) {
          pos = (pos + SelfState().GetPos()) / 2;
        }
      }

      SelfState().UpdatePos(pos, mSightDelay, mPlayerConf);
      SelfState().UpdatePosEps(eps);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movslq 0x14(%rdi), %rax
movq 0x8(%rdi), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
movb $0x1, %dl
movb %dl, 0x42(%rax,%rcx)
movb %dl, 0xa6(%rax,%rcx)
callq 0x63a7c
movq (%rbx), %r13
movsd 0x148(%r13), %xmm0
movsd %xmm0, -0x30(%rbp)
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
movq $-0xd0, %r12
addq %r12, %rdi
callq 0x5b2be
addsd -0x30(%rbp), %xmm0
mulsd 0xbdb9(%rip), %xmm0     # 0x6b050
divsd 0xbda9(%rip), %xmm0     # 0x6b048
leaq -0x60(%rbp), %r14
leaq -0x40(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x92d0
movsd 0x140(%r13), %xmm0
movsd (%r15), %xmm1
mulsd %xmm0, %xmm1
mulsd (%r14), %xmm0
movsd %xmm1, (%r14)
movsd %xmm0, 0x8(%r14)
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
addq %r12, %rdi
leaq -0x60(%rbp), %rsi
movsd 0xbd66(%rip), %xmm0     # 0x6b058
xorl %edx, %edx
callq 0xf64c
movq (%rbx), %rax
cmpb $0x0, 0x1b2(%rax)
jne 0x5f46c
cmpb $0x0, 0x1b1(%rax)
jne 0x5f46c
movq 0x5688(%rax), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
cmpl %edx, 0x10(%rax)
jne 0x5f332
cmpl %ecx, 0xc(%rax)
je 0x5f46c
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movl 0x14b90(%rax), %ecx
movl %ecx, %edx
addl $0x9, %edx
movslq %edx, %rdx
imulq $0x66666667, %rdx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
negl %edx
addl %edx, %ecx
addl $0x9, %ecx
movslq %ecx, %rcx
imulq $0x2128, %rcx, %r14     # imm = 0x2128
addq %rax, %r14
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %r15      # imm = 0x178
movsd -0xb0(%r15,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x450ba
movsd -0x30(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x5f46c
addq %r15, %r14
addq $-0xc8, %r14
movslq 0x14(%rbx), %r15
movq 0x8(%rbx), %r12
callq 0x450ba
movq 0x5c38(%rax), %rax
imulq $0x178, %r15, %rcx      # imm = 0x178
movslq 0x44(%r12,%rcx), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3020(%rax,%rcx), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm1, %xmm0
setae %al
movapd 0xbc1a(%rip), %xmm1     # 0x6b010
andpd %xmm0, %xmm1
leaq 0xd1bf(%rip), %rcx      # 0x6c5c0
movsd (%rcx,%rax,8), %xmm2
cmpltsd 0xbc31(%rip), %xmm1     # 0x6b040
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movsd -0x60(%rbp), %xmm0
movsd -0x58(%rbp), %xmm2
divsd %xmm1, %xmm0
addsd (%r14), %xmm0
divsd %xmm1, %xmm2
addsd 0x8(%r14), %xmm2
leaq -0x40(%rbp), %rsi
movsd %xmm0, (%rsi)
movsd %xmm2, 0x8(%rsi)
movslq 0x14(%rbx), %rax
movq 0x8(%rbx), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%rax,%rcx), %rdi
addq $-0xd0, %rdi
movl 0x18(%rdi), %edx
movsd 0x20(%rdi), %xmm0
callq 0xf682
movq 0x8(%rbx), %rax
movl 0x28(%rax), %ecx
cmpl 0x14(%rax), %ecx
jne 0x5f480
movl 0x10(%rax), %ecx
cmpl %ecx, 0x24(%rax)
je 0x5f486
cmpb $0x1, 0x2c(%rax)
jne 0x5f4a3
movslq 0x14(%rbx), %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
movabsq $0x40c3880000000000, %rdx # imm = 0x40C3880000000000
movq %rdx, -0xa8(%rax,%rcx)
movq (%rbx), %rax
cmpb $0x1, 0x3382(%rax)
jne 0x5f917
leaq -0x50(%rbp), %rsi
movq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x63ed0
testb %al, %al
je 0x5f742
movl 0x28(%rbx), %edx
cmpl $0xa, %edx
jg 0x5f5c1
movq 0x8(%rbx), %rax
movq %rax, %r12
testl %edx, %edx
je 0x5f53e
movq 0x8(%rax), %rcx
movslq %edx, %rsi
imulq $0x66666667, %rsi, %rsi # imm = 0x66666667
movq %rsi, %rdi
shrq $0x3f, %rdi
sarq $0x22, %rsi
addl %edi, %esi
addl %esi, %esi
leal (%rsi,%rsi,4), %esi
movl 0x14b90(%rcx), %edi
subl %edx, %esi
leal (%rdi,%rsi), %edx
addl $0xa, %edx
movslq %edx, %rdx
imulq $0x66666667, %rdx, %rsi # imm = 0x66666667
movq %rsi, %rdi
shrq $0x3f, %rdi
sarq $0x22, %rsi
addl %edi, %esi
addl %esi, %esi
leal (%rsi,%rsi,4), %esi
subl %esi, %edx
movslq %edx, %rdx
imulq $0x2128, %rdx, %r12     # imm = 0x2128
addq %rcx, %r12
movslq 0x14(%rbx), %rcx
imulq $0x178, %rcx, %r13      # imm = 0x178
leaq (%rax,%r13), %r15
addq $-0xd0, %r15
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4a75c
movq %rax, %r14
callq 0x4a75c
movsd -0x30(%rbp), %xmm3
movsd -0x38(%r12,%r13), %xmm0
maxsd 0x3168(%r14), %xmm0
movsd 0x3160(%rax), %xmm1
minsd %xmm0, %xmm1
subsd %xmm1, %xmm3
movl 0x28(%rbx), %eax
movsd 0x18(%rbx), %xmm0
movsd 0xbac0(%rip), %xmm1     # 0x6b060
ucomisd %xmm3, %xmm1
jbe 0x5f6df
movsd 0xbabe(%rip), %xmm2     # 0x6b070
addsd %xmm2, %xmm3
ucomisd %xmm3, %xmm1
ja 0x5f5b2
jmp 0x5f729
movq 0x27a28(%rip), %r14     # 0x86ff0
leaq 0x10299(%rip), %rsi     # 0x6f868
movl $0x15, %edx
movq %r14, %rdi
callq 0x9560
leaq 0xfbdf(%rip), %rsi      # 0x6f1c2
movl $0x1, %edx
movq %r14, %rdi
callq 0x9560
movq %r14, %rdi
movl $0x2f1, %esi            # imm = 0x2F1
callq 0x9880
movq %rax, %r14
leaq 0xde78(%rip), %rsi      # 0x6d47f
movl $0x3, %edx
movq %rax, %rdi
callq 0x9560
leaq 0x10263(%rip), %rsi     # 0x6f87e
movl $0x15, %edx
movq %r14, %rdi
callq 0x9560
movl 0x28(%rbx), %esi
movq %r14, %rdi
callq 0x9880
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r14, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
movslq 0x14(%rbx), %rax
movq 0x8(%rbx), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%rax,%rcx), %r15
addq $-0xd0, %r15
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4a75c
movq %rax, %r14
callq 0x4a75c
movsd -0x30(%rbp), %xmm3
movsd 0x98(%r15), %xmm0
maxsd 0x3168(%r14), %xmm0
movsd 0x3160(%rax), %xmm1
minsd %xmm0, %xmm1
subsd %xmm1, %xmm3
movl 0x28(%rbx), %eax
movsd 0x18(%rbx), %xmm0
movsd 0xb99b(%rip), %xmm1     # 0x6b060
ucomisd %xmm3, %xmm1
jbe 0x5f705
movsd 0xb99d(%rip), %xmm2     # 0x6b070
addsd %xmm2, %xmm3
ucomisd %xmm3, %xmm1
ja 0x5f6d3
jmp 0x5f729
ucomisd 0xb961(%rip), %xmm3     # 0x6b048
jb 0x5f729
movsd 0xb977(%rip), %xmm1     # 0x6b068
movsd 0xb94f(%rip), %xmm2     # 0x6b048
addsd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
jae 0x5f6f9
jmp 0x5f729
ucomisd 0xb93b(%rip), %xmm3     # 0x6b048
jb 0x5f729
movsd 0xb951(%rip), %xmm1     # 0x6b068
movsd 0xb929(%rip), %xmm2     # 0x6b048
addsd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
jae 0x5f71f
movsd %xmm3, 0xb0(%r15)
movl %eax, 0xb8(%r15)
movsd %xmm0, 0xc0(%r15)
cmpl $0x0, 0x28(%rbx)
jne 0x5f7ea
movq (%rbx), %r13
movsd 0x148(%r13), %xmm0
movsd %xmm0, -0x30(%rbp)
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
movq $-0xd0, %r12
addq %r12, %rdi
callq 0x5b2be
addsd -0x30(%rbp), %xmm0
mulsd 0xb8c8(%rip), %xmm0     # 0x6b050
divsd 0xb8b8(%rip), %xmm0     # 0x6b048
leaq -0x40(%rbp), %r14
leaq -0x48(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x92d0
movsd 0x140(%r13), %xmm0
movsd (%r15), %xmm1
mulsd %xmm0, %xmm1
mulsd (%r14), %xmm0
movsd %xmm1, (%r14)
movsd %xmm0, 0x8(%r14)
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
addq %r12, %rdi
leaq -0x40(%rbp), %rsi
movsd 0xb875(%rip), %xmm0     # 0x6b058
xorl %edx, %edx
callq 0xf64c
xorpd %xmm0, %xmm0
leaq -0x40(%rbp), %rsi
movapd %xmm0, (%rsi)
leaq -0x48(%rbp), %rdx
movq $0x0, (%rdx)
movq %rbx, %rdi
callq 0x63fc2
testb %al, %al
je 0x5f917
movsd -0x48(%rbp), %xmm0
movslq 0x14(%rbx), %rcx
movq 0x8(%rbx), %rax
imulq $0x178, %rcx, %rcx      # imm = 0x178
leaq (%rcx,%rax), %rdi
addq $-0xd0, %rdi
ucomisd 0x28(%rdi), %xmm0
jbe 0x5f885
movsd -0x40(%rbp), %xmm0
subsd 0x8(%rdi), %xmm0
movsd -0x38(%rbp), %xmm1
subsd 0x10(%rdi), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0xb7f9(%rip), %xmm1     # 0x6b058
ucomisd %xmm0, %xmm1
jbe 0x5f8e9
addq %rcx, %rax
addq $-0xc8, %rax
movups (%rax), %xmm0
movaps %xmm0, -0x40(%rbp)
movsd 0x28(%rdi), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x5f8e9
jne 0x5f8e9
jp 0x5f8e9
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd 0x8(%rdi), %xmm3
movsd 0x10(%rdi), %xmm2
movapd %xmm0, %xmm4
subsd %xmm3, %xmm4
movapd %xmm1, %xmm5
subsd %xmm2, %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm4, %xmm4
addsd %xmm5, %xmm4
movsd 0xb797(%rip), %xmm5     # 0x6b058
ucomisd %xmm4, %xmm5
jbe 0x5f8e9
addsd %xmm3, %xmm0
addsd %xmm2, %xmm1
movsd 0xbfa1(%rip), %xmm2     # 0x6b878
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movl 0x28(%rbx), %edx
movsd 0x18(%rbx), %xmm0
leaq -0x40(%rbp), %rsi
callq 0xf682
movslq 0x14(%rbx), %rax
movq 0x8(%rbx), %rcx
movsd -0x48(%rbp), %xmm0
imulq $0x178, %rax, %rax      # imm = 0x178
movsd %xmm0, -0xa8(%rcx,%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq