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) {
auto& keyboard = InputCore::GetKeyboard();
auto keyboard = InputCore::GetKeyboard();
KeyboardKey param = KeyboardKey(key.sym, key.scancode, SDL_GetKeyName(key.scancode));
if (state == SDL_PRESSED) {

View File

@ -237,14 +237,14 @@ void GRenderWindow::closeEvent(QCloseEvent* 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());
keyboard->KeyPressed(param);
}
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());
keyboard->KeyReleased(param);
}

View File

@ -18,5 +18,4 @@ public:
virtual bool CloseDevice() = 0;
protected:
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);
keysPressedCopy = keysPressed;
}
for (const auto &ent1 : keyMapping) {
int scancode = std::stoul(ent1.first, nullptr, 16);
for (const auto& entry : keyMapping) {
int scancode = std::stoul(entry.first, nullptr, 16);
KeyboardKey proxy = KeyboardKey(0, scancode, "");
if (keysPressedCopy[proxy] == true && keysPressedLast[scancode] == false) {
for (const auto& key : ent1.second) {
for (const auto& key : entry.second) {
KeyMap::PressKey(key, 1.0);
}
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);
}
keysPressedLast[scancode] = false;

View File

@ -32,7 +32,9 @@ struct KeyboardKey {
uint32_t scancode;
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 {
return scancode == other.scancode;

View File

@ -47,29 +47,29 @@ void SDLGamepad::ProcessInput() {
if (gamepad == nullptr)
return;
SDL_GameControllerUpdate();
for (const auto &ent1 : keyMapping) {
SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[ent1.first].c_str());
for (const auto& entry : keyMapping) {
SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[entry.first].c_str());
if (button != SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_INVALID) {
Uint8 pressed = SDL_GameControllerGetButton(gamepad, button);
if (pressed == 1 && keysPressed[ent1.first] == false) {
for (const auto& padstate : ent1.second) {
if (pressed == 1 && keysPressed[entry.first] == false) {
for (const auto& padstate : entry.second) {
KeyMap::PressKey(padstate, 1.0);
keysPressed[ent1.first] = true;
keysPressed[entry.first] = true;
}
}
else if (pressed == 0 && keysPressed[ent1.first] == true) {
for (const auto& padstate : ent1.second) {
else if (pressed == 0 && keysPressed[entry.first] == true) {
for (const auto& padstate : entry.second) {
KeyMap::ReleaseKey(padstate);
keysPressed[ent1.first] = false;
keysPressed[entry.first] = false;
}
}
}
else {
// 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) {
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.
if (abs(value) < 0.2 * 32767.0)
KeyMap::ReleaseKey(padstate);

View File

@ -17,7 +17,8 @@ public:
void ProcessInput() override;
bool CloseDevice() override;
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 B","b" },
{ "Button X","x" },

View File

@ -14,10 +14,10 @@
namespace InputCore {
constexpr u64 frame_ticks = 268123480ull / 60;
static int tick_event;
Service::HID::PadState pad_state;
std::tuple<s16, s16> circle_pad = { 0,0 };
std::shared_ptr<Keyboard> main_keyboard;
std::vector<std::shared_ptr<IDevice>> devices; ///< Devices that are handling input for the game
static Service::HID::PadState pad_state;
static std::tuple<s16, s16> circle_pad = { 0,0 };
static std::shared_ptr<Keyboard> main_keyboard;
static std::vector<std::shared_ptr<IDevice>> devices; ///< Devices that are handling input for the game
static void InputTickCallback(u64, int cycles_late) {
for (auto& device : devices)
@ -43,7 +43,7 @@ Service::HID::PadState GetPadState() {
return pad_state;
}
void SetPadState(Service::HID::PadState& state) {
void SetPadState(const Service::HID::PadState& state) {
pad_state.hex = state.hex;
}
@ -51,7 +51,7 @@ std::tuple<s16, s16> GetCirclePad() {
return circle_pad;
}
void SetCirclePad(std::tuple<s16, s16>& pad) {
void SetCirclePad(std::tuple<s16, s16> pad) {
circle_pad = pad;
}
@ -60,10 +60,10 @@ std::shared_ptr<Keyboard> GetKeyboard() {
}
/// Get Unique input mappings from settings
std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
static std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
std::vector<Settings::InputDeviceMapping> uniqueMappings;
for (auto& mapping : Settings::values.input_mappings) {
for (const auto& mapping : Settings::values.input_mappings) {
if (!CheckIfMappingExists(uniqueMappings, mapping)) {
uniqueMappings.push_back(mapping);
}
@ -71,9 +71,9 @@ std::vector<Settings::InputDeviceMapping> GatherUniqueMappings() {
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;
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];
std::string key = Settings::values.input_mappings[i].key;
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
void GenerateUniqueDevices(std::vector<Settings::InputDeviceMapping> uniqueMappings) {
static void GenerateUniqueDevices(const std::vector<Settings::InputDeviceMapping>& uniqueMappings) {
std::shared_ptr<IDevice> input;
for (auto& mapping : uniqueMappings) {
for (const auto& mapping : uniqueMappings) {
switch (mapping.framework) {
case Settings::DeviceFramework::Qt:
{
@ -116,8 +116,6 @@ void GenerateUniqueDevices(std::vector<Settings::InputDeviceMapping> uniqueMappi
}
}
void ParseSettings() {
std::vector<std::shared_ptr<IDevice>> devices;
auto uniqueMappings = GatherUniqueMappings();
GenerateUniqueDevices(uniqueMappings);

View File

@ -17,9 +17,9 @@ namespace InputCore {
void Init();
void Shutdown();
Service::HID::PadState GetPadState();
void SetPadState(Service::HID::PadState& state);
void SetPadState(const Service::HID::PadState& state);
std::tuple<s16, s16> GetCirclePad();
void SetCirclePad(std::tuple<s16, s16>& circle );
void SetCirclePad(std::tuple<s16, s16> circle);
std::shared_ptr<Keyboard> GetKeyboard();
/// Read settings to initialize devices
void ParseSettings();