Fix travis build. Fix more code style issues

This commit is contained in:
Anon 2016-08-06 17:09:25 -05:00
parent 750838581d
commit 6ad7260471
11 changed files with 143 additions and 143 deletions

View File

@ -42,7 +42,7 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
} }
void EmuWindow_SDL2::OnKeyEvent(SDL_Keysym key, u8 state) { void EmuWindow_SDL2::OnKeyEvent(SDL_Keysym key, u8 state) {
auto& keyboard = InputCore::GetKeyboard(); auto keyboard = InputCore::GetKeyboard();
KeyboardKey param = KeyboardKey(key.sym, key.scancode, SDL_GetKeyName(key.scancode)); KeyboardKey param = KeyboardKey(key.sym, key.scancode, SDL_GetKeyName(key.scancode));
if (state == SDL_PRESSED) { if (state == SDL_PRESSED) {

View File

@ -237,14 +237,14 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
void GRenderWindow::keyPressEvent(QKeyEvent* event) void GRenderWindow::keyPressEvent(QKeyEvent* event)
{ {
auto& keyboard = InputCore::GetKeyboard(); auto keyboard = InputCore::GetKeyboard();
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString()); KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
keyboard->KeyPressed(param); keyboard->KeyPressed(param);
} }
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
{ {
auto& keyboard = InputCore::GetKeyboard(); auto keyboard = InputCore::GetKeyboard();
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString()); KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
keyboard->KeyReleased(param); keyboard->KeyReleased(param);
} }

View File

@ -18,5 +18,4 @@ public:
virtual bool CloseDevice() = 0; virtual bool CloseDevice() = 0;
protected: protected:
std::map<std::string, std::vector<KeyMap::KeyTarget>> keyMapping; ///< Maps the string in the settings file to the HID Padstate object std::map<std::string, std::vector<KeyMap::KeyTarget>> keyMapping; ///< Maps the string in the settings file to the HID Padstate object
}; };

View File

