From 695a14a406d163322c46e062b4f17913ad11f06a Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Fri, 1 Oct 2021 05:13:16 +0800 Subject: [PATCH] Rename game_controller to gamepad --- CMakeLists.txt | 1 + src/application.cpp | 38 +++---- src/application.hpp | 14 +-- src/event/input-events.cpp | 20 ++-- src/event/input-events.hpp | 28 ++--- src/game/bootloader.cpp | 6 +- src/game/states/loading.cpp | 100 +++++++++--------- src/game/states/splash.cpp | 2 +- src/input/event-router.cpp | 52 ++++----- src/input/event-router.hpp | 20 ++-- .../{game-controller.cpp => gamepad.cpp} | 74 ++++++------- .../{game-controller.hpp => gamepad.hpp} | 67 ++++++------ src/input/input.hpp | 2 +- src/input/listener.cpp | 12 +-- src/input/listener.hpp | 8 +- src/input/mapper.cpp | 16 +-- src/input/mapper.hpp | 8 +- src/input/mapping.cpp | 12 +-- src/input/mapping.hpp | 54 +++++----- src/input/sdl-game-controller-tables.cpp | 48 ++++----- src/input/sdl-game-controller-tables.hpp | 14 +-- 21 files changed, 298 insertions(+), 298 deletions(-) rename src/input/{game-controller.cpp => gamepad.cpp} (70%) rename src/input/{game-controller.hpp => gamepad.hpp} (69%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4aa351..af368e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.7) + option(VERSION_STRING "Project version string" "0.0.0") project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX) diff --git a/src/application.cpp b/src/application.cpp index acf0ebb..ee7cc35 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -174,7 +174,7 @@ application::application(): logger->pop_task(EXIT_SUCCESS); } - // Init SDL joystick and game controller subsystems + // Init SDL joystick and gamepad subsystems logger->push_task("Initializing SDL Joystick and Game Controller subsystems"); if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) != 0) { @@ -185,9 +185,9 @@ application::application(): logger->pop_task(EXIT_SUCCESS); } - // Load SDL game controller mappings + // Load SDL gamepad mappings /* - logger->push_task("Loading SDL game controller mappings from database"); + logger->push_task("Loading SDL gamepad mappings from database"); std::string gamecontrollerdb_path = data_path + "controls/gamecontrollerdb.txt"; if (SDL_GameControllerAddMappingsFromFile(gamecontrollerdb_path.c_str()) == -1) { @@ -211,7 +211,7 @@ application::application(): mouse = new input::mouse(); mouse->set_event_dispatcher(event_dispatcher); - // Connect game controllers + // Connect gamepads translate_sdl_events(); // Setup frame scheduler @@ -600,9 +600,9 @@ void application::translate_sdl_events() { if (sdl_event.cbutton.button != SDL_CONTROLLER_BUTTON_INVALID) { - if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end()) + if (auto it = gamepad_map.find(sdl_event.cdevice.which); it != gamepad_map.end()) { - input::game_controller_button button = input::sdl_button_table[sdl_event.cbutton.button]; + input::gamepad_button button = input::sdl_button_table[sdl_event.cbutton.button]; it->second->press(button); } } @@ -613,9 +613,9 @@ void application::translate_sdl_events() { if (sdl_event.cbutton.button != SDL_CONTROLLER_BUTTON_INVALID) { - if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end()) + if (auto it = gamepad_map.find(sdl_event.cdevice.which); it != gamepad_map.end()) { - input::game_controller_button button = input::sdl_button_table[sdl_event.cbutton.button]; + input::gamepad_button button = input::sdl_button_table[sdl_event.cbutton.button]; it->second->release(button); } } @@ -626,9 +626,9 @@ void application::translate_sdl_events() { if (sdl_event.caxis.axis != SDL_CONTROLLER_AXIS_INVALID) { - if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end()) + if (auto it = gamepad_map.find(sdl_event.cdevice.which); it != gamepad_map.end()) { - input::game_controller_axis axis = input::sdl_axis_table[sdl_event.caxis.axis]; + input::gamepad_axis axis = input::sdl_axis_table[sdl_event.caxis.axis]; float value = sdl_event.caxis.value; value /= (value < 0.0f) ? 32768.0f : 32767.0f; it->second->move(axis, value); @@ -646,27 +646,27 @@ void application::translate_sdl_events() std::string controller_name = SDL_GameControllerNameForIndex(sdl_event.cdevice.which); if (sdl_controller) { - if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end()) + if (auto it = gamepad_map.find(sdl_event.cdevice.which); it != gamepad_map.end()) { - logger->log("Reconnected game controller \"" + controller_name + "\""); + logger->log("Reconnected gamepad \"" + controller_name + "\""); it->second->connect(true); } else { - logger->log("Connected game controller \"" + controller_name + "\""); + logger->log("Connected gamepad \"" + controller_name + "\""); - input::game_controller* controller = new input::game_controller(); + input::gamepad* controller = new input::gamepad(); controller->set_event_dispatcher(event_dispatcher); - game_controllers.push_back(controller); - game_controller_map[sdl_event.cdevice.which] = controller; + gamepads.push_back(controller); + gamepad_map[sdl_event.cdevice.which] = controller; controller->connect(false); } } else { - logger->error("Failed to connected game controller \"" + controller_name + "\""); + logger->error("Failed to connected gamepad \"" + controller_name + "\""); } } @@ -680,9 +680,9 @@ void application::translate_sdl_events() if (sdl_controller) { SDL_GameControllerClose(sdl_controller); - logger->log("Disconnected game controller"); + logger->log("Disconnected gamepad"); - if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end()) + if (auto it = gamepad_map.find(sdl_event.cdevice.which); it != gamepad_map.end()) { it->second->disconnect(); } diff --git a/src/application.hpp b/src/application.hpp index 43ca4d2..ff7f411 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -28,7 +28,7 @@ #include "gl/rasterizer.hpp" #include "input/keyboard.hpp" #include "input/mouse.hpp" -#include "input/game-controller.hpp" +#include "input/gamepad.hpp" // Forward declarations typedef struct SDL_Window SDL_Window; @@ -210,8 +210,8 @@ public: /// Returns the virtual mouse. input::mouse* get_mouse(); - /// Returns the list of virtual game controllers. - const std::list& get_game_controllers(); + /// Returns the list of virtual gamepads. + const std::list& get_gamepads(); /// Returns the application's event dispatcher. event_dispatcher* get_event_dispatcher(); @@ -254,8 +254,8 @@ private: // Input devices input::keyboard* keyboard; input::mouse* mouse; - std::list game_controllers; - std::unordered_map game_controller_map; + std::list gamepads; + std::unordered_map gamepad_map; }; inline debug::logger* application::get_logger() @@ -298,9 +298,9 @@ inline input::mouse* application::get_mouse() return mouse; } -inline const std::list& application::get_game_controllers() +inline const std::list& application::get_gamepads() { - return game_controllers; + return gamepads; } inline event_dispatcher* application::get_event_dispatcher() diff --git a/src/event/input-events.cpp b/src/event/input-events.cpp index 7ccbdd9..35d4d0d 100644 --- a/src/event/input-events.cpp +++ b/src/event/input-events.cpp @@ -75,40 +75,40 @@ event_base* mouse_wheel_scrolled_event::clone() const return event; } -event_base* game_controller_connected_event::clone() const +event_base* gamepad_connected_event::clone() const { - game_controller_connected_event* event = new game_controller_connected_event(); + gamepad_connected_event* event = new gamepad_connected_event(); event->controller = controller; event->reconnected = reconnected; return event; } -event_base* game_controller_disconnected_event::clone() const +event_base* gamepad_disconnected_event::clone() const { - game_controller_disconnected_event* event = new game_controller_disconnected_event(); + gamepad_disconnected_event* event = new gamepad_disconnected_event(); event->controller = controller; return event; } -event_base* game_controller_button_pressed_event::clone() const +event_base* gamepad_button_pressed_event::clone() const { - game_controller_button_pressed_event* event = new game_controller_button_pressed_event(); + gamepad_button_pressed_event* event = new gamepad_button_pressed_event(); event->controller = controller; event->button = button; return event; } -event_base* game_controller_button_released_event::clone() const +event_base* gamepad_button_released_event::clone() const { - game_controller_button_released_event* event = new game_controller_button_released_event(); + gamepad_button_released_event* event = new gamepad_button_released_event(); event->controller = controller; event->button = button; return event; } -event_base* game_controller_axis_moved_event::clone() const +event_base* gamepad_axis_moved_event::clone() const { - game_controller_axis_moved_event* event = new game_controller_axis_moved_event(); + gamepad_axis_moved_event* event = new gamepad_axis_moved_event(); event->controller = controller; event->axis = axis; event->value = value; diff --git a/src/event/input-events.hpp b/src/event/input-events.hpp index 20a912f..287120e 100644 --- a/src/event/input-events.hpp +++ b/src/event/input-events.hpp @@ -24,7 +24,7 @@ #include "input/scancode.hpp" #include "input/keyboard.hpp" #include "input/mouse.hpp" -#include "input/game-controller.hpp" +#include "input/gamepad.hpp" /** * Input event which indicates a keyboard key has been pressed. @@ -109,60 +109,60 @@ public: /** * Input event which indicates a controller has been connected. */ -class game_controller_connected_event: public event +class gamepad_connected_event: public event { public: virtual event_base* clone() const; - input::game_controller* controller; + input::gamepad* controller; bool reconnected; }; /** * Input event which indicates a controller has been disconnected. */ -class game_controller_disconnected_event: public event +class gamepad_disconnected_event: public event { public: virtual event_base* clone() const; - input::game_controller* controller; + input::gamepad* controller; }; /** * Input event which indicates a controller button has been pressed. */ -class game_controller_button_pressed_event: public event +class gamepad_button_pressed_event: public event { public: virtual event_base* clone() const; - input::game_controller* controller; - input::game_controller_button button; + input::gamepad* controller; + input::gamepad_button button; }; /** * Input event which indicates a controller button has been released. */ -class game_controller_button_released_event: public event +class gamepad_button_released_event: public event { public: virtual event_base* clone() const; - input::game_controller* controller; - input::game_controller_button button; + input::gamepad* controller; + input::gamepad_button button; }; /** * Input event which indicates a controller axis has been moved. */ -class game_controller_axis_moved_event: public event +class gamepad_axis_moved_event: public event { public: virtual event_base* clone() const; - input::game_controller* controller; - input::game_controller_axis axis; + input::gamepad* controller; + input::gamepad_axis axis; float value; }; diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 57ed91d..5f658b3 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -81,7 +81,7 @@ #include "input/event-router.hpp" #include "input/mapper.hpp" #include "input/listener.hpp" -#include "input/game-controller.hpp" +#include "input/gamepad.hpp" #include "input/mouse.hpp" #include "input/keyboard.hpp" #include "configuration.hpp" @@ -892,9 +892,9 @@ void setup_controls(game::context* ctx) /* // Add menu control mappings - ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->menu_back_control, nullptr, input::game_controller_button::b)); + ctx->input_event_router->add_mapping(input::gamepad_button_mapping(ctx->menu_back_control, nullptr, input::gamepad_button::b)); //ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_tool_menu_control(), nullptr, input::scancode::left_shift)); - ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->control_system->get_tool_menu_control(), nullptr, input::game_controller_button::x)); + ctx->input_event_router->add_mapping(input::gamepad_button_mapping(ctx->control_system->get_tool_menu_control(), nullptr, input::gamepad_button::x)); ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_select_control, nullptr, input::scancode::enter)); ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_select_control, nullptr, input::scancode::space)); diff --git a/src/game/states/loading.cpp b/src/game/states/loading.cpp index fb85367..df07ad0 100644 --- a/src/game/states/loading.cpp +++ b/src/game/states/loading.cpp @@ -56,7 +56,7 @@ namespace loading { /// Creates or loads control configuration static void load_controls(game::context* ctx); -static input::game_controller_response_curve parse_response_curve(const std::string& curve); +static input::gamepad_response_curve parse_response_curve(const std::string& curve); /// Creates the universe and solar system. static void cosmogenesis(game::context* ctx); @@ -155,7 +155,7 @@ void load_controls(game::context* ctx) ctx->controls["tilt_down_mouse"] = new input::control(); ctx->controls["use_tool"] = new input::control(); - // Set activation threshold for menu navigation controls to mitigate drifting game controller axes + // Set activation threshold for menu navigation controls to mitigate drifting gamepad axes const float menu_activation_threshold = 0.1f; ctx->controls["menu_up"]->set_activation_threshold(menu_activation_threshold); ctx->controls["menu_down"]->set_activation_threshold(menu_activation_threshold); @@ -166,33 +166,33 @@ void load_controls(game::context* ctx) input::keyboard* keyboard = ctx->app->get_keyboard(); input::mouse* mouse = ctx->app->get_mouse(); - const std::unordered_map gamepad_button_map = + const std::unordered_map gamepad_button_map = { - {"a", input::game_controller_button::a}, - {"b", input::game_controller_button::b}, - {"x", input::game_controller_button::x}, - {"y", input::game_controller_button::y}, - {"back", input::game_controller_button::back}, - {"guide", input::game_controller_button::guide}, - {"start", input::game_controller_button::start}, - {"leftstick", input::game_controller_button::left_stick}, - {"rightstick", input::game_controller_button::right_stick}, - {"leftshoulder", input::game_controller_button::left_shoulder}, - {"rightshoulder", input::game_controller_button::right_shoulder}, - {"dpup", input::game_controller_button::dpad_up}, - {"dpdown", input::game_controller_button::dpad_down}, - {"dpleft", input::game_controller_button::dpad_left}, - {"dpright", input::game_controller_button::dpad_right} + {"a", input::gamepad_button::a}, + {"b", input::gamepad_button::b}, + {"x", input::gamepad_button::x}, + {"y", input::gamepad_button::y}, + {"back", input::gamepad_button::back}, + {"guide", input::gamepad_button::guide}, + {"start", input::gamepad_button::start}, + {"leftstick", input::gamepad_button::left_stick}, + {"rightstick", input::gamepad_button::right_stick}, + {"leftshoulder", input::gamepad_button::left_shoulder}, + {"rightshoulder", input::gamepad_button::right_shoulder}, + {"dpup", input::gamepad_button::dpad_up}, + {"dpdown", input::gamepad_button::dpad_down}, + {"dpleft", input::gamepad_button::dpad_left}, + {"dpright", input::gamepad_button::dpad_right} }; - const std::unordered_map gamepad_axis_map = + const std::unordered_map gamepad_axis_map = { - {"leftx", input::game_controller_axis::left_x}, - {"lefty", input::game_controller_axis::left_y}, - {"rightx", input::game_controller_axis::right_x}, - {"righty", input::game_controller_axis::right_y}, - {"lefttrigger", input::game_controller_axis::left_trigger}, - {"righttrigger", input::game_controller_axis::right_trigger} + {"leftx", input::gamepad_axis::left_x}, + {"lefty", input::gamepad_axis::left_y}, + {"rightx", input::gamepad_axis::right_x}, + {"righty", input::gamepad_axis::right_y}, + {"lefttrigger", input::gamepad_axis::left_trigger}, + {"righttrigger", input::gamepad_axis::right_trigger} }; // Check if a control profile is set in the config file @@ -335,7 +335,7 @@ void load_controls(game::context* ctx) } // Map control to gamepad button - ctx->input_event_router->add_mapping(input::game_controller_button_mapping(control, nullptr, button_it->second)); + ctx->input_event_router->add_mapping(input::gamepad_button_mapping(control, nullptr, button_it->second)); ctx->logger->log("Mapped control \"" + name + "\" to gamepad button " + button); } @@ -362,7 +362,7 @@ void load_controls(game::context* ctx) bool axis_negative = (axis_sign == '-'); // Map control to gamepad axis - ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(control, nullptr, axis_it->second, axis_negative)); + ctx->input_event_router->add_mapping(input::gamepad_axis_mapping(control, nullptr, axis_it->second, axis_negative)); ctx->logger->log("Mapped control \"" + name + "\" to gamepad axis " + axis); } @@ -396,12 +396,12 @@ void load_controls(game::context* ctx) bool gamepad_right_deadzone_cross = true; float gamepad_left_deadzone_roundness = 0.0f; float gamepad_right_deadzone_roundness = 0.0f; - input::game_controller_response_curve gamepad_leftx_response_curve = input::game_controller_response_curve::linear; - input::game_controller_response_curve gamepad_lefty_response_curve = input::game_controller_response_curve::linear; - input::game_controller_response_curve gamepad_rightx_response_curve = input::game_controller_response_curve::linear; - input::game_controller_response_curve gamepad_righty_response_curve = input::game_controller_response_curve::linear; - input::game_controller_response_curve gamepad_lefttrigger_response_curve = input::game_controller_response_curve::linear; - input::game_controller_response_curve gamepad_righttrigger_response_curve = input::game_controller_response_curve::linear; + input::gamepad_response_curve gamepad_leftx_response_curve = input::gamepad_response_curve::linear; + input::gamepad_response_curve gamepad_lefty_response_curve = input::gamepad_response_curve::linear; + input::gamepad_response_curve gamepad_rightx_response_curve = input::gamepad_response_curve::linear; + input::gamepad_response_curve gamepad_righty_response_curve = input::gamepad_response_curve::linear; + input::gamepad_response_curve gamepad_lefttrigger_response_curve = input::gamepad_response_curve::linear; + input::gamepad_response_curve gamepad_righttrigger_response_curve = input::gamepad_response_curve::linear; if (ctx->config->contains("gamepad_leftx_activation_min")) gamepad_leftx_activation_min = (*ctx->config)["gamepad_leftx_activation_min"].get(); @@ -448,24 +448,24 @@ void load_controls(game::context* ctx) if (ctx->config->contains("gamepad_righttrigger_response_curve")) gamepad_righttrigger_response_curve = parse_response_curve((*ctx->config)["gamepad_righttrigger_response_curve"].get()); - for (input::game_controller* gamepad: ctx->app->get_game_controllers()) + for (input::gamepad* gamepad: ctx->app->get_gamepads()) { - gamepad->set_activation_threshold(input::game_controller_axis::left_x, gamepad_leftx_activation_min, gamepad_leftx_activation_max); - gamepad->set_activation_threshold(input::game_controller_axis::left_y, gamepad_lefty_activation_min, gamepad_lefty_activation_max); - gamepad->set_activation_threshold(input::game_controller_axis::right_x, gamepad_rightx_activation_min, gamepad_rightx_activation_max); - gamepad->set_activation_threshold(input::game_controller_axis::right_y, gamepad_righty_activation_min, gamepad_righty_activation_max); - gamepad->set_activation_threshold(input::game_controller_axis::left_trigger, gamepad_lefttrigger_activation_min, gamepad_lefttrigger_activation_max); - gamepad->set_activation_threshold(input::game_controller_axis::right_trigger, gamepad_righttrigger_activation_min, gamepad_righttrigger_activation_max); + gamepad->set_activation_threshold(input::gamepad_axis::left_x, gamepad_leftx_activation_min, gamepad_leftx_activation_max); + gamepad->set_activation_threshold(input::gamepad_axis::left_y, gamepad_lefty_activation_min, gamepad_lefty_activation_max); + gamepad->set_activation_threshold(input::gamepad_axis::right_x, gamepad_rightx_activation_min, gamepad_rightx_activation_max); + gamepad->set_activation_threshold(input::gamepad_axis::right_y, gamepad_righty_activation_min, gamepad_righty_activation_max); + gamepad->set_activation_threshold(input::gamepad_axis::left_trigger, gamepad_lefttrigger_activation_min, gamepad_lefttrigger_activation_max); + gamepad->set_activation_threshold(input::gamepad_axis::right_trigger, gamepad_righttrigger_activation_min, gamepad_righttrigger_activation_max); gamepad->set_left_deadzone_cross(gamepad_left_deadzone_cross); gamepad->set_right_deadzone_cross(gamepad_right_deadzone_cross); gamepad->set_left_deadzone_roundness(gamepad_left_deadzone_roundness); gamepad->set_right_deadzone_roundness(gamepad_right_deadzone_roundness); - gamepad->set_response_curve(input::game_controller_axis::left_x, gamepad_leftx_response_curve); - gamepad->set_response_curve(input::game_controller_axis::left_y, gamepad_lefty_response_curve); - gamepad->set_response_curve(input::game_controller_axis::right_x, gamepad_rightx_response_curve); - gamepad->set_response_curve(input::game_controller_axis::right_y, gamepad_righty_response_curve); - gamepad->set_response_curve(input::game_controller_axis::left_trigger, gamepad_lefttrigger_response_curve); - gamepad->set_response_curve(input::game_controller_axis::right_trigger, gamepad_righttrigger_response_curve); + gamepad->set_response_curve(input::gamepad_axis::left_x, gamepad_leftx_response_curve); + gamepad->set_response_curve(input::gamepad_axis::left_y, gamepad_lefty_response_curve); + gamepad->set_response_curve(input::gamepad_axis::right_x, gamepad_rightx_response_curve); + gamepad->set_response_curve(input::gamepad_axis::right_y, gamepad_righty_response_curve); + gamepad->set_response_curve(input::gamepad_axis::left_trigger, gamepad_lefttrigger_response_curve); + gamepad->set_response_curve(input::gamepad_axis::right_trigger, gamepad_righttrigger_response_curve); } // Toggle fullscreen @@ -507,13 +507,13 @@ void load_controls(game::context* ctx) ); } -static input::game_controller_response_curve parse_response_curve(const std::string& curve) +static input::gamepad_response_curve parse_response_curve(const std::string& curve) { if (curve == "square") - return input::game_controller_response_curve::square; + return input::gamepad_response_curve::square; else if (curve == "cube") - return input::game_controller_response_curve::cube; - return input::game_controller_response_curve::linear; + return input::gamepad_response_curve::cube; + return input::gamepad_response_curve::linear; } void cosmogenesis(game::context* ctx) diff --git a/src/game/states/splash.cpp b/src/game/states/splash.cpp index 54369a7..bc64f99 100644 --- a/src/game/states/splash.cpp +++ b/src/game/states/splash.cpp @@ -74,7 +74,7 @@ void enter(game::context* ctx) [ctx](const event_base& event) { auto id = event.get_event_type_id(); - if (id != mouse_moved_event::event_type_id && id != mouse_wheel_scrolled_event::event_type_id && id != game_controller_axis_moved_event::event_type_id) + if (id != mouse_moved_event::event_type_id && id != mouse_wheel_scrolled_event::event_type_id && id != gamepad_axis_moved_event::event_type_id) { ctx->timeline->clear(); ctx->fade_transition->get_animation()->stop(); diff --git a/src/input/event-router.cpp b/src/input/event-router.cpp index a9fcb35..bc94930 100644 --- a/src/input/event-router.cpp +++ b/src/input/event-router.cpp @@ -77,20 +77,20 @@ void event_router::add_mapping(const mapping& mapping) break; } - case mapping_type::game_controller_axis: + case mapping_type::gamepad_axis: { - input::game_controller_axis_mapping* game_controller_axis_mapping = new input::game_controller_axis_mapping(static_cast(mapping)); - game_controller_axis_mappings.push_back(game_controller_axis_mapping); - controls[control].push_back(game_controller_axis_mapping); + input::gamepad_axis_mapping* gamepad_axis_mapping = new input::gamepad_axis_mapping(static_cast(mapping)); + gamepad_axis_mappings.push_back(gamepad_axis_mapping); + controls[control].push_back(gamepad_axis_mapping); break; } - case mapping_type::game_controller_button: + case mapping_type::gamepad_button: { - input::game_controller_button_mapping* game_controller_button_mapping = new input::game_controller_button_mapping(static_cast(mapping)); - game_controller_button_mappings.push_back(game_controller_button_mapping); - controls[control].push_back(game_controller_button_mapping); + input::gamepad_button_mapping* gamepad_button_mapping = new input::gamepad_button_mapping(static_cast(mapping)); + gamepad_button_mappings.push_back(gamepad_button_mapping); + controls[control].push_back(gamepad_button_mapping); break; } @@ -125,12 +125,12 @@ void event_router::remove_mappings(control* control) mouse_button_mappings.remove(static_cast(mapping)); break; - case mapping_type::game_controller_axis: - game_controller_axis_mappings.remove(static_cast(mapping)); + case mapping_type::gamepad_axis: + gamepad_axis_mappings.remove(static_cast(mapping)); break; - case mapping_type::game_controller_button: - game_controller_button_mappings.remove(static_cast(mapping)); + case mapping_type::gamepad_button: + gamepad_button_mappings.remove(static_cast(mapping)); break; default: @@ -154,9 +154,9 @@ void event_router::set_event_dispatcher(::event_dispatcher* event_dispatcher) this->event_dispatcher->unsubscribe(this); this->event_dispatcher->unsubscribe(this); this->event_dispatcher->unsubscribe(this); - this->event_dispatcher->unsubscribe(this); - this->event_dispatcher->unsubscribe(this); - this->event_dispatcher->unsubscribe(this); + this->event_dispatcher->unsubscribe(this); + this->event_dispatcher->unsubscribe(this); + this->event_dispatcher->unsubscribe(this); } this->event_dispatcher = event_dispatcher; @@ -169,9 +169,9 @@ void event_router::set_event_dispatcher(::event_dispatcher* event_dispatcher) event_dispatcher->subscribe(this); event_dispatcher->subscribe(this); event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); } } @@ -190,8 +190,8 @@ void event_router::remove_mappings() mouse_motion_mappings.clear(); mouse_wheel_mappings.clear(); mouse_button_mappings.clear(); - game_controller_axis_mappings.clear(); - game_controller_button_mappings.clear(); + gamepad_axis_mappings.clear(); + gamepad_button_mappings.clear(); } const std::list* event_router::get_mappings(control* control) const @@ -301,9 +301,9 @@ void event_router::handle_event(const mouse_button_released_event& event) } } -void event_router::handle_event(const game_controller_axis_moved_event& event) +void event_router::handle_event(const gamepad_axis_moved_event& event) { - for (const game_controller_axis_mapping* mapping: game_controller_axis_mappings) + for (const gamepad_axis_mapping* mapping: gamepad_axis_mappings) { if ((!mapping->controller || mapping->controller == event.controller) && mapping->axis == event.axis) { @@ -319,9 +319,9 @@ void event_router::handle_event(const game_controller_axis_moved_event& event) } } -void event_router::handle_event(const game_controller_button_pressed_event& event) +void event_router::handle_event(const gamepad_button_pressed_event& event) { - for (const game_controller_button_mapping* mapping: game_controller_button_mappings) + for (const gamepad_button_mapping* mapping: gamepad_button_mappings) { if ((!mapping->controller || mapping->controller == event.controller) && mapping->button == event.button) { @@ -330,9 +330,9 @@ void event_router::handle_event(const game_controller_button_pressed_event& even } } -void event_router::handle_event(const game_controller_button_released_event& event) +void event_router::handle_event(const gamepad_button_released_event& event) { - for (const game_controller_button_mapping* mapping: game_controller_button_mappings) + for (const gamepad_button_mapping* mapping: gamepad_button_mappings) { if ((!mapping->controller || mapping->controller == event.controller) && mapping->button == event.button) { diff --git a/src/input/event-router.hpp b/src/input/event-router.hpp index 3673608..dc60c82 100644 --- a/src/input/event-router.hpp +++ b/src/input/event-router.hpp @@ -34,8 +34,8 @@ class key_mapping; class mouse_motion_mapping; class mouse_wheel_mapping; class mouse_button_mapping; -class game_controller_axis_mapping; -class game_controller_button_mapping; +class gamepad_axis_mapping; +class gamepad_button_mapping; enum class mouse_motion_axis; enum class mouse_wheel_axis; @@ -49,9 +49,9 @@ class event_router: public event_handler, public event_handler, public event_handler, - public event_handler, - public event_handler, - public event_handler + public event_handler, + public event_handler, + public event_handler { public: /** @@ -99,9 +99,9 @@ private: virtual void handle_event(const mouse_wheel_scrolled_event& event); virtual void handle_event(const mouse_button_pressed_event& event); virtual void handle_event(const mouse_button_released_event& event); - virtual void handle_event(const game_controller_axis_moved_event& event); - virtual void handle_event(const game_controller_button_pressed_event& event); - virtual void handle_event(const game_controller_button_released_event& event); + virtual void handle_event(const gamepad_axis_moved_event& event); + virtual void handle_event(const gamepad_button_pressed_event& event); + virtual void handle_event(const gamepad_button_released_event& event); event_dispatcher* event_dispatcher; std::map> controls; @@ -109,8 +109,8 @@ private: std::list mouse_motion_mappings; std::list mouse_wheel_mappings; std::list mouse_button_mappings; - std::list game_controller_axis_mappings; - std::list game_controller_button_mappings; + std::list gamepad_axis_mappings; + std::list gamepad_button_mappings; }; } // namespace input diff --git a/src/input/game-controller.cpp b/src/input/gamepad.cpp similarity index 70% rename from src/input/game-controller.cpp rename to src/input/gamepad.cpp index c593712..191a99b 100644 --- a/src/input/game-controller.cpp +++ b/src/input/gamepad.cpp @@ -17,7 +17,7 @@ * along with Antkeeper source code. If not, see . */ -#include "game-controller.hpp" +#include "gamepad.hpp" #include "event/input-events.hpp" #include "event/event-dispatcher.hpp" #include "math/map.hpp" @@ -26,7 +26,7 @@ namespace input { -game_controller::game_controller(): +gamepad::gamepad(): connected(true), left_deadzone_cross(true), right_deadzone_cross(true), @@ -38,70 +38,70 @@ game_controller::game_controller(): axis_values[i] = 0.0f; axis_activation_min[i] = 0.0f; axis_activation_max[i] = 1.0f; - axis_response_curves[i] = game_controller_response_curve::linear; + axis_response_curves[i] = gamepad_response_curve::linear; } } -void game_controller::set_activation_threshold(game_controller_axis axis, float min, float max) +void gamepad::set_activation_threshold(gamepad_axis axis, float min, float max) { axis_activation_min[static_cast(axis)] = min; axis_activation_max[static_cast(axis)] = max; } -void game_controller::set_response_curve(game_controller_axis axis, game_controller_response_curve curve) +void gamepad::set_response_curve(gamepad_axis axis, gamepad_response_curve curve) { axis_response_curves[static_cast(axis)] = curve; } -void game_controller::set_left_deadzone_cross(bool cross) +void gamepad::set_left_deadzone_cross(bool cross) { left_deadzone_cross = cross; } -void game_controller::set_right_deadzone_cross(bool cross) +void gamepad::set_right_deadzone_cross(bool cross) { right_deadzone_cross = cross; } -void game_controller::set_left_deadzone_roundness(float roundness) +void gamepad::set_left_deadzone_roundness(float roundness) { left_deadzone_roundness = roundness; } -void game_controller::set_right_deadzone_roundness(float roundness) +void gamepad::set_right_deadzone_roundness(float roundness) { right_deadzone_roundness = roundness; } -void game_controller::press(game_controller_button button) +void gamepad::press(gamepad_button button) { if (!device::event_dispatcher) { return; } - game_controller_button_pressed_event event; + gamepad_button_pressed_event event; event.controller = this; event.button = button; device::event_dispatcher->queue(event); } -void game_controller::release(game_controller_button button) +void gamepad::release(gamepad_button button) { if (!device::event_dispatcher) { return; } - game_controller_button_released_event event; + gamepad_button_released_event event; event.controller = this; event.button = button; device::event_dispatcher->queue(event); } -void game_controller::move(game_controller_axis axis, float value) +void gamepad::move(gamepad_axis axis, float value) { // Update axis value axis_values[static_cast(axis)] = value; @@ -113,20 +113,20 @@ void game_controller::move(game_controller_axis axis, float value) switch (axis) { - case game_controller_axis::left_x: - case game_controller_axis::left_y: + case gamepad_axis::left_x: + case gamepad_axis::left_y: if (left_deadzone_cross) handle_axial_motion(axis); else - handle_biaxial_motion(game_controller_axis::left_x, game_controller_axis::left_y); + handle_biaxial_motion(gamepad_axis::left_x, gamepad_axis::left_y); break; - case game_controller_axis::right_x: - case game_controller_axis::right_y: + case gamepad_axis::right_x: + case gamepad_axis::right_y: if (right_deadzone_cross) handle_axial_motion(axis); else - handle_biaxial_motion(game_controller_axis::right_x, game_controller_axis::right_y); + handle_biaxial_motion(gamepad_axis::right_x, gamepad_axis::right_y); break; default: @@ -135,17 +135,17 @@ void game_controller::move(game_controller_axis axis, float value) } } -void game_controller::handle_axial_motion(game_controller_axis axis) +void gamepad::handle_axial_motion(gamepad_axis axis) { // Get axis parameters const int axis_index = static_cast(axis); const float activation_min = axis_activation_min[axis_index]; const float activation_max = axis_activation_max[axis_index]; const float axis_value = axis_values[axis_index]; - const game_controller_response_curve response_curve = axis_response_curves[axis_index]; + const gamepad_response_curve response_curve = axis_response_curves[axis_index]; // Build event - game_controller_axis_moved_event event; + gamepad_axis_moved_event event; event.controller = this; event.axis = axis; @@ -172,7 +172,7 @@ void game_controller::handle_axial_motion(game_controller_axis axis) device::event_dispatcher->queue(event); } -void game_controller::handle_biaxial_motion(game_controller_axis axis_x, game_controller_axis axis_y) +void gamepad::handle_biaxial_motion(gamepad_axis axis_x, gamepad_axis axis_y) { // Get axis parameters const int x_axis_index = static_cast(axis_x); @@ -183,9 +183,9 @@ void game_controller::handle_biaxial_motion(game_controller_axis axis_x, game_co const float y_activation_max = axis_activation_max[y_axis_index]; const float x_axis_value = axis_values[x_axis_index]; const float y_axis_value = axis_values[y_axis_index]; - const game_controller_response_curve x_response_curve = axis_response_curves[x_axis_index]; - const game_controller_response_curve y_response_curve = axis_response_curves[y_axis_index]; - const float deadzone_roundness = (axis_x == game_controller_axis::left_x) ? left_deadzone_roundness : right_deadzone_roundness; + const gamepad_response_curve x_response_curve = axis_response_curves[x_axis_index]; + const gamepad_response_curve y_response_curve = axis_response_curves[y_axis_index]; + const float deadzone_roundness = (axis_x == gamepad_axis::left_x) ? left_deadzone_roundness : right_deadzone_roundness; const float radius = std::min(x_activation_min, y_activation_min) * deadzone_roundness; const float dx = std::max(0.0f, std::abs(x_axis_value) - x_activation_min + radius); @@ -193,7 +193,7 @@ void game_controller::handle_biaxial_motion(game_controller_axis axis_x, game_co const float distance = std::sqrt(dx * dx + dy * dy) - radius; // Build event - game_controller_axis_moved_event event; + gamepad_axis_moved_event event; event.controller = this; if (distance > 0.0f) @@ -230,20 +230,20 @@ void game_controller::handle_biaxial_motion(game_controller_axis axis_x, game_co } } -float game_controller::curve_response(game_controller_axis axis, float response) const +float gamepad::curve_response(gamepad_axis axis, float response) const { - const game_controller_response_curve response_curve = axis_response_curves[static_cast(axis)]; + const gamepad_response_curve response_curve = axis_response_curves[static_cast(axis)]; switch (response_curve) { - case game_controller_response_curve::linear: + case gamepad_response_curve::linear: break; - case game_controller_response_curve::square: + case gamepad_response_curve::square: response = response * response; break; - case game_controller_response_curve::cube: + case gamepad_response_curve::cube: response = response * response * response; break; } @@ -251,22 +251,22 @@ float game_controller::curve_response(game_controller_axis axis, float response) return response; } -void game_controller::connect(bool reconnected) +void gamepad::connect(bool reconnected) { connected = true; - game_controller_connected_event event; + gamepad_connected_event event; event.controller = this; event.reconnected = reconnected; device::event_dispatcher->queue(event); } -void game_controller::disconnect() +void gamepad::disconnect() { connected = false; - game_controller_disconnected_event event; + gamepad_disconnected_event event; event.controller = this; device::event_dispatcher->queue(event); diff --git a/src/input/game-controller.hpp b/src/input/gamepad.hpp similarity index 69% rename from src/input/game-controller.hpp rename to src/input/gamepad.hpp index 98a09be..f90dd4a 100644 --- a/src/input/game-controller.hpp +++ b/src/input/gamepad.hpp @@ -17,15 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_INPUT_GAME_CONTROLLER_HPP -#define ANTKEEPER_INPUT_GAME_CONTROLLER_HPP +#ifndef ANTKEEPER_INPUT_GAMEPAD_HPP +#define ANTKEEPER_INPUT_GAMEPAD_HPP #include "device.hpp" namespace input { -/// Game controller buttons. -enum class game_controller_button +/// Gamepad buttons. +enum class gamepad_button { a, b, @@ -44,8 +44,8 @@ enum class game_controller_button dpad_right }; -/// Game controller axes. -enum class game_controller_axis +/// Gamepad axes. +enum class gamepad_axis { /// Left stick x-axis. left_x, @@ -66,8 +66,8 @@ enum class game_controller_axis right_trigger, }; -/// Game controller axis activation response curves. -enum class game_controller_response_curve +/// Gamepad axis activation response curves. +enum class gamepad_response_curve { /// Linear response curve. linear, @@ -80,37 +80,37 @@ enum class game_controller_response_curve }; /** - * A virtual game controller which can generate game controller-related input events and pass them to an event dispatcher. + * A virtual gamepad which can generate gamepad-related input events and pass them to an event dispatcher. * * @ingroup input */ -class game_controller: public device +class gamepad: public device { public: /** - * Creates a game controller input device. + * Creates a gamepad input device. */ - game_controller(); + gamepad(); - /// Destroys a game controller input device. - virtual ~game_controller() = default; + /// Destroys a gamepad input device. + virtual ~gamepad() = default; /** - * Sets the activation threshold for a game controller axis. + * Sets the activation threshold for a gamepad axis. * - * @param axis Game controller axis. + * @param axis Gamepad axis. * @param min Axis minimum activation threshold. * @param max Axis maximum activation threshold. */ - void set_activation_threshold(game_controller_axis axis, float min, float max); + void set_activation_threshold(gamepad_axis axis, float min, float max); /** * Sets the activation response curve of an axis. * - * @param axis Game controller axis. + * @param axis Gamepad axis. * @param curve Activation response curve. */ - void set_response_curve(game_controller_axis axis, game_controller_response_curve curve); + void set_response_curve(gamepad_axis axis, gamepad_response_curve curve); /** * Sets the type of deadzone shape for the axes on the left stick. @@ -141,51 +141,51 @@ public: void set_right_deadzone_roundness(float roundness); /** - * Simulates a game controller button press. + * Simulates a gamepad button press. * * @param button Index of the pressed button. */ - void press(game_controller_button button); + void press(gamepad_button button); /** - * Simulates a game controller button release. + * Simulates a gamepad button release. * * @param button Index of the released button. */ - void release(game_controller_button button); + void release(gamepad_button button); /** - * Simulates a game controller axis movement. + * Simulates a gamepad axis movement. * * @param axis Index of the moved axis. * @param negative Whether the movement was negative or positive. * @param value Normalized degree of movement. */ - void move(game_controller_axis axis, float value); + void move(gamepad_axis axis, float value); /** - * Simulates a game controller being connected. + * Simulates a gamepad being connected. * * @param reconnected `true` if the controller is being reconnected, or `false` if the controller is being connected for the first time. */ void connect(bool reconnnected); - /// Simulates a game controller being disconnected. + /// Simulates a gamepad being disconnected. void disconnect(); /// Returns `true` if the controller is currently connected. bool is_connected() const; private: - void handle_axial_motion(game_controller_axis axis); - void handle_biaxial_motion(game_controller_axis axis_x, game_controller_axis axis_y); - float curve_response(game_controller_axis axis, float response) const; + void handle_axial_motion(gamepad_axis axis); + void handle_biaxial_motion(gamepad_axis axis_x, gamepad_axis axis_y); + float curve_response(gamepad_axis axis, float response) const; bool connected; float axis_values[6]; float axis_activation_min[6]; float axis_activation_max[6]; - game_controller_response_curve axis_response_curves[6]; + gamepad_response_curve axis_response_curves[6]; bool left_deadzone_cross; bool right_deadzone_cross; @@ -193,12 +193,11 @@ private: float right_deadzone_roundness; }; -inline bool game_controller::is_connected() const +inline bool gamepad::is_connected() const { return connected; } } // namespace input -#endif // ANTKEEPER_INPUT_GAME_CONTROLLER_HPP - +#endif // ANTKEEPER_INPUT_GAMEPAD_HPP diff --git a/src/input/input.hpp b/src/input/input.hpp index 0680505..f9755d9 100644 --- a/src/input/input.hpp +++ b/src/input/input.hpp @@ -27,7 +27,7 @@ namespace input {} #include "control-set.hpp" #include "device.hpp" #include "event-router.hpp" -#include "game-controller.hpp" +#include "gamepad.hpp" #include "keyboard.hpp" #include "listener.hpp" #include "mapper.hpp" diff --git a/src/input/listener.cpp b/src/input/listener.cpp index 5707e21..1cb9a74 100644 --- a/src/input/listener.cpp +++ b/src/input/listener.cpp @@ -41,8 +41,8 @@ void listener::set_event_dispatcher(::event_dispatcher* event_dispatcher) this->event_dispatcher->unsubscribe(this); this->event_dispatcher->unsubscribe(this); this->event_dispatcher->unsubscribe(this); - this->event_dispatcher->unsubscribe(this); - this->event_dispatcher->unsubscribe(this); + this->event_dispatcher->unsubscribe(this); + this->event_dispatcher->unsubscribe(this); } this->event_dispatcher = event_dispatcher; @@ -53,8 +53,8 @@ void listener::set_event_dispatcher(::event_dispatcher* event_dispatcher) event_dispatcher->subscribe(this); event_dispatcher->subscribe(this); event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); } } @@ -108,7 +108,7 @@ void listener::handle_event(const mouse_wheel_scrolled_event& event) callback(event); } -void listener::handle_event(const game_controller_button_pressed_event& event) +void listener::handle_event(const gamepad_button_pressed_event& event) { if (!is_enabled() || !callback) { @@ -118,7 +118,7 @@ void listener::handle_event(const game_controller_button_pressed_event& event) callback(event); } -void listener::handle_event(const game_controller_axis_moved_event& event) +void listener::handle_event(const gamepad_axis_moved_event& event) { if (!is_enabled() || !callback) { diff --git a/src/input/listener.hpp b/src/input/listener.hpp index b06ed20..a6418ec 100644 --- a/src/input/listener.hpp +++ b/src/input/listener.hpp @@ -35,8 +35,8 @@ class listener: public event_handler, public event_handler, public event_handler, - public event_handler, - public event_handler + public event_handler, + public event_handler { public: /** @@ -78,8 +78,8 @@ private: void handle_event(const mouse_moved_event& event); void handle_event(const mouse_wheel_scrolled_event& event); void handle_event(const mouse_button_pressed_event& event); - void handle_event(const game_controller_axis_moved_event& event); - void handle_event(const game_controller_button_pressed_event& event); + void handle_event(const gamepad_axis_moved_event& event); + void handle_event(const gamepad_button_pressed_event& event); event_dispatcher* event_dispatcher; std::function callback; diff --git a/src/input/mapper.cpp b/src/input/mapper.cpp index 5c74a6f..90a1fc5 100644 --- a/src/input/mapper.cpp +++ b/src/input/mapper.cpp @@ -43,8 +43,8 @@ void mapper::set_event_dispatcher(::event_dispatcher* event_dispatcher) this->event_dispatcher->unsubscribe(this); this->event_dispatcher->unsubscribe(this); this->event_dispatcher->unsubscribe(this); - this->event_dispatcher->unsubscribe(this); - this->event_dispatcher->unsubscribe(this); + this->event_dispatcher->unsubscribe(this); + this->event_dispatcher->unsubscribe(this); } this->event_dispatcher = event_dispatcher; @@ -55,8 +55,8 @@ void mapper::set_event_dispatcher(::event_dispatcher* event_dispatcher) event_dispatcher->subscribe(this); event_dispatcher->subscribe(this); event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); } } @@ -135,24 +135,24 @@ void mapper::handle_event(const mouse_wheel_scrolled_event& event) } } -void mapper::handle_event(const game_controller_button_pressed_event& event) +void mapper::handle_event(const gamepad_button_pressed_event& event) { if (!is_enabled() || !callback) { return; } - callback(game_controller_button_mapping(control, event.controller, event.button)); + callback(gamepad_button_mapping(control, event.controller, event.button)); } -void mapper::handle_event(const game_controller_axis_moved_event& event) +void mapper::handle_event(const gamepad_axis_moved_event& event) { if (!is_enabled() || !callback) { return; } - callback(game_controller_axis_mapping(control, event.controller, event.axis, (event.value < 0.0f))); + callback(gamepad_axis_mapping(control, event.controller, event.axis, (event.value < 0.0f))); } } // namespace input diff --git a/src/input/mapper.hpp b/src/input/mapper.hpp index e78dfd3..216d28e 100644 --- a/src/input/mapper.hpp +++ b/src/input/mapper.hpp @@ -36,8 +36,8 @@ class mapper: public event_handler, public event_handler, public event_handler, - public event_handler, - public event_handler + public event_handler, + public event_handler { public: /** @@ -86,8 +86,8 @@ private: void handle_event(const mouse_moved_event& event); void handle_event(const mouse_wheel_scrolled_event& event); void handle_event(const mouse_button_pressed_event& event); - void handle_event(const game_controller_axis_moved_event& event); - void handle_event(const game_controller_button_pressed_event& event); + void handle_event(const gamepad_axis_moved_event& event); + void handle_event(const gamepad_button_pressed_event& event); event_dispatcher* event_dispatcher; control* control; diff --git a/src/input/mapping.cpp b/src/input/mapping.cpp index 9bab916..e8e58dc 100644 --- a/src/input/mapping.cpp +++ b/src/input/mapping.cpp @@ -101,19 +101,19 @@ mouse_button_mapping& mouse_button_mapping::operator=(const mouse_button_mapping return *this; } -game_controller_axis_mapping::game_controller_axis_mapping(const game_controller_axis_mapping& mapping) +gamepad_axis_mapping::gamepad_axis_mapping(const gamepad_axis_mapping& mapping) { *this = mapping; } -game_controller_axis_mapping::game_controller_axis_mapping(input::control* control, game_controller* controller, game_controller_axis axis, bool negative): +gamepad_axis_mapping::gamepad_axis_mapping(input::control* control, gamepad* controller, gamepad_axis axis, bool negative): mapping(control), controller(controller), axis(axis), negative(negative) {} -game_controller_axis_mapping& game_controller_axis_mapping::operator=(const game_controller_axis_mapping& mapping) +gamepad_axis_mapping& gamepad_axis_mapping::operator=(const gamepad_axis_mapping& mapping) { control = mapping.control; controller = mapping.controller; @@ -122,18 +122,18 @@ game_controller_axis_mapping& game_controller_axis_mapping::operator=(const game return *this; } -game_controller_button_mapping::game_controller_button_mapping(const game_controller_button_mapping& mapping) +gamepad_button_mapping::gamepad_button_mapping(const gamepad_button_mapping& mapping) { *this = mapping; } -game_controller_button_mapping::game_controller_button_mapping(input::control* control, game_controller* controller, game_controller_button button): +gamepad_button_mapping::gamepad_button_mapping(input::control* control, gamepad* controller, gamepad_button button): mapping(control), controller(controller), button(button) {} -game_controller_button_mapping& game_controller_button_mapping::operator=(const game_controller_button_mapping& mapping) +gamepad_button_mapping& gamepad_button_mapping::operator=(const gamepad_button_mapping& mapping) { control = mapping.control; controller = mapping.controller; diff --git a/src/input/mapping.hpp b/src/input/mapping.hpp index 2457f26..425ffde 100644 --- a/src/input/mapping.hpp +++ b/src/input/mapping.hpp @@ -25,12 +25,12 @@ namespace input { enum class mouse_motion_axis; enum class mouse_wheel_axis; enum class scancode; -enum class game_controller_axis; -enum class game_controller_button; +enum class gamepad_axis; +enum class gamepad_button; class control; class keyboard; class mouse; -class game_controller; +class gamepad; /** * Enumerates the supported types of control mappings. @@ -41,8 +41,8 @@ enum class mapping_type mouse_motion, mouse_wheel, mouse_button, - game_controller_axis, - game_controller_button + gamepad_axis, + gamepad_button }; /** @@ -150,50 +150,50 @@ inline mapping_type mouse_button_mapping::get_type() const } /** - * A mapping between a control and a game controller axis. + * A mapping between a control and a gamepad axis. */ -class game_controller_axis_mapping: public mapping +class gamepad_axis_mapping: public mapping { public: - game_controller_axis_mapping() = default; - game_controller_axis_mapping(const game_controller_axis_mapping& mapping); - game_controller_axis_mapping(input::control* control, game_controller* controller, game_controller_axis axis, bool negative); - virtual ~game_controller_axis_mapping() = default; - game_controller_axis_mapping& operator=(const game_controller_axis_mapping& mapping); + gamepad_axis_mapping() = default; + gamepad_axis_mapping(const gamepad_axis_mapping& mapping); + gamepad_axis_mapping(input::control* control, gamepad* controller, gamepad_axis axis, bool negative); + virtual ~gamepad_axis_mapping() = default; + gamepad_axis_mapping& operator=(const gamepad_axis_mapping& mapping); virtual mapping_type get_type() const; - game_controller* controller; - game_controller_axis axis; + gamepad* controller; + gamepad_axis axis; bool negative; }; -inline mapping_type game_controller_axis_mapping::get_type() const +inline mapping_type gamepad_axis_mapping::get_type() const { - return mapping_type::game_controller_axis; + return mapping_type::gamepad_axis; } /** - * A mapping between a control and a game controller button. + * A mapping between a control and a gamepad button. * * @ingroup input. */ -class game_controller_button_mapping: public mapping +class gamepad_button_mapping: public mapping { public: - game_controller_button_mapping() = default; - game_controller_button_mapping(const game_controller_button_mapping& mapping); - game_controller_button_mapping(input::control* control, game_controller* controller, game_controller_button button); - virtual ~game_controller_button_mapping() = default; - game_controller_button_mapping& operator=(const game_controller_button_mapping& mapping); + gamepad_button_mapping() = default; + gamepad_button_mapping(const gamepad_button_mapping& mapping); + gamepad_button_mapping(input::control* control, gamepad* controller, gamepad_button button); + virtual ~gamepad_button_mapping() = default; + gamepad_button_mapping& operator=(const gamepad_button_mapping& mapping); virtual mapping_type get_type() const; - game_controller* controller; - game_controller_button button; + gamepad* controller; + gamepad_button button; }; -inline mapping_type game_controller_button_mapping::get_type() const +inline mapping_type gamepad_button_mapping::get_type() const { - return mapping_type::game_controller_button; + return mapping_type::gamepad_button; } } // namespace input diff --git a/src/input/sdl-game-controller-tables.cpp b/src/input/sdl-game-controller-tables.cpp index c318ace..8c84226 100644 --- a/src/input/sdl-game-controller-tables.cpp +++ b/src/input/sdl-game-controller-tables.cpp @@ -18,37 +18,37 @@ */ #include "sdl-game-controller-tables.hpp" -#include "game-controller.hpp" +#include "gamepad.hpp" namespace input { -const game_controller_button sdl_button_table[15] = +const gamepad_button sdl_button_table[15] = { - game_controller_button::a, // SDL_CONTROLLER_BUTTON_A, - game_controller_button::b, // SDL_CONTROLLER_BUTTON_B, - game_controller_button::x, // SDL_CONTROLLER_BUTTON_X, - game_controller_button::y, // SDL_CONTROLLER_BUTTON_Y, - game_controller_button::back, // SDL_CONTROLLER_BUTTON_BACK, - game_controller_button::guide, // SDL_CONTROLLER_BUTTON_GUIDE, - game_controller_button::start, // SDL_CONTROLLER_BUTTON_START, - game_controller_button::left_stick, // SDL_CONTROLLER_BUTTON_LEFTSTICK, - game_controller_button::right_stick, // SDL_CONTROLLER_BUTTON_RIGHTSTICK, - game_controller_button::left_shoulder, // SDL_CONTROLLER_BUTTON_LEFTSHOULDER, - game_controller_button::right_shoulder, // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, - game_controller_button::dpad_up, // SDL_CONTROLLER_BUTTON_DPAD_UP, - game_controller_button::dpad_down, // SDL_CONTROLLER_BUTTON_DPAD_DOWN, - game_controller_button::dpad_left, // SDL_CONTROLLER_BUTTON_DPAD_LEFT, - game_controller_button::dpad_right, // SDL_CONTROLLER_BUTTON_DPAD_RIGHT, + gamepad_button::a, // SDL_CONTROLLER_BUTTON_A, + gamepad_button::b, // SDL_CONTROLLER_BUTTON_B, + gamepad_button::x, // SDL_CONTROLLER_BUTTON_X, + gamepad_button::y, // SDL_CONTROLLER_BUTTON_Y, + gamepad_button::back, // SDL_CONTROLLER_BUTTON_BACK, + gamepad_button::guide, // SDL_CONTROLLER_BUTTON_GUIDE, + gamepad_button::start, // SDL_CONTROLLER_BUTTON_START, + gamepad_button::left_stick, // SDL_CONTROLLER_BUTTON_LEFTSTICK, + gamepad_button::right_stick, // SDL_CONTROLLER_BUTTON_RIGHTSTICK, + gamepad_button::left_shoulder, // SDL_CONTROLLER_BUTTON_LEFTSHOULDER, + gamepad_button::right_shoulder, // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, + gamepad_button::dpad_up, // SDL_CONTROLLER_BUTTON_DPAD_UP, + gamepad_button::dpad_down, // SDL_CONTROLLER_BUTTON_DPAD_DOWN, + gamepad_button::dpad_left, // SDL_CONTROLLER_BUTTON_DPAD_LEFT, + gamepad_button::dpad_right, // SDL_CONTROLLER_BUTTON_DPAD_RIGHT, }; -const game_controller_axis sdl_axis_table[6] = +const gamepad_axis sdl_axis_table[6] = { - game_controller_axis::left_x, // SDL_CONTROLLER_AXIS_LEFTX, - game_controller_axis::left_y, // SDL_CONTROLLER_AXIS_LEFTY, - game_controller_axis::right_x, // SDL_CONTROLLER_AXIS_RIGHTX, - game_controller_axis::right_y, // SDL_CONTROLLER_AXIS_RIGHTY, - game_controller_axis::left_trigger, // SDL_CONTROLLER_AXIS_TRIGGERLEFT, - game_controller_axis::right_trigger, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT, + gamepad_axis::left_x, // SDL_CONTROLLER_AXIS_LEFTX, + gamepad_axis::left_y, // SDL_CONTROLLER_AXIS_LEFTY, + gamepad_axis::right_x, // SDL_CONTROLLER_AXIS_RIGHTX, + gamepad_axis::right_y, // SDL_CONTROLLER_AXIS_RIGHTY, + gamepad_axis::left_trigger, // SDL_CONTROLLER_AXIS_TRIGGERLEFT, + gamepad_axis::right_trigger, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT, }; } // namespace input diff --git a/src/input/sdl-game-controller-tables.hpp b/src/input/sdl-game-controller-tables.hpp index babecfb..77f64e5 100644 --- a/src/input/sdl-game-controller-tables.hpp +++ b/src/input/sdl-game-controller-tables.hpp @@ -17,18 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_INPUT_SDL_GAME_CONTROLLER_TABLES_HPP -#define ANTKEEPER_INPUT_SDL_GAME_CONTROLLER_TABLES_HPP +#ifndef ANTKEEPER_INPUT_SDL_GAMEPAD_TABLES_HPP +#define ANTKEEPER_INPUT_SDL_GAMEPAD_TABLES_HPP namespace input { -enum class game_controller_button; -enum class game_controller_axis; +enum class gamepad_button; +enum class gamepad_axis; -extern const game_controller_button sdl_button_table[15]; -extern const game_controller_axis sdl_axis_table[6]; +extern const gamepad_button sdl_button_table[15]; +extern const gamepad_axis sdl_axis_table[6]; } // namespace input -#endif // ANTKEEPER_INPUT_SDL_GAME_CONTROLLER_TABLES_HPP +#endif // ANTKEEPER_INPUT_SDL_GAMEPAD_TABLES_HPP