Merge remote-tracking branch 'remotes/SRB2/vanilla-hotplug' into unfuck-gamepads

# Conflicts:
#	src/d_clisrv.c
#	src/d_netcmd.c
#	src/d_netcmd.h
#	src/dehacked.c
#	src/doomdef.h
#	src/g_game.c
#	src/hu_stuff.c
#	src/lua_baselib.c
#	src/m_menu.c
#	src/sdl/i_system.c
#	src/sdl/sdlmain.h
This commit is contained in:
wolfy852 2018-12-06 13:07:39 -06:00
commit 5fe81afeaa
13 changed files with 211 additions and 134 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0)
project(SRB2
VERSION 2.1.20
VERSION 2.1.21
LANGUAGES C)
if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR})

View File

@ -1,4 +1,4 @@
version: 2.1.20.{branch}-{build}
version: 2.1.21.{branch}-{build}
os: MinGW
environment:

View File

@ -1487,6 +1487,8 @@ static boolean SV_SendServerConfig(INT32 node)
for (i = 0; i < MAXPLAYERS; i++)
{
netbuffer->u.servercfg.adminplayers[i] = (SINT8)adminplayers[i];
if (!playeringame[i])
continue;
netbuffer->u.servercfg.adminplayers[i] = (SINT8)adminplayers[i];
@ -2774,13 +2776,16 @@ static void Command_Kick(void)
if (pn == -1 || pn == 0)
return;
// Special case if we are trying to kick a player who is downloading the game state:
// trigger a timeout instead of kicking them, because a kick would only
// take effect after they have finished downloading
if (sendingsavegame[playernode[pn]])
if (server)
{
Net_ConnectionTimeout(playernode[pn]);
return;
// Special case if we are trying to kick a player who is downloading the game state:
// trigger a timeout instead of kicking them, because a kick would only
// take effect after they have finished downloading
if (sendingsavegame[playernode[pn]])
{
Net_ConnectionTimeout(playernode[pn]);
return;
}
}
WRITESINT8(p, pn);
@ -2834,7 +2839,9 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
}
// Is playernum authorized to make this kick?
if (playernum != serverplayer && !IsPlayerAdmin(playernum))
if (playernum != serverplayer && !IsPlayerAdmin(playernum)
&& !(playerpernode[playernode[playernum]] == 2
&& nodetoplayer2[playernode[playernum]] == pnum))
{
// We received a kick command from someone who isn't the
// server or admin, and who isn't in splitscreen removing

View File

@ -403,7 +403,6 @@ consvar_t cv_overtime = {"overtime", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL,
consvar_t cv_rollingdemos = {"rollingdemos", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_timetic = {"timerres", "Normal", CV_SAVE|CV_NOSHOWHELP, timetic_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // use tics in display
static CV_PossibleValue_t pointlimit_cons_t[] = {{0, "MIN"}, {999999990, "MAX"}, {0, NULL}};
consvar_t cv_pointlimit = {"pointlimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, pointlimit_cons_t,
PointLimit_OnChange, 0, NULL, NULL, 0, 0, NULL};
@ -3533,11 +3532,7 @@ void SetAdminPlayer(INT32 playernum)
break; // End the loop now. If it keeps going, the same player might get assigned to two slots.
}
/*if (i == 3 && adminplayers[i] != -1) // End of the loop and all slots are full
{
adminplayers[0] = playernum; // Overwrite the first slot
break;
}*/
}
}
@ -3709,7 +3704,7 @@ static void Command_MotD_f(void)
}
if ((netgame || multiplayer) && client)
SendNetXCmd(XD_SETMOTD, mymotd, sizeof(motd));
SendNetXCmd(XD_SETMOTD, mymotd, i); // send the actual size of the motd string, not the full buffer's size
else
{
strcpy(motd, mymotd);
@ -4146,6 +4141,47 @@ static void Command_Version_f(void)
#else
CONS_Printf("SRB2Kart %s (%s %s %s)\n", VERSIONSTRING, compdate, comptime, comprevision);
#endif
// Base library
#if defined( HAVE_SDL)
CONS_Printf("SDL ");
#elif defined(_WINDOWS)
CONS_Printf("DD ");
#endif
// OS
// Would be nice to use SDL_GetPlatform for this
#if defined(_WIN32)
CONS_Printf("Windows ");
#elif defined(LINUX)
CONS_Printf("Linux ");
#elif defined(MACOSX)
CONS_Printf("macOS" );
#elif defined(UNIXCOMMON)
CONS_Printf("Unix (Common) ");
#else
CONS_Printf("Other OS ");
#endif
// Bitness
if (sizeof(void*) == 4)
CONS_Printf("32-bit ");
else if (sizeof(void*) == 8)
CONS_Printf("64-bit ");
else // 16-bit? 128-bit?
CONS_Printf("Bits Unknown ");
// No ASM?
#ifdef NOASM
CONS_Printf("\x85" "NOASM " "\x80");
#endif
// Debug build
#ifdef _DEBUG
CONS_Printf("\x85" "DEBUG " "\x80");
#endif
CONS_Printf("\n");
}
#ifdef UPDATE_ALERT

