summaryrefslogtreecommitdiffstats
path: root/src/glut/dos/callback.c
diff options
context:
space:
mode:
authorDaniel Borca <[email protected]>2004-01-15 08:30:05 +0000
committerDaniel Borca <[email protected]>2004-01-15 08:30:05 +0000
commitf8761dc0409000c6695467f72b32adf63e48361e (patch)
tree7a04bcd15819f68ca16347cb22e1595d9bc870a6 /src/glut/dos/callback.c
parent0849ed12755e21d5df2b83c9e8cc91f15ee1d896 (diff)
implemented glutTimerFunc
Diffstat (limited to 'src/glut/dos/callback.c')
-rw-r--r--src/glut/dos/callback.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/glut/dos/callback.c b/src/glut/dos/callback.c
index 8ab75e794c5..174cbdda996 100644
--- a/src/glut/dos/callback.c
+++ b/src/glut/dos/callback.c
@@ -19,7 +19,7 @@
*/
/*
- * DOS/DJGPP glut driver v1.3 for Mesa
+ * DOS/DJGPP glut driver v1.4 for Mesa
*
* Copyright (C) 2002 - Borca Daniel
@@ -31,10 +31,33 @@
+typedef struct {
+ void (*func) (int); /* function to call */
+ int value; /* value to pass to callback */
+ int ttl; /* time to live (blank shots) */
+ int fid; /* func-id as returned from PCHW */
+} GLUTSShotCB;
+
+static GLboolean g_sscb_semaphore;
+
GLUTidleCB g_idle_func = NULL;
+static void g_single_shot_callback (void *opaque)
+{
+ GLUTSShotCB *cb = (GLUTSShotCB *)opaque;
+ while (g_sscb_semaphore) {
+ }
+ if (!--cb->ttl) {
+ cb->func(cb->value);
+ pc_remove_int(cb->fid);
+ cb->func = NULL;
+ }
+} ENDOFUNC(g_single_shot_callback)
+
+
+
void APIENTRY glutDisplayFunc (GLUTdisplayCB func)
{
g_curwin->display = func;
@@ -106,6 +129,45 @@ void APIENTRY glutIdleFunc (GLUTidleCB func)
void APIENTRY glutTimerFunc (unsigned int millis, GLUTtimerCB func, int value)
{
+ static GLUTSShotCB g_sscb[MAX_SSHOT_CB];
+ static int virgin = GL_TRUE;
+
+ int i;
+ int ttl;
+ unsigned int freq;
+
+ if (virgin) {
+ virgin = GL_FALSE;
+ LOCKDATA(g_sscb);
+ LOCKDATA(g_sscb_semaphore);
+ LOCKFUNC(g_single_shot_callback);
+ /* we should lock the callee also... */
+ }
+
+ if (millis > 0) {
+ if (millis > 50) {
+ /* don't go beyond 20Hz */
+ freq = 200;
+ ttl = millis * freq / 1000;
+ } else {
+ freq = 1000 / millis;
+ ttl = 1;
+ }
+ g_sscb_semaphore++;
+ for (i = 0; i < MAX_SSHOT_CB; i++) {
+ if (g_sscb[i].func == NULL) {
+ int fid = pc_install_int((PFUNC)func, &g_sscb[i], freq);
+ if (fid >= 0) {
+ g_sscb[i].func = func;
+ g_sscb[i].value = value;
+ g_sscb[i].ttl = ttl;
+ g_sscb[i].fid = fid;
+ }
+ break;
+ }
+ }
+ g_sscb_semaphore--;
+ }
}