From 333c94be52004c96b7de76521178b27374a18721 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 23 Oct 2025 10:55:46 +0200 Subject: [PATCH 01/17] 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 --- src/g_input.h | 2 +- src/i_system.h | 4 -- src/s_sound.c | 2 +- src/sdl/i_system.cpp | 74 +++++------------------ src/sdl/i_video.c | 136 ++++++++++++++++++++++++++---------------- src/sdl/mixer_sound.c | 2 +- 6 files changed, 102 insertions(+), 118 deletions(-) diff --git a/src/g_input.h b/src/g_input.h index ec4a9d795..c430fe7bc 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -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, diff --git a/src/i_system.h b/src/i_system.h index f5187e037..b3dedd396 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -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); diff --git a/src/s_sound.c b/src/s_sound.c index 1bac40a46..5338b4e7e 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1813,7 +1813,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); diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 4e9e54d72..8f720cfa1 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -719,16 +719,12 @@ static void JoyReset(SDLJoyInfo_t *JoySet) { SDL_GameControllerClose(JoySet->dev); } + JoySet->dev = NULL; JoySet->oldjoy = -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]; @@ -788,10 +784,12 @@ void I_UpdateJoystickDeviceIndex(UINT8 player) 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) @@ -799,6 +797,7 @@ void I_UpdateJoystickDeviceIndex(UINT8 player) 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 +805,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 +828,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 +839,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 +883,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,6 +918,7 @@ 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); @@ -1058,14 +1012,13 @@ void I_InitJoystick(UINT8 index) // 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; } 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 +1083,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 +1097,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; } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9ce860cb4..6a8145b0a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -699,16 +699,19 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) 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); @@ -719,37 +722,24 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) 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 == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + { + 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; @@ -785,47 +775,89 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) default: return; } + D_PostEvent(&event); } +static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 type) +{ + event_t event; + 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++) + { + if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + { + event.data1 = hat_buttons_base[i]; + break; + } + } + + if (i == MAXSPLITSCREENPLAYERS) + return; + + switch (type) + { + 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; - SDL_JoystickID joyid[4]; 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; + } // 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 == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + { + event.data1 = 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) - { - // dpad buttons are mapped as the hat instead - return; - } - - if (evt.which == joyid[0]) - { - event.data1 = KEY_JOY1; - } - 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) @@ -848,7 +880,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) @@ -1091,7 +1125,6 @@ void I_StartupMouse(void) void I_OsPolling(void) { SDL_Keymod mod; - INT32 i; if (consolevent) I_GetConsoleEvents(); @@ -1099,9 +1132,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(); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 646d44135..59cffed4a 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -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.54.0 From a4cc8b05853abee1ce329f191ff0f289fa14b242 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 23 Oct 2025 11:12:13 +0200 Subject: [PATCH 02/17] keep track of joystick instance index means we dont constantly need to refetch it needs testing on windoze --- src/sdl/i_system.cpp | 11 ++++++++--- src/sdl/i_video.c | 6 +++--- src/sdl/sdlmain.h | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 8f720cfa1..dd197cd1b 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -721,6 +721,7 @@ static void JoyReset(SDLJoyInfo_t *JoySet) } JoySet->dev = NULL; + JoySet->id = -1; JoySet->oldjoy = -1; JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0; } @@ -779,7 +780,7 @@ 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 { @@ -794,6 +795,7 @@ void I_UpdateJoystickDeviceIndex(UINT8 player) { if (compareJoystick == player) continue; + if (value == JoyInfo[compareJoystick].oldjoy || value == cv_usejoystick[compareJoystick].value) break; } @@ -925,6 +927,7 @@ static int joy_open(int playerIndex, int joyIndex) } JoyInfo[playerIndex].dev = newdev; + JoyInfo[playerIndex].id = I_GetJoystickDeviceIndex(JoyInfo[playerIndex].dev); if (JoyInfo[playerIndex].dev == NULL) { @@ -1003,15 +1006,17 @@ 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; + JoyInfo[index].oldjoy = JoyInfo[index].id + 1; } else { diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6a8145b0a..6b2cbec7b 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -728,7 +728,7 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + if (evt.which == JoyInfo[i].id) { event.type = ev_joystick + i; break; @@ -788,7 +788,7 @@ static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + if (evt.which == JoyInfo[i].id) { event.data1 = hat_buttons_base[i]; break; @@ -850,7 +850,7 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + if (evt.which == JoyInfo[i].id) { event.data1 = buttons_base[i]; break; diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 2caafc729..0fe93953a 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -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 -- 2.54.0 From 736a626ccf7b36f6216954ec92b793200cc66b73 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 23 Oct 2025 11:16:07 +0200 Subject: [PATCH 03/17] init joyinfo in I_InitJoystick --- src/sdl/i_system.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index dd197cd1b..4716fe97c 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -721,8 +721,8 @@ static void JoyReset(SDLJoyInfo_t *JoySet) } JoySet->dev = NULL; - JoySet->id = -1; JoySet->oldjoy = -1; + JoySet->id = -1; JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0; } @@ -994,6 +994,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); -- 2.54.0 From 1d3dae01e90327da79aad1973d8ded510a30149e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 23 Oct 2025 11:22:37 +0200 Subject: [PATCH 04/17] set SDL_HINT_AUTO_UPDATE_SENSORS hint to 0 we dont need any of that so disable it --- src/sdl/i_system.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 4716fe97c..2721e2e96 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -964,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; -- 2.54.0 From fcae07262510f9c04f8ba70a9ff8d3da75a18ab2 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Oct 2025 18:17:17 +0200 Subject: [PATCH 05/17] 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 --- src/d_main.c | 56 ----------------------------------------------- src/g_input.c | 3 --- src/i_video.h | 2 ++ src/m_menu.c | 27 +++-------------------- src/m_menu.h | 10 --------- src/sdl/i_video.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 93 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 1bc346deb..5b86be281 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -164,57 +164,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] = {0}; static void D_DeviceLEDTick(void) @@ -839,11 +788,6 @@ void D_SRB2Loop(void) if (!dedicated) { - if (menuactive) - { - D_GamePadMenuScrollTicker(); - } - D_DeviceLEDTick(); } } diff --git a/src/g_input.c b/src/g_input.c index e8bc8223e..89d887375 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -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)); } // diff --git a/src/i_video.h b/src/i_video.h index 852645c30..ad29983fa 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -143,6 +143,8 @@ boolean I_CheckNativeRes(void); void I_SetBorderlessWindow(void); +void I_HandleControllerHatRepeat(void); + #ifdef USE_FBO_OGL void RefreshOGLSDLSurface(void); diff --git a/src/m_menu.c b/src/m_menu.c index a7be33c42..3c95030d8 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -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; diff --git a/src/m_menu.h b/src/m_menu.h index de4f3b983..22b768385 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -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); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6b2cbec7b..9152fd8b8 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -581,7 +581,9 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) } if (event.data1) + { D_PostEvent(&event); + } } static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) @@ -719,6 +721,57 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) } } +static Uint32 hatrepeattimer[MAXSPLITSCREENPLAYERS]; +#define HATREPEATDELAY 19 + +void I_HandleControllerHatRepeat(void) +{ + static event_t event = {ev_keydown, 0, 0, 0}; + + // why bother if theres no controllers? + if (numcontrollers == 0) + return; + + 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; -- 2.54.0 From cdb7b6fedef3a4b99872bffec68167818c7efedb Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Oct 2025 18:17:59 +0200 Subject: [PATCH 06/17] initialize input events to something --- src/sdl/i_video.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9152fd8b8..abf82b4f3 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -553,7 +553,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) { @@ -635,7 +635,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; @@ -690,7 +690,7 @@ 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) { @@ -726,12 +726,12 @@ static Uint32 hatrepeattimer[MAXSPLITSCREENPLAYERS]; void I_HandleControllerHatRepeat(void) { - static event_t event = {ev_keydown, 0, 0, 0}; - // 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, @@ -834,7 +834,7 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 type) { - event_t event; + event_t event = {0}; UINT8 i; static const int hat_buttons_base[] = {KEY_HAT1, KEY_2HAT1, KEY_3HAT1, KEY_4HAT1}; @@ -888,7 +888,7 @@ static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint32 type) { - event_t event; + event_t event = {0}; UINT8 i; static const int buttons_base[] = {KEY_JOY1, KEY_2JOY1, KEY_3JOY1, KEY_4JOY1}; -- 2.54.0 From 8ccf4eb9ba6ee0edf0e515e34311e94eb18e9aca Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Oct 2025 18:27:30 +0200 Subject: [PATCH 07/17] this can be alot smoler --- src/sdl/i_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index abf82b4f3..9993a2134 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -721,7 +721,7 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) } } -static Uint32 hatrepeattimer[MAXSPLITSCREENPLAYERS]; +static UINT8 hatrepeattimer[MAXSPLITSCREENPLAYERS]; #define HATREPEATDELAY 19 void I_HandleControllerHatRepeat(void) -- 2.54.0 From d4a130f1dc73f3dc99711262ab3afdafaf2fec95 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Oct 2025 18:28:57 +0200 Subject: [PATCH 08/17] remove those memsets not needed anymore now --- src/sdl/i_video.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9993a2134..d2604277c 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -648,8 +648,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: @@ -694,8 +692,6 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) if (USE_MOUSEINPUT) { - SDL_memset(&event, 0, sizeof(event_t)); - if (evt.y > 0) { event.data1 = KEY_MOUSEWHEELUP; -- 2.54.0 From c080fc873247280c5c677f5381ae677abe2d320c Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 11 Nov 2025 22:39:13 +0100 Subject: [PATCH 09/17] GL_UpdateTexture: fix small oversight from when i refactored it GL_TEXFMT_AP_88 needs to increment the image data ptr even if chromakeyed --- src/hardware/r_opengl/r_opengl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 566d2458c..cb7eca43c 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2004,7 +2004,7 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) { if (chromakeyed && (*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX)) { - tex[idx].s = (byteColor_t){0, 0, 0, 0}; + memset(&tex[idx].s, 0, sizeof(byteColor_t)); pTexInfo->flags |= TF_TRANSPARENT; // there is a hole in it } else @@ -2016,10 +2016,9 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) if (texinfoformat != GL_TEXFMT_AP_88) continue; - if (chromakeyed) - continue; - tex[idx].s.alpha = *pImgData; + if (!chromakeyed) + tex[idx].s.alpha = *pImgData; pImgData++; } } @@ -2054,9 +2053,9 @@ void GL_UpdateTexture(GLMipmap_t *pTexInfo) { for (i = 0; i < w; i++, idx++) { - tex[idx].s.red = *pImgData; - tex[idx].s.green = *pImgData; - tex[idx].s.blue = *pImgData; + tex[idx].s.red = + tex[idx].s.green = + tex[idx].s.blue = *pImgData; pImgData++; tex[idx].s.alpha = *pImgData; pImgData++; @@ -3187,7 +3186,8 @@ void GL_SetTransform(FTransform *stransform) { float dy = stransform->viewaiming * 2; - if (stransform->fliptype == TRANSFORM_FLIP || stransform->fliptype == TRANSFORM_MIRRORFLIP) + if (stransform->fliptype == TRANSFORM_FLIP + || stransform->fliptype == TRANSFORM_MIRRORFLIP) dy *= -1.0f; pglTranslatef(0.0f, -dy/BASEVIDHEIGHT, 0.0f); -- 2.54.0 From c58e54544d1dc5cade58dc8d4c0fedb373d7f0d2 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Nov 2025 16:49:44 +0100 Subject: [PATCH 10/17] initialize all remaining globals well atleast all i can find lel --- src/command.c | 2 +- src/console.c | 8 +++--- src/dehacked.c | 6 ++--- src/f_finale.c | 2 +- src/filesrch.c | 10 ++++---- src/hardware/r_opengl/r_opengl.c | 11 ++++---- src/hu_stuff.c | 44 ++++++++++++++++---------------- src/lua_script.c | 2 +- src/m_argv.c | 4 +-- src/m_cond.c | 4 +-- src/m_menu.c | 13 +++------- src/m_menu.h | 3 --- src/mserv.c | 4 +-- src/p_ceilng.c | 3 --- src/p_local.h | 2 -- src/p_polyobj.c | 10 ++++---- src/p_slopes.c | 3 +-- src/sdl/i_main.c | 2 +- src/sdl/i_system.cpp | 2 +- src/sdl/i_video.c | 6 ++--- src/sounds.c | 2 +- src/st_stuff.c | 18 ++++++------- src/w_wad.c | 2 +- 23 files changed, 75 insertions(+), 88 deletions(-) diff --git a/src/command.c b/src/command.c index 459938aa8..d12ae5d49 100644 --- a/src/command.c +++ b/src/command.c @@ -277,7 +277,7 @@ static xcommand_t *com_commands = NULL; // current commands #define MAX_ARGS 80 static size_t com_argc; -char *com_argv[MAX_ARGS]; +char *com_argv[MAX_ARGS] = {}; static const char *com_null_string = ""; static char *com_args = NULL; // current command args or NULL diff --git a/src/console.c b/src/console.c index 3172b9f20..2757b22e7 100644 --- a/src/console.c +++ b/src/console.c @@ -58,7 +58,7 @@ I_mutex con_mutex; static boolean con_started = false; // console has been initialised boolean con_startup = false; // true at game startup, screen need refreshing static boolean con_forcepic = true; // at startup toggle console translucency when first off - boolean con_recalc; // set true when screen size has changed + boolean con_recalc = false; // set true when screen size has changed static tic_t con_tick; // console ticker for anim or blinking prompt cursor // con_scrollup should use time (currenttime - lasttime).. @@ -66,8 +66,8 @@ static tic_t con_tick; // console ticker for anim or blinking prompt cursor static boolean consoletoggle; // true when console key pushed, ticker will handle static boolean consoleready; // console prompt is ready - INT32 con_destlines; // vid lines used by console at final position -static INT32 con_curlines; // vid lines currently used by console + INT32 con_destlines = 0; // vid lines used by console at final position +static INT32 con_curlines; // vid lines currently used by console static UINT8 con_hudlines; // number of console heads up message lines static UINT32 con_hudtime[MAXHUDLINES]; // remaining time of display for hud msg lines @@ -83,7 +83,7 @@ static size_t con_totallines; // lines of console text into the console buf static size_t con_width; // columns of chars, depend on vid mode width static size_t con_scrollup; // how many rows of text to scroll up (pgup/pgdn) -UINT32 con_scalefactor; // text size scale factor +UINT32 con_scalefactor = 0; // text size scale factor // hold 32 last lines of input for history #define CON_MAXPROMPTCHARS 256 diff --git a/src/dehacked.c b/src/dehacked.c index 1e2fd5798..a3540fdff 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -47,9 +47,9 @@ // Free slot names // The crazy word-reading stuff uses these. -char *FREE_STATES[NUMSTATEFREESLOTS]; -char *FREE_MOBJS[NUMMOBJFREESLOTS]; -UINT8 used_spr[(NUMSPRITEFREESLOTS / 8) + 1]; // Bitwise flag for sprite freeslot in use! I would use ceil() here if I could, but it only saves 1 byte of memory anyway. +char *FREE_STATES[NUMSTATEFREESLOTS] = {}; +char *FREE_MOBJS[NUMMOBJFREESLOTS] = {}; +UINT8 used_spr[(NUMSPRITEFREESLOTS / 8) + 1] = {}; // Bitwise flag for sprite freeslot in use! I would use ceil() here if I could, but it only saves 1 byte of memory anyway. #define initfreeslots() {\ memset(FREE_STATES,0,sizeof(char *) * NUMSTATEFREESLOTS);\ diff --git a/src/f_finale.c b/src/f_finale.c index ca22349a0..450910021 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -208,7 +208,7 @@ static void F_SkyScroll(INT32 scrollspeed) INT32 intro_scenenum = 0; INT32 intro_curtime = 0; -const char *introtext[NUMINTROSCENES]; +const char *introtext[NUMINTROSCENES] = {}; static tic_t introscenetime[NUMINTROSCENES] = { diff --git a/src/filesrch.c b/src/filesrch.c index eb68222e2..c0940b2eb 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -44,16 +44,16 @@ consvar_t cv_addons_search_case = {"addons_search_case", "No", CV_SAVE, CV_YesNo static CV_PossibleValue_t addons_search_type_cons_t[] = {{0, "Start"}, {1, "Anywhere"}, {0, NULL}}; consvar_t cv_addons_search_type = {"addons_search_type", "Anywhere", CV_SAVE, addons_search_type_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -char menupath[MAXFILEPATH]; -size_t menupathindex[menudepth]; +char menupath[MAXFILEPATH] = {}; +size_t menupathindex[menudepth] = {}; size_t menudepthleft = menudepth; char menusearchbuf[MAXSTRINGLENGTH+1]; textinput_t menusearch; -char **dirmenu, **coredirmenu; // core only local for this file -size_t sizedirmenu, sizecoredirmenu; // ditto -size_t dir_on[menudepth]; +char **dirmenu = NULL, **coredirmenu = NULL; // core only local for this file +size_t sizedirmenu = 0, sizecoredirmenu = 0; // ditto +size_t dir_on[menudepth] = {}; UINT8 refreshdirmenu = 0; char *refreshdirname = NULL; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index cb7eca43c..80697eb8c 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -25,7 +25,7 @@ // Eeeeh not sure is this right way, but it works < sry :c < sry again it had to go :c -#if defined (HWRENDER) && !defined (NOROPENGL) +#if defined (HWRENDER) #include "../../r_fps.h" // For R_GetTimeFrac, used for the leveltime shader uniform @@ -101,7 +101,7 @@ static LTListItem *LightTablesHead = NULL; static RGBA_t screenPalette[256] = {0}; // the palette for the postprocessing step in palette rendering static GLuint screenPaletteTex = 0; // 1D texture containing the screen palette static GLuint paletteLookupTex = 0; // 3D texture containing RGB -> palette index lookup table -RGBA_t myPaletteData[256]; // the palette for converting textures to RGBA +RGBA_t myPaletteData[256] = {0}; // the palette for converting textures to RGBA static GLint gltexformat = GL_RGB5_A1; GLint screen_width = 0; // used by Draw2DLine() @@ -128,7 +128,7 @@ int majorGL = 0, minorGL = 0; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) static GLfloat modelMatrix[16]; -GLfloat projMatrix[16]; +GLfloat projMatrix[16] = {0}; static GLint viewport[4]; #ifdef USE_FBO_OGL @@ -216,7 +216,7 @@ static const GLfloat byte2float[256] = { // -----------------+ #ifdef DEBUG_TO_FILE -FILE *gllogstream; +FILE *gllogstream = NULL; #endif FUNCPRINTF void GL_DBG_Printf(const char *format, ...) @@ -1138,7 +1138,6 @@ static void GL_Perspective(GLfloat fovy, GLfloat aspect) { 0.0f, 0.0f, 0.0f, 0.0f}, }; - const GLfloat focallength = (GLfloat)(1.0f / (GLfloat)tan(fovy * (GLfloat)M_PIl / 360.0f)); const GLfloat deltaZ = FAR_CLIPPING_PLANE - NEAR_CLIPPING_PLANE; if ((fabsf((float)deltaZ) < 1.0E-36f) || fpclassify(aspect) == FP_ZERO) @@ -1146,6 +1145,8 @@ static void GL_Perspective(GLfloat fovy, GLfloat aspect) return; } + const GLfloat focallength = (GLfloat)(1.0f / (GLfloat)tan(fovy * (GLfloat)M_PIl / 360.0f)); + m[0][0] = focallength / aspect; m[1][1] = focallength; m[2][2] = -(FAR_CLIPPING_PLANE + NEAR_CLIPPING_PLANE) / deltaZ; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 955bebb2f..8819d63b4 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -68,32 +68,32 @@ //------------------------------------------- // heads up font //------------------------------------------- -patch_t *hu_font[HU_FONTSIZE]; -patch_t *kart_font[KART_FONTSIZE]; // SRB2kart -patch_t *tny_font[HU_FONTSIZE]; -patch_t *tallnum[10]; // 0-9 +patch_t *hu_font[HU_FONTSIZE] = {}; +patch_t *kart_font[KART_FONTSIZE] = {}; // SRB2kart +patch_t *tny_font[HU_FONTSIZE] = {}; +patch_t *tallnum[10] = {}; // 0-9 // Level title and credits fonts -patch_t *lt_font[LT_FONTSIZE]; -patch_t *cred_font[CRED_FONTSIZE]; +patch_t *lt_font[LT_FONTSIZE] = {}; +patch_t *cred_font[CRED_FONTSIZE] = {}; // ping font // Note: I'd like to adress that at this point we might *REALLY* want to work towards a common drawString function that can take any font we want because this is really turning into a MESS. :V -Lat' -patch_t *pingnum[10]; -patch_t *pinggfx[5]; // small ping graphic -patch_t *pingmeasure[2]; // ping measurement graphic +patch_t *pingnum[10] = {}; +patch_t *pinggfx[5] = {}; // small ping graphic +patch_t *pingmeasure[2] = {}; // ping measurement graphic -patch_t *ranknum[10]; // rank numbers +patch_t *ranknum[10] = {}; // rank numbers -patch_t *framecounter; -patch_t *frameslash; // framerate stuff. Used in screen.c +patch_t *framecounter = NULL; +patch_t *frameslash = NULL; // framerate stuff. Used in screen.c -static player_t *plr; -boolean chat_on; // entering a chat message? +static player_t *plr = NULL; +boolean chat_on = false; // entering a chat message? static char w_chat_buf[HU_MAXMSGLEN + 1]; static textinput_t w_chat; static boolean headsupactive = false; -boolean hu_showscores; // draw rankings +boolean hu_showscores = false; // draw rankings static char hu_tick; static tic_t hu_emoteanim = 0; #define MAXEMOTESUGGESTIONS 8 @@ -101,14 +101,14 @@ static emote_t *emote_suggestions[MAXEMOTESUGGESTIONS] = {0}; static huddrawlist_h luahuddrawlist_scores; -patch_t *rflagico; -patch_t *bflagico; -patch_t *rmatcico; -patch_t *bmatcico; -patch_t *tallminus; +patch_t *rflagico = NULL; +patch_t *bflagico = NULL; +patch_t *rmatcico = NULL; +patch_t *bmatcico = NULL; +patch_t *tallminus = NULL; // song credits -static patch_t *songcreditbg; +static patch_t *songcreditbg = NULL; // ------- // protos. @@ -122,7 +122,7 @@ consvar_t cv_showspecstuff = {"showspecstuff", "No", CV_SAVE, CV_YesNo, NULL, 0, // KEYBOARD LAYOUTS FOR ENTERING TEXT //====================================================================== -char *shiftxform; +char *shiftxform = NULL; char english_shiftxform[] = { diff --git a/src/lua_script.c b/src/lua_script.c index 448d7221d..96ce94a22 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -41,7 +41,7 @@ lua_State *gL = NULL; // Mathlib global state static lua_State *mL = NULL; -int hook_defrosting; +int hook_defrosting = 0; // List of internal libraries to load from SRB2 static lua_CFunction liblist[] = { diff --git a/src/m_argv.c b/src/m_argv.c index b62d390d9..36c73d61c 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -20,11 +20,11 @@ /** \brief number of arg */ -INT32 myargc; +INT32 myargc = 0; /** \brief string table */ -char **myargv; +char **myargv = NULL; /** \brief did we alloc myargv ourselves? */ diff --git a/src/m_cond.c b/src/m_cond.c index f9d871969..acf78e6ef 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -25,10 +25,10 @@ // Map triggers for linedef executors // 32 triggers, one bit each -UINT32 unlocktriggers; +UINT32 unlocktriggers = 0; // The meat of this system lies in condition sets -conditionset_t conditionSets[MAXCONDITIONSETS]; +conditionset_t conditionSets[MAXCONDITIONSETS] = {}; // Default Emblem locations emblem_t emblemlocations[MAXEMBLEMS] = diff --git a/src/m_menu.c b/src/m_menu.c index 09a0c6350..cd5aa04b6 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -145,19 +145,19 @@ I_mutex m_menu_mutex; M_waiting_mode_t m_waiting_mode = M_NOT_WAITING; -const char *quitmsg[NUM_QUITMESSAGES]; +const char *quitmsg[NUM_QUITMESSAGES] = {}; // Stuff for customizing the player select screen Tails 09-22-2003 -description_t description[MAXSKINS]; +description_t description[MAXSKINS] = {}; -INT32 mapwads[NUMMAPS]; +INT32 mapwads[NUMMAPS] = {}; boolean browselocalskins = false; boolean menuactive = false; boolean fromlevelselect = false; -char menu_text_input_buf[MAXSTRINGLENGTH]; +char menu_text_input_buf[MAXSTRINGLENGTH] = {}; static textinput_t menuinput; static INT32 coolalphatimer = 9; @@ -171,7 +171,6 @@ typedef enum } levellist_mode_t; levellist_mode_t levellistmode = LLM_CREATESERVER; -UINT8 maplistoption = 0; static char joystickInfo[8][29]; @@ -181,10 +180,6 @@ static float serverlistslidex; static INT32 serverlistsearched[MAXSERVERLIST] = {0}; static UINT32 serverlistsearchedcount = 0; -//static saveinfo_t savegameinfo[MAXSAVEGAMES]; // Extra info about the save games. - -INT16 startmap; // Mario, NiGHTS, or just a plain old normal game? - static INT16 itemOn = 1; // menu item skull is on, Hack by Tails 09-18-2002 static INT16 skullAnimCounter = 10; // skull animation counter static boolean interpTimerHackAllow = 0; diff --git a/src/m_menu.h b/src/m_menu.h index de4f3b983..8391ef994 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -282,9 +282,6 @@ extern CV_PossibleValue_t gametype_cons_t[]; extern char dummystaffname[22]; -extern INT16 startmap; -extern INT32 ultimate_selectable; - #define MAXSAVEGAMES 31 //note: last save game is "no save" #define NOSAVESLOT MAXSAVEGAMES-1 //slot where Play Without Saving appears diff --git a/src/mserv.c b/src/mserv.c index c7eb50442..4de05216e 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -89,10 +89,10 @@ consvar_t cv_masterserver_nagattempts = {"masterserver_nagattempts", "5", CV_SAV #if defined (MASTERSERVER) && defined (HAVE_THREADS) -int ms_QueryId; +int ms_QueryId = 0; I_mutex ms_QueryId_mutex; -msg_server_t *ms_ServerList; +msg_server_t *ms_ServerList = NULL; I_mutex ms_ServerList_mutex; #endif diff --git a/src/p_ceilng.c b/src/p_ceilng.c index 8170343c9..a00d78008 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -24,9 +24,6 @@ // CEILINGS // ========================================================================== -// the list of ceilings moving currently, including crushers -INT32 ceilmovesound = sfx_None; - /** Moves a moving ceiling. * * \param ceiling Thinker for the ceiling to be moved. diff --git a/src/p_local.h b/src/p_local.h index dc101502f..6977cc4b1 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -474,8 +474,6 @@ void P_DoNightsScore(player_t *player); // #include "p_spec.h" -extern INT32 ceilmovesound; - // Factor to scale scrolling effect into mobj-carrying properties = 3/32. // (This is so scrolling floors and objects on them can move at same speed.) #define CARRYFACTOR (FRACUNIT-ORIG_FRICTION) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 5e5590ced..15090a7ea 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -90,14 +90,14 @@ // // The Polyobjects -polyobj_t *PolyObjects; -INT32 numPolyObjects; +polyobj_t *PolyObjects = NULL; +INT32 numPolyObjects = 0; // Polyobject Blockmap -- initialized in P_LoadBlockMap -polymaplink_t **polyblocklinks; +polymaplink_t **polyblocklinks = NULL; -static size_t *KnownPolySides; -static size_t KnownPolySidesCount; +static size_t *KnownPolySides = NULL; +static size_t KnownPolySidesCount = 0; // // Static Data diff --git a/src/p_slopes.c b/src/p_slopes.c index 850813331..2ec2898b9 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -38,7 +38,6 @@ static void P_UpdateSlopeLightOffset(pslope_t *slope) fixed_t light = FRACUNIT; fixed_t extralight = 0; - if (slope->normal.z == 0) { slope->lightOffset = 0; @@ -296,7 +295,7 @@ static fixed_t P_GetExtent(sector_t *sector, line_t *line) // Find furthest vertex from the reference line. It, along with the two ends // of the line, will define the plane. - for(i = 0; i < sector->linecount; i++) + for (i = 0; i < sector->linecount; i++) { line_t *li = sector->lines[i]; vertex_t tempv; diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index b2ab7777f..cc04dc6a6 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -53,7 +53,7 @@ extern int SDL_main(int argc, char *argv[]); #ifdef LOGMESSAGES FILE *logstream = NULL; -char logfilename[1024]; +char logfilename[1024] = {}; #endif #ifndef DOXYGEN diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 5281a7f01..272379aa8 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -227,7 +227,7 @@ typedef struct char buffer[256]; } feild_t; -feild_t tty_con; +feild_t tty_con = {}; // lock to prevent clearing partial lines, since not everything // printed ends on a newline. diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 787ce1b07..0410dc442 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -151,9 +151,9 @@ static UINT32 localPalette[256]; Uint16 realwidth = BASEVIDWIDTH; Uint16 realheight = BASEVIDHEIGHT; #define HalfWarpMouse(x,y) if (wrapmouseok) SDL_WarpMouseInWindow(window, (Uint16)(x/2),(Uint16)(y/2)) -static SDL_bool exposevideo = SDL_FALSE; -static SDL_bool usesdl2soft = SDL_FALSE; -static SDL_bool borderlesswindow = SDL_FALSE; +static SDL_bool exposevideo = SDL_FALSE; +static SDL_bool usesdl2soft = SDL_FALSE; +static SDL_bool borderlesswindow = SDL_FALSE; // SDL2 vars SDL_Window *window = NULL; diff --git a/src/sounds.c b/src/sounds.c index c1e2f83a7..dbd5478bd 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -972,7 +972,7 @@ sfxinfo_t S_sfx[NUMSFX] = // initialized to NULL }; -char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][7]; +char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][7] = {}; // Prepare free sfx slots to add sfx at run time void S_InitRuntimeSounds (void) diff --git a/src/st_stuff.c b/src/st_stuff.c index a4b3d0465..99188e919 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -61,13 +61,13 @@ tic_t directortoggletimer = 0; // STATUS BAR DATA // -patch_t *facerankprefix[MAXSKINS]; // ranking -patch_t *facewantprefix[MAXSKINS]; // wanted -patch_t *facemmapprefix[MAXSKINS]; // minimap +patch_t *facerankprefix[MAXSKINS] = {}; // ranking +patch_t *facewantprefix[MAXSKINS] = {}; // wanted +patch_t *facemmapprefix[MAXSKINS] = {}; // minimap -patch_t *localfacerankprefix[MAXLOCALSKINS]; // ranking -patch_t *localfacewantprefix[MAXLOCALSKINS]; // wanted -patch_t *localfacemmapprefix[MAXLOCALSKINS]; // minimap +patch_t *localfacerankprefix[MAXLOCALSKINS] = {}; // ranking +patch_t *localfacewantprefix[MAXLOCALSKINS] = {}; // wanted +patch_t *localfacemmapprefix[MAXLOCALSKINS] = {}; // minimap /*char *facerankprefix_name[MAXSKINS]; // ranking char *facewantprefix_name[MAXSKINS]; // wanted @@ -91,8 +91,8 @@ static patch_t *envelope; #endif // current player for overlay drawing -player_t *stplyr; -UINT8 stplyrnum; +player_t *stplyr = NULL; +UINT8 stplyrnum = 0; // SRB2kart @@ -342,7 +342,7 @@ void ST_changeDemoView(void) // STATUS BAR OVERLAY // ========================================================================= -boolean st_overlay; +boolean st_overlay = true; // ========================================================================= // INTERNAL DRAWING diff --git a/src/w_wad.c b/src/w_wad.c index b55d0e98f..640ee0367 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -107,7 +107,7 @@ static const char pat_end[] = {0x50, 0x4b, 0x05, 0x06, 0x00}; // GLOBALS //=========================================================================== UINT16 numwadfiles = 0; // number of active wadfiles -wadfile_t *wadfiles[MAX_WADFILES]; // 0 to numwadfiles-1 are valid +wadfile_t *wadfiles[MAX_WADFILES] = {}; // 0 to numwadfiles-1 are valid // W_Shutdown // Closes all of the WAD files before quitting -- 2.54.0 From b779c9e63d28c228817fda203ed7fb99b82786da Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Nov 2025 19:04:26 +0100 Subject: [PATCH 11/17] ensure byteColor_t is packed make sure it is always sized 4 bytes and not padded at all since that is assumed to be the size --- src/doomtype.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doomtype.h b/src/doomtype.h index 78867ed69..8043b7285 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -293,7 +293,7 @@ typedef struct UINT8 green; UINT8 blue; UINT8 alpha; -} byteColor_t; +} ATTRPACK byteColor_t; union FColorRGBA { -- 2.54.0 From aa985823ba451838206435552203d8c6885c6f23 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Nov 2025 19:20:29 +0100 Subject: [PATCH 12/17] speed up GL_SetPalette "take 2" ensuring bytecolor is packed nd mypalettedata is initialized this seems to now work properly on windows --- src/hardware/r_opengl/r_opengl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 80697eb8c..b8466ee3a 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1499,14 +1499,14 @@ void GL_ReadScreenTexture(int tex, UINT8 *restrict dest, INT32 scale) // -----------------+ void GL_SetPalette(RGBA_t *palette) { - INT32 i; + const size_t palsize = (sizeof(RGBA_t) * 256); - for (i = 0; i < 256; i++) + // on a palette change, you have to reload all of the textures + if (memcmp(myPaletteData, palette, palsize)) { - myPaletteData[i].s = palette[i].s; + memcpy(myPaletteData, palette, palsize); + GL_Flush(); } - - GL_Flush(); } // -----------------+ -- 2.54.0 From dfca24b37093dc2bc2e5df85377f45e1d9691f91 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 13 Nov 2025 14:53:12 +0100 Subject: [PATCH 13/17] HWR_SkyDomeVertex: tiny optimization save a tiny bit of float division, use float sin and cos functions, handle implicit float conversions --- src/hardware/hw_main.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index afce789f6..a2539cc7d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5067,42 +5067,46 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) static gl_sky_t gl_sky; -#define DEG2RADGL(a) ((a * M_PIl) / 180.0f) - static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, signed char yflip, float delta, boolean foglayer) { + static constexpr float radians = (float)(M_PIl / 180.0f); static constexpr float scale = 10000.0f; - static constexpr float maxSideAngle = DEG2RADGL(60.0f); + static constexpr float maxSideAngle = 60.0f * radians; - float topAngle = DEG2RADGL(c / (float)sky->columns * 360.0f); + float topAngle = ((float)c / (float)sky->columns * 360.0f) * radians; float sideAngle = (maxSideAngle * (float)(sky->rows - r) / (float)sky->rows); - float height = (float)(sin(sideAngle)); - float realRadius = (scale * (float)cos(sideAngle)); - float x = (realRadius * (float)cos(topAngle)); + float height = sinf(sideAngle); + float realRadius = (scale * cosf(sideAngle)); + float x = (realRadius * cosf(topAngle)); float y = (!yflip) ? scale * height : -scale * height; - float z = (realRadius * (float)sin(topAngle)); - float timesRepeat = (4 * (256.0f / sky->width)); - - if (std::fpclassify(timesRepeat) == FP_ZERO) - timesRepeat = 1.0f; + float z = (realRadius * sinf(topAngle)); + float timesRepeat; if (!foglayer) { + timesRepeat = (4.0f * (256.0f / (float)sky->width)); + + if (std::fpclassify(timesRepeat) == FP_ZERO) + timesRepeat = 1.0f; + vbo->r = 255; vbo->g = 255; vbo->b = 255; vbo->a = (r == 0 ? 0 : 255); // And the texture coordinates. - vbo->u = (-timesRepeat * c / (float)sky->columns); - if (!yflip) // Flipped Y is for the lower hemisphere. - vbo->v = (r / (float)sky->rows) + 0.5f; + vbo->u = (-timesRepeat * (float)c / (float)sky->columns); + + if (!yflip) // Flipped Y is for the lower hemisphere. + vbo->v = ((float)r / (float)sky->rows) + 0.5f; else - vbo->v = 1.0f + ((sky->rows - r) / (float)sky->rows) + 0.5f; + vbo->v = 1.0f + ((float)(sky->rows - r) / (float)sky->rows) + 0.5f; } if (r != 4) + { y += 300.0f; + } // And finally the vertex. vbo->x = x; -- 2.54.0 From 4e8865d4957894ff9bbb1ef0beb03f253212632d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 13 Nov 2025 17:37:30 +0100 Subject: [PATCH 14/17] cleanup some wonky float/double maths --- src/dedicated/i_system.c | 42 ++++++++++++++++++-------------- src/hardware/hw_main.cpp | 24 +++++++++--------- src/hardware/r_opengl/r_opengl.c | 14 +++++------ src/sdl/i_system.cpp | 34 ++++++++++++++------------ 4 files changed, 63 insertions(+), 51 deletions(-) diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index d2ffa12ad..fe8889405 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -808,20 +808,23 @@ static void I_SetupMumble(void) void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) { #ifdef HAVE_MUMBLE - double angle; + float angle; fixed_t anglef; if (!mumble) return; - if (mumble->uiVersion != 2) { - wcsncpy(mumble->name, L"SRB2Kart "VERSIONSTRINGW, 256); + if (mumble->uiVersion != 2) + { + 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++; - if (!netgame || gamestate != GS_LEVEL) { // Zero out, but never delink. + // Zero out, but never delink. + if (!netgame || gamestate != GS_LEVEL) + { mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f; mumble->fAvatarFront[0] = 1.0f; mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f; @@ -838,31 +841,34 @@ void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) mumble->context_len = (UINT32)(p - mumble->context); } - if (mobj) { - mumble->fAvatarPosition[0] = FIXED_TO_FLOAT(mobj->x) / MUMBLEUNIT; - mumble->fAvatarPosition[1] = FIXED_TO_FLOAT(mobj->z) / MUMBLEUNIT; - mumble->fAvatarPosition[2] = FIXED_TO_FLOAT(mobj->y) / MUMBLEUNIT; + if (mobj) + { + mumble->fAvatarPosition[0] = FixedToFloat(mobj->x) / MUMBLEUNIT; + mumble->fAvatarPosition[1] = FixedToFloat(mobj->z) / MUMBLEUNIT; + mumble->fAvatarPosition[2] = FixedToFloat(mobj->y) / MUMBLEUNIT; anglef = AngleFixed(mobj->angle); - angle = FIXED_TO_FLOAT(anglef)*DEG2RAD; - mumble->fAvatarFront[0] = (float)cos(angle); + angle = (float)(FixedToFloat(anglef) * DEG2RAD); + mumble->fAvatarFront[0] = cosf(angle); mumble->fAvatarFront[1] = 0.0f; - mumble->fAvatarFront[2] = (float)sin(angle); - } else { + mumble->fAvatarFront[2] = sinf(angle); + } + else + { mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f; mumble->fAvatarFront[0] = 1.0f; mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f; } - mumble->fCameraPosition[0] = FIXED_TO_FLOAT(listener.x) / MUMBLEUNIT; - mumble->fCameraPosition[1] = FIXED_TO_FLOAT(listener.z) / MUMBLEUNIT; - mumble->fCameraPosition[2] = FIXED_TO_FLOAT(listener.y) / MUMBLEUNIT; + mumble->fCameraPosition[0] = FixedToFloat(listener.x) / MUMBLEUNIT; + mumble->fCameraPosition[1] = FixedToFloat(listener.z) / MUMBLEUNIT; + mumble->fCameraPosition[2] = FixedToFloat(listener.y) / MUMBLEUNIT; anglef = AngleFixed(listener.angle); - angle = FIXED_TO_FLOAT(anglef)*DEG2RAD; - mumble->fCameraFront[0] = (float)cos(angle); + angle = (float)(FixedToFloat(anglef) * DEG2RAD); + mumble->fCameraFront[0] = cosf(angle); mumble->fCameraFront[1] = 0.0f; - mumble->fCameraFront[2] = (float)sin(angle); + mumble->fCameraFront[2] = sinf(angle); #else (void)mobj; (void)listener; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index a2539cc7d..8dc4d3804 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5940,31 +5940,33 @@ static void HWR_DoPostProcessor(player_t *player) float disStart = (leveltime-1) + FixedToFloat(R_GetTimeFrac(RTF_LEVEL)); UINT8 x, y; - INT32 WAVELENGTH; - INT32 AMPLITUDE; - INT32 FREQUENCY; + float WAVELENGTH; + float AMPLITUDE; + float FREQUENCY; // Modifies the wave. if (thiscam->postimg & POSTIMG_WATER) { - WAVELENGTH = 5; - AMPLITUDE = 40; - FREQUENCY = 8; + WAVELENGTH = 5.0f; + AMPLITUDE = 40.0f; + FREQUENCY = 8.0f; } else { - WAVELENGTH = 10; - AMPLITUDE = 60; - FREQUENCY = 4; + WAVELENGTH = 10.0f; + AMPLITUDE = 60.0f; + FREQUENCY = 4.0f; } + //static constexpr float scale = ((float)SCREENVERTS - 1.0f) / 9.0f; // well this evals to just 1.0f and what is x / 1? kek + for (x = 0; x < SCREENVERTS; x++) { for (y = 0; y < SCREENVERTS; y++) { // Change X position based on its Y position. - v[x][y][0] = (x/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f + (float)sin((disStart+(y*WAVELENGTH))/FREQUENCY)/AMPLITUDE; - v[x][y][1] = (y/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f; + v[x][y][0] = x-4.5f + sinf(((disStart+((float)y * WAVELENGTH)) / FREQUENCY)) / AMPLITUDE; // (x / scale) + v[x][y][1] = y-4.5f; // (y / scale) } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b8466ee3a..024dd2629 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1583,11 +1583,11 @@ void GL_Draw2DLine(F2DCoord * v1, F2DCoord * v2, RGBA_t Color) // This is the preferred, 'modern' way of rendering lines -- creating a polygon. if (fabsf(v2->x - v1->x) > FLT_EPSILON) - angle = (float)atan((v2->y-v1->y)/(v2->x-v1->x)); + angle = atanf((v2->y-v1->y)/(v2->x-v1->x)); else angle = (float)N_PI_DEMI; - dx = (float)sin(angle) / (float)screen_width; - dy = (float)cos(angle) / (float)screen_height; + dx = sinf(angle) / (float)screen_width; + dy = cosf(angle) / (float)screen_height; p[0] = v1->x - dx; p[1] = -(v1->y + dy); p[2] = 1; p[3] = v2->x - dx; p[4] = -(v2->y + dy); p[5] = 1; @@ -3136,8 +3136,8 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics void GL_SetTransform(FTransform *stransform) { static boolean special_splitscreen; - GLdouble used_fov; boolean shearing = false; + float used_fov; pglLoadIdentity(); @@ -3196,11 +3196,11 @@ void GL_SetTransform(FTransform *stransform) if (special_splitscreen) { - used_fov = (float)(atan(tan(used_fov * M_PIl / 360) * 0.8) * 360 / M_PIl); - GL_Perspective((GLfloat)used_fov, 2*ASPECT_RATIO); + used_fov = (atanf(tanf(used_fov * (float)M_PI / 360.0f) * 0.8f) * 360.0f / (float)M_PI); + GL_Perspective(used_fov, 2*ASPECT_RATIO); } else - GL_Perspective((GLfloat)used_fov, ASPECT_RATIO); + GL_Perspective(used_fov, ASPECT_RATIO); pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 272379aa8..0dc751c85 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1260,7 +1260,7 @@ static void I_SetupMumble(void) void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) { #ifdef HAVE_MUMBLE - double angle; + float angle; fixed_t anglef; if (!mumble) @@ -1274,7 +1274,9 @@ void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) } mumble->uiTick++; - if (!netgame || gamestate != GS_LEVEL) { // Zero out, but never delink. + // Zero out, but never delink. + if (!netgame || gamestate != GS_LEVEL) + { mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f; mumble->fAvatarFront[0] = 1.0f; mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f; @@ -1293,30 +1295,32 @@ void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) if (mobj) { - mumble->fAvatarPosition[0] = FIXED_TO_FLOAT(mobj->x) / MUMBLEUNIT; - mumble->fAvatarPosition[1] = FIXED_TO_FLOAT(mobj->z) / MUMBLEUNIT; - mumble->fAvatarPosition[2] = FIXED_TO_FLOAT(mobj->y) / MUMBLEUNIT; + mumble->fAvatarPosition[0] = FixedToFloat(mobj->x) / MUMBLEUNIT; + mumble->fAvatarPosition[1] = FixedToFloat(mobj->z) / MUMBLEUNIT; + mumble->fAvatarPosition[2] = FixedToFloat(mobj->y) / MUMBLEUNIT; anglef = AngleFixed(mobj->angle); - angle = FIXED_TO_FLOAT(anglef)*DEG2RAD; - mumble->fAvatarFront[0] = (float)cos(angle); + angle = (float)(FixedToFloat(anglef) * DEG2RAD); + mumble->fAvatarFront[0] = cosf(angle); mumble->fAvatarFront[1] = 0.0f; - mumble->fAvatarFront[2] = (float)sin(angle); - } else { + mumble->fAvatarFront[2] = sinf(angle); + } + else + { mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f; mumble->fAvatarFront[0] = 1.0f; mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f; } - mumble->fCameraPosition[0] = FIXED_TO_FLOAT(listener.x) / MUMBLEUNIT; - mumble->fCameraPosition[1] = FIXED_TO_FLOAT(listener.z) / MUMBLEUNIT; - mumble->fCameraPosition[2] = FIXED_TO_FLOAT(listener.y) / MUMBLEUNIT; + mumble->fCameraPosition[0] = FixedToFloat(listener.x) / MUMBLEUNIT; + mumble->fCameraPosition[1] = FixedToFloat(listener.z) / MUMBLEUNIT; + mumble->fCameraPosition[2] = FixedToFloat(listener.y) / MUMBLEUNIT; anglef = AngleFixed(listener.angle); - angle = FIXED_TO_FLOAT(anglef)*DEG2RAD; - mumble->fCameraFront[0] = (float)cos(angle); + angle = (float)(FixedToFloat(anglef) * DEG2RAD); + mumble->fCameraFront[0] = cosf(angle); mumble->fCameraFront[1] = 0.0f; - mumble->fCameraFront[2] = (float)sin(angle); + mumble->fCameraFront[2] = sinf(angle); #else (void)mobj; (void)listener; -- 2.54.0 From 19a4e379d7531550f8f93ff41c86ea06ca2884f5 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 13 Nov 2025 17:38:27 +0100 Subject: [PATCH 15/17] HWR_DoWipe: always draw a black screen if it returns early otherwise this just flashes like crazy should there ever be any issue here --- src/hardware/hw_main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 8dc4d3804..100028a20 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5992,20 +5992,27 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) } if (wipenum > 99 || scrnnum > 99) // not a valid wipe number + { + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // just draw a black screen instead of flashing and crap return; // shouldn't end up here really, the loop should've stopped running beforehand + } // puts the numbers into the lumpname sprintf(&lumpname[4], "%.2hu%.2hu", (UINT16)wipenum, (UINT16)scrnnum); lumpnum = W_CheckNumForName(lumpname); if (lumpnum == LUMPERROR) // again, shouldn't be here really + { + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // just draw a black screen instead of flashing and crap return; + } lsize = W_LumpLength(lumpnum); if (!(lsize == 256000 || lsize == 64000 || lsize == 16000 || lsize == 4000)) { CONS_Alert(CONS_WARNING, "Fade mask lump %s of incorrect size, ignored\n", lumpname); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // just draw a black screen instead of flashing and crap return; // again, shouldn't get here if it is a bad size } -- 2.54.0 From efe700965014e7150a02bbcf32a1c998012b7cd9 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 13 Nov 2025 19:00:06 +0100 Subject: [PATCH 16/17] PT_ReceivedGamestate: add missing SATURNPAK ifdef --- src/d_clisrv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f69d67cfe..038661541 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5854,12 +5854,14 @@ static void PT_FileFragmentFromPlayer(SINT8 node) Got_Filetxpak(); } +#ifdef SATURNPAK static void PT_ReceivedGamestate(SINT8 node) { sendingsavegame[node] = false; resendingsavegame[node] = 0; savegameresendcooldown[node] = I_GetTime() + cv_resynchcooldown.value * TICRATE; // I_GetTime() + 5 * TICRATE; } +#endif /** Handles a packet received from a node that is in game * -- 2.54.0 From 1fb60e823031358d3257cb32b407edaaece6109e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 13 Nov 2025 19:31:20 +0100 Subject: [PATCH 17/17] fix sourcefile for src dir --- src/Sourcefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Sourcefile b/src/Sourcefile index 352081bc5..462ec9871 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -20,6 +20,7 @@ i_tcp.c i_time.c info.c lzf.c +md5.c m_aatree.c m_anigif.c m_argv.c @@ -43,18 +44,19 @@ screen.c sounds.c st_stuff.c string.c +stun.c tables.c v_video.c w_wad.c y_inter.c z_zone.cpp -r_bsp.c +r_bsp.cpp r_data.c -r_draw.c +r_draw.cpp r_fps.cpp r_main.cpp r_patch.cpp -r_patchrotation.c +r_patchrotation.cpp r_plane.cpp r_segs.cpp r_skins.c -- 2.54.0