diff options
m--------- | lib/gfz | 0 | ||||
-rw-r--r-- | src/Game.h | 4 | ||||
-rw-r--r-- | src/GameInitDispose.cpp | 1 | ||||
-rw-r--r-- | src/GameLoop.cpp | 99 | ||||
-rw-r--r-- | src/GameTick.cpp | 2 | ||||
-rw-r--r-- | src/main.zig | 17 |
6 files changed, 61 insertions, 62 deletions
diff --git a/lib/gfz b/lib/gfz -Subproject be76fd8b6e8ce2c4be4a53e0f3e9ced369ad5e6 +Subproject 22b95f38d9c6e2bcaf6cc746bf4bfc654e2413a diff --git a/src/Game.h b/src/Game.h index 6e53188..1f92ba7 100644 --- a/src/Game.h +++ b/src/Game.h @@ -22,6 +22,8 @@ #ifndef BLACKSHADES_GAME_H #define BLACKSHADES_GAME_H +#include <GLFW/glfw3.h> + #include "config.h" #ifdef __cplusplus @@ -190,7 +192,6 @@ public: void LoadingScreen(float percent); // Game functions - void HandleKeyDown(char theChar); void Tick(); void Splat(int k); }; @@ -204,6 +205,7 @@ extern "C" { 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*); #ifdef __cplusplus diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index 7599837..bbcd5b2 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -21,7 +21,6 @@ // 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" 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, diff --git a/src/GameTick.cpp b/src/GameTick.cpp index 61e5dec..708508e 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -22,8 +22,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; diff --git a/src/main.zig b/src/main.zig index 70d08c1..976fdd6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -24,22 +24,33 @@ const configuration = @import("config.zig"); const al = @import("zeal"); 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); +} + pub fn main() !void { const loca = try Loca.init(allocator, .{}); defer loca.deinit(); const config = try configuration.parse(allocator, loca.user_config); - const game = legacy.makeGame(@bitCast(legacy.Config, 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(); + legacy.initGl(game); + try window.setCursorMode(.disabled); - // try window.setInputMode(.raw_mouse_motion, true); + if (try gf.rawMouseMotionSupported()) + try window.setInputMode(.raw_mouse_motion, true); try window.setInputMode(.sticky_mouse_buttons, true); try window.setInputMode(.sticky_keys, true); - legacy.initGl(game); + try window.setKeyCallback(keyCallback); const device = try al.Device.init(null); defer device.deinit() catch unreachable; |