commit 5774e2f239baa77105630ef164fd2de0a9edfedb Author: copygirl Date: Mon Feb 19 11:13:20 2024 +0100 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..528240e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d864d9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/zig-cache/ +/zig-out/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c111ec7 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + "version": "0.2.0", + "configurations": [{ + "name": "Debug", + "type": "lldb", + "preLaunchTask": "build", + "request": "launch", + "cwd": "${workspaceFolder}", + "program": "${workspaceFolder}/zig-out/bin/zig-bloxel-game", + "args": [], + }] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7baa495 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + "version": "2.0.0", + "tasks": [{ + "label": "build", + "group": { "kind": "build", "isDefault": true }, + "type": "shell", + "command": "zig build", + "problemMatcher": [] + },{ + "label": "test", + "group": { "kind": "test", "isDefault": true }, + "type": "shell", + "command": "zig build test", + "problemMatcher": [] + }] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a669e5a --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Zig Bloxel Game + +This is a small project attempting to create a "bloxel" game (think Minecraft) using the relatively new [Zig] programming language with the help of [Mach] and [Flecs]. + +[Zig]: https://ziglang.org/ +[Mach]: https://machengine.org/ +[Flecs]: https://flecs.dev/ diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..9bfec28 --- /dev/null +++ b/build.zig @@ -0,0 +1,31 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const exe = b.addExecutable(.{ + .name = "zig-bloxel-game", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| run_cmd.addArgs(args); + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + const unit_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + + const run_unit_tests = b.addRunArtifact(unit_tests); + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_unit_tests.step); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..780f385 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,11 @@ +.{ + .name = "zig-bloxel-game", + .version = "0.0.0", + + .paths = .{ + "src", + "build.zig", + "build.zig.zon", + "README.md", + }, +} diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..9bafad8 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,17 @@ +const std = @import("std"); + +pub fn main() !void { + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + try bw.flush(); +} + +test "simple test" { + var list = std.ArrayList(i32).init(std.testing.allocator); + defer list.deinit(); + try list.append(42); + try std.testing.expectEqual(@as(i32, 42), list.pop()); +}