ref: cdbc892c80a42bf0bbd3559831eb9675b5f019f4
parent: 7f731a106441c357ae9e3509d7541cf87bcc9a63
author: Simon Howard <[email protected]>
date: Sun Jan 1 19:17:42 EST 2006
Encapsulate the event queue code properly. Add a D_PopEvent function to read a new event from the event queue. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 241
--- a/src/d_event.h
+++ b/src/d_event.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: d_event.h 8 2005-07-23 16:44:57Z fraggle $
+// $Id: d_event.h 241 2006-01-02 00:17:42Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -112,12 +112,7 @@
//
// GLOBAL VARIABLES
//
-#define MAXEVENTS 64
-extern event_t events[MAXEVENTS];
-extern int eventhead;
-extern int eventtail;
-
extern gameaction_t gameaction;
@@ -125,6 +120,10 @@
//-----------------------------------------------------------------------------
//
// $Log$
+// Revision 1.3 2006/01/02 00:17:41 fraggle
+// Encapsulate the event queue code properly. Add a D_PopEvent function
+// to read a new event from the event queue.
+//
// Revision 1.2 2005/07/23 16:44:55 fraggle
// Update copyright to GNU GPL
//
--- 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,11 +282,14 @@
// 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;
+
+
//
// D_PostEvent
// Called by the I/O functions when input is detected
@@ -290,10 +297,32 @@
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;
+}
+
+
//
// D_ProcessEvents
// Send all the events of the given timestamp down the responder chain
@@ -307,10 +336,8 @@
&& (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);
--- a/src/d_main.h
+++ b/src/d_main.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: d_main.h 18 2005-07-23 18:56:07Z fraggle $
+// $Id: d_main.h 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.4 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.3 2005/07/23 18:56:07 fraggle
// Remove unneccessary pragmas
//
@@ -62,7 +66,11 @@
void D_DoomMain (void);
// Called by IO functions when input is detected.
-void D_PostEvent (event_t* ev);
+void D_PostEvent (event_t *ev);
+
+// Read an event from the event queue
+
+event_t *D_PopEvent(void);
--- a/src/d_net.c
+++ b/src/d_net.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: d_net.c 239 2006-01-02 00:00:08Z fraggle $
+// $Id: d_net.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.13 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.12 2006/01/02 00:00:08 fraggle
// Neater prefixes: NET_Client -> NET_CL_. NET_Server -> NET_SV_.
//
@@ -73,9 +77,10 @@
//-----------------------------------------------------------------------------
-static const char rcsid[] = "$Id: d_net.c 239 2006-01-02 00:00:08Z fraggle $";
+static const char rcsid[] = "$Id: d_net.c 241 2006-01-02 00:17:42Z fraggle $";
+#include "d_main.h"
#include "m_menu.h"
#include "i_system.h"
#include "i_video.h"
@@ -518,10 +523,9 @@
I_StartTic ();
I_StartTic ();
- for ( ; eventtail != eventhead
- ; eventtail = (eventtail + 1) & (MAXEVENTS-1) )
+
+ while ((ev = D_PopEvent()) != NULL)
{
- ev = &events[eventtail];
if (ev->type == ev_keydown && ev->data1 == KEY_ESCAPE)
I_Error ("Network game synchronization aborted.");
}