Add lua_compatmode
This commit is contained in:
parent
48bb0ea5ef
commit
71ab72c85e
4 changed files with 33 additions and 13 deletions
|
|
@ -65,6 +65,9 @@ static int nextid;
|
|||
// After a hook errors once, don't print the error again.
|
||||
static UINT8 * hooksErrored;
|
||||
|
||||
// compat mode for each hook
|
||||
static UINT8 * hookCompat;
|
||||
|
||||
static int errorRef;
|
||||
|
||||
static boolean mobj_hook_available(int hook_type, mobjtype_t mobj_type)
|
||||
|
|
@ -187,10 +190,17 @@ static void add_hook_ref(lua_State *L, int idx)
|
|||
BIT_ARRAY_SIZE (nextid + 1) * sizeof *hooksErrored,
|
||||
PU_STATIC, &hooksErrored);
|
||||
hooksErrored[nextid >> 3] = 0;
|
||||
Z_Realloc(hookCompat,
|
||||
BIT_ARRAY_SIZE (nextid + 1) * sizeof *hookCompat,
|
||||
PU_STATIC, &hookCompat);
|
||||
hookCompat[nextid >> 3] = 0;
|
||||
}
|
||||
|
||||
Z_Realloc(hookRefs, (nextid + 1) * sizeof *hookRefs, PU_STATIC, &hookRefs);
|
||||
|
||||
if (lua_compatmode)
|
||||
set_bit_array(hookCompat, nextid);
|
||||
|
||||
// set the hook function in the registry.
|
||||
lua_pushvalue(L, idx);
|
||||
hookRefs[nextid++] = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
|
@ -388,6 +398,7 @@ static void init_hook_call
|
|||
static void get_hook(Hook_State *hook, const int *ids, int n)
|
||||
{
|
||||
hook->id = ids[n];
|
||||
lua_compatmode = in_bit_array(hookCompat, hook->id);
|
||||
lua_getref(gL, hookRefs[hook->id]);
|
||||
}
|
||||
|
||||
|
|
@ -396,6 +407,7 @@ static void get_hook_from_table(Hook_State *hook, int n)
|
|||
lua_rawgeti(gL, -1, n);
|
||||
hook->id = lua_tonumber(gL, -1);
|
||||
lua_pop(gL, 1);
|
||||
lua_compatmode = in_bit_array(hookCompat, hook->id);
|
||||
lua_getref(gL, hookRefs[hook->id]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,6 +150,8 @@ int LUA_Call(lua_State *L, int nargs, int nresults, int errorhandlerindex)
|
|||
return err;
|
||||
}
|
||||
|
||||
boolean lua_compatmode = false;
|
||||
|
||||
// Moved here from lib_getenum.
|
||||
int LUA_PushGlobals(lua_State *L, const char *word)
|
||||
{
|
||||
|
|
@ -408,6 +410,9 @@ int LUA_PushGlobals(lua_State *L, const char *word)
|
|||
} else if (fastcmp(word, "gamestate")) {
|
||||
lua_pushinteger(L, gamestate);
|
||||
return 1;
|
||||
} else if (fastcmp(word, "compatmode")) {
|
||||
lua_pushboolean(L, lua_compatmode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -640,6 +645,8 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults)
|
|||
name[len] = '\0';
|
||||
}
|
||||
|
||||
lua_compatmode = wadfiles[wad]->compatmode;
|
||||
|
||||
LUA_LoadFile(&f, name, noresults); // actually load file!
|
||||
|
||||
// Okay, we've modified the game beyond the point of no return.
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ void LUA_ClearExtVars(void);
|
|||
void LUA_ClearState(void);
|
||||
|
||||
extern INT32 lua_lumploading; // is LUA_LoadLump being called?
|
||||
extern boolean lua_compatmode; // compatmode enabled for this lump/hook?
|
||||
|
||||
int LUA_GetErrorMessage(lua_State *L);
|
||||
int LUA_Call(lua_State *L, int nargs, int nresults, int errorhandlerindex);
|
||||
|
|
|
|||
26
src/w_wad.c
26
src/w_wad.c
|
|
@ -879,6 +879,19 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup)
|
|||
}
|
||||
#endif // HWRENDER
|
||||
|
||||
// check if compatmode is needed
|
||||
switch (wadfile->type)
|
||||
{
|
||||
case RET_WAD:
|
||||
wadfile->compatmode = CheckCompatWad(numwadfiles - 1);
|
||||
break;
|
||||
case RET_PK3:
|
||||
wadfile->compatmode = CheckCompatZip(numwadfiles - 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: HACK ALERT - Load Lua & SOC stuff right here. I feel like this should be out of this place, but... Let's stick with this for now.
|
||||
switch (wadfile->type)
|
||||
{
|
||||
|
|
@ -899,19 +912,6 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup)
|
|||
break;
|
||||
}
|
||||
|
||||
// check if compatmode is needed
|
||||
switch (wadfile->type)
|
||||
{
|
||||
case RET_WAD:
|
||||
wadfile->compatmode = CheckCompatWad(numwadfiles - 1);
|
||||
break;
|
||||
case RET_PK3:
|
||||
wadfile->compatmode = CheckCompatZip(numwadfiles - 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (refreshdirmenu & REFRESHDIR_GAMEDATA)
|
||||
G_LoadGameData();
|
||||
DEH_UpdateMaxFreeslots();
|
||||
|
|
|
|||
Loading…
Reference in a new issue