@ -23,17 +23,17 @@ void Keyboard::ProcessInput() {
std::lock_guard<std::mutex> lock(m); std::lock_guard<std::mutex> lock(m);
keysPressedCopy = keysPressed; keysPressedCopy = keysPressed;
} }
for (const auto &ent1 : keyMapping) { for (const auto& entry : keyMapping) {
int scancode = std::stoul(ent1.first, nullptr, 16); int scancode = std::stoul(entry.first, nullptr, 16);
KeyboardKey proxy = KeyboardKey(0, scancode, ""); KeyboardKey proxy = KeyboardKey(0, scancode, "");
if (keysPressedCopy[proxy] == true && keysPressedLast[scancode] == false) { if (keysPressedCopy[proxy] == true && keysPressedLast[scancode] == false) {
for (const auto& key : ent1.second) { for (const auto& key : entry.second) {
KeyMap::PressKey(key, 1.0); KeyMap::PressKey(key, 1.0);
} }
keysPressedLast[scancode] = true; keysPressedLast[scancode] = true;
} }
else if (keysPressedCopy[proxy] == false && keysPressedLast[scancode] == true) { else if (keysPressedCopy[proxy] == false && keysPressedLast[scancode] == true) {
for (const auto& key : ent1.second) { for (const auto& key : entry.second) {
KeyMap::ReleaseKey(key); KeyMap::ReleaseKey(key);
} }
keysPressedLast[scancode] = false; keysPressedLast[scancode] = false;

View File

@ -32,7 +32,9 @@ struct KeyboardKey {
uint32_t scancode; uint32_t scancode;
std::string character; std::string character;
KeyboardKey(uint32_t key_, uint32_t scancode_, std::string character_) : key(key_), scancode(scancode_), character(std::move(character_)) { KeyboardKey(uint32_t key_, uint32_t scancode_, std::string character_)
: key(key_), scancode(scancode_), character(std::move(character_))
{
} }
bool operator==(const KeyboardKey& other) const { bool operator==(const KeyboardKey& other) const {
return scancode == other.scancode; return scancode == other.scancode;

View File

@ -47,29 +47,29 @@ void SDLGamepad::ProcessInput() {
if (gamepad == nullptr) if (gamepad == nullptr)
return; return;
SDL_GameControllerUpdate(); SDL_GameControllerUpdate();
for (const auto &ent1 : keyMapping) { for (const auto& entry : keyMapping) {
SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[ent1.first].c_str()); SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[entry.first].c_str());
if (button != SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_INVALID) { if (button != SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_INVALID) {
Uint8 pressed = SDL_GameControllerGetButton(gamepad, button); Uint8 pressed = SDL_GameControllerGetButton(gamepad, button);
if (pressed == 1 && keysPressed[ent1.first] == false) { if (pressed == 1 && keysPressed[entry.first] == false) {
for (const auto& padstate : ent1.second) { for (const auto& padstate : entry.second) {
KeyMap::PressKey(padstate, 1.0); KeyMap::PressKey(padstate, 1.0);
keysPressed[ent1.first] = true; keysPressed[entry.first] = true;
} }
} }
else if (pressed == 0 && keysPressed[ent1.first] == true) { else if (pressed == 0 && keysPressed[entry.first] == true) {
for (const auto& padstate : ent1.second) { for (const auto& padstate : entry.second) {
KeyMap::ReleaseKey(padstate); KeyMap::ReleaseKey(padstate);
keysPressed[ent1.first] = false; keysPressed[entry.first] = false;
} }
} }
} }
else { else {
// Try axis if button isn't valid // Try axis if button isn't valid
SDL_GameControllerAxis axis = SDL_GameControllerGetAxisFromString(friendlyNameMapping[ent1.first].c_str()); SDL_GameControllerAxis axis = SDL_GameControllerGetAxisFromString(friendlyNameMapping[entry.first].c_str());
if (axis != SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_INVALID) { if (axis != SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_INVALID) {
Sint16 value = SDL_GameControllerGetAxis(gamepad, axis); Sint16 value = SDL_GameControllerGetAxis(gamepad, axis);
for (const auto& padstate : ent1.second) { for (const auto& padstate : entry.second) {
// dont process if in deadzone. Replace later with settings for deadzone. // dont process if in deadzone. Replace later with settings for deadzone.
if (abs(value) < 0.2 * 32767.0) if (abs(value) < 0.2 * 32767.0)
KeyMap::ReleaseKey(padstate); KeyMap::ReleaseKey(padstate);

View File

@ -17,7 +17,8 @@ public:
void ProcessInput() override; void ProcessInput() override;
bool CloseDevice() override; bool CloseDevice() override;
private: private:
std::map<std::string, std::string> friendlyNameMapping = { /// Maps the friendly name shown on GUI with the string name for getting the SDL button instance. /// Maps the friendly name shown on GUI with the string name for getting the SDL button instance.
std::map<std::string, std::string> friendlyNameMapping = {
{ "Button A","a" }, { "Button A","a" },
{ "Button B","b" }, { "Button B","b" },
{ "Button X","x" }, { "Button X","x" },

View File

@ -14,10 +14,10 @@
namespace InputCore { namespace InputCore {
constexpr u64 frame_ticks = 268123480ull / 60; constexpr u64 frame_ticks = 268123480ull / 60;
static int tick_event; static int tick_event;
Service::HID::PadState pad_state; static Service::HID::PadState pad_state;
std::tuple<s16, s16> circle_pad = { 0,0 }; static std::tuple<s16, s16> circle_pad = { 0,0 };
std::shared_ptr<Keyboard> main_keyboard; static std::shared_ptr<Keyboard> main_keyboard;
std::vector<std::shared_ptr<IDevice>> devices; ///< Devices that are handling input for the game static std::vector<std::shared_ptr<IDevice>> devices; ///< Devices that are handling input for the game
static void InputTickCallback(u64, int cycles_late) { static void InputTickCallback(u64, int cycles_late) {
for (auto& device : devices) for (auto& device : devices)
@ -43,7 +43,7 @@ Service::HID::PadState GetPadState() {
return pad_state; return pad_state;
} }
void SetPadState(Service::HID::PadState& state) { void SetPadState(const Service::HID::PadState& state) {
pad_state.hex = state.hex; pad_state.hex = state.hex;
} }
@ -51,7 +51,7 @@ std::tuple<s16, s16> GetCirclePad() {
return circle_pad; return circle_pad;
} }
void SetCirclePad(std::tuple<s16, s16>& pad) { void SetCirclePad(std::tuple<s16, s16> pad) {
circle_pad = pad; circle_pad = pad;
} }
@ -59,11 +59,11 @@ std::shared_ptr<Keyboard> GetKeyboard() {
return main_keyboard; return main_keyboard;
} }
///Get Unique input mappings from settings /// Get Unique input mappings from settings
std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() { static std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
std::vector<Settings::InputDeviceMapping> uniqueMappings; std::vector<Settings::InputDeviceMapping> uniqueMappings;
for (auto& mapping : Settings::values.input_mappings) { for (const auto& mapping : Settings::values.input_mappings) {
if (!CheckIfMappingExists(uniqueMappings, mapping)) { if (!CheckIfMappingExists(uniqueMappings, mapping)) {
uniqueMappings.push_back(mapping); uniqueMappings.push_back(mapping);
} }
@ -71,9 +71,9 @@ std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
return uniqueMappings; return uniqueMappings;
} }
std::map<std::string, std::vector<KeyMap::KeyTarget>> BuildKeyMapping(Settings::InputDeviceMapping mapping) { static std::map<std::string, std::vector<KeyMap::KeyTarget>> BuildKeyMapping(Settings::InputDeviceMapping mapping) {
std::map<std::string, std::vector<KeyMap::KeyTarget>> keyMapping; std::map<std::string, std::vector<KeyMap::KeyTarget>> keyMapping;
for (int i = 0; i < Settings::values.input_mappings.size(); i++) { for (size_t i = 0; i < Settings::values.input_mappings.size(); i++) {
KeyMap::KeyTarget val = KeyMap::mapping_targets[i]; KeyMap::KeyTarget val = KeyMap::mapping_targets[i];
std::string key = Settings::values.input_mappings[i].key; std::string key = Settings::values.input_mappings[i].key;
if (Settings::values.input_mappings[i] == mapping) { if (Settings::values.input_mappings[i] == mapping) {
@ -83,10 +83,10 @@ std::map<std::string, std::vector<KeyMap::KeyTarget>> BuildKeyMapping(Settings::
return keyMapping; return keyMapping;
} }
///Generate a device for each unique mapping /// Generate a device for each unique mapping
void GenerateUniqueDevices(std::vector<Settings::InputDeviceMapping> uniqueMappings) { static void GenerateUniqueDevices(const std::vector<Settings::InputDeviceMapping>& uniqueMappings) {
std::shared_ptr<IDevice> input; std::shared_ptr<IDevice> input;
for (auto& mapping : uniqueMappings) { for (const auto& mapping : uniqueMappings) {
switch (mapping.framework) { switch (mapping.framework) {
case Settings::DeviceFramework::Qt: case Settings::DeviceFramework::Qt:
{ {
@ -109,19 +109,17 @@ void GenerateUniqueDevices(std::vector<Settings::InputDeviceMapping> uniqueMappi
} }
devices.push_back(input); devices.push_back(input);
//Build map of inputs to listen for, for this device // Build map of inputs to listen for, for this device
auto keyMapping = BuildKeyMapping(mapping); auto keyMapping = BuildKeyMapping(mapping);
input->InitDevice(mapping.number, keyMapping); input->InitDevice(mapping.number, keyMapping);
} }
} }
void ParseSettings() { void ParseSettings() {
std::vector<std::shared_ptr<IDevice>> devices;
auto uniqueMappings = GatherUniqueMappings(); auto uniqueMappings = GatherUniqueMappings();
GenerateUniqueDevices(uniqueMappings); GenerateUniqueDevices(uniqueMappings);
//init keyboard, if it hasn't already // init keyboard, if it hasn't already
if (main_keyboard == nullptr) if (main_keyboard == nullptr)
main_keyboard = std::make_shared<Keyboard>(); main_keyboard = std::make_shared<Keyboard>();
} }

View File

@ -14,16 +14,16 @@
class Keyboard; class Keyboard;
namespace InputCore { namespace InputCore {
void Init(); void Init();
void Shutdown(); void Shutdown();
Service::HID::PadState GetPadState(); Service::HID::PadState GetPadState();
void SetPadState(Service::HID::PadState& state); void SetPadState(const Service::HID::PadState& state);
std::tuple<s16, s16> GetCirclePad(); std::tuple<s16, s16> GetCirclePad();
void SetCirclePad(std::tuple<s16, s16>& circle ); void SetCirclePad(std::tuple<s16, s16> circle);
std::shared_ptr<Keyboard> GetKeyboard(); std::shared_ptr<Keyboard> GetKeyboard();
/// Read settings to initialize devices /// Read settings to initialize devices
void ParseSettings(); void ParseSettings();
/// Helper method to check if device was already initialized /// Helper method to check if device was already initialized
bool CheckIfMappingExists(const std::vector<Settings::InputDeviceMapping>& uniqueMapping, Settings::InputDeviceMapping mappingToCheck); bool CheckIfMappingExists(const std::vector<Settings::InputDeviceMapping>& uniqueMapping, Settings::InputDeviceMapping mappingToCheck);
} }

View File

@ -12,8 +12,8 @@
#include "input_core/key_map.h" #include "input_core/key_map.h"
namespace KeyMap { namespace KeyMap {
constexpr int MAX_CIRCLEPAD_POS = 0x9C; /// Max value for a circle pad position constexpr int MAX_CIRCLEPAD_POS = 0x9C; /// Max value for a circle pad position
const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets = { { const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets = { {
Service::HID::PAD_A, Service::HID::PAD_B, Service::HID::PAD_X, Service::HID::PAD_Y, Service::HID::PAD_A, Service::HID::PAD_B, Service::HID::PAD_X, Service::HID::PAD_Y,
Service::HID::PAD_L, Service::HID::PAD_R, Service::HID::PAD_ZL, Service::HID::PAD_ZR, Service::HID::PAD_L, Service::HID::PAD_R, Service::HID::PAD_ZL, Service::HID::PAD_ZR,
Service::HID::PAD_START, Service::HID::PAD_SELECT, Service::HID::PAD_TOUCH, Service::HID::PAD_START, Service::HID::PAD_SELECT, Service::HID::PAD_TOUCH,
@ -24,16 +24,16 @@ namespace KeyMap {
Service::HID::PAD_CIRCLE_DOWN, Service::HID::PAD_CIRCLE_DOWN,
Service::HID::PAD_CIRCLE_LEFT, Service::HID::PAD_CIRCLE_LEFT,
Service::HID::PAD_CIRCLE_RIGHT, Service::HID::PAD_CIRCLE_RIGHT,
} }; } };
///Array of inputs that are analog only, and require a strength when set ///Array of inputs that are analog only, and require a strength when set
const std::array<KeyTarget, 4> analog_inputs = { const std::array<KeyTarget, 4> analog_inputs = {
Service::HID::PAD_CIRCLE_UP, Service::HID::PAD_CIRCLE_UP,
Service::HID::PAD_CIRCLE_DOWN, Service::HID::PAD_CIRCLE_DOWN,
Service::HID::PAD_CIRCLE_LEFT, Service::HID::PAD_CIRCLE_LEFT,
Service::HID::PAD_CIRCLE_RIGHT Service::HID::PAD_CIRCLE_RIGHT
}; };
void PressKey(KeyTarget target, const float strength) { void PressKey(KeyTarget target, const float strength) {
auto pad_state = InputCore::GetPadState(); auto pad_state = InputCore::GetPadState();
// If is digital keytarget // If is digital keytarget
if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) { if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) {
@ -50,9 +50,9 @@ namespace KeyMap {
} }
InputCore::SetCirclePad(circle_pad); InputCore::SetCirclePad(circle_pad);
} }
} }
void ReleaseKey(KeyTarget target) { void ReleaseKey(KeyTarget target) {
auto pad_state = InputCore::GetPadState(); auto pad_state = InputCore::GetPadState();
// If is digital keytarget // If is digital keytarget
if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) { if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) {
@ -69,5 +69,5 @@ namespace KeyMap {
} }
InputCore::SetCirclePad(circle_pad); InputCore::SetCirclePad(circle_pad);
} }
} }
} }

View File

@ -12,23 +12,23 @@
class EmuWindow; class EmuWindow;
namespace KeyMap { namespace KeyMap {
/** /**
* Represents key mapping targets that are not real 3DS buttons. * Represents key mapping targets that are not real 3DS buttons.
* They will be handled by KeyMap and translated to 3DS input. * They will be handled by KeyMap and translated to 3DS input.
*/ */
enum class IndirectTarget { enum class IndirectTarget {
CirclePadUp, CirclePadUp,
CirclePadDown, CirclePadDown,
CirclePadLeft, CirclePadLeft,
CirclePadRight, CirclePadRight,
CirclePadModifier CirclePadModifier
}; };
/** /**
* Represents a key mapping target. It can be a PadState that represents real 3DS buttons, * Represents a key mapping target. It can be a PadState that represents real 3DS buttons,
* or an IndirectTarget. * or an IndirectTarget.
*/ */
struct KeyTarget { struct KeyTarget {
bool direct; bool direct;
union { union {
u32 direct_target_hex; u32 direct_target_hex;
@ -52,13 +52,13 @@ namespace KeyMap {
const bool operator==(const KeyTarget &other) const { const bool operator==(const KeyTarget &other) const {
return this->target.direct_target_hex == other.target.direct_target_hex; return this->target.direct_target_hex == other.target.direct_target_hex;
} }
}; };
extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets; extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets;
///Handles the pressing of a key and modifies InputCore state ///Handles the pressing of a key and modifies InputCore state
void PressKey(KeyTarget target, float strength); void PressKey(KeyTarget target, float strength);
///Handles the releasing of a key and modifies InputCore state ///Handles the releasing of a key and modifies InputCore state
void ReleaseKey(KeyTarget target); void ReleaseKey(KeyTarget target);
} }