// File: /workspace/github_cpp_makefile_star2_O1/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 $0x198, %rsp            # imm = 0x198
movq %r8, %r12
movq %rcx, %r13
movl %edx, %r15d
movq %rdi, %rbx
movl %esi, -0x70(%rbp)
movl %esi, (%rdi)
movl %edx, 0x4(%rdi)
addq $0x30, %rdi
movq %rdi, -0x68(%rbp)
callq 0x61a4
leaq 0x48(%rbx), %rdi
movq %rdi, -0x88(%rbp)
callq 0x61a4
leaq 0x60(%rbx), %rdi
movq %rdi, -0x80(%rbp)
callq 0x61a4
leaq 0x78(%rbx), %r14
movq %r14, %rdi
callq 0x61a4
xorpd %xmm0, %xmm0
movupd %xmm0, 0xb0(%rbx)
movupd %xmm0, 0xa0(%rbx)
movupd %xmm0, 0x90(%rbx)
movq %r12, 0xc0(%rbx)
movq %rbx, -0x50(%rbp)
movq %r13, 0xc8(%rbx)
leaq -0xf8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x7956(%rip), %rsi      # 0xe900
leaq 0x7952(%rip), %rdx      # 0xe903
leaq -0x108(%rbp), %rdi
callq 0x5342
leaq -0x108(%rbp), %rdi
callq 0x57d8
movq -0x50(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq -0x108(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6feb
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0xd8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x7907(%rip), %rsi      # 0xe904
leaq 0x7907(%rip), %rdx      # 0xe90b
leaq -0xe8(%rbp), %rdi
callq 0x5342
leaq -0xe8(%rbp), %rdi
callq 0x57d8
movq -0x50(%rbp), %rcx
movl %eax, 0xc(%rcx)
movq -0xe8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x703e
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0xb8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x78bc(%rip), %rsi      # 0xe90c
leaq 0x78bc(%rip), %rdx      # 0xe913
leaq -0xc8(%rbp), %rdi
callq 0x5342
leaq -0xc8(%rbp), %rdi
callq 0x57d8
movq -0x50(%rbp), %rcx
movl %eax, 0x10(%rcx)
movq -0xc8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x7091
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x32d0
movq -0x50(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rax), %xmm0
mulsd 0x77f3(%rip), %xmm0     # 0xe898
maxsd 0x77f3(%rip), %xmm0     # 0xe8a0
movsd 0x75c3(%rip), %xmm1     # 0xe678
minsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rax)
leaq -0x38(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x7847(%rip), %rsi      # 0xe914
leaq 0x7851(%rip), %rdx      # 0xe925
leaq -0x48(%rbp), %rdi
callq 0x5342
leaq 0x2718(%r13), %rdi
leaq -0x48(%rbp), %rsi
movq %rdi, -0x58(%rbp)
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x7113
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x7805(%rip), %rsi      # 0xe926
leaq 0x780f(%rip), %rdx      # 0xe937
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x28(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x715c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x120(%rbp), %rdi
callq 0x61a4
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x77c2(%rip), %rsi      # 0xe938
leaq 0x77cb(%rip), %rdx      # 0xe948
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movsd %xmm0, -0x120(%rbp)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x71b0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x778b(%rip), %rsi      # 0xe949
leaq 0x7794(%rip), %rdx      # 0xe959
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x71f8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x7754(%rip), %rsi      # 0xe95a
leaq 0x775d(%rip), %rdx      # 0xe96a
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x7240
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x771d(%rip), %rsi      # 0xe96b
leaq 0x7724(%rip), %rdx      # 0xe979
callq 0x5342
movq %r14, -0x78(%rbp)
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x728c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
xorps %xmm0, %xmm0
cvtsi2sdl -0x70(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, -0xa0(%rbp)
xorpd %xmm0, %xmm0
movl $0x1, %ebx
movq %r12, -0x90(%rbp)
leaq -0x48(%rbp), %r14
movq %r14, %rdi
leaq -0x120(%rbp), %rsi
movsd %xmm0, -0x60(%rbp)
callq 0x627c
movq -0x68(%rbp), %rdi
movq %r14, %rsi
callq 0x6310
movq -0x50(%rbp), %rdi
callq 0x6a30
movsd -0x60(%rbp), %xmm0
addsd 0x7382(%rip), %xmm0     # 0xe678
movsd %xmm0, -0x60(%rbp)
movq -0x68(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movupd (%rcx), %xmm0
movupd %xmm0, (%rsp)
movq %r12, %rdi
callq 0x8d1c
movsd -0x98(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x733f
movsd -0x60(%rbp), %xmm0
movsd 0x7574(%rip), %xmm1     # 0xe8a8
ucomisd %xmm0, %xmm1
ja 0x72bc
jmp 0x746e
xorl %r12d, %r12d
xorl %r14d, %r14d
xorpd %xmm0, %xmm0
movq %r13, %rdi
movsd 0x7324(%rip), %xmm1     # 0xe678
callq 0xa500
movsd %xmm0, -0x70(%rbp)
xorpd %xmm0, %xmm0
movq %r13, %rdi
movsd 0x730b(%rip), %xmm1     # 0xe678
callq 0xa500
movq %r13, %r15
movsd -0x70(%rbp), %xmm1
mulsd -0xa0(%rbp), %xmm1
mulsd -0xa8(%rbp), %xmm0
movq -0x68(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, -0x130(%rbp)
movups (%rcx), %xmm2
movaps %xmm2, -0x140(%rbp)
leaq -0x188(%rbp), %rdi
movq -0x50(%rbp), %r13
movq %r13, %rsi
callq 0x6cc2
movq -0x178(%rbp), %rax
leaq -0x158(%rbp), %rcx
movq %rax, 0x10(%rcx)
movups -0x188(%rbp), %xmm0
movups %xmm0, (%rcx)
movaps -0x140(%rbp), %xmm0
movaps %xmm0, -0x170(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x160(%rbp)
movapd -0x170(%rbp), %xmm0
movapd -0x160(%rbp), %xmm1
movaps -0x150(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r13, %rdi
callq 0x783a
ucomisd 0x7413(%rip), %xmm0     # 0xe838
movzbl %r14b, %r14d
cmovnel %ebx, %r14d
cmovpl %ebx, %r14d
movq %r15, %r13
jne 0x744a
jp 0x744a
leal 0x1(%r12), %eax
cmpl $0x3f, %r12d
movl %eax, %r12d
jb 0x7345
movsd -0x60(%rbp), %xmm0
movsd 0x7451(%rip), %xmm1     # 0xe8a8
ucomisd %xmm0, %xmm1
movq -0x90(%rbp), %r12
jbe 0x746e
testb $0x1, %r14b
je 0x72bc
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rbx
movq %rbx, (%rdi)
leaq 0x74fa(%rip), %rsi      # 0xe97a
leaq 0x7502(%rip), %rdx      # 0xe989
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movq -0x78(%rbp), %r14
movsd (%rax), %xmm0
movq -0x88(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x74c1
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x74bb(%rip), %rsi      # 0xe98a
leaq 0x74c3(%rip), %rdx      # 0xe999
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x50(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x750a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x7482(%rip), %rsi      # 0xe99a
leaq 0x748a(%rip), %rdx      # 0xe9a9
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x58(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x7553
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x7449(%rip), %rsi      # 0xe9aa
leaq 0x744d(%rip), %rdx      # 0xe9b5
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x80(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x759b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x740d(%rip), %rsi      # 0xe9b6
leaq 0x7411(%rip), %rdx      # 0xe9c1
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x68(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x75e4
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x73d0(%rip), %rsi      # 0xe9c2
leaq 0x73d4(%rip), %rdx      # 0xe9cd
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x70(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x762d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x7393(%rip), %rsi      # 0xe9ce
leaq 0x7395(%rip), %rdx      # 0xe9d7
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movsd %xmm0, (%r14)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x7672
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x7358(%rip), %rsi      # 0xe9d8
leaq 0x735a(%rip), %rdx      # 0xe9e1
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x76be
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
leaq -0x48(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x7316(%rip), %rsi      # 0xe9e2
leaq 0x7318(%rip), %rdx      # 0xe9eb
callq 0x5342
leaq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x81c8
movsd (%rax), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x770a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
jmp 0x77e9
jmp 0x7777
jmp 0x77e9
movq %rax, %r14
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x77ec
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32d0
jmp 0x77ec
jmp 0x77e9
movq %rax, %r14
movq -0xc8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x77ec
movq -0xb8(%rbp), %rsi
jmp 0x7787
jmp 0x77e9
movq %rax, %r14
movq -0xe8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x77ec
movq -0xd8(%rbp), %rsi
jmp 0x7787
jmp 0x77e9
movq %rax, %r14
movq -0x108(%rbp), %rdi
cmpq %rbx, %rdi
je 0x77ec
movq -0xf8(%rbp), %rsi
jmp 0x7787
jmp 0x77e9
jmp 0x77e9
jmp 0x77e9
jmp 0x77e9
jmp 0x77e9
movq %rax, %r14
movq -0x50(%rbp), %rax
leaq 0x90(%rax), %rbx
movq 0xa8(%rax), %rdi
testq %rdi, %rdi
je 0x7816
movq -0x50(%rbp), %rax
movq 0xb8(%rax), %rsi
subq %rdi, %rsi
callq 0x32d0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x7831
movq -0x50(%rbp), %rax
movq 0xa0(%rax), %rsi
subq %rdi, %rsi
callq 0x32d0
movq %r14, %rdi
callq 0x3490
nop