Only create floor sprite slopes when needed, instead of always allocating them.

Has to be done manually in Lua. Use P_CreateFloorSpriteSlope, and P_DeleteFloorSpriteSlope when done with it.
This commit is contained in:
Jaime Passos 2020-10-14 13:07:02 -03:00
parent ab526e47cc
commit e63efdac13
4 changed files with 45 additions and 4 deletions

View File

@ -910,6 +910,28 @@ static int lib_pMaceRotate(lua_State *L)
return 0;
}
static int lib_pCreateFloorSpriteSlope(lua_State *L)
{
mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
NOHUD
INLEVEL
if (!mobj)
return LUA_ErrInvalid(L, "mobj_t");
LUA_PushUserdata(L, (pslope_t *)P_CreateFloorSpriteSlope(mobj), META_SLOPE);
return 1;
}
static int lib_pDeleteFloorSpriteSlope(lua_State *L)
{
mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
NOHUD
INLEVEL
if (!mobj)
return LUA_ErrInvalid(L, "mobj_t");
P_DeleteFloorSpriteSlope(mobj);
return 1;
}
static int lib_pRailThinker(lua_State *L)
{
mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
@ -3536,6 +3558,8 @@ static luaL_Reg lib[] = {
{"P_CheckSolidLava",lib_pCheckSolidLava},
{"P_CanRunOnWater",lib_pCanRunOnWater},
{"P_MaceRotate",lib_pMaceRotate},
{"P_CreateFloorSpriteSlope",lib_pCreateFloorSpriteSlope},
{"P_DeleteFloorSpriteSlope",lib_pDeleteFloorSpriteSlope},
{"P_RailThinker",lib_pRailThinker},
{"P_XYMovement",lib_pXYMovement},
{"P_RingXYMovement",lib_pRingXYMovement},

View File

@ -10473,8 +10473,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
// Sprite rendering
mobj->spritexscale = mobj->spriteyscale = mobj->scale;
mobj->spritexoffset = mobj->spriteyoffset = 0;
mobj->floorspriteslope = Z_Calloc(sizeof(pslope_t), PU_LEVEL, NULL);
mobj->floorspriteslope->normal.z = FRACUNIT;
mobj->floorspriteslope = NULL;
// set subsector and/or block links
P_SetThingPosition(mobj);
@ -10876,6 +10875,22 @@ static inline precipmobj_t *P_SpawnSnowMobj(fixed_t x, fixed_t y, fixed_t z, mob
return mo;
}
void *P_CreateFloorSpriteSlope(mobj_t *mobj)
{
if (mobj->floorspriteslope)
Z_Free(mobj->floorspriteslope);
mobj->floorspriteslope = Z_Calloc(sizeof(pslope_t), PU_LEVEL, NULL);
mobj->floorspriteslope->normal.z = FRACUNIT;
return (void *)mobj->floorspriteslope;
}
void P_DeleteFloorSpriteSlope(mobj_t *mobj)
{
if (mobj->floorspriteslope)
Z_Free(mobj->floorspriteslope);
mobj->floorspriteslope = NULL;
}
//
// P_RemoveMobj
//

View File

@ -472,6 +472,8 @@ void P_SpawnItemPattern(mapthing_t *mthing, boolean bonustime);
void P_SpawnHoopOfSomething(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 number, mobjtype_t type, angle_t rotangle);
void P_SpawnPrecipitation(void);
void P_SpawnParaloop(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 number, mobjtype_t type, statenum_t nstate, angle_t rotangle, boolean spawncenter);
void *P_CreateFloorSpriteSlope(mobj_t *mobj);
void P_DeleteFloorSpriteSlope(mobj_t *mobj);
boolean P_BossTargetPlayer(mobj_t *actor, boolean closest);
boolean P_SupermanLook4Players(mobj_t *actor);
void P_DestroyRobots(void);

View File

@ -1620,7 +1620,7 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
diff2 |= MD2_SPRITEYSCALE;
if (mobj->spritexoffset)
diff2 |= MD2_SPRITEXOFFSET;
if (mobj->floorspriteslope)
{
pslope_t *slope = mobj->floorspriteslope;
if (slope->zangle || slope->zdelta || slope->xydirection
@ -2823,7 +2823,7 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
mobj->spriteyoffset = READFIXED(save_p);
if (diff2 & MD2_FLOORSPRITESLOPE)
{
pslope_t *slope = mobj->floorspriteslope;
pslope_t *slope = (pslope_t *)P_CreateFloorSpriteSlope(mobj);
slope->zdelta = READFIXED(save_p);
slope->zangle = READANGLE(save_p);