Screw checking for nameofs being zero, just keep count of mobjs/states

This commit is contained in:
GenericHeroGuy 2025-05-18 14:46:24 +02:00
parent 4e66cb67a8
commit c3fe5e80ac
8 changed files with 36 additions and 39 deletions

View file

@ -111,7 +111,7 @@ static void CacheAndPushConstant(lua_State *L, const char *name, lua_Integer val
static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
{
const char *p;
fixed_t i;
size_t i;
if (strlen(word) == 1) { // Assume sprite frame if length 1.
if (*word >= 'A' && *word <= '~')
@ -285,9 +285,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
lua_pushinteger(L, S_FIRSTFREESLOT);
return 1;
}
for (i = 0; i < NUMSTATES; i++) {
if (!states[i].nameofs)
break;
for (i = 0; i < numstates; i++) {
if (fastcmp(p, strbuf_get(statenames, states[i].nameofs))) {
CacheAndPushConstant(L, word, i);
return 1;
@ -308,9 +306,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
lua_pushinteger(L, MT_FIRSTFREESLOT);
return 1;
}
for (i = 0; i < NUMMOBJTYPES; i++) {
if (!mobjinfo[i].nameofs)
break;
for (i = 0; i < nummobjtypes ; i++) {
if (fastcmp(p, strbuf_get(mobjnames, mobjinfo[i].nameofs))) {
CacheAndPushConstant(L, word, i);
return 1;
@ -346,7 +342,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
}
else if (fastncmp("SPR2_",word,5)) {
p = word+5;
for (i = 0; i < (fixed_t)free_spr2; i++)
for (i = 0; i < free_spr2; i++)
if (!spr2names[i][4])
{
// special 3-char cases, e.g. SPR2_RUN
@ -449,9 +445,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
}
else if (fastncmp("SKINCOLOR_",word,10)) {
p = word+10;
for (i = 0; i < MAXSKINCOLORS; i++) {
if (!skincolors[i].nameofs)
break;
for (i = 0; i < numskincolors; i++) {
if (fastcmp(p, strbuf_get(skincolornames, skincolors[i].nameofs))) {
CacheAndPushConstant(L, word, i);
return 1;
@ -461,9 +455,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
}
else if (fastncmp("MN_",word,3)) {
p = word+3;
for (i = 0; i < NUMMENUTYPES; i++) {
if (!menudefs[i].nameofs)
break;
for (i = 0; i < nummenutypes; i++) {
if (fastcmp(p, strbuf_get(menunames, menudefs[i].nameofs)) ){
CacheAndPushConstant(L, word, i);
return 1;

View file

@ -4126,9 +4126,7 @@ mobjtype_t get_mobjtype(const char *word)
return atoi(word);
if (fastncmp("MT_",word,3))
word += 3; // take off the MT_
for (i = 0; i < NUMMOBJTYPES; i++) {
if (!mobjinfo[i].nameofs)
break;
for (i = 0; i < nummobjtypes; i++) {
if (fastcmp(word, strbuf_get(mobjnames, mobjinfo[i].nameofs)))
return i;
}
@ -4143,9 +4141,7 @@ statenum_t get_state(const char *word)
return atoi(word);
if (fastncmp("S_",word,2))
word += 2; // take off the S_
for (i = 0; i < NUMSTATES; i++) {
if (!states[i].nameofs)
break;
for (i = 0; i < numstates; i++) {
if (fastcmp(word, strbuf_get(statenames, states[i].nameofs)))
return i;
}
@ -4160,9 +4156,7 @@ 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 < MAXSKINCOLORS; i++) {
if (!skincolors[i].nameofs)
break;
for (i = 0; i < numskincolors; i++) {
if (fastcmp(word, strbuf_get(skincolornames, skincolors[i].nameofs)))
return i;
}
@ -4221,9 +4215,7 @@ menutype_t get_menutype(const char *word)
return atoi(word);
if (fastncmp("MN_",word,3))
word += 3; // take off the MN_
for (i = 0; i < NUMMENUTYPES; i++) {
if (!menudefs[i].nameofs)
break;
for (i = 0; i < nummenutypes; i++) {
if (fastcmp(word, strbuf_get(menunames, menudefs[i].nameofs)))
return i;
}

View file

@ -16,7 +16,6 @@
#include "doomdef.h" // Constants
#include "d_think.h" // actionf_t
#include "info.h" // Mobj, state, sprite, etc constants
#include "m_menu.h" // NUMMENUFREESLOTS
#include "lua_script.h"
#include "strbuf.h"

View file

@ -218,6 +218,7 @@ INT32 DEH_ReadFreeslot(const char *type, const char *word, INT32 *out)
if (!states[i].nameofs) {
CONS_Printf("State S_%s allocated.\n",word);
states[i].nameofs = strbuf_append(&statenames, word);
numstates++;
freeslotusage[0][0]++;
*out = i;
return 0;
@ -231,6 +232,7 @@ INT32 DEH_ReadFreeslot(const char *type, const char *word, INT32 *out)
if (!mobjinfo[i].nameofs) {
CONS_Printf("MobjType MT_%s allocated.\n",word);
mobjinfo[i].nameofs = strbuf_append(&mobjnames, word);
nummobjtypes++;
freeslotusage[1][0]++;
*out = i;
return 0;
@ -320,10 +322,11 @@ INT32 DEH_ReadFreeslot(const char *type, const char *word, INT32 *out)
}
else if (fastcmp(type, "MN"))
{
for (i = MN_FIRSTFREESLOT; i < NUMMENUTYPES; i++) {
for (i = MN_FIRSTFREESLOT; i < MAXMENUTYPES; i++) {
if (!menudefs[i].nameofs) {
CONS_Printf("Menu MN_%s allocated.\n",word);
menudefs[i].nameofs = strbuf_append(&menunames, word);
nummenutypes++;
*out = i;
return 0;
}
@ -632,12 +635,12 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
if (i == 0 && word2[0] != '0') // If word2 isn't a number
i = get_menutype(word2); // find a huditem by name
if (i >= 1 && i < NUMMENUTYPES)
if (i >= 1 && i < nummenutypes)
readmenu(f, i);
else
{
// zero-based, but let's start at 1
deh_warning("Menu number %d out of range (1 - %d)", i, NUMMENUTYPES-1);
deh_warning("Menu number %d out of range (1 - %d)", i, nummenutypes-1);
ignorelines(f);
}
}

View file

@ -81,8 +81,10 @@ playersprite_t spr2defaults[NUMPLAYERSPRITES] = {
// Doesn't work with g++, needs actionf_p1 (don't modify this comment)
state_t states[NUMSTATES] = {0};
size_t numstates;
mobjinfo_t mobjinfo[NUMMOBJTYPES] = {0};
size_t nummobjtypes;
skincolor_t skincolors[MAXSKINCOLORS] = {0};
@ -145,6 +147,8 @@ void P_ResetData(INT32 flags)
if (!init)
memset(states, 0, sizeof(states));
numstates = S_FIRSTFREESLOT;
if (statenames)
Z_Free(statenames);
statenames = strbuf_alloc();
@ -165,6 +169,8 @@ void P_ResetData(INT32 flags)
if (!init)
memset(mobjinfo, 0, sizeof(mobjinfo));
nummobjtypes = MT_FIRSTFREESLOT;
if (mobjnames)
Z_Free(mobjnames);
mobjnames = strbuf_alloc();
@ -211,10 +217,12 @@ void P_ResetData(INT32 flags)
// menudefs (TODO: actually reset this with resetdata?)
if (init)
{
memset(&menudefs[MN_FIRSTFREESLOT], 0, sizeof (menu_t) * NUMMENUFREESLOTS);
for (i = 0; i < NUMMENUTYPES; i++)
memset(menudefs, 0, sizeof(menudefs));
for (i = 0; i < MAXMENUTYPES; i++)
menudefs[i].drawroutine = M_DrawGenericMenu;
nummenutypes = MN_FIRSTFREESLOT;
if (menunames)
Z_Free(menunames);
menunames = strbuf_alloc();

View file

@ -91,6 +91,7 @@ struct state_t
};
extern state_t states[NUMSTATES];
extern size_t numstates;
extern char sprnames[NUMSPRITES + 1][5];
extern char spr2names[NUMPLAYERSPRITES][5];
extern playersprite_t spr2defaults[NUMPLAYERSPRITES];
@ -138,6 +139,7 @@ struct mobjinfo_t
};
extern mobjinfo_t mobjinfo[NUMMOBJTYPES];
extern size_t nummobjtypes;
void P_ResetData(INT32 flags);

View file

@ -166,7 +166,8 @@ static UINT32 serverlistpage;
INT16 startmap; // Mario, NiGHTS, or just a plain old normal game?
menu_t menudefs[NUMMENUTYPES]; // array of all menudefs
menu_t menudefs[MAXMENUTYPES]; // array of all menudefs
size_t nummenutypes;
menutype_t menustack[NUMMENULEVELS]; // stack of active menus, [0] == current menu
static menu_t *currentMenu; // current menudef
static INT16 itemOn = 1; // menu item skull is on, Hack by Tails 09-18-2002
@ -754,7 +755,7 @@ void Moviemode_option_Onchange(void)
// MENU PRESENTATION PARAMETER HANDLING (BACKGROUNDS)
// =========================================================================
menupres_t menupres[NUMMENUTYPES];
menupres_t menupres[MAXMENUTYPES];
void M_InitMenuPresTables(void)
{
@ -762,7 +763,7 @@ void M_InitMenuPresTables(void)
// Called in d_main before SOC can get to the tables
// Set menupres defaults
for (i = 0; i < NUMMENUTYPES; i++)
for (i = 0; i < MAXMENUTYPES; i++)
{
// so-called "undefined"
menupres[i].fadestrength = -1;

View file

@ -46,9 +46,8 @@ typedef enum
MN_FIRSTFREESLOT,
MN_LASTFREESLOT = MN_FIRSTFREESLOT + 128,
NUMMENUTYPES,
MAXMENUTYPES,
} menutype_t;
#define NUMMENUFREESLOTS (NUMMENUTYPES - MN_FIRSTFREESLOT)
extern menutype_t menustack[NUMMENULEVELS];
@ -84,7 +83,7 @@ typedef struct
INT16 exitwipe; // wipe type to run on menu exit, -1 means default
} menupres_t;
extern menupres_t menupres[NUMMENUTYPES];
extern menupres_t menupres[MAXMENUTYPES];
void M_InitMenuPresTables(void);
//UINT8 M_GetYoungestChildMenu(void);
@ -258,7 +257,8 @@ struct menu_t
void (*quitroutine)(INT32 choice); // called before quit a menu
};
extern menu_t menudefs[NUMMENUTYPES];
extern menu_t menudefs[MAXMENUTYPES];
extern size_t nummenutypes;
void M_EnterMenu(menutype_t menu, boolean callexit);
void M_ExitMenu(void);