Why stop there? Go for skincolors too :^)

This commit is contained in:
GenericHeroGuy 2025-05-14 16:06:11 +02:00
parent 1793c2ea95
commit 1b095d220e
9 changed files with 31 additions and 60 deletions

View file

@ -1277,9 +1277,6 @@ void D_SRB2Main(void)
// MAINCFG is now taken care of where "OBJCTCFG" is handled // MAINCFG is now taken care of where "OBJCTCFG" is handled
G_LoadGameSettings(); G_LoadGameSettings();
// Test Dehacked lists
DEH_TableCheck();
// Netgame URL special case: change working dir to EXE folder. // Netgame URL special case: change working dir to EXE folder.
ChangeDirForUrlHandler(); ChangeDirForUrlHandler();

View file

@ -111,18 +111,17 @@ static inline int lib_freeslot(lua_State *L)
else if (fastcmp(type, "SKINCOLOR")) else if (fastcmp(type, "SKINCOLOR"))
{ {
skincolornum_t i; skincolornum_t i;
for (i = 0; i < NUMCOLORFREESLOTS; i++) for (i = SKINCOLOR_FIRSTFREESLOT; i < MAXSKINCOLORS; i++)
if (!FREE_SKINCOLORS[i]) { if (!skincolors[i].nameofs) {
CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word); CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word);
FREE_SKINCOLORS[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); skincolors[i].nameofs = strbuf_append(&skincolornames, word);
strcpy(FREE_SKINCOLORS[i],word);
M_AddMenuColor(numskincolors++); M_AddMenuColor(numskincolors++);
K_ReloadHUDColorCvar(); K_ReloadHUDColorCvar();
lua_pushinteger(L, SKINCOLOR_FIRSTFREESLOT + i); lua_pushinteger(L, i);
r++; r++;
break; break;
} }
if (i == NUMCOLORFREESLOTS) if (i == MAXSKINCOLORS)
CONS_Alert(CONS_WARNING, "Ran out of free skincolor slots!\n"); CONS_Alert(CONS_WARNING, "Ran out of free skincolor slots!\n");
} }
else if (fastcmp(type, "SPR2")) 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)) { else if (fastncmp("SKINCOLOR_",word,10)) {
p = word+10; p = word+10;
for (i = 0; i < NUMCOLORFREESLOTS; i++) { for (i = 0; i < MAXSKINCOLORS; i++) {
if (!FREE_SKINCOLORS[i]) if (!skincolors[i].nameofs)
break; break;
if (fastcmp(p, FREE_SKINCOLORS[i])) { if (fastcmp(p, strbuf_get(skincolornames, skincolors[i].nameofs))) {
CacheAndPushConstant(L, word, SKINCOLOR_FIRSTFREESLOT+i);
return 1;
}
}
for (i = 0; i < SKINCOLOR_FIRSTFREESLOT; i++)
if (fastcmp(p, COLOR_ENUMS[i])) {
CacheAndPushConstant(L, word, i); CacheAndPushConstant(L, word, i);
return 1; return 1;
} }
}
return luaL_error(L, "skincolor '%s' could not be found.\n", word); return luaL_error(L, "skincolor '%s' could not be found.\n", word);
} }
else if (fastncmp("MN_",word,3)) { else if (fastncmp("MN_",word,3)) {

View file

@ -464,11 +464,10 @@ void readfreeslots(MYFILE *f)
} }
else if (fastcmp(type, "SKINCOLOR")) else if (fastcmp(type, "SKINCOLOR"))
{ {
for (i = 0; i < NUMCOLORFREESLOTS; i++) for (i = SKINCOLOR_FIRSTFREESLOT; i < MAXSKINCOLORS; i++)
if (!FREE_SKINCOLORS[i]) { if (!skincolors[i].nameofs) {
CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word); CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word);
FREE_SKINCOLORS[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); skincolors[i].nameofs = strbuf_append(&skincolornames, word);
strcpy(FREE_SKINCOLORS[i],word);
M_AddMenuColor(numskincolors++); M_AddMenuColor(numskincolors++);
K_ReloadHUDColorCvar(); K_ReloadHUDColorCvar();
break; break;
@ -4298,15 +4297,12 @@ skincolornum_t get_skincolor(const char *word)
return atoi(word); return atoi(word);
if (fastncmp("SKINCOLOR_",word,10)) if (fastncmp("SKINCOLOR_",word,10))
word += 10; // take off the SKINCOLOR_ word += 10; // take off the SKINCOLOR_
for (i = 0; i < NUMCOLORFREESLOTS; i++) { for (i = 0; i < MAXSKINCOLORS; i++) {
if (!FREE_SKINCOLORS[i]) if (!skincolors[i].nameofs)
break; break;
if (fastcmp(word, FREE_SKINCOLORS[i])) if (fastcmp(word, strbuf_get(skincolornames, skincolors[i].nameofs)))
return SKINCOLOR_FIRSTFREESLOT+i;
}
for (i = 0; i < SKINCOLOR_FIRSTFREESLOT; i++)
if (fastcmp(word, COLOR_ENUMS[i]))
return i; return i;
}
deh_warning("Couldn't find skincolor named 'SKINCOLOR_%s'",word); deh_warning("Couldn't find skincolor named 'SKINCOLOR_%s'",word);
return -1; return -1;
} }

