diff options
| author | Rachel Bryk <RachelBryk@gmail.com> | 2014-08-11 13:43:26 -0400 |
|---|---|---|
| committer | Rachel Bryk <RachelBryk@gmail.com> | 2014-09-03 03:08:09 -0400 |
| commit | 5adbc83453d14b23818442f545ceede0e4548196 (patch) | |
| tree | bdc853c8e073ad09189a8f2811306105d061fbec /Source/Core/InputCommon | |
| parent | 64575d565a47e582715aac003d8a0c55cc4ac2ca (diff) | |
Change ControlState typedef to double, and change all related floats/doubles to use it.
Fixes an off by 1 issue related to double->float->double conversion, and eliminates numerous warnings.
Diffstat (limited to 'Source/Core/InputCommon')
9 files changed, 49 insertions, 49 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp index 87378f86e0..6200ec2002 100644 --- a/Source/Core/InputCommon/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu.cpp @@ -104,7 +104,7 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s { if (s->is_virtual) continue; - sec->Set(group + s->name, s->value*100.0f, s->default_value*100.0f); + sec->Set(group + s->name, (float)s->value * 100.0f, (float)s->default_value * 100.0f); } for (auto& c : controls) @@ -113,7 +113,7 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s sec->Set(group + c->name, c->control_ref->expression, ""); // range - sec->Set(group + c->name + "/Range", c->control_ref->range*100.0f, 100.0f); + sec->Set(group + c->name + "/Range", (float) (c->control_ref->range*100.0, 100.0)); } // extensions diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h index d390c1f90f..ec1ab8a2b7 100644 --- a/Source/Core/InputCommon/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu.h @@ -151,7 +151,7 @@ public: // The GameCube controller and Wiimote attachments have a different default radius AnalogStick(const char* const _name, ControlState default_radius); - void GetState(double* const x, double* const y) + void GetState(ControlState* const x, ControlState* const y) { ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); @@ -167,7 +167,7 @@ public: ControlState dist = sqrt(xx*xx + yy*yy); // dead zone code - dist = std::max(0.0f, dist - deadzone); + dist = std::max(0.0, dist - deadzone); dist /= (1 - deadzone); // radius @@ -178,8 +178,8 @@ public: if (m) dist *= 0.5; - yy = std::max(-1.0f, std::min(1.0f, ang_sin * dist)); - xx = std::max(-1.0f, std::min(1.0f, ang_cos * dist)); + yy = std::max(-1.0, std::min(1.0, ang_sin * dist)); + xx = std::max(-1.0, std::min(1.0, ang_cos * dist)); *y = yy; *x = xx; @@ -210,7 +210,7 @@ public: public: MixedTriggers(const std::string& _name); - void GetState(u16 *const digital, const u16* bitmasks, double* analog) + void GetState(u16 *const digital, const u16* bitmasks, ControlState* analog) { const unsigned int trig_count = ((unsigned int) (controls.size() / 2)); for (unsigned int i=0; i<trig_count; ++i,++bitmasks,++analog) @@ -233,12 +233,12 @@ public: public: Triggers(const std::string& _name); - void GetState(double* analog) + void GetState(ControlState* analog) { const unsigned int trig_count = ((unsigned int) (controls.size())); const ControlState deadzone = settings[0]->value; for (unsigned int i=0; i<trig_count; ++i,++analog) - *analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0f) / (1 - deadzone); + *analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0) / (1 - deadzone); } }; @@ -247,12 +247,12 @@ public: public: Slider(const std::string& _name); - void GetState(double* const slider) + void GetState(ControlState* const slider) { - const float deadzone = settings[0]->value; - const float state = controls[1]->control_ref->State() - controls[0]->control_ref->State(); + const ControlState deadzone = settings[0]->value; + const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State(); - if (fabsf(state) > deadzone) + if (fabs(state) > deadzone) *slider = (state - (deadzone * sign(state))) / (1 - deadzone); else *slider = 0; @@ -264,24 +264,24 @@ public: public: Force(const std::string& _name); - void GetState(double* axis) + void GetState(ControlState* axis) { - const float deadzone = settings[0]->value; - for (unsigned int i=0; i<6; i+=2) + const ControlState deadzone = settings[0]->value; + for (unsigned int i = 0; i < 6; i += 2) { - float tmpf = 0; - const float state = controls[i+1]->control_ref->State() - controls[i]->control_ref->State(); - if (fabsf(state) > deadzone) + ControlState tmpf = 0; + const ControlState state = controls[i+1]->control_ref->State() - controls[i]->control_ref->State(); + if (fabs(state) > deadzone) tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone)); - float &ax = m_swing[i >> 1]; + ControlState &ax = m_swing[i >> 1]; *axis++ = (tmpf - ax); ax = tmpf; } } private: - float m_swing[3]; + ControlState m_swing[3]; }; class Tilt : public ControlGroup @@ -289,7 +289,7 @@ public: public: Tilt(const std::string& _name); - void GetState(double* const x, double* const y, const bool step = true) + void GetState(ControlState* const x, ControlState* const y, const bool step = true) { // this is all a mess @@ -298,7 +298,7 @@ public: ControlState deadzone = settings[0]->value; ControlState circle = settings[1]->value; - auto const angle = settings[2]->value / 1.8f; + auto const angle = settings[2]->value / 1.8; ControlState m = controls[4]->control_ref->State(); // deadzone / circle stick code @@ -309,7 +309,7 @@ public: ControlState ang_cos = cos(ang); // the amt a full square stick would have at current angle - ControlState square_full = std::min(ang_sin ? 1/fabsf(ang_sin) : 2, ang_cos ? 1/fabsf(ang_cos) : 2); + ControlState square_full = std::min(ang_sin ? 1/fabs(ang_sin) : 2, ang_cos ? 1/fabs(ang_cos) : 2); // the amt a full stick would have that was (user setting circular) at current angle // I think this is more like a pointed circle rather than a rounded square like it should be @@ -318,7 +318,7 @@ public: ControlState dist = sqrt(xx*xx + yy*yy); // dead zone code - dist = std::max(0.0f, dist - deadzone * stick_full); + dist = std::max(0.0, dist - deadzone * stick_full); dist /= (1 - deadzone); // circle stick code @@ -328,8 +328,8 @@ public: if (m) dist *= 0.5; - yy = std::max(-1.0f, std::min(1.0f, ang_sin * dist)); - xx = std::max(-1.0f, std::min(1.0f, ang_cos * dist)); + yy = std::max(-1.0, std::min(1.0, ang_sin * dist)); + xx = std::max(-1.0, std::min(1.0, ang_cos * dist)); // this is kinda silly here // gui being open will make this happen 2x as fast, o well @@ -338,14 +338,14 @@ public: if (step) { if (xx > m_tilt[0]) - m_tilt[0] = std::min(m_tilt[0] + 0.1f, xx); + m_tilt[0] = std::min(m_tilt[0] + 0.1, xx); else if (xx < m_tilt[0]) - m_tilt[0] = std::max(m_tilt[0] - 0.1f, xx); + m_tilt[0] = std::max(m_tilt[0] - 0.1, xx); if (yy > m_tilt[1]) - m_tilt[1] = std::min(m_tilt[1] + 0.1f, yy); + m_tilt[1] = std::min(m_tilt[1] + 0.1, yy); else if (yy < m_tilt[1]) - m_tilt[1] = std::max(m_tilt[1] - 0.1f, yy); + m_tilt[1] = std::max(m_tilt[1] - 0.1, yy); } *y = m_tilt[1] * angle; @@ -353,7 +353,7 @@ public: } private: - float m_tilt[2]; + ControlState m_tilt[2]; }; class Cursor : public ControlGroup @@ -361,34 +361,34 @@ public: public: Cursor(const std::string& _name); - void GetState(double* const x, double* const y, double* const z, const bool adjusted = false) + void GetState(ControlState* const x, ControlState* const y, ControlState* const z, const bool adjusted = false) { - const float zz = controls[4]->control_ref->State() - controls[5]->control_ref->State(); + const ControlState zz = controls[4]->control_ref->State() - controls[5]->control_ref->State(); // silly being here if (zz > m_z) - m_z = std::min(m_z + 0.1f, zz); + m_z = std::min(m_z + 0.1, zz); else if (zz < m_z) - m_z = std::max(m_z - 0.1f, zz); + m_z = std::max(m_z - 0.1, zz); *z = m_z; // hide - if (controls[6]->control_ref->State() > 0.5f) + if (controls[6]->control_ref->State() > 0.5) { *x = 10000; *y = 0; } else { - float yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); - float xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); + ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); + ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); // adjust cursor according to settings if (adjusted) { xx *= (settings[1]->value * 2); yy *= (settings[2]->value * 2); - yy += (settings[0]->value - 0.5f); + yy += (settings[0]->value - 0.5); } *x = xx; @@ -396,7 +396,7 @@ public: } } - float m_z; + ControlState m_z; }; class Extension : public ControlGroup diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp index 1ff48877db..ecd5db838c 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp @@ -266,7 +266,7 @@ std::string Joystick::Hat::GetName() const ControlState Joystick::Axis::GetState() const { - return std::max(0.0f, ControlState(m_axis - m_base) / m_range); + return std::max(0.0, ControlState(m_axis - m_base) / m_range); } ControlState Joystick::Button::GetState() const diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 52960bbc3c..d9728dcbac 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -298,12 +298,12 @@ ControlState KeyboardMouse::Button::GetState() const ControlState KeyboardMouse::Axis::GetState() const { - return std::max(0.0f, ControlState(m_axis) / m_range); + return std::max(0.0, ControlState(m_axis) / m_range); } ControlState KeyboardMouse::Cursor::GetState() const { - return std::max(0.0f, ControlState(m_axis) / (m_positive ? 1.0f : -1.0f)); + return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0)); } void KeyboardMouse::Light::SetState(const ControlState state) diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index 6e1868a4ba..fa4f351cb5 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -10,7 +10,7 @@ #include "Common/Common.h" // idk in case I wanted to change it to double or something, idk what's best -typedef float ControlState; +typedef double ControlState; namespace ciface { diff --git a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp index c28356260d..e93b22826d 100644 --- a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp @@ -273,7 +273,7 @@ public: case TOK_OR: return std::max(lhsValue, rhsValue); case TOK_ADD: - return std::min(lhsValue + rhsValue, 1.0f); + return std::min(lhsValue + rhsValue, 1.0); default: assert(false); return 0; diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm index 89642aecf0..98df7c3535 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm @@ -253,7 +253,7 @@ ControlState Keyboard::Key::GetState() const ControlState Keyboard::Cursor::GetState() const { - return std::max(0.0f, ControlState(m_axis) / (m_positive ? 1.0f : -1.0f)); + return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0)); } ControlState Keyboard::Button::GetState() const diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index c43cd255e8..b745f7b2d4 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -407,7 +407,7 @@ ControlState Joystick::Button::GetState() const ControlState Joystick::Axis::GetState() const { - return std::max(0.0f, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range); + return std::max(0.0, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range); } ControlState Joystick::Hat::GetState() const diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp index 8b68fa80bc..b58c1c81a5 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp @@ -256,7 +256,7 @@ ControlState Device::Trigger::GetState() const ControlState Device::Axis::GetState() const { - return std::max( 0.0f, ControlState(m_axis) / m_range ); + return std::max( 0.0, ControlState(m_axis) / m_range ); } void Device::Motor::SetState(ControlState state) |
