This commit is contained in:
Dario48 2026-04-18 22:35:31 +02:00
commit c0f3adda16
5 changed files with 107 additions and 60 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.zig-cache/
zig-out/
zig-pkg/
result

View file

@ -4,6 +4,16 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const raylib_dep = b.dependency("raylib_zig", .{
.target = target,
.optimize = optimize,
.linux_display_backend = .Wayland,
});
const raylib = raylib_dep.module("raylib");
const raygui = raylib_dep.module("raygui");
const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
const mod = b.addModule("sand", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
@ -17,36 +27,29 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.imports = &.{
.{ .name = "sand", .module = mod },
.{ .name = "raylib", .module = raylib },
.{ .name = "raygui", .module = raygui },
},
}),
});
exe.root_module.linkLibrary(raylib_artifact);
b.installArtifact(exe);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const mod_tests = b.addTest(.{
.root_module = mod,
});
const run_mod_tests = b.addRunArtifact(mod_tests);
const exe_tests = b.addTest(.{
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
const exe_check = b.addExecutable(.{
.name = "sand",
.root_module = exe.root_module,
});
const run_exe_tests = b.addRunArtifact(exe_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
test_step.dependOn(&run_exe_tests.step);
const check = b.step("check", "Check if foo compiles");
check.dependOn(&exe_check.step);
}

View file

@ -3,7 +3,12 @@
.version = "1.0.0",
.fingerprint = 0xa07a92116fcc91c3, // Changing this has security and trust implications.
.minimum_zig_version = "0.16.0",
.dependencies = .{},
.dependencies = .{
.raylib_zig = .{
.url = "git+https://github.com/raylib-zig/raylib-zig?ref=devel#4b6a05cd102d51f00523dd5c5e18e628df359d20",
.hash = "raylib_zig-5.6.0-dev-KE8REKNmBQDek2Sz27ULioxYpY9IYR0K0CeIC-iJRLCI",
},
},
.paths = .{
"build.zig",
"build.zig.zon",

View file

@ -14,31 +14,45 @@
let
forAllSystems =
f:
builtins.mapAttrs (system: pkgs: f pkgs zig.packages.${system}.zig_0_16_0) nixpkgs.legacyPackages;
builtins.foldl' nixpkgs.lib.recursiveUpdate { } (
builtins.map (system: f system nixpkgs.legacyPackages.${system} zig.packages.${system}.zig_0_16_0) (
builtins.attrNames nixpkgs.legacyPackages
)
);
in
{
devShells = forAllSystems (
pkgs: zig: {
default = pkgs.mkShellNoCC {
packages = [
pkgs.bash
zig
zig.zls
];
};
}
);
forAllSystems (
system: pkgs: zig:
let
nativeBuildInputs = with pkgs; [
wayland-scanner
pkg-config
];
buildInputs = with pkgs; [
libGL
wayland
libxkbcommon
];
in
{
devShells.${system}.default = pkgs.mkShellNoCC {
packages = [
pkgs.bash
zig
zig.zls
];
inherit buildInputs;
inherit nativeBuildInputs;
};
packages = forAllSystems (
pkgs: zig: {
default = zig.makePackage {
pname = "sand";
version = "1.0.0";
src = ./.;
zigReleaseMode = "fast";
depsHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
};
}
);
};
packages.${system}.default = zig.makePackage {
pname = "sand";
version = "1.0.0";
src = ./.;
zigReleaseMode = "fast";
depsHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
inherit buildInputs;
inherit nativeBuildInputs;
};
}
);
}

View file

@ -2,28 +2,52 @@ const std = @import("std");
const sand = @import("sand");
const raylib = @import("raylib");
const raygui = @import("raygui");
pub fn main(init: std.process.Init) !void {
var grid: sand.Grid = try .init(4, 4, init.gpa);
var gridCopy: sand.Grid = try .init(4, 4, init.gpa);
const screenWidth = 800;
const screenHeight = 450;
var grid: sand.Grid = try .init(screenWidth, screenHeight, init.gpa);
// var gridCopy: sand.Grid = try .init(4, 4, init.gpa);
defer grid.deinit(init.gpa);
defer gridCopy.deinit(init.gpa);
// defer gridCopy.deinit(init.gpa);
//
// grid.arr[2][0].alive = true;
// grid.arr[2][1].alive = true;
// grid.arr[2][2].alive = true;
// grid.arr[2][3].alive = true;
//
// grid.arr[0][1].alive = true;
// grid.arr[1][1].alive = true;
// grid.arr[1][2].alive = true;
//
// std.debug.print("{f}\n", .{grid});
// try grid.copy(&gridCopy);
// grid.updateAll();
//
// while (!grid.eql(gridCopy)) {
// std.debug.print("{f}\n", .{grid});
// try grid.copy(&gridCopy);
// grid.updateAll();
// }
grid.arr[2][0].alive = true;
grid.arr[2][1].alive = true;
grid.arr[2][2].alive = true;
grid.arr[2][3].alive = true;
raylib.initWindow(screenWidth, screenHeight, "sand");
defer raylib.closeWindow();
grid.arr[0][1].alive = true;
grid.arr[1][1].alive = true;
grid.arr[1][2].alive = true;
raylib.setTargetFPS(60);
std.debug.print("{f}\n", .{grid});
try grid.copy(&gridCopy);
grid.updateAll();
while (!grid.eql(gridCopy)) {
std.debug.print("{f}\n", .{grid});
try grid.copy(&gridCopy);
while (!raylib.windowShouldClose()) {
grid.updateAll();
raylib.beginDrawing();
defer raylib.endDrawing();
for (grid.arr, 0..) |line, y| {
for (line, 0..) |cell, x| {
raylib.drawPixel(@intCast(x), @intCast(y), if (cell.alive) .white else .black);
}
}
}
}