summary refs log tree commit diff
path: root/src/GameLoop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GameLoop.cpp')
-rw-r--r--src/GameLoop.cpp99
1 files changed, 44 insertions, 55 deletions
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp
index c0caaaf..9e42b88 100644
--- a/src/GameLoop.cpp
+++ b/src/GameLoop.cpp
@@ -19,8 +19,6 @@
 // You should have received a copy of the GNU General Public License
 // along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
 
-#include "GLFW/glfw3.h"
-
 #include "Game.h"
 
 extern float multiplier;
@@ -33,61 +31,62 @@ extern Fog fog;
 extern int environment;
 extern int slomo;
 
-void Game::HandleKeyDown(char key)
+void keyCallback(Game* game, int key, int action, int mods)
 {
-	if (mainmenu)
+	if (game->mainmenu || action != GLFW_PRESS)
 		return;
 
-	ALfloat pitch;
+	auto shift = mods & GLFW_MOD_SHIFT;
+	auto player = game->person[0];
 	XYZ facing;
 
 	switch(key) {
-	case 'l':
-		lasersight ^= 1;
-		break;
-	case 'k':
-		if (debug)
-			timeremaining = 0;
+	case GLFW_KEY_L:
+		game->lasersight ^= 1;
 		break;
-	case 'b':
-		if (!debug)
-			break;
-		alSourcePlay(gSourceID[soulinsound]);
-		pitch = (slomo ^= 1) ? 0.5f : 1.0f;
-		alSourcef(gSourceID[knifesong], AL_PITCH, pitch);
-		alSourcef(gSourceID[shootsong], AL_PITCH, pitch);
-		alSourcef(gSourceID[zombiesong], AL_PITCH, pitch);
+	case GLFW_KEY_K:
+		if (game->debug)
+			game->timeremaining = 0;
 		break;
-	case 'B':
-		if (!debug)
+	case GLFW_KEY_B:
+		if (!game->debug)
 			break;
 		alSourcePlay(gSourceID[soulinsound]);
-		paused = 1 - paused;
+		if (shift) {
+			game->paused = 1 - game->paused;
+		} else {
+			auto pitch = (slomo ^= 1) ? 0.5f : 1.0f;
+			alSourcef(gSourceID[knifesong], AL_PITCH, pitch);
+			alSourcef(gSourceID[shootsong], AL_PITCH, pitch);
+			alSourcef(gSourceID[zombiesong], AL_PITCH, pitch);
+		}
 		break;
-	case 'f':
-		if (!debug)
+	case GLFW_KEY_F:
+		if (!game->debug)
 			break;
 		alSourcePlay(gSourceID[souloutsound]);
 
-		facing = 0;
-		facing.z = -1;
+		facing = {0, 0, -1};
 		facing = DoRotation(facing, -camera.rotation2, 0, 0);
 		facing = DoRotation(facing, 0, 0 - camera.rotation, 0);
 
-		for(int i = 1; i < numpeople; i++) {
-			if (person[i].skeleton.free == 1
-			    || findDistancefast(person[i].playercoords,
-			                        person[0].playercoords) > 1000)
+		for (int i = 1; i < game->numpeople; i++) {
+			auto& person = game->person[i];
+			if (person.skeleton.free == 1
+			    || findDistancefast(person.playercoords,
+						player.playercoords) > 1000)
 				continue;
-			person[i].skeleton.free = 1;
-			person[i].longdead = 1;
+			person.skeleton.free = 1;
+			person.longdead = 1;
 
-			for (auto& joint : person[i].skeleton.joints) {
-				joint.position = DoRotation(joint.position, 0, person[i].playerrotation, 0);
-				joint.position += person[i].playercoords;
+			for (auto& joint : person.skeleton.joints) {
+				joint.position = DoRotation(joint.position,
+					0, person.playerrotation, 0);
+				joint.position += person.playercoords;
 				joint.realoldposition = joint.position;
-				joint.velocity = DoRotation(joint.velocity, 0, person[i].playerrotation, 0);
-				joint.velocity += person[i].velocity;
+				joint.velocity = DoRotation(joint.velocity,
+					0, person.playerrotation, 0);
+				joint.velocity += person.velocity;
 				joint.velocity += facing * 50;
 				joint.velocity.x += abs(Random() % 20) - 10;
 				joint.velocity.y += abs(Random() % 20) - 10;
@@ -95,31 +94,21 @@ void Game::HandleKeyDown(char key)
 			}
 		}
 		break;
-	case 'X':
-		if (!debug || person[0].grenphase)
+	case GLFW_KEY_X:
+		if (!game->debug || !shift || player.grenphase)
 			break;
-		person[0].ammo = -1;
-		person[0].whichgun++;
-		person[0].grenphase = 0;
-		person[0].reloads[person[0].whichgun] = 3;
-		if (person[0].whichgun > 7)
-			person[0].whichgun = 0;
+		player.ammo = -1;
+		player.whichgun++;
+		player.grenphase = 0;
+		player.reloads[player.whichgun] = 3;
+		if (player.whichgun > 7)
+			player.whichgun = 0;
 		break;
 	}
 }
 
 void eventLoop(Game* game)
 {
-	/*
-	 * SDL_Event event;
-	 * while (SDL_PollEvent(&event)) {
-	 * 	if (event.type == SDL_KEYUP
-	 * 	    && event.key.keysym.unicode
-	 * 	    && !(event.key.keysym.unicode & 0xFF80))
-	 * 		game->HandleKeyDown(event.key.keysym.unicode);
-	 * }
-	 */
-
 	auto start = glfwGetTime();
 	GLfloat oldmult = multiplier;
 	int colaccuracy = min(game->sps,