// File: /workspace/github_cpp_makefile_star2_O3/Lut99[P]RayTracer/src/lib/Renderer.cpp
// Function: RayTracer::Renderer::render_animation(RayTracer::RenderWorld*, RayTracer::Camera*, RayTracer::Frames&)
void Renderer::render_animation(RenderWorld* world, Camera* cam, Frames& out) {
    #ifdef THREADED
    ThreadPool pool(this->n_threads, this->batch_size);
    #endif

    for (std::size_t i = 0; i < out.n_frames; i++) {
        // Render this frame
        ProgressBar prgrs(0, cam->width * cam->height - 1, "(" + to_string(i + 1) + "/" + to_string(out.n_frames) + ")", "");

        #ifndef THREADED

        for (int y = cam->height-1; y >= 0; y--) {
            for (int x = 0; x < cam->width; x++) {
                // Render the pixel
                out[y][x] = world->render_pixel(x, y, *cam);

                if (this->show_progressbar) {
                    prgrs.update();
                }
            }
        }

        #else

        // Use the thread pool to render it
        unsigned long batch_index = 0;
        unsigned long to_do = cam->width * cam->height;
        while (batch_index < to_do) {
            // Update the progressbar in any case for smoothness
            if (this->show_progressbar) {
                prgrs.set(batch_index);
            }

            // If a the queue is full, continue
            if (pool.batch_queue_full()) {
                pool.wait();
            }

            // Create a new batch and append it
            PixelBatch batch = pool.get_batch(cam->width, cam->height, batch_index);
            batch.camera = cam;
            batch.world = world;
            batch.out = &out.get_current_frame();
            pool.add_batch(batch);
        }

        // Make sure the threads are complete
        pool.complete();

        #endif

        // Update the frames
        out.next();

        // Update the world & camera
        chrono::milliseconds time_passed(1000 / out.fps);
        world->update(time_passed);
        cam->update(time_passed);
    }

    #ifdef THREADED
    pool.stop();
    #endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x100(%rsp)
cmpl $0x0, 0x44(%rcx)
je 0x61ef2
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
xorl %ecx, %ecx
leaq 0x28(%rsp), %rbp
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
leaq 0x1(%rcx), %r12
movl $0x1, %esi
cmpq $0x9, %rcx
jb 0x619df
movl $0x4, %esi
movq %r12, %rcx
cmpq $0x63, %rcx
jbe 0x619d8
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x619dd
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x619df
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x619a2
addl $-0x3, %esi
jmp 0x619df
addl $-0x2, %esi
jmp 0x619df
decl %esi
movslq 0x8(%r14), %rax
movq %rax, 0xf8(%rsp)
movslq 0xc(%r14), %rax
movq %rax, 0x48(%rsp)
movl %esi, %esi
leaq 0xc0(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
xorl %edx, %edx
callq 0x3a520
movq 0xb0(%rsp), %rdi
movl 0xb8(%rsp), %esi
movq %r12, 0xf0(%rsp)
movq %r12, %rdx
callq 0x5d303
movl $0x1, %r8d
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x2687e(%rip), %rcx     # 0x882c9
callq 0x3a4e0
leaq 0x80(%rsp), %r13
movq %r13, 0x70(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x61a7e
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x61a86
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x70(%rsp), %rdi
leaq 0x26643(%rip), %rsi     # 0x880ed
callq 0x3a810
leaq 0x18(%rsp), %rsi
movq %rsi, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x61ad7
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x61add
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movl $0xd1b71759, %esi       # imm = 0xD1B71759
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl 0x44(%rbx), %r13d
movl $0x1, %eax
cmpl $0xa, %r13d
jb 0x61b49
movl $0x4, %eax
movl %r13d, %ecx
cmpl $0x63, %ecx
jbe 0x61b42
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x61b47
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x61b49
movl %ecx, %edx
imulq %rsi, %rdx
shrq $0x2d, %rdx
addl $0x4, %eax
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x61b11
addl $-0x3, %eax
jmp 0x61b49
addl $-0x2, %eax
jmp 0x61b49
decl %eax
movl %eax, %esi
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
xorl %edx, %edx
callq 0x3a520
movq 0x50(%rsp), %rdi
movl 0x58(%rsp), %esi
movl %r13d, %edx
callq 0x581f2
movq 0x8(%rsp), %rcx
movl $0xf, %edi
leaq 0x18(%rsp), %rax
cmpq %rax, %rcx
je 0x61b8b
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
leaq 0x80(%rsp), %r13
jbe 0x61bc4
movl $0xf, %edi
leaq 0x60(%rsp), %r9
cmpq %r9, %rsi
je 0x61bbf
movq 0x60(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x61bd0
leaq 0x8(%rsp), %rdi
callq 0x3a130
jmp 0x61bde
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a4e0
leaq 0x38(%rsp), %rsi
movq %rsi, 0x28(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x61c03
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x61c09
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq %rbp, %rdi
leaq 0x2450b(%rip), %rsi     # 0x8613b
callq 0x3a810
leaq 0xa0(%rsp), %rsi
movq %rsi, 0x90(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0xd0(%rsp), %r12
je 0x61c71
movq %rdx, 0x90(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xa0(%rsp)
jmp 0x61c77
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x98(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xe0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq %r12, %rdi
leaq 0x226ec(%rip), %rdx     # 0x84398
movq %rdx, %rsi
callq 0x44390
movq 0x48(%rsp), %rdx
imulq 0xf8(%rsp), %rdx
decq %rdx
leaq 0x108(%rsp), %rdi
xorl %esi, %esi
leaq 0x90(%rsp), %rcx
movq %r12, %r8
callq 0x78936
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x61d04
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x61d29
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x61d45
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x61d61
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x61d7d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x61d97
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x61dbc
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x3a480
movl 0xc(%r14), %r13d
testl %r13d, %r13d
jle 0x61e5e
movl 0x8(%r14), %eax
movl %r13d, %edx
movq %rdx, 0x48(%rsp)
leal -0x1(%rdx), %r13d
testl %eax, %eax
jle 0x61e53
xorl %r12d, %r12d
movq %rbp, %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r13d, %ecx
movq %r14, %r8
callq 0x7a78c
movq %rbx, %rdi
movl %r13d, %esi
callq 0x629fc
movq %rax, 0x8(%rsp)
movl %edx, 0x10(%rsp)
leaq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x6373e
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x63712
movq 0x100(%rsp), %rax
cmpb $0x1, 0x8(%rax)
jne 0x61e47
movl $0x1, %esi
leaq 0x108(%rsp), %rdi
callq 0x78f2e
incl %r12d
movl 0x8(%r14), %eax
cmpl %eax, %r12d
jl 0x61de0
cmpl $0x2, 0x48(%rsp)
jge 0x61dcd
movq %rbx, %rdi
callq 0x626c2
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
divl 0x48(%rbx)
movl %eax, %r12d
movq %r15, %rdi
movq %r12, %rsi
callq 0x7a8a2
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
callq *0x18(%rax)
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x61eaf
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x61ed4
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3a480
movl 0x44(%rbx), %eax
movq 0xf0(%rsp), %rcx
cmpq %rax, %rcx
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
jb 0x6198b
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x62012
movq %rax, %rbx
jmp 0x61f89
movq %rax, %rbx
jmp 0x61f6d
movq %rax, %rbx
jmp 0x61f48
movq %rax, %rbx
jmp 0x61fed
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x61f48
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x61f6d
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x61f89
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x61faf
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3a480
jmp 0x61faf
movq %rax, %rbx
jmp 0x61fd3
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x61fcb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a480
leaq 0x80(%rsp), %r13
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x61fed
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x6205f
movq 0xc0(%rsp), %rsi
jmp 0x62057
jmp 0x62012
jmp 0x62012
jmp 0x62012
movq %rax, %rbx
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x6203a
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x6205f
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3a480
movq %rbx, %rdi
callq 0x3a790
nop