add imgui listbox
This commit is contained in:
parent
d33c1af92c
commit
6d2696437c
|
@ -258,7 +258,9 @@ console.stackstr = function (skip = 0) {
|
||||||
};
|
};
|
||||||
|
|
||||||
console.stack = function (skip = 0) {
|
console.stack = function (skip = 0) {
|
||||||
console.log(console.stackstr(skip + 1));
|
var stack = console.stackstr(skip+1);
|
||||||
|
console.log(stack);
|
||||||
|
return stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
console.stdout_lvl = 1;
|
console.stdout_lvl = 1;
|
||||||
|
|
|
@ -85,12 +85,21 @@ profile.start_cpu_gather = function()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function push_time(arr, ob, max)
|
||||||
|
{
|
||||||
|
arr.push({
|
||||||
|
time:profile.now(),
|
||||||
|
ob
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
profile.cpu_frames = [];
|
||||||
profile.cpu_frame = function()
|
profile.cpu_frame = function()
|
||||||
{
|
{
|
||||||
if (gathering_cpu) return;
|
if (gathering_cpu) return;
|
||||||
|
|
||||||
profile.gather(Math.random_range(300,600), function() {
|
profile.gather(Math.random_range(300,600), function() {
|
||||||
console.stack(2);
|
push_time(profile.cpu_frames, console.stack(2));
|
||||||
profile.gather_stop();
|
profile.gather_stop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -318,16 +327,20 @@ profile.print_mem = function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profile.last_mem = undefined;
|
||||||
|
profile.mems = [];
|
||||||
|
profile.gcs = [];
|
||||||
profile.print_gc = function()
|
profile.print_gc = function()
|
||||||
{
|
{
|
||||||
var gc = os.check_gc();
|
var gc = os.check_gc();
|
||||||
if (!gc) return;
|
if (!gc) return;
|
||||||
var mem = os.mem();
|
profile.gcs.push(gc);
|
||||||
|
profile.mems.push(os.mem());
|
||||||
say("GC Hit");
|
say("GC Hit");
|
||||||
say (`time: ${profile.best_t(gc.time)}`);
|
say (`time: ${profile.best_t(gc.time)}`);
|
||||||
say(`new threshold: ${profile.best_mem(mem.gc_threshold)}`);
|
say(`new threshold: ${profile.best_mem(profile.mems.last().gc_threshold)}`);
|
||||||
say(`memory checked: ${profile.best_mem(gc.mem)}`);
|
say(`memory checked: ${profile.best_mem(profile.gcs.last().mem)}`);
|
||||||
say(`memory freed: ${profile.best_mem(gc.startmem - gc.mem)}`);
|
say(`memory freed: ${profile.best_mem(profile.gcs.last().startmem - profile.gcs.last().mem)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {profile};
|
return {profile};
|
||||||
|
|
|
@ -126,7 +126,6 @@ game.engine_start = function (s) {
|
||||||
};
|
};
|
||||||
|
|
||||||
game.startengine = 0;
|
game.startengine = 0;
|
||||||
var frames = [];
|
|
||||||
|
|
||||||
prosperon.release_mode = function()
|
prosperon.release_mode = function()
|
||||||
{
|
{
|
||||||
|
@ -136,13 +135,6 @@ prosperon.release_mode = function()
|
||||||
}
|
}
|
||||||
prosperon.debug = true;
|
prosperon.debug = true;
|
||||||
|
|
||||||
globalThis.fps = function () {
|
|
||||||
return 0;
|
|
||||||
// var sum = 0;
|
|
||||||
// for (var i = 0; i < frames.length; i++) sum += frames[i];
|
|
||||||
// return frames.length / sum;
|
|
||||||
};
|
|
||||||
|
|
||||||
game.timescale = 1;
|
game.timescale = 1;
|
||||||
|
|
||||||
var eachobj = function (obj, fn) {
|
var eachobj = function (obj, fn) {
|
||||||
|
|
|
@ -168,6 +168,25 @@ JSC_CCALL(imgui_nextcolumn, ImGui::NextColumn() )
|
||||||
JSC_SCALL(imgui_collapsingheader, ret = boolean2js(ImGui::CollapsingHeader(str)) )
|
JSC_SCALL(imgui_collapsingheader, ret = boolean2js(ImGui::CollapsingHeader(str)) )
|
||||||
JSC_SCALL(imgui_radio, ret = boolean2js(ImGui::RadioButton(str, js2boolean(argv[1]))))
|
JSC_SCALL(imgui_radio, ret = boolean2js(ImGui::RadioButton(str, js2boolean(argv[1]))))
|
||||||
|
|
||||||
|
JSC_SCALL(imgui_tree,
|
||||||
|
if (ImGui::TreeNode(str)) {
|
||||||
|
script_call_sym(argv[1],0,NULL);
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_SCALL(imgui_listbox,
|
||||||
|
char **arr = js2strarr(argv[1]);
|
||||||
|
int n = js_arrlen(argv[1]);
|
||||||
|
int idx = js2number(argv[2]);
|
||||||
|
ImGui::ListBox(str, &idx, arr, n, 4);
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
free(arr[i]);
|
||||||
|
|
||||||
|
// arrfree(arr); // TODO: Doesn't this need freed?
|
||||||
|
ret = number2js(idx);
|
||||||
|
)
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_imgui_funcs[] = {
|
static const JSCFunctionListEntry js_imgui_funcs[] = {
|
||||||
MIST_FUNC_DEF(imgui, window, 2),
|
MIST_FUNC_DEF(imgui, window, 2),
|
||||||
MIST_FUNC_DEF(imgui, menu, 2),
|
MIST_FUNC_DEF(imgui, menu, 2),
|
||||||
|
@ -191,6 +210,8 @@ static const JSCFunctionListEntry js_imgui_funcs[] = {
|
||||||
MIST_FUNC_DEF(imgui, columns, 2),
|
MIST_FUNC_DEF(imgui, columns, 2),
|
||||||
MIST_FUNC_DEF(imgui, nextcolumn, 0),
|
MIST_FUNC_DEF(imgui, nextcolumn, 0),
|
||||||
MIST_FUNC_DEF(imgui, collapsingheader, 1),
|
MIST_FUNC_DEF(imgui, collapsingheader, 1),
|
||||||
|
MIST_FUNC_DEF(imgui, tree, 2),
|
||||||
|
MIST_FUNC_DEF(imgui, listbox, 3),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int started = 0;
|
static int started = 0;
|
||||||
|
@ -213,6 +234,7 @@ JSValue gui_init(JSContext *js)
|
||||||
|
|
||||||
void gui_input(sapp_event *e)
|
void gui_input(sapp_event *e)
|
||||||
{
|
{
|
||||||
|
if (!started) return;
|
||||||
simgui_handle_event(e);
|
simgui_handle_event(e);
|
||||||
ImGuiIO io = ImGui::GetIO();
|
ImGuiIO io = ImGui::GetIO();
|
||||||
wantkeys = io.WantCaptureKeyboard;
|
wantkeys = io.WantCaptureKeyboard;
|
||||||
|
|
|
@ -184,6 +184,17 @@ void js_setpropstr(JSValue v, const char *str, JSValue p)
|
||||||
|
|
||||||
static inline cpBody *js2body(JSValue v) { return js2gameobject(v)->body; }
|
static inline cpBody *js2body(JSValue v) { return js2gameobject(v)->body; }
|
||||||
|
|
||||||
|
char **js2strarr(JSValue v)
|
||||||
|
{
|
||||||
|
int n = js_arrlen(v);
|
||||||
|
char **arr = malloc(sizeof(*arr));
|
||||||
|
arr = NULL;
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
arrput(arr, js2strdup(js_getpropidx(v, i)));
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
JSValue strarr2js(char **c)
|
JSValue strarr2js(char **c)
|
||||||
{
|
{
|
||||||
JSValue arr = JS_NewArray(js);
|
JSValue arr = JS_NewArray(js);
|
||||||
|
|
|
@ -171,6 +171,8 @@ JSValue floatarr2js(int n, float *a);
|
||||||
int js2boolean(JSValue v);
|
int js2boolean(JSValue v);
|
||||||
JSValue boolean2js(int b);
|
JSValue boolean2js(int b);
|
||||||
|
|
||||||
|
char **js2strarr(JSValue v);
|
||||||
|
|
||||||
#define PREP_PARENT(TYPE, PARENT) \
|
#define PREP_PARENT(TYPE, PARENT) \
|
||||||
TYPE##_proto = JS_NewObject(js); \
|
TYPE##_proto = JS_NewObject(js); \
|
||||||
JS_SetPropertyFunctionList(js, TYPE##_proto, js_##TYPE##_funcs, countof(js_##TYPE##_funcs)); \
|
JS_SetPropertyFunctionList(js, TYPE##_proto, js_##TYPE##_funcs, countof(js_##TYPE##_funcs)); \
|
||||||
|
|
|
@ -70,13 +70,12 @@ void log_shutdown()
|
||||||
const char *logfmt = "%s:%d: [%s] %s, %s: ";
|
const char *logfmt = "%s:%d: [%s] %s, %s: ";
|
||||||
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
struct tm *tinfo = localtime(&now);
|
struct tm *tinfo = localtime(&now);
|
||||||
char timebuf[80];
|
char timebuf[80];
|
||||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tinfo);
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tinfo);
|
||||||
/*
|
|
||||||
fprintf(logout, logfmt, file, line, timebuf, logstr[priority], catstr[category]);
|
fprintf(logout, logfmt, file, line, timebuf, logstr[priority], catstr[category]);
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -84,7 +83,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
||||||
vfprintf(logout, message, args);
|
vfprintf(logout, message, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
fprintf(logout, "\n");
|
fprintf(logout, "\n");
|
||||||
*/
|
|
||||||
if (priority == LOG_DEBUG || priority >= stdout_lvl) {
|
if (priority == LOG_DEBUG || priority >= stdout_lvl) {
|
||||||
printf(logfmt, file, line, timebuf, logcolor[priority], catstr[category]);
|
printf(logfmt, file, line, timebuf, logcolor[priority], catstr[category]);
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -109,17 +108,17 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
||||||
void log_print(const char *str)
|
void log_print(const char *str)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
//fprintf(writeout, "%s", str);
|
fprintf(writeout, "%s", str);
|
||||||
#else
|
#else
|
||||||
//printf(str);
|
printf(str);
|
||||||
//fflush(stdout);
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void term_print(const char *str)
|
void term_print(const char *str)
|
||||||
{
|
{
|
||||||
//fprintf(stdout, "%s", str);
|
fprintf(stdout, "%s", str);
|
||||||
//fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {
|
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {
|
||||||
|
|
Loading…
Reference in a new issue