foxygit / doom Log in
commit f6956e28323356252784580e103062e4dfccc2c8
Author:     Michael Day <contact@michaelcday.com>
AuthorDate: Tue Feb 6 09:50:26 2024 -0500
Commit:     Michael Day <contact@michaelcday.com>
CommitDate: Thu Feb 8 09:21:53 2024 -0500

    raven: Add flying joystick binds
---
 src/heretic/g_game.c      |  6 +++---
 src/hexen/g_game.c        |  6 +++---
 src/i_joystick.c          |  2 +-
 src/i_joystick.h          |  2 +-
 src/m_config.c            | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/m_controls.c          |  8 ++++++++
 src/m_controls.h          |  4 ++++
 src/setup/joystick.c      | 14 +++++++++++++-
 src/setup/txt_joybinput.c |  3 +++
 9 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c
index b77bf65d..030ed2ff 100644
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -475,15 +475,15 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic)
     // haleyjd: removed externdriver crap

     // Fly up/down/drop keys
-    if (gamekeydown[key_flyup])
+    if (gamekeydown[key_flyup] || joybuttons[joybflyup])
     {
         flyheight = 5;          // note that the actual flyheight will be twice this
     }
-    if (gamekeydown[key_flydown])
+    if (gamekeydown[key_flydown] || joybuttons[joybflydown])
     {
         flyheight = -5;
     }
-    if (gamekeydown[key_flycenter])
+    if (gamekeydown[key_flycenter] || joybuttons[joybflycenter])
     {
         flyheight = TOCENTER;
         // haleyjd: removed externdriver crap
diff --git a/src/hexen/g_game.c b/src/hexen/g_game.c
index ba007f78..ecfb3832 100644
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -407,15 +407,15 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic)
     // haleyjd: removed externdriver crap

     // Fly up/down/drop keys
-    if (gamekeydown[key_flyup])
+    if (gamekeydown[key_flyup] || joybuttons[joybflyup])
     {
         flyheight = 5;          // note that the actual flyheight will be twice this
     }
-    if (gamekeydown[key_flydown])
+    if (gamekeydown[key_flydown] || joybuttons[joybflydown])
     {
         flyheight = -5;
     }
-    if (gamekeydown[key_flycenter])
+    if (gamekeydown[key_flycenter] || joybuttons[joybflycenter])
     {
         flyheight = TOCENTER;
         // haleyjd: removed externdriver crap
diff --git a/src/i_joystick.c b/src/i_joystick.c
index 330a4b81..9e28a100 100644
--- a/src/i_joystick.c
+++ b/src/i_joystick.c
@@ -90,7 +90,7 @@ int joystick_look_sensitivity = 10;
 // Virtual to physical button joystick button mapping. By default this
 // is a straight mapping.
 static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
-    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
 };

 void I_ShutdownGamepad(void)
diff --git a/src/i_joystick.h b/src/i_joystick.h
index 6f73c8d7..15c8daa3 100644
--- a/src/i_joystick.h
+++ b/src/i_joystick.h
@@ -24,7 +24,7 @@
 // Number of "virtual" joystick buttons defined in configuration files.
 // This needs to be at least as large as the number of different key
 // bindings supported by the higher-level game code (joyb* variables).
-#define NUM_VIRTUAL_BUTTONS 14
+#define NUM_VIRTUAL_BUTTONS 17

 // Max allowed number of virtual mappings. Chosen to be less than joybspeed
 // autorun value.
diff --git a/src/m_config.c b/src/m_config.c
index a45c38c6..141f896b 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1421,6 +1421,27 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_INT(joystick_physical_button13),

+    //!
+    // The physical joystick button that corresponds to joystick
+    // virtual button #14.
+    //
+
+    CONFIG_VARIABLE_INT(joystick_physical_button14),
+
+    //!
+    // The physical joystick button that corresponds to joystick
+    // virtual button #15.
+    //
+
+    CONFIG_VARIABLE_INT(joystick_physical_button15),
+
+    //!
+    // The physical joystick button that corresponds to joystick
+    // virtual button #16.
+    //
+
+    CONFIG_VARIABLE_INT(joystick_physical_button16),
+
     //!
     // If non-zero, use the SDL_GameController interface instead of the
     // SDL_Joystick interface.
@@ -1519,6 +1540,27 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_INT(joyb_invright),

+    //!
+    // @game heretic hexen
+    // Joystick virtual button to fly up.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_flyup),
+
+    //!
+    // @game heretic hexen
+    // Joystick virtual button to fly down.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_flydown),
+
+    //!
+    // @game heretic hexen
+    // Joystick virtual button to center flying.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_flycenter),
+
     //!
     // Key to pause or unpause the game.
     //
