diff --git a/build.zig b/build.zig index 60fa64c..c87e77e 100644 --- a/build.zig +++ b/build.zig @@ -18,7 +18,6 @@ pub fn build(b: *std.Build) void { const raylib_dep = b.dependency("raylib_zig", .{ .target = target, .optimize = optimize, - .shared = true, }); const raylib = raylib_dep.module("raylib"); @@ -43,13 +42,8 @@ pub fn build(b: *std.Build) void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - const main_tests = b.addTest(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize }); - const game_tests = b.addTest(.{ .root_source_file = b.path("src/game.zig"), .target = target, .optimize = optimize }); - - const run_exe_main_tests = b.addRunArtifact(main_tests); - const run_exe_game_tests = b.addRunArtifact(game_tests); - + const tests = b.addTest(.{ .root_module = exe_mod }); + const run_tests = b.addRunArtifact(tests); const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&run_exe_main_tests.step); - test_step.dependOn(&run_exe_game_tests.step); + test_step.dependOn(&run_tests.step); } diff --git a/build.zig.zon b/build.zig.zon index 9ae8166..375280c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -32,8 +32,8 @@ .dependencies = .{ .raylib_zig = .{ - .url = "git+https://github.com/Not-Nik/raylib-zig?ref=devel#5013830647196ba938a3a25a36b8245606e9a9cd", - .hash = "raylib_zig-5.6.0-dev-KE8REM0tBQAHVn9Xjqlgu9l1qgfTmP8aJa1kLhD584bV", + .url = "git+https://github.com/raylib-zig/raylib-zig?ref=devel#cd71c85d571027ac8033357f83b124ee051825b3", + .hash = "raylib_zig-5.6.0-dev-KE8REENOBQC-m5nK7M2b5aKSIubJPbPLUYcRhT7aT3RN", }, }, .paths = .{ diff --git a/src/game.zig b/src/game.zig index 634fdcf..c65fc0f 100644 --- a/src/game.zig +++ b/src/game.zig @@ -28,6 +28,7 @@ pub const Game = struct { playFieldSize: Vec2, direction: Direction, body: std.ArrayList(Vec2), + allocator: std.mem.Allocator, state: State, rng: std.Random.DefaultPrng, @@ -44,7 +45,7 @@ pub const Game = struct { const startPos: u8 = 10; for (0..bodySize) |i| { const index = std.math.cast(i32, i) orelse unreachable; - try body.append(Vec2{ startPos - index, 10 }); + try body.append(allocator, Vec2{ startPos - index, 10 }); } const seed: u64 = @intCast(std.time.nanoTimestamp()); @@ -55,6 +56,7 @@ pub const Game = struct { .food = Vec2{ 11, 13 }, .direction = Direction.right, .body = body, + .allocator = allocator, .state = State.running, .rng = prng, .grow = false, @@ -66,7 +68,7 @@ pub const Game = struct { } pub fn deinit(self: *Game) void { - self.body.deinit(); + self.body.deinit(self.allocator); } pub fn setDirection(self: *Game, newDirection: Direction) void { @@ -104,7 +106,7 @@ pub const Game = struct { } } - try self.body.insert(0, newHead); + try self.body.insert(self.allocator, 0, newHead); if (self.grow) { self.grow = false; } else { diff --git a/src/main.zig b/src/main.zig index 642b0e8..1350299 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,6 +2,10 @@ const std = @import("std"); const rl = @import("raylib"); const g = @import("game.zig"); +test { + _ = g; +} + pub fn main() anyerror!void { const allocator = std.heap.page_allocator; const scaleFactor = 20;