void G_Tick() {
	BufferTextInput();

	if (G_ContainsHeightMap(*((heightmap*)((object*)G_staticMeshes.first->value)->shape), G_camPos)) 
		printf("\rYes\n");

	vec3 dir = {0, 0, 0};
	float moveSpeed = G_moveSpeed * (SYS_deltaMillis / 1000.0);
	float rotSpeed = G_rotSpeed * (SYS_deltaMillis / 1000.0);
	if (IN_IsKeyPressed(IN_W))		dir[2]		-= moveSpeed;
	if (IN_IsKeyPressed(IN_A))		dir[0]		-= moveSpeed;
	if (IN_IsKeyPressed(IN_S))		dir[2]		+= moveSpeed;
	if (IN_IsKeyPressed(IN_D))		dir[0]		+= moveSpeed;
	if (IN_IsKeyPressed(IN_UP))		dir[1]		+= moveSpeed;
	if (IN_IsKeyPressed(IN_DOWN))	dir[1]		-= moveSpeed;
	if (IN_IsKeyPressed(IN_RIGHT))	G_camRot[1]	+= rotSpeed;
	if (IN_IsKeyPressed(IN_LEFT))	G_camRot[1]	-= rotSpeed;
	if (IN_IsKeyPressed(IN_PITCH_UP))	G_camRot[0]	+= rotSpeed;
	if (IN_IsKeyPressed(IN_PITCH_DOWN))	G_camRot[0]	-= rotSpeed;
	if (IN_IsKeyPressed(IN_ACTION)) {
		if (!actionHeld) {
			Shoot();
			actionHeld = true;
		}
	}else actionHeld = false;
	if (IN_IsKeyPressed(IN_TOGGLE)) {
		if (!toggleHeld) {
			ads = ads ? false : true;
			lastAdsTime = SYS_TimeMillis() / 1000.0;
			toggleHeld = true;
		}
	}else toggleHeld = false;
	if (IN_IsKeyPressed(IN_CHAT)) {
		if (!chatHeld) {
			IN_StartTextInput();
			C_console.inputActive = true;
			chatHeld = true;
		}
	}else chatHeld = false;
	
	if (IN_IsKeyPressed(IN_RELOAD)) {
		ReloadLevel();
	}
	
	if (G_camRot[0] > PITCH_LIMIT) G_camRot[0] = PITCH_LIMIT;
	else if (G_camRot[0] < -PITCH_LIMIT) G_camRot[0] = -PITCH_LIMIT;
	
	float c = cos(G_camRot[1]);
	float s = sin(G_camRot[1]);
	G_camPos[0] += -dir[2] * s + dir[0] * c;
	G_camPos[2] += dir[2] * c + dir[0] * s;
	G_camPos[1] += dir[1];
	
	mat4x4_translate(G_gunMat, G_camPos[0], G_camPos[1], G_camPos[2]);
	mat4x4_rotate_Y(G_gunMat, G_gunMat, G_camRot[1] + M_PI);
	mat4x4_rotate_X(G_gunMat, G_gunMat, -G_camRot[0]);

	double d, f;
	{
		termf terms[2] = {{2, 2}, {-1, 4}};
		d = G_Valuef((function) {0, 1, 2, terms},
							(SYS_TimeMillis() / 1000.0 - lastAdsTime) * 5);
		if (ads) d = 1 - d;
	}
	{
		termf terms[2] = {{1, 0.3}, {-1, 1}};
		f = G_Valuef((function) {0, 1, 2, terms},
							(SYS_TimeMillis() / 1000.0 - lastShootTime) * 5);
	}
	V_SetProj(fov->value * d + adsFov->value * (1 - d));
	vec3 resultant = {0, 0, 0};
	for (int i = 0; i < 3; i++) {
		resultant[i] += defGunPos[i];
		resultant[i] += hipGunPos[i] * d;
		resultant[i] += fireGunPos[i] * f;
		resultant[i] += hipFireGunPos[i] * d * f;
	}
	resultant[0] += d * 0.01 * cos(SYS_TimeMillis() / 2000.0);
	resultant[1] += d * 0.005 * cos(SYS_TimeMillis() / 1500.0);
	mat4x4_translate_in_place(G_gunMat, resultant[0], resultant[1], resultant[2]);
	
	HandleSmoke();

	if (IN_IsKeyPressed(IN_RELOAD)) V_reloadShaders = true;
}
void BasicSceneModule::ReloadButtonClick(rEvent& event){
	ReloadLevel();
}