// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, 0x80(%rsp)
movq %rdi, 0x100(%rsp)
cmpl $0x0, 0x44(%rcx)
je 0x62436
movq %rcx, %rbx
movq %rdx, %r14
leaq 0xb8(%rsp), %r12
xorl %ecx, %ecx
leaq 0x40(%rsp), %rbp
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
leaq 0x1(%rcx), %r15
movl $0x1, %esi
cmpq $0x9, %rcx
jb 0x61f34
movl $0x4, %esi
movq %r15, %rcx
cmpq $0x63, %rcx
jbe 0x61f2d
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x61f32
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x61f34
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x61ef7
addl $-0x3, %esi
jmp 0x61f34
addl $-0x2, %esi
jmp 0x61f34
decl %esi
movslq 0x8(%r14), %rax
movq %rax, 0xf0(%rsp)
movslq 0xc(%r14), %rax
movq %rax, 0xf8(%rsp)
movl %esi, %esi
movq %r12, %r13
movq %r12, 0xa8(%rsp)
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x3a510
movq 0xa8(%rsp), %rdi
movl 0xb0(%rsp), %esi
movq %r15, 0xe8(%rsp)
movq %r15, %rdx
callq 0x5d707
movl $0x1, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x2732b(%rip), %rcx     # 0x892c9
callq 0x3a4d0
leaq 0x70(%rsp), %rsi
movq %rsi, 0x60(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0xc8(%rsp), %r15
je 0x61fd3
movq %rdx, 0x60(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x70(%rsp)
jmp 0x61fd9
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %r13, %r12
movq 0x8(%rax), %rdx
movq %rdx, 0x68(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x60(%rsp), %rdi
leaq 0x270ed(%rip), %rsi     # 0x890ed
callq 0x3a800
leaq 0x10(%rsp), %rsi
movq %rsi, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6202b
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x62031
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movl $0xd1b71759, %esi       # imm = 0xD1B71759
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl 0x44(%rbx), %r13d
movl $0x1, %eax
cmpl $0xa, %r13d
jb 0x6209d
movl $0x4, %eax
movl %r13d, %ecx
cmpl $0x63, %ecx
jbe 0x62096
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x6209b
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x6209d
movl %ecx, %edx
imulq %rsi, %rdx
shrq $0x2d, %rdx
addl $0x4, %eax
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x62065
addl $-0x3, %eax
jmp 0x6209d
addl $-0x2, %eax
jmp 0x6209d
decl %eax
movl %eax, %esi
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x20(%rsp), %rdi
xorl %edx, %edx
callq 0x3a510
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %esi
movl %r13d, %edx
callq 0x583c8
movq (%rsp), %rcx
movl $0xf, %esi
leaq 0x10(%rsp), %rax
cmpq %rax, %rcx
je 0x620de
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %r8
movq 0x28(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
leaq 0x70(%rsp), %r13
jbe 0x62111
movl $0xf, %esi
leaq 0x30(%rsp), %rdi
cmpq %rdi, 0x20(%rsp)
je 0x6210c
movq 0x30(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x62120
movq 0x20(%rsp), %rsi
movq %rsp, %rdi
callq 0x3a130
jmp 0x6212e
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a4d0
leaq 0x50(%rsp), %rsi
movq %rsi, 0x40(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x62153
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x62159
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x48(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq %rbp, %rdi
leaq 0x24fbe(%rip), %rsi     # 0x8713e
callq 0x3a800
leaq 0x98(%rsp), %rsi
movq %rsi, 0x88(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x621b9
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x621bf
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x90(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xd8(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq %r15, %rdi
leaq 0x231a7(%rip), %rdx     # 0x8539b
movq %rdx, %rsi
callq 0x44728
movq 0xf8(%rsp), %rdx
imulq 0xf0(%rsp), %rdx
decq %rdx
leaq 0x108(%rsp), %rdi
xorl %esi, %esi
leaq 0x88(%rsp), %rcx
movq %r15, %r8
callq 0x79316
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x6224f
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x62274
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x62290
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x622ac
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3a470
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x622c7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x622de
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x622fb
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3a470
movl 0xc(%r14), %r13d
testl %r13d, %r13d
jle 0x62395
movl %r13d, %r15d
leal -0x1(%r15), %r13d
cmpl $0x0, 0x8(%r14)
jle 0x6238b
xorl %r12d, %r12d
movq %rbp, %rdi
movq 0x80(%rsp), %rsi
movl %r12d, %edx
movl %r13d, %ecx
movq %r14, %r8
callq 0x7b0ea
movq %rbx, %rdi
movl %r13d, %esi
callq 0x62f34
movq %rax, (%rsp)
movl %edx, 0x8(%rsp)
movq %rsp, %rdi
movl %r12d, %esi
callq 0x63c6a
movq %rax, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
callq 0x63c3e
movq 0x100(%rsp), %rax
cmpb $0x1, 0x8(%rax)
jne 0x62382
movl $0x1, %esi
leaq 0x108(%rsp), %rdi
callq 0x798f8
incl %r12d
cmpl 0x8(%r14), %r12d
jl 0x62319
cmpl $0x2, %r15d
jge 0x62308
movq %rbx, %rdi
callq 0x62c08
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
divl 0x48(%rbx)
movl %eax, %r12d
movq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0x7b200
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
callq *0x18(%rax)
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
leaq 0xb8(%rsp), %r12
je 0x623f3
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x62418
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3a470
movl 0x44(%rbx), %eax
movq 0xe8(%rsp), %rcx
cmpq %rax, %rcx
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
jb 0x61ee0
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6255f
movq %r12, %r15
movq %rax, %rbx
jmp 0x624df
movq %r12, %r15
movq %rax, %rbx
jmp 0x624c3
movq %r12, %r15
movq %rax, %rbx
jmp 0x6249e
movq %rax, %rbx
movq %r13, %r15
jmp 0x62542
movq %r12, %r15
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x6249e
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x624c3
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x624df
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6250b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3a470
jmp 0x6250b
movq %r12, %r15
movq %rax, %rbx
jmp 0x62526
movq %r12, %r15
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x62526
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3a470
leaq 0x70(%rsp), %r13
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x62542
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x625ac
movq 0xb8(%rsp), %rsi
jmp 0x625a4
jmp 0x6255f
jmp 0x6255f
jmp 0x6255f
movq %rax, %rbx
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x62587
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x625ac
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3a470
movq %rbx, %rdi
callq 0x3a780