diff --git a/scripts/base.js b/scripts/base.js index 5489323..7ff195c 100644 --- a/scripts/base.js +++ b/scripts/base.js @@ -1176,6 +1176,13 @@ Object.defineProperty(Array.prototype, "mirrored", { }, }); +Object.defineProperty(Array.prototype, "forEachRight", { + value: function(fn) { + for (var i = this.length-1; i >= 0; i--) + fn(this[i], i); + } +}); + Math.lerp = vector.lerp; Math.gcd = vector.gcd; Math.lcm = vector.lcm; diff --git a/scripts/entity.js b/scripts/entity.js index 25d87e2..599b844 100644 --- a/scripts/entity.js +++ b/scripts/entity.js @@ -1,22 +1,5 @@ globalThis.entityreport = {}; -var timer_manager = {}; -timer_manager.timers = new Map(); -timer_manager.make_timer = function(obj, fn, seconds) -{ - var timer = os.make_timer(_ => { - fn(); - this.timers.delete(obj); - }); - - this.timers.set(obj, timer); - return _ => { - if (this.timers.has(obj)) { - - } - }; -} - function obj_unique_name(name, obj) { name = name.replaceAll(".", "_"); if (!(name in obj)) return name; @@ -365,8 +348,7 @@ var entity = { kill() { if (this.__kill) return; this.__kill = true; - - this.timers.forEach(x => x()); + this.timers.forEachRight(x => x()); delete this.timers; Event.rm_obj(this); input.do_uncontrol(this); diff --git a/scripts/profile.js b/scripts/profile.js index c2745e7..06eb9e6 100644 --- a/scripts/profile.js +++ b/scripts/profile.js @@ -337,29 +337,23 @@ var classes = ["gameobject", "transform", "dsp_node", "texture", "font", "warp_g var get_snapshot = function() { var snap = profile.snapshot; - snap.actors ??= {}; - Object.assign(snap.actors, actor.__stats()); - snap.memory ??= {}; - Object.assign(snap.memory, os.mem()); + snap.actors = actor.__stats(); + snap.memory = os.mem(); snap.memory.textures = game.texture.total_size(); snap.memory.texture_vram = game.texture.total_vram(); - snap.rusage ??= {}; - var rusage = os.rusage(); - rusage.ru_maxrss *= 1024; // delivered in KB; convert here to B - Object.assign(snap.rusage, rusage); + snap.rusage = os.rusage(); + snap.rusage.ru_maxrss *= 1024; // delivered in KB; convert here to B - snap.mallinfo ??= {}; - Object.assign(snap.mallinfo, os.mallinfo()); - - snap.particles ??= {}; - Object.assign(snap.particles, stat_emitters()); + snap.mallinfo = os.mallinfo(); + snap.particles = stat_emitters(); snap.obj ??= {}; for (var i of classes) { var proto = globalThis[`${i}_proto`]; if (!proto) continue; snap.obj[i] = proto._count(); + snap.obj[i + "_mem"] = proto._count() * proto.memsize(); } } diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index c5c2bbd..125ea19 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -14,6 +14,8 @@ #include "datastream.h" #include "sound.h" #include "stb_ds.h" +#define STB_RECT_PACK_IMPLEMENTATION +#include "stb_rect_pack.h" #include "string.h" #include "window.h" #include "spline.h" @@ -3363,7 +3365,38 @@ JSC_CCALL(os_skin_calculate, skin_calculate(sk); ) +JSC_CCALL(os_rectpack, + int width = js2number(argv[0]); + int height = js2number(argv[1]); + int num = js_arrlen(argv[2]); + stbrp_context ctx[1]; + stbrp_rect rects[num]; + + for (int i = 0; i < num; i++) { + HMM_Vec2 wh = js2vec2(js_getpropidx(argv[2], i)); + rects[i].w = wh.x; + rects[i].h = wh.y; + rects[i].id = i; + } + + stbrp_node nodes[width]; + stbrp_init_target(ctx, width, height, nodes, width); + int packed = stbrp_pack_rects(ctx, rects, num); + + if (!packed) + return JS_UNDEFINED; + + ret = JS_NewArray(js); + for (int i = 0; i < num; i++) { + HMM_Vec2 pos; + pos.x = rects[i].x; + pos.y = rects[i].y; + js_setprop_num(ret, i, vec22js(pos)); + } +) + static const JSCFunctionListEntry js_os_funcs[] = { + MIST_FUNC_DEF(os, rectpack, 3), MIST_FUNC_DEF(os, cwd, 0), MIST_FUNC_DEF(os, rusage, 0), MIST_FUNC_DEF(os, mallinfo, 0),