diff --git a/extras/gameExtras/src/debuggers/ParticleDebugger.zig b/extras/gameExtras/src/debuggers/ParticleDebugger.zig new file mode 100644 index 0000000..ae210f0 --- /dev/null +++ b/extras/gameExtras/src/debuggers/ParticleDebugger.zig @@ -0,0 +1,108 @@ +const std = @import("std"); +const backlog = @import("Backlog"); +const core = backlog.core; +const rend = backlog.rend; +const imgui = backlog.imgui; +const ig = imgui.api; + +const ItemWidth = 80; + +pub const ParticleDebugger = struct { + editParticle: ?core.Entity = null, + savedGravity: core.Vectorf = .{}, + + pub fn init() ParticleDebugger { + return .{}; + } + + pub fn displayRandRangeImgui(comptime Name: []const u8, range: *rend.particles.ParticleRandRangef) void { + ig.textFmt(Name, .{}) catch {}; + ig.sameLine(0, 10); + ig.setNextItemWidth(ItemWidth); + _ = ig.inputFloat("Min##particleEd" ++ Name, &range.min, 1.0, 5.0, null, .{}); + ig.sameLine(0, 10); + ig.setNextItemWidth(ItemWidth); + _ = ig.inputFloat("Max##particleEd" ++ Name, &range.max, 1.0, 5.0, null, .{}); + } + + pub fn editVector(comptime Name: []const u8, range: *core.Vectorf) void { + ig.textFmt(Name, .{}) catch {}; + ig.sameLine(0, 10); + ig.setNextItemWidth(ItemWidth); + _ = ig.inputFloat("X##particleEd" ++ Name, &range.x, 1.0, 5.0, null, .{}); + ig.sameLine(0, 10); + ig.setNextItemWidth(ItemWidth); + _ = ig.inputFloat("Y##particleEd" ++ Name, &range.y, 1.0, 5.0, null, .{}); + ig.sameLine(0, 10); + ig.setNextItemWidth(ItemWidth); + _ = ig.inputFloat("Z##particleEd" ++ Name, &range.z, 1.0, 5.0, null, .{}); + } + + pub fn particleDebug(self: *@This()) void { + if (ig.begin("particleDebugger", null, .{})) { + var buffer: [256]u8 = undefined; + ig.textFmt("active particles: {d}", .{rend.context().particleRenderer.lastParticleCount}) catch unreachable; + for (rend.ParticleEmitter.BaseContainer.dense.items, 0..) |*emitter, i| { + ig.textFmt("emitter {d}", .{emitter.sparseIndex.index}) catch {}; + ig.sameLine(0, 10); + if (ig.smallButton(std.fmt.bufPrintZ(&buffer, "edit##{d}", .{i}) catch unreachable)) { + self.editParticle = emitter.value.entity; + } + } + } + ig.end(); + + var checkbox: bool = true; + + if (self.editParticle) |edit| { + if (edit.fetch(rend.ParticleEmitter)) |emitter| { + if (ig.begin("editParticle", null, .{})) { + displayRandRangeImgui("Acceleration", &emitter.particleAcceleration); + displayRandRangeImgui("Velocity", &emitter.particleVelocity); + displayRandRangeImgui("Life", &emitter.particleLife); + displayRandRangeImgui("Size", &emitter.particleSizeSpawn); + displayRandRangeImgui("spawnRate", &emitter.spawnRate); + + if (emitter.gravity != null) { + checkbox = true; + } else { + checkbox = false; + } + + if (ig.checkbox("hasGravity", &checkbox)) { + if (!checkbox) { + self.savedGravity = emitter.gravity.?; + emitter.gravity = null; + } + + if (checkbox) { + emitter.gravity = self.savedGravity; + } + } + + if (emitter.gravity != null) { + editVector("gravity", &emitter.gravity.?); + } + + _ = ig.inputInt("maxParticles##particleEd", @ptrCast(&emitter.maxParticles), 1, 5, .{}); + _ = ig.checkbox("showDebug", &emitter._showDebug); + _ = ig.checkbox("useLocalScene", &emitter.useLocalScene); + _ = ig.checkbox("billboard", &emitter.billboard); + + if (ig.smallButton("alive")) { + emitter.state = .alive; + } + ig.sameLine(0, 10); + if (ig.smallButton("kill")) { + emitter.state = .dead; + } + ig.sameLine(0, 10); + if (ig.smallButton("pause")) { + emitter.state = .paused; + } + } + ig.end(); + } + } + } +}; \ No newline at end of file diff --git a/extras/gameExtras/src/gameExtras.zig b/extras/gameExtras/src/gameExtras.zig index 614e3d8..c9984e8 100644 --- a/extras/gameExtras/src/gameExtras.zig +++ b/extras/gameExtras/src/gameExtras.zig @@ -6,5 +6,6 @@ pub const ObjectSpawner = @import("debuggers/objectSpawner.zig"); pub const RendererDebug = @import("debuggers/RendererDebug.zig"); pub const EngineTool = @import("debuggers/EngineTool.zig"); pub const PhysicsObjectList = @import("debuggers/PhysicsObjectList.zig"); +pub const ParticleDebugger = @import("debuggers/ParticleDebugger.zig"); pub const browser = @import("debuggers/fileBrowser.zig"); diff --git a/projects/sampleGame/externGame/externGame.zig b/projects/sampleGame/externGame/externGame.zig index 5f113e5..853f0b0 100644 --- a/projects/sampleGame/externGame/externGame.zig +++ b/projects/sampleGame/externGame/externGame.zig @@ -48,14 +48,13 @@ pub const ExternGameObject = struct { tbMap: ?*bsp.maploader.TBMap = null, physicsObjectsWindow: *extras.PhysicsObjectList = undefined, fireTraceFilter: physics.IgnoreFixedBodiesFilter = .{}, + particleDebugger: extras.ParticleDebugger.ParticleDebugger = undefined, //lmao: bool = false, //lmao2: bool = true, a: bool = false, // lib: bool = false, //s: u32 = 0x42, - editParticle: ?core.Entity = null, - savedGravity: core.Vectorf = .{}, pub fn loadMap2(self: *@This()) !void { if (self.tbMap) |tbMap| { @@ -71,104 +70,13 @@ pub const ExternGameObject = struct { core.engine_log("map loaded", .{}); } - const ItemWidth = 80; - - pub fn displayRandRangeImgui(comptime Name: []const u8, range: *rend.particles.ParticleRandRangef) void { - ig.textFmt(Name, .{}) catch {}; - ig.sameLine(0, 10); - ig.setNextItemWidth(ItemWidth); - _ = ig.inputFloat("Min##particleEd" ++ Name, &range.min, 1.0, 5.0, null, .{}); - ig.sameLine(0, 10); - ig.setNextItemWidth(ItemWidth); - _ = ig.inputFloat("Max##particleEd" ++ Name, &range.max, 1.0, 5.0, null, .{}); - } - - pub fn editVector(comptime Name: []const u8, range: *core.Vectorf) void { - ig.textFmt(Name, .{}) catch {}; - ig.sameLine(0, 10); - ig.setNextItemWidth(ItemWidth); - _ = ig.inputFloat("X##particleEd" ++ Name, &range.x, 1.0, 5.0, null, .{}); - ig.sameLine(0, 10); - ig.setNextItemWidth(ItemWidth); - _ = ig.inputFloat("Y##particleEd" ++ Name, &range.y, 1.0, 5.0, null, .{}); - ig.sameLine(0, 10); - ig.setNextItemWidth(ItemWidth); - _ = ig.inputFloat("Z##particleEd" ++ Name, &range.z, 1.0, 5.0, null, .{}); - } - - pub fn particleDebug(self: *@This()) void { - if (ig.begin("particleDebugger", null, .{})) { - var buffer: [256]u8 = undefined; - ig.textFmt("active particles: {d}", .{rend.context().particleRenderer.lastParticleCount}) catch unreachable; - for (rend.ParticleEmitter.BaseContainer.dense.items, 0..) |*emitter, i| { - ig.textFmt("emitter {d}", .{emitter.sparseIndex.index}) catch {}; - ig.sameLine(0, 10); - if (ig.smallButton(std.fmt.bufPrintZ(&buffer, "edit##{d}", .{i}) catch unreachable)) { - self.editParticle = emitter.value.entity; - } - } - } - ig.end(); - - var checkbox: bool = true; - - if (self.editParticle) |edit| { - if (edit.fetch(rend.ParticleEmitter)) |emitter| { - if (ig.begin("editParticle", null, .{})) { - displayRandRangeImgui("Acceleration", &emitter.particleAcceleration); - displayRandRangeImgui("Velocity", &emitter.particleVelocity); - displayRandRangeImgui("Life", &emitter.particleLife); - displayRandRangeImgui("Size", &emitter.particleSizeSpawn); - displayRandRangeImgui("spawnRate", &emitter.spawnRate); - - if (emitter.gravity != null) { - checkbox = true; - } else { - checkbox = false; - } - - if (ig.checkbox("hasGravity", &checkbox)) { - if (!checkbox) { - self.savedGravity = emitter.gravity.?; - emitter.gravity = null; - } - - if (checkbox) { - emitter.gravity = self.savedGravity; - } - } - - if (emitter.gravity != null) { - editVector("gravity", &emitter.gravity.?); - } - - _ = ig.inputInt("maxParticles##particleEd", @ptrCast(&emitter.maxParticles), 1, 5, .{}); - _ = ig.checkbox("showDebug", &emitter._showDebug); - _ = ig.checkbox("useLocalScene", &emitter.useLocalScene); - _ = ig.checkbox("billboard", &emitter.billboard); - - if (ig.smallButton("alive")) { - emitter.state = .alive; - } - ig.sameLine(0, 10); - if (ig.smallButton("kill")) { - emitter.state = .dead; - } - ig.sameLine(0, 10); - if (ig.smallButton("pause")) { - emitter.state = .paused; - } - } - ig.end(); - } - } - } pub fn create(allocator: std.mem.Allocator) !*@This() { const self = try Slack.create(allocator); self.* = .{ .allocator = allocator, .consoleWindow = imgui.utils.ConsoleWindow.init(allocator), + .particleDebugger = extras.ParticleDebugger.ParticleDebugger.init(), }; imgui.utils.addMenuFunc(self, "Input Stack Viewer", extras.inputDebugger.windowOpen); @@ -323,7 +231,7 @@ pub const ExternGameObject = struct { } } } - self.particleDebug(); + self.particleDebugger.particleDebug(); } }