Skip to content

Commit

Permalink
Update last known distance values for elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Oct 7, 2015
1 parent 66398f5 commit ef8061d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
20 changes: 19 additions & 1 deletion src/inputdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,39 @@ void InputDevice::setActiveSetNumber(int index)
// Grab current states for all elements in old set
SetJoystick *current_set = joystick_sets.value(active_set);
SetJoystick *old_set = current_set;
SetJoystick *tempSet = joystick_sets.value(index);

for (int i = 0; i < current_set->getNumberButtons(); i++)
{
JoyButton *button = current_set->getJoyButton(i);
buttonstates.append(button->getButtonState());
tempSet->getJoyButton(i)->copyLastMouseDistanceFromDeadZone(button);
tempSet->getJoyButton(i)->copyLastAccelerationDistance(button);
}

for (int i = 0; i < current_set->getNumberAxes(); i++)
{
JoyAxis *axis = current_set->getJoyAxis(i);
axesstates.append(axis->getCurrentRawValue());
tempSet->getJoyAxis(i)->copyRawValues(axis);
tempSet->getJoyAxis(i)->copyThrottledValues(axis);
}

for (int i = 0; i < current_set->getNumberHats(); i++)
{
JoyDPad *dpad = current_set->getJoyDPad(i);
dpadstates.append(dpad->getCurrentDirection());

JoyButton *button = dpad->getJoyButton(dpad->getCurrentDirection());
JoyButton *tempSetButton = tempSet->getJoyDPad(i)->getJoyButton(dpad->getCurrentDirection());
tempSetButton->copyLastAccelerationDistance(button);
tempSetButton->copyLastMouseDistanceFromDeadZone(button);
}

for (int i=0; i < current_set->getNumberSticks(); i++)
{
// Last distances for elements are taken from associated axes.
// Copying is not required here.
JoyControlStick *stick = current_set->getJoyStick(i);
stickstates.append(stick->getCurrentDirection());
}
Expand All @@ -198,6 +211,11 @@ void InputDevice::setActiveSetNumber(int index)
{
JoyDPad *dpad = current_set->getVDPad(i);
vdpadstates.append(dpad->getCurrentDirection());

JoyButton *button = dpad->getJoyButton(dpad->getCurrentDirection());
JoyButton *tempSetButton = tempSet->getJoyDPad(i)->getJoyButton(dpad->getCurrentDirection());
tempSetButton->copyLastAccelerationDistance(button);
tempSetButton->copyLastMouseDistanceFromDeadZone(button);
}

// Release all current pressed elements and change set number
Expand Down Expand Up @@ -478,7 +496,7 @@ void InputDevice::setActiveSetNumber(int index)
}

//axis->joyEvent(value, tempignore);
axis->queuePendingEvent(value, tempignore);
axis->queuePendingEvent(value, tempignore, false);
}

// Activate all dpad buttons in the switched set
Expand Down
42 changes: 32 additions & 10 deletions src/joyaxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,36 @@ JoyAxis::~JoyAxis()
reset();
}

void JoyAxis::queuePendingEvent(int value, bool ignoresets)
void JoyAxis::queuePendingEvent(int value, bool ignoresets, bool updateLastValues)
{
pendingEvent = false;
pendingValue = 0;
pendingIgnoreSets = false;
pendingUpdateLastValues = true;

if (this->stick)
{
stickPassEvent(value, ignoresets);
stickPassEvent(value, ignoresets, updateLastValues);
}
else
{
pendingEvent = true;
pendingValue = value;
pendingIgnoreSets = ignoresets;
pendingUpdateLastValues = updateLastValues;
}
}

void JoyAxis::activatePendingEvent()
{
if (pendingEvent)
{
joyEvent(pendingValue);
joyEvent(pendingValue, pendingUpdateLastValues);

pendingEvent = false;
pendingValue = false;
pendingIgnoreSets = false;
pendingUpdateLastValues = true;
}
}

Expand All @@ -99,12 +102,15 @@ void JoyAxis::clearPendingEvent()
pendingIgnoreSets = false;
}

void JoyAxis::stickPassEvent(int value, bool ignoresets)
void JoyAxis::stickPassEvent(int value, bool ignoresets, bool updateLastValues)
{
if (this->stick)
{
lastKnownThottledValue = currentThrottledValue;
lastKnownRawValue = currentRawValue;
if (updateLastValues)
{
lastKnownThottledValue = currentThrottledValue;
lastKnownRawValue = currentRawValue;
}

setCurrentRawValue(value);
//currentRawValue = value;
Expand Down Expand Up @@ -135,16 +141,19 @@ void JoyAxis::stickPassEvent(int value, bool ignoresets)
}
}

