// File: /workspace/github_c_makefile_star2_O2/Hazematman[P]BSP-Renderer/game.c
// Function: run
void run(){
	bool running = true;
	SDL_Event e;

	GLint projViewLoc = getUniformLoc(&prg, "projView");
	GLint modelLoc = getUniformLoc(&prg, "model");
	GLint texLoc = getUniformLoc(&prg, "tex");
	
	while(running){
		while(SDL_PollEvent(&e)){
			if(e.type == SDL_QUIT){
				running = false;
			}else if(e.type == SDL_KEYDOWN){
				switch(e.key.keysym.sym){
					case SDLK_w:
						pos.z -= speed;
						break;
					case SDLK_s:
						pos.z += speed;
						break;
					case SDLK_a:
						pos.x -= speed;
						break;
					case SDLK_d:
						pos.x += speed;
						break;
					case SDLK_e:
						pos.y += speed;
						break;
					case SDLK_q:
						pos.y -= speed;
						break;
					case SDLK_LEFT:
						angle += 0.1;
						break;
					case SDLK_RIGHT:
						angle -= 0.1;
						break;
				}
			}
		}

		mat4 projView;
		mat4 model;
		identity(&projView);
		identity(&model);
		perspective(&projView, 45.0f * (PI/180.0f), WINDOW_WIDTH/WINDOW_HEIGHT, 0.1f, 10000.0f);
		rotateY(&projView, -angle);
		translate(&projView, -pos.x, -pos.y, -pos.z);
		//printf("%f %f %f %f\n",angle, pos.x, pos.y, pos.z);

		glUseProgram(prg.prgID);
		glUniformMatrix4fv(projViewLoc, 1, GL_FALSE, &projView.m[0]);
		glUniformMatrix4fv(modelLoc, 1, GL_FALSE, &model.m[0]);
		glUniform1i(texLoc, 0);

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		renderAllBspFaces(bsp);
		SDL_GL_SwapWindow(screen);
	}

	SDL_Quit();

	freeBsp(bsp);
	freePalette(plt);
	freePak(pf);
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
leaq 0x58ae(%rip), %rbx      # 0xcc38
leaq 0x2677(%rip), %rsi      # 0x9a08
movq %rbx, %rdi
callq 0x5de7
movl %eax, 0xc(%rsp)
leaq 0x266d(%rip), %rsi      # 0x9a11
movq %rbx, %rdi
callq 0x5de7
movl %eax, 0x8(%rsp)
leaq 0x20bb(%rip), %rsi      # 0x9472
movq %rbx, %rdi
callq 0x5de7
movl %eax, 0x4(%rsp)
movb $0x1, %al
leaq 0x10(%rsp), %r15
leaq 0x88(%rsp), %r12
leaq 0x48(%rsp), %r13
leaq 0x5252(%rip), %rbp      # 0xc630
pushq $0x1
popq %rbx
movl %eax, %r14d
movq %r15, %rdi
callq 0x1090
testl %eax, %eax
je 0x746f
xorl %eax, %eax
movl 0x10(%rsp), %ecx
cmpl $0x100, %ecx            # imm = 0x100
je 0x73e1
movl %r14d, %eax
cmpl $0x300, %ecx            # imm = 0x300
jne 0x73e1
movl 0x24(%rsp), %ecx
cmpl $0x61, %ecx
je 0x75ff
cmpl $0x64, %ecx
je 0x75bb
cmpl $0x65, %ecx
je 0x75df
cmpl $0x71, %ecx
je 0x75cd
cmpl $0x73, %ecx
je 0x7565
cmpl $0x40000050, %ecx       # imm = 0x40000050
je 0x7597
cmpl $0x4000004f, %ecx       # imm = 0x4000004F
je 0x7585
movl %r14d, %eax
cmpl $0x77, %ecx
jne 0x73e1
movss 0x57ea(%rip), %xmm0     # 0xcc4c
addss 0x2526(%rip), %xmm0     # 0x9990
jmp 0x7575
movq %r12, %rdi
callq 0x5e34
movq %r13, %rdi
callq 0x5e34
movq %r12, %rdi
movss 0x250e(%rip), %xmm0     # 0x9998
movss 0x23e6(%rip), %xmm1     # 0x9878
movss 0x2502(%rip), %xmm2     # 0x999c
movss 0x24fe(%rip), %xmm3     # 0x99a0
callq 0x5fb7
movss 0x57a1(%rip), %xmm0     # 0xcc50
movaps 0x240a(%rip), %xmm1     # 0x98c0
xorps %xmm1, %xmm0
movq %r12, %rdi
callq 0x60c3
movss 0x577b(%rip), %xmm0     # 0xcc44
movaps 0x23f0(%rip), %xmm2     # 0x98c0
xorps %xmm2, %xmm0
movss 0x576d(%rip), %xmm1     # 0xcc48
xorps %xmm2, %xmm1
movaps %xmm2, %xmm3
movss 0x5763(%rip), %xmm2     # 0xcc4c
xorps %xmm3, %xmm2
movq %r12, %rdi
callq 0x6077
movl 0x573e(%rip), %edi      # 0xcc38
leaq 0x5137(%rip), %rax      # 0xc638
callq *(%rax)
movl 0xc(%rsp), %edi
movl %ebx, %esi
xorl %edx, %edx
movq %r12, %rcx
callq *(%rbp)
movl 0x8(%rsp), %edi
movl %ebx, %esi
xorl %edx, %edx
movq %r13, %rcx
callq *(%rbp)
movl 0x4(%rsp), %edi
xorl %esi, %esi
leaq 0x5084(%rip), %rax      # 0xc5b0
callq *(%rax)
movl $0x4100, %edi           # imm = 0x4100
leaq 0x4c36(%rip), %rax      # 0xc170
callq *(%rax)
movq 0x5715(%rip), %rdi      # 0xcc58
callq 0x6e91
movq 0x56d9(%rip), %rdi      # 0xcc28
callq 0x1180
movb $0x1, %al
testb $0x1, %r14b
jne 0x73e1
jmp 0x761f
movss 0x56df(%rip), %xmm0     # 0xcc4c
addss 0x241f(%rip), %xmm0     # 0x9994
movss %xmm0, 0x56cf(%rip)     # 0xcc4c
movl %r14d, %eax
jmp 0x73e1
cvtss2sd 0x56c3(%rip), %xmm0     # 0xcc50
addsd 0x2413(%rip), %xmm0     # 0x99a8
jmp 0x75a7
cvtss2sd 0x56b1(%rip), %xmm0     # 0xcc50
addsd 0x2409(%rip), %xmm0     # 0x99b0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x569d(%rip)     # 0xcc50
movl %r14d, %eax
jmp 0x73e1
movss 0x5681(%rip), %xmm0     # 0xcc44
addss 0x23c9(%rip), %xmm0     # 0x9994
jmp 0x760f
movss 0x5673(%rip), %xmm0     # 0xcc48
addss 0x23b3(%rip), %xmm0     # 0x9990
jmp 0x75ef
movss 0x5661(%rip), %xmm0     # 0xcc48
addss 0x23a5(%rip), %xmm0     # 0x9994
movss %xmm0, 0x5651(%rip)     # 0xcc48
movl %r14d, %eax
jmp 0x73e1
movss 0x563d(%rip), %xmm0     # 0xcc44
addss 0x2381(%rip), %xmm0     # 0x9990
movss %xmm0, 0x562d(%rip)     # 0xcc44
movl %r14d, %eax
jmp 0x73e1
callq 0x1060
movq 0x562d(%rip), %rdi      # 0xcc58
callq 0x6f43
movq 0x5629(%rip), %rdi      # 0xcc60
callq 0x6470
movq 0x5625(%rip), %rdi      # 0xcc68
callq 0x63ee
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq