summary refs log tree commit diff
diff options
context:
space:
mode:
m---------lib/gfz0
-rw-r--r--src/Game.h12
-rw-r--r--src/GameInitDispose.cpp3
-rw-r--r--src/GameTick.cpp154
-rw-r--r--src/Support.cpp14
-rw-r--r--src/Support.h1
-rw-r--r--src/config.ini2
-rw-r--r--src/config.zig2
-rw-r--r--src/main.zig5
9 files changed, 80 insertions, 113 deletions
diff --git a/lib/gfz b/lib/gfz
-Subproject 63f402e1bc8b9bf790a890d6b3ab86c7a9e61a4
+Subproject bac6c9042375f2a09d6505cc8dda20166c1a152
diff --git a/src/Game.h b/src/Game.h
index 58770c3..3c0776a 100644
--- a/src/Game.h
+++ b/src/Game.h
@@ -68,11 +68,7 @@ public:
 	float viewdistance;
 
 	// Mouse
-	Point mouseloc;
-	float mouserotation,mouserotation2;
-	float oldmouserotation,oldmouserotation2;
-	float mousesensitivity;
-	float usermousesensitivity;
+	float mouse_sensitivity;
 
 	// Project specific
 	int cityrotation[num_blocks][num_blocks];
@@ -132,7 +128,6 @@ public:
 
 	XYZ lastshot[2];
 	bool zoom;
-	bool oldzoom;
 
 	int numpeople;
 	float spawndelay;
@@ -185,10 +180,11 @@ typedef struct Game Game;
 extern "C" {
 #endif // __cplusplus
 	Game* makeGame(struct Config config);
-	void resizeWindow(Game* game, int width, int height);
-	void handleKey(Game* game, int key, int action, int mods);
 	void initGl(Game* game);
 	void initGame(Game* game);
+	void resizeWindow(Game* game, int width, int height);
+	void handleKey(Game* game, int key, int action, int mods);
+	void look(Game* game, double xpos, double ypos);
 	void setMenu(Game* game, bool value);
 	void eventLoop(Game* game);
 	void closeGame(Game* game);
diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp
index e5fb13c..935945c 100644
--- a/src/GameInitDispose.cpp
+++ b/src/GameInitDispose.cpp
@@ -75,8 +75,7 @@ Game* makeGame(Config config)
 
 	game->musictoggle = config.music;
 
-	game->usermousesensitivity = config.mouse_sensitivity;
-	game->mousesensitivity = game->usermousesensitivity;
+	game->mouse_sensitivity = config.mouse_sensitivity;
 	forwardskey = GLFW_KEY_W;
 	backwardskey = GLFW_KEY_S;
 	leftkey = GLFW_KEY_A;
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 760db74..c8b1111 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -124,6 +124,7 @@ void Game::updateSong()
 
 void Game::handleMenu()
 {
+	Point mouseloc;
 	GetMouse(&mouseloc);
 	float mousex = (float) mouseloc.h * 640 / screenwidth;
 	float mousey = 480 - (float) mouseloc.v * 480 / screenheight;
@@ -150,7 +151,6 @@ void Game::handleMenu()
 			initGame(this);
 		}
 
-		GetMouse(&mouseloc);
 		if (visions)
 			alSourcePlay(gSourceID[visionsound]);
 
@@ -173,49 +173,40 @@ void Game::handleMenu()
 	}
 }
 
-void Game::mouseLook()
+void look(Game* game, double xpos, double ypos)
 {
-	if ((person[0].aimamount <= 0
-	     && person[0].targetanimation != crouchanim)) {
-		camera.rotation = camera.visrotation;
-		camera.rotation2 = camera.visrotation2;
-		mousesensitivity = usermousesensitivity;
-	} else if (person[0].aimamount >= 1 && !zoom) {
-		mousesensitivity = usermousesensitivity * 0.8;
-	}
+	if (game->menu)
+		return;
+
+	int width, height;
+	const auto window = glfwGetCurrentContext();
+	glfwGetWindowSize(window, &width, &height);
+	int xcenter = width / 2, ycenter = height / 2;
+	glfwSetCursorPos(window, xcenter, ycenter); // we shouldn't need this
+
+	auto& player = game->person[0];
+	auto factor = game->mouse_sensitivity;
+	if (player.aimamount >= 1)
+		factor *= (game->zoom) ? 0.05 : 0.8;
 	if (slomo == 2)
-		mousesensitivity *= 0.6;
-
-	GetMouseRel(&mouseloc);
-	auto factor = mousesensitivity / 1.3888;
-	mouserotation = mouseloc.h * factor;
-	mouserotation2 = mouseloc.v * factor;
-	if (abs(mouseloc.h) < 400)
-		camera.rotation += mouserotation;
-	if (abs(mouseloc.v) < 200)
-		camera.rotation2 += mouserotation2;
-
-	auto hrot = factor * 500;
-	if (mouseloc.h > 400)
-		camera.rotation += mouserotation - hrot;
-	if (mouseloc.h < -400)
-		camera.rotation += mouserotation + hrot;
-
-	auto vrot = factor * 300;
-	if (mouseloc.v > 200)
-		camera.rotation2 += mouserotation2 - vrot;
-	if (mouseloc.v < -200)
-		camera.rotation2 += mouserotation2 + vrot;
-	camera.rotation2 = min(max(camera.rotation2, -89.0f), 89.0f);
+		factor *= 0.6;
+
+	camera.rotation += (xpos - xcenter) * factor;
+	camera.rotation2 += (ypos - ycenter) * factor;
 
-	// Smooth
+	// Smoothen camera movements
 	camera.rotation = camera.rotation * 0.7 + camera.oldrotation * 0.3;
+	camera.oldrotation = camera.rotation;
+	player.playerrotation = 180 - camera.rotation;
+
 	camera.rotation2 = camera.rotation2 * 0.7 + camera.oldrotation2 * 0.3;
+	camera.rotation2 = min(max(camera.rotation2, -89.0f), 89.0f);
+	camera.oldrotation2 = camera.rotation2;
 
-	if (zoom || visions || person[0].aimamount <= 0
-	    || person[0].whichgun == nogun
-	    || person[0].whichgun == grenade
-	    || person[0].whichgun == knife) {
+	if (game->zoom || visions || player.aimamount <= 0
+	    || player.whichgun == nogun
+	    || player.whichgun == grenade
+	    || player.whichgun == knife) {
 		camera.visrotation = camera.rotation;
 		camera.visrotation2 = camera.rotation2;
 	} else {
@@ -224,10 +215,6 @@ void Game::mouseLook()
 		camera.visrotation2 = min(camera.rotation2 + 15,
 			max(camera.rotation2 - 15, camera.visrotation2));
 	}
-
-	person[0].playerrotation = 180 - camera.rotation;
-	camera.oldrotation = camera.rotation;
-	camera.oldrotation2 = camera.rotation2;
 }
 
 void Game::setListener(XYZ& facing)
@@ -380,8 +367,6 @@ void Game::Tick()
 	flatfacing.y = 0;
 	Normalise(&flatfacing);
 
-	mouseLook();
-
 	//Check collision with buildings
 	int beginx,endx;
 	int beginz,endz;
@@ -959,47 +944,48 @@ void Game::Tick()
 
 		}
 
-		if(person[i].skeleton.free==0){
-			//Gun
-			if(person[i].type==playertype||person[i].type==eviltype){
-				if(i==0){
-					if(person[i].whichgun==shotgun)person[i].recoil-=multiplier*4;
-					if(person[i].whichgun==sniperrifle)person[i].recoil-=multiplier*2;
-					if(person[i].whichgun==handgun1)person[i].recoil-=multiplier*5;
-					if(person[i].whichgun==handgun2)person[i].recoil-=multiplier*5;
-					if(person[i].whichgun==assaultrifle)person[i].recoil-=multiplier*10;
-				}
-
-				if(i!=0){
-					if(person[i].whichgun==shotgun)person[i].recoil-=multiplier*1;
-					if(person[i].whichgun==sniperrifle)person[i].recoil-=multiplier*1;
-					if(person[i].whichgun==handgun1)person[i].recoil-=multiplier*2;
-					if(person[i].whichgun==handgun2)person[i].recoil-=multiplier*2;
-					if(person[i].whichgun==assaultrifle)person[i].recoil-=multiplier*10;
+		if (!person[i].skeleton.free) {
+			// Gun
+			switch (person[i].type) {
+			case playertype:
+				switch (person[i].whichgun) {
+				case shotgun:
+					person[i].recoil -= multiplier * 4;
+					break;
+				case sniperrifle:
+					person[i].recoil -= multiplier * 2;
+					break;
+				case handgun1:
+				case handgun2:
+					person[i].recoil -= multiplier * 5;
+					break;
+				case assaultrifle:
+					person[i].recoil-=multiplier * 10;
+					break;
 				}
-
-				if(person[i].recoil<0)person[i].recoil=0;
-
-				if(i==0){
-					oldzoom = zoom;
-					if(zoom){
-						mousesensitivity=.05*usermousesensitivity;
-						if(person[i].targetanimation!=crouchanim||person[i].currentanimation!=crouchanim||person[i].aiming<1){
-							zoom=0;
-						}
-						if(visions==1)zoom=0;
-					}
-
-					if(person[i].currentanimation==crouchanim&&person[i].targetanimation==crouchanim&&person[i].aiming>=1&&person[i].whichgun==sniperrifle){
-						zoom=1;
-						if(zoom&&!oldzoom)camera.rotation2-=6;
-					}
-
-					if(!zoom)mousesensitivity=1*usermousesensitivity;
-
-					if(person[i].whichgun!=sniperrifle)zoom=0;
+				this->zoom = person[0].whichgun == sniperrifle
+					&& person[0].aiming >=1 && !visions
+					&& person[0].currentanimation == crouchanim
+					&& person[0].targetanimation == crouchanim;
+				break;
+			case eviltype:
+				switch (person[i].whichgun) {
+				case shotgun:
+				case sniperrifle:
+					person[i].recoil -= multiplier * 1;
+					break;
+				case handgun1:
+				case handgun2:
+					person[i].recoil -= multiplier * 2;
+					break;
+				case assaultrifle:
+					person[i].recoil-=multiplier * 10;
+					break;
 				}
+				break;
 			}
+			if (person[i].recoil < 0)
+				person[i].recoil = 0;
 
 			//Zombie eat
 			if(i > 0
@@ -3336,10 +3322,6 @@ void Game::Tick()
 	psychicpower+=multiplier*5;
 	if(psychicpower>10)psychicpower=10;
 
-	if (paused || person[0].currentanimation== diveanim
-	    || person[0].currentanimation == throwanim)
-		GetMouse(&mouseloc);
-
 	setListener(facing);
 	if (score < 0)
 		score = 0;
diff --git a/src/Support.cpp b/src/Support.cpp
index a233dd7..fc2b0ac 100644
--- a/src/Support.cpp
+++ b/src/Support.cpp
@@ -29,20 +29,6 @@ void GetMouse(Point *p)
 	p->v = floor(ypos);
 }
 
-void GetMouseRel(Point *p)
-{
-	const auto window = glfwGetCurrentContext();
-	glfwGetWindowSize(window, &p->h, &p->v);
-	p->h /= 2;
-	p->v /= 2;
-
-	double xpos, ypos;
-	glfwGetCursorPos(window, &xpos, &ypos);
-	glfwSetCursorPos(window, p->h, p->v); // we shouldn't need this
-	p->h = floor(xpos) - p->h;
-	p->v = floor(ypos) - p->v;
-}
-
 int Button(void)
 {
 	const auto window = glfwGetCurrentContext();
diff --git a/src/Support.h b/src/Support.h
index 901b9b4..7d95073 100644
--- a/src/Support.h
+++ b/src/Support.h
@@ -33,7 +33,6 @@ typedef struct Point
 
 int Random();
 void GetMouse(Point *p);
-void GetMouseRel(Point *p);
 int Button(void);
 bool IsKeyDown(int key);
 
diff --git a/src/config.ini b/src/config.ini
index 9889ad4..fdd3793 100644
--- a/src/config.ini
+++ b/src/config.ini
@@ -9,7 +9,7 @@ blood = true
 music = true
 
 [input]
-mouse sensitivity = 0.7
+mouse sensitivity = 1.0
 
 [misc]
 custom levels = false
diff --git a/src/config.zig b/src/config.zig
index e54a70d..49c6dad 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -38,7 +38,7 @@ pub const Config = extern struct {
 
     music: bool = true,
 
-    mouse_sensitivity: f32 = 0.7,
+    mouse_sensitivity: f32 = 1.0,
 
     custom_levels: bool = false,
     debug: bool = false,
diff --git a/src/main.zig b/src/main.zig
index dd071fa..17c4119 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -36,6 +36,10 @@ fn handleKey(window: ?*gf.Window.Impl, key: c_int, scancode: c_int,
     legacy.handleKey(game, key, action, mods);
 }
 
+fn look(window: ?*gf.Window.Impl, xpos: f64, ypos: f64) callconv(.C) void {
+    legacy.look(game, xpos, ypos);
+}
+
 pub fn main() !void {
     const loca = try Loca.init(allocator, .{});
     defer loca.deinit();
@@ -57,6 +61,7 @@ pub fn main() !void {
     try window.setInputMode(.sticky_mouse_buttons, true);
     try window.setInputMode(.sticky_keys, true);
     try window.setKeyCallback(handleKey);
+    try window.setCursorPosCallback(look);
 
     const device = try al.Device.init(null);
     defer device.deinit() catch unreachable;