Skip to content

Commit

Permalink
Fixed|Input: Controls menu does not wait for axis movement
Browse files Browse the repository at this point in the history
When making axis bindings, check the position relative to the axis position at the beginning.

IssueID #2307
  • Loading branch information
skyjake committed Feb 16, 2019
1 parent 7fabe30 commit f54c669
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
3 changes: 3 additions & 0 deletions doomsday/apps/client/include/ui/axisinputcontrol.h
Expand Up @@ -62,6 +62,9 @@ class AxisInputControl : public InputDevice::Control
de::ddouble position() const;
void setPosition(de::ddouble newPosition);

void markPosition();
de::ddouble markedPosition() const;

/**
* Update the position of the axis control from a "real" position.
*
Expand Down
15 changes: 13 additions & 2 deletions doomsday/apps/client/src/ui/axisinputcontrol.cpp
Expand Up @@ -35,8 +35,9 @@ DENG2_PIMPL_NOREF(AxisInputControl)
Type type = Pointer;
dint flags = 0;

ddouble position = 0; ///< Current translated position (-1..1) including any filtering.
ddouble realPosition = 0; ///< The actual latest position (-1..1).
ddouble position = 0; ///< Current translated position (-1..1) including any filtering.
ddouble realPosition = 0; ///< The actual latest position (-1..1).
ddouble markedPosition = 0;

dfloat offset = 0; ///< Offset to add to real input value.
dfloat scale = 1; ///< Scaling factor for real input values.
Expand Down Expand Up @@ -185,6 +186,16 @@ void AxisInputControl::setPosition(ddouble newPosition)
d->position = newPosition;
}

void AxisInputControl::markPosition()
{
d->markedPosition = d->position;
}

ddouble AxisInputControl::markedPosition() const
{
return d->markedPosition;
}

void AxisInputControl::applyRealPosition(dfloat pos)
{
DENG2_GUARD(this);
Expand Down
35 changes: 26 additions & 9 deletions doomsday/apps/client/src/ui/inputsystem.cpp
Expand Up @@ -414,10 +414,11 @@ DENG2_PIMPL(InputSystem)
// enough for an echo.
if (ev.type == E_AXIS)
{
InputDevice const &device = self().device(ev.device);
float const pos = device.axis(ev.axis.id).translateRealPosition(ev.axis.pos);
const InputDevice &device = self().device(ev.device);
const float pos = device.axis(ev.axis.id).translateRealPosition(ev.axis.pos);
const float markedPos = float(device.axis(ev.axis.id).markedPosition());

if ((ev.axis.type == EAXIS_ABSOLUTE && fabs(pos) < .5f) ||
if ((ev.axis.type == EAXIS_ABSOLUTE && fabs(pos - markedPos) < .5f) ||
(ev.axis.type == EAXIS_RELATIVE && fabs(pos) < .02f))
{
return; // Not significant enough.
Expand All @@ -427,10 +428,10 @@ DENG2_PIMPL(InputSystem)
// Echo the event.
String name = "echo-" + B_EventToString(ev);

Block const nameUtf8 = name.toUtf8();
ddevent_t echo; de::zap(echo);
echo.device = uint(-1);
echo.type = E_SYMBOLIC;
const Block nameUtf8 = name.toUtf8();
ddevent_t echo{};
echo.device = -1;
echo.type = E_SYMBOLIC;
echo.symbolic.id = 0;
echo.symbolic.name = nameUtf8.constData();

Expand Down Expand Up @@ -950,8 +951,24 @@ InputSystem::InputSystem() : d(new Impl(this))
initAllDevices();
}

void InputSystem::timeChanged(Clock const &)
{}
void InputSystem::timeChanged(const Clock &)
{
// Symbolic echo mode is used when creating input bindings interactively.
// For axis controls, we need to know the difference to whatever position
// the axis had before symbolic mode started, so here we mark the current
// position.

if (!symbolicEchoMode)
{
for (auto *device : d->devices)
{
for (int i = 0; i < device->axisCount(); ++i)
{
device->axis(i).markPosition();
}
}
}
}

ConfigProfiles &InputSystem::settings()
{
Expand Down

0 comments on commit f54c669

Please sign in to comment.