X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcontrol%2Fgame_controller_manager.cpp;h=4c9ccbf155c927a16667a16438b25d7334466436;hb=4b9d82b256a71b25636bee6a4f54142f8a5e757f;hp=160e598e80d3d70fee25ac55611f6ab6e201d8dd;hpb=f90d0d547f908577a23c922f1cfe9968d7ce86dc;p=supertux.git diff --git a/src/control/game_controller_manager.cpp b/src/control/game_controller_manager.cpp index 160e598e8..4c9ccbf15 100644 --- a/src/control/game_controller_manager.cpp +++ b/src/control/game_controller_manager.cpp @@ -1,5 +1,5 @@ // SuperTux -// Copyright (C) 2014 Ingo Ruhnke +// Copyright (C) 2014 Ingo Ruhnke // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,13 +18,15 @@ #include -#include "control/joystickkeyboardcontroller.hpp" +#include "control/input_manager.hpp" #include "util/log.hpp" -GameControllerManager::GameControllerManager(JoystickKeyboardController* parent) : +GameControllerManager::GameControllerManager(InputManager* parent) : m_parent(parent), m_deadzone(8000), - m_game_controllers() + m_game_controllers(), + m_stick_state(), + m_button_state() { } @@ -40,33 +42,40 @@ void GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev) { //log_info << "button event: " << static_cast(ev.button) << " " << static_cast(ev.state) << std::endl; - auto controller = m_parent->get_main_controller(); + auto controller = m_parent->get_controller(); + auto set_control = [this, &controller](Controller::Control control, bool value) + { + m_button_state[control] = value; + controller->set_control(control, m_button_state[control] || m_stick_state[control]); + }; switch(ev.button) { case SDL_CONTROLLER_BUTTON_A: - controller->set_control(Controller::JUMP, ev.state); - controller->set_control(Controller::MENU_SELECT, ev.state); + set_control(Controller::JUMP, ev.state); + set_control(Controller::MENU_SELECT, ev.state); break; case SDL_CONTROLLER_BUTTON_B: + set_control(Controller::MENU_BACK, ev.state); break; case SDL_CONTROLLER_BUTTON_X: - controller->set_control(Controller::ACTION, ev.state); + set_control(Controller::ACTION, ev.state); break; case SDL_CONTROLLER_BUTTON_Y: break; case SDL_CONTROLLER_BUTTON_BACK: + set_control(Controller::CONSOLE, ev.state); break; case SDL_CONTROLLER_BUTTON_GUIDE: - controller->set_control(Controller::CONSOLE, ev.state); + set_control(Controller::CHEAT_MENU, ev.state); break; case SDL_CONTROLLER_BUTTON_START: - controller->set_control(Controller::PAUSE_MENU, ev.state); + set_control(Controller::PAUSE_MENU, ev.state); break; case SDL_CONTROLLER_BUTTON_LEFTSTICK: @@ -76,27 +85,27 @@ GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev) break; case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: - controller->set_control(Controller::PEEK_LEFT, ev.state); + set_control(Controller::PEEK_LEFT, ev.state); break; case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: - controller->set_control(Controller::PEEK_RIGHT, ev.state); + set_control(Controller::PEEK_RIGHT, ev.state); break; case SDL_CONTROLLER_BUTTON_DPAD_UP: - controller->set_control(Controller::UP, ev.state); + set_control(Controller::UP, ev.state); break; case SDL_CONTROLLER_BUTTON_DPAD_DOWN: - controller->set_control(Controller::DOWN, ev.state); + set_control(Controller::DOWN, ev.state); break; case SDL_CONTROLLER_BUTTON_DPAD_LEFT: - controller->set_control(Controller::LEFT, ev.state); + set_control(Controller::LEFT, ev.state); break; case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: - controller->set_control(Controller::RIGHT, ev.state); + set_control(Controller::RIGHT, ev.state); break; default: @@ -111,24 +120,30 @@ GameControllerManager::process_axis_event(const SDL_ControllerAxisEvent& ev) // to OR the values together //log_info << "axis event: " << static_cast(ev.axis) << " " << ev.value << std::endl; - auto controller = m_parent->get_main_controller(); - auto axis2button = [this, &controller](int value, + auto controller = m_parent->get_controller(); + auto set_control = [this, &controller](Controller::Control control, bool value) + { + m_stick_state[control] = value; + controller->set_control(control, m_button_state[control] || m_stick_state[control]); + }; + + auto axis2button = [this, &set_control](int value, Controller::Control control_left, Controller::Control control_right) { if (value < -m_deadzone) { - controller->set_control(control_left, true); - controller->set_control(control_right, false); + set_control(control_left, true); + set_control(control_right, false); } else if (value > m_deadzone) { - controller->set_control(control_left, false); - controller->set_control(control_right, true); + set_control(control_left, false); + set_control(control_right, true); } else { - controller->set_control(control_left, false); - controller->set_control(control_right, false); + set_control(control_left, false); + set_control(control_right, false); } };