lots of random playing around with modules,
This commit is contained in:
parent
402704bf4f
commit
84c289ee2a
|
|
@ -144,7 +144,7 @@ pub const SoundEngine = struct {
|
|||
_ = ma.ma_engine_set_volume(self.engine, volume);
|
||||
}
|
||||
|
||||
pub fn stopSound(self: *@This(), soundName: core.Name) void {
|
||||
pub fn stopSound(self: *@This(), soundName: *core.Name) void {
|
||||
const sound = self.sounds.get(soundName.handle()).?;
|
||||
|
||||
if (ma.ma_sound_stop(sound) != ma.MA_SUCCESS) {
|
||||
|
|
|
|||
|
|
@ -458,3 +458,14 @@ pub fn MakeNameFmt(comptime fmt: []const u8, args: anytype) Name {
|
|||
var makeNameBuf: [256]u8 = undefined;
|
||||
return algorithm.MakeName(std.fmt.bufPrint(&makeNameBuf, fmt, args) catch unreachable);
|
||||
}
|
||||
|
||||
pub fn PatchOrCreateObject(comptime T: type, args: engine.NeonObjectParams) void {
|
||||
if (getEngineObject(T) != null) {
|
||||
engineObject.updateEngineVTable(T);
|
||||
return;
|
||||
}
|
||||
logging.engine_log("spawning object {s}", .{T.NeonObjectTable.typeName});
|
||||
_ = createObject(T, args) catch {
|
||||
logging.engine_err("Unable to create object", .{});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ pub const EngineDataEventError = error{
|
|||
OutOfMemory,
|
||||
};
|
||||
|
||||
const FuncInfo = struct {
|
||||
name: []const u8,
|
||||
ptr: *const anyopaque,
|
||||
};
|
||||
|
||||
pub const FieldInfo = struct {
|
||||
name: []const u8,
|
||||
size: u32,
|
||||
|
|
@ -49,6 +54,25 @@ pub const FieldInfo = struct {
|
|||
alignment: u32,
|
||||
};
|
||||
|
||||
const core = @import("core.zig");
|
||||
|
||||
pub fn updateEngineVTable(comptime T: type) void {
|
||||
const ref = core.getEngineObjectRef(T).?;
|
||||
const vtable: *EngineObjectVTable = @constCast(ref.vtable);
|
||||
const version = vtable.version;
|
||||
|
||||
if (ref.vtable.fieldList) |fieldList| {
|
||||
core.PatchStruct(T, @ptrCast(@alignCast(ref.ptr)), fieldList);
|
||||
}
|
||||
|
||||
vtable.* = T.NeonObjectTable;
|
||||
vtable.version = version + 1;
|
||||
|
||||
if (@hasDecl(T, "objectReload")) {
|
||||
core.get(T).objectReload();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn PatchStruct(comptime T: type, p: *T, old: []const FieldInfo) void {
|
||||
const t = @typeInfo(T).@"struct";
|
||||
|
||||
|
|
@ -74,16 +98,16 @@ pub fn PatchStruct(comptime T: type, p: *T, old: []const FieldInfo) void {
|
|||
dest.ptr = @ptrCast(&@field(new, field.name));
|
||||
dest.len = @sizeOf(@TypeOf(@field(new, field.name)));
|
||||
|
||||
std.debug.print(
|
||||
"patching field {s} {d} bytes {d} -> {d} {s}\n",
|
||||
.{
|
||||
field.name,
|
||||
src.len,
|
||||
of.offset,
|
||||
@offsetOf(T, field.name),
|
||||
if (of.offset == @offsetOf(T, field.name)) "" else "change!",
|
||||
},
|
||||
);
|
||||
// std.debug.print(
|
||||
// "patching field {s} {d} bytes {d} -> {d} {s}\n",
|
||||
// .{
|
||||
// field.name,
|
||||
// src.len,
|
||||
// of.offset,
|
||||
// @offsetOf(T, field.name),
|
||||
// if (of.offset == @offsetOf(T, field.name)) "" else "change!",
|
||||
// },
|
||||
// );
|
||||
|
||||
std.mem.copyForwards(u8, dest, src);
|
||||
} else {
|
||||
|
|
@ -94,6 +118,35 @@ pub fn PatchStruct(comptime T: type, p: *T, old: []const FieldInfo) void {
|
|||
p.* = new;
|
||||
}
|
||||
|
||||
pub fn EngineObjectDelegate(comptime T: type) type {
|
||||
return struct {
|
||||
func: ?T = null,
|
||||
target: *anyopaque,
|
||||
|
||||
functionName: []const u8,
|
||||
version: i32 = -1,
|
||||
vtable: *EngineObjectVTable,
|
||||
|
||||
pub fn call(self: *@This(), args: anytype) void {
|
||||
//if (!core.BuildOption("static_build")) { todo; disable this vtable check in non-static builds
|
||||
if (self.vtable.version != self.version) {
|
||||
self.version = self.vtable.version;
|
||||
if (self.vtable.findFunc(self.functionName)) |p| {
|
||||
self.func = @ptrCast(@alignCast(p));
|
||||
} else {
|
||||
core.engine_log("unable to find function {s} in {s}", .{ self.functionName, self.vtable.typeName });
|
||||
self.func = null;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
if (self.func) |func| {
|
||||
func(self.target, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub const EngineObjectVTable = struct {
|
||||
typeName: []const u8,
|
||||
typeSize: usize,
|
||||
|
|
@ -116,6 +169,51 @@ pub const EngineObjectVTable = struct {
|
|||
fieldList: ?[]const FieldInfo = null,
|
||||
slackSize: ?usize = null,
|
||||
|
||||
funcList: ?[]const FuncInfo = null,
|
||||
version: i32 = 0,
|
||||
|
||||
pub fn findFunc(self: *const @This(), name: []const u8) ?*const anyopaque {
|
||||
if (self.funcList) |flist| {
|
||||
for (flist) |fi| {
|
||||
// core.engine_log("checking func {s} vs {s}.", .{ fi.name, name });
|
||||
if (std.mem.eql(u8, fi.name, name)) {
|
||||
return fi.ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn addFunctionsList(self: *@This(), comptime TargetType: type) void {
|
||||
const ti = @typeInfo(TargetType);
|
||||
|
||||
const funcList = blk: {
|
||||
comptime var f: []const FuncInfo = &.{};
|
||||
inline for (ti.@"struct".decls) |decl| {
|
||||
if (std.mem.eql(u8, decl.name, "NeonObjectTable")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const t = @typeInfo(@TypeOf(@field(TargetType, decl.name)));
|
||||
|
||||
switch (t) {
|
||||
.@"fn" => {
|
||||
// @compileLog(decl.name);
|
||||
f = f ++ .{FuncInfo{
|
||||
.name = decl.name,
|
||||
.ptr = @ptrCast(@alignCast(&@field(TargetType, decl.name))),
|
||||
}};
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
break :blk f;
|
||||
};
|
||||
|
||||
self.funcList = funcList;
|
||||
}
|
||||
|
||||
fn fieldInfoCompare(_: void, a: FieldInfo, b: FieldInfo) bool {
|
||||
return a.offset < b.offset;
|
||||
}
|
||||
|
|
@ -152,6 +250,7 @@ pub const EngineObjectVTable = struct {
|
|||
.init_func = undefined,
|
||||
};
|
||||
self.addFieldList(TargetType);
|
||||
self.addFunctionsList(TargetType);
|
||||
|
||||
if (engineObjectName) |eon| {
|
||||
self.singletonName = eon;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ pub const LoadedModule = struct {
|
|||
startOnLoad: bool = true,
|
||||
started: bool = false,
|
||||
initialLoad: bool = true,
|
||||
autoLoad: bool = true,
|
||||
loadNextFrame: bool = false,
|
||||
|
||||
pub fn getInterface(self: @This()) ?ModuleInterface {
|
||||
return self.loaded.getLastOrNull();
|
||||
|
|
@ -75,6 +77,7 @@ pub const LoadedModule = struct {
|
|||
pub fn load(self: *@This(), allocator: std.mem.Allocator) !void {
|
||||
core.engine_log("[ModuleLoader] loading module: ", .{});
|
||||
self.lastLoad = std.time.microTimestamp();
|
||||
|
||||
try self.stageModule(allocator);
|
||||
try self.loadStagedModule(allocator);
|
||||
}
|
||||
|
|
@ -100,7 +103,8 @@ pub const LoadedModule = struct {
|
|||
shouldLoad = true;
|
||||
}
|
||||
|
||||
if (shouldLoad) {
|
||||
if (shouldLoad and (self.autoLoad or self.loadNextFrame)) {
|
||||
self.loadNextFrame = false;
|
||||
try self.load(allocator);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -165,6 +169,18 @@ pub const ModuleLoader = struct {
|
|||
try self.loadedModules.append(self.arena.allocator(), loaded);
|
||||
}
|
||||
|
||||
pub fn activateModuleVersion(self: *@This(), mod: *LoadedModule, index: usize) void {
|
||||
mod.autoLoad = false; // once we load a specific version we don't want to autoload anymore
|
||||
//
|
||||
if (index < mod.loaded.items.len) {
|
||||
var a = self.backingAllocator;
|
||||
var args = getModuleLoaderArgs(false);
|
||||
if (mod.loaded.items[index].startup(&a, &args)) {
|
||||
core.engine_log("module startup done", .{});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick(self: *@This(), dt: f64) void {
|
||||
_ = dt;
|
||||
for (self.loadedModules.items) |loaded| {
|
||||
|
|
|
|||
|
|
@ -74,11 +74,13 @@ fn arenaAlloc() std.mem.Allocator {
|
|||
return getInputStack().arena.allocator();
|
||||
}
|
||||
|
||||
fn BindingData(Listener: type, Func: type) type {
|
||||
fn BindingData(Func: type) type {
|
||||
return struct {
|
||||
pub const Delegate = core.EngineObjectDelegate(Func);
|
||||
keysDown: KeysDownQueue,
|
||||
keysUp: std.ArrayListUnmanaged(Key) = .{},
|
||||
listeners: std.ArrayListUnmanaged(Listener) = .{},
|
||||
listeners: std.ArrayListUnmanaged(Delegate) = .{},
|
||||
listenerId: std.ArrayListUnmanaged(u32) = .{},
|
||||
consumed: bool = false,
|
||||
routed: bool = false,
|
||||
count: u32 = 0,
|
||||
|
|
@ -93,9 +95,28 @@ fn BindingData(Listener: type, Func: type) type {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn addListener(self: *@This(), ctx: ?*anyopaque, func: Func) u32 {
|
||||
// pub fn addListener(self: *@This(), ctx: ?*anyopaque, func: Func) u32 {
|
||||
// const allocator = arenaAlloc();
|
||||
// self.listeners.append(allocator, .{ .id = self.count, .ctx = ctx, .func = func }) catch unreachable;
|
||||
// self.count +%= 1;
|
||||
|
||||
// return self.count;
|
||||
// }
|
||||
|
||||
//pub fn addListener(self: *@This(), ctx:?*anyopaque, func: Func)
|
||||
|
||||
pub fn addListener(self: *@This(), comptime T: type, comptime funcName: []const u8, target: *anyopaque) u32 {
|
||||
const delegate = Delegate{
|
||||
.target = target,
|
||||
.func = @field(T, funcName),
|
||||
.version = T.NeonObjectTable.version,
|
||||
.functionName = funcName,
|
||||
.vtable = &T.NeonObjectTable,
|
||||
};
|
||||
|
||||
const allocator = arenaAlloc();
|
||||
self.listeners.append(allocator, .{ .id = self.count, .ctx = ctx, .func = func }) catch unreachable;
|
||||
self.listeners.append(allocator, delegate) catch unreachable;
|
||||
self.listenerId.append(allocator, self.count) catch unreachable;
|
||||
self.count +%= 1;
|
||||
|
||||
return self.count;
|
||||
|
|
@ -104,7 +125,8 @@ fn BindingData(Listener: type, Func: type) type {
|
|||
pub fn removeListener(self: *@This(), id: u32) void {
|
||||
for (self.listeners.items.len, 0..) |listener, i| {
|
||||
if (listener.id == id) {
|
||||
self.listeners.swapRemove(i);
|
||||
_ = self.listenerId.swapRemove(i);
|
||||
_ = self.listeners.swapRemove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -130,21 +152,20 @@ fn BindingData(Listener: type, Func: type) type {
|
|||
}
|
||||
|
||||
pub const ActionBinding = struct {
|
||||
data: BindingData(Listener, ActionFunc),
|
||||
data: BindingData(ActionFunc),
|
||||
keys: std.ArrayListUnmanaged(ActionBindingKey) = .{},
|
||||
|
||||
pub const Listener = struct {
|
||||
id: u32,
|
||||
ctx: ?*anyopaque,
|
||||
func: ActionFunc,
|
||||
};
|
||||
// pub const Listener = struct {
|
||||
// id: u32,
|
||||
// delegate: core.
|
||||
// };
|
||||
|
||||
pub fn create(name: core.Name) !*@This() {
|
||||
const allocator = arenaAlloc();
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
self.* = .{
|
||||
.data = BindingData(Listener, ActionFunc).init(name),
|
||||
.data = BindingData(ActionFunc).init(name),
|
||||
};
|
||||
|
||||
return self;
|
||||
|
|
@ -180,24 +201,24 @@ pub const AxisBindingKeyMagnitude = struct {
|
|||
pub const Axis1dFunc = *const fn (?*anyopaque, f32) void;
|
||||
|
||||
pub const Axis1dBinding = struct {
|
||||
data: BindingData(Listener, Axis1dFunc),
|
||||
data: BindingData(Axis1dFunc),
|
||||
keys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
||||
magnitude: f32 = 0.0,
|
||||
|
||||
clampValue: ?f32 = 1.0,
|
||||
|
||||
pub const Listener = struct {
|
||||
id: u32,
|
||||
ctx: ?*anyopaque,
|
||||
func: Axis1dFunc,
|
||||
};
|
||||
// pub const Listener = struct {
|
||||
// id: u32,
|
||||
// ctx: ?*anyopaque,
|
||||
// func: Axis1dFunc,
|
||||
// };
|
||||
|
||||
pub fn create(name: core.Name) !*@This() {
|
||||
const allocator = arenaAlloc();
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
self.* = .{
|
||||
.data = BindingData(Listener, Axis1dFunc).init(name),
|
||||
.data = BindingData(Axis1dFunc).init(name),
|
||||
};
|
||||
|
||||
return self;
|
||||
|
|
@ -231,7 +252,7 @@ pub const Axis1dBinding = struct {
|
|||
|
||||
pub const Axis2dFunc = *const fn (?*anyopaque, core.Vector2f) void;
|
||||
pub const Axis2dBinding = struct {
|
||||
data: BindingData(Listener, Axis2dFunc),
|
||||
data: BindingData(Axis2dFunc),
|
||||
yKeys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
||||
xKeys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
||||
|
||||
|
|
@ -243,18 +264,18 @@ pub const Axis2dBinding = struct {
|
|||
|
||||
clampValue: ?f32 = 1.0,
|
||||
|
||||
pub const Listener = struct {
|
||||
id: u32,
|
||||
ctx: ?*anyopaque,
|
||||
func: Axis2dFunc,
|
||||
};
|
||||
// pub const Listener = struct {
|
||||
// id: u32,
|
||||
// ctx: ?*anyopaque,
|
||||
// func: Axis2dFunc,
|
||||
// };
|
||||
|
||||
pub fn create(name: core.Name) !*@This() {
|
||||
const allocator = arenaAlloc();
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
self.* = .{
|
||||
.data = BindingData(Listener, Axis2dFunc).init(name),
|
||||
.data = BindingData(Axis2dFunc).init(name),
|
||||
};
|
||||
|
||||
return self;
|
||||
|
|
@ -354,15 +375,15 @@ pub const Binding = union(BindingType) {
|
|||
.action => {},
|
||||
.axis1d => |p| {
|
||||
p.data.routed = false;
|
||||
for (p.data.listeners.items) |listener| {
|
||||
listener.func(listener.ctx, p.magnitude);
|
||||
for (p.data.listeners.items) |*listener| {
|
||||
listener.call(p.magnitude);
|
||||
}
|
||||
p.magnitude = 0.0;
|
||||
},
|
||||
.axis2d => |p| {
|
||||
p.data.routed = false;
|
||||
for (p.data.listeners.items) |listener| {
|
||||
listener.func(listener.ctx, p.magnitude);
|
||||
for (p.data.listeners.items) |*listener| {
|
||||
listener.call(p.magnitude);
|
||||
}
|
||||
p.magnitude = core.Vector2f.Zeroes;
|
||||
},
|
||||
|
|
@ -382,8 +403,8 @@ pub const Binding = union(BindingType) {
|
|||
}
|
||||
|
||||
if (routed) {
|
||||
for (p.data.listeners.items) |listener| {
|
||||
listener.func(listener.ctx, event);
|
||||
for (p.data.listeners.items) |*listener| {
|
||||
listener.call(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -403,9 +424,6 @@ pub const Binding = union(BindingType) {
|
|||
}
|
||||
|
||||
p.data.routed = routed;
|
||||
// for (p.data.listeners.items) |listener| {
|
||||
// listener.func(listener.ctx, magnitude);
|
||||
// }
|
||||
},
|
||||
.axis2d => |p| {
|
||||
for (p.xKeys.items) |keyBinding| {
|
||||
|
|
@ -429,11 +447,6 @@ pub const Binding = union(BindingType) {
|
|||
p.magnitude.y = std.math.clamp(p.magnitude.y, -clampValue, clampValue);
|
||||
}
|
||||
|
||||
// core.engine_log(" >> {any} > routeBindingEvent magnitude {d} {d}", .{ key, p.magnitude.x, p.magnitude.y });
|
||||
|
||||
// for (p.data.listeners.items) |listener| {
|
||||
// listener.func(listener.ctx, p.magnitude);
|
||||
// }
|
||||
p.data.routed = routed;
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,9 +269,9 @@ pub const LoggerSys = struct {
|
|||
try self.writeOutBuffer.writer().print(fmt, args);
|
||||
self.lock.unlock();
|
||||
|
||||
if (self.sessionBuffer != null) {
|
||||
// self.sessionBuffer.?.lockWriter().print(fmt, args) catch {};
|
||||
// self.sessionBuffer.?.unlock();
|
||||
if (self.sessionBuffer != null and !core.getEngine().isShuttingDown()) {
|
||||
self.sessionBuffer.?.lockWriter().print(fmt, args) catch {};
|
||||
self.sessionBuffer.?.unlock();
|
||||
}
|
||||
|
||||
if (self.writeOutBuffer.items.len > LogBufferSize) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
|||
|
||||
try self.addWindowsMenu(.{
|
||||
.name = "sample window",
|
||||
.vtable = &NeonObjectTable,
|
||||
.open = false,
|
||||
.ctx = self,
|
||||
.windowFunction = windowOpen,
|
||||
|
|
@ -24,9 +25,20 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
|||
return self;
|
||||
}
|
||||
|
||||
pub fn setEntryOpen(self: *@This(), name: []const u8, open: ?bool) void {
|
||||
var n = core.MakeName(name);
|
||||
const x = self.entriesByName.get(n.handle()).?;
|
||||
if (open) |o| {
|
||||
x.open = o;
|
||||
} else {
|
||||
x.open = !x.open;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addMenuObject(self: *@This(), ptr: anytype, comptime name: []const u8) !void {
|
||||
const T = @TypeOf(ptr.*);
|
||||
try self.addWindowsMenu(.{
|
||||
.vtable = &T.NeonObjectTable,
|
||||
.name = name,
|
||||
.ctx = ptr,
|
||||
.windowFunction = T.windowOpen,
|
||||
|
|
@ -87,6 +99,7 @@ pub fn tick(self: *@This(), dt: f64) void {
|
|||
|
||||
for (self.windowsMenu.items) |entry| {
|
||||
if (entry.open) {
|
||||
entry.updateFunc();
|
||||
entry.windowFunction(entry, dt);
|
||||
}
|
||||
}
|
||||
|
|
@ -103,6 +116,16 @@ pub const MenuEntry = struct {
|
|||
open: bool = false,
|
||||
ctx: ?*anyopaque,
|
||||
windowFunction: *const fn (*MenuEntry, f64) void,
|
||||
vtable: *core.EngineObjectVTable,
|
||||
version: i32 = -1,
|
||||
|
||||
pub fn updateFunc(self: *@This()) void {
|
||||
if (self.vtable.version != self.version) {
|
||||
const func = self.vtable.findFunc("windowOpen");
|
||||
self.windowFunction = @ptrCast(@alignCast(func));
|
||||
self.version = self.vtable.version;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const ig = @import("../imgui.zig").api;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
buffer: core.LogBuffer,
|
||||
allocator: std.mem.Allocator,
|
||||
buffer: core.LogBuffer = undefined,
|
||||
allocator: std.mem.Allocator = undefined,
|
||||
lastLength: usize = 0,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) @This() {
|
||||
return .{
|
||||
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "extras.consoleWindow");
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.buffer = core.LogBuffer.init(allocator),
|
||||
};
|
||||
|
||||
self.setup();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn setup(self: *@This()) void {
|
||||
|
|
@ -27,7 +34,11 @@ pub fn windowOpen(entry: *imgui.utils.MenuEntry, dt: f64) void {
|
|||
defer self.buffer.lock.unlock();
|
||||
|
||||
if (ig.begin("Console Output", &entry.open, .{})) {
|
||||
ig.textSlice(self.buffer.buffer.items);
|
||||
var items = self.buffer.buffer.items;
|
||||
|
||||
items = self.buffer.buffer.items[if (items.len > 10000) items.len - 10000 else 0..items.len];
|
||||
ig.textSlice(items);
|
||||
|
||||
if (self.lastLength != self.buffer.buffer.items.len)
|
||||
ig.setScrollHereY(1.0);
|
||||
}
|
||||
|
|
@ -36,8 +47,9 @@ pub fn windowOpen(entry: *imgui.utils.MenuEntry, dt: f64) void {
|
|||
self.lastLength = self.buffer.buffer.items.len;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.buffer.deinit();
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const imgui = @import("../imgui.zig");
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ pub const ConsoleWindow = @import("consoleWindow.zig");
|
|||
pub const TopBar = @import("TopBar.zig");
|
||||
pub const MenuEntry = TopBar.MenuEntry;
|
||||
|
||||
pub fn addMenuFunc(ctx: ?*anyopaque, name: []const u8, func: *const fn (*MenuEntry, f64) void) void {
|
||||
if (core.getEngineObject(TopBar)) |topbar| {
|
||||
topbar.addWindowsMenu(.{ .name = name, .ctx = ctx, .windowFunction = func }) catch {};
|
||||
}
|
||||
}
|
||||
// pub fn addMenuFunc(ctx: ?*anyopaque, name: []const u8, func: *const fn (*MenuEntry, f64) void) void {
|
||||
// if (core.getEngineObject(TopBar)) |topbar| {
|
||||
// topbar.addWindowsMenu(.{ .name = name, .ctx = ctx, .windowFunction = func }) catch {};
|
||||
// }
|
||||
// }
|
||||
|
||||
const core = @import("core");
|
||||
|
|
|
|||
|
|
@ -370,38 +370,8 @@ pub fn preTick(self: *@This(), dt: f64) !void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn tickServer(self: *@This(), dt: f64) void {
|
||||
_ = dt;
|
||||
|
||||
var event: enet.ENetEvent = undefined;
|
||||
|
||||
const result = enet.enet_host_service(self.host.?, &event, 0);
|
||||
|
||||
if (result > 0) {
|
||||
switch (event.type) {
|
||||
enet.ENET_EVENT_TYPE_CONNECT => {
|
||||
core.engine_log("client connected!!!!");
|
||||
},
|
||||
enet.ENET_EVENT_TYPE_RECEIVE => {
|
||||
const data = @as([*]u8, @ptrCast(event.packet.*.data))[0..event.packet.*.dataLength];
|
||||
_ = data;
|
||||
enet.enet_packet_destroy(event.packet);
|
||||
},
|
||||
|
||||
enet.ENET_EVENT_TYPE_DISCONNECT => {
|
||||
for (self.clients.items, 0..) |client, i| {
|
||||
if (client.id == event.peer.*.connectID) {
|
||||
_ = self.clients.swapRemove(i);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
else => {},
|
||||
}
|
||||
} else if (result < 0) {
|
||||
net.err("Error servicing host\n", .{});
|
||||
}
|
||||
}
|
||||
//pub fn tickServer(self: *@This(), dt: f64) void {
|
||||
// }
|
||||
|
||||
pub fn tickClient(self: *@This(), dt: f64) void {
|
||||
_ = self;
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ pub const PlatformInstance = struct {
|
|||
return self.cursorEnabled;
|
||||
}
|
||||
|
||||
pub fn setCursorVisible(self: @This(), visible: bool) void {
|
||||
pub fn setCursorVisible(self: *@This(), visible: bool) void {
|
||||
self.cursorEnabled = visible;
|
||||
if (visible) {
|
||||
sdl3.showCursor();
|
||||
|
|
|
|||
|
|
@ -315,10 +315,10 @@ pub const ParticleEmitter = struct {
|
|||
const pva = self.generatePVA();
|
||||
|
||||
const life = self.particleLife.getRange();
|
||||
try self.life.append(gParticleAllocator, .{ .current = life, .max = life });
|
||||
try self.particlesPVA.append(gParticleAllocator, pva);
|
||||
try self.finals.append(gParticleAllocator, std.mem.zeroes(core.Mat));
|
||||
try self.size.append(gParticleAllocator, self.particleSizeSpawn.getRange());
|
||||
try self.life.append(particleAllocator(), .{ .current = life, .max = life });
|
||||
try self.particlesPVA.append(particleAllocator(), pva);
|
||||
try self.finals.append(particleAllocator(), std.mem.zeroes(core.Mat));
|
||||
try self.size.append(particleAllocator(), self.particleSizeSpawn.getRange());
|
||||
}
|
||||
|
||||
fn updateLife(self: *@This(), dt: f64) void {
|
||||
|
|
@ -391,14 +391,18 @@ pub const ParticleEmitter = struct {
|
|||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.life.deinit(gParticleAllocator);
|
||||
self.particlesPVA.deinit(gParticleAllocator);
|
||||
self.finals.deinit(gParticleAllocator);
|
||||
self.size.deinit(gParticleAllocator);
|
||||
self.life.deinit(particleAllocator());
|
||||
self.particlesPVA.deinit(particleAllocator());
|
||||
self.finals.deinit(particleAllocator());
|
||||
self.size.deinit(particleAllocator());
|
||||
}
|
||||
};
|
||||
|
||||
var gParticleAllocator: std.mem.Allocator = undefined;
|
||||
fn particleAllocator() std.mem.Allocator {
|
||||
return core.get(ParticleSystem).particleArena.allocator();
|
||||
}
|
||||
|
||||
// var gParticleAllocator: std.mem.Allocator = undefined;
|
||||
|
||||
pub const ParticleSystem = struct {
|
||||
particleArena: std.heap.ArenaAllocator,
|
||||
|
|
@ -414,8 +418,6 @@ pub const ParticleSystem = struct {
|
|||
.allocator = allocator,
|
||||
};
|
||||
|
||||
gParticleAllocator = self.particleArena.allocator();
|
||||
|
||||
ParticleRandRangef.randomEngine = std.Random.DefaultPrng.init(0x1234);
|
||||
ParticleRandRangef.randomFunc = ParticleRandRangef.randomEngine.random();
|
||||
|
||||
|
|
|
|||
|
|
@ -254,6 +254,8 @@ pub fn LoadTrenchbroomMap(baseAllocator: std.mem.Allocator, settings: Settings)
|
|||
const fileMapping = try core.fs().loadFile(settings.mapName);
|
||||
defer core.fs().unmap(fileMapping);
|
||||
|
||||
core.engine_log("loading map :{s}", .{settings.mapName});
|
||||
|
||||
var arena = std.heap.ArenaAllocator.init(baseAllocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ lastUpdateFrame: u64 = 0,
|
|||
arena: std.heap.ArenaAllocator,
|
||||
strings: std.ArrayListUnmanaged([]u8) = .{},
|
||||
|
||||
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "game.EngineTool");
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ lastUpdateFrame: u64 = 0,
|
|||
arena: std.heap.ArenaAllocator,
|
||||
bodyIds: std.ArrayList(physics.BodyId),
|
||||
|
||||
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "extras.PhysicsObjectList");
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
allocator: std.mem.Allocator = undefined,
|
||||
|
||||
selectedObjectToSpawn: ?core.Name = null,
|
||||
|
||||
spawnedObjects: std.ArrayListUnmanaged(core.Entity) = .{},
|
||||
|
||||
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "extras.gameManagerUI");
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
self.* = .{ .allocator = allocator };
|
||||
|
||||
if (core.getEngineObject(igu.TopBar)) |topbar| {
|
||||
topbar.addMenuObject(self, "Game Manager") catch {};
|
||||
}
|
||||
|
||||
core.engine_log("why is this not spawning", .{});
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn objectReload(self: *@This()) void {
|
||||
_ = self;
|
||||
}
|
||||
|
||||
pub fn windowOpen(entry: *igu.MenuEntry, dt: f64) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(entry.ctx));
|
||||
_ = self;
|
||||
_ = dt;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.spawnedObjects.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const backlog = @import("Backlog");
|
||||
const core = backlog.core;
|
||||
const rend = backlog.rend;
|
||||
const ig = backlog.imgui.api;
|
||||
const igu = backlog.imgui.utils;
|
||||
const std = @import("std");
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
allocator: std.mem.Allocator = undefined,
|
||||
|
||||
selectedObjectToSpawn: ?core.Name = null,
|
||||
|
||||
spawnedObjects: std.ArrayListUnmanaged(core.Entity) = .{},
|
||||
|
||||
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "extras.ModulesLoader");
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
self.* = .{ .allocator = allocator };
|
||||
|
||||
if (core.getEngineObject(igu.TopBar)) |topbar| {
|
||||
topbar.addMenuObject(self, "Module Loader") catch {};
|
||||
}
|
||||
|
||||
core.engine_log("why is this not spawning", .{});
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn windowOpen(entry: *igu.MenuEntry, dt: f64) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(entry.ctx));
|
||||
_ = self;
|
||||
_ = dt;
|
||||
|
||||
if (ig.begin("ModuleLoaderList", null, .{})) {
|
||||
if (core.getEngineObject(core.ModuleLoader)) |moduleloader| {
|
||||
for (moduleloader.loadedModules.items) |module| {
|
||||
ig.textf("{s}", .{module.moduleName});
|
||||
ig.sameLine(0, 10);
|
||||
if (ig.checkbox("autoload", &module.autoLoad)) {}
|
||||
|
||||
for (module.loaded.items, 0..) |*loaded, i| {
|
||||
_ = loaded;
|
||||
ig.textf("{d}", .{i});
|
||||
ig.sameLine(0, 10);
|
||||
ig.pushID_Int(@intCast(i));
|
||||
if (ig.smallButton("activate")) {
|
||||
moduleloader.activateModuleVersion(module, i);
|
||||
}
|
||||
ig.popID();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ig.end();
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.spawnedObjects.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const backlog = @import("Backlog");
|
||||
const core = backlog.core;
|
||||
const rend = backlog.rend;
|
||||
const ig = backlog.imgui.api;
|
||||
const igu = backlog.imgui.utils;
|
||||
const std = @import("std");
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
allocator: std.mem.Allocator,
|
||||
allocator: std.mem.Allocator = undefined,
|
||||
|
||||
selectedObjectToSpawn: ?core.Name = null,
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ 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 ModuleLoader = @import("debuggers/modulesLoader.zig");
|
||||
|
||||
pub const browser = @import("debuggers/fileBrowser.zig");
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ pub const GameList = struct {
|
|||
|
||||
pub fn setGameTag(self: *@This(), gameName: []const u8, name: []const u8) void {
|
||||
var n = core.MakeName(name);
|
||||
(self.gamesByTag.getOrPut(gameName) catch unreachable).append(n.handle()) catch unreachable;
|
||||
const game = (self.gamesByTag.getOrPut(self.allocator, n.handle()) catch unreachable).value_ptr;
|
||||
game.append(self.allocator, self.games.get(gameName) orelse unreachable) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn removeTag(self: *@This(), game: []const u8, tag: []const u8) void {
|
||||
|
|
@ -62,9 +63,9 @@ pub const GameList = struct {
|
|||
var gameName = core.MakeName(game);
|
||||
|
||||
if (self.gamesByTag.getPtr(tagName.handle())) |list| {
|
||||
for (list.items) |i| {
|
||||
for (list.items, 0..) |i, j| {
|
||||
if (i.gameName.eql(&gameName)) {
|
||||
list.swapRemove(i);
|
||||
_ = list.swapRemove(j);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,6 +293,7 @@ pub const PackerFS = struct {
|
|||
self.lock.lock();
|
||||
defer self.lock.unlock();
|
||||
|
||||
std.debug.print("loading file: {s}", .{path});
|
||||
var pathName = Name.Make(path);
|
||||
if (self.fileHandlesByName.get(pathName.handle())) |fileNameHandle| {
|
||||
// std.debug.print("{s} maps to index {d}\n", .{ path, fileNameHandle });
|
||||
|
|
@ -307,6 +308,7 @@ pub const PackerFS = struct {
|
|||
|
||||
for (self.contentPaths.items) |contentPath| {
|
||||
if (try self.loadFileDirect(contentPath, path)) |mapping| {
|
||||
std.debug.print("loading directly: {s}, {s}", .{ contentPath, path });
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -26,23 +26,13 @@ pub export fn subtract(a: i32, b: i32) i32 {
|
|||
var gAllocator: std.mem.Allocator = undefined;
|
||||
|
||||
pub fn start_module(args: core.ModuleLoaderArgs) !void {
|
||||
if (args.firstLoad) {
|
||||
_ = core.createObject(ExternGameObject, .{}) catch {};
|
||||
core.engine_logs("creating externgame");
|
||||
return;
|
||||
}
|
||||
core.PatchOrCreateObject(extras.ModuleLoader, .{});
|
||||
core.PatchOrCreateObject(extras.ObjectSystemSpawner, .{});
|
||||
core.PatchOrCreateObject(ExternGameObject, .{});
|
||||
core.PatchOrCreateObject(imgui.utils.ConsoleWindow, .{});
|
||||
|
||||
_ = args;
|
||||
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).?;
|
||||
const vtable: *core.EngineObjectVTable = @constCast(ref.vtable);
|
||||
|
||||
core.PatchStruct(ExternGameObject, @ptrCast(@alignCast(ref.ptr)), ref.vtable.fieldList.?);
|
||||
vtable.* = ExternGameObject.NeonObjectTable;
|
||||
|
||||
core.get(ExternGameObject).onHotReload();
|
||||
}
|
||||
|
||||
pub const BoxObject = struct {
|
||||
|
|
@ -98,7 +88,6 @@ pub const ExternGameObject = struct {
|
|||
pub const Slack = core.SlackStruct(@This(), 1024);
|
||||
|
||||
allocator: std.mem.Allocator = undefined,
|
||||
consoleWindow: imgui.utils.ConsoleWindow = undefined,
|
||||
tbMap: ?*bsp.maploader.TBMap = null,
|
||||
physicsObjectsWindow: *extras.PhysicsObjectList = undefined,
|
||||
fireTraceFilter: physics.IgnoreFixedBodiesFilter = .{},
|
||||
|
|
@ -108,23 +97,16 @@ pub const ExternGameObject = struct {
|
|||
clientLink: ?*net.Link = null,
|
||||
|
||||
recompiling: bool = false,
|
||||
volume: f32 = 100,
|
||||
volume2: f64 = 100,
|
||||
volume4: f64 = 100,
|
||||
newBool: bool = true,
|
||||
new2Bool: bool = true,
|
||||
//lmao: bool = false,
|
||||
//lmao2: bool = true,
|
||||
// lib: bool = false,
|
||||
//s: u32 = 0x42,
|
||||
//
|
||||
firstTick: bool = true,
|
||||
|
||||
frameCount: u32 = 0,
|
||||
|
||||
fireInput: ?*core.ActionBinding = null,
|
||||
altFireInput: ?*core.ActionBinding = null,
|
||||
reloadInput: ?*core.ActionBinding = null,
|
||||
openSpawner: ?*core.ActionBinding = null,
|
||||
reloadMapInput: ?*core.ActionBinding = null,
|
||||
|
||||
volume: f32 = 100.0,
|
||||
vo2lume: f32 = 100.0,
|
||||
|
||||
a: core.Vector2f = .{ .x = 1, .y = 4 },
|
||||
b: core.Vector2f = .{ .x = 4, .y = 1 },
|
||||
|
|
@ -147,6 +129,11 @@ pub const ExternGameObject = struct {
|
|||
try self.setupInputs();
|
||||
}
|
||||
|
||||
pub fn onMapReload(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
const self = core.cast(*@This(), ctx.?);
|
||||
self.loadMap2() catch {};
|
||||
}
|
||||
|
||||
pub fn setupInputs(self: *@This()) !void {
|
||||
if (self.fireInput) |fireInput| {
|
||||
fireInput.deactivate();
|
||||
|
|
@ -159,29 +146,56 @@ pub const ExternGameObject = struct {
|
|||
input.deactivate();
|
||||
}
|
||||
|
||||
if (self.openSpawner) |input| {
|
||||
input.deactivate();
|
||||
self.openSpawner = null;
|
||||
}
|
||||
|
||||
if (self.reloadMapInput) |input| {
|
||||
input.deactivate();
|
||||
self.reloadMapInput = null;
|
||||
}
|
||||
|
||||
if (self.reloadMapInput == null) {
|
||||
self.reloadMapInput = try core.ActionBinding.create(core.MakeName("input"));
|
||||
self.reloadMapInput.?.addKey(.@"7", .keyDown);
|
||||
_ = self.reloadMapInput.?.data.addListener(@This(), "onMapReload", self);
|
||||
}
|
||||
self.reloadMapInput.?.activate();
|
||||
|
||||
if (self.reloadInput == null) {
|
||||
self.reloadInput = try core.ActionBinding.create(core.MakeName("input"));
|
||||
self.reloadInput = try core.ActionBinding.create(core.MakeName("reloadInput"));
|
||||
self.reloadInput.?.addKey(.@"9", .keyDown);
|
||||
_ = self.reloadInput.?.data.addListener(self, onRequestReload);
|
||||
_ = self.reloadInput.?.data.addListener(@This(), "onRequestReload", self);
|
||||
}
|
||||
self.reloadInput.?.activate();
|
||||
|
||||
if (self.fireInput == null) {
|
||||
self.fireInput = try core.ActionBinding.create(core.MakeName("fire"));
|
||||
self.fireInput.?.addKey(.Mouse1, .keyDown);
|
||||
_ = self.fireInput.?.data.addListener(self, onFire);
|
||||
_ = self.fireInput.?.data.addListener(@This(), "onFire", self);
|
||||
}
|
||||
self.fireInput.?.activate();
|
||||
|
||||
if (self.altFireInput == null) {
|
||||
self.altFireInput = try core.ActionBinding.create(core.MakeName("altFire"));
|
||||
self.altFireInput.?.addKey(.Mouse3, .keyDown);
|
||||
_ = self.altFireInput.?.data.addListener(self, onAltFire);
|
||||
_ = self.altFireInput.?.data.addListener(@This(), "onAltFire", self);
|
||||
}
|
||||
self.altFireInput.?.activate();
|
||||
|
||||
if (self.openSpawner == null) {
|
||||
self.openSpawner = try core.ActionBinding.create(core.MakeName("openSpawner"));
|
||||
self.openSpawner.?.addKey(.@"8", .keyDown);
|
||||
_ = self.openSpawner.?.data.addListener(@This(), "onOpenSpawner", self);
|
||||
}
|
||||
self.openSpawner.?.activate();
|
||||
|
||||
core.engine_log("inputs bound for externGame", .{});
|
||||
}
|
||||
|
||||
pub fn onHotReload(self: *@This()) void {
|
||||
pub fn objectReload(self: *@This()) void {
|
||||
core.engine_logs("extern game object reload");
|
||||
self.setupInputs() catch {
|
||||
core.engine_errs("Unable to setup inputs");
|
||||
};
|
||||
|
|
@ -211,14 +225,12 @@ pub const ExternGameObject = struct {
|
|||
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);
|
||||
// core.get(imgui.utils.TopBar).addMenuObject(self, "Input Stack Viewer", extras.inputDebugger.windowOpen);
|
||||
|
||||
self.physicsObjectsWindow = try extras.PhysicsObjectList.create(self.allocator);
|
||||
self.consoleWindow.setup();
|
||||
|
||||
try core.registerObject(BoxObject, "Box");
|
||||
try core.registerObjectAdvanced(BoxObject, "BoxSmoky", "createSmoky");
|
||||
|
|
@ -340,7 +352,15 @@ pub const ExternGameObject = struct {
|
|||
self.recompiling = false;
|
||||
}
|
||||
|
||||
fn onRequestReload(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
pub fn onOpenSpawner(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
core.engine_logs("spawner opened");
|
||||
_ = ctx;
|
||||
if (core.getEngineObject(imgui.utils.TopBar)) |topbar| {
|
||||
topbar.setEntryOpen("New Object Spawner", null);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn onRequestReload(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
const self = core.cast(*@This(), ctx.?);
|
||||
|
||||
if (!self.recompiling) {
|
||||
|
|
@ -366,7 +386,7 @@ pub const ExternGameObject = struct {
|
|||
}
|
||||
}
|
||||
|
||||
fn onAltFire(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
pub fn onAltFire(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
|
||||
if (platform.context().isCursorEnabled()) {
|
||||
|
|
@ -385,7 +405,7 @@ pub const ExternGameObject = struct {
|
|||
}
|
||||
}
|
||||
|
||||
fn onFire(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
pub fn onFire(ctx: ?*anyopaque, _: core.ActionEvent) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
|
||||
if (platform.context().isCursorEnabled()) {
|
||||
|
|
@ -399,8 +419,6 @@ pub const ExternGameObject = struct {
|
|||
.position = p,
|
||||
};
|
||||
self.spawnedEntities.append(self.allocator, core.get(extras.ObjectSystemSpawner).spawnObjectAt(posRot) orelse return) catch unreachable;
|
||||
|
||||
// addBox(p.add(n.fmul(1.0))) catch unreachable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -409,7 +427,11 @@ pub const ExternGameObject = struct {
|
|||
pub fn tick(self: *@This(), dt: f64) void {
|
||||
const rctx = rend.context();
|
||||
_ = rctx;
|
||||
|
||||
_ = dt;
|
||||
//self.time += @floatCast(dt);
|
||||
|
||||
//core.debugSphere(.{ .y = 10 + std.math.sin(self.time) }, 5, .{});
|
||||
|
||||
if (core.getEngineObject(imgui.utils.TopBar)) |topbar| {
|
||||
topbar.menuOpen = platform.context().isCursorEnabled();
|
||||
|
|
@ -424,8 +446,6 @@ pub const ExternGameObject = struct {
|
|||
self.firstTick = false;
|
||||
}
|
||||
|
||||
imgui.utils.structDebugWindow(self);
|
||||
|
||||
if (self.recompiling) {
|
||||
if (ig.begin("recompiling", null, .{})) {
|
||||
ig.textf("recompiling...", .{});
|
||||
|
|
@ -434,6 +454,10 @@ pub const ExternGameObject = struct {
|
|||
}
|
||||
|
||||
if (platform.context().isCursorEnabled()) {
|
||||
// imgui.utils.structDebugWindow(self);
|
||||
|
||||
// imgui.utils.structDebugWindow(core.get(rend.renderer.Renderer));
|
||||
|
||||
if (ig.begin("meh", null, .{})) {
|
||||
// if (ig.checkbox("move lights ", null)) {}
|
||||
|
||||
|
|
@ -443,6 +467,8 @@ pub const ExternGameObject = struct {
|
|||
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;
|
||||
|
||||
ig.textf("lmao", .{});
|
||||
|
||||
if (ig.smallButton("reload map")) {
|
||||
self.loadMap2() catch unreachable;
|
||||
}
|
||||
|
|
@ -531,7 +557,6 @@ pub const ExternGameObject = struct {
|
|||
}
|
||||
|
||||
self.spawnedEntities.deinit(self.allocator);
|
||||
self.consoleWindow.deinit();
|
||||
self.physicsObjectsWindow.destroy();
|
||||
self.allocator.destroy(Slack.fromPtr(self));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,17 +268,6 @@ pub fn prepare(self: *@This()) !void {
|
|||
try rendererDebug.skyboxes.append(rendererDebug.allocator, core.MakeName("t_skybox"));
|
||||
try rendererDebug.skyboxes.append(rendererDebug.allocator, core.MakeName("t_dark_skybox"));
|
||||
|
||||
const objectSpawner2 = try core.createObject(extras.ObjectSystemSpawner, .{});
|
||||
_ = objectSpawner2;
|
||||
|
||||
//self.objectSpawner = try extras.ObjectSpawner.create(self.allocator);
|
||||
self.objectSpawner = try core.createObject(extras.ObjectSpawner, .{});
|
||||
// try self.objectSpawner.addSpawnFunction("fox", FoxObject);
|
||||
try self.objectSpawner.addSpawnFunction("particle", ParticleObject);
|
||||
try self.objectSpawner.addSpawnFunction("doomplayer", DoomPlayer.DoomCanvas);
|
||||
try self.objectSpawner.addSpawnFunction("empire", @import("empire.zig"));
|
||||
try self.objectSpawner.addSpawnFunction("DamagedHelmet", DamagedHelmet);
|
||||
|
||||
try core.getEngineObject(core.GameObjectSystem).?.registerObject("foxObject", FoxObject);
|
||||
|
||||
try assets.loadList(assetReferences);
|
||||
|
|
@ -300,14 +289,14 @@ fn beginPlay(p: ?*anyopaque) void {
|
|||
fn _beginPlay(self: *@This()) !void {
|
||||
const exitInput = try core.ActionBinding.create(core.MakeName("exit"));
|
||||
exitInput.addKey(.escape, .keyDown);
|
||||
_ = exitInput.data.addListener(null, onExit);
|
||||
_ = exitInput.data.addListener(@This(), "onExit", self);
|
||||
exitInput.activate();
|
||||
|
||||
{
|
||||
const inp = try core.ActionBinding.create(core.MakeName("slow"));
|
||||
inp.addKey(.lshift, .keyDown);
|
||||
inp.addKey(.lshift, .keyUp);
|
||||
_ = inp.data.addListener(self, slowDown);
|
||||
_ = inp.data.addListener(@This(), "slowDown", self);
|
||||
inp.activate();
|
||||
}
|
||||
|
||||
|
|
@ -322,7 +311,7 @@ fn _beginPlay(self: *@This()) !void {
|
|||
moveInput.addKey(.d, 1.0, .x);
|
||||
moveInput.addKey(.a, -1.0, .x);
|
||||
|
||||
_ = moveInput.data.addListener(self, onMove);
|
||||
_ = moveInput.data.addListener(@This(), "onMove", self);
|
||||
moveInput.activate();
|
||||
|
||||
{
|
||||
|
|
@ -330,7 +319,7 @@ fn _beginPlay(self: *@This()) !void {
|
|||
i.addKey(.f, 1.0);
|
||||
i.addKey(.v, -1.0);
|
||||
|
||||
_ = i.data.addListener(self, distanceMove);
|
||||
_ = i.data.addListener(@This(), "distanceMove", self);
|
||||
i.activate();
|
||||
}
|
||||
|
||||
|
|
@ -339,47 +328,47 @@ fn _beginPlay(self: *@This()) !void {
|
|||
verticalInput.addKey(.e, 1.0);
|
||||
verticalInput.addKey(.q, -1.0);
|
||||
|
||||
_ = verticalInput.data.addListener(self, verticalMovement);
|
||||
_ = verticalInput.data.addListener(@This(), "verticalMovement", self);
|
||||
verticalInput.activate();
|
||||
}
|
||||
|
||||
{
|
||||
const mouseLook = try core.Axis2dBinding.create(core.MakeName("mouseLook"));
|
||||
mouseLook.enableMouseRelative();
|
||||
_ = mouseLook.data.addListener(self, onMouseLook);
|
||||
_ = mouseLook.data.addListener(@This(), "onMouseLook", self);
|
||||
mouseLook.activate();
|
||||
}
|
||||
|
||||
{
|
||||
const shaderReload = try core.ActionBinding.create(core.MakeName("shaderReload"));
|
||||
shaderReload.addKey(.r, .keyDown);
|
||||
_ = shaderReload.data.addListener(self, onShaderReload);
|
||||
_ = shaderReload.data.addListener(@This(), "onShaderReload", self);
|
||||
shaderReload.activate();
|
||||
}
|
||||
|
||||
{
|
||||
const input = try core.ActionBinding.create(core.MakeName("toggleDoom"));
|
||||
input.addKey(.f2, .keyDown);
|
||||
_ = input.data.addListener(self, toggleDoom);
|
||||
_ = input.data.addListener(@This(), "toggleDoom", self);
|
||||
input.activate();
|
||||
}
|
||||
|
||||
{
|
||||
const input = try core.ActionBinding.create(core.MakeName("toggleMouseLook"));
|
||||
input.addKey(.t, .keyDown);
|
||||
_ = input.data.addListener(self, toggleMouseLook);
|
||||
_ = input.data.addListener(@This(), "toggleMouseLook", self);
|
||||
input.activate();
|
||||
}
|
||||
|
||||
self.updateMouseLook();
|
||||
}
|
||||
|
||||
fn game_endPlay(p: ?*anyopaque) void {
|
||||
const self = core.cast(@This(), p);
|
||||
pub fn game_endPlay(p: ?*anyopaque) void {
|
||||
const self = core.cast(*@This(), p.?);
|
||||
_ = self;
|
||||
}
|
||||
|
||||
fn onMouseLook(ctx: ?*anyopaque, axis: core.Vector2f) void {
|
||||
pub fn onMouseLook(ctx: ?*anyopaque, axis: core.Vector2f) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
|
||||
if (self.inputEnabled) {
|
||||
|
|
@ -387,7 +376,7 @@ fn onMouseLook(ctx: ?*anyopaque, axis: core.Vector2f) void {
|
|||
}
|
||||
}
|
||||
|
||||
fn toggleDoom(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
pub fn toggleDoom(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
_ = action;
|
||||
|
||||
|
|
@ -398,7 +387,7 @@ fn toggleDoom(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
|||
}
|
||||
}
|
||||
|
||||
fn toggleMouseLook(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
pub fn toggleMouseLook(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
_ = action;
|
||||
|
||||
|
|
@ -409,13 +398,13 @@ fn toggleMouseLook(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
|||
self.updateMouseLook();
|
||||
}
|
||||
|
||||
fn updateMouseLook(self: *@This()) void {
|
||||
pub fn updateMouseLook(self: *@This()) void {
|
||||
self.fpcamera.mouseLookEnabled = self.mouseLook;
|
||||
platform.setMouseRelativeMode(self.mouseLook);
|
||||
// platform.setImguiVisible(!self.mouseLook);
|
||||
}
|
||||
|
||||
fn onShaderReload(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
pub fn onShaderReload(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
_ = ctx;
|
||||
_ = action;
|
||||
|
||||
|
|
@ -425,7 +414,7 @@ fn onShaderReload(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
|||
};
|
||||
}
|
||||
|
||||
fn slowDown(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
pub fn slowDown(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
|
||||
if (action == .keyUp) {
|
||||
|
|
@ -436,22 +425,17 @@ fn slowDown(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
|||
}
|
||||
}
|
||||
|
||||
fn distanceMove(ctx: ?*anyopaque, axis: f32) void {
|
||||
pub fn distanceMove(ctx: ?*anyopaque, axis: f32) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
self.centerDistMove = axis;
|
||||
}
|
||||
|
||||
fn cameraRotate(ctx: ?*anyopaque, axis: f32) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
self.rotateAxis = axis;
|
||||
}
|
||||
|
||||
fn verticalMovement(ctx: ?*anyopaque, axis: f32) void {
|
||||
pub fn verticalMovement(ctx: ?*anyopaque, axis: f32) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
self.verticalMove = axis;
|
||||
}
|
||||
|
||||
fn onMove(ctx: ?*anyopaque, axis: core.Vector2f) void {
|
||||
pub fn onMove(ctx: ?*anyopaque, axis: core.Vector2f) void {
|
||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||
self.moveVector = .{ .x = axis.x, .z = axis.y, .y = 0.0 };
|
||||
}
|
||||
|
|
@ -470,28 +454,6 @@ pub fn getMouseMovement(self: *@This()) core.Vector2f {
|
|||
return rv;
|
||||
}
|
||||
|
||||
pub fn tryLoadExtern(self: *@This(), gameName: []const u8) !void {
|
||||
var buf = std.mem.zeroes([256]u8);
|
||||
|
||||
const os_tag = @import("builtin").os.tag;
|
||||
|
||||
var suffix: []const u8 = "dll";
|
||||
var prefix: []const u8 = "";
|
||||
if (os_tag == .linux) {
|
||||
prefix = "lib";
|
||||
suffix = "so";
|
||||
} else if (os_tag == .macos) {
|
||||
suffix = "dylib";
|
||||
prefix = "lib";
|
||||
}
|
||||
|
||||
const path = try std.fmt.bufPrint(&buf, "zig-out/modules/{s}{s}.{s}", .{ prefix, gameName, suffix });
|
||||
var lib = try std.DynLib.open(path);
|
||||
// std.debug.print("path: {s}", .{path});
|
||||
|
||||
self.addFunc = lib.lookup(@TypeOf(self.addFunc.?), "add");
|
||||
}
|
||||
|
||||
pub fn tick(self: *@This(), dt: f64) void {
|
||||
const fdt: f32 = @floatCast(dt);
|
||||
|
||||
|
|
@ -515,13 +477,6 @@ pub fn tick(self: *@This(), dt: f64) void {
|
|||
}
|
||||
|
||||
self.fpcamera.resolve();
|
||||
|
||||
const forward = self.fpcamera.getForward();
|
||||
const debugCenter = self.fpcamera.getPosition().add(forward.fmul(self.centerDist));
|
||||
self.objectSpawner.spawnPosition = debugCenter;
|
||||
self.objectSpawner.spawnRotation = core.Rotation.eulerY(core.radians(self.fpcamera.yaw));
|
||||
|
||||
self.objectSpawner.windowOpen = !self.mouseLook;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
|
|
@ -531,7 +486,6 @@ pub fn deinit(self: *@This()) void {
|
|||
self.fpcamera.destroy();
|
||||
self.engineTool.destroy();
|
||||
|
||||
// self.objectSpawner.destroy();
|
||||
// self.videoplayer.destroy();
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue