summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/Game.h7
-rw-r--r--src/GameDraw.cpp112
-rw-r--r--src/GameInitDispose.cpp42
-rw-r--r--src/GameLoop.cpp14
-rw-r--r--src/GameTick.cpp8
-rw-r--r--src/config.h1
-rw-r--r--src/config.ini1
-rw-r--r--src/config.zig5
-rw-r--r--src/main.zig4
9 files changed, 47 insertions, 147 deletions
diff --git a/src/Game.h b/src/Game.h
index 5e6520b..58770c3 100644
--- a/src/Game.h
+++ b/src/Game.h
@@ -122,9 +122,8 @@ public:
 	bool blurness;
 
 	bool paused;
-	int mainmenu;
+	bool menu;
 
-	Point olddrawmouse;
 	XYZ vipgoal;
 	XYZ aimer[2];
 
@@ -156,7 +155,6 @@ public:
 	bool killedinnocent;
 	bool gameinprogress;
 	bool beatgame;
-	bool mainmenuness;
 	int murderer;
 	float timeremaining;
 	int whichsong;
@@ -178,6 +176,8 @@ public:
 	void Splat(int k);
 };
 #else // __cplusplus
+#include <stdbool.h>
+
 typedef struct Game Game;
 #endif // __cplusplus
 
