commit dd7a2d5f7d3bb8100a284e9b3e291e2d5fc6ed97 Author: derek.holloway Date: Sun May 18 11:42:05 2025 -0700 init commit diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..b6693eb --- /dev/null +++ b/build.zig @@ -0,0 +1,33 @@ +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_Game", .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize }); + + const raylib_dep = b.dependency("raylib_zig", .{ + .target = target, + .optimize = optimize, + }); + + const raylib = raylib_dep.module("raylib"); // main raylib module + const raygui = raylib_dep.module("raygui"); // raygui module + const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library + + exe.linkLibrary(raylib_artifact); + exe.root_module.addImport("raylib", raylib); + exe.root_module.addImport("raygui", raygui); + + 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); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..d353483 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,52 @@ +.{ + // This is the default name used by packages depending on this one. For + // example, when a user runs `zig fetch --save `, this field is used + // as the key in the `dependencies` table. Although the user can choose a + // different name, most users will stick with this provided value. + // + // It is redundant to include "zig" in this name because it is already + // within the Zig package namespace. + .name = .Zig_Game, + + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + + // Together with name, this represents a globally unique package + // identifier. This field is generated by the Zig toolchain when the + // package is first created, and then *never changes*. This allows + // unambiguous detection of one package being an updated version of + // another. + // + // When forking a Zig project, this id should be regenerated (delete the + // field and run `zig build`) if the upstream project is still maintained. + // Otherwise, the fork is *hostile*, attempting to take control over the + // original project's identity. Thus it is recommended to leave the comment + // on the following line intact, so that it shows up in code reviews that + // modify the field. + .fingerprint = 0xb2051f0788a78dfb, // Changing this has security and trust implications. + + // Tracks the earliest Zig version that the package considers to be a + // supported use case. + .minimum_zig_version = "0.14.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .raylib_zig = .{ + .url = "git+https://github.com/Not-Nik/raylib-zig#d4fc514d54a3b37b9b3e4f4983f611c3469e8c2a", + .hash = "raylib_zig-5.6.0-dev-KE8REHguBQAE0xoNkra7mtEqr8cCZHk7k_03txLZB-cZ", + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + // For example... + //"LICENSE", + //"README.md", + }, +} diff --git a/src/Entity.zig b/src/Entity.zig new file mode 100644 index 0000000..838f4d9 --- /dev/null +++ b/src/Entity.zig @@ -0,0 +1,47 @@ +const std = @import("std"); +const rl = @import("raylib"); + +const Vector3_t = rl.Vector3; + +pub const Collider_t = struct { + boundingRadius: f32 = 1, + boundingCenter: Vector3_t = Vector3_t{.x=0,.y=0,.z=0}, +}; + +pub const StoredString_t = struct { + data_ptr: *const u8 = undefined, + length: usize = 0 +}; + +pub const EntityFlags_t = packed struct(u8) { + flag1: bool = false, + flag2: bool = false, + flag3: bool = false, + flag4: bool = false, + flag5: bool = false, + flag6: bool = false, + flag7: bool = false, + flag8: bool = false, +}; + +pub const Mesh_t = struct { + meshData: rl.Mesh = undefined, + meshMaterial: rl.Material = undefined, + lod_Distance: f32 = 1, +}; + +pub const Node_t = struct { + Id: u32 = 1, + Parent: ?*Node_t = undefined, + Name: []const u8 = undefined, + Children: ?std.ArrayList(Node_t) = undefined, +}; + +pub const Entity_t = struct { + Transform: rl.Transform = undefined, + Flags: EntityFlags_t = EntityFlags_t{}, + Collider: Collider_t = Collider_t{}, + Mesh: Mesh_t = Mesh_t{}, + Node: Node_t = Node_t{}, + RuntimeFlags: EntityFlags_t = EntityFlags_t{}, +}; \ No newline at end of file diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..91263ba --- /dev/null +++ b/src/main.zig @@ -0,0 +1,90 @@ +const std = @import("std"); +const rl = @import("raylib"); + +const Entity_t = @import("Entity.zig").Entity_t; +const EntitiesList_t = std.MultiArrayList(Entity_t); +var G_alloc: *std.mem.Allocator = undefined; +var G_camera: *rl.Camera3D = undefined; + +fn Render3D() void { + rl.clearBackground(.white); + + rl.drawCube( + .{ .x=4, .y=-4, .z=4 }, + 2, + 2, + 2, + .{ .r=255, .b=0, .g=0, .a=255 } + ); + rl.drawCubeWires( + .{ .x=4, .y=-4, .z=4 }, + 2, + 2, + 2, + .{ .r=0, .b=0, .g=0, .a=255 } + ); + + rl.drawSphere( + .{.x=4, .y=0, .z=4}, + 2, + .{.r=0, .g=255, .b=0, .a=255}, + ); + + rl.updateCamera(G_camera, rl.CameraMode.first_person); +} + +fn RenderUI() void { + rl.drawFPS(10, 10); +} + +fn PhysicsUpdate() void { + +} + +pub fn main() !void { + // Allocator + var gpa = std.heap.GeneralPurposeAllocator(.{ .thread_safe = true } ){}; + var alloc = gpa.allocator(); + defer alloc.destroy(G_alloc); + G_alloc = &alloc; + + // Create the Main Camera + var MainCamera = rl.Camera3D{ + .up = rl.Vector3{ .x=0, .y=1, .z=0 }, + .position = rl.Vector3{ .x=0, .y=0, .z=0}, + .projection = rl.CameraProjection.perspective, + .fovy = 60, + .target = rl.Vector3{ .x=1, .y=0, .z=0 } + }; + G_camera = &MainCamera; + + // Player List + var Entities = EntitiesList_t{}; + defer Entities.deinit(G_alloc.*); + + // Create the Root Node + var RootNode = Entity_t{}; + RootNode.Node.Name = "Root Node"; + try Entities.append(G_alloc.*, RootNode); + + // Setup + //rl.disableCursor(); + rl.setTargetFPS(60); + + // Create window + rl.initWindow( 512, 512, "Hello world"); + defer rl.closeWindow(); + while(!rl.windowShouldClose()){ + + // Start Render Loop + rl.beginDrawing(); + rl.beginMode3D(MainCamera); + Render3D(); + rl.endMode3D(); + RenderUI(); + rl.endDrawing(); + PhysicsUpdate(); + //std.debug.print("{s}", .{ Player1.Node.Name }); + + } +} \ No newline at end of file diff --git a/zig-out/bin/Zig_Game b/zig-out/bin/Zig_Game new file mode 100755 index 0000000..aec5376 Binary files /dev/null and b/zig-out/bin/Zig_Game differ diff --git a/zig-out/tmp-debug-build/bin/Zig_Game b/zig-out/tmp-debug-build/bin/Zig_Game new file mode 100755 index 0000000..aa42d0b Binary files /dev/null and b/zig-out/tmp-debug-build/bin/Zig_Game differ