161 lines
5.4 KiB
Zig
161 lines
5.4 KiB
Zig
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();
|
|
rend.setupFromModule();
|
|
backlog.physics.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;
|
|
|
|
fn start_module(args: core.ModuleLoaderArgs) !void {
|
|
if (args.firstLoad) {
|
|
_ = core.createObject(ExternGameObject, .{}) catch {};
|
|
return;
|
|
}
|
|
|
|
core.logDisplay("externGame", "extern game reloaded ", .{});
|
|
core.logDisplay("externGame", "hello mother fucker", .{});
|
|
core.logDisplay("externGame", "accessing old object at {x} same object? {d}", .{ @intFromPtr(core.EngineObject(ExternGameObject).get()), @sizeOf(ExternGameObject) });
|
|
|
|
// getting rid of dumb comment
|
|
//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;
|
|
|
|
core.PatchStruct(ExternGameObject, @ptrCast(@alignCast(ref.ptr)), ref.vtable.fieldList.?);
|
|
}
|
|
|
|
pub const ExternGameObject = struct {
|
|
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "game.ExternGameObject");
|
|
pub const Slack = core.SlackStruct(@This(), 512);
|
|
|
|
allocator: std.mem.Allocator = undefined,
|
|
consoleWindow: imgui.utils.ConsoleWindow = undefined,
|
|
tbMap: ?*bsp.maploader.TBMap = null,
|
|
|
|
//lmao: bool = false,
|
|
//lmao2: bool = true,
|
|
a: bool = false,
|
|
// lib: bool = false,
|
|
//s: u32 = 0x42,
|
|
|
|
pub fn loadMap2(self: *@This()) !void {
|
|
if (self.tbMap) |tbMap| {
|
|
core.engine_log("killing the map", .{});
|
|
tbMap.destroy();
|
|
}
|
|
|
|
self.tbMap = try bsp.maploader.LoadTrenchbroomMap(self.allocator, .{
|
|
.rotation = core.Rotation.eulerX(core.radians(-90.0)),
|
|
.mapName = "bsp/testmap.map",
|
|
});
|
|
|
|
core.engine_log("map loaded", .{});
|
|
}
|
|
|
|
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
|
const self = try Slack.create(allocator);
|
|
self.* = .{
|
|
.allocator = allocator,
|
|
.consoleWindow = imgui.utils.ConsoleWindow.init(allocator),
|
|
};
|
|
|
|
imgui.utils.addMenuFunc(self, "Input Stack Viewer", extras.inputDebugger.windowOpen);
|
|
self.consoleWindow.setup();
|
|
|
|
return self;
|
|
}
|
|
|
|
pub fn tick(self: *@This(), dt: f64) void {
|
|
const rctx = rend.context();
|
|
_ = 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;
|
|
}
|
|
}
|
|
}
|
|
ig.end();
|
|
|
|
//_ = self;
|
|
_ = rctx;
|
|
// imgui.utils.structHexView(self);
|
|
// imgui.utils.structHexView(rctx.activeCamera.?);
|
|
// 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.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(Slack.fromPtr(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;
|
|
const extras = @import("gameExtras");
|
|
const bsp = @import("bsp");
|