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;
} }
@ -60,10 +60,10 @@ std::shared_ptr<Keyboard> GetKeyboard() {
} }
/// 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) {
@ -84,9 +84,9 @@ std::map<std::string, std::vector<KeyMap::KeyTarget>> BuildKeyMapping(Settings::
} }
/// 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:
{ {
@ -116,8 +116,6 @@ void GenerateUniqueDevices(std::vector<Settings::InputDeviceMapping> uniqueMappi
} }
} }
void ParseSettings() { void ParseSettings() {
std::vector<std::shared_ptr<IDevice>> devices;
auto uniqueMappings = GatherUniqueMappings(); auto uniqueMappings = GatherUniqueMappings();
GenerateUniqueDevices(uniqueMappings); GenerateUniqueDevices(uniqueMappings);

View File

@ -17,9 +17,9 @@ 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();