- SW: Remove PLAYER::posZset() in favour of new utilities.

This commit is contained in:
Mitchell Richters 2022-11-23 18:19:12 +11:00 committed by Christoph Oelckers
parent f18512e270
commit fe795e6cfb
3 changed files with 95 additions and 122 deletions

View file

@ -1896,10 +1896,6 @@ struct PLAYER
return actor->spr.pos.XY();
}
void posZset(const double val)
{
actor->spr.pos.Z = val - actor->viewzoffset;
}
void posZadd(const double val)
{
actor->spr.pos.Z += val;
@ -1954,6 +1950,56 @@ struct PLAYER
{
return PlayerOldPosition;
}
void setHeightAndZ(const double newz, const double newheight)
{
actor->spr.pos.Z = newz;
height = newheight;
}
bool belowFloorZ(const double floorz, const double newheight = DBL_MAX)
{
if (newheight == DBL_MAX)
{
if (actor->getOffsetZ() > floorz)
{
actor->spr.pos.Z = floorz - actor->viewzoffset;
return true;
}
}
else
{
if (actor->spr.pos.Z > floorz)
{
setHeightAndZ(floorz, newheight);
return true;
}
}
return false;
}
bool aboveCeilZ(const double ceilz, const double newheight = DBL_MAX)
{
if (newheight == DBL_MAX)
{
if (actor->getOffsetZ() < ceilz)
{
actor->spr.pos.Z = ceilz - actor->viewzoffset;
return true;
}
}
else
{
if (actor->spr.pos.Z < ceilz)
{
setHeightAndZ(ceilz, newheight);
return true;
}
}
return false;
}
};
extern PLAYER Player[MAX_SW_PLAYERS_REG+1];

View file

