summaryrefslogtreecommitdiff
path: root/src/d_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/d_main.c')
-rw-r--r--src/d_main.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/d_main.c b/src/d_main.c
index 1df9cabf..89b6c472 100644
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: d_main.c 237 2006-01-01 23:53:15Z fraggle $
+// $Id: d_main.c 241 2006-01-02 00:17:42Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.34 2006/01/02 00:17:42 fraggle
+// Encapsulate the event queue code properly. Add a D_PopEvent function
+// to read a new event from the event queue.
+//
// Revision 1.33 2006/01/01 23:53:14 fraggle
// Remove GS_WAITINGSTART gamestate. This will be independent of the main
// loop to avoid interfering with the main game code too much.
@@ -150,7 +154,7 @@
//-----------------------------------------------------------------------------
-static const char rcsid[] = "$Id: d_main.c 237 2006-01-01 23:53:15Z fraggle $";
+static const char rcsid[] = "$Id: d_main.c 241 2006-01-02 00:17:42Z fraggle $";
#define BGCOLOR 7
#define FGCOLOR 8
@@ -278,9 +282,12 @@ void D_DoAdvanceDemo (void);
// Events are asynchronous inputs generally generated by the game user.
// Events can be discarded if no responder claims them
//
-event_t events[MAXEVENTS];
-int eventhead;
-int eventtail;
+
+#define MAXEVENTS 64
+
+static event_t events[MAXEVENTS];
+static int eventhead;
+static int eventtail;
//
@@ -290,7 +297,29 @@ int eventtail;
void D_PostEvent (event_t* ev)
{
events[eventhead] = *ev;
- eventhead = (eventhead + 1) & (MAXEVENTS-1);
+ eventhead = (eventhead + 1) % MAXEVENTS;
+}
+
+// Read an event from the queue.
+
+event_t *D_PopEvent(void)
+{
+ event_t *result;
+
+ // No more events waiting.
+
+ if (eventtail == eventhead)
+ {
+ return NULL;
+ }
+
+ result = &events[eventtail];
+
+ // Advance to the next event in the queue.
+
+ eventtail = (eventtail + 1) % MAXEVENTS;
+
+ return result;
}
@@ -307,10 +336,8 @@ void D_ProcessEvents (void)
&& (W_CheckNumForName("map01")<0) )
return;
- for ( ; eventtail != eventhead ;
- eventtail = (eventtail + 1) & (MAXEVENTS-1) )
+ while ((ev = D_PopEvent()) != NULL)
{
- ev = &events[eventtail];
if (M_Responder (ev))
continue; // menu ate the event
G_Responder (ev);