// File: FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: UpdateEmitterInfo(patch_s*)
static void		UpdateEmitterInfo (patch_t *patch)
{
#if ACCURATEBOUNCE_DEFAULT_SKYLEVEL + 3 > SKYLEVELMAX
#error "please raise SKYLEVELMAX"
#endif
	const vec_t *origin = patch->origin;
	const Winding *winding = patch->winding;
	vec_t radius = ON_EPSILON;
	for (int x = 0; x < winding->m_NumPoints; x++)
	{
		vec3_t delta;
		vec_t dist;
		VectorSubtract (winding->m_Points[x], origin, delta);
		dist = VectorLength (delta);
		if (dist > radius)
		{
			radius = dist;
		}
	}
	int skylevel = ACCURATEBOUNCE_DEFAULT_SKYLEVEL;
	vec_t area = winding->getArea ();
	vec_t size = 0.8f;
	if (area < size * radius * radius) // the shape is too thin
	{
		skylevel++;
		size *= 0.25f;
		if (area < size * radius * radius)
		{
			skylevel++;
			size *= 0.25f;
			if (area < size * radius * radius)
			{
				// stop here
				radius = sqrt (area / size);
				// just decrease the range to limit the use of the new method. because when the area is small, the new method becomes randomized and unstable.
			}
		}
	}
	patch->emitter_range = ACCURATEBOUNCE_THRESHOLD * radius;
	if (g_noemitterrange)
	{
		patch->emitter_range = 0.0;
	}
	patch->emitter_skylevel = skylevel;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x30(%rsp)
movss 0x15c63(%rip), %xmm0    # 0x6db90
movss %xmm0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x5803b
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss (%rax), %xmm0
movq 0x38(%rsp), %rax
subss (%rax), %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss 0x4(%rax), %xmm0
movq 0x38(%rsp), %rax
subss 0x4(%rax), %xmm0
movss %xmm0, 0x20(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm0
movq 0x38(%rsp), %rax
subss 0x8(%rax), %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x1c(%rsp), %xmm0
mulss 0x1c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x20(%rsp), %xmm1
mulss 0x20(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
movss 0x24(%rsp), %xmm1
mulss 0x24(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
callq 0x4270
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18(%rsp)
movss 0x18(%rsp), %xmm0
ucomiss 0x2c(%rsp), %xmm0
jbe 0x58029
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x2c(%rsp)
jmp 0x5802b
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x57f3b
movl $0x5, 0x14(%rsp)
movq 0x30(%rsp), %rdi
callq 0xdcb0
movss %xmm0, 0x10(%rsp)
movss 0x1576d(%rip), %xmm0    # 0x6d7c8
movss %xmm0, 0xc(%rsp)
movss 0x10(%rsp), %xmm1
movss 0xc(%rsp), %xmm0
mulss 0x2c(%rsp), %xmm0
mulss 0x2c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x58115
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movss 0x16b47(%rip), %xmm0    # 0x6ebdc
mulss 0xc(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x10(%rsp), %xmm1
movss 0xc(%rsp), %xmm0
mulss 0x2c(%rsp), %xmm0
mulss 0x2c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x58113
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movss 0x16b0b(%rip), %xmm0    # 0x6ebdc
mulss 0xc(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x10(%rsp), %xmm1
movss 0xc(%rsp), %xmm0
mulss 0x2c(%rsp), %xmm0
mulss 0x2c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x58111
movss 0x10(%rsp), %xmm0
divss 0xc(%rsp), %xmm0
callq 0x8e40
movss %xmm0, 0x2c(%rsp)
jmp 0x58113
jmp 0x58115
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x16451(%rip), %xmm0    # 0x6e578
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x40(%rsp), %rax
movss %xmm0, 0x1c(%rax)
testb $0x1, 0x54d7a48(%rip)   # 0x552fb88
je 0x5814f
movq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x1c(%rax)
movl 0x14(%rsp), %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x20(%rax)
addq $0x48, %rsp
retq