summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-09-12 00:28:36 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-09-12 00:31:47 +0700
commit62445a15b14a059032d7c0c3e16a959d25bff604 (patch)
tree4c0aba823939c3d266bc447dfe6c51fa4f2c0f1a
parente3614a94b984d12baa7f4f6010b6707805ce0928 (diff)
downloadblackshades-2.2.0.tar.gz
Make window resizable 2.2.0
m---------lib/gfz0
-rw-r--r--src/Game.h11
-rw-r--r--src/GameDraw.cpp12
-rw-r--r--src/GameInitDispose.cpp12
-rw-r--r--src/GameLoop.cpp2
-rw-r--r--src/main.zig15
6 files changed, 29 insertions, 23 deletions
diff --git a/lib/gfz b/lib/gfz
-Subproject 22b95f38d9c6e2bcaf6cc746bf4bfc654e2413a
+Subproject c4d5e7dccfdfa102f1aeb39074789ce3d51dac9
diff --git a/src/Game.h b/src/Game.h
index f290f34..7e27345 100644
--- a/src/Game.h
+++ b/src/Game.h
@@ -194,11 +194,12 @@ typedef struct Game Game;
 extern "C" {
 #endif // __cplusplus
 	Game* makeGame(struct Config config);
-	void initGl(Game*);
-	void initGame(Game*);
-	void keyCallback(Game*, int key, int action, int mods);
-	void eventLoop(Game*);
-	void closeGame(Game*);
+	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 eventLoop(Game* game);
+	void closeGame(Game* game);
 #ifdef __cplusplus
 } // extern "C"
 #endif // __cplusplus
diff --git a/src/GameDraw.cpp b/src/GameDraw.cpp
index 07905e6..9612a5b 100644
--- a/src/GameDraw.cpp
+++ b/src/GameDraw.cpp
@@ -720,14 +720,12 @@ int Game::DrawGLScene(void)
 
 			glEnable(GL_LIGHT0);
 
-			//Change fov if zooming with scope
-
-			if(!zoom)ReSizeGLScene(90,.1);
-
-			if(zoom)ReSizeGLScene(10,.6);
-
+			// Change fov if zooming with scope
+			if (zoom)
+				ReSizeGLScene(10.0f, 0.6f);
+			else
+				ReSizeGLScene(90.0f, 0.1f);
 			nocolors=0;
-
 		}
 
 		if(visions==1){
diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp
index 2d2a5c4..1c8cffb 100644
--- a/src/GameInitDispose.cpp
+++ b/src/GameInitDispose.cpp
@@ -58,11 +58,16 @@ extern int aimkey;
 extern int psychicaimkey;
 extern int psychickey;
 
+void resizeWindow(Game* game, int width, int height)
+{
+	game->screenwidth = width;
+	game->screenheight = height;
+}
+
 Game* makeGame(Config config)
 {
 	auto game = new Game();
-	game->screenwidth = config.width;
-	game->screenheight = config.height;
+	resizeWindow(game, config.width, config.height);
 	game->usermousesensitivity = config.mouse_sensitivity;
 	game->mousesensitivity = game->usermousesensitivity;
 	game->debug = config.debug;
@@ -1811,9 +1816,6 @@ void initGl(Game* game)
 
 GLvoid Game::ReSizeGLScene(float fov, float near)
 {
-	if (screenheight==0)
-		screenheight=1;
-
 	glViewport(0,0,screenwidth,screenheight);
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp
index 1ef1c9f..7b7c617 100644
--- a/src/GameLoop.cpp
+++ b/src/GameLoop.cpp
@@ -35,7 +35,7 @@ extern int aimkey;
 extern int psychicaimkey;
 extern int psychickey;
 
-void keyCallback(Game* game, int key, int action, int mods)
+void handleKey(Game* game, int key, int action, int mods)
 {
 	if (action != GLFW_PRESS)
 		return;
diff --git a/src/main.zig b/src/main.zig
index 976fdd6..2364b8e 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -26,10 +26,14 @@ const gl = @import("zgl");
 
 var game: *legacy.Game = undefined;
 
-fn keyCallback(window: ?@typeInfo(gf.Window).Struct.fields[0].field_type,
-               key: c_int, scancode: c_int,
-               action: c_int, mods: c_int) callconv(.C) void {
-    legacy.keyCallback(game, key, action, mods);
+fn resizeWindow(window: ?*gf.Window.Impl,
+                width: c_int, height: c_int) callconv(.C) void {
+    legacy.resizeWindow(game, width, height);
+}
+
+fn handleKey(window: ?*gf.Window.Impl, key: c_int, scancode: c_int,
+             action: c_int, mods: c_int) callconv(.C) void {
+    legacy.handleKey(game, key, action, mods);
 }
 
 pub fn main() !void {
@@ -43,6 +47,7 @@ pub fn main() !void {
     const window = try gf.Window.create(config.width, config.height,
                                         "Black Shades", .{}, .{});
     try window.makeCurrent();
+    try window.setSizeCallback(resizeWindow);
     legacy.initGl(game);
 
     try window.setCursorMode(.disabled);
@@ -50,7 +55,7 @@ pub fn main() !void {
         try window.setInputMode(.raw_mouse_motion, true);
     try window.setInputMode(.sticky_mouse_buttons, true);
     try window.setInputMode(.sticky_keys, true);
-    try window.setKeyCallback(keyCallback);
+    try window.setKeyCallback(handleKey);
 
     const device = try al.Device.init(null);
     defer device.deinit() catch unreachable;