// File: Alcaro[P]bridges/game.cpp
// Function: (anonymous namespace)::game_impl::gamegen_step()
void gamegen_step()
	{
#ifdef ARLIB_THREAD
		if (gamegen_core)
		{
			if (gamegen_core->done(NULL))
			{
				gamegen_next[gamegen_type] = gamegen_core->pack();
				gamegen_diff_expect[gamegen_type] = gamegen_core->found_difficulty();
				delete gamegen_core;
				gamegen_core = NULL;
				gamegen_validated[gamegen_type] = true;
			}
			else return;
		}
		
		for (int i=0;i<3;i++)
		{
			if (gamegen_next[i] && !gamegen_validated[i])
			{
				// ensure that the cached levels are still valid
				// i.e. level generator (or its underlying RNG) haven't changed since the save was created
				gamemap tmp;
				gamemap::generator::unpack(game_params(100+i), gamegen_next[i], tmp);
				if (tmp.solve_difficulty() != gamegen_diff_expect[i]) gamegen_next[i] = 0;
				gamegen_validated[i] = true;
				return; // only do a little each frame
			}
			if (!gamegen_next[i])
			{
				gamegen_core = new gamemap::generator(game_params(100+i));
				gamegen_type = i;
				return; // only one at the time; it's already multithreaded, no point slamming the system
			}
		}
#endif
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x24a90, %rsp          # imm = 0x24A90
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x24a80(%rbp)
cmpq $0x0, 0x24aa0(%rax)
je 0x48b92
movq -0x24a80(%rbp), %rax
movq 0x24aa0(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x52420
testb $0x1, %al
jne 0x48ae8
jmp 0x48b8b
movq -0x24a80(%rbp), %rax
movq 0x24aa0(%rax), %rdi
callq 0x524e0
movq %rax, %rdx
movq -0x24a80(%rbp), %rax
movzbl 0x24a98(%rax), %ecx
movq %rdx, 0x24a80(%rax,%rcx,8)
movq 0x24aa0(%rax), %rdi
callq 0x4e6a0
movl %eax, %edx
movq -0x24a80(%rbp), %rax
movzbl 0x24a98(%rax), %ecx
movl %edx, 0x24aac(%rax,%rcx,4)
movq 0x24aa0(%rax), %rax
movq %rax, -0x24a88(%rbp)
cmpq $0x0, %rax
je 0x48b68
movq -0x24a88(%rbp), %rdi
callq 0x4e6c0
movq -0x24a88(%rbp), %rdi
movl $0xb0, %esi
callq 0x4370
movq -0x24a80(%rbp), %rax
movq $0x0, 0x24aa0(%rax)
movzbl 0x24a98(%rax), %ecx
movb $0x1, 0x24aa8(%rax,%rcx)
jmp 0x48b90
jmp 0x48d06
jmp 0x48b92
movl $0x0, -0xc(%rbp)
cmpl $0x3, -0xc(%rbp)
jge 0x48d06
movq -0x24a80(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq $0x0, 0x24a80(%rax,%rcx,8)
je 0x48c70
movq -0x24a80(%rbp), %rax
movslq -0xc(%rbp), %rcx
testb $0x1, 0x24aa8(%rax,%rcx)
jne 0x48c70
movq -0x24a80(%rbp), %rsi
movl -0xc(%rbp), %edx
addl $0x64, %edx
leaq -0x24a48(%rbp), %rdi
callq 0x4c810
movq -0x24a80(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq 0x24a80(%rax,%rcx,8), %rsi
leaq -0x24a48(%rbp), %rdi
leaq -0x24a14(%rbp), %rdx
callq 0x52560
leaq -0x24a48(%rbp), %rdi
callq 0x4e710
leaq -0x24a14(%rbp), %rdi
callq 0x55060
movq -0x24a80(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl 0x24aac(%rcx,%rdx,4), %eax
je 0x48c58
movq -0x24a80(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq $0x0, 0x24a80(%rax,%rcx,8)
movq -0x24a80(%rbp), %rax
movslq -0xc(%rbp), %rcx
movb $0x1, 0x24aa8(%rax,%rcx)
jmp 0x48d06
movq -0x24a80(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq $0x0, 0x24a80(%rax,%rcx,8)
jne 0x48cf6
movl $0xb0, %edi
callq 0x4340
movq -0x24a80(%rbp), %rsi
movq %rax, -0x24a90(%rbp)
movl -0xc(%rbp), %edx
addl $0x64, %edx
leaq -0x24a78(%rbp), %rdi
callq 0x4c810
movq -0x24a90(%rbp), %rdi
leaq -0x24a78(%rbp), %rsi
callq 0x4fcd0
movq -0x24a90(%rbp), %rcx
movq -0x24a80(%rbp), %rax
movq %rcx, 0x24aa0(%rax)
leaq -0x24a78(%rbp), %rdi
callq 0x4e710
movq -0x24a80(%rbp), %rax
movl -0xc(%rbp), %ecx
movb %cl, 0x24a98(%rax)
jmp 0x48d06
jmp 0x48cf8
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x48b99
addq $0x24a90, %rsp          # imm = 0x24A90
popq %rbp
retq
nop