fix uickjs string print issue

This commit is contained in:
John Alanbrook 2024-09-04 14:34:45 -05:00
parent 6d2696437c
commit fd8b1b8006
5 changed files with 27 additions and 19 deletions

View file

@ -5,6 +5,7 @@ debug.termout = true;
debug.console = false; debug.console = false;
debug.cheat = false; debug.cheat = false;
debug.meta = false; debug.meta = false;
debug.showprofiler = false;
debug.fn_break = function(fn,obj = globalThis) { debug.fn_break = function(fn,obj = globalThis) {
if (typeof fn !== 'function') return; if (typeof fn !== 'function') return;

View file

@ -157,6 +157,7 @@ profile.best_t = function (t) {
profile.report = function (start, msg = "[undefined report]") { console.info(`${msg} in ${profile.best_t(profile.now() - start)}`); }; profile.report = function (start, msg = "[undefined report]") { console.info(`${msg} in ${profile.best_t(profile.now() - start)}`); };
var frame_avg = false; var frame_avg = false;
profile.frame_avg_t = 72000;
profile.start_frame_avg = function() profile.start_frame_avg = function()
{ {
@ -183,31 +184,38 @@ profile.toggle_frame_avg = function()
else profile.start_frame_avg(); else profile.start_frame_avg();
} }
var profile_frames = {}; var profile_framer = {
var profile_frame_ts = []; series: [],
var profile_cframe = profile_frames; avg: {},
frame: 72000,
};
var profile_cframe = undefined;
var pframe = 0; var pframe = 0;
var profile_stack = [];
profile.frame = function profile_frame(title) profile.frame = function profile_frame(title)
{ {
if (!frame_avg) return; if (!frame_avg) return;
profile_frame_ts.push(profile_cframe); if (!profile_cframe) {
profile_cframe = {};
profile_framer.series.push({
time:profile.now(),
data:profile_cframe
});
} else
profile_stack.push(profile_cframe);
profile_cframe[title] ??= {}; profile_cframe[title] ??= {};
profile_cframe = profile_cframe[title]; profile_cframe = profile_cframe[title];
profile_cframe._times ??= []; profile_cframe.time = profile.now();
profile_cframe._times[pframe] ??= 0;
profile_cframe._times[pframe] = profile.now() - profile_cframe._times[pframe];
} }
profile.endframe = function profile_endframe() profile.endframe = function profile_endframe()
{ {
if (!frame_avg) return; if (!frame_avg) return;
profile_cframe.time = profile.now() - profile_cframe.time;
if (profile_cframe === profile_frames) return;
profile_cframe._times[pframe] = profile.now() - profile_cframe._times[pframe];
profile_cframe = profile_frame_ts.pop(); profile_cframe = profile_frame_ts.pop();
if (profile_cframe === profile_frames) pframe++;
} }
var print_frame = function(frame, indent, title) var print_frame = function(frame, indent, title)

View file

@ -1007,7 +1007,7 @@ var imgui_fn = function()
}); });
imgui.menu("Debug", imdebug); imgui.menu("Debug", imdebug);
imgui.menu("View", _ => { imgui.menu("View", _ => {
imtoggle("Profiler", gamestate, 'showprofiler'); imtoggle("Profiler", debug, 'showprofiler');
imtoggle("Terminal out", debug, 'termout'); imtoggle("Terminal out", debug, 'termout');
imtoggle("Meta [f7]", debug, 'meta'); imtoggle("Meta [f7]", debug, 'meta');
imtoggle("Cheats [f8]", debug, 'cheat'); imtoggle("Cheats [f8]", debug, 'cheat');

View file

@ -12,12 +12,10 @@ if (os.sys() === 'macos') {
appy.inputs['S-q'] = os.quit; appy.inputs['S-q'] = os.quit;
} }
//appy.inputs.f12 = function() { mum.debug = !mum.debug; } appy.inputs.f7 = function() { debug.meta = !debug.meta; }
appy.inputs['C-space'] = function() { appy.inputs.f8 = function() { debug.cheat = !debug.cheat; }
game.ooop = !game.ooop; appy.inputs.f9 = function() { debug.console = !debug.console; }
} appy.inputs.f10 = function() { debug.show = !debug.show; }
appy.inputs.f9 = function() { profile.print_mem(); }
appy.inputs.f10 = function() { profile.toggle_frame_avg(); }
appy.inputs.f11 = window.toggle_fullscreen; appy.inputs.f11 = window.toggle_fullscreen;
appy.inputs.f11.doc = "Toggle window fullscreen."; appy.inputs.f11.doc = "Toggle window fullscreen.";
appy.inputs.f11.title = "Toggle Fullscreen"; appy.inputs.f11.title = "Toggle Fullscreen";

View file

@ -2376,7 +2376,7 @@ void JS_FreeContext(JSContext *ctx)
{ {
JSMemoryUsage stats; JSMemoryUsage stats;
JS_ComputeMemoryUsage(rt, &stats); JS_ComputeMemoryUsage(rt, &stats);
JS_DumpMemoryUsage(stdout, &stats, rt); // JS_DumpMemoryUsage(stdout, &stats, rt);
} }
#endif #endif
@ -2575,6 +2575,7 @@ static __maybe_unused void JS_DumpChar(JSRuntime *rt, int c, int sep)
static __maybe_unused void JS_DumpString(JSRuntime *rt, const JSString *p) static __maybe_unused void JS_DumpString(JSRuntime *rt, const JSString *p)
{ {
return; // TODO: Reimplment this
int i, sep; int i, sep;
if (p == NULL) { if (p == NULL) {