@ -1498,9 +1498,8 @@ void DoPlayerJumpHeight(PLAYER* pp)
{
if (pp->lo_sectp && (pp->lo_sectp->extra & SECTFX_DYNAMIC_AREA))
{
if (pp->posZget() + PLAYER_HEIGHTF > pp->loz)
if (pp->belowFloorZ(pp->loz, PLAYER_HEIGHTF))
{
pp->posZset(pp->loz - PLAYER_HEIGHTF);
DoPlayerBeginRun(pp);
}
}
@ -2059,12 +2058,8 @@ void PlayerSectorBound(PLAYER* pp, double amt)
calcSlope(pp->cursector, pp->posGet(), &cz, &fz);
if (pp->posZget() > fz - amt)
pp->posZset(fz - amt);
if (pp->posZget() < cz + amt)
pp->posZset(cz + amt);
pp->belowFloorZ(fz - amt);
pp->aboveCeilZ(cz + amt);
}
//---------------------------------------------------------------------------
@ -2229,19 +2224,13 @@ void DoPlayerMove(PLAYER* pp)
{
if (pp->Flags & (PF_FLYING|PF_JUMPING|PF_FALLING))
{
if (pp->posZget() > pp->loz)
pp->posZset(pp->loz - PLAYER_HEIGHTF);
if (pp->posZget() < pp->hiz)
pp->posZset(pp->hiz + PLAYER_HEIGHTF);
pp->belowFloorZ(pp->loz, PLAYER_HEIGHTF);
pp->aboveCeilZ(pp->hiz, PLAYER_HEIGHTF);
}
else if (pp->Flags & (PF_SWIMMING|PF_DIVING))
{
if (pp->posZget() > pp->loz)
pp->posZset(pp->loz - PLAYER_SWIM_HEIGHTF);
if (pp->posZget() < pp->hiz)
pp->posZset(pp->hiz + PLAYER_SWIM_HEIGHTF);
pp->belowFloorZ(pp->loz, PLAYER_SWIM_HEIGHTF);
pp->aboveCeilZ(pp->hiz, PLAYER_SWIM_HEIGHTF);
}
}
}
@ -2306,11 +2295,8 @@ void DoPlayerSectorUpdatePostMove(PLAYER* pp)
// adjust the posz to be in a sector
calcSlope(pp->cursector, pp->posGet(), &cz, &fz);
if (pp->posZget() > fz)
pp->posZset(fz);
if (pp->posZget() < cz)
pp->posZset(cz);
pp->belowFloorZ(fz);
pp->aboveCeilZ(cz);
// try again
updatesectorz(pp->posGet(), &pp->cursector);
@ -2920,22 +2906,6 @@ void DoPlayerBeginForceJump(PLAYER* pp)
//
//---------------------------------------------------------------------------
bool PlayerCeilingHit(PLAYER* pp, double zlimit)
{
return (pp->posZget() < zlimit);
}
bool PlayerFloorHit(PLAYER* pp, double zlimit)
{
return (pp->posZget() > zlimit);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DoPlayerJump(PLAYER* pp)
{
short i;
@ -2972,11 +2942,8 @@ void DoPlayerJump(PLAYER* pp)
pp->posZadd(pp->jump_speed * JUMP_FACTOR);
// if player gets to close the ceiling while jumping
if (PlayerCeilingHit(pp, pp->hiz + 4))
if (pp->aboveCeilZ(pp->hiz + 4))
{
// put player at the ceiling
pp->posZset(pp->hiz + 4);
// reverse your speed to falling
pp->jump_speed = -pp->jump_speed;
@ -2989,10 +2956,8 @@ void DoPlayerJump(PLAYER* pp)
// added this because jumping up to slopes or jumping on steep slopes
// sometimes caused the view to go into the slope
// if player gets to close the floor while jumping
if (PlayerFloorHit(pp, pp->loz - pp->p_floor_dist))
if (pp->belowFloorZ(pp->loz - pp->p_floor_dist))
{
pp->posZset(pp->loz - pp->p_floor_dist);
pp->jump_speed = 0;
PlayerSectorBound(pp, 1);
DoPlayerBeginRun(pp);
@ -3046,12 +3011,8 @@ void DoPlayerForceJump(PLAYER* pp)
pp->posZadd(pp->jump_speed * JUMP_FACTOR);
// if player gets to close the ceiling while jumping
//if (pp->posGet()z < pp->hiz + Z(4))
if (PlayerCeilingHit(pp, pp->hiz + 4))
if (pp->aboveCeilZ(pp->hiz + 4))
{
// put player at the ceiling
pp->posZset(pp->hiz + 4);
// reverse your speed to falling
pp->jump_speed = -pp->jump_speed;
@ -3173,15 +3134,9 @@ void DoPlayerFall(PLAYER* pp)
// need a test for head hits a sloped ceiling while falling
// if player gets to close the Ceiling while Falling
if (PlayerCeilingHit(pp, pp->hiz + pp->p_ceiling_dist))
{
// put player at the ceiling
pp->posZset(pp->hiz + pp->p_ceiling_dist);
// don't return or anything - allow to fall until
// hit floor
}
pp->aboveCeilZ(pp->hiz + pp->p_ceiling_dist);
if (PlayerFloorHit(pp, pp->loz - PLAYER_HEIGHTF + recoil_amnt))
if (pp->actor->spr.pos.Z > pp->loz + recoil_amnt)
{
sectortype* sectp = pp->cursector;
@ -3203,7 +3158,7 @@ void DoPlayerFall(PLAYER* pp)
// i any kind of crawl key get rid of recoil
if (DoPlayerTestCrawl(pp) || (pp->input.actions & SB_CROUCH))
{
pp->posZset(pp->loz - PLAYER_CRAWL_HEIGHTF);
pp->setHeightAndZ(pp->loz, PLAYER_CRAWL_HEIGHTF);
}
else
{
@ -3383,18 +3338,16 @@ void DoPlayerClimb(PLAYER* pp)
pp->climb_ndx &= 1023;
// if player gets to close the ceiling while climbing
if (PlayerCeilingHit(pp, pp->hiz))
if (pp->aboveCeilZ(pp->hiz))
{
// put player at the hiz
pp->posZset(pp->hiz);
NewStateGroup(pp->actor, sg_PlayerNinjaClimb);
}
// if player gets to close the ceiling while climbing
if (PlayerCeilingHit(pp, pp->hiz + 4))
if (pp->aboveCeilZ(pp->hiz + 4))
{
// put player at the ceiling
pp->posZset(pp->LadderSector->ceilingz + 4);
plActor->spr.pos.Z = pp->LadderSector->ceilingz + 4 - plActor->viewzoffset;
NewStateGroup(pp->actor, sg_PlayerNinjaClimb);
}
@ -3417,11 +3370,8 @@ void DoPlayerClimb(PLAYER* pp)
pp->climb_ndx &= 1023;
// if you are touching the floor
if (PlayerFloorHit(pp, pp->loz - 4 - PLAYER_HEIGHTF))
if (pp->belowFloorZ(pp->loz - 4, PLAYER_HEIGHTF))
{
// stand on floor
pp->posZset(pp->loz - 4 - PLAYER_HEIGHTF);
// if moving backwards start running
if (climbVel < 0)
{
@ -3437,8 +3387,6 @@ void DoPlayerClimb(PLAYER* pp)
NewStateGroup(pp->actor, sg_PlayerNinjaClimb);
}
// setsprite to players location
plActor->spr.pos.Z = pp->posZget() + PLAYER_HEIGHTF;
ChangeActorSect(pp->actor, pp->cursector);
if (!SyncInput())
@ -3619,7 +3567,7 @@ void DoPlayerCrawl(PLAYER* pp)
if (FAF_ConnectArea(pp->cursector))
{
// adjust the z
pp->posZset(pp->cursector->ceilingz + 12);
plActor->spr.pos.Z = pp->cursector->ceilingz + 12 - plActor->viewzoffset;
}
DoPlayerBeginDiveNoWarp(pp);
@ -3673,7 +3621,7 @@ void DoPlayerCrawl(PLAYER* pp)
if (pp->insector() && (pp->cursector->extra & SECTFX_DYNAMIC_AREA))
{
pp->posZset(pp->loz - PLAYER_CRAWL_HEIGHTF);
pp->setHeightAndZ(pp->loz, PLAYER_CRAWL_HEIGHTF);
}
DoPlayerBob(pp);
@ -3757,17 +3705,9 @@ void DoPlayerFly(PLAYER* pp)
// Make the min distance from the ceiling/floor match bobbing amount
// so the player never goes into the ceiling/floor
// Only get so close to the ceiling
if (PlayerCeilingHit(pp, pp->hiz + PLAYER_FLY_BOB_AMT + 8))
// Only get so close to the ceiling or floor
if (pp->aboveCeilZ(pp->hiz + PLAYER_FLY_BOB_AMT + 8) || pp->belowFloorZ(pp->loz - PLAYER_FLY_BOB_AMT, PLAYER_HEIGHTF))
{
pp->posZset(pp->hiz + PLAYER_FLY_BOB_AMT + 8);
pp->z_speed = 0;
}
// Only get so close to the floor
if (PlayerFloorHit(pp, pp->loz - PLAYER_HEIGHTF - PLAYER_FLY_BOB_AMT))
{
pp->posZset(pp->loz - PLAYER_HEIGHTF - PLAYER_FLY_BOB_AMT);
pp->z_speed = 0;
}
@ -3991,7 +3931,7 @@ int PlayerCanDiveNoWarp(PLAYER* pp)
if (SectorIsUnderwaterArea(sect))
{
pp->setcursector(sect);
pp->posZset(sect->ceilingz + 20);
pp->actor->spr.pos.Z = sect->ceilingz + 20 - pp->actor->viewzoffset;
pp->z_speed = 20;
pp->jump_speed = 0;
@ -4243,7 +4183,7 @@ void DoPlayerWarpToUnderwater(PLAYER* pp)
else
pp->setcursector(over);
pp->posZset(under_act->sector()->ceilingz + 6);
plActor->spr.pos.Z = under_act->sector()->ceilingz + 6 - plActor->viewzoffset;
pp->posprevSet(pp->posGet());
@ -4313,7 +4253,7 @@ void DoPlayerWarpToSurface(PLAYER* pp)
pp->setcursector(over);
}
pp->posZset(over_act->sector()->floorz - 2);
plActor->spr.pos.Z = over_act->sector()->floorz - 2 - plActor->viewzoffset;
// set z range and wade depth so we know how high to set view
DoPlayerZrange(pp);
@ -4660,7 +4600,7 @@ void DoPlayerDive(PLAYER* pp)
{
// if not underwater sector we must surface
// force into above sector
pp->posZset(pp->cursector->ceilingz- 8);
plActor->spr.pos.Z = pp->cursector->ceilingz - 8 - plActor->viewzoffset;
pp->setcursector(sect);
DoPlayerStopDiveNoWarp(pp);
DoPlayerBeginRun(pp);
@ -4675,10 +4615,7 @@ void DoPlayerDive(PLAYER* pp)
if (sectu && (sectu->number == 0 || (sectu->flags & SECTFU_CANT_SURFACE)))
{
// for room over room water the hiz will be the top rooms ceiling
if (pp->posZget() < pp->hiz + pp->p_ceiling_dist)
{
pp->posZset(pp->hiz + pp->p_ceiling_dist);
}
pp->aboveCeilZ(pp->hiz + pp->p_ceiling_dist);
}
else
{
@ -4694,10 +4631,7 @@ void DoPlayerDive(PLAYER* pp)
}
// Only get so close to the floor
if (pp->posZget() >= pp->loz - PLAYER_DIVE_HEIGHTF)
{
pp->posZset(pp->loz - PLAYER_DIVE_HEIGHTF);
}
pp->belowFloorZ(pp->loz, PLAYER_DIVE_HEIGHTF);
// make player bob if sitting still
if (!PLAYER_MOVING(pp) && pp->z_speed == 0)
@ -5209,7 +5143,7 @@ void DoPlayerBeginOperate(PLAYER* pp)
pp->posXY() = sop->pmid.XY();
updatesector(pp->posGet(), &pp->cursector);
calcSlope(pp->cursector, pp->posGet(), &cz, &fz);
pp->posZset(fz - PLAYER_HEIGHTF);
pp->setHeightAndZ(fz, PLAYER_HEIGHTF);
pp->Flags &= ~(PF_CRAWLING|PF_JUMPING|PF_FALLING|PF_LOCK_CRAWL);
@ -5234,7 +5168,7 @@ void DoPlayerBeginOperate(PLAYER* pp)
PlaySOsound(pp->sop->mid_sector, SO_DRIVE_SOUND);
else
PlaySOsound(pp->sop->mid_sector, SO_IDLE_SOUND);
pp->posZset(fz - PLAYER_HEIGHTF);
pp->setHeightAndZ(fz, PLAYER_HEIGHTF);
DoPlayerBeginOperateVehicle(pp);
break;
case SO_TURRET_MGUN:
@ -5243,7 +5177,7 @@ void DoPlayerBeginOperate(PLAYER* pp)
PlaySOsound(pp->sop->mid_sector, SO_DRIVE_SOUND);
else
PlaySOsound(pp->sop->mid_sector, SO_IDLE_SOUND);
pp->posZset(fz - PLAYER_HEIGHTF);
pp->setHeightAndZ(fz, PLAYER_HEIGHTF);
DoPlayerBeginOperateTurret(pp);
break;
#if 0
@ -5252,7 +5186,7 @@ void DoPlayerBeginOperate(PLAYER* pp)
PlaySOsound(pp->sop->mid_sector, SO_DRIVE_SOUND);
else
PlaySOsound(pp->sop->mid_sector, SO_IDLE_SOUND);
pp->pos.Z = fz - PLAYER_HEIGHTF;
pp->setHeightAndZ(fz, PLAYER_HEIGHTF);
DoPlayerBeginOperateBoat(pp);
break;
#endif
@ -5299,7 +5233,7 @@ void DoPlayerBeginRemoteOperate(PLAYER* pp, SECTOR_OBJECT* sop)
pp->posXY() = sop->pmid.XY();
updatesector(pp->posGet(), &pp->cursector);
calcSlope(pp->cursector, pp->posGet(), &cz, &fz);
pp->posZset(fz - PLAYER_HEIGHTF);
pp->setHeightAndZ(fz, PLAYER_HEIGHTF);
pp->Flags &= ~(PF_CRAWLING|PF_JUMPING|PF_FALLING|PF_LOCK_CRAWL);
@ -5327,7 +5261,7 @@ void DoPlayerBeginRemoteOperate(PLAYER* pp, SECTOR_OBJECT* sop)
PlaySOsound(pp->sop->mid_sector, SO_DRIVE_SOUND);
else
PlaySOsound(pp->sop->mid_sector, SO_IDLE_SOUND);
pp->posZset(fz - PLAYER_HEIGHTF);
pp->setHeightAndZ(fz, PLAYER_HEIGHTF);
DoPlayerBeginOperateVehicle(pp);
break;
case SO_TURRET_MGUN:
@ -5336,7 +5270,7 @@ void DoPlayerBeginRemoteOperate(PLAYER* pp, SECTOR_OBJECT* sop)
PlaySOsound(pp->sop->mid_sector, SO_DRIVE_SOUND);
else
PlaySOsound(pp->sop->mid_sector, SO_IDLE_SOUND);
pp->posZset(fz - PLAYER_HEIGHTF);
pp->setHeightAndZ(fz, PLAYER_HEIGHTF);
DoPlayerBeginOperateTurret(pp);
break;
default:
@ -5383,7 +5317,7 @@ void PlayerRemoteReset(PLAYER* pp, sectortype* sect)
auto rsp = pp->remoteActor;
pp->posXY() = rsp->spr.pos.XY();
pp->posZset(sect->floorz - PLAYER_HEIGHTF);
pp->setHeightAndZ(sect->floorz, PLAYER_HEIGHTF);
pp->vect.Zero();
pp->ovect.Zero();
@ -5549,11 +5483,8 @@ void DoPlayerDeathJump(PLAYER* pp)
// if player gets to close the ceiling while jumping
//if (pp->posz < pp->hiz + Z(4))
if (PlayerCeilingHit(pp, pp->hiz + 4))
if (pp->aboveCeilZ(pp->hiz + 4))
{
// put player at the ceiling
pp->posZset(pp->hiz + 4);
// reverse your speed to falling
pp->jump_speed = -pp->jump_speed;
@ -5591,7 +5522,7 @@ void DoPlayerDeathFall(PLAYER* pp)
else
loz = pp->loz;
if (PlayerFloorHit(pp, loz - PLAYER_DEATH_HEIGHTF))
if (pp->belowFloorZ(loz, PLAYER_DEATH_HEIGHTF))
{
if (loz != pp->loz)
SpawnSplash(pp->actor);
@ -5601,7 +5532,6 @@ void DoPlayerDeathFall(PLAYER* pp)
else
PlaySound(DIGI_BODYFALL2, pp, v3df_dontpan);
pp->posZset(loz - PLAYER_DEATH_HEIGHTF);
pp->Flags &= ~(PF_FALLING);
}
}
@ -6074,7 +6004,7 @@ void DoPlayerDeathCheckKeys(PLAYER* pp)
{
// Spawn a dead LoWang body for non-head deaths
// Hey Frank, if you think of a better check, go ahead and put it in.
if (PlayerFloorHit(pp, pp->loz - PLAYER_HEIGHTF))
if (plActor->spr.pos.Z > pp->loz)
{
if (pp->DeathType == PLAYER_DEATH_FLIP || pp->DeathType == PLAYER_DEATH_RIPPER)
QueueLoWangs(pp->actor);
@ -6345,9 +6275,8 @@ void DoPlayerDeathDrown(PLAYER* pp)
pp->posZadd(2);
// Stick like glue when you hit the ground
if (pp->posZget() > pp->loz - PLAYER_DEATH_HEIGHTF)
if (pp->belowFloorZ(pp->loz, PLAYER_DEATH_HEIGHTF))
{
pp->posZset(pp->loz - PLAYER_DEATH_HEIGHTF);
pp->Flags &= ~(PF_FALLING);
}
}
@ -6600,7 +6529,7 @@ void DoPlayerRun(PLAYER* pp)
//DoPlayerHeight(pp);
//DoPlayerHeight(pp);
//DoPlayerHeight(pp);
pp->posZset(pp->loz - PLAYER_HEIGHTF);
pp->setHeightAndZ(pp->loz, PLAYER_HEIGHTF);
DoPlayerBeginJump(pp);
return;
}
@ -6695,7 +6624,7 @@ void DoPlayerRun(PLAYER* pp)
if ((pp->cursector && pp->cursector->extra & SECTFX_DYNAMIC_AREA))
{
pp->posZset(pp->loz - PLAYER_HEIGHTF);
pp->setHeightAndZ(pp->loz, PLAYER_HEIGHTF);
}
// Adjust height moving up and down sectors

View file

@ -1743,8 +1743,7 @@ PlayerPart:
{
// move up some for really fast moving plats
DoPlayerZrange(pp);
pp->posZset(pp->loz - PLAYER_CRAWL_HEIGHTF);
pp->actor->spr.pos.Z = pp->loz;
pp->setHeightAndZ(pp->loz, PLAYER_CRAWL_HEIGHTF);
}
else
{
@ -1753,8 +1752,7 @@ PlayerPart:
if (!(pp->Flags & (PF_JUMPING | PF_FALLING | PF_FLYING)))
{
pp->posZset(pp->loz - PLAYER_HEIGHTF);
pp->actor->spr.pos.Z = pp->loz;
pp->setHeightAndZ(pp->loz, PLAYER_HEIGHTF);
}
}
}