Skip to content

Commit

Permalink
XInput: Apply immediately as well
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Nov 28, 2014
1 parent 1b3d017 commit 1958a10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 4 additions & 10 deletions Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index)
: m_index(index), m_subtype(caps.SubType)
{
ZeroMemory(&m_state_out, sizeof(m_state_out));
ZeroMemory(&m_current_state_out, sizeof(m_current_state_out));

// XInputGetCaps seems to always claim all capabilities are supported
// but I will leave all this stuff in, incase m$ fixes xinput up a bit
Expand Down Expand Up @@ -162,7 +161,7 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index)
{
//WORD val = (&caps.Vibration.wLeftMotorSpeed)[i]; // should be max value / nope, more lies
if ((&caps.Vibration.wLeftMotorSpeed)[i])
AddOutput(new Motor(i, (&m_state_out.wLeftMotorSpeed)[i], 65535));
AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535));
}

ZeroMemory(&m_state_in, sizeof(m_state_in));
Expand Down Expand Up @@ -208,15 +207,9 @@ void Device::UpdateInput()
PXInputGetState(m_index, &m_state_in);
}

void Device::UpdateOutput()
void Device::UpdateMotors()
{
// this if statement is to make rumble work better when multiple ControllerInterfaces are using the device
// only calls XInputSetState if the state changed
if (memcmp(&m_state_out, &m_current_state_out, sizeof(m_state_out)))
{
m_current_state_out = m_state_out;
PXInputSetState(m_index, &m_state_out);
}
PXInputSetState(m_index, &m_state_out);
}

// GET name/source/id
Expand Down Expand Up @@ -261,6 +254,7 @@ ControlState Device::Axis::GetState() const
void Device::Motor::SetState(ControlState state)
{
m_motor = (WORD)(state * m_range);
m_parent->UpdateMotors();
}

}
Expand Down
8 changes: 5 additions & 3 deletions Source/Core/InputCommon/ControllerInterface/XInput/XInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,29 @@ class Device : public Core::Device
{
public:
std::string GetName() const;
Motor(u8 index, WORD& motor, WORD range) : m_index(index), m_motor(motor), m_range(range) {}
Motor(u8 index, Device* parent, WORD &motor, WORD range) : m_index(index), m_parent(parent), m_motor(motor), m_range(range) {}
void SetState(ControlState state);
private:
WORD& m_motor;
const WORD m_range;
const u8 m_index;
Device* m_parent;
};

public:
void UpdateInput() override;
void UpdateOutput() override;

Device(const XINPUT_CAPABILITIES& capabilities, u8 index);

std::string GetName() const;
int GetId() const;
std::string GetSource() const;

void UpdateMotors();

private:
XINPUT_STATE m_state_in;
XINPUT_VIBRATION m_state_out, m_current_state_out;
XINPUT_VIBRATION m_state_out;
const BYTE m_subtype;
const u8 m_index;
};
Expand Down

0 comments on commit 1958a10

Please sign in to comment.