From 40448e90b7095790dc9a764cc71932d613992120 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 16 Apr 2016 19:10:12 -0700 Subject: [PATCH] Qt: Remove some C99isms from C++ code --- CHANGES | 1 + src/platform/qt/InputProfile.cpp | 198 +++++++++++++++++-------------- src/platform/qt/InputProfile.h | 52 +++++--- 3 files changed, 147 insertions(+), 104 deletions(-) diff --git a/CHANGES b/CHANGES index 678f28579..950f4c461 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,7 @@ Misc: - FFmpeg: Update dependencies on Ubuntu - OpenGL: Log shader compilation failure - All: Allow use of external minizip library + - Qt: Remove some C99isms from C++ code 0.4.0: (2016-02-02) Features: diff --git a/src/platform/qt/InputProfile.cpp b/src/platform/qt/InputProfile.cpp index d27bfae7d..80aece552 100644 --- a/src/platform/qt/InputProfile.cpp +++ b/src/platform/qt/InputProfile.cpp @@ -14,7 +14,7 @@ using namespace QGBA; const InputProfile InputProfile::s_defaultMaps[] = { { "XInput Controller #\\d+", // XInput (Windows) - (int[GBA_KEY_MAX]) { + { /*keyA */ 11, /*keyB */ 10, /*keySelect */ 5, @@ -26,20 +26,22 @@ const InputProfile InputProfile::s_defaultMaps[] = { /*keyR */ 9, /*keyL */ 8 }, - (ShortcutButton[]) { - {"loadState", 12}, - {"saveState", 13}, - {} + { + /*loadState */ 12, + /*saveState */ 13, + /*holdFastForward */ -1, + /*holdRewind */ -1, }, - (ShortcutAxis[]) { - {"holdFastForward", GamepadAxisEvent::Direction::POSITIVE, 5}, - {"holdRewind", GamepadAxisEvent::Direction::POSITIVE, 4}, - {} + { + /*loadState */ {GamepadAxisEvent::Direction::NEUTRAL, -1}, + /*saveState */ {GamepadAxisEvent::Direction::NEUTRAL, -1}, + /*holdFastForward */ {GamepadAxisEvent::Direction::POSITIVE, 5}, + /*holdRewind */ {GamepadAxisEvent::Direction::POSITIVE, 4}, } }, { "(Microsoft X-Box 360 pad|Xbox Gamepad \\(userspace driver\\))", // Linux - (int[GBA_KEY_MAX]) { + { /*keyA */ 1, /*keyB */ 0, /*keySelect */ 6, @@ -51,20 +53,22 @@ const InputProfile InputProfile::s_defaultMaps[] = { /*keyR */ 5, /*keyL */ 4 }, - (ShortcutButton[]) { - {"loadState", 2}, - {"saveState", 3}, - {} + { + /*loadState */ 2, + /*saveState */ 3, + /*holdFastForward */ -1, + /*holdRewind */ -1, }, - (ShortcutAxis[]) { - {"holdFastForward", GamepadAxisEvent::Direction::POSITIVE, 5}, - {"holdRewind", GamepadAxisEvent::Direction::POSITIVE, 2}, - {} + { + /*loadState */ {GamepadAxisEvent::Direction::NEUTRAL, -1}, + /*saveState */ {GamepadAxisEvent::Direction::NEUTRAL, -1}, + /*holdFastForward */ {GamepadAxisEvent::Direction::POSITIVE, 5}, + /*holdRewind */ {GamepadAxisEvent::Direction::POSITIVE, 2}, } }, { "Xbox 360 Wired Controller", // OS X - (int[GBA_KEY_MAX]) { + { /*keyA */ 1, /*keyB */ 0, /*keySelect */ 9, @@ -76,20 +80,22 @@ const InputProfile InputProfile::s_defaultMaps[] = { /*keyR */ 5, /*keyL */ 4 }, - (ShortcutButton[]) { - {"loadState", 2}, - {"saveState", 3}, - {} + { + /*loadState */ 2, + /*saveState */ 3, + /*holdFastForward */ -1, + /*holdRewind */ -1, }, - (ShortcutAxis[]) { - {"holdFastForward", GamepadAxisEvent::Direction::POSITIVE, 5}, - {"holdRewind", GamepadAxisEvent::Direction::POSITIVE, 2}, - {} + { + /*loadState */ {GamepadAxisEvent::Direction::NEUTRAL, -1}, + /*saveState */ {GamepadAxisEvent::Direction::NEUTRAL, -1}, + /*holdFastForward */ {GamepadAxisEvent::Direction::POSITIVE, 5}, + /*holdRewind */ {GamepadAxisEvent::Direction::POSITIVE, 2}, } }, { "(Sony Computer Entertainment )?Wireless Controller", // The DualShock 4 device ID is cut off on Windows - (int[GBA_KEY_MAX]) { + { /*keyA */ 1, /*keyB */ 2, /*keySelect */ 8, @@ -101,17 +107,16 @@ const InputProfile InputProfile::s_defaultMaps[] = { /*keyR */ 5, /*keyL */ 4 }, - (ShortcutButton[]) { - {"loadState", 0}, - {"saveState", 3}, - {"holdFastForward", 7}, - {"holdRewind", 6}, - {} + { + /*loadState */ 0, + /*saveState */ 3, + /*holdFastForward */ 7, + /*holdRewind */ 6, }, }, { "PLAYSTATION\\(R\\)3 Controller", // DualShock 3 (OS X) - (int[GBA_KEY_MAX]) { + { /*keyA */ 13, /*keyB */ 14, /*keySelect */ 0, @@ -123,17 +128,16 @@ const InputProfile InputProfile::s_defaultMaps[] = { /*keyR */ 11, /*keyL */ 10 }, - (ShortcutButton[]) { - {"loadState", 15}, - {"saveState", 12}, - {"holdFastForward", 9}, - {"holdRewind", 8}, - {} - } + { + /*loadState */ 15, + /*saveState */ 12, + /*holdFastForward */ 9, + /*holdRewind */ 8, + }, }, { "Wiimote \\(..-..-..-..-..-..\\)", // WJoy (OS X) - (int[GBA_KEY_MAX]) { + { /*keyA */ 15, /*keyB */ 16, /*keySelect */ 7, @@ -145,50 +149,49 @@ const InputProfile InputProfile::s_defaultMaps[] = { /*keyR */ 20, /*keyL */ 19 }, - (ShortcutButton[]) { - {"loadState", 18}, - {"saveState", 17}, - {"holdFastForward", 22}, - {"holdRewind", 21}, - {} - } + { + /*loadState */ 18, + /*saveState */ 17, + /*holdFastForward */ 22, + /*holdRewind */ 21, + }, }, }; constexpr InputProfile::InputProfile(const char* name, - int keys[GBA_KEY_MAX], - const ShortcutButton* shortcutButtons, - const ShortcutAxis* shortcutAxes, - AxisValue axes[GBA_KEY_MAX], + const KeyList keys, + const Shortcuts shortcutButtons, + const Shortcuts shortcutAxes, + const KeyList axes, const struct Coord& tiltAxis, const struct Coord& gyroAxis, float gyroSensitivity) : m_profileName(name) , m_keys { - keys[GBA_KEY_A], - keys[GBA_KEY_B], - keys[GBA_KEY_SELECT], - keys[GBA_KEY_START], - keys[GBA_KEY_RIGHT], - keys[GBA_KEY_LEFT], - keys[GBA_KEY_UP], - keys[GBA_KEY_DOWN], - keys[GBA_KEY_R], - keys[GBA_KEY_L] + keys.keyA, + keys.keyB, + keys.keySelect, + keys.keyStart, + keys.keyRight, + keys.keyLeft, + keys.keyUp, + keys.keyDown, + keys.keyR, + keys.keyL, } , m_shortcutButtons(shortcutButtons) , m_shortcutAxes(shortcutAxes) , m_axes { - axes[GBA_KEY_A], - axes[GBA_KEY_B], - axes[GBA_KEY_SELECT], - axes[GBA_KEY_START], - axes[GBA_KEY_RIGHT], - axes[GBA_KEY_LEFT], - axes[GBA_KEY_UP], - axes[GBA_KEY_DOWN], - axes[GBA_KEY_R], - axes[GBA_KEY_L] + axes.keyA, + axes.keyB, + axes.keySelect, + axes.keyStart, + axes.keyRight, + axes.keyLeft, + axes.keyUp, + axes.keyDown, + axes.keyR, + axes.keyL, } , m_tiltAxis(tiltAxis) , m_gyroAxis(gyroAxis) @@ -221,24 +224,45 @@ void InputProfile::apply(InputController* controller) const { } bool InputProfile::lookupShortcutButton(const QString& shortcutName, int* button) const { - for (size_t i = 0; m_shortcutButtons[i].shortcut; ++i) { - const ShortcutButton& shortcut = m_shortcutButtons[i]; - if (QLatin1String(shortcut.shortcut) == shortcutName) { - *button = shortcut.button; - return true; - } + if (shortcutName == QLatin1String("loadState")) { + *button = m_shortcutButtons.loadState; + return true; + } + if (shortcutName == QLatin1String("saveState")) { + *button = m_shortcutButtons.saveState; + return true; + } + if (shortcutName == QLatin1String("holdFastForward")) { + *button = m_shortcutButtons.holdFastForward; + return true; + } + if (shortcutName == QLatin1String("holdRewind")) { + *button = m_shortcutButtons.holdRewind; + return true; } return false; } bool InputProfile::lookupShortcutAxis(const QString& shortcutName, int* axis, GamepadAxisEvent::Direction* direction) const { - for (size_t i = 0; m_shortcutAxes[i].shortcut; ++i) { - const ShortcutAxis& shortcut = m_shortcutAxes[i]; - if (QLatin1String(shortcut.shortcut) == shortcutName) { - *axis = shortcut.axis; - *direction = shortcut.direction; - return true; - } + if (shortcutName == QLatin1String("loadState")) { + *axis = m_shortcutAxes.loadState.axis; + *direction = m_shortcutAxes.loadState.direction; + return true; + } + if (shortcutName == QLatin1String("saveState")) { + *axis = m_shortcutAxes.saveState.axis; + *direction = m_shortcutAxes.saveState.direction; + return true; + } + if (shortcutName == QLatin1String("holdFastForward")) { + *axis = m_shortcutAxes.holdFastForward.axis; + *direction = m_shortcutAxes.holdFastForward.direction; + return true; + } + if (shortcutName == QLatin1String("holdRewind")) { + *axis = m_shortcutAxes.holdRewind.axis; + *direction = m_shortcutAxes.holdRewind.direction; + return true; } return false; } diff --git a/src/platform/qt/InputProfile.h b/src/platform/qt/InputProfile.h index 8a710db5a..dc7ffd4cf 100644 --- a/src/platform/qt/InputProfile.h +++ b/src/platform/qt/InputProfile.h @@ -35,28 +35,46 @@ private: int axis; }; - struct ShortcutButton { - const char* shortcut; - int button; + template struct Shortcuts { + T loadState; + T saveState; + T holdFastForward; + T holdRewind; }; - struct ShortcutAxis { - const char* shortcut; + struct Axis { GamepadAxisEvent::Direction direction; int axis; }; + template struct KeyList { + T keyA; + T keyB; + T keySelect; + T keyStart; + T keyRight; + T keyLeft; + T keyUp; + T keyDown; + T keyR; + T keyL; + }; + constexpr InputProfile(const char* name, - int keys[GBA_KEY_MAX], - const ShortcutButton* shortcutButtons = (ShortcutButton[]) {{}}, - const ShortcutAxis* shortcutAxes = (ShortcutAxis[]) {{}}, - AxisValue axes[GBA_KEY_MAX] = (AxisValue[GBA_KEY_MAX]) { - {}, {}, {}, {}, - { GamepadAxisEvent::Direction::POSITIVE, 0 }, - { GamepadAxisEvent::Direction::NEGATIVE, 0 }, - { GamepadAxisEvent::Direction::NEGATIVE, 1 }, - { GamepadAxisEvent::Direction::POSITIVE, 1 }, - {}, {}}, + const KeyList keys, + const Shortcuts shortcutButtons = { -1, -1, -1, -1}, + const Shortcuts shortcutAxes = { + {GamepadAxisEvent::Direction::NEUTRAL, -1}, + {GamepadAxisEvent::Direction::NEUTRAL, -1}, + {GamepadAxisEvent::Direction::NEUTRAL, -1}, + {GamepadAxisEvent::Direction::NEUTRAL, -1}}, + const KeyList axes = { + {}, {}, {}, {}, + { GamepadAxisEvent::Direction::POSITIVE, 0 }, + { GamepadAxisEvent::Direction::NEGATIVE, 0 }, + { GamepadAxisEvent::Direction::NEGATIVE, 1 }, + { GamepadAxisEvent::Direction::POSITIVE, 1 }, + {}, {}}, const struct Coord& tiltAxis = { 2, 3 }, const struct Coord& gyroAxis = { 0, 1 }, float gyroSensitivity = 2e+09f); @@ -66,8 +84,8 @@ private: const char* m_profileName; const int m_keys[GBA_KEY_MAX]; const AxisValue m_axes[GBA_KEY_MAX]; - const ShortcutButton* m_shortcutButtons; - const ShortcutAxis* m_shortcutAxes; + const Shortcuts m_shortcutButtons; + const Shortcuts m_shortcutAxes; Coord m_tiltAxis; Coord m_gyroAxis; float m_gyroSensitivity;