From 6e04e4171e3ea1cf4f58f933f3b28ac1629252c0 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 6 Jun 2025 00:19:23 +0200 Subject: [PATCH 1/6] fix the goddamn boolean --- src/doomtype.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index 174bba5b1..88e9ce5a4 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -156,22 +156,19 @@ size_t strlcpy(char *dst, const char *src, size_t siz); /* Boolean type definition */ -// \note __BYTEBOOL__ used to be set above if "macintosh" was defined, -// if macintosh's version of boolean type isn't needed anymore, then isn't this macro pointless now? -#ifndef __BYTEBOOL__ - #define __BYTEBOOL__ - - //faB: clean that up !! - #if defined( _MSC_VER) && (_MSC_VER >= 1800) // MSVC 2013 and forward - #include "stdbool.h" - #elif defined (_WIN32) - #define false FALSE // use windows types - #define true TRUE - #define boolean BOOL - #else - typedef enum {false, true} boolean; - #endif -#endif // __BYTEBOOL__ +#ifndef _WIN32 +#include +// dont use stdbools _BOOL type +// its smaller (1 byte) than the old interger bool (4 bytes) +// which results in packed struct sizes being mismatched between vanilla and this +// however we gotta still include stdbool cause since c23 true and false are keywords +// which we cant use as enumeration constants +typedef int32_t boolean; +#else +#define false FALSE +#define true TRUE +#define boolean BOOL +#endif /* 7.18.2.1 Limits of exact-width integer types */ #ifndef INT8_MIN From 3a55972997efad4956dded445602e3945427be5a Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 28 Jun 2025 21:03:15 +0300 Subject: [PATCH 2/6] Initial emote support --- src/Sourcefile | 1 + src/d_netcmd.c | 3 + src/doomtype.h | 2 + src/hu_stuff.c | 73 +++++++++++++++- src/m_emotes.cpp | 220 +++++++++++++++++++++++++++++++++++++++++++++++ src/m_emotes.h | 38 ++++++++ src/p_setup.c | 6 ++ 7 files changed, 341 insertions(+), 2 deletions(-) create mode 100644 src/m_emotes.cpp create mode 100644 src/m_emotes.h diff --git a/src/Sourcefile b/src/Sourcefile index 227e6c95a..23572d293 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -28,6 +28,7 @@ m_cond.c m_fixed.c m_menu.c m_textinput.c +m_emotes.cpp m_misc.c m_perfstats.c m_queue.c diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 91ea8e945..ff7a2031a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -21,6 +21,7 @@ #include "i_system.h" #include "g_game.h" #include "hu_stuff.h" +#include "m_emotes.h" #include "g_input.h" #include "m_menu.h" #include "r_local.h" @@ -917,6 +918,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_keyboardlayout); + CV_RegisterVar(&cv_emotes); + // time attack ghost options are also saved to config CV_RegisterVar(&cv_ghost_besttime); CV_RegisterVar(&cv_ghost_bestlap); diff --git a/src/doomtype.h b/src/doomtype.h index 88e9ce5a4..c598e86ee 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -100,8 +100,10 @@ typedef long ssize_t; #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif +#ifndef __cplusplus char *strcasestr(const char *in, const char *what); #define stristr strcasestr +#endif #if defined (macintosh) //|| defined (__APPLE__) //skip all boolean/Boolean crap #define true 1 diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f8f0524b2..b1d0cd64a 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -17,6 +17,7 @@ #include "m_menu.h" // gametype_cons_t #include "m_cond.h" // emblems +#include "m_emotes.h" #include "d_clisrv.h" @@ -93,6 +94,7 @@ static textinput_t w_chat; static boolean headsupactive = false; boolean hu_showscores; // draw rankings static char hu_tick; +static tic_t hu_emoteanim = 0; static huddrawlist_h luahuddrawlist_scores; @@ -1102,6 +1104,7 @@ void HU_Ticker(void) return; hu_tick++; + hu_emoteanim++; hu_tick &= 7; // currently only to blink chat input cursor if (PLAYER1INPUTDOWN(gc_scores)) @@ -1406,6 +1409,40 @@ boolean HU_Responder(event_t *ev) #ifndef NONET +static INT32 HU_DrawEmote(INT32 x, INT32 y, emote_t *emote, INT32 flags) +{ + if (emote->numframes == 0) + return 4; // charwidth + + const char *lumpname = emote->frames[(hu_emoteanim/emote->timeperframe) % emote->numframes]; + patch_t *emotepatch = W_CachePatchName(lumpname, PU_CACHE); + + int emotewidth = min(6, emotepatch->width); + int charheight = 6; + + fixed_t scale = (FRACUNIT/emotepatch->width)*emotewidth; + + x *= FRACUNIT; + y *= FRACUNIT; + + y -= (scale*emotepatch->height-charheight*FRACUNIT)/2; + + V_DrawFixedPatch(x, y, scale, flags, emotepatch, NULL); + + return emotewidth; +} + +static INT32 HU_EmoteWidth(emote_t *emote) +{ + if (emote->numframes == 0) + return 4; // charwidth + + const char *lumpname = emote->frames[(hu_emoteanim/emote->timeperframe) % emote->numframes]; + patch_t *emotepatch = W_CachePatchName(lumpname, PU_CACHE); + + return min(8, emotepatch->width); +} + // Precompile a wordwrapped string to any given width. // This is a muuuch better method than V_WORDWRAP. // again stolen and modified a bit from video.c, don't mind me, will need to rearrange this one day. @@ -1417,6 +1454,8 @@ static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) size_t slen; char *newstring = Z_StrDup(string); INT32 spacewidth = (vid.width < 640) ? 8 : 4, charwidth = (vid.width < 640) ? 8 : 4; + emote_t *emote = NULL; + int emotelen = 0; slen = strlen(string); x = 0; @@ -1438,7 +1477,12 @@ static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) c = toupper(c); c -= HU_FONTSTART; - if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) + if (string[i] == ':' && (emote = M_VerifyEmote(string+i, &emotelen))) + { + chw = HU_EmoteWidth(emote); + i += emotelen-1; + } + else if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) { chw = spacewidth; lastusablespace = i; @@ -1460,7 +1504,6 @@ static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) return newstring; } - // 30/7/18: chaty is now the distance at which the lowest point of the chat will be drawn if that makes any sense. INT16 chatx = 13, chaty = 169; // let's use this as our coordinates, shh @@ -1493,6 +1536,8 @@ static void HU_drawMiniChat(void) char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); size_t j = 0; INT32 linescount = 0; + emote_t *emote = NULL; + int emotelen = 0; while(msg[j]) // iterate through msg { @@ -1517,6 +1562,11 @@ static void HU_drawMiniChat(void) ++j; } + else if (msg[j] == ':' && (emote = M_VerifyEmote(msg+j, &emotelen))) + { + dx += HU_EmoteWidth(emote) - charwidth; + j += emotelen; + } else { j++; @@ -1562,6 +1612,8 @@ static void HU_drawMiniChat(void) size_t j = 0; char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; + emote_t *emote = NULL; + int emotelen = 0; while(msg[j]) // iterate through msg { @@ -1588,6 +1640,15 @@ static void HU_drawMiniChat(void) ++j; } + else if (msg[j] == ':' && (emote = M_VerifyEmote(msg+j, &emotelen))) + { + if (cv_chatbacktint.value) // on request of wolfy + V_DrawFillConsoleMap(x + dx + 2, y+dy, charwidth, charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); + + dx += HU_DrawEmote(x+dx+2, y+dy, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag) - charwidth; + + j += emotelen; + } else { if (cv_chatbacktint.value) // on request of wolfy @@ -1665,6 +1726,9 @@ static void HU_drawChatLog(INT32 offset) INT32 j = 0; char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_log[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; + emote_t *emote = NULL; + int emotelen = 0; + while(msg[j]) // iterate through msg { if (msg[j] < HU_FONTSTART) // don't draw @@ -1686,6 +1750,11 @@ static void HU_drawChatLog(INT32 offset) ++j; } + else if (msg[j] == ':' && (emote = M_VerifyEmote(msg+j, &emotelen))) + { + dx += HU_DrawEmote(x+dx+2, y+dy, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT) - charwidth; + j += emotelen; + } else { if ((y+dy+2 >= chat_topy) && (y+dy < (chat_bottomy))) diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp new file mode 100644 index 000000000..25d3a4ebc --- /dev/null +++ b/src/m_emotes.cpp @@ -0,0 +1,220 @@ +#include +#include +#include +#include + +#include "m_emotes.h" + +extern "C" { +#include "w_wad.h" +} + +#include "z_zone.h" + +consvar_t cv_emotes = {"emotes", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};; + +static std::map emotes; + +// TODO - Would be really nice to generalize soc-like file parsing and not reimplement it 100 times :))))) +void M_LoadEmotes(UINT16 wadnum) +{ + UINT16 lumpnum = W_CheckNumForNamePwad("EMOTES", wadnum, 0); + + if (lumpnum == INT16_MAX) + return; + + char *lump = static_cast(W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE)); + size_t size = W_LumpLengthPwad(wadnum, lumpnum); + + std::istringstream file(std::string(lump, size)); + std::string line; + + emote_t *emote = nullptr; + std::string emote_name; + + // Just smol lambda to remove all the trailing chars we might not want + auto trim = [](std::string &str) { + str.erase(0, str.find_first_not_of(" \t\n\r\f\v")); + str.erase(str.find_last_not_of(" \t\n\r\f\v")+1); + }; + + int numemotes = 0; + int linenum = 0; + + while (std::getline(file, line)) + { + ++linenum; + + trim(line); + + if (line.empty()) + continue; + + size_t split = line.find('='); + + // Didn't find the =, means we're about to parse `Emote ` + if (split == line.npos) + { + split = line.find(' '); + + if (split == line.npos) + { + CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized line. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); + continue; + } + + if (strnicmp(line.c_str(), "emote", 5)) + { + CONS_Alert(CONS_WARNING, "EMOTES: 'Emote' expected. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); + continue; + } + + emote_name = line.substr(split+1); + + if (emote_name.find_first_of(" \t\n\r\f\v") != emote_name.npos) + { + CONS_Alert(CONS_WARNING, "EMOTES: Emote name cannot contain spaces. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); + continue; + } + + // This first->second looks kind of weird i know + emote = &emotes[emote_name]; + + emote->timeperframe = 1; + emote->numframes = 0; + std::memset(emote->frames, 0, sizeof(emote->frames)); + + ++numemotes; + } + else if (emote) + { + std::string field = line.substr(0, split); + std::string value = line.substr(split+1); + + trim(field); + trim(value); + + if (stricmp(field.c_str(), "frames") == 0) + { + UINT8 numframes = 0; + + auto copy_frame = [&] { + if (numframes == MAXEMOTEFRAMES) + { + CONS_Alert(CONS_WARNING, "EMOTES: Too many frames. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); + return false; + } + + size_t list_split = value.find(','); + std::string framelumpname = value.substr(0, list_split); + trim(framelumpname); + + if (list_split == value.npos) + value = ""; + else + value = value.substr(list_split+1, value.npos); + + // End of list of frames + if (framelumpname.size() == 0) + return false; + + if (framelumpname.size() > 8) + { + CONS_Alert(CONS_WARNING, "EMOTES: Frame %d name is too long. (file %s, line %d)", numframes, wadfiles[wadnum]->filename, linenum); + framelumpname = framelumpname.substr(0, 8); + } + + std::strncpy(emote->frames[numframes], framelumpname.c_str(), framelumpname.size()+1); + + ++numframes; + + return true; + }; + + while (copy_frame()) {} + + if (numframes == 0) + { + CONS_Alert(CONS_WARNING, "EMOTES: Expected list of frames. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); + } + + emote->numframes = numframes; + } + else if (stricmp(field.c_str(), "timeperframe") == 0) + { + emote->timeperframe = std::stoi(value); + + if (emote->timeperframe <= 0) + { + emote->timeperframe = 1; + CONS_Alert(CONS_WARNING, "EMOTES: Bad value for 'timeperframe'. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); + } + } + else + { + CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized field '%s'. (file %s, line %d)", field.c_str(), wadfiles[wadnum]->filename, linenum); + } + } + else + { + CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized line. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); + } + } + + CONS_Printf("Added %d emotes\n", numemotes); +} + +emote_t *M_FindEmote(const char *name, int skip) +{ + if (!cv_emotes.value) + return nullptr; + + char query[MAXEMOTENAME+1] = {0}; + std::strncpy(query, name, MAXEMOTENAME); + + for (auto &pair: emotes) + { + if (pair.first.rfind(query, 0, MAXEMOTENAME) != 0) + continue; + + if (skip > 0) + { + --skip; + continue; + } + + return &pair.second; + } + + return nullptr; +} + +emote_t *M_VerifyEmote(const char *name, int *emotelen) +{ + if (!cv_emotes.value) + return nullptr; + + const char *p = name+1; // skip ':' + emote_t *match = nullptr; + + while (*p && (p - name) < MAXEMOTENAME) + { + if (*p == ':') + { + std::string checkname = std::string(name+1, (p-name)-1); + auto it = emotes.find(checkname); + + if (it != emotes.end()) + match = &it->second; + + break; + } + + ++p; + } + + if (match && emotelen) + *emotelen = p-name+1; + + return match; +} diff --git a/src/m_emotes.h b/src/m_emotes.h new file mode 100644 index 000000000..f3e1875ce --- /dev/null +++ b/src/m_emotes.h @@ -0,0 +1,38 @@ +#ifndef __M_EMOTES__ +#define __M_EMOTES__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "doomdef.h" +#include "command.h" + +extern consvar_t cv_emotes; + +#define MAXEMOTENAME 32 +#define MAXEMOTEFRAMES 32 + +typedef struct emote_s { + char frames[MAXEMOTEFRAMES][9]; + UINT8 numframes; + tic_t timeperframe; +} emote_t; + +// Reads and adds emotes from EMOTES lump, with syntax similar to soc +void M_LoadEmotes(UINT16 wadnum); + +// Finds first matching emote, ignoring first few matches +emote_t *M_FindEmote(const char *name, int skips); + +// Starts from ':' character, goes until it finds ':' or end of string +// If end of string is found, or closing ':' is found but resulting emote name doesn't exist, +// it returns null, otherwise it returns emote and stores into *emotelen how much characters +// needs to be skipped to get past emote name +emote_t *M_VerifyEmote(const char *name, int *emotelen); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __M_EMOTES__ diff --git a/src/p_setup.c b/src/p_setup.c index c56e8a2be..f5d92e7ca 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -34,6 +34,7 @@ #include "r_fps.h" // R_ResetViewInterpolation in level load #include "s_sound.h" +#include "m_emotes.h" #include "st_stuff.h" #include "w_wad.h" #include "z_zone.h" @@ -3310,6 +3311,11 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // S_LoadMusicDefs(wadnum); + // + // look for emotes + // + M_LoadEmotes(wadnum); + // TODO: Experimental SPRTINFO support, test first R_LoadSpriteInfoLumps(wadnum, wadfiles[wadnum]->numlumps); From 4b129314d3a5ca2ab8087a73b4f7b0299f8b2f7b Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 28 Jun 2025 21:04:09 +0300 Subject: [PATCH 3/6] Right that got removed in the end :chonkbunckle: --- src/m_emotes.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index 25d3a4ebc..50718b79b 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -77,7 +77,6 @@ void M_LoadEmotes(UINT16 wadnum) continue; } - // This first->second looks kind of weird i know emote = &emotes[emote_name]; emote->timeperframe = 1; From 74bdabc636afa93283ccfa98904f2ba33d97b39a Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 28 Jun 2025 22:31:33 +0300 Subject: [PATCH 4/6] Load emotes from base wads too at boot (so it loads ones from -file wads) --- src/d_main.c | 3 +++ src/m_emotes.cpp | 7 +++++++ src/m_emotes.h | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index ecd7e6247..fbc2c6c03 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -40,6 +40,7 @@ #include "g_game.h" #include "g_input.h" #include "hu_stuff.h" +#include "m_emotes.h" #include "i_sound.h" #include "i_system.h" #include "i_time.h" @@ -1997,6 +1998,8 @@ void D_SRB2Main(void) S_InitMusicDefs(); + M_InitEmotes(); + CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index 50718b79b..4c28f72b4 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -163,6 +163,13 @@ void M_LoadEmotes(UINT16 wadnum) CONS_Printf("Added %d emotes\n", numemotes); } +void M_InitEmotes(void) +{ + UINT16 i; + for (i = 0; i < numwadfiles; i++) + M_LoadEmotes(i); +} + emote_t *M_FindEmote(const char *name, int skip) { if (!cv_emotes.value) diff --git a/src/m_emotes.h b/src/m_emotes.h index f3e1875ce..0290e3909 100644 --- a/src/m_emotes.h +++ b/src/m_emotes.h @@ -22,6 +22,9 @@ typedef struct emote_s { // Reads and adds emotes from EMOTES lump, with syntax similar to soc void M_LoadEmotes(UINT16 wadnum); +// Load emotes from all base wads +void M_InitEmotes(void); + // Finds first matching emote, ignoring first few matches emote_t *M_FindEmote(const char *name, int skips); From da24ba20c7ff30ff3c61897701d4ffdf893ccf4a Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 28 Jun 2025 22:39:44 +0300 Subject: [PATCH 5/6] Fix emotes having not enough 'background' rendered :chonkbunckle: --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index b1d0cd64a..aea2a2310 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1643,7 +1643,7 @@ static void HU_drawMiniChat(void) else if (msg[j] == ':' && (emote = M_VerifyEmote(msg+j, &emotelen))) { if (cv_chatbacktint.value) // on request of wolfy - V_DrawFillConsoleMap(x + dx + 2, y+dy, charwidth, charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); + V_DrawFillConsoleMap(x + dx + 2, y+dy, HU_EmoteWidth(emote), charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); dx += HU_DrawEmote(x+dx+2, y+dy, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag) - charwidth; From e2336357836da65ad26f7062349f16bedf7bf317 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 29 Jun 2025 00:05:25 +0300 Subject: [PATCH 6/6] huh? --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index aea2a2310..e125a7b7e 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1643,7 +1643,7 @@ static void HU_drawMiniChat(void) else if (msg[j] == ':' && (emote = M_VerifyEmote(msg+j, &emotelen))) { if (cv_chatbacktint.value) // on request of wolfy - V_DrawFillConsoleMap(x + dx + 2, y+dy, HU_EmoteWidth(emote), charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); + V_DrawFillConsoleMap(x + dx + 2, y+dy, HU_EmoteWidth(emote)-charwidth/2, charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); dx += HU_DrawEmote(x+dx+2, y+dy, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag) - charwidth;