// File: /workspace/github_cpp_makefile_star2_O3/KellerMartins[P]PDS2-Pacman/source/game/mapa.cpp
// Function: Mapa::OnUpdate()
void Mapa::OnUpdate(){
	tempoInterp += GetFrameTime()*0.0125;
	for(unsigned int i=0; i<_objetosMapa.size(); i++){
		Object3D* objMapa = _objetosMapa.at(i);

		if(Mapa::GetElementoMapa(objMapa->position.x, objMapa->position.z) == Parede){
			float val = 0;
			int luzR = 0;
			int luzG = 0;
			int luzB = 0;

			std::vector<Enemy*>& inimigos = Enemy::GetEnemies(); 
			for(Enemy* e : inimigos){
				Vector3 pos = {(float)e->GetX(), 0, (float)e->GetY()};
				float distVal = Smoothstep(0.4,0.8,1.0 - Distance(objMapa->position, pos)/4.0);

				Color corInimigo = e->GetColor();
				luzR += corInimigo.r*distVal;
				luzG += corInimigo.g*distVal;
				luzB += corInimigo.b*distVal;
				val += distVal;
			}

			val = Clamp(val, 0, 1);
			luzR = Clamp(luzR, 0, 255);
			luzG = Clamp(luzG, 0, 255);
			luzB = Clamp(luzB, 0, 255);
			Color luz = (Color){(unsigned char)luzR, (unsigned char)luzG, (unsigned char)luzB, 255};

			objMapa->SetColor(Lerp(objMapa->GetColor(), Lerp(BLUE, luz, val), tempoInterp));
		}
		else{
			objMapa->SetColor(Lerp(objMapa->GetColor(), { 255, 211, 0, 255 }, tempoInterp));
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r13
callq 0x2f43a
cvtss2sd %xmm0, %xmm0
mulsd 0x8cca5(%rip), %xmm0    # 0x99448
addsd 0xcb07d(%rip), %xmm0    # 0xd7828
movsd %xmm0, 0xcb075(%rip)    # 0xd7828
movq 0x11c8(%r13), %rax
cmpq %rax, 0x11d0(%r13)
je 0xcaa7
xorl %r15d, %r15d
leaq 0xcd74f(%rip), %r12     # 0xd9f20
movq %r13, -0x68(%rbp)
movq (%rax,%r15,8), %rax
cvttss2si 0x10(%rax), %rbx
movq %rax, -0x48(%rbp)
cvttss2si 0x18(%rax), %r14
cmpl $0x15, %ebx
setae %al
cmpl $0x1b, %r14d
setae %cl
orb %al, %cl
jne 0xc97b
callq 0xb940
movl %ebx, %eax
movl %r14d, %ecx
imulq $0x6c, %rax, %rax
addq %r12, %rax
cmpl $0x1, 0x8(%rax,%rcx,4)
jne 0xc97b
movq %r15, -0x70(%rbp)
callq 0xa154
movq (%rax), %rbx
movq 0x8(%rax), %rax
cmpq %rax, %rbx
je 0xc9a3
xorl %r12d, %r12d
xorps %xmm1, %xmm1
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %rax, -0x40(%rbp)
movss %xmm1, -0x2c(%rbp)
movq (%rbx), %r15
movq %r15, %rdi
callq 0xa6f6
movapd %xmm0, -0x60(%rbp)
movq %r15, %rdi
callq 0xa702
movapd %xmm0, %xmm3
movq -0x48(%rbp), %rax
movsd 0x10(%rax), %xmm0
movss 0x18(%rax), %xmm1
xorps %xmm2, %xmm2
movaps -0x60(%rbp), %xmm4
movss %xmm4, %xmm2            # xmm2 = xmm4[0],xmm2[1,2,3]
callq 0x9efc
cvtss2sd %xmm0, %xmm0
mulsd 0x8cbc2(%rip), %xmm0    # 0x99450
addsd 0x8cbc2(%rip), %xmm0    # 0x99458
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
movss 0x8ca53(%rip), %xmm0    # 0x992f8
movss 0x8ca53(%rip), %xmm1    # 0x99300
callq 0x9f38
movss %xmm0, -0x60(%rbp)
movq %r15, %rdi
callq 0xa686
movl %eax, %ecx
movl %eax, %edx
movl $0xff, %esi
andl %esi, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movq -0x40(%rbp), %rax
shrl $0x8, %ecx
xorps %xmm1, %xmm1
cvtsi2ss %r12d, %xmm1
movss -0x60(%rbp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %r12d
andl %esi, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
shrl $0x10, %edx
xorps %xmm1, %xmm1
cvtsi2ss %r13d, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %r13d
andl %esi, %edx
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %r14d, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss -0x2c(%rbp), %xmm1
cvttss2si %xmm0, %r14d
addss %xmm2, %xmm1
addq $0x8, %rbx
cmpq %rax, %rbx
jne 0xc843
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
movsd %xmm1, -0x38(%rbp)
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd %xmm1, -0x40(%rbp)
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd %xmm1, -0x60(%rbp)
movq -0x68(%rbp), %r13
jmp 0xc9b6
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0xe79e
xorps %xmm0, %xmm0
cvtsd2ss 0xcae96(%rip), %xmm0    # 0xd7828
movl %eax, %edi
movl $0xff00d3ff, %esi       # imm = 0xFF00D3FF
callq 0x9dfb
jmp 0xca7c
xorpd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, -0x38(%rbp)
xorpd %xmm1, %xmm1
movsd 0x8ca96(%rip), %xmm2    # 0x99458
callq 0x9d6c
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
xorpd %xmm1, %xmm1
movsd -0x38(%rbp), %xmm0
movsd 0x8ca7f(%rip), %xmm2    # 0x99460
callq 0x9d6c
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
xorpd %xmm1, %xmm1
movsd -0x40(%rbp), %xmm0
movsd 0x8ca62(%rip), %xmm2    # 0x99460
callq 0x9d6c
cvttsd2si %xmm0, %r14d
xorpd %xmm1, %xmm1
movsd -0x60(%rbp), %xmm0
movsd 0x8ca47(%rip), %xmm2    # 0x99460
callq 0x9d6c
cvttsd2si %xmm0, %r12d
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0xe79e
movl %eax, %r15d
shll $0x10, %r12d
shll $0x8, %r14d
movzwl %r14w, %eax
orl %r12d, %eax
movzbl -0x38(%rbp), %esi
orl %eax, %esi
orl $0xff000000, %esi       # imm = 0xFF000000
movl $0xfff17900, %edi       # imm = 0xFFF17900
movss -0x2c(%rbp), %xmm0
callq 0x9dfb
xorps %xmm0, %xmm0
cvtsd2ss 0xcadc1(%rip), %xmm0    # 0xd7828
movl %r15d, %edi
movl %eax, %esi
callq 0x9dfb
movq -0x70(%rbp), %r15
leaq 0xcd4a4(%rip), %r12     # 0xd9f20
movq %rbx, %rdi
movl %eax, %esi
callq 0xe76e
incl %r15d
movq 0x11c8(%r13), %rax
movq 0x11d0(%r13), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0xc7d5
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq