// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
callq 0x2e7fe
cvtss2sd %xmm0, %xmm0
mulsd 0x8c355(%rip), %xmm0    # 0x98418
addsd 0xca77d(%rip), %xmm0    # 0xd6848
movsd %xmm0, 0xca775(%rip)    # 0xd6848
leaq 0x11c8(%rbx), %r14
xorl %r15d, %r15d
movq %rbx, -0x60(%rbp)
movq %r14, -0x58(%rbp)
movl %r15d, %r15d
movq 0x11d0(%rbx), %rax
subq 0x11c8(%rbx), %rax
sarq $0x3, %rax
cmpq %r15, %rax
jbe 0xc334
movq %r14, %rdi
movq %r15, %rsi
callq 0xc620
movq (%rax), %r12
cvttss2si 0x10(%r12), %rdi
cvttss2si 0x18(%r12), %rsi
callq 0xbefc
cmpl $0x1, %eax
jne 0xc243
movq %r12, -0x38(%rbp)
movq %r15, -0x68(%rbp)
callq 0x9f9a
movq (%rax), %r14
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq -0x70(%rbp), %r14
je 0xc264
movq (%r14), %r13
movq %r13, %rdi
movss %xmm0, -0x2c(%rbp)
callq 0xa4bc
movapd %xmm0, -0x50(%rbp)
movq %r13, %rdi
callq 0xa4c8
movapd %xmm0, %xmm3
movq -0x38(%rbp), %rax
movsd 0x10(%rax), %xmm0
movss 0x18(%rax), %xmm1
xorps %xmm2, %xmm2
movaps -0x50(%rbp), %xmm4
movss %xmm4, %xmm2            # xmm2 = xmm4[0],xmm2[1,2,3]
callq 0x9d91
cvtss2sd %xmm0, %xmm0
mulsd 0x8c27a(%rip), %xmm0    # 0x98420
addsd 0x8c27a(%rip), %xmm0    # 0x98428
cvtsd2ss %xmm0, %xmm2
movss 0x8c10e(%rip), %xmm0    # 0x982c8
movss 0x8c10e(%rip), %xmm1    # 0x982d0
callq 0x9dca
movss %xmm0, -0x50(%rbp)
movq %r13, %rdi
callq 0xa44c
movl %eax, %ecx
shrl $0x8, %ecx
movl %eax, %edx
movl $0xff, %esi
andl %esi, %eax
cvtsi2ss %eax, %xmm0
shrl $0x10, %edx
cvtsi2ss %r12d, %xmm1
movss -0x50(%rbp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %r12d
andl %esi, %ecx
cvtsi2ss %ecx, %xmm0
cvtsi2ss %r15d, %xmm1
mulss %xmm2, %xmm0
movaps %xmm2, %xmm3
andl %esi, %edx
cvtsi2ss %edx, %xmm2
addss %xmm1, %xmm0
cvtsi2ss %ebx, %xmm1
cvttss2si %xmm0, %r15d
movss -0x2c(%rbp), %xmm0
mulss %xmm3, %xmm2
addss %xmm1, %xmm2
cvttss2si %xmm2, %ebx
addss %xmm3, %xmm0
addq $0x8, %r14
jmp 0xc151
movq %r12, %rdi
callq 0xde52
cvtsd2ss 0xca5f5(%rip), %xmm0    # 0xd6848
movl %eax, %edi
movl $0xff00d3ff, %esi       # imm = 0xFF00D3FF
callq 0x9c9f
jmp 0xc322
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
movsd 0x8c1b5(%rip), %xmm2    # 0x98428
callq 0x9c10
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
cvtsi2sd %r12d, %xmm0
xorps %xmm1, %xmm1
movsd 0x8c19f(%rip), %xmm2    # 0x98430
callq 0x9c10
cvttsd2si %xmm0, %r14d
cvtsi2sd %r15d, %xmm0
xorps %xmm1, %xmm1
movsd 0x8c185(%rip), %xmm2    # 0x98430
callq 0x9c10
cvttsd2si %xmm0, %r15d
cvtsi2sd %ebx, %xmm0
xorps %xmm1, %xmm1
movsd 0x8c16c(%rip), %xmm2    # 0x98430
callq 0x9c10
cvttsd2si %xmm0, %ebx
movq -0x38(%rbp), %r12
movq %r12, %rdi
callq 0xde52
movl %eax, %r13d
shll $0x10, %ebx
shll $0x8, %r15d
movzwl %r15w, %eax
orl %ebx, %eax
movzbl %r14b, %esi
orl %eax, %esi
orl $0xff000000, %esi       # imm = 0xFF000000
movl $0xfff17900, %edi       # imm = 0xFFF17900
movss -0x2c(%rbp), %xmm0
callq 0x9c9f
cvtsd2ss 0xca53c(%rip), %xmm0    # 0xd6848
movl %r13d, %edi
movl %eax, %esi
callq 0x9c9f
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r14
movq -0x68(%rbp), %r15
movq %r12, %rdi
movl %eax, %esi
callq 0xde22
incl %r15d
jmp 0xc0e5
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop