diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-10-29 18:27:46 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-10-29 18:31:49 +0700 |
commit | 2432be0c7f788270221b6f9eaf3f765b6118d8c2 (patch) | |
tree | b69df71ede09554c6c8792b96f598b486a982832 | |
parent | 6b871944a9b2df0f84cbe3682244e07cb415fe79 (diff) | |
download | blackshades-2.4.3.tar.gz |
Sort imports and clean up 2.4.3
-rw-r--r-- | CHANGES | 8 | ||||
-rw-r--r-- | src/config.zig | 41 | ||||
-rw-r--r-- | src/main.zig | 16 | ||||
-rw-r--r-- | src/misc.zig | 17 |
4 files changed, 35 insertions, 47 deletions
diff --git a/CHANGES b/CHANGES index ff983cf..5d41932 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +Tag: 2.4.3 +Date: 2021-10-29 + + Make keyboard input configurable + + Backwards walking and running animations + have also been accidentally fixed. + Tag: 2.4.2 Date: 2021-10-21 diff --git a/src/config.zig b/src/config.zig index 2e028f1..d204ead 100644 --- a/src/config.zig +++ b/src/config.zig @@ -18,23 +18,27 @@ const Dir = std.fs.Dir; const File = std.fs.File; -const Key = @import("gfz").Key; +const IntegerBitSet = std.bit_set.IntegerBitSet; const allocator = std.heap.c_allocator; -const c = @import("main.zig").c; const cwd = std.fs.cwd; -const data_dir = @import("build_options").data_dir; +const endian = @import("builtin").target.cpu.arch.endian(); const eql = std.mem.eql; -const ini = @import("ini"); const join = std.fs.path.join; const maxInt = std.math.maxInt; const mkdir = std.os.mkdir; -const parseBool = @import("misc.zig").parseBool; const parseFloat = std.fmt.parseFloat; const parseInt = std.fmt.parseInt; const std = @import("std"); const stringToEnum = std.meta.stringToEnum; const tokenize = std.mem.tokenize; +const Key = @import("gfz").Key; +const ini = @import("ini"); + +const data_dir = @import("build_options").data_dir; +const c = @import("cimport.zig"); +const parseBool = @import("misc.zig").parseBool; + const default_levels_len = 13; /// Open the given file for reading, @@ -58,18 +62,6 @@ const Level = extern struct { difficulty: f32, }; -const Weapons = packed struct { - // TODO: remove nogun and sort - jaw: bool = false, - sniper_rifle: bool = false, - assault_rifle: bool = false, - magnum: bool = false, - handgun: bool = false, - grenade: bool = false, - knife: bool = false, - shotgun: bool = false, -}; - fn parseLevels(dir_path: []const u8, length: usize) ![*]Level { var dir = try cwd().makeOpenPath(dir_path, .{}); defer dir.close(); @@ -99,20 +91,11 @@ fn parseLevels(dir_path: []const u8, length: usize) ![*]Level { c.night_environment else return error.InvalidData; } else if (eql(u8, kv.key, "evil weapons")) { - var weapons = Weapons{}; + var weapons = IntegerBitSet(8).initEmpty(); var enums = tokenize(kv.value, " "); while (enums.next()) |weapon| - switch (try parseInt(u3, weapon, 10)) { - c.nogun => weapons.jaw = true, - c.sniperrifle => weapons.sniper_rifle = true, - c.assaultrifle => weapons.assault_rifle = true, - c.handgun1 => weapons.magnum = true, - c.handgun2 => weapons.handgun = true, - c.grenade => weapons.grenade = true, - c.knife => weapons.knife = true, - c.shotgun => weapons.shotgun = true, - }; - levels[i].evil_weapons = @bitCast(u8, weapons); + weapons.set(try parseInt(u3, weapon, 10)); + levels[i].evil_weapons = weapons.mask; } else if (eql(u8, kv.key, "evil rarity")) { levels[i].evil_rarity = try parseInt(u8, kv.value, 10); } else if (eql(u8, kv.key, "guard weapon")) { diff --git a/src/main.zig b/src/main.zig index 241e557..f6a2353 100644 --- a/src/main.zig +++ b/src/main.zig @@ -16,23 +16,21 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. -pub const c = @cImport({ - @cInclude("Game.h"); - @cInclude("Constants.h"); -}); +const allocator = std.heap.c_allocator; +const free = std.c.free; +const std = @import("std"); const Loca = @import("loca").Loca; -const Scores = misc.Scores; const al = @import("zeal"); -const allocator = std.heap.c_allocator; -const configuration = @import("config.zig"); -const free = std.c.free; const gf = @import("gfz"); const gl = @import("zgl"); + +const Scores = misc.Scores; +const c = @import("cimport.zig"); +const configuration = @import("config.zig"); const misc = @import("misc.zig"); const loadScores = misc.loadScores; const saveScores = misc.saveScores; -const std = @import("std"); var game: *c.Game = undefined; diff --git a/src/misc.zig b/src/misc.zig index 678538b..359c914 100644 --- a/src/misc.zig +++ b/src/misc.zig @@ -25,22 +25,15 @@ usingnamespace @cImport({ const Dir = std.fs.Dir; const TokenIterator = std.mem.TokenIterator; -const Key = gf.Key; -const Window = gf.Window; -const al = @import("zeal"); const allocPrint = std.fmt.allocPrint; const allocator = std.heap.c_allocator; const assert = std.debug.assert; const count = std.mem.count; const cwd = std.fs.cwd; -const data_dir = @import("build_options").data_dir ++ [_]u8{ sep }; const endsWith = std.mem.endsWith; const eql = std.mem.eql; const free = std.c.free; -const gf = @import("gfz"); -const ini = @import("ini"); const join = std.fs.path.joinZ; -const hash = std.crypto.hash.Blake3.hash; const maxInt = std.math.maxInt; const parseFloat = std.fmt.parseFloat; const parseInt = std.fmt.parseInt; @@ -50,10 +43,16 @@ const startsWith = std.mem.startsWith; const std = @import("std"); const tokenize = std.mem.tokenize; +const al = @import("zeal"); +const gf = @import("gfz"); +const ini = @import("ini"); + +const data_dir = @import("build_options").data_dir ++ [_]u8{ sep }; + /// Return whether the given keyboard key is pressed. export fn keyPress(key: c_int) bool { - const window = (Window.getCurrent() catch unreachable).?; - return (window.getKey(@intToEnum(Key, key)) catch unreachable) == .press; + const window = (gf.Window.getCurrent() catch unreachable).?; + return (window.getKey(@intToEnum(gf.Key, key)) catch unreachable) == .press; } /// Read given file to heap, allocated by C allocator. |