[chocolate-doom] 13/79: Encapsulate the event queue code properly. Add a D_PopEvent function to read a new event from the event queue.

Jonathan Dowland jmtd at moszumanska.debian.org
Mon Jan 30 15:07:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

jmtd pushed a commit to annotated tag chocolate-doom-0.1.3
in repository chocolate-doom.

commit cdbc892c80a42bf0bbd3559831eb9675b5f019f4
Author: Simon Howard <fraggle at gmail.com>
Date:   Mon Jan 2 00:17:42 2006 +0000

    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
---
 src/d_event.h | 11 +++++------
 src/d_main.c  | 45 ++++++++++++++++++++++++++++++++++++---------
 src/d_main.h  | 12 ++++++++++--
 src/d_net.c   | 14 +++++++++-----
 4 files changed, 60 insertions(+), 22 deletions(-)

diff --git a/src/d_event.h b/src/d_event.h
index ed02f4a..0fba28f 100644
--- 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,11 +112,6 @@ typedef enum
 //
 // GLOBAL VARIABLES
 //
-#define MAXEVENTS		64
-
-extern  event_t		events[MAXEVENTS];
-extern  int             eventhead;
-extern	int		eventtail;
 
 extern  gameaction_t    gameaction;
 
@@ -125,6 +120,10 @@ extern  gameaction_t    gameaction;
 //-----------------------------------------------------------------------------
 //
 // $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
 //
diff --git a/src/d_main.c b/src/d_main.c
index 1df9cab..89b6c47 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);
diff --git a/src/d_main.h b/src/d_main.h
index bcc2d6a..c227cdd 100644
--- 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_AddFile (char *file);
 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);
 
 	
 
diff --git a/src/d_net.c b/src/d_net.c
index 0e9fa25..6f90b5d 100644
--- 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 @@ void CheckAbort (void)
 	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.");
     } 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/chocolate-doom.git



More information about the Pkg-games-commits mailing list