// File: /workspace/github_cpp_makefile_star2_O3/soybin[P]idyll/src/renderer.cpp
// Function: renderer::renderer(int, int, seed*, fractal*)
renderer::renderer(int WIDTH, int HEIGHT, seed* s, fractal* f) 	: WIDTH(WIDTH), HEIGHT(HEIGHT), s(s), f(f) {

	// get field of view from config file
	FOV = config::getInt("fov");

	// get sample value from config file
	SAMPLES = config::getInt("samples");

	// get surface bounces per ray
	BOUNCES = config::getInt("bounces");

	// set lower bound for randomness in sky noise
	SKY_NOISE = std::min(std::max(0.8, SAMPLES / 8.0), 1.0);

	// get random glossiness chance and glossiness amount from the
	// region's seed.
	// this represents the probability for a ray to be reflected
	// as glossy instead of as diffuse, and with which intensity
	// it will do so
	GLOSSINESS_CHANCE = s->values["GLOSSINESS_CHANCE"];
	GLOSSINESS_AMOUNT = s->values["GLOSSINESS_AMOUNT"];

	// random positioning of the camera along the surface of a
	// sphere with a certain radius
	math::vec3 dir;
	dir.x = s->values["xcameraDirection"];
	dir.y = s->values["ycameraDirection"];
	dir.z = s->values["zcameraDirection"];
	double distance = s->values["cameraDistance"];
	for (double radius = 0.0; radius < MAX_DIST; ) {
		cameraPosition = dir * radius;
		updateRotationMatrix();
		++radius;
		if (f->de(cameraPosition) < distance) continue;
		bool hit = false;
		for (int i = 0; i < 64; ++i) {
			double y = HEIGHT * s->d(0.0, 1.0);
			double x = WIDTH * s->d(0.0, 1.0);
			double d = march({cameraPosition, calculateRayDirection(x, y)});
			if (d != -1.0) {
				hit = true;
				break;
			}
		}
		if (hit) {
			break;
		}
	}

	// get directional light direction
	lightDirection.x = s->values["xlightDirection"];
	lightDirection.y = s->values["ylightDirection"];
	lightDirection.z = s->values["zlightDirection"];

	// get directional light color
	lightColor.x = s->values["xlightColor"];
	lightColor.y = s->values["ylightColor"];
	lightColor.z = s->values["zlightColor"];
	
	// get sky color
	skyColor.x = s->values["xskyColor"];
	skyColor.y = s->values["yskyColor"];
	skyColor.z = s->values["zskyColor"];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %r8, %r12
movq %rcx, %r14
movl %edx, %r13d
movq %rdi, %rbx
movl %esi, -0x68(%rbp)
movl %esi, (%rdi)
movl %edx, 0x4(%rdi)
addq $0x30, %rdi
movq %rdi, -0x60(%rbp)
callq 0x61cc
leaq 0x48(%rbx), %rdi
movq %rdi, -0x78(%rbp)
callq 0x61cc
leaq 0x60(%rbx), %r15
movq %r15, %rdi
callq 0x61cc
leaq 0x78(%rbx), %rdi
movq %rdi, -0x80(%rbp)
callq 0x61cc
xorpd %xmm0, %xmm0
movupd %xmm0, 0xb0(%rbx)
movupd %xmm0, 0xa0(%rbx)
movupd %xmm0, 0x90(%rbx)
movq %r12, -0x90(%rbp)
movq %r12, 0xc0(%rbx)
movq %r14, %r12
movq %rbx, -0x50(%rbp)
movq %r14, 0xc8(%rbx)
leaq -0xf0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x7a0b(%rip), %rsi      # 0xe8f8
leaq 0x7a07(%rip), %rdx      # 0xe8fb
leaq -0x100(%rbp), %rdi
callq 0x5366
leaq -0x100(%rbp), %rdi
callq 0x5800
movq -0x50(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6f2e
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0xd0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x79bc(%rip), %rsi      # 0xe8fc
leaq 0x79bc(%rip), %rdx      # 0xe903
leaq -0xe0(%rbp), %rdi
callq 0x5366
leaq -0xe0(%rbp), %rdi
callq 0x5800
movq -0x50(%rbp), %rcx
movl %eax, 0xc(%rcx)
movq -0xe0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6f81
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0xb0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x7971(%rip), %rsi      # 0xe904
leaq 0x7971(%rip), %rdx      # 0xe90b
leaq -0xc0(%rbp), %rdi
callq 0x5366
leaq -0xc0(%rbp), %rdi
callq 0x5800
movq %r15, -0x70(%rbp)
movq -0x50(%rbp), %rcx
movl %eax, 0x10(%rcx)
movq -0xc0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6fd8
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x32d0
movq -0x50(%rbp), %rbx
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rbx), %xmm0
mulsd 0x78a4(%rip), %xmm0     # 0xe890
maxsd 0x78a4(%rip), %xmm0     # 0xe898
movsd 0x767c(%rip), %xmm1     # 0xe678
minsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rbx)
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x78f8(%rip), %rsi      # 0xe90c
leaq 0x7902(%rip), %rdx      # 0xe91d
leaq -0x48(%rbp), %rdi
callq 0x5366
leaq 0x2718(%r12), %rdi
leaq -0x48(%rbp), %rsi
movq %rdi, -0x58(%rbp)
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x7057
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x78b9(%rip), %rsi      # 0xe91e
leaq 0x78c3(%rip), %rdx      # 0xe92f
callq 0x5366
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x709c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x118(%rbp), %rdi
callq 0x61cc
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x787a(%rip), %rsi      # 0xe930
leaq 0x7883(%rip), %rdx      # 0xe940
callq 0x5366
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x70f0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x7843(%rip), %rsi      # 0xe941
leaq 0x784c(%rip), %rdx      # 0xe951
callq 0x5366
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x7138
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x780c(%rip), %rsi      # 0xe952
leaq 0x7815(%rip), %rdx      # 0xe962
callq 0x5366
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, -0x108(%rbp)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x7180
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x77d5(%rip), %rsi      # 0xe963
leaq 0x77dc(%rip), %rdx      # 0xe971
callq 0x5366
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x71c8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
xorps %xmm0, %xmm0
cvtsi2sdl -0x68(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, -0x98(%rbp)
xorl %r14d, %r14d
leaq -0x148(%rbp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
leaq -0x48(%rbp), %r15
movq %r15, %rdi
leaq -0x118(%rbp), %rsi
callq 0x62a4
movq -0x60(%rbp), %rdi
movq %r15, %rsi
callq 0x6338
movq -0x50(%rbp), %rdi
callq 0x69b4
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movupd (%rcx), %xmm0
movupd %xmm0, (%rsp)
movq -0x90(%rbp), %rdi
callq 0x8b6e
movsd -0x88(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x7345
movl $0x40, %r15d
xorpd %xmm0, %xmm0
movq %r12, %rdi
movsd 0x740d(%rip), %xmm1     # 0xe678
callq 0xa334
movsd %xmm0, -0x68(%rbp)
xorpd %xmm0, %xmm0
movq %r12, %r13
movq %r12, %rdi
movsd 0x73f1(%rip), %xmm1     # 0xe678
callq 0xa334
movsd -0x68(%rbp), %xmm1
mulsd -0x98(%rbp), %xmm1
mulsd -0xa0(%rbp), %xmm0
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, -0x120(%rbp)
movups (%rcx), %xmm2
movaps %xmm2, -0x130(%rbp)
leaq -0x178(%rbp), %rdi
movq -0x50(%rbp), %r12
movq %r12, %rsi
callq 0x6bfe
movq -0x168(%rbp), %rax
movq %rax, 0x10(%rbx)
movups -0x178(%rbp), %xmm0
movups %xmm0, (%rbx)
movaps -0x130(%rbp), %xmm0
movaps %xmm0, -0x160(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x150(%rbp)
movapd -0x160(%rbp), %xmm0
movapd -0x150(%rbp), %xmm1
movaps -0x140(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r12, %rdi
callq 0x7704
ucomisd 0x7503(%rip), %xmm0     # 0xe838
jne 0x7355
jp 0x7355
movq %r13, %r12
decl %r15d
jne 0x725c
incl %r14d
cmpl $0x100, %r14d           # imm = 0x100
jne 0x71f2
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %r15
movq %r15, (%rdi)
leaq 0x760b(%rip), %rsi      # 0xe972
leaq 0x7613(%rip), %rdx      # 0xe981
callq 0x5366
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %r12
movq %r12, %rdi
movq -0x50(%rbp), %rbx
callq 0x8024
movq -0x80(%rbp), %r14
movsd (%rax), %xmm0
movq -0x78(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x73ac
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x75c8(%rip), %rsi      # 0xe982
leaq 0x75d0(%rip), %rdx      # 0xe991
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x73f0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x7594(%rip), %rsi      # 0xe992
leaq 0x759c(%rip), %rdx      # 0xe9a1
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x7434
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x7560(%rip), %rsi      # 0xe9a2
leaq 0x7564(%rip), %rdx      # 0xe9ad
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movq -0x70(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x747b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x7525(%rip), %rsi      # 0xe9ae
leaq 0x7529(%rip), %rdx      # 0xe9b9
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x74bf
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x74ed(%rip), %rsi      # 0xe9ba
leaq 0x74f1(%rip), %rdx      # 0xe9c5
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x70(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x7503
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x74b5(%rip), %rsi      # 0xe9c6
leaq 0x74b7(%rip), %rdx      # 0xe9cf
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, (%r14)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x7547
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x747b(%rip), %rsi      # 0xe9d0
leaq 0x747d(%rip), %rdx      # 0xe9d9
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x80(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x758e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x743e(%rip), %rsi      # 0xe9da
leaq 0x7440(%rip), %rdx      # 0xe9e3
callq 0x5366
leaq -0x48(%rbp), %rsi
movq %r12, %rdi
callq 0x8024
movsd (%rax), %xmm0
movsd %xmm0, 0x88(%rbx)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x75d5
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
jmp 0x76b4
jmp 0x7642
jmp 0x76b4
movq %rax, %r14
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x76b7
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
jmp 0x76b7
jmp 0x76b4
movq %rax, %r14
movq -0xc0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x76b7
movq -0xb0(%rbp), %rsi
jmp 0x7652
jmp 0x76b4
movq %rax, %r14
movq -0xe0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x76b7
movq -0xd0(%rbp), %rsi
jmp 0x7652
jmp 0x76b4
movq %rax, %r14
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x76b7
movq -0xf0(%rbp), %rsi
jmp 0x7652
jmp 0x76b4
jmp 0x76b4
jmp 0x76b4
jmp 0x76b4
jmp 0x76b4
movq %rax, %r14
movq -0x50(%rbp), %rax
leaq 0x90(%rax), %rbx
movq 0xa8(%rax), %rdi
testq %rdi, %rdi
je 0x76e1
movq -0x50(%rbp), %rax
movq 0xb8(%rax), %rsi
subq %rdi, %rsi
callq 0x32d0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x76fc
movq -0x50(%rbp), %rax
movq 0xa0(%rax), %rsi
subq %rdi, %rsi
callq 0x32d0
movq %r14, %rdi
callq 0x3490