pub export fn startup(p_allocator: *anyopaque, p_a: ?*anyopaque) bool { const allocator = core.modulePreamble(p_allocator, p_a) catch return false; _ = allocator; imgui.setupFromModule(); platform.setupFromModule(); // TODO backlog.setupFromModule start_module(core.startup_getArgs(p_a.?)) catch return false; return true; } pub export fn add(a: i32, b: i32) i32 { return a + b; } pub export fn subtract(a: i32, b: i32) i32 { return a + b; } var gAllocator: std.mem.Allocator = undefined; pub fn log(comptime fmt: []const u8, args: anytype) void { core.engine_log("[ExternGame]: " ++ fmt, args); } fn start_module(args: core.ModuleLoaderArgs) !void { if (args.firstLoad) { _ = core.createObject(ExternGameObject, .{}) catch {}; return; } log("extern game reloaded ", .{}); log("hello mother fucker", .{}); log("accessing old object at {x} same object? {d}", .{ @intFromPtr(core.EngineObject(ExternGameObject).get()), @sizeOf(ExternGameObject) }); log("gonna try something dumb- lets patch the vtable of that old object with my vtable's values", .{}); const ref = core.getEngineObjectRef(ExternGameObject).?; ref.vtable.tick_func = ExternGameObject.NeonObjectTable.tick_func; } pub const ExternGameObject = struct { pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "game.ExternGameObject"); allocator: std.mem.Allocator, pub fn create(allocator: std.mem.Allocator) !*@This() { const self = try allocator.create(@This()); self.* = .{ .allocator = allocator }; return self; } pub fn tick(self: *@This(), dt: f64) void { _ = dt; _ = self; const rctx = rend.context(); imgui.utils.structDebugWindow(rctx); if (ig.begin("external game object", null, .{})) { ig.textf("sup", .{}); _ = ig.sliderFloat("skybox strength", &rctx.skyboxSystem.brightnessFactor, 0, 10, null, .{}); if (rctx.activeCamera) |camera| { const forwardVector = camera.forward(); ig.textf("forward vector x:{d} y:{d} z:{d}", .{ forwardVector.x, forwardVector.y, forwardVector.z }); } ig.textf("window at 0x{x}", .{@intFromPtr(backlog.platform.context().window)}); if (ig.smallButton("click to show sdl messagebox")) { //_ = backlog.platform.windowing.sdl3.c.SDL_ShowSimpleMessageBox(0, "lmao", "you lmaoed your last uwu", backlog.platform.context().window); } } 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()}); var iterator = rctx.meshPool.installedMeshes.iterator(); while (iterator.next()) |i| { ig.textf("{s}", .{i.value_ptr.*.name.utf8()}); } } ig.end(); } pub fn destroy(self: *@This()) void { self.allocator.destroy(self); } }; pub export fn shutdown() void {} const std = @import("std"); const backlog = @import("backlog"); const core = backlog.core; const imgui = backlog.imgui; const rend = backlog.rend; const ig = imgui.api; const platform = backlog.platform;