Compare commits

..
Author SHA1 Message Date
Alug 24163a7c92 Merge branch 'Saturn-Next' into controllerfixes 2025-11-11 14:53:40 +01:00
Alug d934197246 git merge pls 2025-11-11 14:49:11 +01:00
Alug d4a130f1dc remove those memsets
not needed anymore now
2025-10-24 18:40:29 +02:00
Alug 8ccf4eb9ba this can be alot smoler 2025-10-24 18:40:25 +02:00
Alug cdb7b6fede initialize input events to something 2025-10-24 18:40:21 +02:00
Alug fcae072625 refactor controller dpad menu repeat handling
dont hack around manually checking for state checks
just use sdl provided stuff and poll if a dpad button currently is being held
2025-10-24 18:40:18 +02:00
Alug 1d3dae01e9 set SDL_HINT_AUTO_UPDATE_SENSORS hint to 0
we dont need any of that so disable it
2025-10-23 20:58:01 +02:00
Alug 736a626ccf init joyinfo in I_InitJoystick 2025-10-23 20:57:58 +02:00
Alug a4cc8b0585 keep track of joystick instance index
means we dont constantly need to refetch it
needs testing on windoze
2025-10-23 20:57:55 +02:00
Alug 333c94be52 clean up controller dpad input handling
just treat them as "normal" buttons instead of manually polling for them
alot cleaner and gets rid of yet another polling loop
also clean up some other stuff
needs to be tested with multiple controllers in splitscreen but cba to do that atm
2025-10-23 20:57:52 +02:00
17 changed files with 179 additions and 289 deletions

No files matched your search

