diff --git a/client/src/main.c b/client/src/main.c index 96f77545..04e4ecb2 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -820,11 +820,11 @@ static int lg_run(void) DEBUG_INFO("Using font: %s", g_state.fontName); g_state.overlays = ll_new(); + app_registerOverlay(&LGOverlayConfig, NULL); app_registerOverlay(&LGOverlayAlert , NULL); app_registerOverlay(&LGOverlayFPS , NULL); app_registerOverlay(&LGOverlayGraphs, NULL); app_registerOverlay(&LGOverlayHelp , NULL); - app_registerOverlay(&LGOverlayConfig, NULL); // initialize metrics ringbuffers g_state.renderTimings = ringbuffer_new(256, sizeof(float)); diff --git a/client/src/overlay/config.c b/client/src/overlay/config.c index 4c111078..f8d918a5 100644 --- a/client/src/overlay/config.c +++ b/client/src/overlay/config.c @@ -21,27 +21,50 @@ #include "interface/overlay.h" #include "cimgui.h" #include "overlay_utils.h" +#include "ll.h" #include "../main.h" #include "../overlays.h" #include "version.h" +#include "common/debug.h" #include "common/appstrings.h" +typedef struct ConfigCallback +{ + const char * title; + void * udata; + void (*callback)(void * udata); +} +ConfigCallback; + +typedef struct OverlayConfig +{ + struct ll * callbacks; +} +OverlayConfig; + +static OverlayConfig cfg = { 0 }; + static bool config_init(void ** udata, void * params) { + cfg.callbacks = ll_new(); + if (!cfg.callbacks) + { + DEBUG_ERROR("failed to allocate ram"); + return false; + } + return true; } static void config_free(void * udata) { -} + ConfigCallback * cb; + while(ll_shift(cfg.callbacks, (void **)&cb)) + free(cb); -static void graphIterator(GraphHandle handle, const char * name, bool * enabled, - void * udata) -{ - igTableNextColumn(); - igCheckbox(name, enabled); + ll_free(cfg.callbacks); } static int config_render(void * udata, bool interactive, struct Rect * windowRects, @@ -132,14 +155,12 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec } } - if(igCollapsingHeaderBoolPtr("Performance Metrics", NULL, 0)) + ConfigCallback * cb; + for (ll_reset(cfg.callbacks); ll_walk(cfg.callbacks, (void **)&cb); ) { - igCheckbox("Show Timing Graphs", &g_state.showTiming); - igSeparator(); - - igBeginTable("split", 2, 0, (ImVec2){}, 0); - overlayGraph_iterate(graphIterator, NULL); - igEndTable(); + if (!igCollapsingHeaderBoolPtr(cb->title, NULL, 0)) + continue; + cb->callback(cb->udata); } overlayGetImGuiRect(windowRects); @@ -154,3 +175,19 @@ struct LG_OverlayOps LGOverlayConfig = .free = config_free, .render = config_render }; + +void overlayConfig_register(const char * title, void (*callback)(void * udata), + void * udata) +{ + ConfigCallback * cb = calloc(1, sizeof(*cb)); + if (!cb) + { + DEBUG_ERROR("failed to allocate ram"); + return; + } + + cb->title = title; + cb->udata = udata; + cb->callback = callback; + ll_push(cfg.callbacks, cb); +}; diff --git a/client/src/overlay/graphs.c b/client/src/overlay/graphs.c index 1d366878..7e876405 100644 --- a/client/src/overlay/graphs.c +++ b/client/src/overlay/graphs.c @@ -22,6 +22,7 @@ #include "cimgui.h" #include "../main.h" +#include "../overlays.h" #include "ll.h" #include "common/debug.h" @@ -43,9 +44,28 @@ struct OverlayGraph float max; }; + +static void configCallback(void * udata) +{ + igCheckbox("Show Timing Graphs", &g_state.showTiming); + igSeparator(); + + igBeginTable("split", 2, 0, (ImVec2){}, 0); + + GraphHandle graph; + for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); ) + { + igTableNextColumn(); + igCheckbox(graph->name, &graph->enabled); + } + + igEndTable(); +} + static bool graphs_init(void ** udata, void * params) { gs.graphs = ll_new(); + overlayConfig_register("Performance Metrics", configCallback, NULL); return true; } diff --git a/client/src/overlays.h b/client/src/overlays.h index 0108eb6c..696fb10f 100644 --- a/client/src/overlays.h +++ b/client/src/overlays.h @@ -33,6 +33,9 @@ GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, float min, float max); void overlayGraph_unregister(); void overlayGraph_iterate(void (*callback)(GraphHandle handle, const char * name, - bool * enabled, void * udata), void * udata); + bool * enabled, void * udata), void * udata); + +void overlayConfig_register(const char * title, void (*callback)(void * udata), + void * udata); #endif