foxygit / doom Log in
commit dc120bcc11cf046d95cb6432c5b039f76c104f34
Author:     Jonathan Dowland <jon+github@alcopop.org>
AuthorDate: Mon Aug 15 17:20:43 2016 +0100
Commit:     Jonathan Dowland <jon+github@alcopop.org>
CommitDate: Mon Aug 15 17:20:01 2016 +0100

    Add joystick virtual button for toggle automap

    Add a distinct logic branch to the top of the AM_Responder
    routines that exits out, rather than modify the rc variable/
    branching logic in the rest of the routine. Use the same
    button bounce timeout approach used for m_menu.

    Additionally adjust the column widths for the setup screen for
    joystick configuration, to account for the width of the string
    "Toggle Automap".
---
 src/doom/am_map.c         | 22 ++++++++++++++++++++++
 src/heretic/am_map.c      | 20 ++++++++++++++++++++
 src/hexen/am_map.c        | 25 +++++++++++++++++++++++++
 src/m_config.c            |  6 ++++++
 src/m_controls.c          |  2 ++
 src/m_controls.h          |  1 +
 src/setup/joystick.c      |  5 ++++-
 src/setup/txt_joybinput.c |  1 +
 src/strife/am_map.c       | 23 +++++++++++++++++++++++
 9 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/src/doom/am_map.c b/src/doom/am_map.c
index 8d3c49ee..2e4e9e35 100644
--- a/src/doom/am_map.c
+++ b/src/doom/am_map.c
@@ -32,6 +32,7 @@
 #include "m_controls.h"
 #include "m_misc.h"
 #include "i_system.h"
+#include "i_timer.h"

 // Needs access to LFB.
 #include "v_video.h"
@@ -598,11 +599,32 @@ AM_Responder

     int rc;
     static int bigstate=0;
+    static int joywait = 0;
     static char buffer[20];
     int key;

     rc = false;

