NYXA/README.md
2026-07-26 13:18:39 +00:00

2.4 KiB

Includes

  • Plugins
  • Scheduler
  • Resources
  • Events
  • ECS (Archetype)

Plugin

pub const plugin: App.plugin.Plugin = .{
    .name = "Renderer",
    .description = "Vulkan Renderer",
    .build = build,
};

System

pub fn render(ctx: App.scheduler.Context) !void {
    // --- GET RESOURCES ---
    const res = try ctx.app.resources.getMany(struct {
        window: *Window,
        device: *Device,
        render_frame: ?*RenderFrame,
    });

    if (res.render_frame) |rf| {
        _ = rf;
    }
}

Simple Events

// --- SEND MANY EVENTS ---
try app.events.sendMany(&.{
    event.AppExit{
        .reason = "Yes",
    },
});

// --- MAIN GAME LOOP ---
while (true) {
    // --- USE AND EAT EVENT ---
    if (app.events.consume(event.AppExit)) |app_exit| {
        std.debug.print("Exit Reason: {s}\n", .{
            app_exit.reason,
        });
        break;
    }
}

Event Queue

const Register = struct {
    username: []const u8,
};

// --- QUEUE ---
if (app.events.get(event.Register)) |queue| {
    // --- GET EVERY EVENT ---
    for (queue.items()) |register| {
        // --- DEBUG ---
        std.debug.print("New Register: Username(s)\n", .{
            register.username
        });
        // ...
    }
    // --- CLEAR EVENT QUEUE ---
    queue.clear();
}

Simple

test "Main" {
    // --- APP ---
    var app: Self = .init(std.testing.allocator);
    defer app.deinit();

    { // PLUGINS
        // --- ADD PLUGINS ---
        try app.plugins.addMany(&.{
            example.simple.plugin,
        });

        // --- BUILD PLUGINS ---
        try app.plugins.build(.{
            .app = &app,
        });
    }

    { // SYSTEMS
        try app.schedules.runMany(&.{
            example.simple.stage.Init,
            example.simple.stage.Inputs,
            example.simple.stage.Update,
            example.simple.stage.Draw,
            example.simple.stage.Deinit,
        }, .{
            .app = &app,
        });
    }
}

Default App Stages

pub const stage = struct {
    // --- LIFETIME ---
    pub const init = struct {};
    pub const deinit = struct {};

    // --- FRAME ---
    pub const begin_frame = struct {};
    pub const end_frame = struct {};

    // --- CORE ---
    pub const inputs = struct {};
    pub const fixed_update = struct {};
    pub const update = struct {};
    pub const draw = struct {};
};