// File: /workspace/github_cpp_makefile_star2_O1/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 0x2f3b6
cvtss2sd %xmm0, %xmm0
mulsd 0x8cd5b(%rip), %xmm0    # 0x99448
addsd 0xcb133(%rip), %xmm0    # 0xd7828
movsd %xmm0, 0xcb12b(%rip)    # 0xd7828
movq 0x11c8(%r13), %rax
cmpq %rax, 0x11d0(%r13)
je 0xc9f1
xorl %r15d, %r15d
leaq 0xcd805(%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 0xc8c5
callq 0xb96c
movl %ebx, %eax
movl %r14d, %ecx
imulq $0x6c, %rax, %rax
addq %r12, %rax
cmpl $0x1, 0x8(%rax,%rcx,4)
jne 0xc8c5
movq %r15, -0x70(%rbp)
callq 0xa168
movq (%rax), %rbx
movq 0x8(%rax), %rax
cmpq %rax, %rbx
je 0xc8ed
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 0xa726
movapd %xmm0, -0x60(%rbp)
movq %r15, %rdi
callq 0xa732
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 0x9f00
cvtss2sd %xmm0, %xmm0
mulsd 0x8cc78(%rip), %xmm0    # 0x99450
addsd 0x8cc78(%rip), %xmm0    # 0x99458
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
movss 0x8cb09(%rip), %xmm0    # 0x992f8
movss 0x8cb09(%rip), %xmm1    # 0x99300
callq 0x9f4d
movss %xmm0, -0x60(%rbp)
movq %r15, %rdi
callq 0xa6b2
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 0xc78d
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 0xc900
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0xe6ee
xorps %xmm0, %xmm0
cvtsd2ss 0xcaf4c(%rip), %xmm0    # 0xd7828
movl %eax, %edi
movl $0xff00d3ff, %esi       # imm = 0xFF00D3FF
callq 0x9dff
jmp 0xc9c6
xorpd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, -0x38(%rbp)
xorpd %xmm1, %xmm1
movsd 0x8cb4c(%rip), %xmm2    # 0x99458
callq 0x9d70
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
xorpd %xmm1, %xmm1
movsd -0x38(%rbp), %xmm0
movsd 0x8cb35(%rip), %xmm2    # 0x99460
callq 0x9d70
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
xorpd %xmm1, %xmm1
movsd -0x40(%rbp), %xmm0
movsd 0x8cb18(%rip), %xmm2    # 0x99460
callq 0x9d70
cvttsd2si %xmm0, %r14d
xorpd %xmm1, %xmm1
movsd -0x60(%rbp), %xmm0
movsd 0x8cafd(%rip), %xmm2    # 0x99460
callq 0x9d70
cvttsd2si %xmm0, %r12d
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0xe6ee
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 0x9dff
xorps %xmm0, %xmm0
cvtsd2ss 0xcae77(%rip), %xmm0    # 0xd7828
movl %r15d, %edi
movl %eax, %esi
callq 0x9dff
movq -0x70(%rbp), %r15
leaq 0xcd55a(%rip), %r12     # 0xd9f20
movq %rbx, %rdi
movl %eax, %esi
callq 0xe6be
incl %r15d
movq 0x11c8(%r13), %rax
movq 0x11d0(%r13), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0xc71f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq