diff options
-rw-r--r-- | src/GameLoop.cpp | 39 | ||||
-rw-r--r-- | src/config.h | 2 | ||||
-rw-r--r-- | src/config.zig | 72 |
3 files changed, 59 insertions, 54 deletions
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index cc383c8..3364bc2 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -158,30 +158,21 @@ void handleKey(Game* game, int key, int action, int mods) if (!game->debug) return; - const auto shift = mods & GLFW_MOD_SHIFT; - XYZ facing; - - switch(key) { - case GLFW_KEY_TAB: + if (key == keymap.switch_view) { thirdperson = (thirdperson == 2) ? 0 : (thirdperson + 1); - break; - case GLFW_KEY_K: + } else if (key == keymap.skip) { game->timeremaining = 0; - break; - case GLFW_KEY_B: + } else if (key == keymap.pause) { alSourcePlay(gSourceID[soulinsound]); - 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 GLFW_KEY_F: - facing = {0, 0, -1}; - facing = DoRotation(facing, -camera.rotation2, 0, 0); + game->paused = 1 - game->paused; + } else if (key == keymap.slomo) { + alSourcePlay(gSourceID[soulinsound]); + 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); + } else if (key == keymap.force) { + auto facing = DoRotation({0, 0, -1}, -camera.rotation2, 0, 0); facing = DoRotation(facing, 0, 0 - camera.rotation, 0); alSourcePlay(gSourceID[souloutsound]); @@ -208,17 +199,15 @@ void handleKey(Game* game, int key, int action, int mods) joint.velocity.z += abs(Random() % 20) - 10; } } - break; - case GLFW_KEY_X: + } else if (key == keymap.switch_weapon) { if (player.grenphase) - break; + return; player.grenphase = 0; player.ammo = -1; player.whichgun++; if (player.whichgun > 7) player.whichgun = 0; player.reloads[player.whichgun] = 3; - break; } } diff --git a/src/config.h b/src/config.h index a58c2f3..9adaab1 100644 --- a/src/config.h +++ b/src/config.h @@ -18,6 +18,8 @@ struct Key { int forwards, backwards, left, right; int crouch, accelerate, dive; int reload, aim, psychic_aim, psychic, laser_sight; + int switch_view, switch_weapon; + int skip, pause, slomo, force; }; struct Config { diff --git a/src/config.zig b/src/config.zig index 86eb6d8..2e028f1 100644 --- a/src/config.zig +++ b/src/config.zig @@ -140,30 +140,32 @@ pub const Config = extern struct { music: bool = true, mouse_sensitivity: f32 = 1.0, - // TODO: Convert to Key enum key: extern struct { - forwards: c_int = @enumToInt(Key.W), - backwards: c_int = @enumToInt(Key.S), - left: c_int = @enumToInt(Key.A), - right: c_int = @enumToInt(Key.D), - crouch: c_int = @enumToInt(Key.LEFT_CONTROL), - accelerate: c_int = @enumToInt(Key.LEFT_SHIFT), - dive: c_int = @enumToInt(Key.SPACE), - reload: c_int = @enumToInt(Key.R), - aim: c_int = @enumToInt(Key.E), - psychic_aim: c_int = @enumToInt(Key.Q), - psychic: c_int = @enumToInt(Key.Z), - laser_sight: c_int = @enumToInt(Key.L), + forwards: Key = .W, + backwards: Key = .S, + left: Key = .A, + right: Key = .D, + crouch: Key = .LEFT_CONTROL, + accelerate: Key = .LEFT_SHIFT, + dive: Key = .SPACE, + reload: Key = .R, + aim: Key = .E, + psychic_aim: Key = .Q, + psychic: Key = .Z, + laser_sight: Key = .L, + + switch_view: Key = .TAB, + switch_weapon: Key = .X, + skip: Key = .K, + pause: Key = .P, + slomo: Key = .B, + force: Key = .F, } = .{}, levels: extern struct { ptr: [*]Level = undefined, len: usize = 0 } = .{}, debug: bool = false, }; -fn parseKey(str: []const u8) c_int { - return @enumToInt(stringToEnum(Key, str).?); -} - /// Parse config.ini in the given base directory. pub fn parse(base_dir: []const u8) !Config { const config_dir = try join(allocator, &.{ base_dir, "blackshades" }); @@ -204,29 +206,41 @@ pub fn parse(base_dir: []const u8) !Config { if (eql(u8, kv.key, "mouse sensitivity")) config.mouse_sensitivity = try parseFloat(f32, kv.value) else if (eql(u8, kv.key, "forwards key")) - config.key.forwards = parseKey(kv.value) + config.key.forwards = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "backwards key")) - config.key.backwards = parseKey(kv.value) + config.key.backwards = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "left key")) - config.key.left = parseKey(kv.value) + config.key.left = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "right key")) - config.key.right = parseKey(kv.value) + config.key.right = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "crouch key")) - config.key.crouch = parseKey(kv.value) + config.key.crouch = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "accelerate key")) - config.key.accelerate = parseKey(kv.value) + config.key.accelerate = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "dive key")) - config.key.dive = parseKey(kv.value) + config.key.dive = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "reload key")) - config.key.reload = parseKey(kv.value) + config.key.reload = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "aim key")) - config.key.aim = parseKey(kv.value) + config.key.aim = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "psychic aim key")) - config.key.psychic_aim = parseKey(kv.value) + config.key.psychic_aim = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "psychic key")) - config.key.psychic = parseKey(kv.value) + config.key.psychic = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "laser sight key")) - config.key.laser_sight = parseKey(kv.value) + config.key.laser_sight = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "switch view key")) + config.key.switch_view = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "switch weapon key")) + config.key.switch_weapon = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "skip key")) + config.key.skip = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "pause key")) + config.key.pause = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "slomo key")) + config.key.slomo = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "force key")) + config.key.force = stringToEnum(Key, kv.value).? else return error.InvalidData; } else if (eql(u8, section, "misc")) { if (eql(u8, kv.key, "custom levels")) |