From 8da59dc288f734d0926c39de853a94f8d0ee02ca Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 17:36:47 +0100 Subject: [PATCH 1/3] slightly cleanup rumble and led ticker --- src/d_main.c | 7 +++++-- src/p_tick.c | 17 +++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index a44c12ad6..f9e1ca27e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -171,14 +171,17 @@ static inline void D_DeviceLEDTick(void) UINT16 color[MAXSPLITSCREENPLAYERS]; UINT16 curcolor[MAXSPLITSCREENPLAYERS]; - if (I_NumJoys() == 0 || (cv_gamepadled[0].value == 0 && cv_gamepadled[1].value == 0 && cv_gamepadled[2].value == 0 && cv_gamepadled[3].value == 0)) + if (I_NumJoys() == 0) { return; } for (i = 0; i <= splitscreen; i++) { - if (cv_usejoystick[i].value == 0) + if (!cv_usejoystick[i].value) + continue; + + if (!cv_gamepadled[i].value) continue; color[i] = G_GetSkinColor(i); diff --git a/src/p_tick.c b/src/p_tick.c index 3b0cadde8..9d5c8539b 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -354,21 +354,25 @@ static void P_DeviceRumbleTick(void) { UINT8 i; - if (I_NumJoys() == 0 || (cv_rumble[0].value == 0 && cv_rumble[1].value == 0 && cv_rumble[2].value == 0 && cv_rumble[3].value == 0)) + if (I_NumJoys() == 0 || gamestate != GS_LEVEL) { return; } for (i = 0; i <= splitscreen; i++) { - player_t *player = &players[displayplayers[i]]; UINT16 low = 0; UINT16 high = 0; - if (!P_IsLocalPlayer(player)) + if (!cv_usejoystick[i].value) continue; - if (cv_usejoystick[i].value == 0) + if (!cv_rumble[i].value) + continue; + + player_t *player = &players[displayplayers[i]]; + + if (!P_IsLocalPlayer(player)) continue; if (!playeringame[displayplayers[i]] || player->spectator) @@ -402,10 +406,11 @@ static void P_DeviceRumbleTick(void) high = 65536 / 256; } - if (low == 0 && high == 0) + // hack alert! i just dont want this thing constantly resetting the rumble lol + if (low == 0 && high == 0) continue; - G_PlayerDeviceRumble(i, low, high, 57); // hack alert! i just dont want this think constantly resetting the rumble lol + G_PlayerDeviceRumble(i, low, high, 57); } } From bb3a65f8ffc8e85a27f4aa234fcb343a1598e450 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 1 Jan 2025 19:58:49 +0300 Subject: [PATCH 2/3] Repurpose ST_DrawTextInput into M_DrawTextInputScroll, and move its definition into m_textinput.c. M_DrawTextInput is now a macro using M_DrawTextInputScroll --- src/m_menu.c | 36 ++++-------------------- src/m_menu.h | 4 --- src/m_textinput.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ src/m_textinput.h | 5 ++++ src/st_stuff.c | 71 +---------------------------------------------- 5 files changed, 82 insertions(+), 105 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 42cf93f9c..03eeef210 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4980,33 +4980,6 @@ void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 fla V_DrawFill(x+5, y+5, width*8+6, boxlines*8+6, 239|flags); } -void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) -{ - INT32 skullx = x; - - V_DrawString(x, y, V_ALLOWLOWERCASE|flags, input->buffer); - - // draw text cursor for name - if (input->length) - skullx = x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE); - - if (skullAnimCounter < 4) // blink cursor - V_DrawCharacter(skullx, y+3, '_'|flags, false); - - // draw selection - if (input->select != input->cursor) - { - size_t start = min(input->select, input->cursor); - size_t end = max(input->select, input->cursor); - - size_t len = end - start; - - INT32 startx = V_SubStringWidth(input->buffer, start, V_ALLOWLOWERCASE); - - V_DrawFill(x+startx, y, V_SubStringWidth(input->buffer+start, len, V_ALLOWLOWERCASE), 8, 103|V_TRANSLUCENT|flags); - } -} - // horizontally centered text static void M_CentreText(INT32 y, const char *string) { @@ -10195,7 +10168,8 @@ static void M_StartServerMenu(INT32 choice) // CONNECT VIA IP // ============== -static char setupm_ip[28]; +#define SETUPM_IP_MAXSIZE ((28-1)*8) +static char setupm_ip[64]; static textinput_t setupm_input_ip; #endif @@ -10203,8 +10177,8 @@ void M_Multiplayer(INT32 choice) { (void)choice; #ifndef NONET - memset(setupm_ip, 0, 28); - M_TextInputInit(&setupm_input_ip, setupm_ip, 28); + memset(setupm_ip, 0, sizeof(setupm_ip)); + M_TextInputInit(&setupm_input_ip, setupm_ip, sizeof(setupm_ip)); #endif M_SetupNextMenu(&MP_MainDef); } @@ -10243,7 +10217,7 @@ Update the maxplayers label... if (itemOn != 9) V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); else - M_DrawTextInput(x+8, y+12, &setupm_input_ip, 0); + M_DrawTextInputScroll(x+8, y+12, &setupm_input_ip, 0, SETUPM_IP_MAXSIZE); #endif // character bar, ripped off the color bar :V diff --git a/src/m_menu.h b/src/m_menu.h index 9806773b4..72864c669 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -64,10 +64,6 @@ void M_DrawTextBox(INT32 x, INT32 y, INT32 width, INT32 boxlines); // Same but with extra flags applied void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 flags); -// Draw text input -typedef struct textinput_s textinput_t; -void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags); - // Used in d_netcmd to restart time attack void M_ModeAttackRetry(INT32 choice); diff --git a/src/m_textinput.c b/src/m_textinput.c index 266a8f300..dfe9f5a64 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -1,4 +1,7 @@ #include "m_textinput.h" +#include "m_menu.h" // MAXSTRINGLENGTH +#include "v_video.h" +#include "r_main.h" // renderisnewtic #include "i_system.h" #include "keys.h" #include "console.h" @@ -132,6 +135,8 @@ void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size) input->buffer = buffer; input->buffer_size = buffer_size; + input->skull = 0; + M_TextInputClear(input); } @@ -314,3 +319,69 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key) return true; } + +void M_DrawTextInputScroll(INT32 x, INT32 y, textinput_t *input, INT32 flags, INT32 MAXINPUTWIDTH) +{ + if (renderisnewtic) + input->skull++; + input->skull %= 8; + + char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; + + size_t drawstart = 0; + size_t drawend = 0; // Only used for selection + + INT32 skullx = x; + + while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) + ++drawstart; + + size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1; + drawend = drawstart + drawlength; + + memcpy(nametodraw, input->buffer+drawstart, drawlength); + + if (input->length) + skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); + + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw); + + // draw text cursor for name + if (input->skull < 4) // blink cursor + V_DrawCharacter(skullx, y+3, '_'|flags, false); + + // draw selection + if (input->select != input->cursor) + { + size_t start = min(input->select, input->cursor); + size_t end = max(input->select, input->cursor); + + INT32 startx = 0; + INT32 width = 0; + + // I couldn't figure out one formula so here's bunch of separate cases + if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name + { + startx = -2; + width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4; + } + else if (start < drawstart) // Only left side of selection is off visible part + { + startx = -2; + size_t len = (end - start) - (drawstart - start); + width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2; + } + else if (end > drawend) // Only right side of selection is off visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2; + } + else // All selection is on visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE); + } + + V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags); + } +} diff --git a/src/m_textinput.h b/src/m_textinput.h index aad5e94ab..649288ec4 100644 --- a/src/m_textinput.h +++ b/src/m_textinput.h @@ -10,6 +10,8 @@ typedef struct textinput_s { char *buffer; size_t buffer_size; + + unsigned skull; } textinput_t; void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size); @@ -20,4 +22,7 @@ void M_TextInputSetString(textinput_t *input, const char *c); boolean M_TextInputHandle(textinput_t *input, INT32 key); +#define M_DrawTextInput(x, y, input, flags) M_DrawTextInputScroll((x), (y), (input), (flags), ((input)->buffer_size-1)*8) +void M_DrawTextInputScroll(INT32 x, INT32 y, textinput_t *input, INT32 flags, INT32 MAXINPUTWIDTH); + #endif diff --git a/src/st_stuff.c b/src/st_stuff.c index aaa926515..fa64b3709 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -829,82 +829,13 @@ static void ST_overlayDrawer(void) } } -static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) -{ - static UINT8 skullAnimCounter = 0; - static const INT32 MAXINPUTWIDTH = (MAXSTRINGLENGTH-1)*8; - - if (renderisnewtic) - skullAnimCounter++; - skullAnimCounter %= 8; - - char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; - - size_t drawstart = 0; - size_t drawend = 0; // Only used for selection - - INT32 skullx = x; - - while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) - ++drawstart; - - size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1; - drawend = drawstart + drawlength; - - memcpy(nametodraw, input->buffer+drawstart, drawlength); - - if (input->length) - skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); - - V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw); - - // draw text cursor for name - if (skullAnimCounter < 4) // blink cursor - V_DrawCharacter(skullx, y+3, '_'|flags, false); - - // draw selection - if (input->select != input->cursor) - { - size_t start = min(input->select, input->cursor); - size_t end = max(input->select, input->cursor); - - INT32 startx = 0; - INT32 width = 0; - - // I couldn't figure out one formula so here's bunch of separate cases - if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name - { - startx = -2; - width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4; - } - else if (start < drawstart) // Only left side of selection is off visible part - { - startx = -2; - size_t len = (end - start) - (drawstart - start); - width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2; - } - else if (end > drawend) // Only right side of selection is off visible part - { - startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); - width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2; - } - else // All selection is on visible part - { - startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); - width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE); - } - - V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags); - } -} - void ST_DrawDemoTitleEntry(void) { #define x (BASEVIDWIDTH/2 - 139) #define y (BASEVIDHEIGHT/2) M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - ST_DrawTextInput(x + 8, y + 12, &demo.titlenameinput, 0); + M_DrawTextInputScroll(x + 8, y + 12, &demo.titlenameinput, 0, (MAXSTRINGLENGTH-1)*8); M_DrawTextBox(x + 30, y - 24, 26, 1); V_DrawString(x + 38, y - 16, V_ALLOWLOWERCASE, "Enter the name of the replay."); From e321d759c0bc8461d5ab7bccf96a718dd5edd2e3 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 1 Jan 2025 20:01:54 +0300 Subject: [PATCH 3/3] Thats not defined or used anywhere, bad automerge maybe? --- src/st_stuff.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index fa64b3709..8b431b2f0 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -788,8 +788,6 @@ static void ST_overlayDrawer(void) snprintf(directortoggle, 32, "%s - Toggle Director", item1 != NULL ? item1 : item2 != NULL ? item2 : "Not Bound"); V_DrawString(2, BASEVIDHEIGHT-10, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_HUDTRANSHALF, directortoggle); - - directortextactive = true; } else {