View File

@ -9755,7 +9755,7 @@ static inline int lib_getenum(lua_State *L)
/*} else if (fastcmp(word,"admin")) { // Replaced with IsPlayerAdmin
if (!playeringame[adminplayer] || IsPlayerAdmin(serverplayer))
return 0;
LUA_PushUserdata(L, &players[adminplayer], META_PLAYER);
LUA_PushUserdata(L, &players[adminplayers[0]], META_PLAYER);
return 1;*/
} else if (fastcmp(word,"emeralds")) {
lua_pushinteger(L, emeralds);

View File

@ -140,7 +140,7 @@
extern FILE *logstream;
#endif
//#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3
#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3
#ifdef DEVELOP
#define VERSION 0 // Game version
#define SUBVERSION 0 // more precise version number
@ -286,7 +286,7 @@ typedef enum
SKINCOLOR_SLATE,
SKINCOLOR_STEEL,
SKINCOLOR_JET,
SKINCOLOR_SAPPHIRE, // sweet mother, i cannot weave slender aphrodite has overcome me with longing for a girl
SKINCOLOR_SAPPHIRE, // sweet mother, i cannot weave slender aphrodite has overcome me with longing for a girl
SKINCOLOR_PERIWINKLE,
SKINCOLOR_BLUE,
SKINCOLOR_BLUEBERRY,

View File

@ -8585,7 +8585,7 @@ static void M_DrawJoystick(void)
}
}
static void M_SetupJoystickMenu(INT32 choice)
void M_SetupJoystickMenu(INT32 choice)
{
INT32 i = 0;
const char *joyNA = "Unavailable";

View File

@ -69,7 +69,6 @@ void M_QuitResponse(INT32 ch);
// Determines whether to show a level in the list
boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt);
// flags for items in the menu
// menu handle (what we do when key is pressed
#define IT_TYPE 14 // (2+4+8)
@ -173,6 +172,10 @@ extern menu_t *currentMenu;
extern menu_t MainDef;
extern menu_t SP_LoadDef;
// Call upon joystick hotplug
void M_SetupJoystickMenu(INT32 choice);
extern menu_t OP_JoystickSetDef;
// Stuff for customizing the player select screen
typedef struct
{

View File

@ -871,7 +871,7 @@ static UINT64 lastjoyhats = 0;
*/
static void I_ShutdownJoystick(void)
void I_ShutdownJoystick(void)
{
INT32 i;
event_t event;
@ -905,15 +905,8 @@ static void I_ShutdownJoystick(void)
joystick_started = 0;
JoyReset(&JoyInfo);
if (!joystick_started && !joystick2_started && !joystick3_started && !joystick4_started
&& SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
{
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (cv_usejoystick.value == 0)
{
I_OutputMsg("I_Joystick: SDL's Joystick system has been shutdown\n");
}
}
// don't shut down the subsystem here, because hotplugging
}
void I_GetJoystickEvents(void)
@ -1060,37 +1053,20 @@ static int joy_open(const char *fname)
int num_joy = 0;
int i;
if (joystick_started == 0 && joystick2_started == 0 && joystick3_started == 0 && joystick4_started == 0)
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
{
CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError());
return -1;
}
else
{
num_joy = SDL_NumJoysticks();
}
CONS_Printf(M_GetText("Joystick subsystem not started\n"));
return -1;
}
if (num_joy < joyindex)
{
CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname);
for (i = 0; i < num_joy; i++)
CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i));
I_ShutdownJoystick();
return -1;
}
}
else
{
JoyReset(&JoyInfo);
//I_ShutdownJoystick();
//joy_open(fname);
}
JoyReset(&JoyInfo);
if (joyindex <= 0)
return 0;
num_joy = SDL_NumJoysticks();
if (joyindex <= 0 || num_joy == 0 || JoyInfo.oldjoy == joyindex)
if (num_joy == 0 || JoyInfo.oldjoy == joyindex)
{
// I_OutputMsg("Unable to use that joystick #(%s), non-number\n",fname);
if (num_joy != 0)
@ -1098,10 +1074,20 @@ static int joy_open(const char *fname)
CONS_Printf(M_GetText("Found %d joysticks on this system\n"), num_joy);
for (i = 0; i < num_joy; i++)
CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i));
if (num_joy < joyindex)
{
CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname);
for (i = 0; i < num_joy; i++)
CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i));
return 0;
}
}
else
{
CONS_Printf("%s", M_GetText("Found no joysticks on this system\n"));
if (joyindex <= 0 || num_joy == 0) return 0;
return 0;
}
}
JoyInfo.dev = SDL_JoystickOpen(joyindex-1);
@ -1109,7 +1095,6 @@ static int joy_open(const char *fname)
if (JoyInfo.dev == NULL)
{
CONS_Printf(M_GetText("Couldn't open joystick: %s\n"), SDL_GetError());
I_ShutdownJoystick();
return -1;
}
else
@ -1121,7 +1106,6 @@ static int joy_open(const char *fname)
/* if (joyaxes<2)
{
I_OutputMsg("Not enought axes?\n");
I_ShutdownJoystick();
return 0;
}*/
@ -1156,7 +1140,7 @@ static UINT64 lastjoy2hats = 0;
\return void
*/
static void I_ShutdownJoystick2(void)
void I_ShutdownJoystick2(void)
{
INT32 i;
event_t event;
@ -1190,15 +1174,8 @@ static void I_ShutdownJoystick2(void)
joystick2_started = 0;
JoyReset(&JoyInfo2);
if (!joystick_started && !joystick2_started && !joystick3_started && !joystick4_started
&& SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
{
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (cv_usejoystick2.value == 0)
{
DEBFILE("I_Joystick2: SDL's Joystick system has been shutdown\n");
}
}
// don't shut down the subsystem here, because hotplugging
}
void I_GetJoystick2Events(void)
@ -1347,35 +1324,20 @@ static int joy_open2(const char *fname)
int num_joy = 0;
int i;
if (joystick_started == 0 && joystick2_started == 0 && joystick3_started == 0 && joystick4_started == 0)
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
{
CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError());
return -1;
}
else
num_joy = SDL_NumJoysticks();
CONS_Printf(M_GetText("Joystick subsystem not started\n"));
return -1;
}
if (num_joy < joyindex)
{
CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname);
for (i = 0; i < num_joy; i++)
CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i));
I_ShutdownJoystick2();
return -1;
}
}
else
{
JoyReset(&JoyInfo2);
//I_ShutdownJoystick();
//joy_open(fname);
}
JoyReset(&JoyInfo2);
if (joyindex <= 0)
return 0;
num_joy = SDL_NumJoysticks();
if (joyindex <= 0 || num_joy == 0 || JoyInfo2.oldjoy == joyindex)
if (num_joy == 0 || JoyInfo2.oldjoy == joyindex)
{
// I_OutputMsg("Unable to use that joystick #(%s), non-number\n",fname);
if (num_joy != 0)
@ -1383,18 +1345,27 @@ static int joy_open2(const char *fname)
CONS_Printf(M_GetText("Found %d joysticks on this system\n"), num_joy);
for (i = 0; i < num_joy; i++)
CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i));
if (num_joy < joyindex)
{
CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname);
for (i = 0; i < num_joy; i++)
CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i));
return 0;
}
}
else
{
CONS_Printf("%s", M_GetText("Found no joysticks on this system\n"));
if (joyindex <= 0 || num_joy == 0) return 0;
return 0;
}
}
JoyInfo2.dev = SDL_JoystickOpen(joyindex-1);
if (!JoyInfo2.dev)
if (JoyInfo2.dev == NULL)
{
CONS_Printf(M_GetText("Couldn't open joystick2: %s\n"), SDL_GetError());
I_ShutdownJoystick2();
return -1;
}
else
@ -1403,10 +1374,9 @@ static int joy_open2(const char *fname)
JoyInfo2.axises = SDL_JoystickNumAxes(JoyInfo2.dev);
if (JoyInfo2.axises > JOYAXISSET*2)
JoyInfo2.axises = JOYAXISSET*2;
/* if (joyaxes < 2)
/* if (joyaxes<2)
{
I_OutputMsg("Not enought axes?\n");
I_ShutdownJoystick2();
return 0;
}*/
@ -1997,34 +1967,65 @@ static int joy_open4(const char *fname)
//
void I_InitJoystick(void)
{
I_ShutdownJoystick();
//I_ShutdownJoystick();
SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE);
if (!strcmp(cv_usejoystick.string, "0") || M_CheckParm("-nojoy"))
if (M_CheckParm("-nojoy"))
return;
if (joy_open(cv_usejoystick.string) != -1)
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{
CONS_Printf("Initing joy system\n");
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
{
CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError());
return;
}
}
if (strcmp(cv_usejoystick.string, "0") && joy_open(cv_usejoystick.string) != -1)
{
JoyInfo.oldjoy = atoi(cv_usejoystick.string);
joystick_started = 1;
}
else
{
if (JoyInfo.oldjoy)
I_ShutdownJoystick();
cv_usejoystick.value = 0;
return;
joystick_started = 0;
}
joystick_started = 1;
}
void I_InitJoystick2(void)
{
I_ShutdownJoystick2();
//I_ShutdownJoystick2();
SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE);
if (!strcmp(cv_usejoystick2.string, "0") || M_CheckParm("-nojoy"))
if (M_CheckParm("-nojoy"))
return;
if (joy_open2(cv_usejoystick2.string) != -1)
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{
CONS_Printf("Initing joy system\n");
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
{
CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError());
return;
}
}
if (strcmp(cv_usejoystick2.string, "0") && joy_open2(cv_usejoystick2.string) != -1)
{
JoyInfo2.oldjoy = atoi(cv_usejoystick2.string);
joystick2_started = 1;
}
else
{
if (JoyInfo2.oldjoy)
I_ShutdownJoystick2();
cv_usejoystick2.value = 0;
return;
joystick2_started = 0;
}
joystick2_started = 1;
}
void I_InitJoystick3(void)
@ -2061,27 +2062,26 @@ void I_InitJoystick4(void)
static void I_ShutdownInput(void)
{
// Yes, the name is misleading: these send neutral events to
// clean up the unplugged joystick's input
// Note these methods are internal to this file, not called elsewhere.
I_ShutdownJoystick();
I_ShutdownJoystick2();
if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
{
JoyReset(&JoyInfo);
JoyReset(&JoyInfo2);
CONS_Printf("Shutting down joy system\n");
JoyReset(&JoyInfo3);
JoyReset(&JoyInfo4);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
I_OutputMsg("I_Joystick: SDL's Joystick system has been shutdown\n");
}
}
INT32 I_NumJoys(void)
{
INT32 numjoy = 0;
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1)
numjoy = SDL_NumJoysticks();
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}
else
if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
numjoy = SDL_NumJoysticks();
return numjoy;
}
@ -2091,18 +2091,9 @@ static char joyname[255]; // MAX_PATH; joystick name is straight from the driver
const char *I_GetJoyName(INT32 joyindex)
{
const char *tempname = NULL;
joyname[0] = 0;
joyindex--; //SDL's Joystick System starts at 0, not 1
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
{
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1)
{
tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname)
strncpy(joyname, tempname, 255);
}
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}
else
if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
{
tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname)

