From 1b095d220eaef002fceeb5816fc8a703eb110457 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Wed, 14 May 2025 16:06:11 +0200 Subject: [PATCH] Why stop there? Go for skincolors too :^) --- src/d_main.cpp | 3 --- src/deh_lua.c | 24 +++++++++--------------- src/deh_soc.c | 18 +++++++----------- src/deh_tables.c | 20 +------------------- src/deh_tables.h | 8 ++------ src/dehacked.c | 10 ++++++++++ src/dehacked.h | 2 -- src/doomdef.h | 1 + src/p_setup.c | 5 +---- 9 files changed, 31 insertions(+), 60 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 0a9b105d5..cd4ae1cda 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1277,9 +1277,6 @@ void D_SRB2Main(void) // MAINCFG is now taken care of where "OBJCTCFG" is handled G_LoadGameSettings(); - // Test Dehacked lists - DEH_TableCheck(); - // Netgame URL special case: change working dir to EXE folder. ChangeDirForUrlHandler(); diff --git a/src/deh_lua.c b/src/deh_lua.c index a1983727b..132bd72c7 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -111,18 +111,17 @@ static inline int lib_freeslot(lua_State *L) else if (fastcmp(type, "SKINCOLOR")) { skincolornum_t i; - for (i = 0; i < NUMCOLORFREESLOTS; i++) - if (!FREE_SKINCOLORS[i]) { + for (i = SKINCOLOR_FIRSTFREESLOT; i < MAXSKINCOLORS; i++) + if (!skincolors[i].nameofs) { CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word); - FREE_SKINCOLORS[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); - strcpy(FREE_SKINCOLORS[i],word); + skincolors[i].nameofs = strbuf_append(&skincolornames, word); M_AddMenuColor(numskincolors++); K_ReloadHUDColorCvar(); - lua_pushinteger(L, SKINCOLOR_FIRSTFREESLOT + i); + lua_pushinteger(L, i); r++; break; } - if (i == NUMCOLORFREESLOTS) + if (i == MAXSKINCOLORS) CONS_Alert(CONS_WARNING, "Ran out of free skincolor slots!\n"); } else if (fastcmp(type, "SPR2")) @@ -588,19 +587,14 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word) } else if (fastncmp("SKINCOLOR_",word,10)) { p = word+10; - for (i = 0; i < NUMCOLORFREESLOTS; i++) { - if (!FREE_SKINCOLORS[i]) + for (i = 0; i < MAXSKINCOLORS; i++) { + if (!skincolors[i].nameofs) break; - if (fastcmp(p, FREE_SKINCOLORS[i])) { - CacheAndPushConstant(L, word, SKINCOLOR_FIRSTFREESLOT+i); - return 1; - } - } - for (i = 0; i < SKINCOLOR_FIRSTFREESLOT; i++) - if (fastcmp(p, COLOR_ENUMS[i])) { + if (fastcmp(p, strbuf_get(skincolornames, skincolors[i].nameofs))) { CacheAndPushConstant(L, word, i); return 1; } + } return luaL_error(L, "skincolor '%s' could not be found.\n", word); } else if (fastncmp("MN_",word,3)) { diff --git a/src/deh_soc.c b/src/deh_soc.c index 909760398..564127ef4 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -464,11 +464,10 @@ void readfreeslots(MYFILE *f) } else if (fastcmp(type, "SKINCOLOR")) { - for (i = 0; i < NUMCOLORFREESLOTS; i++) - if (!FREE_SKINCOLORS[i]) { + for (i = SKINCOLOR_FIRSTFREESLOT; i < MAXSKINCOLORS; i++) + if (!skincolors[i].nameofs) { CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word); - FREE_SKINCOLORS[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); - strcpy(FREE_SKINCOLORS[i],word); + skincolors[i].nameofs = strbuf_append(&skincolornames, word); M_AddMenuColor(numskincolors++); K_ReloadHUDColorCvar(); break; @@ -4298,15 +4297,12 @@ skincolornum_t get_skincolor(const char *word) return atoi(word); if (fastncmp("SKINCOLOR_",word,10)) word += 10; // take off the SKINCOLOR_ - for (i = 0; i < NUMCOLORFREESLOTS; i++) { - if (!FREE_SKINCOLORS[i]) + for (i = 0; i < MAXSKINCOLORS; i++) { + if (!skincolors[i].nameofs) break; - if (fastcmp(word, FREE_SKINCOLORS[i])) - return SKINCOLOR_FIRSTFREESLOT+i; - } - for (i = 0; i < SKINCOLOR_FIRSTFREESLOT; i++) - if (fastcmp(word, COLOR_ENUMS[i])) + if (fastcmp(word, strbuf_get(skincolornames, skincolors[i].nameofs))) return i; + } deh_warning("Couldn't find skincolor named 'SKINCOLOR_%s'",word); return -1; } diff --git a/src/deh_tables.c b/src/deh_tables.c index 57229a2ee..92f522e21 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -34,7 +34,7 @@ strbuf_t *statenames; strbuf_t *mobjnames; -char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; +strbuf_t *skincolornames; char *FREE_MENUS[NUMMENUFREESLOTS]; 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. @@ -427,12 +427,6 @@ const char *const TO_LIST[] = { NULL }; -const char *COLOR_ENUMS[] = { -#define _(name, ...) #name, -#include "info/skincolors.h" -#undef _ -}; - const char *const POWERS_LIST[] = { "INVULNERABILITY", "SNEAKERS", @@ -1511,15 +1505,3 @@ struct int_const_s const INT_CONST[] = { {NULL,0} }; - -// For this to work compile-time without being in this file, -// this function would need to check sizes at runtime, without sizeof -void DEH_TableCheck(void) -{ -#if defined(_DEBUG) || defined(PARANOIA) - const size_t dehcolors = sizeof(COLOR_ENUMS)/sizeof(const char*); - - if (dehcolors != SKINCOLOR_FIRSTFREESLOT) - I_Error("You forgot to update the Dehacked colors list, you dolt!\n(%d colors defined, versus %s in the Dehacked list)\n", SKINCOLOR_FIRSTFREESLOT, sizeu1(dehcolors)); -#endif -} diff --git a/src/deh_tables.h b/src/deh_tables.h index 5071e7a2b..2169d6a40 100644 --- a/src/deh_tables.h +++ b/src/deh_tables.h @@ -28,14 +28,14 @@ extern "C" { // The crazy word-reading stuff uses these. extern strbuf_t *statenames; extern strbuf_t *mobjnames; -extern char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; +extern strbuf_t *skincolornames; extern char *FREE_MENUS[NUMMENUFREESLOTS]; extern 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() {\ statenames = strbuf_alloc();\ mobjnames = strbuf_alloc();\ - memset(FREE_SKINCOLORS,0,sizeof(char *) * NUMCOLORFREESLOTS);\ + skincolornames = strbuf_alloc();\ memset(used_spr,0,sizeof(UINT8) * ((NUMSPRITEFREESLOTS / 8) + 1));\ } @@ -87,7 +87,6 @@ extern const char *const MSF_LIST[]; // Sector flags extern const char *const SSF_LIST[]; // Sector special flags extern const char *const SD_LIST[]; // Sector damagetype extern const char *const TO_LIST[]; // Sector triggerer -extern const char *COLOR_ENUMS[]; extern const char *const POWERS_LIST[]; extern const char *const KARTSTUFF_LIST[]; extern const char *const KARTHUD_LIST[]; @@ -98,9 +97,6 @@ extern struct menu_drawer_s const MENU_DRAWERS[]; extern struct int_const_s const INT_CONST[]; -// Moved to this file because it can't work compile-time otherwise -void DEH_TableCheck(void); - #ifdef __cplusplus } // extern "C" #endif diff --git a/src/dehacked.c b/src/dehacked.c index daa45d795..daf240f36 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -188,6 +188,12 @@ static const char *hardcodestates = #undef _ ; +static const char *hardcodeskincolors = +#define _(name, ...) #name "\0" +#include "info/skincolors.h" +#undef _ +; + static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) { char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); @@ -208,6 +214,10 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) name = hardcodestates; for (i = 0; i < S_FIRSTFREESLOT; i++, name += strlen(name)+1) states[i].nameofs = strbuf_append(&statenames, name); + + name = hardcodeskincolors; + for (i = 0; i < SKINCOLOR_FIRSTFREESLOT; i++, name += strlen(name)+1) + skincolors[i].nameofs = strbuf_append(&skincolornames, name); } deh_num_warning = 0; diff --git a/src/dehacked.h b/src/dehacked.h index f32cfd579..fca5c4b15 100644 --- a/src/dehacked.h +++ b/src/dehacked.h @@ -38,8 +38,6 @@ void DEH_LoadDehackedLumpPwad(UINT16 wad, UINT16 lump, boolean mainfile); extern int freeslotusage[2][2]; void DEH_UpdateMaxFreeslots(void); -void DEH_Check(void); - fixed_t get_number(const char *word); FUNCPRINTF void deh_warning(const char *first, ...); void deh_strlcpy(char *dst, const char *src, size_t size, const char *warntext); diff --git a/src/doomdef.h b/src/doomdef.h index 4a5f83f0b..5b85038f8 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -222,6 +222,7 @@ extern char logfilename[1024]; struct skincolor_t { + UINT32 nameofs; // Offset for internal name char name[MAXCOLORNAME+1]; // Skincolor name UINT8 ramp[COLORRAMPSIZE]; // Colormap ramp UINT16 invcolor; // Signpost color diff --git a/src/p_setup.c b/src/p_setup.c index 127891d12..b1ccec8a5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1185,10 +1185,7 @@ static void P_WriteSkincolor(INT32 constant, char **target) || constant >= (INT32)numskincolors) return; - if (constant >= SKINCOLOR_FIRSTFREESLOT) - color_name = FREE_SKINCOLORS[constant - SKINCOLOR_FIRSTFREESLOT]; - else - color_name = COLOR_ENUMS[constant]; + color_name = strbuf_get(skincolornames, skincolors[constant].nameofs); P_WriteDuplicateText( va("SKINCOLOR_%s", color_name),