// File: /workspace/github_c_makefile_star2_O3/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 0xa358(%rip), %r14      # 0xc178
leaq 0x62e1(%rip), %rsi      # 0x8108
movq %r14, %rdi
callq 0x6c25
movl %eax, 0xc(%rsp)
leaq 0x62d7(%rip), %rsi      # 0x8111
movq %r14, %rdi
callq 0x6c25
movl %eax, 0x8(%rsp)
leaq 0x777e(%rip), %rsi      # 0x95cb
movq %r14, %rdi
callq 0x6c25
movl %eax, %r14d
leaq 0x10(%rsp), %r15
leaq 0x88(%rsp), %r12
leaq 0x48(%rsp), %r13
leaq 0xa807(%rip), %rbx      # 0xc678
movq %r15, %rdi
callq 0x1090
movb $0x1, %bpl
testl %eax, %eax
je 0x1fad
movl 0x10(%rsp), %eax
cmpl $0x100, %eax            # imm = 0x100
je 0x1ec4
cmpl $0x300, %eax            # imm = 0x300
jne 0x1ec6
movl 0x24(%rsp), %eax
cmpl $0x72, %eax
jg 0x1ed0
cmpl $0x64, %eax
jg 0x1ef3
cmpl $0x61, %eax
je 0x1f32
cmpl $0x64, %eax
jne 0x1ec6
movss 0xa2ca(%rip), %xmm0     # 0xc184
addss 0x61d2(%rip), %xmm0     # 0x8094
jmp 0x1f42
xorl %ebp, %ebp
movq %r15, %rdi
callq 0x1090
jmp 0x1e7c
cmpl $0x4000004e, %eax       # imm = 0x4000004E
jg 0x1f0f
cmpl $0x73, %eax
je 0x1f4f
cmpl $0x77, %eax
jne 0x1ec6
movss 0xa2a3(%rip), %xmm0     # 0xc18c
addss 0x619f(%rip), %xmm0     # 0x8090
jmp 0x1f5f
cmpl $0x65, %eax
je 0x1f6c
cmpl $0x71, %eax
jne 0x1ec6
movss 0xa283(%rip), %xmm0     # 0xc188
addss 0x6183(%rip), %xmm0     # 0x8090
jmp 0x1f7c
cmpl $0x4000004f, %eax       # imm = 0x4000004F
je 0x1f89
cmpl $0x40000050, %eax       # imm = 0x40000050
jne 0x1ec6
xorps %xmm0, %xmm0
cvtss2sd 0xa268(%rip), %xmm0     # 0xc190
addsd 0x6180(%rip), %xmm0     # 0x80b0
jmp 0x1f9c
movss 0xa24a(%rip), %xmm0     # 0xc184
addss 0x614e(%rip), %xmm0     # 0x8090
movss %xmm0, 0xa23a(%rip)     # 0xc184
jmp 0x1ec6
movss 0xa235(%rip), %xmm0     # 0xc18c
addss 0x6135(%rip), %xmm0     # 0x8094
movss %xmm0, 0xa225(%rip)     # 0xc18c
jmp 0x1ec6
movss 0xa214(%rip), %xmm0     # 0xc188
addss 0x6118(%rip), %xmm0     # 0x8094
movss %xmm0, 0xa204(%rip)     # 0xc188
jmp 0x1ec6
xorps %xmm0, %xmm0
cvtss2sd 0xa1fc(%rip), %xmm0     # 0xc190
addsd 0x610c(%rip), %xmm0     # 0x80a8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xa1e8(%rip)     # 0xc190
jmp 0x1ec6
movq %r12, %rdi
callq 0x6c70
movq %r13, %rdi
callq 0x6c70
movq %r12, %rdi
movss 0x60d0(%rip), %xmm0     # 0x8098
movss 0x608c(%rip), %xmm1     # 0x805c
movss 0x60c4(%rip), %xmm2     # 0x809c
movss 0x60c0(%rip), %xmm3     # 0x80a0
callq 0x6db4
movss 0xa1a3(%rip), %xmm0     # 0xc190
movaps 0x601c(%rip), %xmm1     # 0x8010
xorps %xmm1, %xmm0
movq %r12, %rdi
callq 0x6ec0
movss 0xa17d(%rip), %xmm0     # 0xc184
movaps 0x6002(%rip), %xmm2     # 0x8010
xorps %xmm2, %xmm0
movss 0xa16f(%rip), %xmm1     # 0xc188
xorps %xmm2, %xmm1
movaps %xmm2, %xmm3
movss 0xa165(%rip), %xmm2     # 0xc18c
xorps %xmm3, %xmm2
movq %r12, %rdi
callq 0x6e74
movl 0xa140(%rip), %edi      # 0xc178
leaq 0xa641(%rip), %rax      # 0xc680
callq *(%rax)
movl 0xc(%rsp), %edi
movl $0x1, %esi
xorl %edx, %edx
movq %r12, %rcx
callq *(%rbx)
movl 0x8(%rsp), %edi
movl $0x1, %esi
xorl %edx, %edx
movq %r13, %rcx
callq *(%rbx)
movl %r14d, %edi
xorl %esi, %esi
leaq 0xa58b(%rip), %rax      # 0xc5f8
callq *(%rax)
movl $0x4100, %edi           # imm = 0x4100
leaq 0xa13d(%rip), %rax      # 0xc1b8
callq *(%rax)
movq 0xa114(%rip), %rdi      # 0xc198
callq 0x18b1
movq 0xa0d8(%rip), %rdi      # 0xc168
callq 0x1180
testb $0x1, %bpl
jne 0x1e71
callq 0x1060
movq 0xa0ed(%rip), %rdi      # 0xc198
callq 0x1980
movq 0xa0e9(%rip), %rdi      # 0xc1a0
callq 0x7274
movq 0xa0e5(%rip), %rdi      # 0xc1a8
callq 0x71eb
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop