misc cleanup
This commit is contained in:
22
src/App.zig
22
src/App.zig
@@ -1,22 +0,0 @@
|
||||
const std = @import("std");
|
||||
const nu = @import("nu.zig");
|
||||
|
||||
const Bus = @import("nu/Bus.zig");
|
||||
const Render = @import("nu/Render.zig");
|
||||
const ImGui = @import("nu/ImGui.zig");
|
||||
|
||||
pub const depends = .{ ImGui, Render };
|
||||
|
||||
pub fn setup(_: std.mem.Allocator) !void {}
|
||||
|
||||
pub fn teardown() void {}
|
||||
|
||||
pub fn update() !void {}
|
||||
|
||||
pub fn frame() !void {
|
||||
ImGui.igShowMetricsWindow(null);
|
||||
}
|
||||
|
||||
// pub fn gui() void {
|
||||
// ImGui.igShowMetricsWindow(null);
|
||||
// }
|
108
src/main.zig
108
src/main.zig
@@ -1,7 +1,11 @@
|
||||
const std = @import("std");
|
||||
const nu = @import("nu.zig");
|
||||
|
||||
const App = @import("App.zig");
|
||||
pub const nu_modules = .{
|
||||
App,
|
||||
// UI,
|
||||
};
|
||||
pub const main = nu.main;
|
||||
|
||||
pub const nu_options: nu.Options = .{
|
||||
.window = .{ .title = "Hello World" },
|
||||
@@ -11,44 +15,72 @@ pub const nu_options: nu.Options = .{
|
||||
},
|
||||
};
|
||||
|
||||
// todo declare or infer module dependencies, topological sort for init order. clean up "init" lines in main.
|
||||
//
|
||||
// problem: where should gpa go? probably some "Engine" structure in nu.zig
|
||||
//
|
||||
// don't necessarily need to declare topological sort - depth-first traversal
|
||||
// of each module's dependencies without repeats would do.
|
||||
//
|
||||
// idea - use a structure like std.Build.Step where the polymorphic part is a
|
||||
// component of the larger structure.
|
||||
pub const UI = struct {
|
||||
const im = nu.ImGui;
|
||||
|
||||
pub const nu_driver = nu.Window;
|
||||
pub const nu_present = nu.Render;
|
||||
pub const nu_modules = .{
|
||||
nu.ImGui,
|
||||
App,
|
||||
pub const depends = .{im};
|
||||
|
||||
var color: @Vector(4, f32) = @splat(1);
|
||||
|
||||
pub fn setup(_: std.mem.Allocator) !void {
|
||||
const io: *nu.ImGui.ImGuiIO = @ptrCast(nu.ImGui.igGetIO());
|
||||
io.ConfigFlags |= nu.ImGui.ImGuiConfigFlags_DockingEnable;
|
||||
}
|
||||
|
||||
pub fn frame() !void {
|
||||
nu.ImGui.igShowMetricsWindow(null);
|
||||
|
||||
{
|
||||
const viewport = im.igGetMainViewport();
|
||||
im.igSetNextWindowPos(viewport.*.WorkPos, 0, .{ .x = 0, .y = 0 });
|
||||
im.igSetNextWindowSize(viewport.*.WorkSize, 0);
|
||||
im.igSetNextWindowViewport(viewport.*.ID);
|
||||
im.igPushStyleVar_Float(im.ImGuiStyleVar_WindowRounding, 0);
|
||||
im.igPushStyleVar_Float(im.ImGuiStyleVar_WindowBorderSize, 0);
|
||||
im.igPushStyleVar_Vec2(im.ImGuiStyleVar_WindowPadding, .{ .x = 0, .y = 0 });
|
||||
defer im.igPopStyleVar(3);
|
||||
|
||||
const window_flags =
|
||||
im.ImGuiWindowFlags_MenuBar |
|
||||
im.ImGuiWindowFlags_NoDocking |
|
||||
im.ImGuiWindowFlags_NoTitleBar |
|
||||
im.ImGuiWindowFlags_NoCollapse |
|
||||
im.ImGuiWindowFlags_NoResize |
|
||||
im.ImGuiWindowFlags_NoMove |
|
||||
im.ImGuiWindowFlags_NoBringToFrontOnFocus |
|
||||
im.ImGuiWindowFlags_NoNavFocus |
|
||||
im.ImGuiWindowFlags_NoBackground;
|
||||
|
||||
const dock_flags =
|
||||
im.ImGuiDockNodeFlags_PassthruCentralNode |
|
||||
im.ImGuiDockNodeFlags_NoDockingOverCentralNode;
|
||||
|
||||
_ = im.igBegin("Main Dockspace", null, window_flags);
|
||||
const id = im.igGetID_Str("maindockspace");
|
||||
_ = im.igDockSpace(id, .{ .x = 0, .y = 0 }, dock_flags, null);
|
||||
im.igEnd();
|
||||
}
|
||||
|
||||
if (nu.ImGui.igBegin("Color", null, nu.ImGui.ImGuiWindowFlags_None)) {
|
||||
if (nu.ImGui.igColorEdit4("color", @ptrCast(&color), nu.ImGui.ImGuiColorEditFlags_AlphaPreviewHalf)) {}
|
||||
}
|
||||
nu.ImGui.igEnd();
|
||||
}
|
||||
};
|
||||
|
||||
pub const main = nu.main;
|
||||
const App = struct {
|
||||
const vk = @import("vk");
|
||||
const au = @import("nu/Render/au.zig");
|
||||
|
||||
// pub fn main() !void {
|
||||
// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
// defer _ = gpa.detectLeaks();
|
||||
// const alloc = gpa.allocator();
|
||||
//
|
||||
// nu.init(alloc);
|
||||
// defer nu.deinit();
|
||||
//
|
||||
// try nu.Window.init(alloc);
|
||||
// defer nu.Window.deinit();
|
||||
//
|
||||
// try nu.Render.init(alloc);
|
||||
// defer nu.Render.deinit();
|
||||
//
|
||||
// try nu.ImGui.init(alloc);
|
||||
// defer nu.ImGui.deinit();
|
||||
//
|
||||
// try App.init(alloc);
|
||||
// defer App.deinit();
|
||||
//
|
||||
// try nu.run(alloc);
|
||||
// }
|
||||
pub const depends = .{nu.Render};
|
||||
|
||||
// todo timeline semaphore
|
||||
|
||||
pub fn setup(_: std.mem.Allocator) !void {}
|
||||
|
||||
pub fn teardown() void {}
|
||||
|
||||
pub fn frame() !void {}
|
||||
|
||||
pub fn present(_: au.CommandBufferProxy) void {}
|
||||
};
|
||||
|
11
src/nu.zig
11
src/nu.zig
@@ -14,16 +14,23 @@ const Config = struct {
|
||||
};
|
||||
|
||||
pub const config: Config = if (@hasDecl(root, "nu_config")) root.nu_config else .{};
|
||||
pub const engine = Engine(Window, Render, root.nu_modules);
|
||||
|
||||
// Hooks: setup, teardown, fixed, frame, present
|
||||
|
||||
pub fn main() void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const alloc = gpa.allocator();
|
||||
|
||||
const engine = Engine(root.nu_driver, root.nu_present, root.nu_modules);
|
||||
std.debug.print("Engine modules: ", .{});
|
||||
inline for (engine.modules) |module| std.debug.print("{s} ", .{@typeName(module)});
|
||||
std.debug.print("\n", .{});
|
||||
|
||||
engine.try_invoke("setup", .{alloc}) catch @panic("Startup failed");
|
||||
defer engine.rinvoke("teardown", .{});
|
||||
|
||||
std.debug.print("Setup complete.\n", .{});
|
||||
|
||||
while (engine.next()) {
|
||||
engine.try_invoke("fixed", .{}) catch @panic("fixed failed!");
|
||||
engine.try_invoke("frame", .{}) catch @panic("frame failed!");
|
||||
@@ -41,7 +48,7 @@ pub fn Engine(comptime D: type, comptime R: type, comptime M: anytype) type {
|
||||
}
|
||||
|
||||
pub fn render() !void {
|
||||
return R.render(@This());
|
||||
return R.render();
|
||||
}
|
||||
|
||||
pub fn try_invoke(comptime name: []const u8, args: anytype) !void {
|
||||
|
@@ -26,8 +26,6 @@ var ctx: *im.ImGuiContext = undefined;
|
||||
var descriptor_pool: vk.DescriptorPool = undefined;
|
||||
|
||||
pub fn setup(_: std.mem.Allocator) !void {
|
||||
// try Render.present.register(present);
|
||||
|
||||
ctx = im.igCreateContext(null) orelse {
|
||||
return error.igCreateContextFailed;
|
||||
};
|
||||
@@ -87,7 +85,6 @@ pub fn setup(_: std.mem.Allocator) !void {
|
||||
|
||||
pub fn teardown() void {
|
||||
au.D.deviceWaitIdle() catch |err| std.debug.panic("Device wait failed: {!}", .{err});
|
||||
|
||||
im.impl.ImGui_ImplVulkan_Shutdown();
|
||||
au.D.destroyDescriptorPool(descriptor_pool, null);
|
||||
im.impl.ImGui_ImplGlfw_Shutdown();
|
||||
|
@@ -56,7 +56,7 @@ pub fn teardown() void {
|
||||
au.deinit();
|
||||
}
|
||||
|
||||
pub fn render(engine: anytype) !void {
|
||||
pub fn render() !void {
|
||||
const flight: au.Flights.Flight = flights.next();
|
||||
try flight.wait();
|
||||
|
||||
@@ -84,7 +84,7 @@ pub fn render(engine: anytype) !void {
|
||||
|
||||
// todo manage frame in flight state for each hook; pass the current flight in as context.
|
||||
|
||||
engine.invoke("present", .{cmd});
|
||||
nu.engine.invoke("present", .{cmd});
|
||||
|
||||
target.end_rendering(cmd);
|
||||
try cmd.endCommandBuffer();
|
||||
|
Reference in New Issue
Block a user