diff options
author | Daniel Borca <[email protected]> | 2005-01-14 08:50:08 +0000 |
---|---|---|
committer | Daniel Borca <[email protected]> | 2005-01-14 08:50:08 +0000 |
commit | 404273ad09f0f7bb079386929767e2151a355024 (patch) | |
tree | d9bb8bc6432a7e9edfbf70f8b76c3f7c2230b168 /src/glut/dos/callback.c | |
parent | 0c685896736da5e17cb995b49fc3acce32081bad (diff) |
changed coding style. made `glutTimerFunc' less accurate, but far more reliable.
Diffstat (limited to 'src/glut/dos/callback.c')
-rw-r--r-- | src/glut/dos/callback.c | 183 |
1 files changed, 65 insertions, 118 deletions
diff --git a/src/glut/dos/callback.c b/src/glut/dos/callback.c index b322f673514..6bd05f40658 100644 --- a/src/glut/dos/callback.c +++ b/src/glut/dos/callback.c @@ -19,9 +19,9 @@ */ /* - * DOS/DJGPP glut driver v1.5 for Mesa + * DOS/DJGPP glut driver v1.6 for Mesa * - * Copyright (C) 2002 - Borca Daniel + * Copyright (C) 2002 - Daniel Borca * Email : [email protected] * Web : http://www.geocities.com/dborca */ @@ -30,202 +30,149 @@ #include "glutint.h" - -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; +GLUTSShotCB g_sscb[MAX_SSHOT_CB]; GLUTidleCB g_idle_func = NULL; - -static void g_single_shot_callback (void *opaque) +void APIENTRY +glutDisplayFunc (GLUTdisplayCB func) { - GLUTSShotCB *cb = (GLUTSShotCB *)opaque; - if (!--cb->ttl) { - cb->func(cb->value); - pc_remove_int(cb->fid); - /* We won't be needing this slot anymore, so free it. This operation - * must be the last thing, and must be atomic, to mutex `glutTimerFunc' - */ - cb->func = NULL; - } -} ENDOFUNC(g_single_shot_callback) - - - -void APIENTRY glutDisplayFunc (GLUTdisplayCB func) -{ - g_curwin->display = func; + g_curwin->display = func; } - -void APIENTRY glutReshapeFunc (GLUTreshapeCB func) +void APIENTRY +glutReshapeFunc (GLUTreshapeCB func) { - g_curwin->reshape = func; + g_curwin->reshape = func; } - -void APIENTRY glutKeyboardFunc (GLUTkeyboardCB func) +void APIENTRY +glutKeyboardFunc (GLUTkeyboardCB func) { - g_curwin->keyboard = func; + g_curwin->keyboard = func; } - -void APIENTRY glutMouseFunc (GLUTmouseCB func) +void APIENTRY +glutMouseFunc (GLUTmouseCB func) { - g_curwin->mouse = func; + g_curwin->mouse = func; } - -void APIENTRY glutMotionFunc (GLUTmotionCB func) +void APIENTRY +glutMotionFunc (GLUTmotionCB func) { - g_curwin->motion = func; + g_curwin->motion = func; } - -void APIENTRY glutPassiveMotionFunc (GLUTpassiveCB func) +void APIENTRY +glutPassiveMotionFunc (GLUTpassiveCB func) { - g_curwin->passive = func; + g_curwin->passive = func; } - -void APIENTRY glutEntryFunc (GLUTentryCB func) +void APIENTRY +glutEntryFunc (GLUTentryCB func) { - g_curwin->entry = func; + g_curwin->entry = func; } - -void APIENTRY glutVisibilityFunc (GLUTvisibilityCB func) +void APIENTRY +glutVisibilityFunc (GLUTvisibilityCB func) { - g_curwin->visibility = func; + g_curwin->visibility = func; } - -void APIENTRY glutWindowStatusFunc (GLUTwindowStatusCB func) +void APIENTRY +glutWindowStatusFunc (GLUTwindowStatusCB func) { } - -void APIENTRY glutIdleFunc (GLUTidleCB func) +void APIENTRY +glutIdleFunc (GLUTidleCB func) { - g_idle_func = func; + g_idle_func = func; } - -void APIENTRY glutTimerFunc (unsigned int millis, GLUTtimerCB func, int value) +void APIENTRY +glutTimerFunc (unsigned int millis, GLUTtimerCB func, int value) { - static GLUTSShotCB g_sscb[MAX_SSHOT_CB]; - static GLboolean virgin = GL_TRUE; - - int i; - int ttl; - unsigned int freq; - - if (virgin) { - virgin = GL_FALSE; - LOCKDATA(g_sscb); - LOCKFUNC(g_single_shot_callback); - /* we should lock the callee also... */ - } + int i; - if (millis > 0) { - if (millis > 50) { - /* don't go beyond 20Hz */ - freq = 200; - ttl = millis * freq / 1000; - } else { - freq = 1000 / millis; - ttl = 1; - } - for (i = 0; i < MAX_SSHOT_CB; i++) { - if (g_sscb[i].func == NULL) { - /* We will be needing this slot, so alloc it. This operation - * must be the first thing, and must be atomic, to mutex callbacks! - */ - g_sscb[i].func = func; - g_sscb[i].value = value; - g_sscb[i].ttl = ttl; - /* There is a very small gap here: `pc_install_int' enables - * interrupts just before returning FID value (which will be - * used inside callback). The critical gap is 1 millisecond - * - which I'm sure we won't overrun... - */ - g_sscb[i].fid = pc_install_int((PFUNC)func, &g_sscb[i], freq); - if (g_sscb[i].fid < 0) { - /* Interrupt could not be set! Release the slot back */ - g_sscb[i].func = NULL; - } - break; - } - } - } + if (millis > 0) { + for (i = 0; i < MAX_SSHOT_CB; i++) { + GLUTSShotCB *cb = &g_sscb[i]; + if (cb->func == NULL) { + cb->value = value; + cb->func = func; + cb->time = glutGet(GLUT_ELAPSED_TIME) + millis; + break; + } + } + } } - -void APIENTRY glutSpecialFunc (GLUTspecialCB func) +void APIENTRY +glutSpecialFunc (GLUTspecialCB func) { - g_curwin->special = func; + g_curwin->special = func; } - -void APIENTRY glutSpaceballMotionFunc (GLUTspaceMotionCB func) +void APIENTRY +glutSpaceballMotionFunc (GLUTspaceMotionCB func) { } - -void APIENTRY glutSpaceballRotateFunc (GLUTspaceRotateCB func) +void APIENTRY +glutSpaceballRotateFunc (GLUTspaceRotateCB func) { } - -void APIENTRY glutSpaceballButtonFunc (GLUTspaceButtonCB func) +void APIENTRY +glutSpaceballButtonFunc (GLUTspaceButtonCB func) { } - -void APIENTRY glutDialsFunc (GLUTdialsCB func) +void APIENTRY +glutDialsFunc (GLUTdialsCB func) { } - -void APIENTRY glutButtonBoxFunc (GLUTbuttonBoxCB func) +void APIENTRY +glutButtonBoxFunc (GLUTbuttonBoxCB func) { } - -void APIENTRY glutTabletMotionFunc (GLUTtabletMotionCB func) +void APIENTRY +glutTabletMotionFunc (GLUTtabletMotionCB func) { } - -void APIENTRY glutTabletButtonFunc (GLUTtabletButtonCB func) +void APIENTRY +glutTabletButtonFunc (GLUTtabletButtonCB func) { } - -void APIENTRY glutJoystickFunc (GLUTjoystickCB func, int interval) +void APIENTRY +glutJoystickFunc (GLUTjoystickCB func, int interval) { } |