P_RestoreTMStruct

This commit is contained in:
Sally Coolatta 2022-11-21 15:59:19 -05:00
parent 11a6287c80
commit 35f1fe580c
5 changed files with 66 additions and 25 deletions

View file

@ -1010,7 +1010,7 @@ static int lib_pRailThinker(lua_State *L)
if (!mobj) if (!mobj)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_RailThinker(mobj)); lua_pushboolean(L, P_RailThinker(mobj));
tm = ptm; P_RestoreTMStruct(ptm);
return 1; return 1;
} }
@ -1023,7 +1023,7 @@ static int lib_pXYMovement(lua_State *L)
if (!actor) if (!actor)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
P_XYMovement(actor); P_XYMovement(actor);
tm = ptm; P_RestoreTMStruct(ptm);
return 0; return 0;
} }
@ -1036,7 +1036,7 @@ static int lib_pRingXYMovement(lua_State *L)
if (!actor) if (!actor)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
P_RingXYMovement(actor); P_RingXYMovement(actor);
tm = ptm; P_RestoreTMStruct(ptm);
return 0; return 0;
} }
@ -1049,7 +1049,7 @@ static int lib_pSceneryXYMovement(lua_State *L)
if (!actor) if (!actor)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
P_SceneryXYMovement(actor); P_SceneryXYMovement(actor);
tm = ptm; P_RestoreTMStruct(ptm);
return 0; return 0;
} }
@ -1063,7 +1063,7 @@ static int lib_pZMovement(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_ZMovement(actor)); lua_pushboolean(L, P_ZMovement(actor));
P_CheckPosition(actor, actor->x, actor->y); P_CheckPosition(actor, actor->x, actor->y);
tm = ptm; P_RestoreTMStruct(ptm);
return 1; return 1;
} }
@ -1077,7 +1077,7 @@ static int lib_pRingZMovement(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
P_RingZMovement(actor); P_RingZMovement(actor);
P_CheckPosition(actor, actor->x, actor->y); P_CheckPosition(actor, actor->x, actor->y);
tm = ptm; P_RestoreTMStruct(ptm);
return 0; return 0;
} }
@ -1091,7 +1091,7 @@ static int lib_pSceneryZMovement(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_SceneryZMovement(actor)); lua_pushboolean(L, P_SceneryZMovement(actor));
P_CheckPosition(actor, actor->x, actor->y); P_CheckPosition(actor, actor->x, actor->y);
tm = ptm; P_RestoreTMStruct(ptm);
return 1; return 1;
} }
@ -1105,7 +1105,7 @@ static int lib_pPlayerZMovement(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
P_PlayerZMovement(actor); P_PlayerZMovement(actor);
P_CheckPosition(actor, actor->x, actor->y); P_CheckPosition(actor, actor->x, actor->y);
tm = ptm; P_RestoreTMStruct(ptm);
return 0; return 0;
} }
@ -1313,7 +1313,7 @@ static int lib_pMovePlayer(lua_State *L)
if (!player) if (!player)
return LUA_ErrInvalid(L, "player_t"); return LUA_ErrInvalid(L, "player_t");
P_MovePlayer(player); P_MovePlayer(player);
tm = ptm; P_RestoreTMStruct(ptm);
return 0; return 0;
} }
@ -1395,7 +1395,7 @@ static int lib_pCheckPosition(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_CheckPosition(thing, x, y)); lua_pushboolean(L, P_CheckPosition(thing, x, y));
LUA_PushUserdata(L, tm.thing, META_MOBJ); LUA_PushUserdata(L, tm.thing, META_MOBJ);
tm = ptm; P_RestoreTMStruct(ptm);
return 2; return 2;
} }
@ -1412,7 +1412,7 @@ static int lib_pTryMove(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_TryMove(thing, x, y, allowdropoff)); lua_pushboolean(L, P_TryMove(thing, x, y, allowdropoff));
LUA_PushUserdata(L, tm.thing, META_MOBJ); LUA_PushUserdata(L, tm.thing, META_MOBJ);
tm = ptm; P_RestoreTMStruct(ptm);
return 2; return 2;
} }
@ -1427,7 +1427,7 @@ static int lib_pMove(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_Move(actor, speed)); lua_pushboolean(L, P_Move(actor, speed));
LUA_PushUserdata(L, tm.thing, META_MOBJ); LUA_PushUserdata(L, tm.thing, META_MOBJ);
tm = ptm; P_RestoreTMStruct(ptm);
return 2; return 2;
} }
@ -1445,7 +1445,7 @@ static int lib_pTeleportMove(lua_State *L)
LUA_Deprecated(L, "P_TeleportMove", "P_SetOrigin\" or \"P_MoveOrigin"); LUA_Deprecated(L, "P_TeleportMove", "P_SetOrigin\" or \"P_MoveOrigin");
lua_pushboolean(L, P_MoveOrigin(thing, x, y, z)); lua_pushboolean(L, P_MoveOrigin(thing, x, y, z));
LUA_PushUserdata(L, tm.thing, META_MOBJ); LUA_PushUserdata(L, tm.thing, META_MOBJ);
tm = ptm; P_RestoreTMStruct(ptm);
return 2; return 2;
} }
@ -1462,7 +1462,7 @@ static int lib_pSetOrigin(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_SetOrigin(thing, x, y, z)); lua_pushboolean(L, P_SetOrigin(thing, x, y, z));
LUA_PushUserdata(L, tm.thing, META_MOBJ); LUA_PushUserdata(L, tm.thing, META_MOBJ);
tm = ptm; P_RestoreTMStruct(ptm);
return 2; return 2;
} }
@ -1479,7 +1479,7 @@ static int lib_pMoveOrigin(lua_State *L)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_MoveOrigin(thing, x, y, z)); lua_pushboolean(L, P_MoveOrigin(thing, x, y, z));
LUA_PushUserdata(L, tm.thing, META_MOBJ); LUA_PushUserdata(L, tm.thing, META_MOBJ);
tm = ptm; P_RestoreTMStruct(ptm);
return 2; return 2;
} }

View file

@ -731,7 +731,7 @@ static int sector_set(lua_State *L)
sector->floorheight = lastpos; sector->floorheight = lastpos;
P_CheckSector(sector, true); P_CheckSector(sector, true);
} }
tm = ptm; P_RestoreTMStruct(ptm);
break; break;
} }
case sector_ceilingheight: { // ceilingheight case sector_ceilingheight: { // ceilingheight
@ -745,7 +745,7 @@ static int sector_set(lua_State *L)
sector->ceilingheight = lastpos; sector->ceilingheight = lastpos;
P_CheckSector(sector, true); P_CheckSector(sector, true);
} }
tm = ptm; P_RestoreTMStruct(ptm);
break; break;
} }
case sector_floorpic: case sector_floorpic:
@ -2136,7 +2136,7 @@ static int ffloor_set(lua_State *L)
*ffloor->topheight = lastpos; *ffloor->topheight = lastpos;
P_CheckSector(sector, true); P_CheckSector(sector, true);
} }
tm = ptm; P_RestoreTMStruct(ptm);
break; break;
} }
case ffloor_toppic: case ffloor_toppic:
@ -2157,7 +2157,7 @@ static int ffloor_set(lua_State *L)
*ffloor->bottomheight = lastpos; *ffloor->bottomheight = lastpos;
P_CheckSector(sector, true); P_CheckSector(sector, true);
} }
tm = ptm; P_RestoreTMStruct(ptm);
break; break;
} }
case ffloor_bottompic: case ffloor_bottompic:

View file

@ -522,7 +522,7 @@ static int mobj_set(lua_State *L)
mo->ceilingz = tm.ceilingz; mo->ceilingz = tm.ceilingz;
mo->floorrover = tm.floorrover; mo->floorrover = tm.floorrover;
mo->ceilingrover = tm.ceilingrover; mo->ceilingrover = tm.ceilingrover;
tm = ptm; P_RestoreTMStruct(ptm);
break; break;
} }
case mobj_snext: case mobj_snext:
@ -592,7 +592,7 @@ static int mobj_set(lua_State *L)
mo->ceilingz = tm.ceilingz; mo->ceilingz = tm.ceilingz;
mo->floorrover = tm.floorrover; mo->floorrover = tm.floorrover;
mo->ceilingrover = tm.ceilingrover; mo->ceilingrover = tm.ceilingrover;
tm = ptm; P_RestoreTMStruct(ptm);
break; break;
} }
case mobj_height: case mobj_height:
@ -606,7 +606,7 @@ static int mobj_set(lua_State *L)
mo->ceilingz = tm.ceilingz; mo->ceilingz = tm.ceilingz;
mo->floorrover = tm.floorrover; mo->floorrover = tm.floorrover;
mo->ceilingrover = tm.ceilingrover; mo->ceilingrover = tm.ceilingrover;
tm = ptm; P_RestoreTMStruct(ptm);
break; break;
} }
case mobj_momx: case mobj_momx:

View file

@ -415,6 +415,8 @@ typedef struct tm_s
extern tm_t tm; extern tm_t tm;
void P_RestoreTMStruct(tm_t tmrestore);
extern camera_t *mapcampointer; extern camera_t *mapcampointer;
/* cphipps 2004/08/30 */ /* cphipps 2004/08/30 */

View file

@ -46,6 +46,45 @@
tm_t tm = {0}; tm_t tm = {0};
void P_RestoreTMStruct(tm_t tmrestore)
{
// Reference count management
if (tm.thing != tmrestore.thing)
{
P_SetTarget(&tm.thing, NULL);
}
if (tm.floorthing != tmrestore.floorthing)
{
P_SetTarget(&tm.floorthing, NULL);
}
if (tm.hitthing != tmrestore.hitthing)
{
P_SetTarget(&tm.hitthing, NULL);
}
// Restore state
tm = tmrestore;
// Validation
if (tm.thing && P_MobjWasRemoved(tm.thing) == true)
{
P_SetTarget(&tm.thing, NULL);
}
if (tm.floorthing && P_MobjWasRemoved(tm.floorthing) == true)
{
P_SetTarget(&tm.floorthing, NULL);
}
if (tm.hitthing && P_MobjWasRemoved(tm.hitthing) == true)
{
P_SetTarget(&tm.hitthing, NULL);
}
}
// Mostly re-ported from DOOM Legacy // Mostly re-ported from DOOM Legacy
// Keep track of special lines as they are hit, process them when the move is valid // Keep track of special lines as they are hit, process them when the move is valid
static size_t *spechit = NULL; static size_t *spechit = NULL;
@ -2463,7 +2502,7 @@ BlockItReturn_t PIT_PushableMoved(mobj_t *thing)
P_TryMove(thing, thing->x + stand->momx, thing->y + stand->momy, true); P_TryMove(thing, thing->x + stand->momx, thing->y + stand->momy, true);
// Now restore EVERYTHING so the gargoyle doesn't keep the player's tmstuff and break // Now restore EVERYTHING so the gargoyle doesn't keep the player's tmstuff and break
tm = oldtm; P_RestoreTMStruct(oldtm);
thing->momz = stand->momz; thing->momz = stand->momz;
} }
@ -4880,7 +4919,7 @@ void P_CreateSecNodeList(mobj_t *thing, fixed_t x, fixed_t y)
* OTOH for Boom/MBF demos we have to preserve the buggy behavior. * OTOH for Boom/MBF demos we have to preserve the buggy behavior.
* Fun. We restore its previous value unless we're in a Boom/MBF demo. * Fun. We restore its previous value unless we're in a Boom/MBF demo.
*/ */
tm = ptm; P_RestoreTMStruct(ptm);
} }
// More crazy crap Tails 08-25-2002 // More crazy crap Tails 08-25-2002
@ -4947,7 +4986,7 @@ void P_CreatePrecipSecNodeList(precipmobj_t *thing,fixed_t x,fixed_t y)
* OTOH for Boom/MBF demos we have to preserve the buggy behavior. * OTOH for Boom/MBF demos we have to preserve the buggy behavior.
* Fun. We restore its previous value unless we're in a Boom/MBF demo. * Fun. We restore its previous value unless we're in a Boom/MBF demo.
*/ */
tm = ptm; P_RestoreTMStruct(ptm);
} }
/* cphipps 2004/08/30 - /* cphipps 2004/08/30 -