Add name hashing for supported info types

This commit is contained in:
GenericHeroGuy 2025-05-18 18:13:04 +02:00
parent 0009807746
commit 1d0a066590
6 changed files with 32 additions and 7 deletions

View file

@ -62,7 +62,10 @@ const char *DEH_MenutypeName(menutype_t i)
mobjtype_t DEH_FindMobjtype(const char *word) mobjtype_t DEH_FindMobjtype(const char *word)
{ {
mobjtype_t i; mobjtype_t i;
UINT32 hash = HASH32(word, strlen(word));
for (i = 0; i < nummobjtypes; i++) { for (i = 0; i < nummobjtypes; i++) {
if (hash != mobjinfo[i].namehash)
continue;
if (fastcmp(word, DEH_MobjtypeName(i))) if (fastcmp(word, DEH_MobjtypeName(i)))
return i; return i;
} }
@ -72,7 +75,10 @@ mobjtype_t DEH_FindMobjtype(const char *word)
statenum_t DEH_FindState(const char *word) statenum_t DEH_FindState(const char *word)
{ {
statenum_t i; statenum_t i;
UINT32 hash = HASH32(word, strlen(word));
for (i = 0; i < numstates; i++) { for (i = 0; i < numstates; i++) {
if (hash != states[i].namehash)
continue;
if (fastcmp(word, DEH_StateName(i))) if (fastcmp(word, DEH_StateName(i)))
return i; return i;
} }
@ -82,7 +88,10 @@ statenum_t DEH_FindState(const char *word)
skincolornum_t DEH_FindSkincolor(const char *word) skincolornum_t DEH_FindSkincolor(const char *word)
{ {
skincolornum_t i; skincolornum_t i;
UINT32 hash = HASH32(word, strlen(word));
for (i = 0; i < numskincolors; i++) { for (i = 0; i < numskincolors; i++) {
if (hash != skincolors[i].namehash)
continue;
if (fastcmp(word, DEH_SkincolorName(i))) if (fastcmp(word, DEH_SkincolorName(i)))
return i; return i;
} }
@ -92,7 +101,10 @@ skincolornum_t DEH_FindSkincolor(const char *word)
menutype_t DEH_FindMenutype(const char *word) menutype_t DEH_FindMenutype(const char *word)
{ {
menutype_t i; menutype_t i;
UINT32 hash = HASH32(word, strlen(word));
for (i = 0; i < nummenutypes; i++) { for (i = 0; i < nummenutypes; i++) {
if (hash != menudefs[i].namehash)
continue;
if (fastcmp(word, DEH_MenutypeName(i))) if (fastcmp(word, DEH_MenutypeName(i)))
return i; return i;
} }

View file

@ -218,6 +218,7 @@ INT32 DEH_ReadFreeslot(const char *type, const char *word, INT32 *out)
if (!states[i].nameofs) { if (!states[i].nameofs) {
CONS_Printf("State S_%s allocated.\n",word); CONS_Printf("State S_%s allocated.\n",word);
states[i].nameofs = strbuf_append(&statenames, word); states[i].nameofs = strbuf_append(&statenames, word);
states[i].namehash = HASH32(word, strlen(word));
numstates++; numstates++;
freeslotusage[0][0]++; freeslotusage[0][0]++;
*out = i; *out = i;
@ -232,6 +233,7 @@ INT32 DEH_ReadFreeslot(const char *type, const char *word, INT32 *out)
if (!mobjinfo[i].nameofs) { if (!mobjinfo[i].nameofs) {
CONS_Printf("MobjType MT_%s allocated.\n",word); CONS_Printf("MobjType MT_%s allocated.\n",word);
mobjinfo[i].nameofs = strbuf_append(&mobjnames, word); mobjinfo[i].nameofs = strbuf_append(&mobjnames, word);
mobjinfo[i].namehash = HASH32(word, strlen(word));
nummobjtypes++; nummobjtypes++;
freeslotusage[1][0]++; freeslotusage[1][0]++;
*out = i; *out = i;
@ -246,6 +248,7 @@ INT32 DEH_ReadFreeslot(const char *type, const char *word, INT32 *out)
if (!skincolors[i].nameofs) { if (!skincolors[i].nameofs) {
CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word); CONS_Printf("Skincolor SKINCOLOR_%s allocated.\n",word);
skincolors[i].nameofs = strbuf_append(&skincolornames, word); skincolors[i].nameofs = strbuf_append(&skincolornames, word);
skincolors[i].namehash = HASH32(word, strlen(word));
M_AddMenuColor(numskincolors++); M_AddMenuColor(numskincolors++);
K_ReloadHUDColorCvar(); K_ReloadHUDColorCvar();
*out = i; *out = i;
@ -326,6 +329,7 @@ INT32 DEH_ReadFreeslot(const char *type, const char *word, INT32 *out)
if (!menudefs[i].nameofs) { if (!menudefs[i].nameofs) {
CONS_Printf("Menu MN_%s allocated.\n",word); CONS_Printf("Menu MN_%s allocated.\n",word);
menudefs[i].nameofs = strbuf_append(&menunames, word); menudefs[i].nameofs = strbuf_append(&menunames, word);
menudefs[i].namehash = HASH32(word, strlen(word));
nummenutypes++; nummenutypes++;
*out = i; *out = i;
return 0; return 0;

View file

@ -222,6 +222,7 @@ extern char logfilename[1024];
struct skincolor_t struct skincolor_t
{ {
UINT32 namehash; // Hash for internal name
UINT32 nameofs; // Offset for internal name 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

View file

@ -153,8 +153,10 @@ void P_ResetData(INT32 flags)
Z_Free(statenames); Z_Free(statenames);
statenames = strbuf_alloc(); statenames = strbuf_alloc();
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);
states[i].namehash = HASH32(name, strlen(name));
}
if (!init) if (!init)
{ {
@ -175,8 +177,10 @@ void P_ResetData(INT32 flags)
Z_Free(mobjnames); Z_Free(mobjnames);
mobjnames = strbuf_alloc(); mobjnames = strbuf_alloc();
name = hardcodemobjs; name = hardcodemobjs;
for (i = 0; i < MT_FIRSTFREESLOT; i++, name += strlen(name)+1) for (i = 0; i < MT_FIRSTFREESLOT; i++, name += strlen(name)+1) {
mobjinfo[i].nameofs = strbuf_append(&mobjnames, name); mobjinfo[i].nameofs = strbuf_append(&mobjnames, name);
mobjinfo[i].namehash = HASH32(name, strlen(name));
}
for (i = MT_FIRSTFREESLOT; i <= MT_LASTFREESLOT; i++) for (i = MT_FIRSTFREESLOT; i <= MT_LASTFREESLOT; i++)
mobjinfo[i].doomednum = -1; mobjinfo[i].doomednum = -1;
@ -198,8 +202,10 @@ void P_ResetData(INT32 flags)
Z_Free(skincolornames); Z_Free(skincolornames);
skincolornames = strbuf_alloc(); skincolornames = strbuf_alloc();
name = hardcodeskincolors; name = hardcodeskincolors;
for (i = 0; i < SKINCOLOR_FIRSTFREESLOT; i++, name += strlen(name)+1) for (i = 0; i < SKINCOLOR_FIRSTFREESLOT; i++, name += strlen(name)+1) {
skincolors[i].nameofs = strbuf_append(&skincolornames, name); skincolors[i].nameofs = strbuf_append(&skincolornames, name);
skincolors[i].namehash = HASH32(name, strlen(name));
}
for (i = SKINCOLOR_FIRSTFREESLOT; i <= SKINCOLOR_LASTFREESLOT; i++) for (i = SKINCOLOR_FIRSTFREESLOT; i <= SKINCOLOR_LASTFREESLOT; i++)
{ {
@ -227,7 +233,9 @@ void P_ResetData(INT32 flags)
Z_Free(menunames); Z_Free(menunames);
menunames = strbuf_alloc(); menunames = strbuf_alloc();
name = hardcodemenus; name = hardcodemenus;
for (i = 0; i < MN_FIRSTFREESLOT; i++, name += strlen(name)+1) for (i = 0; i < MN_FIRSTFREESLOT; i++, name += strlen(name)+1) {
menudefs[i].nameofs = strbuf_append(&menunames, name); menudefs[i].nameofs = strbuf_append(&menunames, name);
menudefs[i].namehash = HASH32(name, strlen(name));
}
} }
} }

View file

@ -79,7 +79,7 @@ typedef enum state
struct state_t struct state_t
{ {
UINT32 nameofs; UINT32 namehash, nameofs;
spritenum_t sprite; spritenum_t sprite;
UINT32 frame; // we use the upper 16 bits for translucency and other shade effects UINT32 frame; // we use the upper 16 bits for translucency and other shade effects
@ -110,7 +110,7 @@ typedef enum mobj_type
struct mobjinfo_t struct mobjinfo_t
{ {
UINT32 nameofs; UINT32 namehash, nameofs;
INT32 doomednum; INT32 doomednum;
statenum_t spawnstate; statenum_t spawnstate;

View file

@ -247,7 +247,7 @@ struct menuitem_t
struct menu_t struct menu_t
{ {
UINT32 nameofs; UINT32 namehash, nameofs;
const char *headerpic; const char *headerpic;
INT16 numitems; // # of menu items INT16 numitems; // # of menu items
menuitem_t *menuitems; // menu items menuitem_t *menuitems; // menu items