add layers to callbacks
This commit is contained in:
parent
ad6b82ded1
commit
01905a26a2
|
@ -4,6 +4,7 @@ global.check_registers = function (obj) {
|
||||||
for (var reg in Register.registries) {
|
for (var reg in Register.registries) {
|
||||||
if (typeof obj[reg] === 'function') {
|
if (typeof obj[reg] === 'function') {
|
||||||
var fn = obj[reg].bind(obj);
|
var fn = obj[reg].bind(obj);
|
||||||
|
fn.layer = obj[reg].layer;
|
||||||
var name = obj.ur ? obj.ur.name : obj.toString();
|
var name = obj.ur ? obj.ur.name : obj.toString();
|
||||||
obj.timers.push(Register.registries[reg].register(fn, name));
|
obj.timers.push(Register.registries[reg].register(fn, name));
|
||||||
}
|
}
|
||||||
|
@ -315,9 +316,9 @@ which returns a function that, when invoked, cancels the registry.
|
||||||
var Register = {
|
var Register = {
|
||||||
registries: [],
|
registries: [],
|
||||||
|
|
||||||
add_cb(name, e_event = false) {
|
add_cb(name, e_event = false, flush = undefined) {
|
||||||
var n = {};
|
var n = {};
|
||||||
var fns = {};
|
var fns = [];
|
||||||
|
|
||||||
n.register = function (fn, oname) {
|
n.register = function (fn, oname) {
|
||||||
if (!(fn instanceof Function)) return;
|
if (!(fn instanceof Function)) return;
|
||||||
|
@ -330,16 +331,34 @@ var Register = {
|
||||||
fn(...args);
|
fn(...args);
|
||||||
profile.endcache();
|
profile.endcache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fns.push(dofn);
|
||||||
|
dofn.layer = fn.layer;
|
||||||
|
dofn.layer ??= 0;
|
||||||
|
|
||||||
|
fns.sort((a,b) => a.layer > b.layer);
|
||||||
|
|
||||||
fns[guid] = dofn;
|
|
||||||
return function () {
|
return function () {
|
||||||
delete fns[guid];
|
fns.remove(dofn);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
prosperon[name] = function (...args) {
|
if (!flush) {
|
||||||
fns.forEach(x => x(...args));
|
prosperon[name] = function(...args) {
|
||||||
};
|
fns.forEach(fn => fn(...args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
prosperon[name] = function(...args) {
|
||||||
|
var layer = undefined;
|
||||||
|
for (var fn of fns) {
|
||||||
|
if (layer !== fn.layer) {
|
||||||
|
flush();
|
||||||
|
layer = fn.layer;
|
||||||
|
}
|
||||||
|
fn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prosperon[name].fns = fns;
|
prosperon[name].fns = fns;
|
||||||
n.clear = function () {
|
n.clear = function () {
|
||||||
|
@ -357,13 +376,12 @@ Register.add_cb("appupdate", true);
|
||||||
Register.add_cb("update", true).doc = "Called once per frame.";
|
Register.add_cb("update", true).doc = "Called once per frame.";
|
||||||
Register.add_cb("physupdate", true);
|
Register.add_cb("physupdate", true);
|
||||||
Register.add_cb("gui", true);
|
Register.add_cb("gui", true);
|
||||||
Register.add_cb("hud", true);
|
Register.add_cb("hud", true, render.flush);
|
||||||
Register.add_cb("draw_dbg", true);
|
Register.add_cb("draw_dbg", true);
|
||||||
Register.add_cb("gui_dbg", true);
|
Register.add_cb("gui_dbg", true);
|
||||||
Register.add_cb("hud_dbg", true);
|
Register.add_cb("hud_dbg", true);
|
||||||
Register.add_cb("draw", true);
|
Register.add_cb("draw", true);
|
||||||
Register.add_cb("imgui", true);
|
Register.add_cb("imgui", true);
|
||||||
Register.add_cb("post", true);
|
|
||||||
|
|
||||||
var Event = {
|
var Event = {
|
||||||
events: {},
|
events: {},
|
||||||
|
|
|
@ -642,6 +642,8 @@ function check_flush(flush_fn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render.flush = check_flush;
|
||||||
|
|
||||||
var poly_cache = [];
|
var poly_cache = [];
|
||||||
var poly_idx = 0;
|
var poly_idx = 0;
|
||||||
var poly_ssbo;
|
var poly_ssbo;
|
||||||
|
@ -1121,7 +1123,6 @@ prosperon.render = function()
|
||||||
render.flush_text();
|
render.flush_text();
|
||||||
mum.style = mum.base;
|
mum.style = mum.base;
|
||||||
|
|
||||||
prosperon.post();
|
|
||||||
check_flush();
|
check_flush();
|
||||||
|
|
||||||
profile.endframe();
|
profile.endframe();
|
||||||
|
|
Loading…
Reference in a new issue