View file

@ -34,7 +34,7 @@
strbuf_t *statenames; strbuf_t *statenames;
strbuf_t *mobjnames; strbuf_t *mobjnames;
char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; strbuf_t *skincolornames;
char *FREE_MENUS[NUMMENUFREESLOTS]; 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. 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 NULL
}; };
const char *COLOR_ENUMS[] = {
#define _(name, ...) #name,
#include "info/skincolors.h"
#undef _
};
const char *const POWERS_LIST[] = { const char *const POWERS_LIST[] = {
"INVULNERABILITY", "INVULNERABILITY",
"SNEAKERS", "SNEAKERS",
@ -1511,15 +1505,3 @@ struct int_const_s const INT_CONST[] = {
{NULL,0} {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
}

View file

@ -28,14 +28,14 @@ extern "C" {
// The crazy word-reading stuff uses these. // The crazy word-reading stuff uses these.
extern strbuf_t *statenames; extern strbuf_t *statenames;
extern strbuf_t *mobjnames; extern strbuf_t *mobjnames;
extern char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; extern strbuf_t *skincolornames;
extern char *FREE_MENUS[NUMMENUFREESLOTS]; 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. 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() {\ #define initfreeslots() {\
statenames = strbuf_alloc();\ statenames = strbuf_alloc();\
mobjnames = strbuf_alloc();\ mobjnames = strbuf_alloc();\
memset(FREE_SKINCOLORS,0,sizeof(char *) * NUMCOLORFREESLOTS);\ skincolornames = strbuf_alloc();\
memset(used_spr,0,sizeof(UINT8) * ((NUMSPRITEFREESLOTS / 8) + 1));\ 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 SSF_LIST[]; // Sector special flags
extern const char *const SD_LIST[]; // Sector damagetype extern const char *const SD_LIST[]; // Sector damagetype
extern const char *const TO_LIST[]; // Sector triggerer extern const char *const TO_LIST[]; // Sector triggerer
extern const char *COLOR_ENUMS[];
extern const char *const POWERS_LIST[]; extern const char *const POWERS_LIST[];
extern const char *const KARTSTUFF_LIST[]; extern const char *const KARTSTUFF_LIST[];
extern const char *const KARTHUD_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[]; 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 #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif

View file

@ -188,6 +188,12 @@ static const char *hardcodestates =
#undef _ #undef _
; ;
static const char *hardcodeskincolors =
#define _(name, ...) #name "\0"
#include "info/skincolors.h"
#undef _
;
static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
{ {
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
@ -208,6 +214,10 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
name = hardcodestates; name = hardcodestates;
for (i = 0; i < S_FIRSTFREESLOT; i++, name += strlen(name)+1) for (i = 0; i < S_FIRSTFREESLOT; i++, name += strlen(name)+1)
states[i].nameofs = strbuf_append(&statenames, name); 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; deh_num_warning = 0;

View file

@ -38,8 +38,6 @@ void DEH_LoadDehackedLumpPwad(UINT16 wad, UINT16 lump, boolean mainfile);
extern int freeslotusage[2][2]; extern int freeslotusage[2][2];
void DEH_UpdateMaxFreeslots(void); void DEH_UpdateMaxFreeslots(void);
void DEH_Check(void);
fixed_t get_number(const char *word); fixed_t get_number(const char *word);
FUNCPRINTF void deh_warning(const char *first, ...); FUNCPRINTF void deh_warning(const char *first, ...);
void deh_strlcpy(char *dst, const char *src, size_t size, const char *warntext); void deh_strlcpy(char *dst, const char *src, size_t size, const char *warntext);

View file

@ -222,6 +222,7 @@ extern char logfilename[1024];
struct skincolor_t struct skincolor_t
{ {
UINT32 nameofs; // Offset for internal name
char name[MAXCOLORNAME+1]; // Skincolor name char name[MAXCOLORNAME+1]; // Skincolor name
UINT8 ramp[COLORRAMPSIZE]; // Colormap ramp UINT8 ramp[COLORRAMPSIZE]; // Colormap ramp
UINT16 invcolor; // Signpost color UINT16 invcolor; // Signpost color

View file

@ -1185,10 +1185,7 @@ static void P_WriteSkincolor(INT32 constant, char **target)
|| constant >= (INT32)numskincolors) || constant >= (INT32)numskincolors)
return; return;
if (constant >= SKINCOLOR_FIRSTFREESLOT) color_name = strbuf_get(skincolornames, skincolors[constant].nameofs);
color_name = FREE_SKINCOLORS[constant - SKINCOLOR_FIRSTFREESLOT];
else
color_name = COLOR_ENUMS[constant];
P_WriteDuplicateText( P_WriteDuplicateText(
va("SKINCOLOR_%s", color_name), va("SKINCOLOR_%s", color_name),