+    if (ev->type == ev_joystick && joybautomap >= 0
+        && (ev->data1 & (1 << joybautomap)) != 0 && joywait < I_GetTime())
+    {
+        joywait = I_GetTime() + 5;
+
+        if (!automapactive)
+        {
+            AM_Start ();
+            viewactive = false;
+        }
+        else
+        {
+            bigstate = 0;
+            viewactive = true;
+            AM_Stop ();
+        }
+
+        return true;
+    }
+
     if (!automapactive)
     {
 	if (ev->type == ev_keydown && ev->data1 == key_map_toggle)
diff --git a/src/heretic/am_map.c b/src/heretic/am_map.c
index d80ae5b9..5010b728 100644
--- a/src/heretic/am_map.c
+++ b/src/heretic/am_map.c
@@ -20,6 +20,7 @@

 #include "doomdef.h"
 #include "deh_str.h"
+#include "i_timer.h"
 #include "i_video.h"
 #include "m_controls.h"
 #include "p_local.h"
@@ -508,10 +509,29 @@ boolean AM_Responder(event_t * ev)
     int rc;
     int key;
     static int bigstate = 0;
+    static int joywait = 0;

     key = ev->data1;
     rc = false;

+    if (ev->type == ev_joystick && joybautomap >= 0
+        && (ev->data1 & (1 << joybautomap)) != 0 && joywait < I_GetTime())
+    {
+        joywait = I_GetTime() + 5;
+
+        if (!automapactive)
+        {
+            AM_Start ();
+            viewactive = false;
+        }
+        else
+        {
+            bigstate = 0;
+            viewactive = true;
+            AM_Stop ();
+        }
+    }
+
     if (!automapactive)
     {

diff --git a/src/hexen/am_map.c b/src/hexen/am_map.c
index 6a28b45c..1bd9a75a 100644
--- a/src/hexen/am_map.c
+++ b/src/hexen/am_map.c
@@ -20,6 +20,7 @@
 #include "doomkeys.h"
 #include "i_video.h"
 #include "i_swap.h"
+#include "i_timer.h"
 #include "m_controls.h"
 #include "m_misc.h"
 #include "p_local.h"
@@ -421,9 +422,33 @@ boolean AM_Responder(event_t * ev)
     int rc;
     int key;
     static int bigstate = 0;
+    static int joywait = 0;

     key = ev->data1;

+    if (ev->type == ev_joystick && joybautomap >= 0
+        && (ev->data1 & (1 << joybautomap)) != 0 && joywait < I_GetTime())
+    {
+        joywait = I_GetTime() + 5;
+
+        if (!automapactive)
+        {
+            AM_Start ();
+            SB_state = -1;
+            viewactive = false;
+        }
+        else
+        {
+            bigstate = 0;
+            viewactive = true;
+            AM_Stop ();
+            SB_state = -1;
+        }
+
+        return true;
+    }
+
+
     rc = false;
     if (!automapactive)
     {
diff --git a/src/m_config.c b/src/m_config.c
index 61f90a53..c74832db 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1050,6 +1050,12 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_INT(joyb_menu_activate),

+    //!
+    // Joystick virtual button to toggle the automap.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_toggle_automap),
+
     //!
     // Joystick virtual button that cycles to the previous weapon.
     //
diff --git a/src/m_controls.c b/src/m_controls.c
index 35f848c7..7225647c 100644
--- a/src/m_controls.c
+++ b/src/m_controls.c
@@ -192,6 +192,7 @@ int joybprevweapon = -1;
 int joybnextweapon = -1;

 int joybmenu = -1;
+int joybautomap = -1;

 // Control whether if a mouse button is double clicked, it acts like
 // "use" has been pressed
@@ -225,6 +226,7 @@ void M_BindBaseControls(void)
     M_BindIntVariable("joyb_speed",         &joybspeed);

     M_BindIntVariable("joyb_menu_activate", &joybmenu);
+    M_BindIntVariable("joyb_toggle_automap", &joybautomap);

     // Extra controls that are not in the Vanilla versions:

diff --git a/src/m_controls.h b/src/m_controls.h
index aa07a7e3..5d12f96e 100644
--- a/src/m_controls.h
+++ b/src/m_controls.h
@@ -150,6 +150,7 @@ extern int joybprevweapon;
 extern int joybnextweapon;

 extern int joybmenu;
+extern int joybautomap;

 extern int dclick_use;

diff --git a/src/setup/joystick.c b/src/setup/joystick.c
index 53ea5a29..cf3baa17 100644
--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -141,6 +141,7 @@ static const joystick_config_t empty_defaults[] =
     {"joyb_nextweapon",            -1},
     {"joyb_jump",                  -1},
     {"joyb_menu_activate",         -1},
+    {"joyb_toggle_automap",        -1},
     {"joystick_physical_button0",  0},
     {"joystick_physical_button1",  1},
     {"joystick_physical_button2",  2},
@@ -822,7 +823,7 @@ void ConfigJoystick(void)

     window = TXT_NewWindow("Gamepad/Joystick configuration");
     TXT_SetTableColumns(window, 6);
-    TXT_SetColumnWidths(window, 18, 10, 2, 14, 10, 0);
+    TXT_SetColumnWidths(window, 18, 10, 1, 15, 10, 0);
     TXT_SetWindowHelpURL(window, WINDOW_HELP_URL);

     TXT_AddWidgets(window,
@@ -889,6 +890,8 @@ void ConfigJoystick(void)

     AddJoystickControl(window, "Activate menu", &joybmenu);

+    AddJoystickControl(window, "Toggle Automap", &joybautomap);
+
     TXT_SignalConnect(joystick_button, "pressed", CalibrateJoystick, NULL);
     TXT_SetWindowAction(window, TXT_HORIZ_CENTER, TestConfigAction());

diff --git a/src/setup/txt_joybinput.c b/src/setup/txt_joybinput.c
index 04ebd6fd..b8dbb121 100644
--- a/src/setup/txt_joybinput.c
+++ b/src/setup/txt_joybinput.c
@@ -56,6 +56,7 @@ static int *all_joystick_buttons[] =
     &joybnextweapon,
     &joybjump,
     &joybmenu,
+    &joybautomap,
 };

 static int PhysicalForVirtualButton(int vbutton)
diff --git a/src/strife/am_map.c b/src/strife/am_map.c
index b5b4b8fa..22913c39 100644
--- a/src/strife/am_map.c
+++ b/src/strife/am_map.c
@@ -32,6 +32,7 @@
 #include "m_cheat.h"
 #include "m_controls.h"
 #include "i_system.h"
+#include "i_timer.h"

 // Needs access to LFB.
 #include "v_video.h"
@@ -579,11 +580,33 @@ AM_Responder

     int rc;
     static int bigstate=0;
+    static int joywait = 0;
     static char buffer[20];
     int key;

     rc = false;

+    if (ev->type == ev_joystick && joybautomap >= 0
+        && (ev->data1 & (1 << joybautomap)) != 0 && joywait < I_GetTime())
+    {
+        joywait = I_GetTime() + 5;
+
+        if (!automapactive)
+        {
+            AM_Start ();
+            viewactive = false;
+        }
+        else
+        {
+            bigstate = 0;
+            viewactive = true;
+            AM_Stop ();
+        }
+
+        return true;
+    }
+
+
     if (!automapactive)
     {
 	if (ev->type == ev_keydown && ev->data1 == key_map_toggle)