summary refs log tree commit diff
path: root/src/GameInitDispose.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GameInitDispose.cpp')
-rw-r--r--src/GameInitDispose.cpp106
1 files changed, 42 insertions, 64 deletions
diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp
index b208df5..7599837 100644
--- a/src/GameInitDispose.cpp
+++ b/src/GameInitDispose.cpp
@@ -21,6 +21,7 @@
 // along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
 
 #include <AL/alc.h>
+#include <GLFW/glfw3.h>
 
 #include "config.h"
 #include "Textures.h"
@@ -61,9 +62,10 @@ extern int psychickey;
 Game* makeGame(Config config)
 {
 	auto game = new Game();
-	game->screenwidth = config.screen_width;
-	game->screenheight = config.screen_height;
+	game->screenwidth = config.width;
+	game->screenheight = config.height;
 	game->usermousesensitivity = config.mouse_sensitivity;
+	game->mousesensitivity = game->usermousesensitivity;
 	game->debug = config.debug;
 	game->vblsync = config.vsync;
 	blood = config.blood;
@@ -72,6 +74,27 @@ Game* makeGame(Config config)
 	game->customlevels = config.custom_levels;
 	game->musictoggle = config.music;
 	game->azertykeyboard = config.azerty;
+
+	if (!game->initialized) {
+		// TODO: Read high score
+		ifstream ipstream2 {"highscore.txt"};
+		if (!ipstream2) {
+			ofstream opstream("highscore.txt");
+			opstream << (game->highscore = 0) << endl;
+			opstream << (game->beatgame = 0) << endl;
+			opstream.close();
+		} else {
+			ipstream2 >> game->highscore;
+			ipstream2.ignore(256,'\n');
+			ipstream2 >> game->beatgame;
+			ipstream2.close();
+		}
+
+		game->sps = 40;
+		game->maxfps = 90;
+		game->disttest = true;
+		game->cubetest = true;
+	}
 	return game;
 }
 
@@ -370,7 +393,7 @@ void Game::LoadingScreen(float percent)
 	static char string[256]="";
 	sprintf (string, "LOADING...");
 	text.glPrint(280,195,string,1,1,640,480);
-	SDL_GL_SwapBuffers( );
+	glfwSwapBuffers(glfwGetCurrentContext());
 }
 
 void LoadPersonSpriteTexture(char *fileName, GLuint *textureid)
@@ -658,25 +681,24 @@ void initGame(Game* game)
 
 	if (!game->initialized) {
 		if (game->azertykeyboard) {
-			forwardskey = MAC_Z_KEY;
-			backwardskey = MAC_S_KEY;
-			leftkey = MAC_Q_KEY;
-			rightkey = MAC_D_KEY;
-			aimkey = MAC_A_KEY;
-			psychicaimkey = MAC_E_KEY;
-			psychickey = MAC_W_KEY;
+			forwardskey = GLFW_KEY_Z;
+			backwardskey = GLFW_KEY_S;
+			leftkey = GLFW_KEY_Q;
+			rightkey = GLFW_KEY_D;
+			aimkey = GLFW_KEY_A;
+			psychicaimkey = GLFW_KEY_E;
+			psychickey = GLFW_KEY_W;
 		} else {
-			forwardskey = MAC_W_KEY;
-			backwardskey = MAC_S_KEY;
-			leftkey = MAC_A_KEY;
-			rightkey = MAC_D_KEY;
-			aimkey = MAC_Q_KEY;
-			psychicaimkey = MAC_E_KEY;
-			psychickey = MAC_Z_KEY;
+			forwardskey = GLFW_KEY_W;
+			backwardskey = GLFW_KEY_S;
+			leftkey = GLFW_KEY_A;
+			rightkey = GLFW_KEY_D;
+			aimkey = GLFW_KEY_Q;
+			psychicaimkey = GLFW_KEY_E;
+			psychickey = GLFW_KEY_Z;
 		}
 
 		soundscalefactor=soundscalefactordefault; //Setup sound falloff
-		game->gQuit = false;
 
 		// Sounds
 		LoadSounds(game->musictoggle);
@@ -1787,61 +1809,17 @@ void initGame(Game* game)
 	decals.howmanydecals=0;
 	sprites.howmanysprites=0;
 	game->losedelay = 1;
+	game->framespersecond = 60.0f;
 }
 
 void initGl(Game* game)
 {
-	// Config
-	game->mousesensitivity = 1.0f;
-	if (!game->initialized) {
-		// TODO: Read high score
-		ifstream ipstream2 {"highscore.txt"};
-		if (!ipstream2) {
-			ofstream opstream("highscore.txt");
-			opstream << (game->highscore = 0) << endl;
-			opstream << (game->beatgame = 0) << endl;
-			opstream.close();
-		} else {
-			ipstream2 >> game->highscore;
-			ipstream2.ignore(256,'\n');
-			ipstream2 >> game->beatgame;
-			ipstream2.close();
-		}
-
-		game->sps = 40;
-		game->maxfps = 90;
-		game->disttest = true;
-		game->cubetest = true;
-	}
-
-	// Setup screen
-	if (SDL_Init(SDL_INIT_VIDEO) == -1) {
-		fprintf(stderr, "SDL Init Video failed: %s\n", SDL_GetError());
-		exit(EXIT_FAILURE);
-	}
-	atexit(SDL_Quit);
-
-	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
-	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
-	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
-	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
-	if (SDL_SetVideoMode(game->screenwidth, game->screenheight,
-	                     0, SDL_OPENGL) == NULL) {
-		fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n",
-			SDL_GetError());
-		exit(EXIT_FAILURE);
-	}
-	SDL_WM_SetCaption("Black Shades", "Black Shades");
-	SDL_EnableUNICODE(1); /* toggle it to ON */
-
 	game->text.LoadFontTexture((char*) ":Data:Textures:Font.png");
 	game->text.BuildFont();
 	glAlphaFunc(GL_GREATER, 0.01);
 	glDepthFunc(GL_LESS);
 	glPolygonOffset(-8,0);
-	glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 }
 
 GLvoid Game::ReSizeGLScene(float fov, float near)