fix actor destruction. add rect pack function
This commit is contained in:
parent
93cda3848b
commit
cbd66e5304
|
@ -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.lerp = vector.lerp;
|
||||||
Math.gcd = vector.gcd;
|
Math.gcd = vector.gcd;
|
||||||
Math.lcm = vector.lcm;
|
Math.lcm = vector.lcm;
|
||||||
|
|
|
@ -1,22 +1,5 @@
|
||||||
globalThis.entityreport = {};
|
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) {
|
function obj_unique_name(name, obj) {
|
||||||
name = name.replaceAll(".", "_");
|
name = name.replaceAll(".", "_");
|
||||||
if (!(name in obj)) return name;
|
if (!(name in obj)) return name;
|
||||||
|
@ -365,8 +348,7 @@ var entity = {
|
||||||
kill() {
|
kill() {
|
||||||
if (this.__kill) return;
|
if (this.__kill) return;
|
||||||
this.__kill = true;
|
this.__kill = true;
|
||||||
|
this.timers.forEachRight(x => x());
|
||||||
this.timers.forEach(x => x());
|
|
||||||
delete this.timers;
|
delete this.timers;
|
||||||
Event.rm_obj(this);
|
Event.rm_obj(this);
|
||||||
input.do_uncontrol(this);
|
input.do_uncontrol(this);
|
||||||
|
|
|
@ -337,29 +337,23 @@ var classes = ["gameobject", "transform", "dsp_node", "texture", "font", "warp_g
|
||||||
var get_snapshot = function()
|
var get_snapshot = function()
|
||||||
{
|
{
|
||||||
var snap = profile.snapshot;
|
var snap = profile.snapshot;
|
||||||
snap.actors ??= {};
|
snap.actors = actor.__stats();
|
||||||
Object.assign(snap.actors, actor.__stats());
|
snap.memory = os.mem();
|
||||||
snap.memory ??= {};
|
|
||||||
Object.assign(snap.memory, os.mem());
|
|
||||||
snap.memory.textures = game.texture.total_size();
|
snap.memory.textures = game.texture.total_size();
|
||||||
snap.memory.texture_vram = game.texture.total_vram();
|
snap.memory.texture_vram = game.texture.total_vram();
|
||||||
|
|
||||||
snap.rusage ??= {};
|
snap.rusage = os.rusage();
|
||||||
var rusage = os.rusage();
|
snap.rusage.ru_maxrss *= 1024; // delivered in KB; convert here to B
|
||||||
rusage.ru_maxrss *= 1024; // delivered in KB; convert here to B
|
|
||||||
Object.assign(snap.rusage, rusage);
|
|
||||||
|
|
||||||
snap.mallinfo ??= {};
|
snap.mallinfo = os.mallinfo();
|
||||||
Object.assign(snap.mallinfo, os.mallinfo());
|
snap.particles = stat_emitters();
|
||||||
|
|
||||||
snap.particles ??= {};
|
|
||||||
Object.assign(snap.particles, stat_emitters());
|
|
||||||
|
|
||||||
snap.obj ??= {};
|
snap.obj ??= {};
|
||||||
for (var i of classes) {
|
for (var i of classes) {
|
||||||
var proto = globalThis[`${i}_proto`];
|
var proto = globalThis[`${i}_proto`];
|
||||||
if (!proto) continue;
|
if (!proto) continue;
|
||||||
snap.obj[i] = proto._count();
|
snap.obj[i] = proto._count();
|
||||||
|
snap.obj[i + "_mem"] = proto._count() * proto.memsize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "datastream.h"
|
#include "datastream.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "stb_ds.h"
|
#include "stb_ds.h"
|
||||||
|
#define STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
#include "stb_rect_pack.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "spline.h"
|
#include "spline.h"
|
||||||
|
@ -3363,7 +3365,38 @@ JSC_CCALL(os_skin_calculate,
|
||||||
skin_calculate(sk);
|
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[] = {
|
static const JSCFunctionListEntry js_os_funcs[] = {
|
||||||
|
MIST_FUNC_DEF(os, rectpack, 3),
|
||||||
MIST_FUNC_DEF(os, cwd, 0),
|
MIST_FUNC_DEF(os, cwd, 0),
|
||||||
MIST_FUNC_DEF(os, rusage, 0),
|
MIST_FUNC_DEF(os, rusage, 0),
|
||||||
MIST_FUNC_DEF(os, mallinfo, 0),
|
MIST_FUNC_DEF(os, mallinfo, 0),
|
||||||
|
|
Loading…
Reference in a new issue