summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/Decals.cpp2
-rw-r--r--src/Game.cc2
-rw-r--r--src/Game.h6
-rw-r--r--src/GameDraw.cpp2
-rw-r--r--src/GameLoop.cpp73
-rw-r--r--src/GameTick.cpp2
-rw-r--r--src/Globals.cpp2
-rw-r--r--src/Person.cpp2
-rw-r--r--src/Skeleton.cpp2
-rw-r--r--src/Sprites.cpp2
10 files changed, 49 insertions, 46 deletions
diff --git a/src/Decals.cpp b/src/Decals.cpp
index 2f82bb2..30db128 100644
--- a/src/Decals.cpp
+++ b/src/Decals.cpp
@@ -1,7 +1,7 @@
 #include "Decals.h"
 #include "Textures.h"
 
-extern double multiplier;
+extern float multiplier;
 extern bool slomo;
 extern Fog fog;
 extern bool blood;
diff --git a/src/Game.cc b/src/Game.cc
index e8d722c..31afe2a 100644
--- a/src/Game.cc
+++ b/src/Game.cc
@@ -24,5 +24,5 @@ void run()
 	Game game {};
 	initGl(&game);
 	initGame(&game);
-	game.EventLoop();
+	eventLoop(&game);
 }
diff --git a/src/Game.h b/src/Game.h
index 79162ce..0946e10 100644
--- a/src/Game.h
+++ b/src/Game.h
@@ -64,8 +64,8 @@ public:
 	// Event loop
 	Boolean	gQuit;
 	float gamespeed;
-	double multiplier2, multiplier3, multiplier4, multiplier5;
-	double end, start, timetaken, framespersecond;
+	float multiplier2, multiplier3, multiplier4, multiplier5;
+	float end, start, timetaken, framespersecond;
 	timer theTimer;
 	float sps;
 	int maxfps;
@@ -194,7 +194,6 @@ public:
 
 	// Game functions
 	void HandleKeyDown(char theChar);
-	void EventLoop();
 	void Tick();
 	void Splat(int k);
 	~Game();
@@ -204,5 +203,6 @@ extern "C" {
 	void run();
 	void initGl(Game*);
 	void initGame(Game*);
+	void eventLoop(Game*);
 }
 #endif // BLACKSHADES_GAME_H
diff --git a/src/GameDraw.cpp b/src/GameDraw.cpp
index 925cf38..07905e6 100644
--- a/src/GameDraw.cpp
+++ b/src/GameDraw.cpp
@@ -1,7 +1,7 @@
 #include "Game.h"
 
 extern int thirdperson;
-extern double multiplier;
+extern float multiplier;
 extern int nocolors;
 extern int visions;
 extern unsigned int gSourceID[100];
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp
index 2fa7fc1..a4b4a60 100644
--- a/src/GameLoop.cpp
+++ b/src/GameLoop.cpp
@@ -2,6 +2,7 @@
 // Copyright (C) 2002  David Rosen
 // Copyright (C) 2003  Zachary Jack Slater
 // Copyright (C) 2003  Steven Fuller
+// Copyright (C) 2021  Nguyễn Gia Phong
 //
 // This file is part of Black Shades.
 //
@@ -20,7 +21,7 @@
 
 #include "Game.h"
 
-extern double multiplier;
+extern float multiplier;
 extern int visions;
 extern unsigned int gSourceID[100];
 extern unsigned int gSampleSet[100];
@@ -261,69 +262,71 @@ static void ProcessSDLEvents(Game* g)
 	}
 }
 