+1 -55
View File
@@ -143,11 +143,6 @@ static CV_PossibleValue_t mindelay_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL
consvar_t cv_mindelay = {"mindelay", "0", CV_SAVE, mindelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_gentlemens = {"gentlemensdelay", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Lagless_OnChange, 0, NULL, NULL, 0, 0, NULL}; // this should be a netvar Zzz...
// allows a fake player to appear on the ms and serverlist when your dedi server is empty
static void FakeSeed_OnChange(void);
consvar_t cv_usefakeseed = {"fakeseed", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, FakeSeed_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_fakeseedname = {"fakeseedname", "Player 1", CV_SAVE|CV_CALL|CV_NOINIT, NULL, FakeSeed_OnChange, 0, NULL, NULL, 0, 0, NULL};
SINT8 nodetoplayer[MAXNETNODES] = {};
SINT8 nodetoplayer2[MAXNETNODES] = {}; // say the numplayer for this node if any (splitscreen)
SINT8 nodetoplayer3[MAXNETNODES] = {}; // say the numplayer for this node if any (splitscreen == 2)
@@ -245,13 +240,6 @@ consvar_t cv_httpsource = {"http_source", "", CV_SAVE, NULL, NULL, 0, NULL, NULL
consvar_t cv_kicktime = {"kicktime", "10", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL};
static void FakeSeed_OnChange(void)
{
#ifdef MASTERSERVER
Update_MS();
#endif
}
static boolean UseLocalDelay(void)
{
if (dedicated || (server && server_lagless && !cv_mindelay.value) || modeattacking == ATTACKING_RECORD)
@@ -1556,12 +1544,6 @@ static boolean CL_SendJoin(void)
return HSendPacket(servernode, false, 0, sizeof(clientconfig_pak));
}
static boolean UseFakeSeed(void)
{
// due to complexity this will disable the moment a real player joins
return (dedicated && cv_usefakeseed.value && D_NumPlayers() == 0);
}
static void SV_SendServerInfo(INT32 node, tic_t servertime)
{
UINT8 *p;
@@ -1584,12 +1566,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime)
netbuffer->u.serverinfo.time = (tic_t)LONG(servertime);
netbuffer->u.serverinfo.leveltime = (tic_t)LONG(leveltime);
// force 1 player
if (UseFakeSeed())
netbuffer->u.serverinfo.numberofplayer = (UINT8)1;
else
netbuffer->u.serverinfo.numberofplayer = (UINT8)D_NumPlayers();
netbuffer->u.serverinfo.numberofplayer = (UINT8)D_NumPlayers();
netbuffer->u.serverinfo.maxplayer = (UINT8)(min((dedicated ? MAXPLAYERS-1 : MAXPLAYERS), cv_maxplayers.value));
// SRB2Kart: Vanilla's gametype constants for MS support
@@ -1668,37 +1645,6 @@ static void SV_SendPlayerInfo(INT32 node)
netbuffer->packettype = PT_PLAYERINFO;
// send a fake player to trick ms and serverbrowser
if (UseFakeSeed())
{
//printf("sending fake player lmao\n");
netbuffer->u.playerinfo[0].node = 0;
// fallback to smth, make sure this is always set
if (!cv_fakeseedname.string[0])
CV_Set(&cv_fakeseedname, "Player 1");
strlcpy(netbuffer->u.playerinfo[0].name, cv_fakeseedname.string, MAXPLAYERNAME+1);
memset(netbuffer->u.playerinfo[0].address, 0, 4);
// make it appear as spectator
netbuffer->u.playerinfo[0].team = 255;
// doesent really matter what we put here lel
netbuffer->u.playerinfo[0].score = LONG(42069);
netbuffer->u.playerinfo[0].timeinserver = SHORT(42069);
netbuffer->u.playerinfo[0].skin = (UINT8)1; // no clue wtf skin 1 is, tails maybe?
netbuffer->u.playerinfo[0].data = 0;
// mark every other slot as empty
for (i = 1; i < MSCOMPAT_MAXPLAYERS; i++)
netbuffer->u.playerinfo[i].node = 255;
HSendPacket(node, false, 0, sizeof(plrinfo) * MSCOMPAT_MAXPLAYERS);
return;
}
for (i = 0; i < MSCOMPAT_MAXPLAYERS; i++)
{
if ((i >= MAXPLAYERS) || !playeringame[i])
-2
View File
@@ -582,8 +582,6 @@ extern tic_t simulated_lag;
extern tic_t lowest_lag;
extern consvar_t cv_mindelay, cv_gentlemens;
extern consvar_t cv_usefakeseed, cv_fakeseedname;
extern consvar_t
cv_netticbuffer, cv_allownewplayer,
#ifdef SATURNJOIN
-56
View File
@@ -166,57 +166,6 @@ UINT8 ctrldown = 0; // 0x1 left, 0x2 right
UINT8 altdown = 0; // 0x1 left, 0x2 right
boolean capslock = 0; // gee i wonder what this does.
static void D_PadMenuScrollInput(UINT8 input)
{
event_t dpadev;
memset(&dpadev, 0, sizeof(event_t));
dpadev.type = ev_keydown;
switch (input)
{
case DPAD_UP:
dpadev.data1 = KEY_UPARROW;
break;
case DPAD_DOWN:
dpadev.data1 = KEY_DOWNARROW;
break;
case DPAD_LEFT:
dpadev.data1 = KEY_LEFTARROW;
break;
case DPAD_RIGHT:
dpadev.data1 = KEY_RIGHTARROW;
break;
}
D_PostEvent(&dpadev); // put into eventlist
}
#define SCROLLDELAY 19
// Check if any dpad button is held
// and pass it to the eventlist
static void D_GamePadMenuScrollTicker(void)
{
UINT8 i;
static UINT8 menuInputDelayTimer = 0;
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
if (dpadscrollstate[i])
{
if (menuInputDelayTimer < SCROLLDELAY)
menuInputDelayTimer++;
else if (menuInputDelayTimer == SCROLLDELAY)
D_PadMenuScrollInput(i);
return;
}
}
menuInputDelayTimer = 0;
}
#undef SCROLLDELAY
static UINT16 curcolor[MAXSPLITSCREENPLAYERS] = {};
static void D_DeviceLEDTick(void)
@@ -844,11 +793,6 @@ void D_SRB2Loop(void)
if (!dedicated)
{
if (menuactive)
{
D_GamePadMenuScrollTicker();
}
D_DeviceLEDTick();
}
}
-3
View File
@@ -760,9 +760,6 @@ void D_RegisterServerCommands(void)
CV_RegisterVar(&cv_showping);
CV_RegisterVar(&cv_pingmeasurement);
CV_RegisterVar(&cv_usefakeseed);
CV_RegisterVar(&cv_fakeseedname);
#ifdef SEENAMES
CV_RegisterVar(&cv_allowseenames);
#endif
-3
View File
@@ -262,9 +262,6 @@ void G_ResetControls(void)
memset(joyxmove, 0, sizeof(joyxmove));
memset(joyymove, 0, sizeof(joyymove));
// reset those just in case the game missed the keyup event
memset(dpadscrollstate, false, sizeof(dpadscrollstate));
}
//
+1 -1
View File
@@ -37,7 +37,7 @@ typedef enum
KEY_JOY1 = KEY_MOUSE1 + MOUSEBUTTONS,
KEY_HAT1 = KEY_JOY1 + JOYBUTTONS,
KEY_DBLMOUSE1 =KEY_HAT1 + JOYHATS*4, // double clicks
KEY_DBLMOUSE1 = KEY_HAT1 + JOYHATS*4, // double clicks
KEY_DBLJOY1 = KEY_DBLMOUSE1 + MOUSEBUTTONS,
KEY_DBLHAT1 = KEY_DBLJOY1 + JOYBUTTONS,
-4
View File
@@ -221,10 +221,6 @@ INT32 I_mkdir(const char *dirname, INT32 unixright);
*/
const char *I_LocateWad(void);
/** \brief Joystick events
*/
void I_GetJoystickEvents(UINT8 index);
char *I_GetEnv(const char *name);
INT32 I_PutEnv(char *variable);
+2
View File
@@ -143,6 +143,8 @@ boolean I_CheckNativeRes(void);
void I_SetBorderlessWindow(void);
void I_HandleControllerHatRepeat(void);
#ifdef USE_FBO_OGL
void RefreshOGLSDLSurface(void);
+3 -24
View File
@@ -759,8 +759,6 @@ static void Command_Manual_f(void)
itemOn = 0;
}
boolean dpadscrollstate[4] = {false, false, false, false};
//
// M_Responder
//
@@ -807,19 +805,15 @@ boolean M_Responder(event_t *ev)
break;
case KEY_HAT1:
ch = KEY_UPARROW;
dpadscrollstate[DPAD_UP] = true;
break;
case KEY_HAT1 + 1:
ch = KEY_DOWNARROW;
dpadscrollstate[DPAD_DOWN] = true;
break;
case KEY_HAT1 + 2:
ch = KEY_LEFTARROW;
dpadscrollstate[DPAD_LEFT] = true;
break;
case KEY_HAT1 + 3:
ch = KEY_RIGHTARROW;
dpadscrollstate[DPAD_RIGHT] = true;
break;
}
@@ -835,24 +829,6 @@ boolean M_Responder(event_t *ev)
}
}
}
else if (ev->type == ev_keyup)
{
switch (ev->data1) // if you let go of those set those to false
{
case KEY_HAT1:
dpadscrollstate[DPAD_UP] = false;
break;
case KEY_HAT1 + 1:
dpadscrollstate[DPAD_DOWN] = false;
break;
case KEY_HAT1 + 2:
dpadscrollstate[DPAD_LEFT] = false;
break;
case KEY_HAT1 + 3:
dpadscrollstate[DPAD_RIGHT] = false;
break;
}
}
else if (menuactive)
{
tic_t thistime = I_GetTime();
@@ -1731,6 +1707,9 @@ void M_Ticker(void)
if (dedicated)
return;
if (menuactive)
I_HandleControllerHatRepeat();
if (--skullAnimCounter <= 0)
skullAnimCounter = 8;
-10
View File
@@ -38,16 +38,6 @@ extern boolean forceshowhud;
// Does all the real work of the menu interaction.
boolean M_Responder(event_t *ev);
// for scrolling through menus with controllers
extern boolean dpadscrollstate[4];
enum
{
DPAD_UP,
DPAD_DOWN,
DPAD_LEFT,
DPAD_RIGHT
};
// Called by main loop, runs for demo playback. If this returns true, nullify any further user input.
boolean M_DemoResponder(event_t *ev);
+1 -8
View File
@@ -608,17 +608,10 @@ Update_parameters (void)
}
#endif/*MASTERSERVER*/
}
#ifdef MASTERSERVER
void Update_MS(void)
{
Update_parameters();
}
#endif
#ifdef MASTERSERVER
static void MasterServer_OnChange(void)
{
UnregisterServer();
Set_api(cv_masterserver.string);
-2
View File
@@ -88,8 +88,6 @@ char *GetMODVersion(int id);
#endif
char *GetMasterServerRules(void);
void Update_MS(void);
#endif
void AddMServCommands(void);
+1 -1
View File
@@ -1832,7 +1832,7 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32
}
}
void S_ChangeMusicSpecial (const char *mmusic)
void S_ChangeMusicSpecial(const char *mmusic)
{
if (cv_resetspecialmusic.value)
S_ChangeMusic(mmusic, MUSIC_FORCERESET, true);
+32 -63
View File
@@ -719,16 +719,13 @@ static void JoyReset(SDLJoyInfo_t *JoySet)
{
SDL_GameControllerClose(JoySet->dev);
}
JoySet->dev = NULL;
JoySet->oldjoy = -1;
JoySet->id = -1;
JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0;
//JoySet->scale
}
/** \brief joystick up and running
*/
static INT32 joystick_started[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0};
/** \brief SDL info about joystick
*/
SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS];
@@ -783,22 +780,26 @@ void I_UpdateJoystickDeviceIndex(UINT8 player)
///////////////////////////////////////////////
if (JoyInfo[player].dev)
{
cv_usejoystick[player].value = I_GetJoystickDeviceIndex(JoyInfo[player].dev) + 1;
cv_usejoystick[player].value = JoyInfo[player].id + 1;
}
else
{
UINT8 joystickID, compareJoystick;
for (joystickID = 0; joystickID < MAXSPLITSCREENPLAYERS; joystickID++)
{
// is this cv_usejoystick used?
const INT32 value = atoi(cv_usejoystick[joystickID].string);
for (compareJoystick = 0; compareJoystick < MAXSPLITSCREENPLAYERS; compareJoystick++)
{
if (compareJoystick == player)
continue;
if (value == JoyInfo[compareJoystick].oldjoy || value == cv_usejoystick[compareJoystick].value)
break;
}
if (compareJoystick == MAXSPLITSCREENPLAYERS)
{
// We DID make it through the whole loop, so we can use this one!
@@ -806,6 +807,7 @@ void I_UpdateJoystickDeviceIndex(UINT8 player)
break;
}
}
if (joystickID == MAXSPLITSCREENPLAYERS)
{
// We DID NOT make it through the whole loop, so we can't assign this joystick to anything.
@@ -828,14 +830,6 @@ void I_UpdateJoystickDeviceIndices(UINT8 excludePlayer)
}
}
/** \brief Joystick buttons states
*/
static UINT64 lastjoybuttons[MAXSPLITSCREENPLAYERS] = {0,0,0,0};
/** \brief Joystick hats state
*/
static UINT64 lastjoyhats[MAXSPLITSCREENPLAYERS] = {0,0,0,0};
/** \brief Shuts down joystick
\return void
*/
@@ -847,74 +841,34 @@ void I_ShutdownJoystick(UINT8 index)
event.data2 = 0;
event.data3 = 0;
lastjoybuttons[index] = lastjoyhats[index] = 0;
// emulate the up of all joystick buttons
for (i = 0; i < JOYBUTTONS; i++)
{
event.data1=KEY_JOY1 + i;
event.data1 = KEY_JOY1 + i;
D_PostEvent(&event);
}
// emulate the up of all joystick hats
for (i = 0; i < JOYHATS*4; i++)
{
event.data1=KEY_HAT1+i;
event.data1 = KEY_HAT1+i;
D_PostEvent(&event);
}
// reset joystick position
event.type = ev_joystick;
for (i = 0; i < JOYAXISSET; i++)
{
event.data1 = i;
D_PostEvent(&event);
}
joystick_started[index] = 0;
JoyReset(&JoyInfo[index]);
// don't shut down the subsystem here, because hotplugging
}
void I_GetJoystickEvents(UINT8 index)
{
static event_t event = {};
INT32 i = 0;
UINT64 joyhats = 0;
if (!joystick_started[index])
return;
if (!JoyInfo[index].dev) //I_ShutdownJoystick();
return;
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_UP);
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_DOWN) << 1;
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_LEFT) << 2;
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_RIGHT) << 3;
if (joyhats != lastjoyhats[index])
{
INT64 j = 1; // keep only bits that changed since last time
INT64 newhats = joyhats ^ lastjoyhats[index];
lastjoyhats[index] = 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_HAT1 + i;
D_PostEvent(&event);
}
}
}
}
/** \brief Open joystick handle
\param fname name of joystick
@@ -931,6 +885,7 @@ static int joy_open(int playerIndex, int joyIndex)
CONS_Printf(M_GetText("Joystick subsystem not started\n"));
return -1;
}
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0)
{
CONS_Printf(M_GetText("Game Controller subsystem not started\n"));
@@ -965,12 +920,14 @@ static int joy_open(int playerIndex, int joyIndex)
if (JoyInfo[playerIndex].dev == newdev // same device, nothing to do
|| (newdev == NULL && SDL_GameControllerGetAttached(JoyInfo[playerIndex].dev))) // we failed, but already have a working device
return SDL_CONTROLLER_AXIS_MAX;
// Else, we're changing devices, so send neutral joy events
CONS_Debug(DBG_GAMELOGIC, "Joystick1 device is changing; resetting events...\n");
I_ShutdownJoystick(playerIndex);
}
JoyInfo[playerIndex].dev = newdev;
JoyInfo[playerIndex].id = I_GetJoystickDeviceIndex(JoyInfo[playerIndex].dev);
if (JoyInfo[playerIndex].dev == NULL)
{
@@ -1007,8 +964,9 @@ void I_InitJoystick(UINT8 index)
UINT8 i;
SDL_GameController *newcontroller = NULL;
//I_ShutdownJoystick();
//SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE);
// not sure if this is the best place to put this
SDL_SetHint(SDL_HINT_AUTO_UPDATE_SENSORS, "0");
if (M_CheckParm("-nojoy"))
return;
@@ -1037,6 +995,11 @@ void I_InitJoystick(UINT8 index)
}
}
JoyInfo[index].dev = NULL;
JoyInfo[index].oldjoy = -1;
JoyInfo[index].id = -1;
JoyInfo[index].axises = JoyInfo[index].buttons = JoyInfo[index].hats = JoyInfo[index].balls = 0;
if (cv_usejoystick[index].value)
newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1);
@@ -1049,23 +1012,24 @@ void I_InitJoystick(UINT8 index)
break;
}
JoyInfo[index].id = I_GetJoystickDeviceIndex(JoyInfo[index].dev);
if (newcontroller && i < MAXSPLITSCREENPLAYERS) // don't override an active device
{
cv_usejoystick[index].value = I_GetJoystickDeviceIndex(JoyInfo[index].dev) + 1;
cv_usejoystick[index].value = JoyInfo[index].id + 1;
}
else if (newcontroller && joy_open(index, cv_usejoystick[index].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.
JoyInfo[index].oldjoy = I_GetJoystickDeviceIndex(JoyInfo[index].dev) + 1;
joystick_started[index] = 1;
JoyInfo[index].oldjoy = JoyInfo[index].id + 1;
}
else
{
if (JoyInfo[index].oldjoy)
I_ShutdownJoystick(index);
cv_usejoystick[index].value = 0;
joystick_started[index] = 0;
}
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
@@ -1130,8 +1094,10 @@ static void I_ShutdownInput(void)
INT32 I_NumJoys(void)
{
INT32 numjoy = 0;
if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
numjoy = SDL_NumJoysticks();
return numjoy;
}
@@ -1142,15 +1108,18 @@ 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) == SDL_INIT_JOYSTICK)
{
tempname = SDL_JoystickNameForIndex(joyindex);
if (tempname)
{
memcpy(joyname, tempname, 255);
joyname[255] = '\0';
}
}
return joyname;
}
+135 -56
View File
@@ -558,7 +558,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
{
event_t event;
event_t event = {0};
switch (type)
{
@@ -586,7 +586,9 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
}
if (event.data1)
{
D_PostEvent(&event);
}
}
static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
@@ -638,7 +640,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)
{
event_t event;
event_t event = {0};
// Ignore the event if the mouse is not actually focused on the window.
// This can happen if you used the mouse to restore keyboard focus;
@@ -651,8 +653,6 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)
/// \todo inputEvent.button.which
if (USE_MOUSEINPUT)
{
SDL_memset(&event, 0, sizeof(event_t));
switch (type)
{
case SDL_MOUSEBUTTONUP:
@@ -693,27 +693,28 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)
static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt)
{
event_t event;
event_t event = {0};
if (USE_MOUSEINPUT)
{
SDL_memset(&event, 0, sizeof(event_t));
if (evt.y > 0)
{
event.data1 = KEY_MOUSEWHEELUP;
event.type = ev_keydown;
}
if (evt.y < 0)
{
event.data1 = KEY_MOUSEWHEELDOWN;
event.type = ev_keydown;
}
if (evt.y == 0)
{
event.data1 = 0;
event.type = ev_keyup;
}
if (event.type == ev_keyup || event.type == ev_keydown)
{
D_PostEvent(&event);
@@ -721,40 +722,78 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt)
}
}
static UINT8 hatrepeattimer[MAXSPLITSCREENPLAYERS];
#define HATREPEATDELAY 19
void I_HandleControllerHatRepeat(void)
{
// why bother if theres no controllers?
if (numcontrollers == 0)
return;
event_t event = {ev_keydown, 0, 0, 0};
static const SDL_GameControllerButton hatbutt[4] =
{
SDL_CONTROLLER_BUTTON_DPAD_UP,
SDL_CONTROLLER_BUTTON_DPAD_DOWN,
SDL_CONTROLLER_BUTTON_DPAD_LEFT,
SDL_CONTROLLER_BUTTON_DPAD_RIGHT
};
for (int i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
if (!cv_usejoystick[i].value)
continue;
SDL_GameController *controller = JoyInfo[i].dev;
if (!controller)
continue;
for (UINT8 h = 0; h < JOYHATS; h++)
{
if (SDL_GameControllerGetButton(controller, hatbutt[h]))
{
if (hatrepeattimer[i] < HATREPEATDELAY)
{
hatrepeattimer[i]++;
}
else if (hatrepeattimer[i] == HATREPEATDELAY)
{
event.data1 = KEY_HAT1 + (i * JOYHATS) + h;
D_PostEvent(&event);
}
return;
}
}
hatrepeattimer[i] = 0;
}
}
static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt)
{
event_t event;
SDL_JoystickID joyid[4];
INT32 value;
UINT8 i;
// Determine the Joystick IDs for each current open joystick
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
joyid[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev));
if (evt.which == JoyInfo[i].id)
{
event.type = ev_joystick + i;
break;
}
}
if (i == MAXSPLITSCREENPLAYERS)
return;
event.data1 = event.data2 = event.data3 = INT32_MAX;
if (evt.which == joyid[0])
{
event.type = ev_joystick;
}
else if (evt.which == joyid[1])
{
event.type = ev_joystick2;
}
else if (evt.which == joyid[2])
{
event.type = ev_joystick3;
}
else if (evt.which == joyid[3])
{
event.type = ev_joystick4;
}
else
return;
//axis
if (evt.axis > JOYAXISSET*2)
return;
@@ -790,47 +829,89 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt)
default:
return;
}
D_PostEvent(&event);
}
static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint32 type)
static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 type)
{
event_t event;
SDL_JoystickID joyid[4];
event_t event = {0};
UINT8 i;
static const int hat_buttons_base[] = {KEY_HAT1, KEY_2HAT1, KEY_3HAT1, KEY_4HAT1};
// Determine the Joystick IDs for each current open joystick
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
joyid[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev));
if (evt.which == JoyInfo[i].id)
{
event.data1 = hat_buttons_base[i];
break;
}
}
if ( evt.button == SDL_CONTROLLER_BUTTON_DPAD_UP
|| evt.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN
|| evt.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT
|| evt.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
if (i == MAXSPLITSCREENPLAYERS)
return;
switch (type)
{
// dpad buttons are mapped as the hat instead
case SDL_CONTROLLERBUTTONUP:
event.type = ev_keyup;
break;
case SDL_CONTROLLERBUTTONDOWN:
event.type = ev_keydown;
break;
default:
return;
}
switch (evt.button)
{
case SDL_CONTROLLER_BUTTON_DPAD_UP:
break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
event.data1 += 1;
break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
event.data1 += 2;
break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
event.data1 += 3;
break;
default:
return;
}
if (event.type != ev_console)
{
D_PostEvent(&event);
}
}
static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint32 type)
{
event_t event = {0};
UINT8 i;
static const int buttons_base[] = {KEY_JOY1, KEY_2JOY1, KEY_3JOY1, KEY_4JOY1};
// dpad special case handling
if (evt.button >= SDL_CONTROLLER_BUTTON_DPAD_UP &&
evt.button <= SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
{
Impl_HandleControllerHatEvent(evt, type);
return;
}
if (evt.which == joyid[0])
// Determine the Joystick IDs for each current open joystick
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
event.data1 = KEY_JOY1;
if (evt.which == JoyInfo[i].id)
{
event.data1 = buttons_base[i];
break;
}
}
else if (evt.which == joyid[1])
{
event.data1 = KEY_2JOY1;
}
else if (evt.which == joyid[2])
{
event.data1 = KEY_3JOY1;
}
else if (evt.which == joyid[3])
{
event.data1 = KEY_4JOY1;
}
else
if (i == MAXSPLITSCREENPLAYERS)
return;
switch (type)
@@ -853,7 +934,9 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint
return;
if (event.type != ev_console)
{
D_PostEvent(&event);
}
}
static void Impl_HandleControllerAddedEvent(SDL_Event evt)
@@ -1097,7 +1180,6 @@ void I_StartupMouse(void)
void I_OsPolling(void)
{
SDL_Keymod mod;
INT32 i;
if (consolevent)
I_GetConsoleEvents();
@@ -1105,9 +1187,6 @@ void I_OsPolling(void)
if (SDL_WasInit(SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER))
{
SDL_GameControllerUpdate();
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
I_GetJoystickEvents(i);
}
I_GetEvent();
+1 -1
View File
@@ -73,7 +73,7 @@ write netcode into the sound code, OKAY?
//static UINT16 BUFFERSIZE = 2048;
static UINT16 SAMPLERATE = 44100;
static const UINT16 SAMPLERATE = 44100;
#ifdef HAVE_OPENMPT
#include "libopenmpt/libopenmpt.h"
+2
View File
@@ -42,6 +42,8 @@ typedef struct SDLJoyInfo_s
{
/// Controller handle
SDL_GameController *dev;
/// Controller index
INT32 id;
/// number of old joystick
int oldjoy;
/// number of axies