Skip to content

Commit

Permalink
Fixed: Ignoring input (e.g., during busy mode)
Browse files Browse the repository at this point in the history
The "ignore input" mode was not fully functional. Now events will be
posted even during busy mode, but instead of normal processing
they will only get minimal treatment. For instance, the state of the
Shift key is tracked but events won't be passed to any responders.
  • Loading branch information
skyjake committed Jan 28, 2012
1 parent 0397a33 commit c51e6b6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/dd_input.h
Expand Up @@ -163,7 +163,6 @@ typedef struct inputdev_s {
inputdevhat_t *hats;
} inputdev_t;

extern boolean ignoreInput;
extern int repWait1, repWait2;
extern int keyRepeatDelay1, keyRepeatDelay2; // milliseconds
extern boolean shiftDown, altDown;
Expand All @@ -173,6 +172,7 @@ void DD_InitInput(void);
void DD_ShutdownInput(void);
void DD_StartInput(void);
void DD_StopInput(void);
boolean DD_IgnoreInput(boolean ignore);

void DD_ReadKeyboard(void);
void DD_ReadMouse(timespan_t ticLength);
Expand Down
21 changes: 10 additions & 11 deletions doomsday/engine/portable/src/con_busy.c
Expand Up @@ -106,6 +106,7 @@ static boolean animatedTransitionActive(int busyMode)
int Con_Busy2(BusyTask* task)
{
boolean willAnimateTransition;
boolean wasIgnoringInput;
int result;

if(!task) return 0;
Expand All @@ -126,10 +127,9 @@ int Con_Busy2(BusyTask* task)
Con_Error("Con_Busy: Already busy.\n");
}

// Activate the UI binding context so that any and all accumulated input
// events are discarded when done.
DD_ClearKeyRepeaters();
B_ActivateContext(B_ContextByName(UI_BINDING_CONTEXT_NAME), true);
// Discard input events so that any and all accumulated input
// events are ignored.
wasIgnoringInput = DD_IgnoreInput(true);

Sys_Lock(busy_Mutex);
busyDone = false;
Expand Down Expand Up @@ -166,13 +166,7 @@ int Con_Busy2(BusyTask* task)
Con_AbnormalShutdown((const char*) busyError);
}

if(!transitionInProgress)
{
// Clear any input events that might have accumulated whilst busy.
DD_ClearEvents();
B_ActivateContext(B_ContextByName(UI_BINDING_CONTEXT_NAME), false);
}
else
if(transitionInProgress)
{
transitionStartTime = Sys_GetTime();
transitionPosition = 0;
Expand All @@ -192,6 +186,8 @@ int Con_Busy2(BusyTask* task)
GL_ProcessDeferredTasks(0);
}

DD_IgnoreInput(wasIgnoringInput);

return result;
}

Expand Down Expand Up @@ -445,6 +441,9 @@ static void Con_BusyLoop(void)
busyDoneCopy = busyDone;
Sys_Unlock(busy_Mutex);

// Post and discard all input events.
DD_ProcessEvents(0);

Sys_Sleep(20);

if(canUpload)
Expand Down
33 changes: 26 additions & 7 deletions doomsday/engine/portable/src/dd_input.c
Expand Up @@ -76,12 +76,12 @@ D_CMD(ListInputDevices);

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

static void postEvents(timespan_t ticLength);

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

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

boolean ignoreInput = false;

int mouseFilter = 1; // Filtering on by default.

// The initial and secondary repeater delays (tics).
Expand All @@ -94,6 +94,8 @@ inputdev_t inputDevices[NUM_INPUT_DEVICES];

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

static boolean ignoreInput = false;

static byte shiftKeyMappings[NUMKKEYS], altKeyMappings[NUMKKEYS];

static eventqueue_t queue;
Expand Down Expand Up @@ -545,7 +547,7 @@ static void I_UpdateAxis(inputdev_t *dev, uint axis, float pos, timespan_t ticLe

if(a->type == IDAT_STICK)
a->position = pos; //a->realPosition;
else // Cumulative.
else if(!ignoreInput) // Cumulative.
a->position += pos; //a->realPosition;

// We can clear the expiration when it returns to default state.
Expand Down Expand Up @@ -741,6 +743,23 @@ static void clearQueue(eventqueue_t* q)
q->head = q->tail;
}

boolean DD_IgnoreInput(boolean ignore)
{
boolean old = ignoreInput;
ignoreInput = ignore;
#ifdef _DEBUG
Con_Message("DD_IgnoreInput: ignoring=%i\n", ignore);
#endif
if(!ignore)
{
// Clear all the event buffers.
postEvents(0);
DD_ClearEvents();
DD_ClearKeyRepeaters();
}
return old;
}

/**
* Clear the input event queue.
*/
Expand Down Expand Up @@ -911,12 +930,12 @@ static void dispatchEvents(eventqueue_t* q, timespan_t ticLength)
{
event_t ev;

if(ignoreInput)
continue;

// Update the state of the input device tracking table.
I_TrackInput(ddev, ticLength);

if(ignoreInput)
continue;

DD_ConvertEvent(ddev, &ev);

if(callGameResponders)
Expand Down Expand Up @@ -1208,7 +1227,7 @@ void DD_ReadMouse(timespan_t ticLength)
xpos = mouse.x;
ypos = mouse.y;

if(mouseFilter > 0)
if(ticLength > 0 && mouseFilter > 0)
{
// Filtering ensures that events are sent more evenly on each frame.
static float accumulation[2] = { 0, 0 };
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/src/dd_loop.c
Expand Up @@ -329,6 +329,7 @@ boolean DD_IsSharpTick(void)
*/
boolean DD_IsFrameTimeAdvancing(void)
{
if(Con_IsBusy()) return false;
if(Con_TransitionInProgress()) return false;
return tickFrame || netGame;
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/win32/src/dd_winit.c
Expand Up @@ -552,7 +552,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

case WM_CLOSE:
PostQuitMessage(0);
ignoreInput = TRUE;
DD_IgnoreInput(true);
forwardMsg = FALSE;
break;

Expand Down Expand Up @@ -605,12 +605,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
DD_ClearEvents(); // For good measure.
ignoreInput = FALSE;
DD_IgnoreInput(false);
}
else
{
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
ignoreInput = TRUE;
DD_IgnoreInput(true);
}
}
forwardMsg = FALSE;
Expand Down

0 comments on commit c51e6b6

Please sign in to comment.