diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 92ef1c299..92a5d2042 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5191,6 +5191,8 @@ fixed_t FixedDistance2(fixed_t aX, fixed_t aY, fixed_t bX, fixed_t bY) static ticcmd_t lastCmds; +//Kart doesnt have FPS shootouts, so this is unneeded +/* void CorrectPlayerTargeting(ticcmd_t* cmds) { if (!players[consoleplayer].mo || !cv_netsteadyplayers.value || simtic == gametic) @@ -5296,6 +5298,7 @@ void CorrectPlayerTargeting(ticcmd_t* cmds) } } } +*/ static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) { @@ -5304,8 +5307,9 @@ static void AdjustSimulatedTiccmdInputs(ticcmd_t* cmds) INT16 oldAngle = cmds->angleturn; - if (gamestate == GS_LEVEL && cv_netsteadyplayers.value && !cv_netslingdelay.value) - CorrectPlayerTargeting(cmds); + //Kart doesnt have match mode where this is relevant + //if (gamestate == GS_LEVEL && cv_netsteadyplayers.value && !cv_netslingdelay.value) + // CorrectPlayerTargeting(cmds); if (cmds->angleturn != oldAngle) { @@ -5830,18 +5834,18 @@ static void RunSimulations() blueflagplayer = &players[i]; } - if (players[i].followmobj) - ADJUSTPOSITION(players[i].followmobj, i); +// if (players[i].followmobj) +// ADJUSTPOSITION(players[i].followmobj, i); } for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) { - if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) - ADJUSTPOSITION(mobj, mobj->target->player - players); - else if (mobj->type == MT_BLUEFLAG && blueflagplayer) - ADJUSTPOSITION(mobj, blueflagplayer - players); - else if (mobj->type == MT_REDFLAG && redflagplayer) - ADJUSTPOSITION(mobj, redflagplayer - players); +// if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) +// ADJUSTPOSITION(mobj, mobj->target->player - players); +// else if (mobj->type == MT_BLUEFLAG && blueflagplayer) +// ADJUSTPOSITION(mobj, blueflagplayer - players); +// else if (mobj->type == MT_REDFLAG && redflagplayer) +// ADJUSTPOSITION(mobj, redflagplayer - players); } } } diff --git a/src/g_game.c b/src/g_game.c index 0639e1cae..243625e3c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -7315,7 +7315,7 @@ void G_DoPlayDemo(char *defdemoname) } // net var data - CV_LoadNetVars(&demo_p); + CV_LoadNetVars(&demo_p, false); // Sigh ... it's an empty demo. if (*demo_p == DEMOMARKER) diff --git a/src/p_mobj.c b/src/p_mobj.c index e25073010..fa5fa6297 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6366,7 +6366,7 @@ void P_MobjThinker(mobj_t *mobj) if (mobj->flags & MF_NOTHINK) return; - if ((mobj->flags & MF_BOSS) && mobj->spawnpoint && (bossdisabled & (1<spawnpoint->extrainfo))) + if ((mobj->flags & MF_BOSS) && mobj->spawnpoint) return; // Remove dead target/tracer. diff --git a/src/p_saveg.c b/src/p_saveg.c index 59a6b9882..ce6ce6338 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -465,8 +465,8 @@ static void P_LocalArchivePlayers(void) RELINK(player->axis1); RELINK(player->axis2); RELINK(player->awayviewmobj); - RELINK(player->followmobj); - RELINK(player->drone); + //RELINK(player->followmobj); + //RELINK(player->drone); #undef RELINK } } @@ -497,6 +497,7 @@ static UINT32 num_ffloors = 0; // for loading // Copypasta from r_data.c AddColormapToList // But also check for equality and return the matching index +/* static UINT32 CheckAddNetColormapToList(extracolormap_t *extra_colormap) { extracolormap_t *exc, *exc_prev = NULL; @@ -707,6 +708,7 @@ static void P_NetUnArchiveColormaps(void) } } } +*/ #define SD_FLOORHT 0x01 #define SD_CEILHT 0x02 @@ -845,7 +847,7 @@ static void P_LocalArchiveWorld(void) UINT8* put; // paranoia something something - ClearNetColormaps(); + //ClearNetColormaps(); WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD); put = save_p; @@ -1495,13 +1497,6 @@ static const specialdef_t specialDefs[] = NOSECTOR(T_NoEnemiesSector, levelspecthink_t), // tc_noenemies NOSECTOR(T_EachTimeThinker, levelspecthink_t), // tc_eachtime NOSECTOR(T_Disappear, disappear_t), // tc_disappear - NOSECTOR(T_Fade, fade_t), // tc_fade - WITHSECTOR(T_FadeColormap, fadecolormap_t, ST_FADEMAPDATA), // tc_fade - NOSECTOR(T_PlaneDisplace, planedisplace_t), // tc_planedisplace -#ifdef ESLOPE - NOSECTOR(T_DynamicSlopeLine, dynplanethink_t), // tc_dynslopeline - NOSECTOR(T_DynamicSlopeVert, dynplanethink_t), // tc_dynslopevert -#endif #ifdef POLYOBJECTS NOSECTOR(T_PolyObjRotate, polyrotate_t), // tc_polyrotate NOSECTOR(T_PolyObjMove, polymove_t), // tc_polymove @@ -1510,8 +1505,6 @@ static const specialdef_t specialDefs[] = NOSECTOR(T_PolyDoorSwing, polyswingdoor_t), // tc_polyswingdoor NOSECTOR(T_PolyObjFlag, polymove_t), // tc_polyflag NOSECTOR(T_PolyObjDisplace, polydisplace_t), // tc_polydisplace - NOSECTOR(T_PolyObjRotDisplace, polyrotdisplace_t), // tc_polyrotdisplace - NOSECTOR(T_PolyObjFade, polyfade_t), // tc_polyfade #endif }; #undef A @@ -3326,6 +3319,7 @@ static void P_LocalUnArchiveThinkers() I_Error("Bad SaveState at archive block Thinkers"); // preserve sky box indexes + /* Probably unused for (i = 0; i < 16; i++) { if (skyboxmo[0] == skyboxviewpnts[i]) @@ -3335,6 +3329,7 @@ static void P_LocalUnArchiveThinkers() skyboxviewpnts[i] = NULL; skyboxcenterpnts[i] = NULL; } + */ skyboxmo[0] = skyboxmo[1] = NULL; // sort thinkers into maps to speed up replacement searches @@ -3378,7 +3373,7 @@ static void P_LocalUnArchiveThinkers() for (i = 0; i < (int)numsectors; i++) { mobj_t* thing = sectors[i].thinglist, *next; - sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; + sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata; // clear nothinkers too while (thing) @@ -3516,6 +3511,7 @@ static void P_LocalUnArchiveThinkers() bflagpoint = mobj->spawnpoint; } + /* if (mobj->type == MT_SKYBOX) { if ((mobj->extravalue2 >> 16) == 1) @@ -3523,6 +3519,7 @@ static void P_LocalUnArchiveThinkers() else skyboxviewpnts[mobj->extravalue2 & 0xFFFF] = mobj; } + */ if (mobj->player && mobj->type == MT_PLAYER) mobj->player->mo = mobj; @@ -3551,10 +3548,12 @@ static void P_LocalUnArchiveThinkers() target->ceilingdata = newthinker; if (specialDefs[tclass].sectorTargets & ST_FLOORDATA) target->floordata = newthinker; + /* if (specialDefs[tclass].sectorTargets & ST_LIGHTDATA) target->lightingdata = newthinker; if (specialDefs[tclass].sectorTargets & ST_FADEMAPDATA) target->fadecolormapdata = newthinker; + */ } // relink into the new thinker list @@ -3693,15 +3692,15 @@ static void P_LocalUnArchiveThinkers() RELINK(players[i].axis1); RELINK(players[i].axis2); RELINK(players[i].awayviewmobj); - RELINK(players[i].followmobj); - RELINK(players[i].drone); + //RELINK(players[i].followmobj); + //RELINK(players[i].drone); } } #undef RELINK // restore skyboxes - skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; - skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; + //skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; + //skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; } // @@ -4545,50 +4544,26 @@ static inline boolean P_NetUnArchiveMisc(boolean preserveLevel) return true; } +//made kart splitscreen compat static inline void P_LocalArchiveCameras() { WRITEMEM(save_p, &camera, sizeof(camera)); - WRITEMEM(save_p, &camera2, sizeof(camera2)); } +//made kart splitscreen compat static inline void P_LocalUnArchiveCameras() { - boolean chase1 = camera.chase; - boolean chase2 = camera2.chase; + UINT32 i; + boolean chase[4]; + for (i = 0; i < 4; i++) + chase[i] = camera[i].chase; // this makes things easy! READMEM(save_p, &camera, sizeof(camera)); - READMEM(save_p, &camera2, sizeof(camera2)); // chase is changed outside of tics, so preserve this - camera.chase = chase1; - camera2.chase = chase2; -} - -static inline void P_ArchiveLuabanksAndConsistency(void) -{ - UINT8 i, banksinuse = NUM_LUABANKS; - - gamespeed = READUINT8(save_p); - franticitems = (boolean)READUINT8(save_p); - comeback = (boolean)READUINT8(save_p); - for (i = 0; i < 4; i++) - battlewanted[i] = READSINT8(save_p); - - wantedcalcdelay = READUINT32(save_p); - indirectitemcooldown = READUINT32(save_p); - hyubgone = READUINT32(save_p); - mapreset = READUINT32(save_p); - nospectategrief = READUINT8(save_p); - thwompsactive = (boolean)READUINT8(save_p); - spbplace = READSINT8(save_p); - - // Is it paused? - if (READUINT8(save_p) == 0x2f) - paused = true; - - return true; + camera[i].chase = chase[i]; } UINT64 I_GetTimeUs(void); @@ -4735,7 +4710,7 @@ void P_SaveGameState(savestate_t* savestate) WRITEINT16(save_p, gamemap); WRITEUINT32(save_p, globalmobjnum); - CV_SaveNetVars(&save_p); + CV_SaveNetVars(&save_p, false); // assign mobj nums for pointer relinking for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) @@ -4777,7 +4752,7 @@ void P_SaveGameState(savestate_t* savestate) LUA_Archive(); #endif - P_ArchiveLuabanksAndConsistency(); + //P_ArchiveLuabanksAndConsistency(); saveStateBenchmark = I_GetTimeUs() - time; } @@ -4821,7 +4796,7 @@ boolean P_LoadGameState(const savestate_t* savestate) // This is stupid and hacky _squared_, but it's in the net load code and it says it might work, so I guess it might work! //P_SetRandSeed(P_GetInitSeed()); - P_UnArchiveLuabanksAndConsistency(); + //P_UnArchiveLuabanksAndConsistency(); loadStateBenchmark = I_GetTimeUs() - time; return true; diff --git a/src/s_sound.c b/src/s_sound.c index c391a91f4..d709b5191 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -154,19 +154,6 @@ consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE|CV_C // percent attenuation from front to back #define S_IFRACVOL 30 -typedef struct -{ - // sound information (if null, channel avail.) - sfxinfo_t *sfxinfo; - - // origin of sound - const void *origin; - - // handle of the sound being played - INT32 handle; - -} channel_t; - // the set of channels available static channel_t *channels = NULL; static INT32 numofchannels = 0; @@ -643,7 +630,7 @@ dontplay: if (origin && origin != listenmobj3) { INT32 rc; - rc = S_AdjustSoundParams(listenmobj3, origin, &volume, &sep, &pitch, sfx); + rc = S_AdjustSoundParams(listenmobj3, origin->x, origin->y, origin->z , &volume, &sep, &pitch, sfx); if (!rc) goto dontplay3; // Maybe the other player can hear it... @@ -699,7 +686,7 @@ dontplay3: if (origin && origin != listenmobj4) { INT32 rc; - rc = S_AdjustSoundParams(listenmobj4, origin, &volume, &sep, &pitch, sfx); + rc = S_AdjustSoundParams(listenmobj4, origin->x, origin->y, origin->z, &volume, &sep, &pitch, sfx); if (!rc) goto dontplay4; // Maybe the other player can hear it... @@ -1240,7 +1227,11 @@ void S_DetachChannelsFromOrigin(void* origin) if (channels[i].origin == origin) { // small hack: player-made sounds should stay hearable - if (originmobj->player != &players[displayplayer]) + if (originmobj->player != &players[displayplayers[0]] && + originmobj->player != &players[displayplayers[1]] && + originmobj->player != &players[displayplayers[2]] && + originmobj->player != &players[displayplayers[3]] + ) { channels[i].isdetached = true; channels[i].detachedx = originmobj->x; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e5b4e1b66..3454eca8f 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -131,25 +131,26 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #endif -// Locations for searching the srb2.pk3 +// Locations for searching the srb2.srb #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) -#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2" -#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2" -#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2" -#define DEFAULTWADLOCATION4 "/usr/games/SRB2" +#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2Kart" +#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2Kart" +#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2Kart" +#define DEFAULTWADLOCATION4 "/usr/games/SRB2Kart" #define DEFAULTSEARCHPATH1 "/usr/local/games" #define DEFAULTSEARCHPATH2 "/usr/games" #define DEFAULTSEARCHPATH3 "/usr/local" #elif defined (_WIN32) -#define DEFAULTWADLOCATION1 "c:\\games\\srb2" -#define DEFAULTWADLOCATION2 "\\games\\srb2" +#define DEFAULTWADLOCATION1 "c:\\games\\srb2kart" +#define DEFAULTWADLOCATION2 "\\games\\srb2kart" #define DEFAULTSEARCHPATH1 "c:\\games" #define DEFAULTSEARCHPATH2 "\\games" #endif /** \brief WAD file to look for */ -#define WADKEYWORD1 "srb2.pk3" +#define WADKEYWORD1 "srb2.srb" +#define WADKEYWORD2 "srb2.wad" /** \brief holds wad path */ static char returnWadPath[256]; @@ -204,21 +205,36 @@ static void JoyReset(SDLJoyInfo_t *JoySet) /** \brief First joystick up and running */ -static INT32 joystick_started = 0; +static INT32 joystick_started = 0; /** \brief SDL info about joystick 1 */ SDLJoyInfo_t JoyInfo; - /** \brief Second joystick up and running */ static INT32 joystick2_started = 0; -/** \brief SDL inof about joystick 2 +/** \brief SDL info about joystick 2 */ SDLJoyInfo_t JoyInfo2; +/** \brief Third joystick up and running +*/ +static INT32 joystick3_started = 0; + +/** \brief SDL info about joystick 3 +*/ +SDLJoyInfo_t JoyInfo3; + +/** \brief Fourth joystick up and running +*/ +static INT32 joystick4_started = 0; + +/** \brief SDL info about joystick 4 +*/ +SDLJoyInfo_t JoyInfo4; + #ifdef HAVE_TERMIOS static INT32 fdmouse2 = -1; static INT32 mouse2_started = 0; @@ -608,7 +624,7 @@ static void I_StartupConsole(void) if (gotConsole) { - SetConsoleTitleA("SRB2 Console"); + SetConsoleTitleA("SRB2Kart Console"); consolevent = SDL_TRUE; } @@ -827,6 +843,18 @@ void I_JoyScale2(void) JoyInfo2.scale = Joystick2.bGamepadStyle?1:cv_joyscale2.value; } +void I_JoyScale3(void) +{ + Joystick3.bGamepadStyle = cv_joyscale3.value==0; + JoyInfo3.scale = Joystick3.bGamepadStyle?1:cv_joyscale3.value; +} + +void I_JoyScale4(void) +{ + Joystick4.bGamepadStyle = cv_joyscale4.value==0; + JoyInfo4.scale = Joystick4.bGamepadStyle?1:cv_joyscale4.value; +} + // Cheat to get the device index for a joystick handle INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev) { @@ -837,12 +865,208 @@ INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev) SDL_Joystick *test = SDL_JoystickOpen(i); if (test && test == dev) return i; - else if (JoyInfo.dev != test && JoyInfo2.dev != test) + else if (JoyInfo.dev != test && JoyInfo2.dev != test && JoyInfo3.dev != test && JoyInfo4.dev != test) SDL_JoystickClose(test); } return -1; } +// Misleading function: updates device indices for all players BUT the one specified. +// Necessary for SDL_JOYDEVICEADDED events +void I_UpdateJoystickDeviceIndices(INT32 player) +{ + if (player != 1) // This is a fucking mess. + { + ////////////////////////////// + // update joystick 1's device index + ////////////////////////////// + + if (JoyInfo.dev) + cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; + // is cv_usejoystick used? + else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value + && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick3.value + && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick.string); + // is cv_usejoystick2 used? + else if ( // don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value + && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick3.value + && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick3 used? + else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick2.value + && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick3.value + && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick3.string); + // is cv_usejoystick4 used? + else if (// don't check JoyInfo or cv_usejoystick; we're currently operating on those + atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick2.value + && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick3.value + && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) + cv_usejoystick.value = atoi(cv_usejoystick4.string); + else // we tried... + cv_usejoystick.value = 0; + } + + if (player != 2) + { + ////////////////////////////// + // update joystick 2's device index + ////////////////////////////// + + if (JoyInfo2.dev) + cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; + // is cv_usejoystick2 used? + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick3.value + && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick used? + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick3.value + && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick.string); + // is cv_usejoystick3 used? + else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick3.value + && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick3.string); + // is cv_usejoystick4 used? + else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick.value + // don't check JoyInfo2 or cv_usejoystick2; we're currently operating on those + && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick3.value + && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) + cv_usejoystick2.value = atoi(cv_usejoystick4.string); + else // we tried... + cv_usejoystick2.value = 0; + } + + if (player != 3) + { + ////////////////////////////// + // update joystick 3's device index + ////////////////////////////// + + if (JoyInfo3.dev) + cv_usejoystick3.value = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; + // is cv_usejoystick3 used? + else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick.value + && atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick3.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick3.string); + // is cv_usejoystick used? + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value + && atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick.string); + // is cv_usejoystick2 used? + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value + && atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick2.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick4 used? + else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick.value + && atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick2.value + // don't check JoyInfo3 or cv_usejoystick3; we're currently operating on those + && atoi(cv_usejoystick4.string) != JoyInfo4.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick4.value) + cv_usejoystick3.value = atoi(cv_usejoystick4.string); + else // we tried... + cv_usejoystick3.value = 0; + } + + if (player != 4) + { + ////////////////////////////// + // update joystick 4's device index + ////////////////////////////// + + if (JoyInfo4.dev) + cv_usejoystick4.value = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; + // is cv_usejoystick4 used? + else if (atoi(cv_usejoystick4.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick.value + && atoi(cv_usejoystick4.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick2.value + && atoi(cv_usejoystick4.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick4.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick4.string); + // is cv_usejoystick used? + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value + && atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value + && atoi(cv_usejoystick.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick.string); + // is cv_usejoystick2 used? + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value + && atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value + && atoi(cv_usejoystick2.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick2.string); + // is cv_usejoystick3 used? + else if (atoi(cv_usejoystick3.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick.value + && atoi(cv_usejoystick3.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick2.value + && atoi(cv_usejoystick3.string) != JoyInfo3.oldjoy + && atoi(cv_usejoystick3.string) != cv_usejoystick3.value) + // don't check JoyInfo4 or cv_usejoystick4; we're currently operating on those + cv_usejoystick4.value = atoi(cv_usejoystick3.string); + else // we tried... + cv_usejoystick4.value = 0; + } +} /** \brief Joystick 1 buttons states */ @@ -1386,6 +1610,548 @@ static int joy_open2(int joyindex) } } +//Joystick3 + +/** \brief Joystick 3 buttons states +*/ +static UINT64 lastjoy3buttons = 0; + +/** \brief Joystick 3 hats state +*/ +static UINT64 lastjoy3hats = 0; + +/** \brief Shuts down joystick 3 + + +\return void +*/ +void I_ShutdownJoystick3(void) +{ + INT32 i; + event_t event; + event.type = ev_keyup; + event.data2 = 0; + event.data3 = 0; + + lastjoy3buttons = lastjoy3hats = 0; + + // emulate the up of all joystick buttons + for (i = 0; i < JOYBUTTONS; i++) + { + event.data1 = KEY_3JOY1 + i; + D_PostEvent(&event); + } + + // emulate the up of all joystick hats + for (i = 0; i < JOYHATS*4; i++) + { + event.data1 = KEY_3HAT1 + i; + D_PostEvent(&event); + } + + // reset joystick position + event.type = ev_joystick3; + for (i = 0; i < JOYAXISSET; i++) + { + event.data1 = i; + D_PostEvent(&event); + } + + joystick3_started = 0; + JoyReset(&JoyInfo3); + + // don't shutdown the subsystem here, because hotplugging +} + +void I_GetJoystick3Events(void) +{ + static event_t event = {0,0,0,0}; + INT32 i = 0; + UINT64 joyhats = 0; +#if 0 + INT64 joybuttons = 0; +#endif + INT32 axisx, axisy; + + if (!joystick3_started) + return; + + if (!JoyInfo3.dev) //I_ShutdownJoystick3(); + return; + + +#if 0 + //faB: look for as much buttons as g_input code supports, + // we don't use the others + for (i = JoyInfo3.buttons - 1; i >= 0; i--) + { + joybuttons <<= 1; + if (SDL_JoystickGetButton(JoyInfo3.dev,i)) + joybuttons |= 1; + } + + if (joybuttons != lastjoy3buttons) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newbuttons = joybuttons ^ lastjoy3buttons; + lastjoy3buttons = joybuttons; + + for (i = 0; i < JOYBUTTONS; i++, j <<= 1) + { + if (newbuttons & j) // button changed state? + { + if (joybuttons & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_3JOY1 + i; + D_PostEvent(&event); + } + } + } +#endif + + for (i = JoyInfo3.hats - 1; i >= 0; i--) + { + Uint8 hat = SDL_JoystickGetHat(JoyInfo3.dev, i); + + if (hat & SDL_HAT_UP ) joyhats|=(UINT64)0x1<<(0 + 4*i); + if (hat & SDL_HAT_DOWN ) joyhats|=(UINT64)0x1<<(1 + 4*i); + if (hat & SDL_HAT_LEFT ) joyhats|=(UINT64)0x1<<(2 + 4*i); + if (hat & SDL_HAT_RIGHT) joyhats|=(UINT64)0x1<<(3 + 4*i); + } + + if (joyhats != lastjoy3hats) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newhats = joyhats ^ lastjoy3hats; + lastjoy3hats = joyhats; + + for (i = 0; i < JOYHATS*4; i++, j <<= 1) + { + if (newhats & j) // hat changed state? + { + if (joyhats & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_3HAT1 + i; + D_PostEvent(&event); + } + } + } + + // send joystick axis positions + event.type = ev_joystick3; + + for (i = JOYAXISSET - 1; i >= 0; i--) + { + event.data1 = i; + if (i*2 + 1 <= JoyInfo3.axises) + axisx = SDL_JoystickGetAxis(JoyInfo3.dev, i*2 + 0); + else axisx = 0; + if (i*2 + 2 <= JoyInfo3.axises) + axisy = SDL_JoystickGetAxis(JoyInfo3.dev, i*2 + 1); + else axisy = 0; + + // -32768 to 32767 + axisx = axisx/32; + axisy = axisy/32; + + if (Joystick3.bGamepadStyle) + { + // gamepad control type, on or off, live or die + if (axisx < -(JOYAXISRANGE/2)) + event.data2 = -1; + else if (axisx > (JOYAXISRANGE/2)) + event.data2 = 1; + else + event.data2 = 0; + if (axisy < -(JOYAXISRANGE/2)) + event.data3 = -1; + else if (axisy > (JOYAXISRANGE/2)) + event.data3 = 1; + else + event.data3 = 0; + } + else + { + + axisx = JoyInfo3.scale?((axisx/JoyInfo3.scale)*JoyInfo3.scale):axisx; + axisy = JoyInfo3.scale?((axisy/JoyInfo3.scale)*JoyInfo3.scale):axisy; + +#ifdef SDL_JDEADZONE + if (-SDL_JDEADZONE <= axisx && axisx <= SDL_JDEADZONE) axisx = 0; + if (-SDL_JDEADZONE <= axisy && axisy <= SDL_JDEADZONE) axisy = 0; +#endif + + // analog control style , just send the raw data + event.data2 = axisx; // x axis + event.data3 = axisy; // y axis + } + D_PostEvent(&event); + } + +} + +/** \brief Open joystick handle + + \param fname name of joystick + + \return axises + + +*/ +static int joy_open3(int joyindex) +{ + SDL_Joystick *newdev = NULL; + int num_joy = 0; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf(M_GetText("Joystick subsystem not started\n")); + return -1; + } + + if (joyindex <= 0) + return -1; + + num_joy = SDL_NumJoysticks(); + + if (num_joy == 0) + { + CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); + return -1; + } + + newdev = SDL_JoystickOpen(joyindex - 1); + + // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging + // This indexing is SDL's responsibility and there's not much we can do about it. + // + // Example: + // 1. Plug Controller A -> Index 0 opened + // 2. Plug Controller B -> Index 1 opened + // 3. Unplug Controller A -> Index 0 closed, Index 1 active + // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed + // 5. Plug Controller B -> Index 0 opened + // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B + if (JoyInfo3.dev) + { + if (JoyInfo3.dev == newdev // same device, nothing to do + || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo3.dev))) // we failed, but already have a working device + return JoyInfo.axises; + // Else, we're changing devices, so send neutral joy events + CONS_Debug(DBG_GAMELOGIC, "Joystick3 device is changing; resetting events...\n"); + I_ShutdownJoystick3(); + } + + JoyInfo3.dev = newdev; + + if (JoyInfo3.dev == NULL) + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick3: couldn't open device - %s\n"), SDL_GetError()); + return -1; + } + else + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick3: %s\n"), SDL_JoystickName(JoyInfo3.dev)); + JoyInfo3.axises = SDL_JoystickNumAxes(JoyInfo3.dev); + if (JoyInfo3.axises > JOYAXISSET * 2) + JoyInfo3.axises = JOYAXISSET * 2; + /* if (joyaxes<2) + { + I_OutputMsg("Not enought axes?\n"); + return 0; + }*/ + + JoyInfo3.buttons = SDL_JoystickNumButtons(JoyInfo3.dev); + if (JoyInfo3.buttons > JOYBUTTONS) + JoyInfo3.buttons = JOYBUTTONS; + + JoyInfo3.hats = SDL_JoystickNumHats(JoyInfo3.dev); + if (JoyInfo3.hats > JOYHATS) + JoyInfo3.hats = JOYHATS; + + JoyInfo3.balls = SDL_JoystickNumBalls(JoyInfo3.dev); + + //Joystick.bGamepadStyle = !stricmp(SDL_JoystickName(JoyInfo3.dev), "pad"); + + return JoyInfo3.axises; + } +} + +//Joystick4 + +/** \brief Joystick 4 buttons states +*/ +static UINT64 lastjoy4buttons = 0; + +/** \brief Joystick 4 hats state +*/ +static UINT64 lastjoy4hats = 0; + +/** \brief Shuts down joystick 4 + + +\return void +*/ +void I_ShutdownJoystick4(void) +{ + INT32 i; + event_t event; + event.type = ev_keyup; + event.data2 = 0; + event.data3 = 0; + + lastjoy4buttons = lastjoy4hats = 0; + + // emulate the up of all joystick buttons + for (i = 0; i < JOYBUTTONS; i++) + { + event.data1 = KEY_4JOY1 + i; + D_PostEvent(&event); + } + + // emulate the up of all joystick hats + for (i = 0; i < JOYHATS*4; i++) + { + event.data1 = KEY_4HAT1 + i; + D_PostEvent(&event); + } + + // reset joystick position + event.type = ev_joystick4; + for (i = 0; i < JOYAXISSET; i++) + { + event.data1 = i; + D_PostEvent(&event); + } + + joystick4_started = 0; + JoyReset(&JoyInfo4); + + // don't shutdown the subsystem here, because hotplugging +} + +void I_GetJoystick4Events(void) +{ + static event_t event = {0,0,0,0}; + INT32 i = 0; + UINT64 joyhats = 0; +#if 0 + INT64 joybuttons = 0; +#endif + INT32 axisx, axisy; + + if (!joystick4_started) + return; + + if (!JoyInfo4.dev) //I_ShutdownJoystick4(); + return; + + +#if 0 + //faB: look for as much buttons as g_input code supports, + // we don't use the others + for (i = JoyInfo4.buttons - 1; i >= 0; i--) + { + joybuttons <<= 1; + if (SDL_JoystickGetButton(JoyInfo4.dev,i)) + joybuttons |= 1; + } + + if (joybuttons != lastjoy4buttons) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newbuttons = joybuttons ^ lastjoy4buttons; + lastjoy4buttons = joybuttons; + + for (i = 0; i < JOYBUTTONS; i++, j <<= 1) + { + if (newbuttons & j) // button changed state? + { + if (joybuttons & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_4JOY1 + i; + D_PostEvent(&event); + } + } + } +#endif + + for (i = JoyInfo4.hats - 1; i >= 0; i--) + { + Uint8 hat = SDL_JoystickGetHat(JoyInfo4.dev, i); + + if (hat & SDL_HAT_UP ) joyhats|=(UINT64)0x1<<(0 + 4*i); + if (hat & SDL_HAT_DOWN ) joyhats|=(UINT64)0x1<<(1 + 4*i); + if (hat & SDL_HAT_LEFT ) joyhats|=(UINT64)0x1<<(2 + 4*i); + if (hat & SDL_HAT_RIGHT) joyhats|=(UINT64)0x1<<(3 + 4*i); + } + + if (joyhats != lastjoy4hats) + { + INT64 j = 1; // keep only bits that changed since last time + INT64 newhats = joyhats ^ lastjoy4hats; + lastjoy4hats = joyhats; + + for (i = 0; i < JOYHATS*4; i++, j <<= 1) + { + if (newhats & j) // hat changed state? + { + if (joyhats & j) + event.type = ev_keydown; + else + event.type = ev_keyup; + event.data1 = KEY_4HAT1 + i; + D_PostEvent(&event); + } + } + } + + // send joystick axis positions + event.type = ev_joystick4; + + for (i = JOYAXISSET - 1; i >= 0; i--) + { + event.data1 = i; + if (i*2 + 1 <= JoyInfo4.axises) + axisx = SDL_JoystickGetAxis(JoyInfo4.dev, i*2 + 0); + else axisx = 0; + if (i*2 + 2 <= JoyInfo4.axises) + axisy = SDL_JoystickGetAxis(JoyInfo4.dev, i*2 + 1); + else axisy = 0; + + // -32768 to 32767 + axisx = axisx/32; + axisy = axisy/32; + + if (Joystick4.bGamepadStyle) + { + // gamepad control type, on or off, live or die + if (axisx < -(JOYAXISRANGE/2)) + event.data2 = -1; + else if (axisx > (JOYAXISRANGE/2)) + event.data2 = 1; + else + event.data2 = 0; + if (axisy < -(JOYAXISRANGE/2)) + event.data3 = -1; + else if (axisy > (JOYAXISRANGE/2)) + event.data3 = 1; + else + event.data3 = 0; + } + else + { + + axisx = JoyInfo4.scale?((axisx/JoyInfo4.scale)*JoyInfo4.scale):axisx; + axisy = JoyInfo4.scale?((axisy/JoyInfo4.scale)*JoyInfo4.scale):axisy; + +#ifdef SDL_JDEADZONE + if (-SDL_JDEADZONE <= axisx && axisx <= SDL_JDEADZONE) axisx = 0; + if (-SDL_JDEADZONE <= axisy && axisy <= SDL_JDEADZONE) axisy = 0; +#endif + + // analog control style , just send the raw data + event.data2 = axisx; // x axis + event.data3 = axisy; // y axis + } + D_PostEvent(&event); + } + +} + +/** \brief Open joystick handle + + \param fname name of joystick + + \return axises + + +*/ +static int joy_open4(int joyindex) +{ + SDL_Joystick *newdev = NULL; + int num_joy = 0; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf(M_GetText("Joystick subsystem not started\n")); + return -1; + } + + if (joyindex <= 0) + return -1; + + num_joy = SDL_NumJoysticks(); + + if (num_joy == 0) + { + CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); + return -1; + } + + newdev = SDL_JoystickOpen(joyindex - 1); + + // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging + // This indexing is SDL's responsibility and there's not much we can do about it. + // + // Example: + // 1. Plug Controller A -> Index 0 opened + // 2. Plug Controller B -> Index 1 opened + // 3. Unplug Controller A -> Index 0 closed, Index 1 active + // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed + // 5. Plug Controller B -> Index 0 opened + // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B + if (JoyInfo4.dev) + { + if (JoyInfo4.dev == newdev // same device, nothing to do + || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo4.dev))) // we failed, but already have a working device + return JoyInfo.axises; + // Else, we're changing devices, so send neutral joy events + CONS_Debug(DBG_GAMELOGIC, "Joystick4 device is changing; resetting events...\n"); + I_ShutdownJoystick4(); + } + + JoyInfo4.dev = newdev; + + if (JoyInfo4.dev == NULL) + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick4: couldn't open device - %s\n"), SDL_GetError()); + return -1; + } + else + { + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick4: %s\n"), SDL_JoystickName(JoyInfo4.dev)); + JoyInfo4.axises = SDL_JoystickNumAxes(JoyInfo4.dev); + if (JoyInfo4.axises > JOYAXISSET * 2) + JoyInfo4.axises = JOYAXISSET * 2; + /* if (joyaxes<2) + { + I_OutputMsg("Not enought axes?\n"); + return 0; + }*/ + + JoyInfo4.buttons = SDL_JoystickNumButtons(JoyInfo4.dev); + if (JoyInfo4.buttons > JOYBUTTONS) + JoyInfo4.buttons = JOYBUTTONS; + + JoyInfo4.hats = SDL_JoystickNumHats(JoyInfo4.dev); + if (JoyInfo4.hats > JOYHATS) + JoyInfo4.hats = JOYHATS; + + JoyInfo4.balls = SDL_JoystickNumBalls(JoyInfo4.dev); + + //Joystick.bGamepadStyle = !stricmp(SDL_JoystickName(JoyInfo4.dev), "pad"); + + return JoyInfo4.axises; + } +} + // // I_InitJoystick // @@ -1417,7 +2183,7 @@ void I_InitJoystick(void) if (cv_usejoystick.value) newjoy = SDL_JoystickOpen(cv_usejoystick.value-1); - if (newjoy && JoyInfo2.dev == newjoy) // don't override an active device +if (newjoy && (JoyInfo2.dev == newjoy || JoyInfo3.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; else if (newjoy && joy_open(cv_usejoystick.value) != -1) { @@ -1434,7 +2200,7 @@ void I_InitJoystick(void) joystick_started = 0; } - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) SDL_JoystickClose(newjoy); } @@ -1446,12 +2212,6 @@ void I_InitJoystick2(void) if (M_CheckParm("-nojoy")) return; - if (M_CheckParm("-noxinput")) - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); - - if (M_CheckParm("-nohidapi")) - SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI", "0", SDL_HINT_OVERRIDE); - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { CONS_Printf("I_InitJoystick2()...\n"); @@ -1466,7 +2226,7 @@ void I_InitJoystick2(void) if (cv_usejoystick2.value) newjoy = SDL_JoystickOpen(cv_usejoystick2.value-1); - if (newjoy && JoyInfo.dev == newjoy) // don't override an active device + if (newjoy && (JoyInfo.dev == newjoy || JoyInfo3.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; else if (newjoy && joy_open2(cv_usejoystick2.value) != -1) { @@ -1483,7 +2243,93 @@ void I_InitJoystick2(void) joystick2_started = 0; } - if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) + SDL_JoystickClose(newjoy); +} + +void I_InitJoystick3(void) +{ + SDL_Joystick *newjoy = NULL; + + //I_ShutdownJoystick3(); + //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + if (M_CheckParm("-nojoy")) + return; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf("I_InitJoystick3()...\n"); + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + { + CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); + return; + } + } + + if (cv_usejoystick3.value) + newjoy = SDL_JoystickOpen(cv_usejoystick3.value - 1); + + if (newjoy && (JoyInfo.dev == newjoy || JoyInfo2.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device + cv_usejoystick3.value = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; + else if (newjoy && joy_open3(cv_usejoystick3.value) != -1) + { + // SDL's device indexes are unstable, so cv_usejoystick may not match + // the actual device index. So let's cheat a bit and find the device's current index. + JoyInfo3.oldjoy = I_GetJoystickDeviceIndex(JoyInfo3.dev) + 1; + joystick3_started = 1; + } + else + { + if (JoyInfo3.oldjoy) + I_ShutdownJoystick3(); + cv_usejoystick3.value = 0; + joystick3_started = 0; + } + + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) + SDL_JoystickClose(newjoy); +} + +void I_InitJoystick4(void) +{ + SDL_Joystick *newjoy = NULL; + + //I_ShutdownJoystick4(); + //SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + if (M_CheckParm("-nojoy")) + return; + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf("I_InitJoystick4()...\n"); + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + { + CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); + return; + } + } + + if (cv_usejoystick4.value) + newjoy = SDL_JoystickOpen(cv_usejoystick4.value - 1); + + if (newjoy && (JoyInfo.dev == newjoy || JoyInfo2.dev == newjoy || JoyInfo4.dev == newjoy)) // don't override an active device + cv_usejoystick4.value = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; + else if (newjoy && joy_open4(cv_usejoystick4.value) != -1) + { + // SDL's device indexes are unstable, so cv_usejoystick may not match + // the actual device index. So let's cheat a bit and find the device's current index. + JoyInfo4.oldjoy = I_GetJoystickDeviceIndex(JoyInfo4.dev) + 1; + joystick4_started = 1; + } + else + { + if (JoyInfo4.oldjoy) + I_ShutdownJoystick4(); + cv_usejoystick4.value = 0; + joystick4_started = 0; + } + + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy && JoyInfo3.dev != newjoy && JoyInfo4.dev != newjoy) SDL_JoystickClose(newjoy); } @@ -1494,6 +2340,8 @@ static void I_ShutdownInput(void) // Note these methods are internal to this file, not called elsewhere. I_ShutdownJoystick(); I_ShutdownJoystick2(); + I_ShutdownJoystick3(); + I_ShutdownJoystick4(); if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { @@ -1599,8 +2447,8 @@ void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) return; if(mumble->uiVersion != 2) { - wcsncpy(mumble->name, L"SRB2 "VERSIONSTRINGW, 256); - wcsncpy(mumble->description, L"Sonic Robo Blast 2 with integrated Mumble Link support.", 2048); + wcsncpy(mumble->name, L"SRB2Kart "VERSIONSTRINGW, 256); + wcsncpy(mumble->description, L"Sonic Robo Blast 2 Kart with integrated Mumble Link support.", 2048); mumble->uiVersion = 2; } mumble->uiTick++; @@ -2003,6 +2851,20 @@ void I_Tactile2(FFType pFFType, const JoyFF_t *FFEffect) (void)FFEffect; } +void I_Tactile3(FFType pFFType, const JoyFF_t *FFEffect) +{ + // UNUSED. + (void)pFFType; + (void)FFEffect; +} + +void I_Tactile4(FFType pFFType, const JoyFF_t *FFEffect) +{ + // UNUSED. + (void)pFFType; + (void)FFEffect; +} + /** \brief empty ticcmd for player 1 */ static ticcmd_t emptycmd; @@ -2021,6 +2883,23 @@ ticcmd_t *I_BaseTiccmd2(void) return &emptycmd2; } +/** \brief empty ticcmd for player 3 +*/ +static ticcmd_t emptycmd3; + +ticcmd_t *I_BaseTiccmd3(void) +{ + return &emptycmd3; +} + +/** \brief empty ticcmd for player 4 +*/ +static ticcmd_t emptycmd4; + +ticcmd_t *I_BaseTiccmd4(void) +{ + return &emptycmd4; +} static int lastTimeFudge = -1; extern consvar_t cv_timefudge; @@ -2266,14 +3145,14 @@ void I_Quit(void) #ifndef NONET D_SaveBan(); // save the ban list #endif - G_SaveGameData(); // Tails 12-08-2002 + G_SaveGameData(false); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. - if (demorecording) + if (demo.recording) G_CheckDemoStatus(); if (metalrecording) - G_StopMetalRecording(false); + G_StopMetalRecording(); D_QuitNetGame(); I_ShutdownMusic(); @@ -2351,7 +3230,7 @@ void I_Error(const char *error, ...) if (errorcount == 9) { M_SaveConfig(NULL); - G_SaveGameData(); + G_SaveGameData(false); } if (errorcount > 20) { @@ -2385,13 +3264,13 @@ void I_Error(const char *error, ...) #ifndef NONET D_SaveBan(); // save the ban list #endif - G_SaveGameData(); // Tails 12-08-2002 + G_SaveGameData(false); // Tails 12-08-2002 // Shutdown. Here might be other errors. - if (demorecording) + if (demo.recording) G_CheckDemoStatus(); if (metalrecording) - G_StopMetalRecording(false); + G_StopMetalRecording(); D_QuitNetGame(); I_ShutdownMusic(); @@ -2407,7 +3286,7 @@ void I_Error(const char *error, ...) // which should fail gracefully if it can't put a message box up // on the target system SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2 "VERSIONSTRING" Error", + "SRB2Kart "VERSIONSTRING" Error", buffer, NULL); // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be // initialized at the time, so calling it after SDL_Quit() is @@ -2540,7 +3419,7 @@ void I_GetDiskFreeSpace(INT64 *freespace) char *I_GetUserName(void) { - static char username[MAXPLAYERNAME+1]; + static char username[MAXPLAYERNAME]; char *p; #ifdef _WIN32 DWORD i = MAXPLAYERNAME; @@ -2671,6 +3550,14 @@ static boolean isWadPathOk(const char *path) return true; } + sprintf(wad3path, pandf, path, WADKEYWORD2); + + if (FIL_ReadFileOK(wad3path)) + { + free(wad3path); + return true; + } + free(wad3path); return false; } @@ -2688,7 +3575,7 @@ static void pathonly(char *s) } } -/** \brief search for srb2.pk3 in the given path +/** \brief search for srb2.srb in the given path \param searchDir starting path @@ -2708,13 +3595,20 @@ static const char *searchWad(const char *searchDir) pathonly(tempsw); return tempsw; } - + + strcpy(tempsw, WADKEYWORD2); + fstemp = filesearch(tempsw, searchDir, NULL, true, 20); + if (fstemp == FS_FOUND) + { + pathonly(tempsw); + return tempsw; + } return NULL; } -/** \brief go through all possible paths and look for srb2.pk3 +/** \brief go through all possible paths and look for srb2.srb - \return path to srb2.pk3 if any + \return path to srb2.srb if any */ static const char *locateWad(void) { @@ -2843,7 +3737,7 @@ const char *I_LocateWad(void) if (waddir) { - // change to the directory where we found srb2.pk3 + // change to the directory where we found srb2.srb #if defined (_WIN32) SetCurrentDirectoryA(waddir); #else