-void Game::EventLoop()
+void eventLoop(Game* game)
 {
 	unsigned char theKeyMap[16];
-	gQuit = false;
-	framespersecond = 60;
+	game->gQuit = false;
+	game->framespersecond = 60.0f;
 
-	while (!gQuit) {
-		ProcessSDLEvents(this);
-		start = TimerGetTime(&theTimer);
+	while (!game->gQuit) {
+		ProcessSDLEvents(game);
+		game->start = TimerGetTime(&game->theTimer);
 
 		GLfloat oldmult = multiplier;
-		int colaccuracy = min(sps, sps / (float) framespersecond + 1);
+		int colaccuracy = min(game->sps,
+			game->sps / game->framespersecond + 1.0f);
 		multiplier /= colaccuracy;
-		for (int i = 0; i < (int) (colaccuracy + 0.5); i++)
-			Tick();
-		if (DrawGLScene())
+		for (int i = 0; i < (int) (colaccuracy + 0.5f); i++)
+			game->Tick();
+		if (game->DrawGLScene())
 			SDL_GL_SwapBuffers();
 		else
-			gQuit = true;
+			game->gQuit = true;
 		multiplier = oldmult;
 
 		do {
-			end = TimerGetTime(&theTimer);
-			timetaken = end - start;
-			framespersecond = 6e8 / timetaken;
-		} while (framespersecond > maxfps);
+			game->end = TimerGetTime(&game->theTimer);
+			game->timetaken = game->end - game->start;
+			game->framespersecond = 6e8f / game->timetaken;
+		} while (game->framespersecond > game->maxfps);
 
-		multiplier5 = multiplier4;
-		multiplier4 = multiplier3;
-		multiplier3 = multiplier2;
-		multiplier2 = 1 / framespersecond;
-		multiplier = (multiplier2 + multiplier3
-		              + multiplier4 + multiplier5) / 4;
-		multiplier = min(max(multiplier, 0.00001), 1.0);
-		if (visions == 1 && !mainmenu)
+		game->multiplier5 = game->multiplier4;
+		game->multiplier4 = game->multiplier3;
+		game->multiplier3 = game->multiplier2;
+		game->multiplier2 = 1 / game->framespersecond;
+		multiplier = (game->multiplier2 + game->multiplier3
+			+ game->multiplier4 + game->multiplier5) / 4.0f;
+		multiplier = min(max(multiplier, 0.00001f), 1.0f);
+		if (visions == 1 && !game->mainmenu)
 			multiplier /= 3;
 		if (slomo)
 			multiplier /= 5;
-		if (paused)
+		if (game->paused)
 			multiplier = 0;
 
 		GetKeys((unsigned long*) theKeyMap);
 		if (IsKeyDown(theKeyMap, MAC_COMMAND_KEY)
 		    &&IsKeyDown(theKeyMap, MAC_Q_KEY)) {
-			gQuit = true;
-			if (score > highscore) {
-				highscore=score;
+			game->gQuit = true;
+			if (game->score > game->highscore) {
+				game->highscore = game->score;
 				/* TODO */
 				ofstream opstream("highscore.txt");
-				opstream << highscore;
+				opstream << game->highscore;
 				opstream << "\n";
-				opstream << beatgame;
+				opstream << game->beatgame;
 				opstream.close();
 			}
 		}
 
 		if (IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)) {
 			alSourcePause(gSourceID[rainsound]);
-			mainmenu = 1;
+			game->mainmenu = 1;
 			alSourcePlay(gSourceID[souloutsound]);
-			flashamount = flashr = flashg = flashb = 1;
+			game->flashamount = 1.0f;
+			game->flashr = game->flashg = game->flashb = 1.0f;
 			alSourceStop(gSourceID[visionsound]);
-			whichsong = mainmenusong;
+			game->whichsong = mainmenusong;
 			alSourceStop(gSourceID[knifesong]);
 			alSourceStop(gSourceID[shootsong]);
 			alSourceStop(gSourceID[zombiesong]);
@@ -332,8 +335,8 @@ void Game::EventLoop()
 			alSourcef(gSourceID[shootsong], AL_MIN_GAIN, 0);
 			alSourcef(gSourceID[zombiesong], AL_MIN_GAIN, 0);
 			alSourcef(gSourceID[mainmenusong], AL_MIN_GAIN, 0);
-			alSourcePlay(gSourceID[whichsong]);
-			alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 1);
+			alSourcePlay(gSourceID[game->whichsong]);
+			alSourcef(gSourceID[game->whichsong], AL_MIN_GAIN, 1);
 		}
 	}
 }
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 483f0de..2932d8c 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -24,7 +24,7 @@
 
 #include "Game.h"
 
-extern double multiplier;
+extern float multiplier;
 extern int thirdperson;
 extern int visions;
 extern Sprites sprites;
diff --git a/src/Globals.cpp b/src/Globals.cpp
index fa18cfe..6fdad88 100644
--- a/src/Globals.cpp
+++ b/src/Globals.cpp
@@ -7,7 +7,7 @@
 float sinefluct;
 float sinefluctprog;
 
-double multiplier=0;
+float multiplier = 0.0f;
 
 unsigned int gSourceID[100]; // hundred source IDs
 unsigned int gSampleSet[100]; // hundred sample set ID numbers
diff --git a/src/Person.cpp b/src/Person.cpp
index 7e0d41c..d02d002 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -19,7 +19,7 @@
 
 #include "Person.h"
 
-extern double multiplier;
+extern float multiplier;
 extern unsigned int gSourceID[100];
 extern unsigned int gSampleSet[100];
 extern Animation animation[30];
diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp
index e67b5b8..f1f3ff5 100644
--- a/src/Skeleton.cpp
+++ b/src/Skeleton.cpp
@@ -3,7 +3,7 @@
 
 #include "Serialize.h"
 
-extern double multiplier;
+extern float multiplier;
 extern unsigned int gSourceID[100];
 extern unsigned int gSampleSet[100];
 extern int visions;
diff --git a/src/Sprites.cpp b/src/Sprites.cpp
index d18d64a..2459593 100644
--- a/src/Sprites.cpp
+++ b/src/Sprites.cpp
@@ -1,7 +1,7 @@
 #include "Sprites.h"
 #include "Textures.h"
 
-extern double multiplier;
+extern float multiplier;
 extern bool slomo;
 extern Fog fog;
 extern bool blood;