From aacebe1d40da3b60a047e09c128e163f09441dd9 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Thu, 16 Jan 2020 21:15:45 +0100 Subject: [PATCH] Joystick2 add joystick buttons for automap and main men (#40) * add joystick buttons for automap and main menu Fixes #27 * joystick button triggers either escape or menu_escape * get away with only one GetButtons() function * rename MAX_JB to MAX_JSB Joystick buttons are called JSB in the key binding menu, so we stay consistent with this. * print PREV and NEXT on separate lines in the weapon key binbing screen Thanks @JNechaevsky for noticing, fixes #37. --- Source/am_map.c | 14 ++++++ Source/doomtype.h | 4 ++ Source/g_game.c | 9 +++- Source/i_video.c | 4 +- Source/i_video.h | 4 ++ Source/m_fixed.h | 6 +-- Source/m_menu.c | 109 ++++++++++++++++++++++++---------------------- Source/m_misc.c | 44 +++++++++++++------ Source/m_swap.h | 6 +-- 9 files changed, 121 insertions(+), 79 deletions(-) diff --git a/Source/am_map.c b/Source/am_map.c index 6c90d425..0eeb6e90 100644 --- a/Source/am_map.c +++ b/Source/am_map.c @@ -84,6 +84,8 @@ extern int key_map_follow; extern int key_map_mark; // ^ extern int key_map_clear; // | extern int key_map_grid; // phares +// [FG] automap joystick button +extern int joybautomap; // scale on entry #define INITSCALEMTOF (int)(.2*FRACUNIT) @@ -689,9 +691,21 @@ boolean AM_Responder static int bigstate=0; static char buffer[20]; int ch; // phares + static int joywait = 0; rc = false; + // [FG] automap joystick button + if (ev->type == ev_joystick && joywait < I_GetTime()) + { + if (joybautomap > -1 && (ev->data1 & (1 << joybautomap))) + { + ev->type = ev_keydown; + ev->data1 = key_map; + joywait = I_GetTime() + 5; + } + } + if (!automapactive) { if (ev->type == ev_keydown && ev->data1 == key_map) // phares diff --git a/Source/doomtype.h b/Source/doomtype.h index 6ba2eba9..a91709a2 100644 --- a/Source/doomtype.h +++ b/Source/doomtype.h @@ -75,6 +75,10 @@ typedef int64_t Long64; #define arrlen(array) (sizeof(array) / sizeof(*array)) +#if defined(_MSC_VER) && !defined(__cplusplus) +#define inline __inline +#endif + // The packed attribute forces structures to be packed into the minimum // space necessary. If this is not done, the compiler may align structure // fields differently to optimize memory access, inflating the overall diff --git a/Source/g_game.c b/Source/g_game.c index 04bc5005..0e6ccb10 100644 --- a/Source/g_game.c +++ b/Source/g_game.c @@ -57,6 +57,7 @@ #include "d_deh.h" // Ty 3/27/98 deh declarations #include "p_inter.h" #include "g_game.h" +#include "i_video.h" // [FG] MAX_JSB, MAX_MB #include "statdump.h" // [FG] StatCopy() #define SAVEGAMESIZE 0x20000 @@ -195,6 +196,10 @@ int joybspeed; // [FG] prev/next weapon joystick buttons int joybprevweapon; int joybnextweapon; +// [FG] automap joystick button +int joybautomap; +// [FG] main menu joystick button +int joybmainmenu; #define MAXPLMOVE (forwardmove[1]) #define TURBOTHRESHOLD 0x32 @@ -209,7 +214,7 @@ fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn boolean gamekeydown[NUMKEYS]; int turnheld; // for accelerative turning -boolean mousearray[6]; +boolean mousearray[MAX_MB+1]; // [FG] support more mouse buttons boolean *mousebuttons = &mousearray[1]; // allow [-1] // mouse values are used once @@ -225,7 +230,7 @@ int dclicks2; // joystick values are repeated int joyxmove; int joyymove; -boolean joyarray[9]; +boolean joyarray[MAX_JSB+1]; // [FG] support more joystick buttons boolean *joybuttons = &joyarray[1]; // allow [-1] int savegameslot; diff --git a/Source/i_video.c b/Source/i_video.c index bc2acf40..6aa24cc5 100644 --- a/Source/i_video.c +++ b/Source/i_video.c @@ -80,7 +80,7 @@ static int GetButtonsState(void) result = 0; - for (i = 0; i < 8; ++i) + for (i = 0; i < MAX_JSB; ++i) { if (SDL_JoystickGetButton(sdlJoystick, i)) { @@ -303,7 +303,7 @@ static void UpdateMouseButtonState(unsigned int button, boolean on) { static event_t event; - if (button < SDL_BUTTON_LEFT || button > 5) + if (button < SDL_BUTTON_LEFT || button > MAX_MB) { return; } diff --git a/Source/i_video.h b/Source/i_video.h index 40182534..1ea48ff3 100644 --- a/Source/i_video.h +++ b/Source/i_video.h @@ -32,6 +32,10 @@ #include "doomtype.h" +// [FG] support more joystick and mouse buttons +#define MAX_JSB 12 +#define MAX_MB 5 + // Called by D_DoomMain, // determines the hardware configuration // and sets up the video mode diff --git a/Source/m_fixed.h b/Source/m_fixed.h index 9ae94556..9cfee42c 100644 --- a/Source/m_fixed.h +++ b/Source/m_fixed.h @@ -30,6 +30,7 @@ #define __M_FIXED__ #include // abs() +#include "doomtype.h" #include "i_system.h" // @@ -45,11 +46,6 @@ typedef int fixed_t; // Fixed Point Multiplication // - -#if defined(_MSC_VER) && !defined(__cplusplus) -#define inline __inline -#endif - inline static fixed_t FixedMul(fixed_t a, fixed_t b) { return (fixed_t)((Long64) a*b >> FRACBITS); diff --git a/Source/m_menu.c b/Source/m_menu.c index 328ee7b2..7f422156 100644 --- a/Source/m_menu.c +++ b/Source/m_menu.c @@ -35,8 +35,10 @@ #include "doomdef.h" #include "doomstat.h" +#include "doomtype.h" // [FG] inline #include "dstrings.h" #include "d_main.h" +#include "i_savepng.h" // [FG] SavePNG() #include "i_system.h" #include "i_video.h" #include "v_video.h" @@ -50,7 +52,6 @@ #include "d_deh.h" #include "m_misc.h" #include "m_misc2.h" // [FG] M_StringDuplicate() -#include "i_savepng.h" // [FG] SavePNG() extern patch_t* hu_font[HU_FONTSIZE]; extern boolean message_dontfuckwithme; @@ -170,11 +171,15 @@ extern int joybstrafe; // [FG] strafe left/right joystick buttons extern int joybstrafeleft; extern int joybstraferight; +extern int joybuse; +extern int joybspeed; // [FG] prev/next weapon joystick buttons extern int joybprevweapon; extern int joybnextweapon; -extern int joybuse; -extern int joybspeed; +// [FG] automap joystick button +extern int joybautomap; +// [FG] main menu joystick button +extern int joybmainmenu; extern int health_red; // health amount less than which status is red extern int health_yellow; // health amount less than which status is yellow extern int health_green; // health amount above is blue, below is green @@ -857,6 +862,7 @@ void M_ReadSaveStrings(void) LoadMenu[i].status = 0; continue; } + // [FG] check return value if (!fread(&savegamestrings[i], SAVESTRINGSIZE, 1, fp)) { strcpy(&savegamestrings[i][0],s_EMPTYSTRING); @@ -1909,10 +1915,8 @@ void M_DrawSetting(setup_menu_t* s) else if (key == &key_up || key == &key_speed || key == &key_fire || key == &key_strafe || - // [FG] strafe left/right joystick buttons - key == &key_strafeleft || key == &key_straferight || - // [FG] prev/next weapon keys and buttons - key == &key_prevweapon || key == &key_nextweapon) + // [FG] support more joystick and mouse buttons + s->m_mouse || s->m_joy) { if (s->m_mouse) sprintf(menu_buffer+strlen(menu_buffer), "/MB%d", @@ -2284,11 +2288,7 @@ setup_menu_t keys_settings1[] = // Key Binding screen strings {"RIGHT" ,S_KEY ,m_menu,KB_X,KB_Y+16*8,{&key_menu_right}}, {"BACKSPACE" ,S_KEY ,m_menu,KB_X,KB_Y+17*8,{&key_menu_backspace}}, {"SELECT ITEM" ,S_KEY ,m_menu,KB_X,KB_Y+18*8,{&key_menu_enter}}, - {"EXIT" ,S_KEY ,m_menu,KB_X,KB_Y+19*8,{&key_menu_escape}}, -/* - // [FG] clear key bindings with the DEL key - {"CLEAR" ,S_KEY ,m_menu,KB_X,KB_Y+20*8,{&key_menu_clear}}, -*/ + {"EXIT" ,S_KEY ,m_menu,KB_X,KB_Y+19*8,{&key_menu_escape},0,&joybmainmenu}, // Button for resetting to defaults {0,S_RESET,m_null,X_BUTTON,Y_BUTTON}, @@ -2315,11 +2315,11 @@ setup_menu_t keys_settings2[] = // Key Binding screen strings // key with other keys in the same 'group'. (m_scrn, etc.) {"HELP" ,S_SKIP|S_KEEP ,m_scrn,0 ,0 ,{&key_help}}, - {"MENU" ,S_SKIP|S_KEEP ,m_scrn,0 ,0 ,{&key_escape}}, + {"MENU" ,S_SKIP|S_KEEP ,m_scrn,0 ,0 ,{&key_escape},0,&joybmainmenu}, // killough 10/98: hotkey for entering setup menu: {"SETUP" ,S_KEY ,m_scrn,KB_X,KB_Y+ 1*8,{&key_setup}}, {"PAUSE" ,S_KEY ,m_scrn,KB_X,KB_Y+ 2*8,{&key_pause}}, - {"AUTOMAP" ,S_KEY ,m_scrn,KB_X,KB_Y+ 3*8,{&key_map}}, + {"AUTOMAP" ,S_KEY ,m_scrn,KB_X,KB_Y+ 3*8,{&key_map},0,&joybautomap}, {"VOLUME" ,S_KEY ,m_scrn,KB_X,KB_Y+ 4*8,{&key_soundvolume}}, {"HUD" ,S_KEY ,m_scrn,KB_X,KB_Y+ 5*8,{&key_hud}}, {"MESSAGES" ,S_KEY ,m_scrn,KB_X,KB_Y+ 6*8,{&key_messages}}, @@ -2358,8 +2358,8 @@ setup_menu_t keys_settings3[] = // Key Binding screen strings {"BEST" ,S_KEY ,m_scrn,KB_X,KB_Y+10*8,{&key_weapontoggle}}, {"FIRE" ,S_KEY ,m_scrn,KB_X,KB_Y+11*8,{&key_fire},&mousebfire,&joybfire}, // [FG] prev/next weapon keys and buttons - {"PREV" ,S_KEY ,m_scrn,KB_X,KB_Y+11*8,{&key_prevweapon},&mousebprevweapon,&joybprevweapon}, - {"NEXT" ,S_KEY ,m_scrn,KB_X,KB_Y+12*8,{&key_nextweapon},&mousebnextweapon,&joybnextweapon}, + {"PREV" ,S_KEY ,m_scrn,KB_X,KB_Y+12*8,{&key_prevweapon},&mousebprevweapon,&joybprevweapon}, + {"NEXT" ,S_KEY ,m_scrn,KB_X,KB_Y+13*8,{&key_nextweapon},&mousebnextweapon,&joybnextweapon}, {"<- PREV",S_SKIP|S_PREV,m_null,KB_PREV,KB_Y+20*8, {keys_settings2}}, {"NEXT ->",S_SKIP|S_NEXT,m_null,KB_NEXT,KB_Y+20*8, {keys_settings4}}, @@ -2953,11 +2953,13 @@ enum { general_transpct, general_pcx, general_diskicon, - general_hom -, general_fullscreen + general_hom, + // [FG] fullscreen mode menu toggle + general_fullscreen }; enum { +// [FG] remove sound and music card items /* general_sndcard, general_muscard, @@ -2969,7 +2971,7 @@ enum { #define G_X 250 #define G_Y 44 -#define G_Y2 (G_Y+82+16) +#define G_Y2 (G_Y+82+16) // [FG] remove sound and music card items #define G_Y3 (G_Y+44) #define G_Y4 (G_Y3+52) #define GF_X 76 @@ -2981,11 +2983,8 @@ setup_menu_t gen_settings1[] = { // General Settings screen1 {"High Resolution", S_YESNO, m_null, G_X, G_Y + general_hires*8, {"hires"}, 0, 0, I_ResetScreen}, -#if 0 // SDL2 - {"Use Page-Flipping", S_YESNO, m_null, G_X, G_Y + general_pageflip*8, -#else + // [FG] page_flip = !force_software_renderer {"Use Hardware Acceleration", S_YESNO, m_null, G_X, G_Y + general_pageflip*8, -#endif {"page_flip"}, 0, 0, I_ResetScreen}, {"Wait for Vertical Retrace", S_YESNO, m_null, G_X, @@ -3006,11 +3005,13 @@ setup_menu_t gen_settings1[] = { // General Settings screen1 {"Flashing HOM indicator", S_YESNO, m_null, G_X, G_Y + general_hom*8, {"flashing_hom"}}, + // [FG] fullscreen mode menu toggle {"Fullscreen Mode", S_YESNO, m_null, G_X, G_Y + general_fullscreen*8, {"fullscreen"}, 0, 0, I_ToggleToggleFullScreen}, {"Sound & Music", S_SKIP|S_TITLE, m_null, G_X, G_Y2 - 12}, +// [FG] remove sound and music card items /* {"Sound Card", S_NUM|S_PRGWARN, m_null, G_X, G_Y2 + general_sndcard*8, {"sound_card"}}, @@ -4108,6 +4109,23 @@ void M_DrawCredits(void) // killough 10/98: credit screen M_DrawScreenItems(cred_settings); } +// [FG] support more joystick and mouse buttons + +static inline int GetButtons(const unsigned int max, int data) +{ + int i; + + for (i = 0; i < max; ++i) + { + if (data & (1 << i)) + { + return i; + } + } + + return -1; +} + ///////////////////////////////////////////////////////////////////////////// // // M_Responder @@ -4167,13 +4185,21 @@ boolean M_Responder (event_t* ev) joywait = I_GetTime() + 5; } + // [FG] Menu joystick button + if (joybmainmenu > -1 && (ev->data1 & (1 << joybmainmenu))) + { + ch = menuactive ? key_menu_escape : key_escape; + joywait = I_GetTime() + 5; + } + // phares 4/4/98: // Handle joystick buttons 3 and 4, and allow them to pass down // to where key binding can eat them. if (setup_active && set_keybnd_active) { - if (ev->data1&4 || ev->data1&8 || ev->data1&16 || ev->data1&32 || ev->data1&64 || ev->data1&128) + // [FG] support more joystick and mouse buttons + if (ev->data1 >> 2) { ch = 0; // meaningless, just to get you past the check for -1 joywait = I_GetTime() + 5; @@ -4233,7 +4259,8 @@ boolean M_Responder (event_t* ev) // to where key binding can eat it. if (setup_active && set_keybnd_active) - if (ev->data1&4 || ev->data1&8 || ev->data1&16) + // [FG] support more joystick and mouse buttons + if (ev->data1 >> 2) { ch = 0; // meaningless, just to get you past the check for -1 mousewait = I_GetTime() + 15; @@ -4667,23 +4694,8 @@ boolean M_Responder (event_t* ev) oldbutton = *ptr1->m_joy; group = ptr1->m_group; - if (ev->data1 & 1) - ch = 0; - else if (ev->data1 & 2) - ch = 1; - else if (ev->data1 & 4) - ch = 2; - else if (ev->data1 & 8) - ch = 3; - else if (ev->data1 & 16) - ch = 4; - else if (ev->data1 & 32) - ch = 5; - else if (ev->data1 & 64) - ch = 6; - else if (ev->data1 & 128) - ch = 7; - else + // [FG] support more joystick and mouse buttons + if ((ch = GetButtons(MAX_JSB, ev->data1)) == -1) return true; for (i = 0 ; keys_settings[i] && search ; i++) for (ptr2 = keys_settings[i] ; !(ptr2->m_flags & S_END) ; ptr2++) @@ -4714,17 +4726,8 @@ boolean M_Responder (event_t* ev) oldbutton = *ptr1->m_mouse; group = ptr1->m_group; - if (ev->data1 & 1) - ch = 0; - else if (ev->data1 & 2) - ch = 1; - else if (ev->data1 & 4) - ch = 2; - else if (ev->data1 & 8) - ch = 3; - else if (ev->data1 & 16) - ch = 4; - else + // [FG] support more joystick and mouse buttons + if ((ch = GetButtons(MAX_MB, ev->data1)) == -1) return true; for (i = 0 ; keys_settings[i] && search ; i++) for (ptr2 = keys_settings[i] ; !(ptr2->m_flags & S_END) ; ptr2++) diff --git a/Source/m_misc.c b/Source/m_misc.c index 51de3452..345a47e8 100644 --- a/Source/m_misc.c +++ b/Source/m_misc.c @@ -75,6 +75,10 @@ extern int joybprevweapon; extern int joybnextweapon; extern int joybuse; extern int joybspeed; +// [FG] automap joystick button +extern int joybautomap; +// [FG] main menu joystick button +extern int joybmainmenu; extern int realtic_clock_rate; // killough 4/13/98: adjustable timer extern int tran_filter_pct; // killough 2/21/98 extern int showMessages; @@ -1061,35 +1065,35 @@ default_t defaults[] = { { //jff 3/8/98 allow -1 in mouse bindings to disable mouse function "mouseb_fire", (config_t *) &mousebfire, NULL, - {0}, {-1,4}, number, ss_keys, wad_no, + {0}, {-1,MAX_MB-1}, number, ss_keys, wad_no, "mouse button number to use for fire (-1 = disable)" }, { "mouseb_strafe", (config_t *) &mousebstrafe, NULL, - {1}, {-1,4}, number, ss_keys, wad_no, + {1}, {-1,MAX_MB-1}, number, ss_keys, wad_no, "mouse button number to use for strafing (-1 = disable)" }, { "mouseb_forward", (config_t *) &mousebforward, NULL, - {2}, {-1,4}, number, ss_keys, wad_no, + {2}, {-1,MAX_MB-1}, number, ss_keys, wad_no, "mouse button number to use for forward motion (-1 = disable)" }, //jff 3/8/98 end of lower range change for -1 allowed in mouse binding { // [FG] prev/next weapon keys and buttons "mouseb_prevweapon", (config_t *) &mousebprevweapon, NULL, - {4}, {-1,4}, number, ss_keys, wad_no, + {4}, {-1,MAX_MB-1}, number, ss_keys, wad_no, "mouse button number to cycle to the previous weapon (-1 = disable)" }, { "mouseb_nextweapon", (config_t *) &mousebnextweapon, NULL, - {3}, {-1,4}, number, ss_keys, wad_no, + {3}, {-1,MAX_MB-1}, number, ss_keys, wad_no, "mouse button number to cycle to the mext weapon (-1 = disable)" }, @@ -1103,59 +1107,73 @@ default_t defaults[] = { { "joyb_fire", (config_t *) &joybfire, NULL, - {3}, {-1,7}, number, ss_keys, wad_no, + {3}, {-1,MAX_JSB-1}, number, ss_keys, wad_no, "joystick button number to use for fire" }, { "joyb_strafe", (config_t *) &joybstrafe, NULL, - {-1}, {-1,7}, 0, ss_keys, wad_no, + {-1}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, "joystick button number to use for strafing" }, { "joyb_speed", (config_t *) &joybspeed, NULL, - {1}, {-1,7}, 0, ss_keys, wad_no, + {1}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, "joystick button number to use for running" }, { "joyb_use", (config_t *) &joybuse, NULL, - {0}, {-1,7}, 0, ss_keys, wad_no, + {0}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, "joystick button number to use for use/open" }, { // [FG] strafe left/right joystick buttons "joyb_strafeleft", (config_t *) &joybstrafeleft, NULL, - {4}, {-1,7}, 0, ss_keys, wad_no, + {4}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, "joystick button number to strafe left (sideways left)" }, { "joyb_straferight", (config_t *) &joybstraferight, NULL, - {5}, {-1,7}, 0, ss_keys, wad_no, + {5}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, "joystick button number to strafe right (sideways right)" }, { // [FG] prev/next weapon joystick buttons "joyb_prevweapon", (config_t *) &joybprevweapon, NULL, - {2}, {-1,7}, 0, ss_keys, wad_no, + {2}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, "joystick button number to cycle to the previous weapon" }, { "joyb_nextweapon", (config_t *) &joybnextweapon, NULL, - {-1}, {-1,7}, 0, ss_keys, wad_no, + {-1}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, "joystick button number to cycle to the next weapon" }, + { // [FG] automap joystick button + "joyb_automap", + &joybautomap, NULL, + {-1}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, + "joystick button number to open the automap" + }, + + { // [FG] main menu joystick button + "joyb_mainmenu", + &joybmainmenu, NULL, + {-1}, {-1,MAX_JSB-1}, 0, ss_keys, wad_no, + "joystick button number to open the main menu" + }, + { // killough "snd_channels", (config_t *) &default_numChannels, NULL, diff --git a/Source/m_swap.h b/Source/m_swap.h index ae92f5a6..9c42da3b 100644 --- a/Source/m_swap.h +++ b/Source/m_swap.h @@ -29,6 +29,8 @@ #ifndef __M_SWAP__ #define __M_SWAP__ +#include "doomtype.h" + // Endianess handling. // WAD files are stored little endian. // @@ -38,10 +40,6 @@ // Swap 16bit, that is, MSB and LSB byte. -#if defined(_MSC_VER) && !defined(__cplusplus) -#define inline __inline -#endif - inline static short SHORT(short x) { return (((unsigned char *) &x)[1]<< 8) +