mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-22 04:21:23 +00:00
Handle super stack more intelligently
Counted per action type, and it is decremented after the function is called instead of keeping its old value or even resetting completely when using multiple actions together.
This commit is contained in:
parent
dcdbdec2bf
commit
c53f57a22f
3 changed files with 20 additions and 12 deletions
|
@ -214,7 +214,6 @@ static int action_call(lua_State *L)
|
|||
// Set in lua_infolib.
|
||||
const char *luaactions[MAX_ACTION_RECURSION];
|
||||
UINT8 luaactionstack = 0;
|
||||
UINT8 superstack = 0;
|
||||
|
||||
static int lib_dummysuper(lua_State *L)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,6 @@ extern boolean introchanged;
|
|||
#define MAX_ACTION_RECURSION 30
|
||||
extern const char *luaactions[MAX_ACTION_RECURSION];
|
||||
extern UINT8 luaactionstack;
|
||||
extern UINT8 superstack;
|
||||
|
||||
// If the dehacked patch does not match this version, we throw a warning
|
||||
#define PATCHVERSION 220
|
||||
|
|
|
@ -812,6 +812,7 @@ boolean LUA_SetLuaAction(void *stv, const char *action)
|
|||
return true; // action successfully set.
|
||||
}
|
||||
|
||||
static UINT8 superstack[NUMACTIONS];
|
||||
boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor)
|
||||
{
|
||||
I_Assert(actor != NULL);
|
||||
|
@ -819,7 +820,7 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor)
|
|||
if (actionsoverridden[actionnum][0] == LUA_REFNIL)
|
||||
{
|
||||
// The action was not overridden at all,
|
||||
// so call the hardcoded version.
|
||||
// so just call the hardcoded version.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -830,24 +831,27 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor)
|
|||
|
||||
// 0 is just the reference to the one we're calling,
|
||||
// so we increment here.
|
||||
superstack++;
|
||||
superstack[actionnum]++;
|
||||
|
||||
if (superstack >= MAX_ACTION_RECURSION)
|
||||
if (superstack[actionnum] >= MAX_ACTION_RECURSION)
|
||||
{
|
||||
CONS_Alert(CONS_WARNING, "Max Lua super recursion reached! Cool it on calling super!\n");
|
||||
superstack[actionnum] = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not calling itself, reset the super counter.
|
||||
superstack = 0;
|
||||
}
|
||||
|
||||
if (actionsoverridden[actionnum][superstack] == LUA_REFNIL)
|
||||
if (actionsoverridden[actionnum][superstack[actionnum]] == LUA_REFNIL)
|
||||
{
|
||||
// No Lua reference beyond this point.
|
||||
// Let it call the hardcoded function instead.
|
||||
|
||||
if (superstack[actionnum])
|
||||
{
|
||||
// Decrement super stack
|
||||
superstack[actionnum]--;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -855,7 +859,7 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor)
|
|||
lua_pushcfunction(gL, LUA_GetErrorMessage);
|
||||
|
||||
// Push function by reference.
|
||||
lua_getref(gL, actionsoverridden[actionnum][superstack]);
|
||||
lua_getref(gL, actionsoverridden[actionnum][superstack[actionnum]]);
|
||||
|
||||
if (lua_isnil(gL, -1)) // no match
|
||||
{
|
||||
|
@ -883,6 +887,12 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor)
|
|||
LUA_Call(gL, 3, 0, -(2 + 3));
|
||||
lua_pop(gL, -1); // Error handler
|
||||
|
||||
if (superstack[actionnum])
|
||||
{
|
||||
// Decrement super stack
|
||||
superstack[actionnum]--;
|
||||
}
|
||||
|
||||
--luaactionstack;
|
||||
luaactions[luaactionstack] = NULL;
|
||||
return true; // action successfully called.
|
||||
|
|
Loading…
Reference in a new issue