From 69203653fde1b0e4983ded727bfd12b4d412c3ab Mon Sep 17 00:00:00 2001 From: peterino2 Date: Fri, 30 May 2025 19:45:38 -0700 Subject: [PATCH] adding offsets --- build.zig | 2 +- engine/imgui/src/utils/TopBar.zig | 2 +- engine/papyrus/src/papyrus.zig | 2 + engine/ui/src/sgpu/papyrusSgpu.zig | 2 +- engine/ui/src/ui.zig | 18 ++--- projects/sampleGame/externGame/externGame.zig | 69 +++++++++---------- projects/sampleGame/main.zig | 4 +- 7 files changed, 45 insertions(+), 54 deletions(-) diff --git a/build.zig b/build.zig index 5c6ee94..7f7918f 100644 --- a/build.zig +++ b/build.zig @@ -141,7 +141,7 @@ pub fn addProgram(self: *BuildSystem, opts: AddProgramOptions) *std.Build.Module b.getInstallStep().dependOn(self.nw_builder.getInstallStep()); - run_exe.dependOn(b.getInstallStep()); + // run_exe.dependOn(b.getInstallStep()); return mod; } diff --git a/engine/imgui/src/utils/TopBar.zig b/engine/imgui/src/utils/TopBar.zig index 9127851..b8b5f9e 100644 --- a/engine/imgui/src/utils/TopBar.zig +++ b/engine/imgui/src/utils/TopBar.zig @@ -1,4 +1,4 @@ -pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "game.ExternGameObject"); +pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "game.TopBar"); pub const Slack = core.SlackStruct(@This(), 256); allocator: std.mem.Allocator, diff --git a/engine/papyrus/src/papyrus.zig b/engine/papyrus/src/papyrus.zig index 068d922..3b0a03d 100644 --- a/engine/papyrus/src/papyrus.zig +++ b/engine/papyrus/src/papyrus.zig @@ -488,6 +488,8 @@ pub const Context = struct { self.debugTextCount = 0; } + pub const destroy = deinit; + pub fn deinit(self: *@This()) void { for (0..self.nodes.count()) |i| { const maybeNode = self.nodes.indexToHandle(i); diff --git a/engine/ui/src/sgpu/papyrusSgpu.zig b/engine/ui/src/sgpu/papyrusSgpu.zig index e9f18f2..e0a04ff 100644 --- a/engine/ui/src/sgpu/papyrusSgpu.zig +++ b/engine/ui/src/sgpu/papyrusSgpu.zig @@ -19,7 +19,7 @@ first: bool = true, rectPipeline: *gpu.GPUGraphicsPipeline = undefined, // textPipeline: *gpu.GPUGraphicsPipeline = undefined, -pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This()); +pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "ui.runtime"); pub fn create(allocator: std.mem.Allocator) !*@This() { const self: *@This() = try allocator.create(@This()); diff --git a/engine/ui/src/ui.zig b/engine/ui/src/ui.zig index 6c7ebc7..a91fcf5 100644 --- a/engine/ui/src/ui.zig +++ b/engine/ui/src/ui.zig @@ -1,6 +1,5 @@ const std = @import("std"); pub const core = @import("core"); -pub const api = @import("cimgui"); const rend = @import("rend"); pub const papyrus = @import("papyrus"); @@ -12,24 +11,17 @@ pub const Module: core.ModuleDescription = .{ pub const PapyrusIntegration = @import("sgpu/papyrusSgpu.zig"); -var gIntegration: *PapyrusIntegration = undefined; - pub fn start_module(spec: *core.SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void { _ = args; _ = spec; + _ = allocator; - gIntegration = try PapyrusIntegration.create(allocator); - try gIntegration.setup(); + const ctx = try core.createObject(PapyrusIntegration, .{}); + try ctx.setup(); } -// gets the main context under gIntegration -pub fn context() *papyrus.Context { - return gIntegration.screenContext; -} - -pub fn runtime() *PapyrusIntegration { - return gIntegration; -} +// gets the main context +pub const context = core.EngineObject(PapyrusIntegration).get; pub fn shutdown_module(allocator: std.mem.Allocator) void { _ = allocator; diff --git a/projects/sampleGame/externGame/externGame.zig b/projects/sampleGame/externGame/externGame.zig index d36d56c..72ec9f3 100644 --- a/projects/sampleGame/externGame/externGame.zig +++ b/projects/sampleGame/externGame/externGame.zig @@ -112,47 +112,46 @@ pub const ExternGameObject = struct { pub fn tick(self: *@This(), dt: f64) void { const rctx = rend.context(); + _ = rctx; _ = dt; - if (ig.begin("meh", null, .{})) { - // if (ig.checkbox("move lights ", null)) {} - - ig.textFmt("info: - WASD to move, mouse to look,\n- Q and E to go up and down", .{}) catch return; - ig.textFmt("- shift to slow down camera speed", .{}) catch return; - ig.textFmt("- T to enable/disable mouse cursor", .{}) catch return; - ig.textFmt("- f2 to route all inputs to the doom player", .{}) catch return; - ig.textFmt("- movingLight checkbox makes the light stop moving with you", .{}) catch return; - - if (ig.smallButton("reload map")) { - self.loadMap2() catch unreachable; - } - - if (ig.smallButton("destroy map")) { - if (self.tbMap) |tbMap| { - core.engine_log("killing the map", .{}); - tbMap.destroy(); - self.tbMap = null; - } - } + if (core.getEngineObject(imgui.utils.TopBar)) |topbar| { + topbar.menuOpen = platform.context().isCursorEnabled(); } - ig.end(); if (platform.context().isCursorEnabled()) { - if (ig.begin("cursor", null, .{})) { + if (ig.begin("meh", null, .{})) { + // if (ig.checkbox("move lights ", null)) {} + + ig.textFmt("info: - WASD to move, mouse to look,\n- Q and E to go up and down", .{}) catch return; + ig.textFmt("- shift to slow down camera speed", .{}) catch return; + ig.textFmt("- T to enable/disable mouse cursor", .{}) catch return; + ig.textFmt("- f2 to route all inputs to the doom player", .{}) catch return; + ig.textFmt("- movingLight checkbox makes the light stop moving with you", .{}) catch return; + + if (ig.smallButton("reload map")) { + self.loadMap2() catch unreachable; + } + + if (ig.smallButton("destroy map")) { + if (self.tbMap) |tbMap| { + core.engine_log("killing the map", .{}); + tbMap.destroy(); + self.tbMap = null; + } + } + } + ig.end(); + + if (platform.context().isCursorEnabled()) { if (rend.context().activeCamera) |cam| { const ray = cam.getNormalRayFromScreen(platform.getCursorPosition()); if (physics.traceLine(ray.start, ray.dir.fmul(10000), .{ .bodyFilter = &self.fireTraceFilter, .getNormalsSlow = false })) |r| { core.debugSphere(r.point, 0.2, .{ .color = .{ .x = 1.0 }, .duration = 0 }); - // core.debugLine(ray.start, ray.start.add(ray.dir.fmul(1000)), .{ .duration = 2.5 }); - // physics.applyForce(r.body, ray.dir.fmul(400), r.point); - ig.textf("{d} {d} {d}", .{ r.point.x, r.point.y, r.point.z }); } - - ig.textf("imgui mouse consumed {any}", .{platform.getInstance().imguiMouseConsumed}); } } - ig.end(); } //_ = self; @@ -170,13 +169,13 @@ pub const ExternGameObject = struct { // } // ig.end(); - if (ig.begin("list of textures", null, .{})) { - var iterator = rctx.textureList.map.iterator(); - while (iterator.next()) |i| { - ig.textf("{s}", .{i.value_ptr.*.name.utf8()}); - } - } - ig.end(); + // if (ig.begin("list of textures", null, .{})) { + // var iterator = rctx.textureList.map.iterator(); + // while (iterator.next()) |i| { + // ig.textf("{s}", .{i.value_ptr.*.name.utf8()}); + // } + // } + // ig.end(); // if (ig.begin("list of meshes", null, .{})) { // ig.textf("number of meshes: {d}", .{rctx.meshPool.installedMeshes.count()}); diff --git a/projects/sampleGame/main.zig b/projects/sampleGame/main.zig index a4d13c8..122470e 100644 --- a/projects/sampleGame/main.zig +++ b/projects/sampleGame/main.zig @@ -175,8 +175,6 @@ pub fn prepare(self: *@This()) !void { try self.objectSpawner.addSpawnFunction("empire", @import("empire.zig")); try self.objectSpawner.addSpawnFunction("DamagedHelmet", DamagedHelmet); - ui.context().drawDebug = true; - try assets.loadList(assetReferences); // self.videoplayer = try VideoPlayer.create(self.allocator); // try self.videoplayer.startPlayback("LAPWING2.ogv"); @@ -429,9 +427,9 @@ pub fn tick(self: *@This(), dt: f64) void { // self.loadMap2() catch unreachable; // show a window with the current camera's position + self.objectSpawner.windowOpen = !self.mouseLook; if (!self.mouseLook) { // self.engineTool.tick(); - self.objectSpawner.windowOpen = !self.mouseLook; //if (ig.begin("meh", null, .{})) { //if (ig.checkbox("move lights ", &self.moveLight)) {} //}