void JoyAxis::joyEvent(int value, bool ignoresets)
void JoyAxis::joyEvent(int value, bool ignoresets, bool updateLastValues)
{
if (this->stick && !pendingEvent)
{
stickPassEvent(value, ignoresets);
stickPassEvent(value, ignoresets, updateLastValues);
}
else
{
lastKnownThottledValue = currentThrottledValue;
lastKnownRawValue = currentRawValue;
if (updateLastValues)
{
lastKnownThottledValue = currentThrottledValue;
lastKnownRawValue = currentRawValue;
}

setCurrentRawValue(value);
//currentRawValue = value;
Expand Down Expand Up @@ -586,6 +595,7 @@ void JoyAxis::reset()
pendingEvent = false;
pendingValue = currentRawValue;
pendingIgnoreSets = false;
pendingUpdateLastValues = true;
}

void JoyAxis::reset(int index)
Expand Down Expand Up @@ -1130,3 +1140,15 @@ JoyButton::JoyExtraAccelerationCurve JoyAxis::getExtraAccelerationCurve()

return result;
}

void JoyAxis::copyRawValues(JoyAxis *srcAxis)
{
this->lastKnownRawValue = srcAxis->lastKnownRawValue;
this->currentRawValue = srcAxis->currentRawValue;
}

void JoyAxis::copyThrottledValues(JoyAxis *srcAxis)
{
this->lastKnownThottledValue = srcAxis->lastKnownThottledValue;
this->currentThrottledValue = srcAxis->currentThrottledValue;
}
12 changes: 8 additions & 4 deletions src/joyaxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class JoyAxis : public QObject
PositiveHalfThrottle = 2
};

void joyEvent(int value, bool ignoresets=false);
void queuePendingEvent(int value, bool ignoresets=false);
void joyEvent(int value, bool ignoresets=false, bool updateLastValues=true);
void queuePendingEvent(int value, bool ignoresets=false, bool updateLastValues=true);
void activatePendingEvent();
bool hasPendingEvent();
void clearPendingEvent();
Expand Down Expand Up @@ -132,6 +132,10 @@ class JoyAxis : public QObject
int getLastKnownRawValue();
int getProperReleaseValue();

// Don't use direct assignment but copying from a current axis.
void copyRawValues(JoyAxis *srcAxis);
void copyThrottledValues(JoyAxis *srcAxis);

void setExtraAccelerationCurve(JoyButton::JoyExtraAccelerationCurve curve);
JoyButton::JoyExtraAccelerationCurve getExtraAccelerationCurve();

Expand All @@ -152,7 +156,7 @@ class JoyAxis : public QObject
int calculateThrottledValue(int value);
void setCurrentRawValue(int value);
void performCalibration(int value);
void stickPassEvent(int value, bool ignoresets=false);
void stickPassEvent(int value, bool ignoresets=false, bool updateLastValues=true);

virtual bool readMainConfig(QXmlStreamReader *xml);
virtual bool readButtonConfig(QXmlStreamReader *xml);
Expand All @@ -177,13 +181,13 @@ class JoyAxis : public QObject
QString axisName;
QString defaultAxisName;
SetJoystick *parentSet;
double lastMouseDistance;
int lastKnownThottledValue;
int lastKnownRawValue;

int pendingValue;
bool pendingEvent;
bool pendingIgnoreSets;
bool pendingUpdateLastValues;

signals:
void active(int value);
Expand Down
10 changes: 10 additions & 0 deletions src/joybutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5601,6 +5601,16 @@ double JoyButton::getLastAccelerationDistance()
return lastAccelerationDistance;
}

void JoyButton::copyLastMouseDistanceFromDeadZone(JoyButton *srcButton)
{
this->lastMouseDistance = srcButton->lastMouseDistance;
}

void JoyButton::copyLastAccelerationDistance(JoyButton *srcButton)
{
this->lastAccelerationDistance = srcButton->lastAccelerationDistance;
}

bool JoyButton::isExtraAccelerationEnabled()
{
return extraAccelerationEnabled;
Expand Down
4 changes: 4 additions & 0 deletions src/joybutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class JoyButton : public QObject
virtual double getMouseDistanceFromDeadZone();
virtual double getLastMouseDistanceFromDeadZone();

// Don't use direct assignment but copying from a current button.
virtual void copyLastMouseDistanceFromDeadZone(JoyButton *srcButton);
virtual void copyLastAccelerationDistance(JoyButton *srcButton);

virtual void setVDPad(VDPad *vdpad);
void removeVDPad();
bool isPartVDPad();
Expand Down

0 comments on commit ef8061d

Please sign in to comment.