@@ -189,6 +189,7 @@ extern "C" {
 	void handleKey(Game* game, int key, int action, int mods);
 	void initGl(Game* game);
 	void initGame(Game* game);
+	void setMenu(Game* game, bool value);
 	void eventLoop(Game* game);
 	void closeGame(Game* game);
 #ifdef __cplusplus
diff --git a/src/GameDraw.cpp b/src/GameDraw.cpp
index a3d9fe7..471786d 100644
--- a/src/GameDraw.cpp
+++ b/src/GameDraw.cpp
@@ -42,7 +42,7 @@ extern Decals decals;
 void Game::DrawGLScene(void)
 {
 	//Main menu
-	if (mainmenu == 1) {
+	if (this->menu) {
 		//Setup fast sine fluctuation
 		sinefluct=sin(sinefluctprog);
 		sinefluctprog+=multiplier*1.5;
@@ -425,106 +425,19 @@ void Game::DrawGLScene(void)
 
 		glDepthMask(1);
 
-		//Text
-
+		// Text
 		glEnable(GL_TEXTURE_2D);
+		glColor4f(0.0f ,0.0f ,0.0f ,1.0f);
+		sprintf(string, gameinprogress ? "End Game" : "Quit");
+		text.glPrint(197 - gameinprogress * 15, 87, string, 1, 1.5, 640, 480);
 
-		glColor4f(0,0,0,1);
-
-		if(!gameinprogress)sprintf (string, "Quit");
-
-		if(gameinprogress)sprintf (string, "End Game");
-
-		text.glPrint(197-gameinprogress*15,87,string,1,1.5,640,480);
-
-		//High score
-
-		glColor4f(.5+sinefluct/5,0,0,1);
-
-		if(!beatgame)sprintf (string, "High Score:  %d", highscore);
-
-		if(beatgame)sprintf (string, "High Score:  %d *COMPLETED* Please vote for Black Shades at iDevGames.com!", highscore);
-
-		text.glPrint(0,0,string,1,.8,640,480);
-
-		//Mandatory udg text
-
-		glColor4f(.3-sinefluct/20,.3-sinefluct/20,.3-sinefluct/20,1);
-
-		sprintf (string, "uDevGame 2002 Entry - Visit iDevGames.com for more games!");
-
-		text.glPrint(500,750,string,1,.6,640,480);
-
-		//Mouse (draw)
-
-		glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
-
-		glPushMatrix();										// Store The Projection Matrix
-
-		glLoadIdentity();									// Reset The Projection Matrix
-
-		glOrtho(0,screenwidth,0,screenheight,-100,100);						// Set Up An Ortho Screen
-
-		glMatrixMode(GL_MODELVIEW);
-
-		glDisable(GL_TEXTURE_2D);
-
-		Point mouseloc;
-
-		GetMouse(&mouseloc);
-
-		mouseloc.v=screenheight-mouseloc.v;
-
-		glColor4f(.1,0,0,1);
-
-		float size=5;
-
-		glBegin(GL_TRIANGLES);
-
-			glVertex3f(mouseloc.h,mouseloc.v,0);
-
-			glVertex3f(mouseloc.h+2*size,mouseloc.v-2*size,0);
-
-			glVertex3f(mouseloc.h+.5*size,mouseloc.v-2*size,0);
-
-		glEnd();
-
-		glColor4f(1,0,0,1);
-
-		glBegin(GL_QUADS);
-
-			glVertex3f(olddrawmouse.h,olddrawmouse.v,0);
-
-			glVertex3f(mouseloc.h,mouseloc.v,0);
-
-			glVertex3f(mouseloc.h+2*size,mouseloc.v-2*size,0);
-
-			glVertex3f(olddrawmouse.h+2*size,olddrawmouse.v-2*size,0);
-
-			glVertex3f(olddrawmouse.h,olddrawmouse.v,0);
-
-			glVertex3f(mouseloc.h,mouseloc.v,0);
-
-			glVertex3f(mouseloc.h+.5*size,mouseloc.v-2*size,0);
-
-			glVertex3f(olddrawmouse.h+.5*size,olddrawmouse.v-2*size,0);
-
-			glVertex3f(olddrawmouse.h+2*size,olddrawmouse.v-2*size,0);
-
-			glVertex3f(mouseloc.h+2*size,mouseloc.v-2*size,0);
-
-			glVertex3f(mouseloc.h+.5*size,mouseloc.v-2*size,0);
-
-			glVertex3f(olddrawmouse.h+.5*size,olddrawmouse.v-2*size,0);
-
-		glEnd();
-
-		glPopMatrix();
-
-		olddrawmouse=mouseloc;
-
-		//Flash
+		// High score
+		glColor4f(0.5f + sinefluct / 5.0f, 0.0f, 0.0f, 1.0f);
+		sprintf(string, "High Score: %d%s", highscore,
+			beatgame ? " *COMPLETED*" : "");
+		text.glPrint(0, 0, string, 1, 0.8, 640, 480);
 
+		// Flash
 		if(flashamount>0){
 
 			if(flashamount>1)flashamount=1;
@@ -592,9 +505,6 @@ void Game::DrawGLScene(void)
 			glDepthMask(1);
 		}
 	} else { // in-game
-		// If flashing to fix menu bug, go back to menu after a frame
-		if (mainmenu == 2)
-			mainmenu = 1;
 		glLoadIdentity();
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		glEnable(GL_DEPTH_TEST);
diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp
index d94f6f6..e5fb13c 100644
--- a/src/GameInitDispose.cpp
+++ b/src/GameInitDispose.cpp
@@ -85,28 +85,26 @@ Game* makeGame(Config config)
 	psychicaimkey = GLFW_KEY_E;
 	psychickey = GLFW_KEY_Z;
 
-	game->mainmenuness = config.menu;
 	game->customlevels = config.custom_levels;
 	game->debug = config.debug;
 
-	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->disttest = true;
-		game->cubetest = true;
+	// 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->disttest = true;
+	game->cubetest = true;
+	setMenu(game, true);
 	return game;
 }
 
@@ -1641,14 +1639,6 @@ void initGame(Game* game)
 	game->eqn[3] = 0;
 	glClearColor(fogcolorr,fogcolorg,fogcolorb,1);
 
-	// Draw city one frame to fix evil menu bug
-	if (!game->initialized) {
-		game->mainmenu = 2;
-		game->flashamount = 1;
-		game->flashr = game->flashg = game->flashb = 1;
-		alSourcePlay(gSourceID[soulinsound]);
-	}
-
 	game->initialized = true;
 	/*
 	for(int i=0;i<sprites.howmanysprites;i++){
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp
index 1691157..a927f2f 100644
--- a/src/GameLoop.cpp
+++ b/src/GameLoop.cpp
@@ -39,16 +39,16 @@ void handleKey(Game* game, int key, int action, int mods)
 {
 	if (action != GLFW_PRESS)
 		return;
-	if (game->mainmenu) {
+	if (game->menu) {
 		if (key == GLFW_KEY_SPACE)
-			game->mainmenu = 0;
+			setMenu(game, false);
 		return;
 	}
 
 	auto& player = game->person[0];
 	if (key == GLFW_KEY_ESCAPE) {
 		alSourcePause(gSourceID[rainsound]);
-		game->mainmenu = 1;
+		setMenu(game, true);
 		alSourcePlay(gSourceID[souloutsound]);
 		game->flashamount = 1.0f;
 		game->flashr = game->flashg = game->flashb = 1.0f;
@@ -198,6 +198,12 @@ void handleKey(Game* game, int key, int action, int mods)
 	}
 }
 
+void setMenu(Game* game, bool val)
+{
+	glfwSetInputMode(glfwGetCurrentContext(), GLFW_CURSOR,
+		(game->menu = val) ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED);
+}
+
 void eventLoop(Game* game)
 {
 	auto start = glfwGetTime();
@@ -206,7 +212,7 @@ void eventLoop(Game* game)
 
 	do multiplier = glfwGetTime() - start;
 	while (multiplier < 1.0f / 69);
-	if (visions == 1 && !game->mainmenu)
+	if (visions == 1 && !game->menu)
 		multiplier /= 3;
 	if (slomo)
 		multiplier /= 5;
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index af77e40..760db74 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -136,8 +136,6 @@ void Game::handleMenu()
 			mouseoverbutton = 1;
 		else if (mousey > 112 && mousey < 182)
 			mouseoverbutton = 2;
-	} else if (!mainmenuness) {
-		mouseoverbutton = 1;
 	}
 	oldbutton = button;
 
@@ -157,7 +155,7 @@ void Game::handleMenu()
 			alSourcePlay(gSourceID[visionsound]);
 
 		gameinprogress = 1;
-		mainmenu = 0;
+		setMenu(this, false);
 		break;
 	case 2:
 		if (gameinprogress) {
@@ -320,7 +318,7 @@ XYZ Game::aimBot(int j)
 
 void Game::Tick()
 {
-	if (mainmenu) {
+	if (this->menu) {
 		handleMenu();
 		return;
 	}
@@ -350,7 +348,7 @@ void Game::Tick()
 			alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 1);
 			alSourcePlay(gSourceID[whichsong]);
 
-			mainmenu = beatgame = 1;
+			setMenu(this, beatgame = true);
 			gameinprogress = 0;
 			saveHighScore();
 		} else {
diff --git a/src/config.h b/src/config.h
index 8220a78..693ca69 100644
--- a/src/config.h
+++ b/src/config.h
@@ -15,7 +15,6 @@ struct Config {
 
 	float mouse_sensitivity;
 
-	bool menu;
 	bool custom_levels;
 	bool debug;
 };
diff --git a/src/config.ini b/src/config.ini
index 2961a1f..9889ad4 100644
--- a/src/config.ini
+++ b/src/config.ini
@@ -12,6 +12,5 @@ music = true
 mouse sensitivity = 0.7
 
 [misc]
-menu = true
 custom levels = false
 debug = false
diff --git a/src/config.zig b/src/config.zig
index 380a866..e54a70d 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -40,7 +40,6 @@ pub const Config = extern struct {
 
     mouse_sensitivity: f32 = 0.7,
 
-    menu: bool = true,
     custom_levels: bool = false,
     debug: bool = false,
 };
@@ -100,9 +99,7 @@ pub fn parse(allocator: *Allocator, base_dir: []const u8) !Config {
                     config.mouse_sensitivity = try parseFloat(f32, kv.value)
                 else unreachable;
             } else if (eql(u8, section, "misc")) {
-                if (eql(u8, kv.key, "menu"))
-                    config.menu = try parseBool(kv.value)
-                else if (eql(u8, kv.key, "custom levels"))
+                if (eql(u8, kv.key, "custom levels"))
                     config.custom_levels = try parseBool(kv.value)
                 else if (eql(u8, kv.key, "debug"))
                     config.debug = try parseBool(kv.value)
diff --git a/src/main.zig b/src/main.zig
index 3add1ac..dd071fa 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -40,18 +40,18 @@ pub fn main() !void {
     const loca = try Loca.init(allocator, .{});
     defer loca.deinit();
     const config = try configuration.parse(allocator, loca.user_config);
-    game = legacy.makeGame(@bitCast(legacy.Config, config)).?;
 
     try gf.init();
     defer gf.deinit() catch unreachable;
     const window = try gf.Window.create(config.width, config.height,
                                         "Black Shades", .{}, .{});
     try window.makeCurrent();
+
+    game = legacy.makeGame(@bitCast(legacy.Config, config)).?;
     try window.setSizeCallback(resizeWindow);
     try gf.swapInterval(@boolToInt(config.vsync));
     legacy.initGl(game);
 
-    try window.setCursorMode(.disabled);
     if (try gf.rawMouseMotionSupported())
         try window.setInputMode(.raw_mouse_motion, true);
     try window.setInputMode(.sticky_mouse_buttons, true);