diff --git a/src/m_controls.c b/src/m_controls.c
index 752ca043..e6c58129 100644
--- a/src/m_controls.c
+++ b/src/m_controls.c
@@ -214,6 +214,10 @@ int joybuseartifact = -1;
 int joybinvleft = -1;
 int joybinvright = -1;

+int joybflyup = -1;
+int joybflydown = -1;
+int joybflycenter = -1;
+
 // Control whether if a mouse button is double clicked, it acts like
 // "use" has been pressed

@@ -286,6 +290,10 @@ void M_BindHereticControls(void)
     M_BindIntVariable("joyb_invright", &joybinvright);
     M_BindIntVariable("joyb_useartifact", &joybuseartifact);

+    M_BindIntVariable("joyb_flyup", &joybflyup);
+    M_BindIntVariable("joyb_flydown", &joybflydown);
+    M_BindIntVariable("joyb_flycenter", &joybflycenter);
+
     M_BindIntVariable("key_arti_quartz",        &key_arti_quartz);
     M_BindIntVariable("key_arti_urn",           &key_arti_urn);
     M_BindIntVariable("key_arti_bomb",          &key_arti_bomb);
diff --git a/src/m_controls.h b/src/m_controls.h
index 350653e8..7a8a2eaf 100644
--- a/src/m_controls.h
+++ b/src/m_controls.h
@@ -173,6 +173,10 @@ extern int joybuseartifact;
 extern int joybinvleft;
 extern int joybinvright;

+extern int joybflyup;
+extern int joybflydown;
+extern int joybflycenter;
+
 extern int dclick_use;

 void M_BindBaseControls(void);
diff --git a/src/setup/joystick.c b/src/setup/joystick.c
index 833eeaa4..4c48f983 100644
--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -100,7 +100,7 @@ int joystick_look_sensitivity = 10;

 // Virtual to physical mapping.
 int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
-    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
 };

 static txt_button_t *joystick_button;
@@ -167,6 +167,9 @@ static const joystick_config_t empty_defaults[] =
     {"joyb_useartifact",           -1},
     {"joyb_invleft",               -1},
     {"joyb_invright",              -1},
+    {"joyb_flyup",                 -1},
+    {"joyb_flydown",               -1},
+    {"joyb_flycenter",             -1},
     {"joystick_physical_button0",  0},
     {"joystick_physical_button1",  1},
     {"joystick_physical_button2",  2},
@@ -181,6 +184,9 @@ static const joystick_config_t empty_defaults[] =
     {"joystick_physical_button11",  11},
     {"joystick_physical_button12",  12},
     {"joystick_physical_button13",  13},
+    {"joystick_physical_button14",  14},
+    {"joystick_physical_button15",  15},
+    {"joystick_physical_button16",  16},
     {NULL, 0},
 };

@@ -640,6 +646,9 @@ static const joystick_config_t modern_gamepad[] =
     {"joyb_useartifact", SDL_CONTROLLER_BUTTON_X},
     {"joyb_invleft", SDL_CONTROLLER_BUTTON_DPAD_LEFT},
     {"joyb_invright", SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
+    {"joyb_flyup", SDL_CONTROLLER_BUTTON_DPAD_UP},
+    {"joyb_flydown", SDL_CONTROLLER_BUTTON_DPAD_DOWN},
+    {"joyb_flycenter", SDL_CONTROLLER_BUTTON_LEFTSTICK},
     {NULL, 0},
 };

@@ -1284,6 +1293,9 @@ void ConfigJoystick(TXT_UNCAST_ARG(widget), void *user_data)
         AddJoystickControl(window, "Use artifact", &joybuseartifact);
         AddJoystickControl(window, "Inventory left", &joybinvleft);
         AddJoystickControl(window, "Inventory right", &joybinvright);
+        AddJoystickControl(window, "Fly up", &joybflyup);
+        AddJoystickControl(window, "Fly down", &joybflydown);
+        AddJoystickControl(window, "Fly center", &joybflycenter);
     }

     TXT_SignalConnect(joystick_button, "pressed", CalibrateJoystick, window);
diff --git a/src/setup/txt_joybinput.c b/src/setup/txt_joybinput.c
index 067f63d8..a4362e34 100644
--- a/src/setup/txt_joybinput.c
+++ b/src/setup/txt_joybinput.c
@@ -61,6 +61,9 @@ static int *all_joystick_buttons[NUM_VIRTUAL_BUTTONS] =
     &joybuseartifact,
     &joybinvleft,
     &joybinvright,
+    &joybflyup,
+    &joybflydown,
+    &joybflycenter,
 };

 // For indirection so that we're not dependent on item ordering in the