Skip to content

Commit

Permalink
Bindings: Zero controls when receiving conflicting input
Browse files Browse the repository at this point in the history
Added cvar "input-conflict-zerocontrol" (default: 1) that causes
controls that are being simultaneously affected by more than one
device states from the same input device to be cleared to zero.

This corrects a behavioral compatibility issue where holding down
a turn key when already turning to the other direction would cause
the control position to first go through the half-speed stage
before zeroing.

Another possible solution to address this issue would be to track
staging per control rather than per input device state (i.e., now
there is a timer for each key of the keyboard and none for the
control itself), but implementing that would be too much work
during Candidate phase. It should be done at a later time, though.
  • Loading branch information
skyjake committed Jan 28, 2012
1 parent 0bd0feb commit b2b10de
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doomsday/engine/data/cphelp.txt
Expand Up @@ -957,6 +957,9 @@ desc = Maximum limit for the frame rate (default: 200).
[input-toggle-sharp]
desc = 1=Process toggle events only on sharp ticks for backwards compatible behavior.

[input-conflict-zerocontrol]
desc = 1=If a control is influenced by two or more conflicting input device states, the control position gets zeroed.

[input-key-delay1]
desc = The number of milliseconds to wait before first key repeat.

Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/b_device.h
Expand Up @@ -34,7 +34,8 @@
typedef enum cbdevtype_e {
CBD_TOGGLE,
CBD_AXIS,
CBD_ANGLE
CBD_ANGLE,
NUM_CBD_TYPES
} cbdevtype_t;

// Flags for control-device bindings.
Expand Down
23 changes: 23 additions & 0 deletions doomsday/engine/portable/src/b_device.c
Expand Up @@ -55,6 +55,7 @@

float stageThreshold = 6.f/35;
float stageFactor = .5f;
byte zeroControlUponConflict = true;

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

Expand Down Expand Up @@ -288,6 +289,8 @@ void B_EvaluateDeviceBindingList(int localNum, dbinding_t* listRoot, float* pos,
float deviceOffset;
uint deviceTime;
uint nowTime = Sys_GetRealTime();
boolean conflicted[NUM_CBD_TYPES] = { false, false, false };
boolean appliedState[NUM_CBD_TYPES] = { false, false, false };

*pos = 0;
*relativeOffset = 0;
Expand Down Expand Up @@ -397,6 +400,26 @@ void B_EvaluateDeviceBindingList(int localNum, dbinding_t* listRoot, float* pos,

*pos += devicePos;
*relativeOffset += deviceOffset;

// Is this state contributing to the outcome?
if(!FEQUAL(devicePos, 0.f))
{
if(appliedState[cb->type])
{
// Another binding already influenced this; we have a conflict.
conflicted[cb->type] = true;
}

// We've found one effective binding that influences this control.
appliedState[cb->type] = true;
}
}

if(zeroControlUponConflict)
{
for(i = 0; i < NUM_CBD_TYPES; ++i)
if(conflicted[i])
*pos = 0;
}

// Clamp appropriately.
Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/portable/src/b_main.c
Expand Up @@ -154,6 +154,10 @@ static const keyname_t keyNames[] = {

void B_Register(void)
{
extern byte zeroControlUponConflict;

C_VAR_BYTE("input-conflict-zerocontrol", &zeroControlUponConflict, 0, 0, 1);

#define PROTECTED_FLAGS (CMDF_NO_DEDICATED|CMDF_DED|CMDF_CLIENT)

C_CMD_FLAGS("bindevent", "ss", BindEventToCommand, PROTECTED_FLAGS);
Expand Down

0 comments on commit b2b10de

Please sign in to comment.