mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-14 04:57:54 +00:00
[client] overlay: add 25Hz tick
function
This allows an overlay to manage itself for timed events like alerts/messages, etc.
This commit is contained in:
parent
35334333ac
commit
db2e38ae4d
4 changed files with 51 additions and 9 deletions
|
@ -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 */
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue