// File: /workspace/github_cpp_makefile_star2_O3/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 0x61a06
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 0x59a22
addsd -0x30(%rbp), %xmm0
mulsd 0xb7ab(%rip), %xmm0     # 0x69050
divsd 0xb79b(%rip), %xmm0     # 0x69048
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 0xb758(%rip), %xmm0     # 0x69058
xorl %edx, %edx
callq 0xf53c
movq (%rbx), %rax
cmpb $0x0, 0x1b2(%rax)
jne 0x5da7a
cmpb $0x0, 0x1b1(%rax)
jne 0x5da7a
movq 0x5688(%rax), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
cmpl %edx, 0x10(%rax)
jne 0x5d940
cmpl %ecx, 0xc(%rax)
je 0x5da7a
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 0x43dce
movsd -0x30(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x5da7a
addq %r15, %r14
addq $-0xc8, %r14
movslq 0x14(%rbx), %r15
movq 0x8(%rbx), %r12
callq 0x43dce
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 0xb60c(%rip), %xmm1     # 0x69010
andpd %xmm0, %xmm1
leaq 0xcba1(%rip), %rcx      # 0x6a5b0
movsd (%rcx,%rax,8), %xmm2
cmpltsd 0xb623(%rip), %xmm1     # 0x69040
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 0xf572
movq 0x8(%rbx), %rax
movl 0x28(%rax), %ecx
cmpl 0x14(%rax), %ecx
jne 0x5da8e
movl 0x10(%rax), %ecx
cmpl %ecx, 0x24(%rax)
je 0x5da94
cmpb $0x1, 0x2c(%rax)
jne 0x5dab1
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 0x5df24
leaq -0x48(%rbp), %rsi
movq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x61e5e
movl 0x28(%rbx), %ecx
testb %al, %al
je 0x5dd50
cmpl $0xa, %ecx
jg 0x5dbcf
movq 0x8(%rbx), %rax
movq %rax, %r12
testl %ecx, %ecx
je 0x5db4c
movq 0x8(%rax), %rdx
movslq %ecx, %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(%rdx), %edi
subl %ecx, %esi
leal (%rdi,%rsi), %ecx
addl $0xa, %ecx
movslq %ecx, %rcx
imulq $0x66666667, %rcx, %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, %ecx
movslq %ecx, %rcx
imulq $0x2128, %rcx, %r12     # imm = 0x2128
addq %rdx, %r12
movslq 0x14(%rbx), %rcx
imulq $0x178, %rcx, %r13      # imm = 0x178
leaq (%rax,%r13), %r15
addq $-0xd0, %r15
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x49360
movq %rax, %r14
callq 0x49360
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), %ecx
movsd 0x18(%rbx), %xmm0
movsd 0xb4b2(%rip), %xmm1     # 0x69060
ucomisd %xmm3, %xmm1
jbe 0x5dced
movsd 0xb4b0(%rip), %xmm2     # 0x69070
addsd %xmm2, %xmm3
ucomisd %xmm3, %xmm1
ja 0x5dbc0
jmp 0x5dd37
movq 0x2641a(%rip), %r14     # 0x83ff0
leaq 0xfc4b(%rip), %rsi      # 0x6d828
movl $0x15, %edx
movq %r14, %rdi
callq 0x9560
leaq 0xf5a1(%rip), %rsi      # 0x6d192
movl $0x1, %edx
movq %r14, %rdi
callq 0x9560
movq %r14, %rdi
movl $0x2f1, %esi            # imm = 0x2F1
callq 0x9880
movq %rax, %r14
leaq 0xd842(%rip), %rsi      # 0x6b457
movl $0x3, %edx
movq %rax, %rdi
callq 0x9560
leaq 0xfc15(%rip), %rsi      # 0x6d83e
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 -0x48(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x49360
movq %rax, %r14
callq 0x49360
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), %ecx
movsd 0x18(%rbx), %xmm0
movsd 0xb38d(%rip), %xmm1     # 0x69060
ucomisd %xmm3, %xmm1
jbe 0x5dd13
movsd 0xb38f(%rip), %xmm2     # 0x69070
addsd %xmm2, %xmm3
ucomisd %xmm3, %xmm1
ja 0x5dce1
jmp 0x5dd37
ucomisd 0xb353(%rip), %xmm3     # 0x69048
jb 0x5dd37
movsd 0xb369(%rip), %xmm1     # 0x69068
movsd 0xb341(%rip), %xmm2     # 0x69048
addsd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
jae 0x5dd07
jmp 0x5dd37
ucomisd 0xb32d(%rip), %xmm3     # 0x69048
jb 0x5dd37
movsd 0xb343(%rip), %xmm1     # 0x69068
movsd 0xb31b(%rip), %xmm2     # 0x69048
addsd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
jae 0x5dd2d
movsd %xmm3, 0xb0(%r15)
movl %ecx, 0xb8(%r15)
movsd %xmm0, 0xc0(%r15)
testl %ecx, %ecx
jne 0x5ddf6
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 0x59a22
addsd -0x30(%rbp), %xmm0
mulsd 0xb2bc(%rip), %xmm0     # 0x69050
divsd 0xb2ac(%rip), %xmm0     # 0x69048
leaq -0x40(%rbp), %r14
leaq -0x50(%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 0xb269(%rip), %xmm0     # 0x69058
xorl %edx, %edx
callq 0xf53c
xorpd %xmm0, %xmm0
leaq -0x40(%rbp), %rsi
movapd %xmm0, (%rsi)
leaq -0x50(%rbp), %rdx
movq $0x0, (%rdx)
movq %rbx, %rdi
callq 0x61f4e
testb %al, %al
je 0x5df24
movsd -0x50(%rbp), %xmm6
movslq 0x14(%rbx), %rcx
movq 0x8(%rbx), %rax
imulq $0x178, %rcx, %rcx      # imm = 0x178
leaq (%rcx,%rax), %rdi
addq $-0xd0, %rdi
movsd 0x28(%rdi), %xmm0
ucomisd %xmm0, %xmm6
jbe 0x5de8d
movsd -0x40(%rbp), %xmm1
subsd 0x8(%rdi), %xmm1
movsd -0x38(%rbp), %xmm2
subsd 0x10(%rdi), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
movsd 0xb1e9(%rip), %xmm2     # 0x69058
ucomisd %xmm1, %xmm2
jbe 0x5def1
addq %rcx, %rax
addq $-0xc8, %rax
movupd (%rax), %xmm1
movapd %xmm1, -0x40(%rbp)
movapd %xmm0, %xmm6
jmp 0x5def1
jne 0x5def1
jp 0x5def1
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 0xb18f(%rip), %xmm5     # 0x69058
ucomisd %xmm4, %xmm5
jbe 0x5def1
addsd %xmm3, %xmm0
addsd %xmm2, %xmm1
movsd 0xb999(%rip), %xmm2     # 0x69878
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movsd %xmm6, -0x30(%rbp)
movl 0x28(%rbx), %edx
movsd 0x18(%rbx), %xmm0
leaq -0x40(%rbp), %rsi
callq 0xf572
movslq 0x14(%rbx), %rax
movq 0x8(%rbx), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xa8(%rcx,%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop