updates to engine time and seemingly bugs are fixed

This commit is contained in:
peterino2 2026-01-03 16:35:31 -08:00
parent 81aaaa81b7
commit 9f9f40abd9
6 changed files with 16 additions and 10 deletions

View File

@ -21,7 +21,8 @@ pub fn tick(self: *@This(), dt: f64) void {
} }
pub fn deinit(self: *@This()) void { pub fn deinit(self: *@This()) void {
self.allocator.destroy(self); // Engine handles memory deallocation
_ = self;
} }
pub fn main() anyerror!void { pub fn main() anyerror!void {

View File

@ -172,7 +172,7 @@ pub const packer = @import("packer");
pub const StackCompactor = stacks.StackCompactor; pub const StackCompactor = stacks.StackCompactor;
var staticsInitialized = false; pub var staticsInitialized = false;
var gEngine: *Engine = undefined; var gEngine: *Engine = undefined;
pub const PackerFS = packer.PackerFS; pub const PackerFS = packer.PackerFS;
var gPackerFS: *PackerFS = undefined; var gPackerFS: *PackerFS = undefined;
@ -274,8 +274,6 @@ pub fn maybeInitPackerFs(allocator: std.mem.Allocator) !void {
} }
pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void { pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void {
staticsInitialized = true;
if (map.get("utility")) |x| { if (map.get("utility")) |x| {
if (x.boolean == true) { if (x.boolean == true) {
engine_logs("utility mode - no gui"); engine_logs("utility mode - no gui");
@ -299,6 +297,8 @@ pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.All
gEngine = try allocator.create(Engine); gEngine = try allocator.create(Engine);
gEngine.* = try Engine.init(allocator); gEngine.* = try Engine.init(allocator);
staticsInitialized = true;
_ = try createObject(ModuleLoader, .{}); _ = try createObject(ModuleLoader, .{});
try console.start(); try console.start();

View File

@ -181,7 +181,7 @@ pub const Engine = struct {
if (comptime core.BuildOption("static_build")) { if (comptime core.BuildOption("static_build")) {
newObjectPtr = @ptrCast(@alignCast((try self.allocator.alignedAlloc(u8, .@"16", vtable.typeSize)))); newObjectPtr = @ptrCast(@alignCast((try self.allocator.alignedAlloc(u8, .@"16", vtable.typeSize))));
} else { } else {
newObjectPtr = @ptrCast(@alignCast(&(try self.allocator.create(DebugSlack)).slack)); newObjectPtr = @ptrCast(@alignCast((try self.allocator.create(DebugSlack))));
} }
try vtable.init_func(newObjectPtr, self.allocator, true); try vtable.init_func(newObjectPtr, self.allocator, true);
@ -373,6 +373,7 @@ pub const Engine = struct {
} }
fn destroyObject(self: *@This(), item: EngineObjectRef) void { fn destroyObject(self: *@This(), item: EngineObjectRef) void {
core.engine_log("destroying object {s}", .{item.vtable.typeName});
if (item.vtable.deinit_func) |deinitFn| { if (item.vtable.deinit_func) |deinitFn| {
deinitFn(item.ptr); deinitFn(item.ptr);
} }

View File

@ -5,8 +5,12 @@ const pscopes = core.algorithm.pscopes;
// returns time since engine started in nanoseconds // returns time since engine started in nanoseconds
pub fn getEngineTime() f64 { pub fn getEngineTime() f64 {
const read = core.getEngine().rootTimer.read(); if (core.staticsInitialized) {
return @as(f64, @floatFromInt(read)) / std.time.ns_per_s; const read = core.getEngine().rootTimer.read();
return @as(f64, @floatFromInt(read)) / std.time.ns_per_s;
}
return 0;
} }
// returns a pscopes.TimingScope for the current time. // returns a pscopes.TimingScope for the current time.

View File

@ -108,8 +108,8 @@ pub fn startEngine(spec: *core.SpecVariantMap) bool {
run() catch return false; run() catch return false;
if (core.getEngine().shutdownModuleFunction) |f| { if (core.getEngine().shutdownModuleFunction) |shutdownFunc| {
f(); shutdownFunc();
} else { } else {
core.shutdown_module(allocator); core.shutdown_module(allocator);
} }

View File

@ -258,7 +258,7 @@ fn displayInstructions(self: *@This()) void {
pub fn deinit(self: *@This()) void { pub fn deinit(self: *@This()) void {
self.animationStore.destroy(); self.animationStore.destroy();
self.allocator.destroy(self); // Engine handles memory deallocation
} }
fn copyRecursiveDir( fn copyRecursiveDir(