Skip to content

Commit

Permalink
Input: Never late process sharp axis/angle events
Browse files Browse the repository at this point in the history
Mouse and joystick movement needs low latency, so it's better to not
late process the events even though "input-sharp-lateprocessing" is set.

Added a separate event queue for "late sharp" events.
  • Loading branch information
skyjake committed May 12, 2012
1 parent 832d11c commit 477a59e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/dd_input.h
Expand Up @@ -209,6 +209,7 @@ void DD_ReadJoystick(void);
void DD_PostEvent(ddevent_t *ev);
void DD_ProcessEvents(timespan_t ticLength);
void DD_ProcessSharpEvents(timespan_t ticLength);
void DD_ProcessLateSharpEvents(void);
void DD_ClearEvents(void);
void DD_ClearKeyRepeaters(void);
void DD_ClearKeyRepeaterForKey(int ddkey, int native);
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/src/con_busy.c
Expand Up @@ -464,6 +464,7 @@ static void BusyTask_Loop(void)
// Post and discard all input events.
DD_ProcessEvents(0);
DD_ProcessSharpEvents(0);
DD_ProcessLateSharpEvents();

if(canUpload)
{
Expand Down
44 changes: 33 additions & 11 deletions doomsday/engine/portable/src/dd_input.c
Expand Up @@ -78,6 +78,7 @@ int repWait1 = 15, repWait2 = 3;
int keyRepeatDelay1 = 430, keyRepeatDelay2 = 85; // milliseconds
unsigned int mouseFreq = 0;
boolean shiftDown = false, altDown = false;
byte processSharpTogglesAfterTickers = true;

inputdev_t inputDevices[NUM_INPUT_DEVICES];

Expand All @@ -89,7 +90,8 @@ static boolean ignoreInput = false;
static byte shiftKeyMappings[NUMKKEYS], altKeyMappings[NUMKKEYS];

static eventqueue_t queue;
static eventqueue_t sharpQueue;
static eventqueue_t sharpQueue; // for axes/angles
static eventqueue_t lateSharpQueue; // for toggles

static char defaultShiftTable[96] = // Contains characters 32 to 127.
{
Expand Down Expand Up @@ -126,6 +128,7 @@ void DD_RegisterInput(void)
C_VAR_INT("input-key-delay1", &keyRepeatDelay1, CVF_NO_MAX, 50, 0);
C_VAR_INT("input-key-delay2", &keyRepeatDelay2, CVF_NO_MAX, 20, 0);
C_VAR_BYTE("input-sharp", &useSharpInputEvents, 0, 0, 1);
C_VAR_BYTE("input-sharp-lateprocessing", &processSharpTogglesAfterTickers, 0, 0, 1);

#if _DEBUG
C_VAR_BYTE("rend-dev-input-joy-state", &devRendJoyState, CVF_NO_ARCHIVE, 0, 1);
Expand Down Expand Up @@ -899,6 +902,7 @@ void DD_ClearEvents(void)
{
clearQueue(&queue);
clearQueue(&sharpQueue);
clearQueue(&lateSharpQueue);

DD_ClearEventStrings();
}
Expand Down Expand Up @@ -926,7 +930,10 @@ void DD_PostEvent(ddevent_t *ev)
if(useSharpInputEvents && (ev->type == E_TOGGLE || ev->type == E_AXIS ||
ev->type == E_ANGLE))
{
q = &sharpQueue;
if(ev->type == E_TOGGLE && processSharpTogglesAfterTickers)
q = &lateSharpQueue;
else
q = &sharpQueue;
}

// Cleanup: make sure only keyboard toggles can have a text insert.
Expand Down Expand Up @@ -1079,7 +1086,7 @@ static void updateDeviceAxes(timespan_t ticLength)
/**
* Send all the events of the given timestamp down the responder chain.
*/
static void dispatchEvents(eventqueue_t* q, timespan_t ticLength, boolean updateAxes)
static void dispatchEvents(eventqueue_t* q)
{
const boolean callGameResponders = DD_GameLoaded();
ddevent_t* ddev;
Expand Down Expand Up @@ -1129,12 +1136,6 @@ static void dispatchEvents(eventqueue_t* q, timespan_t ticLength, boolean update
if(callGameResponders && gx.FallbackResponder)
gx.FallbackResponder(&ev);
}

if(updateAxes)
{
// Input events have modified input device state: update the axis positions.
updateDeviceAxes(ticLength);
}
}

/**
Expand Down Expand Up @@ -1167,15 +1168,36 @@ void DD_ProcessEvents(timespan_t ticLength)
postEvents();

// Dispatch all accumulated events down the responder chain.
dispatchEvents(&queue, ticLength, !useSharpInputEvents);
dispatchEvents(&queue);

if(!useSharpInputEvents)
{
// Input events have modified input device state: update the axis positions.
updateDeviceAxes(ticLength);
}
}

void DD_ProcessSharpEvents(timespan_t ticLength)
{
// Sharp ticks may have some events queued on the side.
if(DD_IsSharpTick() || !DD_IsFrameTimeAdvancing())
{
dispatchEvents(&sharpQueue, DD_IsFrameTimeAdvancing()? SECONDSPERTIC : ticLength, true);
dispatchEvents(&sharpQueue);

if(useSharpInputEvents)
{
// Input events have modified input device state: update the axis positions.
updateDeviceAxes(DD_IsFrameTimeAdvancing()? SECONDSPERTIC : ticLength);
}
}
}

void DD_ProcessLateSharpEvents(void)
{
// Sharp ticks may have some events queued on the side.
if(DD_IsSharpTick() || !DD_IsFrameTimeAdvancing())
{
dispatchEvents(&lateSharpQueue);
}
}

Expand Down
19 changes: 5 additions & 14 deletions doomsday/engine/portable/src/dd_loop.c
Expand Up @@ -60,7 +60,6 @@ int maxFrameRate = 120; // Zero means 'unlimited'.
// Refresh frame count (independant of the viewport-specific frameCount).
int rFrameCount = 0;
byte devShowFrameTimeDeltas = false;
byte processSharpEventsAfterTickers = true;

timespan_t sysTime, gameTime, demoTime, ddMapTime;
//timespan_t frameStartTime;
Expand Down Expand Up @@ -92,10 +91,8 @@ static void runTics(void);

void DD_RegisterLoop(void)
{
C_VAR_BYTE("input-sharp-lateprocessing", &processSharpEventsAfterTickers, 0, 0, 1);
C_VAR_INT("refresh-rate-maximum", &maxFrameRate, 0, 35, 1000);
C_VAR_INT("rend-dev-framecount", &rFrameCount,
CVF_NO_ARCHIVE | CVF_PROTECTED, 0, 0);
C_VAR_INT("rend-dev-framecount", &rFrameCount, CVF_NO_ARCHIVE | CVF_PROTECTED, 0, 0);
C_VAR_BYTE("rend-info-deltas-frametime", &devShowFrameTimeDeltas, CVF_NO_ARCHIVE, 0, 1);
}

Expand Down Expand Up @@ -584,20 +581,14 @@ static void runTics(void)

// Process input events.
DD_ProcessEvents(ticLength);
if(!processSharpEventsAfterTickers)
{
// We are allowed to process sharp events before tickers.
DD_ProcessSharpEvents(ticLength);
}
DD_ProcessSharpEvents(ticLength); // only on sharp 35 Hz ticks

// Call all the tickers.
baseTicker(ticLength);

if(processSharpEventsAfterTickers)
{
// This is done after tickers for compatibility with ye olde game logic.
DD_ProcessSharpEvents(ticLength);
}
// This is done after tickers for compatibility with ye olde game logic.
// (cvar: input-sharp-lateprocessing)
DD_ProcessLateSharpEvents(); // only on sharp 35 Hz ticks

// Various global variables are used for counting time.
advanceTime(ticLength);
Expand Down

0 comments on commit 477a59e

Please sign in to comment.