Skip to content

Commit

Permalink
Fixed an input event processing bug that happened when
Browse files Browse the repository at this point in the history
the input event queue was cleared during DD_ProcessEvents.
The head and tail got mixed up and caused the buffer to loop
around and repeat everything.
  • Loading branch information
skyjake committed Jun 5, 2004
1 parent d1619f7 commit 39d2839
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions doomsday/Src/dd_input.c
Expand Up @@ -44,10 +44,6 @@ typedef struct repeater_s {

// PUBLIC DATA DEFINITIONS -------------------------------------------------

event_t events[MAXEVENTS];
int eventhead;
int eventtail;

int mouseFilter = 0; // No filtering by default.
int mouseInverseY = false;
int mouseWheelSensi = 10; // I'm shooting in the dark here.
Expand All @@ -68,6 +64,10 @@ byte shiftKeyMappings[256], altKeyMappings[256];

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static event_t events[MAXEVENTS];
static int eventhead;
static int eventtail;

/* *INDENT-OFF* */
static byte scantokey[256] =
{
Expand Down Expand Up @@ -332,10 +332,44 @@ int CCmdKeyMap(int argc, char **argv)
return true;
}

//==========================================================================
// DD_ProcessEvents
// Send all the events of the given timestamp down the responder chain.
//==========================================================================
/*
* Clear the input event queue.
*/
void DD_ClearEvents(void)
{
eventhead = eventtail;
}

/*
* Called by the I/O functions when input is detected.
*/
void DD_PostEvent(event_t *ev)
{
events[eventhead++] = *ev;
eventhead &= MAXEVENTS - 1;
}

/*
* Get the next event from the input event queue. Returns NULL if no
* more events are available.
*/
static event_t *DD_GetEvent(void)
{
event_t *ev;

if(eventhead == eventtail)
return NULL;

ev = &events[eventtail];
eventtail = (eventtail + 1) & (MAXEVENTS - 1);

return ev;
}

/*
* Send all the events of the given timestamp down the responder
* chain.
*/
void DD_ProcessEvents(void)
{
event_t *ev;
Expand All @@ -344,10 +378,8 @@ void DD_ProcessEvents(void)
DD_ReadJoystick();
DD_ReadKeyboard();

for(; eventtail != eventhead; eventtail = (++eventtail) & (MAXEVENTS - 1))
while((ev = DD_GetEvent()) != NULL)
{
ev = &events[eventtail];

// Track the state of Shift and Alt.
if(ev->data1 == DDKEY_RSHIFT)
{
Expand Down Expand Up @@ -387,16 +419,6 @@ void DD_ProcessEvents(void)
}
}

//==========================================================================
// DD_PostEvent
// Called by the I/O functions when input is detected.
//==========================================================================
void DD_PostEvent(event_t *ev)
{
events[eventhead++] = *ev;
eventhead &= MAXEVENTS - 1;
}

//===========================================================================
// DD_ScanToKey
//===========================================================================
Expand Down Expand Up @@ -431,14 +453,6 @@ byte DD_KeyToScan(byte key)
return 0;
}

/*
* Clear the input event queue.
*/
void DD_ClearEvents(void)
{
eventhead = eventtail;
}

//===========================================================================
// DD_ClearKeyRepeaters
//===========================================================================
Expand Down

0 comments on commit 39d2839

Please sign in to comment.