lots of memory tracking in the game now
This commit is contained in:
parent
99c11b8d28
commit
ab184d5a33
|
|
@ -264,18 +264,32 @@ pub fn addUntrackedAllocation(self: *@This(), allocatedSize: usize) void {
|
||||||
self.lock.lock();
|
self.lock.lock();
|
||||||
self.untrackedAllocationsCount += 1;
|
self.untrackedAllocationsCount += 1;
|
||||||
self.untrackedAllocationsSize += allocatedSize;
|
self.untrackedAllocationsSize += allocatedSize;
|
||||||
self.totalAllocSize += allocatedSize;
|
|
||||||
|
if (self.timeline) |*timeline| {
|
||||||
|
timeline.pushAlloc(self.stackCompactor.?, 0, allocatedSize);
|
||||||
|
}
|
||||||
|
|
||||||
self.lock.unlock();
|
self.lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn removeUntrackedAllocation(self: *@This(), allocatedSize: usize) void {
|
pub fn removeUntrackedAllocation(self: *@This(), allocatedSize: usize) void {
|
||||||
self.lock.lock();
|
self.lock.lock();
|
||||||
self.totalAllocSize -= allocatedSize;
|
|
||||||
self.untrackedAllocationsCount -= 1;
|
self.untrackedAllocationsCount -= 1;
|
||||||
self.untrackedAllocationsSize -= allocatedSize;
|
self.untrackedAllocationsSize -= allocatedSize;
|
||||||
self.lock.unlock();
|
self.lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getTotalMemoryUsed(self: *@This()) usize {
|
||||||
|
return self.totalAllocSize + self.untrackedAllocationsSize + self.getTrackerUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getTrackerUsage(self: *@This()) usize {
|
||||||
|
if (self.timeline) |timeline| {
|
||||||
|
return timeline.events.capacity() + self.stackCompactor.?.stackArena.usage();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
var gMemTracker: ?*@This() = null;
|
var gMemTracker: ?*@This() = null;
|
||||||
|
|
||||||
pub const SetupSettings = struct {
|
pub const SetupSettings = struct {
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,11 @@ pub const HandlerError = error{
|
||||||
EventIgnored,
|
EventIgnored,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const SingleFn = *const fn (NodeHandle, ?*anyopaque) HandlerError!void;
|
pub const SingleFn = *const fn (*papyrus.Context, NodeHandle, ?*anyopaque) HandlerError!void;
|
||||||
pub const PressedFn = *const fn (NodeHandle, PressedType, ?*anyopaque) HandlerError!void;
|
pub const PressedFn = *const fn (*papyrus.Context, NodeHandle, PressedType, ?*anyopaque) HandlerError!void;
|
||||||
|
|
||||||
const Listener = struct {
|
const Listener = struct {
|
||||||
|
ctx: *papyrus.Context,
|
||||||
node: NodeHandle,
|
node: NodeHandle,
|
||||||
event: Type,
|
event: Type,
|
||||||
context: ?*anyopaque,
|
context: ?*anyopaque,
|
||||||
|
|
@ -99,6 +100,7 @@ const Listener = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
const PressedListener = struct {
|
const PressedListener = struct {
|
||||||
|
ctx: *papyrus.Context,
|
||||||
node: NodeHandle,
|
node: NodeHandle,
|
||||||
keycode: Key,
|
keycode: Key,
|
||||||
event: PressedType,
|
event: PressedType,
|
||||||
|
|
@ -109,6 +111,7 @@ const PressedListener = struct {
|
||||||
|
|
||||||
pub fn installMouseOverEventAdvanced(
|
pub fn installMouseOverEventAdvanced(
|
||||||
self: *@This(),
|
self: *@This(),
|
||||||
|
ctx: *papyrus.Context,
|
||||||
node: NodeHandle,
|
node: NodeHandle,
|
||||||
event: Type,
|
event: Type,
|
||||||
context: ?*anyopaque,
|
context: ?*anyopaque,
|
||||||
|
|
@ -118,6 +121,7 @@ pub fn installMouseOverEventAdvanced(
|
||||||
const allocator = self.arena.allocator();
|
const allocator = self.arena.allocator();
|
||||||
|
|
||||||
const listener: Listener = .{
|
const listener: Listener = .{
|
||||||
|
.ctx = ctx,
|
||||||
.node = node,
|
.node = node,
|
||||||
.event = event,
|
.event = event,
|
||||||
.context = context,
|
.context = context,
|
||||||
|
|
@ -136,19 +140,20 @@ pub fn installMouseOverEventAdvanced(
|
||||||
|
|
||||||
pub fn installMouseOverEvent(
|
pub fn installMouseOverEvent(
|
||||||
self: *@This(),
|
self: *@This(),
|
||||||
|
ctx: *papyrus.Context,
|
||||||
node: NodeHandle,
|
node: NodeHandle,
|
||||||
event: Type,
|
event: Type,
|
||||||
context: ?*anyopaque,
|
context: ?*anyopaque,
|
||||||
eventFn: SingleFn,
|
eventFn: SingleFn,
|
||||||
) !void {
|
) !void {
|
||||||
try installMouseOverEventAdvanced(self, node, event, context, eventFn, false);
|
try installMouseOverEventAdvanced(self, ctx, node, event, context, eventFn, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pushMouseOverEvent(self: *@This(), node: NodeHandle, event: Type) HandlerError!void {
|
pub fn pushMouseOverEvent(self: *@This(), node: NodeHandle, event: Type) HandlerError!void {
|
||||||
if (self.inputEvents.get(node)) |listeners| {
|
if (self.inputEvents.get(node)) |listeners| {
|
||||||
for (listeners.items) |listener| {
|
for (listeners.items) |listener| {
|
||||||
if (listener.event == event) {
|
if (listener.event == event) {
|
||||||
try listener.eventFn(node, listener.context);
|
try listener.eventFn(listener.ctx, node, listener.context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,8 +169,18 @@ pub fn pushPressedEvent(self: *@This(), node: NodeHandle, event: PressedType, ke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn installOnPressedEventAdvanced(self: *@This(), node: NodeHandle, event: PressedType, keycode: Key, context: ?*anyopaque, eventFn: PressedFn, innate: bool) !void {
|
pub fn installOnPressedEventAdvanced(
|
||||||
|
self: *@This(),
|
||||||
|
ctx: *papyrus.Context,
|
||||||
|
node: NodeHandle,
|
||||||
|
event: PressedType,
|
||||||
|
keycode: Key,
|
||||||
|
context: ?*anyopaque,
|
||||||
|
eventFn: PressedFn,
|
||||||
|
innate: bool,
|
||||||
|
) !void {
|
||||||
const listener: PressedListener = .{
|
const listener: PressedListener = .{
|
||||||
|
.ctx = ctx,
|
||||||
.node = node,
|
.node = node,
|
||||||
.event = event,
|
.event = event,
|
||||||
.keycode = keycode,
|
.keycode = keycode,
|
||||||
|
|
|
||||||
|
|
@ -733,11 +733,11 @@ pub const Context = struct {
|
||||||
self.get(button).text = LocText.fromUtf8(t);
|
self.get(button).text = LocText.fromUtf8(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
try self.events.installMouseOverEventAdvanced(button, .mouseOver, null, NodeProperty_Button.buttonMouseOverListener, true);
|
try self.events.installMouseOverEventAdvanced(self, button, .mouseOver, null, NodeProperty_Button.buttonMouseOverListener, true);
|
||||||
try self.events.installMouseOverEventAdvanced(button, .mouseOff, null, NodeProperty_Button.buttonMouseOffListener, true);
|
try self.events.installMouseOverEventAdvanced(self, button, .mouseOff, null, NodeProperty_Button.buttonMouseOffListener, true);
|
||||||
|
|
||||||
try self.events.installOnPressedEventAdvanced(button, .onPressed, .Mouse1, null, NodeProperty_Button.buttonOnPressedEvent, true);
|
try self.events.installOnPressedEventAdvanced(self, button, .onPressed, .Mouse1, null, NodeProperty_Button.buttonOnPressedEvent, true);
|
||||||
try self.events.installOnPressedEventAdvanced(button, .onReleased, .Mouse1, null, NodeProperty_Button.buttonOnPressedEvent, true);
|
try self.events.installOnPressedEventAdvanced(self, button, .onReleased, .Mouse1, null, NodeProperty_Button.buttonOnPressedEvent, true);
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ font: papyrus.Font,
|
||||||
buttonStyle: ButtonStyle = .{},
|
buttonStyle: ButtonStyle = .{},
|
||||||
disabled: bool = false,
|
disabled: bool = false,
|
||||||
buttonState: ButtonState = .Normal,
|
buttonState: ButtonState = .Normal,
|
||||||
|
|
||||||
// documentation:
|
// documentation:
|
||||||
// Each PapyrusNode has a common set of fields, these are defined in PapyrusNode
|
// Each PapyrusNode has a common set of fields, these are defined in PapyrusNode
|
||||||
//
|
//
|
||||||
|
|
@ -118,24 +117,21 @@ pub fn addToDrawList(dlb: DrawListBuilder) !void {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buttonMouseOverListener(node: papyrus.NodeHandle, _: ?*anyopaque) papyrus.HandlerError!void {
|
pub fn buttonMouseOverListener(ctx: *papyrus.Context, node: papyrus.NodeHandle, _: ?*anyopaque) papyrus.HandlerError!void {
|
||||||
var ctx = papyrus.getContext();
|
|
||||||
var btn = ctx.getButton(node);
|
var btn = ctx.getButton(node);
|
||||||
if (btn.disabled == false) {
|
if (btn.disabled == false) {
|
||||||
btn.buttonState = .Hovered;
|
btn.buttonState = .Hovered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buttonMouseOffListener(node: papyrus.NodeHandle, _: ?*anyopaque) papyrus.HandlerError!void {
|
pub fn buttonMouseOffListener(ctx: *papyrus.Context, node: papyrus.NodeHandle, _: ?*anyopaque) papyrus.HandlerError!void {
|
||||||
var ctx = papyrus.getContext();
|
|
||||||
var btn = ctx.getButton(node);
|
var btn = ctx.getButton(node);
|
||||||
if (btn.disabled == false) {
|
if (btn.disabled == false) {
|
||||||
btn.buttonState = .Normal;
|
btn.buttonState = .Normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buttonOnPressedEvent(node: papyrus.NodeHandle, eventType: papyrus.PressedType, _: ?*anyopaque) papyrus.HandlerError!void {
|
pub fn buttonOnPressedEvent(ctx: *papyrus.Context, node: papyrus.NodeHandle, eventType: papyrus.PressedType, _: ?*anyopaque) papyrus.HandlerError!void {
|
||||||
var ctx = papyrus.getContext();
|
|
||||||
var btn = ctx.getButton(node);
|
var btn = ctx.getButton(node);
|
||||||
|
|
||||||
if (eventType == .onPressed) {
|
if (eventType == .onPressed) {
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,7 @@ pub const PhysicsRuntime = struct {
|
||||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||||
const self = try allocator.create(@This());
|
const self = try allocator.create(@This());
|
||||||
try zphysics.init(std.heap.c_allocator, .{});
|
try zphysics.init(std.heap.c_allocator, .{});
|
||||||
|
//try zphysics.init(allocator, .{});
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||||
|
|
||||||
const device = rend.context().device;
|
const device = rend.context().device;
|
||||||
|
|
||||||
|
const MaxParticleCount = core.configVar(u32, "rend.particles.maxCount", 200_000);
|
||||||
|
|
||||||
self.ssboScene = device.createGPUBuffer(&.{
|
self.ssboScene = device.createGPUBuffer(&.{
|
||||||
.usage = .{
|
.usage = .{
|
||||||
.bufferusageGraphicsStorageRead = true,
|
.bufferusageGraphicsStorageRead = true,
|
||||||
|
|
@ -125,8 +127,6 @@ pub fn destroy(self: *@This()) void {
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MaxParticleCount = 10_000_000;
|
|
||||||
|
|
||||||
const assets = @import("assets");
|
const assets = @import("assets");
|
||||||
const core = @import("core");
|
const core = @import("core");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,15 @@ pub fn tick(self: *@This(), dt: f64) void {
|
||||||
tracker.eventsCount - self.lastEventsCount,
|
tracker.eventsCount - self.lastEventsCount,
|
||||||
}) catch {};
|
}) catch {};
|
||||||
|
|
||||||
|
self.screenContext.pushDebugText("untracked allocations: {d:.4} MiB in {d} allocations", .{
|
||||||
|
@as(f64, @floatFromInt(tracker.untrackedAllocationsSize)) / 1024 / 1024,
|
||||||
|
tracker.untrackedAllocationsCount,
|
||||||
|
}) catch {};
|
||||||
|
|
||||||
|
self.screenContext.pushDebugText("total {d:.4} MiB", .{
|
||||||
|
@as(f64, @floatFromInt(tracker.getTotalMemoryUsed())) / 1024 / 1024,
|
||||||
|
}) catch {};
|
||||||
|
|
||||||
self.lastEventsCount = tracker.eventsCount;
|
self.lastEventsCount = tracker.eventsCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -371,6 +371,10 @@ pub const TextRenderer = struct {
|
||||||
item.destroy(self.allocator);
|
item.destroy(self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (self.deadList.items) |item| {
|
||||||
|
item.destroy(self.allocator);
|
||||||
|
}
|
||||||
|
|
||||||
self.geo.destroy();
|
self.geo.destroy();
|
||||||
self.linearBuffers.deinit(self.allocator);
|
self.linearBuffers.deinit(self.allocator);
|
||||||
self.assignedBuffers.deinit(self.allocator);
|
self.assignedBuffers.deinit(self.allocator);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ pub const BumpArena = struct {
|
||||||
smallBumpOffset: usize = 0,
|
smallBumpOffset: usize = 0,
|
||||||
pageIndex: usize = 0,
|
pageIndex: usize = 0,
|
||||||
|
|
||||||
|
allocatedBytes: usize = 0,
|
||||||
|
|
||||||
backing: std.mem.Allocator,
|
backing: std.mem.Allocator,
|
||||||
small: SmallAllocPages,
|
small: SmallAllocPages,
|
||||||
large: std.heap.ArenaAllocator,
|
large: std.heap.ArenaAllocator,
|
||||||
|
|
@ -22,6 +24,10 @@ pub const BumpArena = struct {
|
||||||
.remap = std.mem.Allocator.noRemap,
|
.remap = std.mem.Allocator.noRemap,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn usage(self: *@This()) usize {
|
||||||
|
return self.allocatedBytes;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init(backing: std.mem.Allocator) !@This() {
|
pub fn init(backing: std.mem.Allocator) !@This() {
|
||||||
return .{
|
return .{
|
||||||
.backing = backing,
|
.backing = backing,
|
||||||
|
|
@ -52,6 +58,8 @@ pub const BumpArena = struct {
|
||||||
self.mutex.lock();
|
self.mutex.lock();
|
||||||
defer self.mutex.unlock();
|
defer self.mutex.unlock();
|
||||||
|
|
||||||
|
self.allocatedBytes += len;
|
||||||
|
|
||||||
if (len > 4096) {
|
if (len > 4096) {
|
||||||
return self.largeAllocator().vtable.alloc(self.largeAllocator().ptr, len, ptr_align, ret_addr);
|
return self.largeAllocator().vtable.alloc(self.largeAllocator().ptr, len, ptr_align, ret_addr);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ pub const ExternGameObject = struct {
|
||||||
defer settings.release();
|
defer settings.release();
|
||||||
try physics.addShape("ph_small_box", settings);
|
try physics.addShape("ph_small_box", settings);
|
||||||
|
|
||||||
if (false) {
|
if (true) {
|
||||||
const ctx = ui.getScreen();
|
const ctx = ui.getScreen();
|
||||||
const panel2 = try ctx.addPanel(.{});
|
const panel2 = try ctx.addPanel(.{});
|
||||||
ctx.drawDebug = true;
|
ctx.drawDebug = true;
|
||||||
|
|
@ -138,14 +138,18 @@ pub const ExternGameObject = struct {
|
||||||
//ctx.get(panel2).anchor = .TopRight;
|
//ctx.get(panel2).anchor = .TopRight;
|
||||||
// ctx.get(panel2).fill = .FillY; todo, this is a bug. why.
|
// ctx.get(panel2).fill = .FillY; todo, this is a bug. why.
|
||||||
ctx.get(panel2).pos = .{ .x = 900, .y = 200 };
|
ctx.get(panel2).pos = .{ .x = 900, .y = 200 };
|
||||||
ctx.get(panel2).size = .{ .x = 300, .y = 400 };
|
ctx.get(panel2).size = .{ .x = 300, .y = 500 };
|
||||||
ctx.get(panel2).style.backgroundColor = ui.ModernStyle.GreyDark;
|
ctx.get(panel2).style.backgroundColor = ui.ModernStyle.GreyDark;
|
||||||
ctx.getPanel(panel2).titleColor = ui.ModernStyle.GreyDark;
|
ctx.getPanel(panel2).titleColor = ui.ModernStyle.GreyDark;
|
||||||
|
ctx.getPanel(panel2).layoutMode = .Vertical;
|
||||||
|
|
||||||
// add some text to this panel
|
// add some text to this panel
|
||||||
const text = try ctx.addText(panel2, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
|
const text = try ctx.addText(panel2, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
|
||||||
ctx.get(text).pos = .{ .x = 2, .y = 2 };
|
ctx.get(text).pos = .{ .x = 2, .y = 2 };
|
||||||
ctx.get(text).size = ctx.get(panel2).size.sub(.{ .x = 4, .y = 36 });
|
ctx.get(text).size = .{ .x = 296, .y = 300 };
|
||||||
|
|
||||||
|
const btn = try ctx.addButton(panel2, "select file...");
|
||||||
|
_ = btn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue