Qt: Remove some C99isms from C++ code

This commit is contained in:
Jeffrey Pfau 2016-04-16 19:10:12 -07:00
parent f27566fb08
commit 40448e90b7
3 changed files with 147 additions and 104 deletions

View File

@ -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:

View File

@ -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<int> keys,
const Shortcuts<int> shortcutButtons,
const Shortcuts<Axis> shortcutAxes,
const KeyList<AxisValue> 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;
}

View File

@ -35,28 +35,46 @@ private:
int axis;
};
struct ShortcutButton {
const char* shortcut;
int button;
template <typename T> struct Shortcuts {
T loadState;
T saveState;
T holdFastForward;
T holdRewind;
};
struct ShortcutAxis {
const char* shortcut;
struct Axis {
GamepadAxisEvent::Direction direction;
int axis;
};
template <typename T> 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<int> keys,
const Shortcuts<int> shortcutButtons = { -1, -1, -1, -1},
const Shortcuts<Axis> shortcutAxes = {
{GamepadAxisEvent::Direction::NEUTRAL, -1},
{GamepadAxisEvent::Direction::NEUTRAL, -1},
{GamepadAxisEvent::Direction::NEUTRAL, -1},
{GamepadAxisEvent::Direction::NEUTRAL, -1}},
const KeyList<AxisValue> 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<int> m_shortcutButtons;
const Shortcuts<Axis> m_shortcutAxes;
Coord m_tiltAxis;
Coord m_gyroAxis;
float m_gyroSensitivity;