GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AG_CUSTOMEVENTLOOP(3) FreeBSD Library Functions Manual AG_CUSTOMEVENTLOOP(3)

AG_CustomEventLoop
agar GUI custom event loop example

#include <agar/core.h>
#include <agar/gui.h>

In general, most Agar GUI applications will use the standard Agar-Core event loop, AG_EventLoop(3), since it uses the most efficient event-notification 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).

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();
	}
}

AG_Delay(3), AG_Driver(3), AG_Event(3), AG_Timer(3), AG_Window(3)

The AG_CustomEventLoop routine first appeared in Agar 1.0. The AG_GetNextEvent() interface appeared in Agar 1.4.
September 16, 2009 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.