// File: /workspace/github_cpp_makefile_star2_O2/tkaczenko[P]asteroids-clone/src/GameEngine.cpp
// Function: GameEngine::collisions()
void GameEngine::collisions()
{
    for (int i=0; i != 3; i++) {
        for (auto rock_it = rocks.begin(); rock_it != rocks.end(); rock_it++) {
            for(int j = 0; j < ROCK_PARTS; j++) {
                if ( SDL_IntersectRectAndLine(&player.getColPoints()[i],
                                                &rock_it->second.getLines()[j].x,
                                                &rock_it->second.getLines()[j].y,
                                                &rock_it->second.getLines()[j+1].x,
                                                &rock_it->second.getLines()[j+1].y)) {
                    player.setAlive(false);
                }
            }
        }
    }
    BEGIN_MISSILE_COLLISION:
    for (auto bul_it = player.getBullets()->begin(); bul_it != player.getBullets()->end(); bul_it++) {
        SDL_Rect bul = {bul_it->second.getPosition().x, bul_it->second.getPosition().y, 10, 10};
        for (auto rock_it = rocks.begin(); rock_it != rocks.end(); rock_it++) {
            for(int j = 0; j < ROCK_PARTS; j++) {
                if ( SDL_IntersectRectAndLine(&bul,
                                                &rock_it->second.getLines()[j].x,
                                                &rock_it->second.getLines()[j].y,
                                                &rock_it->second.getLines()[j+1].x,
                                                &rock_it->second.getLines()[j+1].y) ) {
                    rocks.erase(rock_it);
                    player.getBullets()->erase(bul_it++);

                    if (rock_it->second.getType() == BIG_ROCK) {
                        this->spawnRock(MED_ROCK, 4, rock_it->second.getPosition().x, rock_it->second.getPosition().y);
                    } else if (rock_it->second.getType() == MED_ROCK) {
                        this->spawnRock(SMALL_ROCK, 2, rock_it->second.getPosition().x, rock_it->second.getPosition().y);
                    } else if (rock_it->second.getType() == SMALL_ROCK) {

                    }
                    goto BEGIN_MISSILE_COLLISION;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x98(%rdi), %rax
movq %rax, -0x48(%rbp)
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0x3133
movq 0xa8(%rbx), %r14
movq %r13, -0x40(%rbp)
shlq $0x4, %r13
cmpq -0x48(%rbp), %r14
je 0x312a
leaq 0xdc(%r14), %rsi
pushq $0xa
popq %r12
subq $0x1, %r12
jb 0x311d
movq 0x38(%rbx), %rdi
addq %r13, %rdi
leaq 0x4(%rsi), %rdx
leaq 0x8(%rsi), %r15
leaq 0xc(%rsi), %r8
movq %r15, %rcx
callq 0x20a0
testl %eax, %eax
je 0x3118
movb $0x0, 0x88(%rbx)
movq %r15, %rsi
jmp 0x30ec
movq %r14, %rdi
callq 0x21d0
movq %rax, %r14
jmp 0x30db
movq -0x40(%rbp), %r13
incq %r13
jmp 0x30c6
leaq 0x40(%rbx), %rax
movq %rax, -0x58(%rbp)
leaq 0x48(%rbx), %rax
movq %rax, -0x60(%rbp)
leaq 0x90(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq -0x70(%rbp), %r12
movq 0x58(%rbx), %rax
cmpq -0x60(%rbp), %rax
je 0x325a
movq %rax, -0x40(%rbp)
movq 0x50(%rax), %rax
movl %eax, -0x70(%rbp)
shrq $0x20, %rax
movl %eax, -0x6c(%rbp)
movabsq $0xa0000000a, %rax      # imm = 0xA0000000A
movq %rax, -0x68(%rbp)
movq 0xa8(%rbx), %r14
cmpq -0x48(%rbp), %r14
je 0x31cb
leaq 0xdc(%r14), %rsi
pushq $0xb
popq %r13
decq %r13
je 0x31be
leaq 0x8(%rsi), %r15
leaq 0x4(%rsi), %rdx
leaq 0x8(%rsi), %rcx
leaq 0xc(%rsi), %r8
movq %r12, %rdi
callq 0x20a0
movq %r15, %rsi
testl %eax, %eax
je 0x3198
jmp 0x31d6
movq %r14, %rdi
callq 0x21d0
movq %rax, %r14
jmp 0x3187
movq -0x40(%rbp), %rdi
callq 0x21d0
jmp 0x3156
movq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x375a
movq -0x58(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x37bc
movl 0x74(%r14), %eax
cmpl $0x25a, %eax            # imm = 0x25A
je 0x3215
cmpl $0x259, %eax            # imm = 0x259
jne 0x3152
movl $0x25a, -0x38(%rbp)     # imm = 0x25A
movl $0x4, -0x34(%rbp)
jmp 0x3223
movl $0x25b, -0x38(%rbp)     # imm = 0x25B
movl $0x2, -0x34(%rbp)
movq 0x50(%r14), %rax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x30(%rbp)
shrq $0x20, %rax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x2c(%rbp)
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x34(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x2c(%rbp), %r8
callq 0x2d92
jmp 0x3152
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop