FreeBSD Manual Pages
AG_CUSTOMEVENTLOOP(3) FreeBSD Library Functions Manual AG_CUSTOMEVENTLOOP(3) NAME AG_CustomEventLoop -- agar GUI custom event loop example SYNOPSIS #include <agar/core.h> #include <agar/gui.h> DESCRIPTION In general, most Agar GUI applications will use the standard Agar-Core event loop, AG_EventLoop(3), since it uses the most efficient event-noti- fication mechanism available for the target platform (e.g., kqueue(2), select(2), etc.) However, Agar-GUI applications are not required to use AG_EventLoop() at all, and may use an application-specific event loop routine. To simplify writing of custom event loops, Agar provides the AG_GetNextEvent(3), AG_ProcessEvent(3) and AG_ProcessTimeouts(3) functions. Low-level driver events are represented by the transparent, driver-independent AG_DriverEvent structure (see AG_Driver(3) for details and examples). CUSTOM EVENT LOOP EXAMPLE The following event loop redraws Agar windows whenever needed (the redraw frequency being limited to some nomimal frame rate), processes input events, and executes timer callbacks (using an inefficient delay loop): void MY_GenericEventLoop(void *obj) { AG_Window *win; Uint32 t1, t2; t1 = AG_GetTicks(); for (;;) { t2 = AG_GetTicks(); if (t2 - t1 >= rNom) { AG_WindowDrawQueued(); t1 = AG_GetTicks(); rCur = rNom - (t1-t2); if (rCur < 1) { rCur = 1; } } else if (AG_PendingEvents(NULL)) { AG_DriverEvent dev; if (AG_GetNextEvent(NULL, &dev) == 1) AG_ProcessEvent(NULL, &dev); } else { AG_ProcessTimeouts(t2); AG_Delay(1); } AG_WindowProcessQueued(); } } SEE ALSO AG_Delay(3), AG_Driver(3), AG_Event(3), AG_Timer(3), AG_Window(3) HISTORY The AG_CustomEventLoop routine first appeared in Agar 1.0. The AG_GetNextEvent() interface appeared in Agar 1.4. FreeBSD 13.0 September 16, 2009 FreeBSD 13.0
NAME | SYNOPSIS | DESCRIPTION | CUSTOM EVENT LOOP EXAMPLE | SEE ALSO | HISTORY
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=AG_CustomEventLoop&sektion=3&manpath=FreeBSD+12.2-RELEASE+and+Ports>