diff --git a/client/include/interface/overlay.h b/client/include/interface/overlay.h index 1319ae7a..2a6c6986 100644 --- a/client/include/interface/overlay.h +++ b/client/include/interface/overlay.h @@ -59,6 +59,15 @@ struct LG_OverlayOps int (*render)(void * udata, bool interactive, struct Rect * windowRects, int maxRects); + /* called 25 times a second by the application + * + * Note: This may not run in the same context as `render`! + * + * return true if the frame needs to be rendered + * optional, if omitted assumes false + */ + bool (*tick)(void * udata, unsigned long long tickCount); + /* TODO: add load/save settings capabillity */ }; diff --git a/client/src/app.c b/client/src/app.c index 90fa637a..cd98084d 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -519,6 +519,10 @@ void app_invalidateWindow(bool full) { if (full) atomic_store(&g_state.invalidateWindow, true); + + if (g_state.jitRender && g_state.ds->stopWaitFrame) + g_state.ds->stopWaitFrame(); + lgSignalEvent(g_state.frameEvent); } @@ -691,15 +695,6 @@ void app_unregisterGraph(GraphHandle handle) overlayGraph_unregister(handle); } -struct Overlay -{ - const struct LG_OverlayOps * ops; - const void * params; - void * udata; - int lastRectCount; - struct Rect lastRects[MAX_OVERLAY_RECTS]; -}; - void app_registerOverlay(const struct LG_OverlayOps * ops, const void * params) { ASSERT_LG_OVERLAY_VALID(ops); diff --git a/client/src/main.c b/client/src/main.c index 42c7fd9b..1d2741d2 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -139,6 +139,26 @@ static bool fpsTimerFn(void * unused) return true; } +static bool tickTimerFn(void * unused) +{ + static unsigned long long tickCount = 0; + + bool needsRender = false; + struct Overlay * overlay; + for (ll_reset(g_state.overlays); + ll_walk(g_state.overlays, (void **)&overlay); ) + { + if (overlay->ops->tick && overlay->ops->tick(overlay->udata, tickCount)) + needsRender = true; + } + + if (needsRender) + app_invalidateWindow(false); + + ++tickCount; + return true; +} + static void preSwapCallback(void * udata) { const uint64_t * renderStart = (const uint64_t *)udata; @@ -169,6 +189,14 @@ static int renderThread(void * unused) return 1; } + LGTimer * tickTimer; + if (!lgCreateTimer(40, tickTimerFn, NULL, &tickTimer)) + { + lgTimerDestroy(fpsTimer); + DEBUG_ERROR("Failed to create the tick timer"); + return 1; + } + LG_LOCK_INIT(g_state.lgrLock); /* signal to other threads that the renderer is ready */ @@ -289,6 +317,7 @@ static int renderThread(void * unused) g_state.state = APP_STATE_SHUTDOWN; + lgTimerDestroy(tickTimer); lgTimerDestroy(fpsTimer); core_stopCursorThread(); diff --git a/client/src/overlays.h b/client/src/overlays.h index 3b191b28..74abb10d 100644 --- a/client/src/overlays.h +++ b/client/src/overlays.h @@ -23,6 +23,15 @@ #include "interface/overlay.h" +struct Overlay +{ + const struct LG_OverlayOps * ops; + const void * params; + void * udata; + int lastRectCount; + struct Rect lastRects[MAX_OVERLAY_RECTS]; +}; + extern struct LG_OverlayOps LGOverlayAlert; extern struct LG_OverlayOps LGOverlayFPS; extern struct LG_OverlayOps LGOverlayGraphs;