Unify info lookup functions for SOC/Lua/ACS
Use MAX* constants instead of -1 for invalid values, because enum signedness is implementation-defined
This commit is contained in:
parent
95ae54fd08
commit
0009807746
10 changed files with 140 additions and 88 deletions
|
|
@ -83,21 +83,13 @@ static bool ACS_GetMobjTypeFromString(const char *word, mobjtype_t *type)
|
|||
word += 3;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUMMOBJTYPES; i++)
|
||||
{
|
||||
if (!mobjinfo[i].nameofs)
|
||||
{
|
||||
break;
|
||||
}
|
||||
mobjtype_t i = DEH_FindMobjtype(word);
|
||||
|
||||
if (fastcmp(word, strbuf_get(mobjnames, mobjinfo[i].nameofs)))
|
||||
{
|
||||
*type = static_cast<mobjtype_t>(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (i == NUMMOBJTYPES)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
*type = i;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
|
|
@ -225,21 +217,13 @@ static bool ACS_GetStateFromString(const char *word, statenum_t *type)
|
|||
word += 2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUMSTATES; i++)
|
||||
{
|
||||
if (!states[i].nameofs)
|
||||
{
|
||||
break;
|
||||
}
|
||||
statenum_t i = DEH_FindState(word);
|
||||
|
||||
if (fastcmp(word, strbuf_get(statenames, states[i].nameofs)))
|
||||
{
|
||||
*type = static_cast<statenum_t>(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (i == NUMSTATES)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
*type = i;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
|
|
@ -2319,7 +2303,7 @@ bool CallFunc_GetObjectClass(ACSVM::Thread *thread, const ACSVM::Word *argV, ACS
|
|||
if (mobj != NULL && P_MobjWasRemoved(mobj) == false)
|
||||
{
|
||||
std::string prefix = "MT_";
|
||||
std::string full = prefix + (strbuf_get(mobjnames, mobjinfo[mobj->type].nameofs));
|
||||
std::string full = prefix + DEH_MobjtypeName(mobj->type);
|
||||
mobjClass = static_cast<INT32>( ~env->getString( full.c_str() )->idx );
|
||||
}
|
||||
|
||||
|
|
@ -4373,7 +4357,7 @@ bool CallFunc_GetThingProperty(ACSVM::Thread *thread, const ACSVM::Word *argV, A
|
|||
case x: \
|
||||
{ \
|
||||
std::string prefix = "MT_"; \
|
||||
std::string full = prefix + (strbuf_get(mobjnames, mobjinfo[mobj->y].nameofs)); \
|
||||
std::string full = prefix + DEH_MobjtypeName(mobj->y); \
|
||||
value = static_cast<INT32>( ~env->getString( full.c_str() )->idx ); \
|
||||
break; \
|
||||
}
|
||||
|
|
@ -4399,7 +4383,7 @@ bool CallFunc_GetThingProperty(ACSVM::Thread *thread, const ACSVM::Word *argV, A
|
|||
{ \
|
||||
statenum_t stateID = static_cast<statenum_t>(mobj->y - states); \
|
||||
std::string prefix = "S_"; \
|
||||
std::string full = prefix + strbuf_get(statenames, states[stateID].nameofs); \
|
||||
std::string full = prefix + DEH_StateName(stateID); \
|
||||
value = static_cast<INT32>( ~env->getString( full.c_str() )->idx ); \
|
||||
break; \
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4872,10 +4872,10 @@ static void Command_ListDoomednums_f(void)
|
|||
CONS_Printf(" doomednum \x82""%d""\x80 is \x85""double-defined\x80 by ", j+1);
|
||||
if (i < MT_FIRSTFREESLOT)
|
||||
{
|
||||
CONS_Printf("\x87""hardcode MT_%s <-- MAJOR ERROR\n", strbuf_get(mobjnames, mobjinfo[i].nameofs));
|
||||
CONS_Printf("\x87""hardcode MT_%s <-- MAJOR ERROR\n", DEH_MobjtypeName(i));
|
||||
continue;
|
||||
}
|
||||
CONS_Printf("\x81""freeslot MT_""%s\n", strbuf_get(mobjnames, mobjinfo[i].nameofs));
|
||||
CONS_Printf("\x81""freeslot MT_""%s\n", DEH_MobjtypeName(i));
|
||||
continue;
|
||||
}
|
||||
table[j] = i;
|
||||
|
|
@ -4908,10 +4908,10 @@ static void Command_ListDoomednums_f(void)
|
|||
CONS_Printf(" doomednum \x82""%d""\x80 is used by ", i+1);
|
||||
if (table[i] < MT_FIRSTFREESLOT)
|
||||
{
|
||||
CONS_Printf("\x87""hardcode MT_%s\n", strbuf_get(mobjnames, mobjinfo[i].nameofs));
|
||||
CONS_Printf("\x87""hardcode MT_%s\n", DEH_MobjtypeName(i));
|
||||
continue;
|
||||
}
|
||||
CONS_Printf("\x81""freeslot MT_""%s\n", strbuf_get(mobjnames, mobjinfo[i].nameofs));
|
||||
CONS_Printf("\x81""freeslot MT_""%s\n", DEH_MobjtypeName(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -285,11 +285,11 @@ 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 (fastcmp(p, strbuf_get(statenames, states[i].nameofs))) {
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
i = DEH_FindState(p);
|
||||
if (i != NUMSTATES)
|
||||
{
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
if (lua_compatmode)
|
||||
for (i = 0; STATE_ALIASES[i].n; i++)
|
||||
|
|
@ -306,11 +306,11 @@ 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 (fastcmp(p, strbuf_get(mobjnames, mobjinfo[i].nameofs))) {
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
i = DEH_FindMobjtype(p);
|
||||
if (i != NUMMOBJTYPES)
|
||||
{
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
if (lua_compatmode)
|
||||
for (i = 0; MOBJ_ALIASES[i].n; i++)
|
||||
|
|
@ -445,21 +445,21 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
|
|||
}
|
||||
else if (fastncmp("SKINCOLOR_",word,10)) {
|
||||
p = word+10;
|
||||
for (i = 0; i < numskincolors; i++) {
|
||||
if (fastcmp(p, strbuf_get(skincolornames, skincolors[i].nameofs))) {
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
i = DEH_FindSkincolor(p);
|
||||
if (i != MAXSKINCOLORS)
|
||||
{
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
return luaL_error(L, "skincolor '%s' could not be found.\n", word);
|
||||
}
|
||||
else if (fastncmp("MN_",word,3)) {
|
||||
p = word+3;
|
||||
for (i = 0; i < nummenutypes; i++) {
|
||||
if (fastcmp(p, strbuf_get(menunames, menudefs[i].nameofs)) ){
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
i = DEH_FindMenutype(p);
|
||||
if (i != MAXMENUTYPES)
|
||||
{
|
||||
CacheAndPushConstant(L, word, i);
|
||||
return 1;
|
||||
}
|
||||
if (mathlib) return luaL_error(L, "menutype '%s' could not be found.\n", word);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1160,7 +1160,7 @@ void readlevelheader(MYFILE *f, char * name)
|
|||
if (fastncmp(tmp, "MT_", 3)) // support for specified mobjtypes...
|
||||
{
|
||||
i = get_mobjtype(tmp);
|
||||
if (i == -1)
|
||||
if (i == NUMMOBJTYPES)
|
||||
{
|
||||
//deh_warning("Level header %d: unknown flicky mobj type %s\n", num, tmp); -- no need for this line as get_mobjtype complains too
|
||||
continue;
|
||||
|
|
@ -2172,7 +2172,7 @@ static void readmenuitem(MYFILE *f, menuitem_t *menuitem)
|
|||
continue;
|
||||
}
|
||||
menutype_t mn = get_menutype(word2);
|
||||
if (mn == MN_NONE)
|
||||
if (mn == MAXMENUTYPES)
|
||||
{
|
||||
WARN("unknown menu '%s'", word2);
|
||||
continue;
|
||||
|
|
@ -2232,7 +2232,7 @@ static void readmenuitem(MYFILE *f, menuitem_t *menuitem)
|
|||
#undef WARN
|
||||
#undef WARN0
|
||||
|
||||
#define WARN(str, ...) deh_warning("Menu %s: " str, strbuf_get(menunames, menudefs[num].nameofs), __VA_ARGS__)
|
||||
#define WARN(str, ...) deh_warning("Menu %s: " str, DEH_MenutypeName(num), __VA_ARGS__)
|
||||
void readmenu(MYFILE *f, INT32 num)
|
||||
{
|
||||
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
|
||||
|
|
@ -2539,7 +2539,7 @@ void readframe(MYFILE *f, INT32 num)
|
|||
else if (fastcmp(word1, "NEXT"))
|
||||
{
|
||||
statenum_t state = get_state(word2);
|
||||
states[num].nextstate = state == (statenum_t)-1 ? S_NULL : state;
|
||||
states[num].nextstate = state == NUMSTATES ? S_NULL : state;
|
||||
}
|
||||
else if (fastcmp(word1, "VAR1"))
|
||||
{
|
||||
|
|
@ -3867,7 +3867,7 @@ void readfollower(MYFILE *f)
|
|||
else
|
||||
{
|
||||
skincolornum_t color = get_skincolor(word2);
|
||||
followers[numfollowers].defaultcolor = color == (skincolornum_t)-1 ? SKINCOLOR_GREEN : color;
|
||||
followers[numfollowers].defaultcolor = color == MAXSKINCOLORS ? SKINCOLOR_GREEN : color;
|
||||
}
|
||||
}
|
||||
else if (fastcmp(word, "SCALE"))
|
||||
|
|
@ -4101,7 +4101,7 @@ void readweather(MYFILE *f, INT32 num)
|
|||
if (fastcmp(word, "TYPE"))
|
||||
{
|
||||
mobjtype_t mt = get_mobjtype(word2);
|
||||
precipprops[num].type = mt == (mobjtype_t)-1 ? MT_NULL : mt;
|
||||
precipprops[num].type = mt == NUMMOBJTYPES ? MT_NULL : mt;
|
||||
}
|
||||
else if (fastcmp(word, "EFFECTS"))
|
||||
{
|
||||
|
|
@ -4126,12 +4126,10 @@ 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 (fastcmp(word, strbuf_get(mobjnames, mobjinfo[i].nameofs)))
|
||||
return i;
|
||||
}
|
||||
deh_warning("Couldn't find mobjtype named 'MT_%s'",word);
|
||||
return -1;
|
||||
i = DEH_FindMobjtype(word);
|
||||
if (i == NUMMOBJTYPES)
|
||||
deh_warning("Couldn't find mobjtype named 'MT_%s'", word);
|
||||
return i;
|
||||
}
|
||||
|
||||
statenum_t get_state(const char *word)
|
||||
|
|
@ -4141,12 +4139,10 @@ 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 (fastcmp(word, strbuf_get(statenames, states[i].nameofs)))
|
||||
return i;
|
||||
}
|
||||
deh_warning("Couldn't find state named 'S_%s'",word);
|
||||
return -1;
|
||||
i = DEH_FindState(word);
|
||||
if (i == NUMSTATES)
|
||||
deh_warning("Couldn't find state named 'S_%s'", word);
|
||||
return i;
|
||||
}
|
||||
|
||||
skincolornum_t get_skincolor(const char *word)
|
||||
|
|
@ -4156,12 +4152,10 @@ 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 < numskincolors; i++) {
|
||||
if (fastcmp(word, strbuf_get(skincolornames, skincolors[i].nameofs)))
|
||||
return i;
|
||||
}
|
||||
deh_warning("Couldn't find skincolor named 'SKINCOLOR_%s'",word);
|
||||
return -1;
|
||||
i = DEH_FindSkincolor(word);
|
||||
if (i == MAXSKINCOLORS)
|
||||
deh_warning("Couldn't find skincolor named 'SKINCOLOR_%s'", word);
|
||||
return i;
|
||||
}
|
||||
|
||||
spritenum_t get_sprite(const char *word)
|
||||
|
|
@ -4215,12 +4209,10 @@ 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 (fastcmp(word, strbuf_get(menunames, menudefs[i].nameofs)))
|
||||
return i;
|
||||
}
|
||||
deh_warning("Couldn't find menutype named 'MN_%s'",word);
|
||||
return MN_NONE;
|
||||
i = DEH_FindMenutype(word);
|
||||
if (i == MAXMENUTYPES)
|
||||
deh_warning("Couldn't find menutype named 'MN_%s'", word);
|
||||
return i;
|
||||
}
|
||||
|
||||
void (*get_menuroutine(const char *word))(INT32)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "k_kart.h" // awardscaledrings_t
|
||||
|
||||
#include "deh_tables.h"
|
||||
#include "fastcmp.h"
|
||||
|
||||
strbuf_t *statenames;
|
||||
strbuf_t *mobjnames;
|
||||
|
|
@ -38,6 +39,66 @@ strbuf_t *skincolornames;
|
|||
strbuf_t *menunames;
|
||||
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.
|
||||
|
||||
const char *DEH_MobjtypeName(mobjtype_t i)
|
||||
{
|
||||
return strbuf_get(mobjnames, mobjinfo[i].nameofs);
|
||||
}
|
||||
|
||||
const char *DEH_StateName(statenum_t i)
|
||||
{
|
||||
return strbuf_get(statenames, states[i].nameofs);
|
||||
}
|
||||
|
||||
const char *DEH_SkincolorName(skincolornum_t i)
|
||||
{
|
||||
return strbuf_get(skincolornames, skincolors[i].nameofs);
|
||||
}
|
||||
|
||||
const char *DEH_MenutypeName(menutype_t i)
|
||||
{
|
||||
return strbuf_get(menunames, menudefs[i].nameofs);
|
||||
}
|
||||
|
||||
mobjtype_t DEH_FindMobjtype(const char *word)
|
||||
{
|
||||
mobjtype_t i;
|
||||
for (i = 0; i < nummobjtypes; i++) {
|
||||
if (fastcmp(word, DEH_MobjtypeName(i)))
|
||||
return i;
|
||||
}
|
||||
return NUMMOBJTYPES;
|
||||
}
|
||||
|
||||
statenum_t DEH_FindState(const char *word)
|
||||
{
|
||||
statenum_t i;
|
||||
for (i = 0; i < numstates; i++) {
|
||||
if (fastcmp(word, DEH_StateName(i)))
|
||||
return i;
|
||||
}
|
||||
return NUMSTATES;
|
||||
}
|
||||
|
||||
skincolornum_t DEH_FindSkincolor(const char *word)
|
||||
{
|
||||
skincolornum_t i;
|
||||
for (i = 0; i < numskincolors; i++) {
|
||||
if (fastcmp(word, DEH_SkincolorName(i)))
|
||||
return i;
|
||||
}
|
||||
return MAXSKINCOLORS;
|
||||
}
|
||||
|
||||
menutype_t DEH_FindMenutype(const char *word)
|
||||
{
|
||||
menutype_t i;
|
||||
for (i = 0; i < nummenutypes; i++) {
|
||||
if (fastcmp(word, DEH_MenutypeName(i)))
|
||||
return i;
|
||||
}
|
||||
return MAXMENUTYPES;
|
||||
}
|
||||
|
||||
struct flickytypes_s FLICKYTYPES[] = {
|
||||
{"BLUEBIRD", MT_FLICKY_01}, // Flicky (Flicky)
|
||||
{"RABBIT", MT_FLICKY_02}, // Pocky (1)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#include "info.h" // Mobj, state, sprite, etc constants
|
||||
#include "lua_script.h"
|
||||
#include "strbuf.h"
|
||||
#include "m_menu.h" // menutype_t
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -31,6 +32,16 @@ extern strbuf_t *skincolornames;
|
|||
extern strbuf_t *menunames;
|
||||
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.
|
||||
|
||||
const char *DEH_MobjtypeName(mobjtype_t i);
|
||||
const char *DEH_StateName(statenum_t i);
|
||||
const char *DEH_SkincolorName(skincolornum_t i);
|
||||
const char *DEH_MenutypeName(menutype_t i);
|
||||
|
||||
mobjtype_t DEH_FindMobjtype(const char *word);
|
||||
statenum_t DEH_FindState(const char *word);
|
||||
skincolornum_t DEH_FindSkincolor(const char *word);
|
||||
menutype_t DEH_FindMenutype(const char *word);
|
||||
|
||||
struct flickytypes_s {
|
||||
const char *name;
|
||||
const mobjtype_t type;
|
||||
|
|
|
|||
|
|
@ -982,7 +982,7 @@ static int state_get(lua_State *L)
|
|||
statenum_t id = st-states;
|
||||
if (id < NUMSTATES)
|
||||
{
|
||||
lua_pushstring(L, strbuf_get(statenames, states[id].nameofs));
|
||||
lua_pushstring(L, DEH_StateName(id));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -1278,7 +1278,7 @@ static int mobjinfo_get(lua_State *L)
|
|||
mobjtype_t id = info-mobjinfo;
|
||||
if (id < NUMMOBJTYPES)
|
||||
{
|
||||
lua_pushstring(L, strbuf_get(mobjnames, mobjinfo[id].nameofs));
|
||||
lua_pushstring(L, DEH_MobjtypeName(id));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1185,7 +1185,7 @@ static void P_WriteSkincolor(INT32 constant, char **target)
|
|||
|| constant >= (INT32)numskincolors)
|
||||
return;
|
||||
|
||||
color_name = strbuf_get(skincolornames, skincolors[constant].nameofs);
|
||||
color_name = DEH_SkincolorName(constant);
|
||||
|
||||
P_WriteDuplicateText(
|
||||
va("SKINCOLOR_%s", color_name),
|
||||
|
|
|
|||
|
|
@ -263,13 +263,13 @@ static const char *MobjTypeName(const mobj_t *mobj)
|
|||
|
||||
if (p1 == (actionf_p1)P_MobjThinker)
|
||||
{
|
||||
return strbuf_get(mobjnames, mobjinfo[mobj->type].nameofs);
|
||||
return DEH_MobjtypeName(mobj->type);
|
||||
}
|
||||
else if (p1 == (actionf_p1)P_RemoveThinkerDelayed)
|
||||
{
|
||||
if (mobj->thinker.debug_mobjtype != MT_NULL)
|
||||
{
|
||||
return strbuf_get(mobjnames, mobjinfo[mobj->thinker.debug_mobjtype].nameofs);
|
||||
return DEH_MobjtypeName(mobj->thinker.debug_mobjtype);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ UINT32 strbuf_append(strbuf_t **strbuf, const char *str);
|
|||
// returns the string at the given offset
|
||||
FUNCINLINE static ATTRINLINE char *strbuf_get(strbuf_t *strbuf, UINT32 ofs)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
return reinterpret_cast<char *>(strbuf) + ofs;
|
||||
#else
|
||||
return (char *)strbuf + ofs;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
Loading…
Reference in a new issue