ControllerInterface: Make UpdateInput / UpdateOutput return void

The return values here have never been checked, so it doesn't make sense
to return a value to begin with.
This commit is contained in:
Jasper St. Pierre 2014-11-13 00:55:14 -08:00
parent 61fcfc4bf2
commit f2787f620e
19 changed files with 35 additions and 76 deletions

View File

@ -135,22 +135,15 @@ void ControllerInterface::Shutdown()
//
// Update input for all devices, return true if all devices returned successful
//
bool ControllerInterface::UpdateInput()
void ControllerInterface::UpdateInput()
{
std::unique_lock<std::recursive_mutex> lk(update_lock, std::defer_lock);
if (!lk.try_lock())
return false;
size_t ok_count = 0;
return;
for (ciface::Core::Device* d : m_devices)
{
if (d->UpdateInput())
++ok_count;
}
return (m_devices.size() == ok_count);
d->UpdateInput();
}
//
@ -158,22 +151,15 @@ bool ControllerInterface::UpdateInput()
//
// Update output for all devices, return true if all devices returned successful
//
bool ControllerInterface::UpdateOutput()
void ControllerInterface::UpdateOutput()
{
std::unique_lock<std::recursive_mutex> lk(update_lock, std::defer_lock);
if (!lk.try_lock())
return false;
size_t ok_count = 0;
return;
for (ciface::Core::Device* d : m_devices)
{
if (d->UpdateOutput())
++ok_count;
}
return (m_devices.size() == ok_count);
d->UpdateOutput();
}
//

View File

@ -120,8 +120,8 @@ public:
bool IsInit() const { return m_is_init; }
void UpdateReference(ControlReference* control, const ciface::Core::DeviceQualifier& default_device) const;
bool UpdateInput();
bool UpdateOutput();
void UpdateInput();
void UpdateOutput();
std::recursive_mutex update_lock;

View File

@ -177,7 +177,7 @@ std::string Joystick::GetSource() const
// update IO
bool Joystick::UpdateInput()
void Joystick::UpdateInput()
{
HRESULT hr = 0;
@ -215,9 +215,7 @@ bool Joystick::UpdateInput()
// try reacquire if input lost
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
hr = m_device->Acquire();
return SUCCEEDED(hr);
m_device->Acquire();
}
// get name

View File

@ -52,7 +52,7 @@ private:
};
public:
bool UpdateInput();
void UpdateInput() override;
Joystick(const LPDIRECTINPUTDEVICE8 device, const unsigned int index);
~Joystick();

View File

@ -139,7 +139,7 @@ void GetMousePos(ControlState* const x, ControlState* const y)
*y = (ControlState)point.y / (ControlState)win_height * 2 - 1;
}
bool KeyboardMouse::UpdateInput()
void KeyboardMouse::UpdateInput()
{
DIMOUSESTATE2 tmp_mouse;
@ -175,11 +175,7 @@ bool KeyboardMouse::UpdateInput()
// update mouse cursor
GetMousePos(&m_state_in.cursor.x, &m_state_in.cursor.y);
return true;
}
return false;
}
std::string KeyboardMouse::GetName() const

View File

@ -77,7 +77,7 @@ private:
};
public:
bool UpdateInput();
void UpdateInput() override;
KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device);
~KeyboardMouse();

View File

@ -100,8 +100,8 @@ public:
virtual std::string GetName() const = 0;
virtual int GetId() const = 0;
virtual std::string GetSource() const = 0;
virtual bool UpdateInput() { return true; }
virtual bool UpdateOutput() { return true; }
virtual void UpdateInput() {}
virtual void UpdateOutput() {}
const std::vector<Input*>& Inputs() const { return m_inputs; }
const std::vector<Output*>& Outputs() const { return m_outputs; }

View File

@ -133,10 +133,8 @@ bool ForceFeedbackDevice::InitForceFeedback(const LPDIRECTINPUTDEVICE8 device, i
return true;
}
bool ForceFeedbackDevice::UpdateOutput()
void ForceFeedbackDevice::UpdateOutput()
{
size_t ok_count = 0;
DIEFFECT eff;
memset(&eff, 0, sizeof(eff));
eff.dwSize = sizeof(DIEFFECT);
@ -151,22 +149,16 @@ bool ForceFeedbackDevice::UpdateOutput()
eff.cbTypeSpecificParams = state.size;
eff.lpvTypeSpecificParams = state.params;
// set params and start effect
ok_count += SUCCEEDED(state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START);
}
else
{
ok_count += SUCCEEDED(state.iface->Stop());
state.iface->Stop();
}
state.params = nullptr;
}
else
{
++ok_count;
}
}
return (m_state_out.size() == ok_count);
}
template<>

View File

@ -52,7 +52,7 @@ private:
public:
bool InitForceFeedback(const LPDIRECTINPUTDEVICE8, int cAxes);
bool UpdateOutput();
void UpdateOutput() override;
virtual ~ForceFeedbackDevice();
private:

View File

@ -53,7 +53,7 @@ private:
};
public:
bool UpdateInput() override;
void UpdateInput() override;
Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window);

View File

@ -54,7 +54,7 @@ Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index, void *win
AddInput(new Button(i, m_mousebuttons[i]));
}
bool Keyboard::UpdateInput()
void Keyboard::UpdateInput()
{
CGRect bounds = CGRectZero;
uint32_t windowid[1] = { m_windowid };
@ -85,8 +85,6 @@ bool Keyboard::UpdateInput()
m_mousebuttons[0] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft);
m_mousebuttons[1] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight);
m_mousebuttons[2] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter);
return true;
}
std::string Keyboard::GetName() const

View File

@ -316,15 +316,13 @@ void Joystick::TriangleEffect::SetState(ControlState state)
}
#endif
bool Joystick::UpdateInput()
void Joystick::UpdateInput()
{
// each joystick is doin this, o well
SDL_JoystickUpdate();
return true;
}
bool Joystick::UpdateOutput()
void Joystick::UpdateOutput()
{
#ifdef USE_SDL_HAPTIC
for (auto &i : m_state_out)
@ -359,7 +357,6 @@ bool Joystick::UpdateOutput()
}
}
#endif
return true;
}
std::string Joystick::GetName() const

View File

@ -134,8 +134,8 @@ private:
#endif
public:
bool UpdateInput() override;
bool UpdateOutput() override;
void UpdateInput() override;
void UpdateOutput() override;
Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index);
~Joystick();

View File

@ -203,23 +203,19 @@ std::string Device::GetSource() const
// Update I/O
bool Device::UpdateInput()
void Device::UpdateInput()
{
return (ERROR_SUCCESS == PXInputGetState(m_index, &m_state_in));
PXInputGetState(m_index, &m_state_in);
}
bool Device::UpdateOutput()
void Device::UpdateOutput()
{
// 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;
return (ERROR_SUCCESS == PXInputSetState(m_index, &m_state_out));
}
else
{
return true;
PXInputSetState(m_index, &m_state_out);
}
}

View File

@ -73,8 +73,8 @@ private:
};
public:
bool UpdateInput();
bool UpdateOutput();
void UpdateInput() override;
void UpdateOutput() override;
Device(const XINPUT_CAPABILITIES& capabilities, u8 index);

View File

@ -208,7 +208,7 @@ void KeyboardMouse::UpdateCursor()
m_state.cursor.y = win_y / (float)win_attribs.height * 2 - 1;
}
bool KeyboardMouse::UpdateInput()
void KeyboardMouse::UpdateInput()
{
XFlush(m_display);
@ -282,8 +282,6 @@ bool KeyboardMouse::UpdateInput()
m_state.axis.y *= MOUSE_AXIS_SMOOTHING;
m_state.axis.y += delta_y;
m_state.axis.y /= MOUSE_AXIS_SMOOTHING+1.0f;
return true;
}
std::string KeyboardMouse::GetName() const

View File

@ -98,7 +98,7 @@ private:
void UpdateCursor();
public:
bool UpdateInput() override;
void UpdateInput() override;
KeyboardMouse(Window window, int opcode, int pointer_deviceid, int keyboard_deviceid);
~KeyboardMouse();

View File

@ -49,7 +49,7 @@ KeyboardMouse::~KeyboardMouse()
XCloseDisplay(m_display);
}
bool KeyboardMouse::UpdateInput()
void KeyboardMouse::UpdateInput()
{
XQueryKeymap(m_display, m_state.keyboard);
@ -64,8 +64,6 @@ bool KeyboardMouse::UpdateInput()
// the mouse position as a range from -1 to 1
m_state.cursor.x = (float)win_x / (float)win_attribs.width * 2 - 1;
m_state.cursor.y = (float)win_y / (float)win_attribs.height * 2 - 1;
return true;
}
std::string KeyboardMouse::GetName() const

View File

@ -70,7 +70,7 @@ private:
};
public:
bool UpdateInput() override;
void UpdateInput() override;
KeyboardMouse(Window window);
~KeyboardMouse();