raylib
This commit is contained in:
parent
07e57c5612
commit
c0f3adda16
5 changed files with 107 additions and 60 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
.zig-cache/
|
.zig-cache/
|
||||||
zig-out/
|
zig-out/
|
||||||
|
zig-pkg/
|
||||||
result
|
result
|
||||||
|
|
|
||||||
37
build.zig
37
build.zig
|
|
@ -4,6 +4,16 @@ pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
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", .{
|
const mod = b.addModule("sand", .{
|
||||||
.root_source_file = b.path("src/root.zig"),
|
.root_source_file = b.path("src/root.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
@ -17,36 +27,29 @@ pub fn build(b: *std.Build) void {
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.imports = &.{
|
.imports = &.{
|
||||||
.{ .name = "sand", .module = mod },
|
.{ .name = "sand", .module = mod },
|
||||||
|
.{ .name = "raylib", .module = raylib },
|
||||||
|
.{ .name = "raygui", .module = raygui },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
exe.root_module.linkLibrary(raylib_artifact);
|
||||||
|
|
||||||
b.installArtifact(exe);
|
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(.{
|
const mod_tests = b.addTest(.{
|
||||||
.root_module = mod,
|
.root_module = mod,
|
||||||
});
|
});
|
||||||
|
|
||||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
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,
|
.root_module = exe.root_module,
|
||||||
});
|
});
|
||||||
|
|
||||||
const run_exe_tests = b.addRunArtifact(exe_tests);
|
const check = b.step("check", "Check if foo compiles");
|
||||||
|
check.dependOn(&exe_check.step);
|
||||||
const test_step = b.step("test", "Run tests");
|
|
||||||
test_step.dependOn(&run_mod_tests.step);
|
|
||||||
test_step.dependOn(&run_exe_tests.step);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,12 @@
|
||||||
.version = "1.0.0",
|
.version = "1.0.0",
|
||||||
.fingerprint = 0xa07a92116fcc91c3, // Changing this has security and trust implications.
|
.fingerprint = 0xa07a92116fcc91c3, // Changing this has security and trust implications.
|
||||||
.minimum_zig_version = "0.16.0",
|
.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 = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
"build.zig.zon",
|
"build.zig.zon",
|
||||||
|
|
|
||||||
64
flake.nix
64
flake.nix
|
|
@ -14,31 +14,45 @@
|
||||||
let
|
let
|
||||||
forAllSystems =
|
forAllSystems =
|
||||||
f:
|
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
|
in
|
||||||
{
|
forAllSystems (
|
||||||
devShells = forAllSystems (
|
system: pkgs: zig:
|
||||||
pkgs: zig: {
|
let
|
||||||
default = pkgs.mkShellNoCC {
|
nativeBuildInputs = with pkgs; [
|
||||||
packages = [
|
wayland-scanner
|
||||||
pkgs.bash
|
pkg-config
|
||||||
zig
|
];
|
||||||
zig.zls
|
buildInputs = with pkgs; [
|
||||||
];
|
libGL
|
||||||
};
|
wayland
|
||||||
}
|
libxkbcommon
|
||||||
);
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.${system}.default = pkgs.mkShellNoCC {
|
||||||
|
packages = [
|
||||||
|
pkgs.bash
|
||||||
|
zig
|
||||||
|
zig.zls
|
||||||
|
];
|
||||||
|
inherit buildInputs;
|
||||||
|
inherit nativeBuildInputs;
|
||||||
|
};
|
||||||
|
|
||||||
packages = forAllSystems (
|
packages.${system}.default = zig.makePackage {
|
||||||
pkgs: zig: {
|
pname = "sand";
|
||||||
default = zig.makePackage {
|
version = "1.0.0";
|
||||||
pname = "sand";
|
src = ./.;
|
||||||
version = "1.0.0";
|
zigReleaseMode = "fast";
|
||||||
src = ./.;
|
depsHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
|
||||||
zigReleaseMode = "fast";
|
inherit buildInputs;
|
||||||
depsHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
|
inherit nativeBuildInputs;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
58
src/main.zig
58
src/main.zig
|
|
@ -2,28 +2,52 @@ const std = @import("std");
|
||||||
|
|
||||||
const sand = @import("sand");
|
const sand = @import("sand");
|
||||||
|
|
||||||
|
const raylib = @import("raylib");
|
||||||
|
const raygui = @import("raygui");
|
||||||
|
|
||||||
pub fn main(init: std.process.Init) !void {
|
pub fn main(init: std.process.Init) !void {
|
||||||
var grid: sand.Grid = try .init(4, 4, init.gpa);
|
const screenWidth = 800;
|
||||||
var gridCopy: sand.Grid = try .init(4, 4, init.gpa);
|
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 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;
|
raylib.initWindow(screenWidth, screenHeight, "sand");
|
||||||
grid.arr[2][1].alive = true;
|
defer raylib.closeWindow();
|
||||||
grid.arr[2][2].alive = true;
|
|
||||||
grid.arr[2][3].alive = true;
|
|
||||||
|
|
||||||
grid.arr[0][1].alive = true;
|
raylib.setTargetFPS(60);
|
||||||
grid.arr[1][1].alive = true;
|
|
||||||
grid.arr[1][2].alive = true;
|
|
||||||
|
|
||||||
std.debug.print("{f}\n", .{grid});
|
while (!raylib.windowShouldClose()) {
|
||||||
try grid.copy(&gridCopy);
|
|
||||||
grid.updateAll();
|
|
||||||
|
|
||||||
while (!grid.eql(gridCopy)) {
|
|
||||||
std.debug.print("{f}\n", .{grid});
|
|
||||||
try grid.copy(&gridCopy);
|
|
||||||
grid.updateAll();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue