devilutionX/Source/controls
Andrew James ff145b422d
Refactor plrctrls functions to use Point and Direction types (#2155)
* Refactor GetRotaryDistance to use Point instead of int x/y params

* Refactor HSExists to use Point instead of int x/y params

* Refactor IsPathBlocked to take typed params (Point, Direction)

The caller was already passing in a Direction value so this matches usage better. I also pulled the Direction to Point helper function up so it is available as a static class member, this allows replacing the use of the Offset array in plrctrls.cpp.

When adding a Direction to a point (and not scaling it first) I avoid explicitly creating a Point object since the operator+ overload will do that conversion implicitly.

* Replace Offsets array with Point::fromDirection

* Refactor GetDistanceRanged to use Point

I've added ExactDistance as a member function of Point to match ApproxDistance instead of only having it defined in GetDistanceRanged, it seemed more appropriate to be part of the class. Also removed temporary variables from callers of GetDistanceRanged as they were mainly used as a convenience for avoiding repetition when passing values into this function.

* Refactor GetDistance to use Point
2021-06-26 17:56:06 +02:00
..
devices Fix fmt issue with a nullptr controller mapping 2021-05-02 13:14:59 +02:00
axis_direction.cpp 🎨 Run readability-identifier-naming on all src sub-folders 2021-04-22 03:53:35 +02:00
axis_direction.h Modernize deprecated headers 2021-04-25 02:50:31 +02:00
controller.cpp 🎨 llvm-include-order 2021-04-19 20:11:20 +02:00
controller.h 🚚 Restructure files 2021-04-16 03:57:22 +02:00
controller_buttons.h Modernize deprecated headers 2021-04-25 02:50:31 +02:00
controller_motion.cpp 🎨 Run readability-identifier-naming on all src sub-folders 2021-04-22 03:53:35 +02:00
controller_motion.h Fix SDL1 Builds 2021-04-22 15:07:31 +02:00
game_controls.cpp Close Cathedral Map when B button is pressed on the controller. 2021-05-18 12:49:30 +02:00
game_controls.h Modernize deprecated headers 2021-04-25 02:50:31 +02:00
keymapper.cpp Keymapper: fix actions being triggered while the chatbox is open 2021-05-30 21:45:34 +02:00
keymapper.hpp Keymapper: add enabled condition, fix being able 2021-05-30 21:45:34 +02:00
menu_controls.cpp 🎨 Correct type checks in src sub-folder 2021-04-22 20:33:24 +02:00
menu_controls.h Modernize deprecated headers 2021-04-25 02:50:31 +02:00
modifier_hints.cpp Refactor Draw* functions to use Rectangle and Point types 2021-06-24 01:36:06 +02:00
modifier_hints.h 🧹 performance-unnecessary-value-param 2021-04-22 00:08:19 +02:00
plrctrls.cpp Refactor plrctrls functions to use Point and Direction types (#2155) 2021-06-26 17:56:06 +02:00
plrctrls.h ♻️ Replace 'coord' struct with 'Point' 2021-05-31 06:05:13 +02:00
README.md 🎨 Format code 2021-04-19 00:37:33 +02:00
remap_keyboard.h 🚚 Restructure files 2021-04-16 03:57:22 +02:00
touch.cpp 🖌️ Refurbish tables in source code (clang-format off) 2021-04-25 23:48:25 +02:00
touch.h 🚚 Restructure files 2021-04-16 03:57:22 +02:00

#Controls handling

DevilutionX supports mouse & keyboard and gamepad input.

This directory currently mostly handles gamepad input.

Low-level gamepad handling is abstracted and 3 implementations are provided:

  1. SDL2 controller API.

  2. SDL 1&2 joystick API.

    This can be used in SDL1 joystick platforms and for mapping additional buttons not defined by SDL2 controller mappings (e.g. additional Nintendo Switch arrows).

  3. Keyboard keys acting as controller buttons.

    This can be used for testing, or on devices where this is the only or the easiest API to use (e.g. RetroFW).

Example keyboard-as-controller build flags:

cmake .. -DUSE_SDL1=ON -DHAS_KBCTRL=1 -DPREFILL_PLAYER_NAME=ON \
-DKBCTRL_BUTTON_DPAD_LEFT=SDLK_LEFT \
-DKBCTRL_BUTTON_DPAD_RIGHT=SDLK_RIGHT \
-DKBCTRL_BUTTON_DPAD_UP=SDLK_UP \
-DKBCTRL_BUTTON_DPAD_DOWN=SDLK_DOWN \
-DKBCTRL_BUTTON_X=SDLK_y \
-DKBCTRL_BUTTON_Y=SDLK_x \
-DKBCTRL_BUTTON_B=SDLK_a \
-DKBCTRL_BUTTON_A=SDLK_b \
-DKBCTRL_BUTTON_RIGHTSHOULDER=SDLK_RIGHTBRACKET \
-DKBCTRL_BUTTON_LEFTSHOULDER=SDLK_LEFTBRACKET \
-DKBCTRL_BUTTON_LEFTSTICK=SDLK_TAB \
-DKBCTRL_BUTTON_START=SDLK_RETURN \
-DKBCTRL_BUTTON_BACK=SDLK_LSHIFT