View File

@ -116,6 +116,9 @@ static INT32 firstEntry = 0;
// Total mouse motion X/Y offsets
static INT32 mousemovex = 0, mousemovey = 0;
// Keep track of joy unplugged count
static INT32 joyunplugcount = 0;
// SDL vars
static SDL_Surface *vidSurface = NULL;
static SDL_Surface *bufSurface = NULL;
@ -944,6 +947,38 @@ void I_GetEvent(void)
case SDL_JOYBUTTONDOWN:
Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type);
break;
case SDL_JOYDEVICEADDED:
CONS_Printf("Joy device %d added\n", evt.jdevice.which);
// recounts hotplugged joysticks
I_InitJoystick();
I_InitJoystick2();
// update the menu
if (currentMenu == &OP_JoystickSetDef)
M_SetupJoystickMenu(0);
break;
case SDL_JOYDEVICEREMOVED:
{
// every time a device is unplugged, the "which" index increments by 1?
INT32 deviceIdx = evt.jdevice.which - joyunplugcount++;
CONS_Printf("Joy device %d removed%s\n", deviceIdx,
(JoyInfo.oldjoy-1 == deviceIdx) ? " was first joystick" :
(JoyInfo2.oldjoy-1 == deviceIdx) ? " was second joystick" : "");
// I_ShutdownJoystick doesn't shut down the subsystem
// It just fires neutral joy events to clean up the unplugged joy
if (JoyInfo.oldjoy-1 == deviceIdx)
I_ShutdownJoystick();
if (JoyInfo2.oldjoy-1 == deviceIdx)
I_ShutdownJoystick2();
// update the menu
if (currentMenu == &OP_JoystickSetDef)
M_SetupJoystickMenu(0);
}
break;
case SDL_QUIT:
I_Quit();
M_QuitResponse('y');

View File

@ -1214,7 +1214,7 @@
C01FCF4B08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 2.1.20;
CURRENT_PROJECT_VERSION = 2.1.21;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
NORMALSRB2,
@ -1226,7 +1226,7 @@
C01FCF4C08A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 2.1.20;
CURRENT_PROJECT_VERSION = 2.1.21;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (

View File

@ -77,6 +77,11 @@ extern SDLJoyInfo_t JoyInfo4;
void I_GetConsoleEvents(void);
// So we can call this from i_video event loop
void I_ShutdownJoystick(void);
void I_ShutdownJoystick2(void);
void SDLforceUngrabMouse(void);
// Needed for some WIN32 functions

View File

@ -1214,7 +1214,7 @@
C01FCF4B08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 2.1.20;
CURRENT_PROJECT_VERSION = 2.1.21;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
NORMALSRB2,
@ -1226,7 +1226,7 @@
C01FCF4C08A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 2.1.20;
CURRENT_PROJECT_VERSION = 2.1.21;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (