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);
|
_ = 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()).?;
|
const sound = self.sounds.get(soundName.handle()).?;
|
||||||
|
|
||||||
if (ma.ma_sound_stop(sound) != ma.MA_SUCCESS) {
|
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;
|
var makeNameBuf: [256]u8 = undefined;
|
||||||
return algorithm.MakeName(std.fmt.bufPrint(&makeNameBuf, fmt, args) catch unreachable);
|
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,
|
OutOfMemory,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const FuncInfo = struct {
|
||||||
|
name: []const u8,
|
||||||
|
ptr: *const anyopaque,
|
||||||
|
};
|
||||||
|
|
||||||
pub const FieldInfo = struct {
|
pub const FieldInfo = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
size: u32,
|
size: u32,
|
||||||
|
|
@ -49,6 +54,25 @@ pub const FieldInfo = struct {
|
||||||
alignment: u32,
|
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 {
|
pub fn PatchStruct(comptime T: type, p: *T, old: []const FieldInfo) void {
|
||||||
const t = @typeInfo(T).@"struct";
|
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.ptr = @ptrCast(&@field(new, field.name));
|
||||||
dest.len = @sizeOf(@TypeOf(@field(new, field.name)));
|
dest.len = @sizeOf(@TypeOf(@field(new, field.name)));
|
||||||
|
|
||||||
std.debug.print(
|
// std.debug.print(
|
||||||
"patching field {s} {d} bytes {d} -> {d} {s}\n",
|
// "patching field {s} {d} bytes {d} -> {d} {s}\n",
|
||||||
.{
|
// .{
|
||||||
field.name,
|
// field.name,
|
||||||
src.len,
|
// src.len,
|
||||||
of.offset,
|
// of.offset,
|
||||||
@offsetOf(T, field.name),
|
// @offsetOf(T, field.name),
|
||||||
if (of.offset == @offsetOf(T, field.name)) "" else "change!",
|
// if (of.offset == @offsetOf(T, field.name)) "" else "change!",
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
|
|
||||||
std.mem.copyForwards(u8, dest, src);
|
std.mem.copyForwards(u8, dest, src);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -94,6 +118,35 @@ pub fn PatchStruct(comptime T: type, p: *T, old: []const FieldInfo) void {
|
||||||
p.* = new;
|
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 {
|
pub const EngineObjectVTable = struct {
|
||||||
typeName: []const u8,
|
typeName: []const u8,
|
||||||
typeSize: usize,
|
typeSize: usize,
|
||||||
|
|
@ -116,6 +169,51 @@ pub const EngineObjectVTable = struct {
|
||||||
fieldList: ?[]const FieldInfo = null,
|
fieldList: ?[]const FieldInfo = null,
|
||||||
slackSize: ?usize = 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 {
|
fn fieldInfoCompare(_: void, a: FieldInfo, b: FieldInfo) bool {
|
||||||
return a.offset < b.offset;
|
return a.offset < b.offset;
|
||||||
}
|
}
|
||||||
|
|
@ -152,6 +250,7 @@ pub const EngineObjectVTable = struct {
|
||||||
.init_func = undefined,
|
.init_func = undefined,
|
||||||
};
|
};
|
||||||
self.addFieldList(TargetType);
|
self.addFieldList(TargetType);
|
||||||
|
self.addFunctionsList(TargetType);
|
||||||
|
|
||||||
if (engineObjectName) |eon| {
|
if (engineObjectName) |eon| {
|
||||||
self.singletonName = eon;
|
self.singletonName = eon;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ pub const LoadedModule = struct {
|
||||||
startOnLoad: bool = true,
|
startOnLoad: bool = true,
|
||||||
started: bool = false,
|
started: bool = false,
|
||||||
initialLoad: bool = true,
|
initialLoad: bool = true,
|
||||||
|
autoLoad: bool = true,
|
||||||
|
loadNextFrame: bool = false,
|
||||||
|
|
||||||
pub fn getInterface(self: @This()) ?ModuleInterface {
|
pub fn getInterface(self: @This()) ?ModuleInterface {
|
||||||
return self.loaded.getLastOrNull();
|
return self.loaded.getLastOrNull();
|
||||||
|
|
@ -75,6 +77,7 @@ pub const LoadedModule = struct {
|
||||||
pub fn load(self: *@This(), allocator: std.mem.Allocator) !void {
|
pub fn load(self: *@This(), allocator: std.mem.Allocator) !void {
|
||||||
core.engine_log("[ModuleLoader] loading module: ", .{});
|
core.engine_log("[ModuleLoader] loading module: ", .{});
|
||||||
self.lastLoad = std.time.microTimestamp();
|
self.lastLoad = std.time.microTimestamp();
|
||||||
|
|
||||||
try self.stageModule(allocator);
|
try self.stageModule(allocator);
|
||||||
try self.loadStagedModule(allocator);
|
try self.loadStagedModule(allocator);
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +103,8 @@ pub const LoadedModule = struct {
|
||||||
shouldLoad = true;
|
shouldLoad = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldLoad) {
|
if (shouldLoad and (self.autoLoad or self.loadNextFrame)) {
|
||||||
|
self.loadNextFrame = false;
|
||||||
try self.load(allocator);
|
try self.load(allocator);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -165,6 +169,18 @@ pub const ModuleLoader = struct {
|
||||||
try self.loadedModules.append(self.arena.allocator(), loaded);
|
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 {
|
pub fn tick(self: *@This(), dt: f64) void {
|
||||||
_ = dt;
|
_ = dt;
|
||||||
for (self.loadedModules.items) |loaded| {
|
for (self.loadedModules.items) |loaded| {
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,13 @@ fn arenaAlloc() std.mem.Allocator {
|
||||||
return getInputStack().arena.allocator();
|
return getInputStack().arena.allocator();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn BindingData(Listener: type, Func: type) type {
|
fn BindingData(Func: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
|
pub const Delegate = core.EngineObjectDelegate(Func);
|
||||||
keysDown: KeysDownQueue,
|
keysDown: KeysDownQueue,
|
||||||
keysUp: std.ArrayListUnmanaged(Key) = .{},
|
keysUp: std.ArrayListUnmanaged(Key) = .{},
|
||||||
listeners: std.ArrayListUnmanaged(Listener) = .{},
|
listeners: std.ArrayListUnmanaged(Delegate) = .{},
|
||||||
|
listenerId: std.ArrayListUnmanaged(u32) = .{},
|
||||||
consumed: bool = false,
|
consumed: bool = false,
|
||||||
routed: bool = false,
|
routed: bool = false,
|
||||||
count: u32 = 0,
|
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();
|
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;
|
self.count +%= 1;
|
||||||
|
|
||||||
return self.count;
|
return self.count;
|
||||||
|
|
@ -104,7 +125,8 @@ fn BindingData(Listener: type, Func: type) type {
|
||||||
pub fn removeListener(self: *@This(), id: u32) void {
|
pub fn removeListener(self: *@This(), id: u32) void {
|
||||||
for (self.listeners.items.len, 0..) |listener, i| {
|
for (self.listeners.items.len, 0..) |listener, i| {
|
||||||
if (listener.id == id) {
|
if (listener.id == id) {
|
||||||
self.listeners.swapRemove(i);
|
_ = self.listenerId.swapRemove(i);
|
||||||
|
_ = self.listeners.swapRemove(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,21 +152,20 @@ fn BindingData(Listener: type, Func: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ActionBinding = struct {
|
pub const ActionBinding = struct {
|
||||||
data: BindingData(Listener, ActionFunc),
|
data: BindingData(ActionFunc),
|
||||||
keys: std.ArrayListUnmanaged(ActionBindingKey) = .{},
|
keys: std.ArrayListUnmanaged(ActionBindingKey) = .{},
|
||||||
|
|
||||||
pub const Listener = struct {
|
// pub const Listener = struct {
|
||||||
id: u32,
|
// id: u32,
|
||||||
ctx: ?*anyopaque,
|
// delegate: core.
|
||||||
func: ActionFunc,
|
// };
|
||||||
};
|
|
||||||
|
|
||||||
pub fn create(name: core.Name) !*@This() {
|
pub fn create(name: core.Name) !*@This() {
|
||||||
const allocator = arenaAlloc();
|
const allocator = arenaAlloc();
|
||||||
const self = try allocator.create(@This());
|
const self = try allocator.create(@This());
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.data = BindingData(Listener, ActionFunc).init(name),
|
.data = BindingData(ActionFunc).init(name),
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
@ -180,24 +201,24 @@ pub const AxisBindingKeyMagnitude = struct {
|
||||||
pub const Axis1dFunc = *const fn (?*anyopaque, f32) void;
|
pub const Axis1dFunc = *const fn (?*anyopaque, f32) void;
|
||||||
|
|
||||||
pub const Axis1dBinding = struct {
|
pub const Axis1dBinding = struct {
|
||||||
data: BindingData(Listener, Axis1dFunc),
|
data: BindingData(Axis1dFunc),
|
||||||
keys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
keys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
||||||
magnitude: f32 = 0.0,
|
magnitude: f32 = 0.0,
|
||||||
|
|
||||||
clampValue: ?f32 = 1.0,
|
clampValue: ?f32 = 1.0,
|
||||||
|
|
||||||
pub const Listener = struct {
|
// pub const Listener = struct {
|
||||||
id: u32,
|
// id: u32,
|
||||||
ctx: ?*anyopaque,
|
// ctx: ?*anyopaque,
|
||||||
func: Axis1dFunc,
|
// func: Axis1dFunc,
|
||||||
};
|
// };
|
||||||
|
|
||||||
pub fn create(name: core.Name) !*@This() {
|
pub fn create(name: core.Name) !*@This() {
|
||||||
const allocator = arenaAlloc();
|
const allocator = arenaAlloc();
|
||||||
const self = try allocator.create(@This());
|
const self = try allocator.create(@This());
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.data = BindingData(Listener, Axis1dFunc).init(name),
|
.data = BindingData(Axis1dFunc).init(name),
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
@ -231,7 +252,7 @@ pub const Axis1dBinding = struct {
|
||||||
|
|
||||||
pub const Axis2dFunc = *const fn (?*anyopaque, core.Vector2f) void;
|
pub const Axis2dFunc = *const fn (?*anyopaque, core.Vector2f) void;
|
||||||
pub const Axis2dBinding = struct {
|
pub const Axis2dBinding = struct {
|
||||||
data: BindingData(Listener, Axis2dFunc),
|
data: BindingData(Axis2dFunc),
|
||||||
yKeys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
yKeys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
||||||
xKeys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
xKeys: std.ArrayListUnmanaged(AxisBindingKeyMagnitude) = .{},
|
||||||
|
|
||||||
|
|
@ -243,18 +264,18 @@ pub const Axis2dBinding = struct {
|
||||||
|
|
||||||
clampValue: ?f32 = 1.0,
|
clampValue: ?f32 = 1.0,
|
||||||
|
|
||||||
pub const Listener = struct {
|
// pub const Listener = struct {
|
||||||
id: u32,
|
// id: u32,
|
||||||
ctx: ?*anyopaque,
|
// ctx: ?*anyopaque,
|
||||||
func: Axis2dFunc,
|
// func: Axis2dFunc,
|
||||||
};
|
// };
|
||||||
|
|
||||||
pub fn create(name: core.Name) !*@This() {
|
pub fn create(name: core.Name) !*@This() {
|
||||||
const allocator = arenaAlloc();
|
const allocator = arenaAlloc();
|
||||||
const self = try allocator.create(@This());
|
const self = try allocator.create(@This());
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.data = BindingData(Listener, Axis2dFunc).init(name),
|
.data = BindingData(Axis2dFunc).init(name),
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
@ -354,15 +375,15 @@ pub const Binding = union(BindingType) {
|
||||||
.action => {},
|
.action => {},
|
||||||
.axis1d => |p| {
|
.axis1d => |p| {
|
||||||
p.data.routed = false;
|
p.data.routed = false;
|
||||||
for (p.data.listeners.items) |listener| {
|
for (p.data.listeners.items) |*listener| {
|
||||||
listener.func(listener.ctx, p.magnitude);
|
listener.call(p.magnitude);
|
||||||
}
|
}
|
||||||
p.magnitude = 0.0;
|
p.magnitude = 0.0;
|
||||||
},
|
},
|
||||||
.axis2d => |p| {
|
.axis2d => |p| {
|
||||||
p.data.routed = false;
|
p.data.routed = false;
|
||||||
for (p.data.listeners.items) |listener| {
|
for (p.data.listeners.items) |*listener| {
|
||||||
listener.func(listener.ctx, p.magnitude);
|
listener.call(p.magnitude);
|
||||||
}
|
}
|
||||||
p.magnitude = core.Vector2f.Zeroes;
|
p.magnitude = core.Vector2f.Zeroes;
|
||||||
},
|
},
|
||||||
|
|
@ -382,8 +403,8 @@ pub const Binding = union(BindingType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (routed) {
|
if (routed) {
|
||||||
for (p.data.listeners.items) |listener| {
|
for (p.data.listeners.items) |*listener| {
|
||||||
listener.func(listener.ctx, event);
|
listener.call(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -403,9 +424,6 @@ pub const Binding = union(BindingType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.data.routed = routed;
|
p.data.routed = routed;
|
||||||
// for (p.data.listeners.items) |listener| {
|
|
||||||
// listener.func(listener.ctx, magnitude);
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
.axis2d => |p| {
|
.axis2d => |p| {
|
||||||
for (p.xKeys.items) |keyBinding| {
|
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);
|
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;
|
p.data.routed = routed;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -269,9 +269,9 @@ pub const LoggerSys = struct {
|
||||||
try self.writeOutBuffer.writer().print(fmt, args);
|
try self.writeOutBuffer.writer().print(fmt, args);
|
||||||
self.lock.unlock();
|
self.lock.unlock();
|
||||||
|
|
||||||
if (self.sessionBuffer != null) {
|
if (self.sessionBuffer != null and !core.getEngine().isShuttingDown()) {
|
||||||
// self.sessionBuffer.?.lockWriter().print(fmt, args) catch {};
|
self.sessionBuffer.?.lockWriter().print(fmt, args) catch {};
|
||||||
// self.sessionBuffer.?.unlock();
|
self.sessionBuffer.?.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.writeOutBuffer.items.len > LogBufferSize) {
|
if (self.writeOutBuffer.items.len > LogBufferSize) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||||
|
|
||||||
try self.addWindowsMenu(.{
|
try self.addWindowsMenu(.{
|
||||||
.name = "sample window",
|
.name = "sample window",
|
||||||
|
.vtable = &NeonObjectTable,
|
||||||
.open = false,
|
.open = false,
|
||||||
.ctx = self,
|
.ctx = self,
|
||||||
.windowFunction = windowOpen,
|
.windowFunction = windowOpen,
|
||||||
|
|
@ -24,9 +25,20 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||||
return self;
|
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 {
|
pub fn addMenuObject(self: *@This(), ptr: anytype, comptime name: []const u8) !void {
|
||||||
const T = @TypeOf(ptr.*);
|
const T = @TypeOf(ptr.*);
|
||||||
try self.addWindowsMenu(.{
|
try self.addWindowsMenu(.{
|
||||||
|
.vtable = &T.NeonObjectTable,
|
||||||
.name = name,
|
.name = name,
|
||||||
.ctx = ptr,
|
.ctx = ptr,
|
||||||
.windowFunction = T.windowOpen,
|
.windowFunction = T.windowOpen,
|
||||||
|
|
@ -87,6 +99,7 @@ pub fn tick(self: *@This(), dt: f64) void {
|
||||||
|
|
||||||
for (self.windowsMenu.items) |entry| {
|
for (self.windowsMenu.items) |entry| {
|
||||||
if (entry.open) {
|
if (entry.open) {
|
||||||
|
entry.updateFunc();
|
||||||
entry.windowFunction(entry, dt);
|
entry.windowFunction(entry, dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +116,16 @@ pub const MenuEntry = struct {
|
||||||
open: bool = false,
|
open: bool = false,
|
||||||
ctx: ?*anyopaque,
|
ctx: ?*anyopaque,
|
||||||
windowFunction: *const fn (*MenuEntry, f64) void,
|
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;
|
const ig = @import("../imgui.zig").api;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,19 @@
|
||||||
buffer: core.LogBuffer,
|
buffer: core.LogBuffer = undefined,
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator = undefined,
|
||||||
lastLength: usize = 0,
|
lastLength: usize = 0,
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator) @This() {
|
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "extras.consoleWindow");
|
||||||
return .{
|
|
||||||
|
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||||
|
const self = try allocator.create(@This());
|
||||||
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.buffer = core.LogBuffer.init(allocator),
|
.buffer = core.LogBuffer.init(allocator),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.setup();
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup(self: *@This()) void {
|
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();
|
defer self.buffer.lock.unlock();
|
||||||
|
|
||||||
if (ig.begin("Console Output", &entry.open, .{})) {
|
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)
|
if (self.lastLength != self.buffer.buffer.items.len)
|
||||||
ig.setScrollHereY(1.0);
|
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;
|
self.lastLength = self.buffer.buffer.items.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *@This()) void {
|
pub fn destroy(self: *@This()) void {
|
||||||
self.buffer.deinit();
|
self.buffer.deinit();
|
||||||
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
const imgui = @import("../imgui.zig");
|
const imgui = @import("../imgui.zig");
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ pub const ConsoleWindow = @import("consoleWindow.zig");
|
||||||
pub const TopBar = @import("TopBar.zig");
|
pub const TopBar = @import("TopBar.zig");
|
||||||
pub const MenuEntry = TopBar.MenuEntry;
|
pub const MenuEntry = TopBar.MenuEntry;
|
||||||
|
|
||||||
pub fn addMenuFunc(ctx: ?*anyopaque, name: []const u8, func: *const fn (*MenuEntry, f64) void) void {
|
// pub fn addMenuFunc(ctx: ?*anyopaque, name: []const u8, func: *const fn (*MenuEntry, f64) void) void {
|
||||||
if (core.getEngineObject(TopBar)) |topbar| {
|
// if (core.getEngineObject(TopBar)) |topbar| {
|
||||||
topbar.addWindowsMenu(.{ .name = name, .ctx = ctx, .windowFunction = func }) catch {};
|
// topbar.addWindowsMenu(.{ .name = name, .ctx = ctx, .windowFunction = func }) catch {};
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
const core = @import("core");
|
const core = @import("core");
|
||||||
|
|
|
||||||
|
|
@ -370,38 +370,8 @@ pub fn preTick(self: *@This(), dt: f64) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tickServer(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 tickClient(self: *@This(), dt: f64) void {
|
pub fn tickClient(self: *@This(), dt: f64) void {
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ pub const PlatformInstance = struct {
|
||||||
return self.cursorEnabled;
|
return self.cursorEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setCursorVisible(self: @This(), visible: bool) void {
|
pub fn setCursorVisible(self: *@This(), visible: bool) void {
|
||||||
self.cursorEnabled = visible;
|
self.cursorEnabled = visible;
|
||||||
if (visible) {
|
if (visible) {
|
||||||
sdl3.showCursor();
|
sdl3.showCursor();
|
||||||
|
|
|
||||||
|
|
@ -315,10 +315,10 @@ pub const ParticleEmitter = struct {
|
||||||
const pva = self.generatePVA();
|
const pva = self.generatePVA();
|
||||||
|
|
||||||
const life = self.particleLife.getRange();
|
const life = self.particleLife.getRange();
|
||||||
try self.life.append(gParticleAllocator, .{ .current = life, .max = life });
|
try self.life.append(particleAllocator(), .{ .current = life, .max = life });
|
||||||
try self.particlesPVA.append(gParticleAllocator, pva);
|
try self.particlesPVA.append(particleAllocator(), pva);
|
||||||
try self.finals.append(gParticleAllocator, std.mem.zeroes(core.Mat));
|
try self.finals.append(particleAllocator(), std.mem.zeroes(core.Mat));
|
||||||
try self.size.append(gParticleAllocator, self.particleSizeSpawn.getRange());
|
try self.size.append(particleAllocator(), self.particleSizeSpawn.getRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn updateLife(self: *@This(), dt: f64) void {
|
fn updateLife(self: *@This(), dt: f64) void {
|
||||||
|
|
@ -391,14 +391,18 @@ pub const ParticleEmitter = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *@This()) void {
|
pub fn deinit(self: *@This()) void {
|
||||||
self.life.deinit(gParticleAllocator);
|
self.life.deinit(particleAllocator());
|
||||||
self.particlesPVA.deinit(gParticleAllocator);
|
self.particlesPVA.deinit(particleAllocator());
|
||||||
self.finals.deinit(gParticleAllocator);
|
self.finals.deinit(particleAllocator());
|
||||||
self.size.deinit(gParticleAllocator);
|
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 {
|
pub const ParticleSystem = struct {
|
||||||
particleArena: std.heap.ArenaAllocator,
|
particleArena: std.heap.ArenaAllocator,
|
||||||
|
|
@ -414,8 +418,6 @@ pub const ParticleSystem = struct {
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
};
|
};
|
||||||
|
|
||||||
gParticleAllocator = self.particleArena.allocator();
|
|
||||||
|
|
||||||
ParticleRandRangef.randomEngine = std.Random.DefaultPrng.init(0x1234);
|
ParticleRandRangef.randomEngine = std.Random.DefaultPrng.init(0x1234);
|
||||||
ParticleRandRangef.randomFunc = ParticleRandRangef.randomEngine.random();
|
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);
|
const fileMapping = try core.fs().loadFile(settings.mapName);
|
||||||
defer core.fs().unmap(fileMapping);
|
defer core.fs().unmap(fileMapping);
|
||||||
|
|
||||||
|
core.engine_log("loading map :{s}", .{settings.mapName});
|
||||||
|
|
||||||
var arena = std.heap.ArenaAllocator.init(baseAllocator);
|
var arena = std.heap.ArenaAllocator.init(baseAllocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
const alloc = arena.allocator();
|
const alloc = arena.allocator();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ lastUpdateFrame: u64 = 0,
|
||||||
arena: std.heap.ArenaAllocator,
|
arena: std.heap.ArenaAllocator,
|
||||||
strings: std.ArrayListUnmanaged([]u8) = .{},
|
strings: std.ArrayListUnmanaged([]u8) = .{},
|
||||||
|
|
||||||
|
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "game.EngineTool");
|
||||||
|
|
||||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||||
const self = try allocator.create(@This());
|
const self = try allocator.create(@This());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ lastUpdateFrame: u64 = 0,
|
||||||
arena: std.heap.ArenaAllocator,
|
arena: std.heap.ArenaAllocator,
|
||||||
bodyIds: std.ArrayList(physics.BodyId),
|
bodyIds: std.ArrayList(physics.BodyId),
|
||||||
|
|
||||||
|
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "extras.PhysicsObjectList");
|
||||||
|
|
||||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||||
const self = try allocator.create(@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,
|
selectedObjectToSpawn: ?core.Name = null,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ pub const RendererDebug = @import("debuggers/RendererDebug.zig");
|
||||||
pub const EngineTool = @import("debuggers/EngineTool.zig");
|
pub const EngineTool = @import("debuggers/EngineTool.zig");
|
||||||
pub const PhysicsObjectList = @import("debuggers/PhysicsObjectList.zig");
|
pub const PhysicsObjectList = @import("debuggers/PhysicsObjectList.zig");
|
||||||
pub const ParticleDebugger = @import("debuggers/ParticleDebugger.zig");
|
pub const ParticleDebugger = @import("debuggers/ParticleDebugger.zig");
|
||||||
|
pub const ModuleLoader = @import("debuggers/modulesLoader.zig");
|
||||||
|
|
||||||
pub const browser = @import("debuggers/fileBrowser.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 {
|
pub fn setGameTag(self: *@This(), gameName: []const u8, name: []const u8) void {
|
||||||
var n = core.MakeName(name);
|
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 {
|
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);
|
var gameName = core.MakeName(game);
|
||||||
|
|
||||||
if (self.gamesByTag.getPtr(tagName.handle())) |list| {
|
if (self.gamesByTag.getPtr(tagName.handle())) |list| {
|
||||||
for (list.items) |i| {
|
for (list.items, 0..) |i, j| {
|
||||||
if (i.gameName.eql(&gameName)) {
|
if (i.gameName.eql(&gameName)) {
|
||||||
list.swapRemove(i);
|
_ = list.swapRemove(j);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,7 @@ pub const PackerFS = struct {
|
||||||
self.lock.lock();
|
self.lock.lock();
|
||||||
defer self.lock.unlock();
|
defer self.lock.unlock();
|
||||||
|
|
||||||
|
std.debug.print("loading file: {s}", .{path});
|
||||||
var pathName = Name.Make(path);
|
var pathName = Name.Make(path);
|
||||||
if (self.fileHandlesByName.get(pathName.handle())) |fileNameHandle| {
|
if (self.fileHandlesByName.get(pathName.handle())) |fileNameHandle| {
|
||||||
// std.debug.print("{s} maps to index {d}\n", .{ path, 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| {
|
for (self.contentPaths.items) |contentPath| {
|
||||||
if (try self.loadFileDirect(contentPath, path)) |mapping| {
|
if (try self.loadFileDirect(contentPath, path)) |mapping| {
|
||||||
|
std.debug.print("loading directly: {s}, {s}", .{ contentPath, path });
|
||||||
return mapping;
|
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;
|
var gAllocator: std.mem.Allocator = undefined;
|
||||||
|
|
||||||
pub fn start_module(args: core.ModuleLoaderArgs) !void {
|
pub fn start_module(args: core.ModuleLoaderArgs) !void {
|
||||||
if (args.firstLoad) {
|
core.PatchOrCreateObject(extras.ModuleLoader, .{});
|
||||||
_ = core.createObject(ExternGameObject, .{}) catch {};
|
core.PatchOrCreateObject(extras.ObjectSystemSpawner, .{});
|
||||||
core.engine_logs("creating externgame");
|
core.PatchOrCreateObject(ExternGameObject, .{});
|
||||||
return;
|
core.PatchOrCreateObject(imgui.utils.ConsoleWindow, .{});
|
||||||
}
|
|
||||||
|
|
||||||
|
_ = args;
|
||||||
core.logDisplay("externGame", "accessing old object at {x} same object? {d}", .{ @intFromPtr(core.EngineObject(ExternGameObject).get()), @sizeOf(ExternGameObject) });
|
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 {
|
pub const BoxObject = struct {
|
||||||
|
|
@ -98,7 +88,6 @@ pub const ExternGameObject = struct {
|
||||||
pub const Slack = core.SlackStruct(@This(), 1024);
|
pub const Slack = core.SlackStruct(@This(), 1024);
|
||||||
|
|
||||||
allocator: std.mem.Allocator = undefined,
|
allocator: std.mem.Allocator = undefined,
|
||||||
consoleWindow: imgui.utils.ConsoleWindow = undefined,
|
|
||||||
tbMap: ?*bsp.maploader.TBMap = null,
|
tbMap: ?*bsp.maploader.TBMap = null,
|
||||||
physicsObjectsWindow: *extras.PhysicsObjectList = undefined,
|
physicsObjectsWindow: *extras.PhysicsObjectList = undefined,
|
||||||
fireTraceFilter: physics.IgnoreFixedBodiesFilter = .{},
|
fireTraceFilter: physics.IgnoreFixedBodiesFilter = .{},
|
||||||
|
|
@ -108,23 +97,16 @@ pub const ExternGameObject = struct {
|
||||||
clientLink: ?*net.Link = null,
|
clientLink: ?*net.Link = null,
|
||||||
|
|
||||||
recompiling: bool = false,
|
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,
|
firstTick: bool = true,
|
||||||
|
|
||||||
frameCount: u32 = 0,
|
|
||||||
|
|
||||||
fireInput: ?*core.ActionBinding = null,
|
fireInput: ?*core.ActionBinding = null,
|
||||||
altFireInput: ?*core.ActionBinding = null,
|
altFireInput: ?*core.ActionBinding = null,
|
||||||
reloadInput: ?*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 },
|
a: core.Vector2f = .{ .x = 1, .y = 4 },
|
||||||
b: core.Vector2f = .{ .x = 4, .y = 1 },
|
b: core.Vector2f = .{ .x = 4, .y = 1 },
|
||||||
|
|
@ -147,6 +129,11 @@ pub const ExternGameObject = struct {
|
||||||
try self.setupInputs();
|
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 {
|
pub fn setupInputs(self: *@This()) !void {
|
||||||
if (self.fireInput) |fireInput| {
|
if (self.fireInput) |fireInput| {
|
||||||
fireInput.deactivate();
|
fireInput.deactivate();
|
||||||
|
|
@ -159,29 +146,56 @@ pub const ExternGameObject = struct {
|
||||||
input.deactivate();
|
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) {
|
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.?.addKey(.@"9", .keyDown);
|
||||||
_ = self.reloadInput.?.data.addListener(self, onRequestReload);
|
_ = self.reloadInput.?.data.addListener(@This(), "onRequestReload", self);
|
||||||
}
|
}
|
||||||
self.reloadInput.?.activate();
|
self.reloadInput.?.activate();
|
||||||
|
|
||||||
if (self.fireInput == null) {
|
if (self.fireInput == null) {
|
||||||
self.fireInput = try core.ActionBinding.create(core.MakeName("fire"));
|
self.fireInput = try core.ActionBinding.create(core.MakeName("fire"));
|
||||||
self.fireInput.?.addKey(.Mouse1, .keyDown);
|
self.fireInput.?.addKey(.Mouse1, .keyDown);
|
||||||
_ = self.fireInput.?.data.addListener(self, onFire);
|
_ = self.fireInput.?.data.addListener(@This(), "onFire", self);
|
||||||
}
|
}
|
||||||
self.fireInput.?.activate();
|
self.fireInput.?.activate();
|
||||||
|
|
||||||
if (self.altFireInput == null) {
|
if (self.altFireInput == null) {
|
||||||
self.altFireInput = try core.ActionBinding.create(core.MakeName("altFire"));
|
self.altFireInput = try core.ActionBinding.create(core.MakeName("altFire"));
|
||||||
self.altFireInput.?.addKey(.Mouse3, .keyDown);
|
self.altFireInput.?.addKey(.Mouse3, .keyDown);
|
||||||
_ = self.altFireInput.?.data.addListener(self, onAltFire);
|
_ = self.altFireInput.?.data.addListener(@This(), "onAltFire", self);
|
||||||
}
|
}
|
||||||
self.altFireInput.?.activate();
|
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 {
|
self.setupInputs() catch {
|
||||||
core.engine_errs("Unable to setup inputs");
|
core.engine_errs("Unable to setup inputs");
|
||||||
};
|
};
|
||||||
|
|
@ -211,14 +225,12 @@ pub const ExternGameObject = struct {
|
||||||
const self = try Slack.create(allocator);
|
const self = try Slack.create(allocator);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.consoleWindow = imgui.utils.ConsoleWindow.init(allocator),
|
|
||||||
.particleDebugger = extras.ParticleDebugger.ParticleDebugger.init(),
|
.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.physicsObjectsWindow = try extras.PhysicsObjectList.create(self.allocator);
|
||||||
self.consoleWindow.setup();
|
|
||||||
|
|
||||||
try core.registerObject(BoxObject, "Box");
|
try core.registerObject(BoxObject, "Box");
|
||||||
try core.registerObjectAdvanced(BoxObject, "BoxSmoky", "createSmoky");
|
try core.registerObjectAdvanced(BoxObject, "BoxSmoky", "createSmoky");
|
||||||
|
|
@ -340,7 +352,15 @@ pub const ExternGameObject = struct {
|
||||||
self.recompiling = false;
|
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.?);
|
const self = core.cast(*@This(), ctx.?);
|
||||||
|
|
||||||
if (!self.recompiling) {
|
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));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
|
|
||||||
if (platform.context().isCursorEnabled()) {
|
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));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
|
|
||||||
if (platform.context().isCursorEnabled()) {
|
if (platform.context().isCursorEnabled()) {
|
||||||
|
|
@ -399,8 +419,6 @@ pub const ExternGameObject = struct {
|
||||||
.position = p,
|
.position = p,
|
||||||
};
|
};
|
||||||
self.spawnedEntities.append(self.allocator, core.get(extras.ObjectSystemSpawner).spawnObjectAt(posRot) orelse return) catch unreachable;
|
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 {
|
pub fn tick(self: *@This(), dt: f64) void {
|
||||||
const rctx = rend.context();
|
const rctx = rend.context();
|
||||||
_ = rctx;
|
_ = rctx;
|
||||||
|
|
||||||
_ = dt;
|
_ = dt;
|
||||||
|
//self.time += @floatCast(dt);
|
||||||
|
|
||||||
|
//core.debugSphere(.{ .y = 10 + std.math.sin(self.time) }, 5, .{});
|
||||||
|
|
||||||
if (core.getEngineObject(imgui.utils.TopBar)) |topbar| {
|
if (core.getEngineObject(imgui.utils.TopBar)) |topbar| {
|
||||||
topbar.menuOpen = platform.context().isCursorEnabled();
|
topbar.menuOpen = platform.context().isCursorEnabled();
|
||||||
|
|
@ -424,8 +446,6 @@ pub const ExternGameObject = struct {
|
||||||
self.firstTick = false;
|
self.firstTick = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
imgui.utils.structDebugWindow(self);
|
|
||||||
|
|
||||||
if (self.recompiling) {
|
if (self.recompiling) {
|
||||||
if (ig.begin("recompiling", null, .{})) {
|
if (ig.begin("recompiling", null, .{})) {
|
||||||
ig.textf("recompiling...", .{});
|
ig.textf("recompiling...", .{});
|
||||||
|
|
@ -434,6 +454,10 @@ pub const ExternGameObject = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platform.context().isCursorEnabled()) {
|
if (platform.context().isCursorEnabled()) {
|
||||||
|
// imgui.utils.structDebugWindow(self);
|
||||||
|
|
||||||
|
// imgui.utils.structDebugWindow(core.get(rend.renderer.Renderer));
|
||||||
|
|
||||||
if (ig.begin("meh", null, .{})) {
|
if (ig.begin("meh", null, .{})) {
|
||||||
// if (ig.checkbox("move lights ", 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("- 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.textFmt("- movingLight checkbox makes the light stop moving with you", .{}) catch return;
|
||||||
|
|
||||||
|
ig.textf("lmao", .{});
|
||||||
|
|
||||||
if (ig.smallButton("reload map")) {
|
if (ig.smallButton("reload map")) {
|
||||||
self.loadMap2() catch unreachable;
|
self.loadMap2() catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
@ -531,7 +557,6 @@ pub const ExternGameObject = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.spawnedEntities.deinit(self.allocator);
|
self.spawnedEntities.deinit(self.allocator);
|
||||||
self.consoleWindow.deinit();
|
|
||||||
self.physicsObjectsWindow.destroy();
|
self.physicsObjectsWindow.destroy();
|
||||||
self.allocator.destroy(Slack.fromPtr(self));
|
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_skybox"));
|
||||||
try rendererDebug.skyboxes.append(rendererDebug.allocator, core.MakeName("t_dark_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 core.getEngineObject(core.GameObjectSystem).?.registerObject("foxObject", FoxObject);
|
||||||
|
|
||||||
try assets.loadList(assetReferences);
|
try assets.loadList(assetReferences);
|
||||||
|
|
@ -300,14 +289,14 @@ fn beginPlay(p: ?*anyopaque) void {
|
||||||
fn _beginPlay(self: *@This()) !void {
|
fn _beginPlay(self: *@This()) !void {
|
||||||
const exitInput = try core.ActionBinding.create(core.MakeName("exit"));
|
const exitInput = try core.ActionBinding.create(core.MakeName("exit"));
|
||||||
exitInput.addKey(.escape, .keyDown);
|
exitInput.addKey(.escape, .keyDown);
|
||||||
_ = exitInput.data.addListener(null, onExit);
|
_ = exitInput.data.addListener(@This(), "onExit", self);
|
||||||
exitInput.activate();
|
exitInput.activate();
|
||||||
|
|
||||||
{
|
{
|
||||||
const inp = try core.ActionBinding.create(core.MakeName("slow"));
|
const inp = try core.ActionBinding.create(core.MakeName("slow"));
|
||||||
inp.addKey(.lshift, .keyDown);
|
inp.addKey(.lshift, .keyDown);
|
||||||
inp.addKey(.lshift, .keyUp);
|
inp.addKey(.lshift, .keyUp);
|
||||||
_ = inp.data.addListener(self, slowDown);
|
_ = inp.data.addListener(@This(), "slowDown", self);
|
||||||
inp.activate();
|
inp.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,7 +311,7 @@ fn _beginPlay(self: *@This()) !void {
|
||||||
moveInput.addKey(.d, 1.0, .x);
|
moveInput.addKey(.d, 1.0, .x);
|
||||||
moveInput.addKey(.a, -1.0, .x);
|
moveInput.addKey(.a, -1.0, .x);
|
||||||
|
|
||||||
_ = moveInput.data.addListener(self, onMove);
|
_ = moveInput.data.addListener(@This(), "onMove", self);
|
||||||
moveInput.activate();
|
moveInput.activate();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -330,7 +319,7 @@ fn _beginPlay(self: *@This()) !void {
|
||||||
i.addKey(.f, 1.0);
|
i.addKey(.f, 1.0);
|
||||||
i.addKey(.v, -1.0);
|
i.addKey(.v, -1.0);
|
||||||
|
|
||||||
_ = i.data.addListener(self, distanceMove);
|
_ = i.data.addListener(@This(), "distanceMove", self);
|
||||||
i.activate();
|
i.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -339,47 +328,47 @@ fn _beginPlay(self: *@This()) !void {
|
||||||
verticalInput.addKey(.e, 1.0);
|
verticalInput.addKey(.e, 1.0);
|
||||||
verticalInput.addKey(.q, -1.0);
|
verticalInput.addKey(.q, -1.0);
|
||||||
|
|
||||||
_ = verticalInput.data.addListener(self, verticalMovement);
|
_ = verticalInput.data.addListener(@This(), "verticalMovement", self);
|
||||||
verticalInput.activate();
|
verticalInput.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const mouseLook = try core.Axis2dBinding.create(core.MakeName("mouseLook"));
|
const mouseLook = try core.Axis2dBinding.create(core.MakeName("mouseLook"));
|
||||||
mouseLook.enableMouseRelative();
|
mouseLook.enableMouseRelative();
|
||||||
_ = mouseLook.data.addListener(self, onMouseLook);
|
_ = mouseLook.data.addListener(@This(), "onMouseLook", self);
|
||||||
mouseLook.activate();
|
mouseLook.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const shaderReload = try core.ActionBinding.create(core.MakeName("shaderReload"));
|
const shaderReload = try core.ActionBinding.create(core.MakeName("shaderReload"));
|
||||||
shaderReload.addKey(.r, .keyDown);
|
shaderReload.addKey(.r, .keyDown);
|
||||||
_ = shaderReload.data.addListener(self, onShaderReload);
|
_ = shaderReload.data.addListener(@This(), "onShaderReload", self);
|
||||||
shaderReload.activate();
|
shaderReload.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const input = try core.ActionBinding.create(core.MakeName("toggleDoom"));
|
const input = try core.ActionBinding.create(core.MakeName("toggleDoom"));
|
||||||
input.addKey(.f2, .keyDown);
|
input.addKey(.f2, .keyDown);
|
||||||
_ = input.data.addListener(self, toggleDoom);
|
_ = input.data.addListener(@This(), "toggleDoom", self);
|
||||||
input.activate();
|
input.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const input = try core.ActionBinding.create(core.MakeName("toggleMouseLook"));
|
const input = try core.ActionBinding.create(core.MakeName("toggleMouseLook"));
|
||||||
input.addKey(.t, .keyDown);
|
input.addKey(.t, .keyDown);
|
||||||
_ = input.data.addListener(self, toggleMouseLook);
|
_ = input.data.addListener(@This(), "toggleMouseLook", self);
|
||||||
input.activate();
|
input.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.updateMouseLook();
|
self.updateMouseLook();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn game_endPlay(p: ?*anyopaque) void {
|
pub fn game_endPlay(p: ?*anyopaque) void {
|
||||||
const self = core.cast(@This(), p);
|
const self = core.cast(*@This(), p.?);
|
||||||
_ = self;
|
_ = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onMouseLook(ctx: ?*anyopaque, axis: core.Vector2f) void {
|
pub fn onMouseLook(ctx: ?*anyopaque, axis: core.Vector2f) void {
|
||||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
|
|
||||||
if (self.inputEnabled) {
|
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));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
_ = action;
|
_ = 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));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
_ = action;
|
_ = action;
|
||||||
|
|
||||||
|
|
@ -409,13 +398,13 @@ fn toggleMouseLook(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||||
self.updateMouseLook();
|
self.updateMouseLook();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn updateMouseLook(self: *@This()) void {
|
pub fn updateMouseLook(self: *@This()) void {
|
||||||
self.fpcamera.mouseLookEnabled = self.mouseLook;
|
self.fpcamera.mouseLookEnabled = self.mouseLook;
|
||||||
platform.setMouseRelativeMode(self.mouseLook);
|
platform.setMouseRelativeMode(self.mouseLook);
|
||||||
// platform.setImguiVisible(!self.mouseLook);
|
// platform.setImguiVisible(!self.mouseLook);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn onShaderReload(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
pub fn onShaderReload(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||||
_ = ctx;
|
_ = ctx;
|
||||||
_ = action;
|
_ = 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));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
|
|
||||||
if (action == .keyUp) {
|
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));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
self.centerDistMove = axis;
|
self.centerDistMove = axis;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cameraRotate(ctx: ?*anyopaque, axis: f32) void {
|
pub fn verticalMovement(ctx: ?*anyopaque, axis: f32) void {
|
||||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
|
||||||
self.rotateAxis = axis;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn verticalMovement(ctx: ?*anyopaque, axis: f32) void {
|
|
||||||
const self: *@This() = @ptrCast(@alignCast(ctx));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
self.verticalMove = axis;
|
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));
|
const self: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
self.moveVector = .{ .x = axis.x, .z = axis.y, .y = 0.0 };
|
self.moveVector = .{ .x = axis.x, .z = axis.y, .y = 0.0 };
|
||||||
}
|
}
|
||||||
|
|
@ -470,28 +454,6 @@ pub fn getMouseMovement(self: *@This()) core.Vector2f {
|
||||||
return rv;
|
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 {
|
pub fn tick(self: *@This(), dt: f64) void {
|
||||||
const fdt: f32 = @floatCast(dt);
|
const fdt: f32 = @floatCast(dt);
|
||||||
|
|
||||||
|
|
@ -515,13 +477,6 @@ pub fn tick(self: *@This(), dt: f64) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fpcamera.resolve();
|
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 {
|
pub fn deinit(self: *@This()) void {
|
||||||
|
|
@ -531,7 +486,6 @@ pub fn deinit(self: *@This()) void {
|
||||||
self.fpcamera.destroy();
|
self.fpcamera.destroy();
|
||||||
self.engineTool.destroy();
|
self.engineTool.destroy();
|
||||||
|
|
||||||
// self.objectSpawner.destroy();
|
|
||||||
// self.videoplayer.destroy();
|
// self.videoplayer.destroy();
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue