- took EResult out of DMover and made it an enum class.

This commit is contained in:
Christoph Oelckers 2016-04-08 13:59:03 +02:00
parent fb2234396c
commit e505bfd7a3
9 changed files with 57 additions and 56 deletions

View file

@ -155,7 +155,7 @@ bool DMover::MoveAttached(int crush, double move, int floorOrCeiling, bool reset
// (Use -1 to prevent it from trying to crush) // (Use -1 to prevent it from trying to crush)
// dest is the desired d value for the plane // dest is the desired d value for the plane
// //
DMover::EResult DMover::MoveFloor(double speed, double dest, int crush, int direction, bool hexencrush) EMoveResult DMover::MoveFloor(double speed, double dest, int crush, int direction, bool hexencrush)
{ {
bool flag; bool flag;
double lastpos; double lastpos;
@ -173,7 +173,7 @@ DMover::EResult DMover::MoveFloor(double speed, double dest, int crush, int dire
{ {
move = m_Sector->floorplane.HeightDiff(lastpos, dest); move = m_Sector->floorplane.HeightDiff(lastpos, dest);
if (!MoveAttached(crush, move, 0, true)) return crushed; if (!MoveAttached(crush, move, 0, true)) return EMoveResult::crushed;
m_Sector->floorplane.setD(dest); m_Sector->floorplane.setD(dest);
flag = P_ChangeSector(m_Sector, crush, move, 0, false); flag = P_ChangeSector(m_Sector, crush, move, 0, false);
@ -188,11 +188,11 @@ DMover::EResult DMover::MoveFloor(double speed, double dest, int crush, int dire
m_Sector->ChangePlaneTexZ(sector_t::floor, move); m_Sector->ChangePlaneTexZ(sector_t::floor, move);
m_Sector->AdjustFloorClip(); m_Sector->AdjustFloorClip();
} }
return pastdest; return EMoveResult::pastdest;
} }
else else
{ {
if (!MoveAttached(crush, -speed, 0, true)) return crushed; if (!MoveAttached(crush, -speed, 0, true)) return EMoveResult::crushed;
m_Sector->floorplane.setD(movedest); m_Sector->floorplane.setD(movedest);
@ -202,7 +202,7 @@ DMover::EResult DMover::MoveFloor(double speed, double dest, int crush, int dire
m_Sector->floorplane.setD(lastpos); m_Sector->floorplane.setD(lastpos);
P_ChangeSector(m_Sector, crush, speed, 0, true); P_ChangeSector(m_Sector, crush, speed, 0, true);
MoveAttached(crush, speed, 0, false); MoveAttached(crush, speed, 0, false);
return crushed; return EMoveResult::crushed;
} }
else else
{ {
@ -229,7 +229,7 @@ DMover::EResult DMover::MoveFloor(double speed, double dest, int crush, int dire
{ {
move = m_Sector->floorplane.HeightDiff(lastpos, dest); move = m_Sector->floorplane.HeightDiff(lastpos, dest);
if (!MoveAttached(crush, move, 0, true)) return crushed; if (!MoveAttached(crush, move, 0, true)) return EMoveResult::crushed;
m_Sector->floorplane.setD(dest); m_Sector->floorplane.setD(dest);
@ -245,11 +245,11 @@ DMover::EResult DMover::MoveFloor(double speed, double dest, int crush, int dire
m_Sector->ChangePlaneTexZ(sector_t::floor, move); m_Sector->ChangePlaneTexZ(sector_t::floor, move);
m_Sector->AdjustFloorClip(); m_Sector->AdjustFloorClip();
} }
return pastdest; return EMoveResult::pastdest;
} }
else else
{ {
if (!MoveAttached(crush, speed, 0, true)) return crushed; if (!MoveAttached(crush, speed, 0, true)) return EMoveResult::crushed;
m_Sector->floorplane.setD(movedest); m_Sector->floorplane.setD(movedest);
@ -261,22 +261,22 @@ DMover::EResult DMover::MoveFloor(double speed, double dest, int crush, int dire
{ {
m_Sector->ChangePlaneTexZ(sector_t::floor, m_Sector->floorplane.HeightDiff(lastpos)); m_Sector->ChangePlaneTexZ(sector_t::floor, m_Sector->floorplane.HeightDiff(lastpos));
m_Sector->AdjustFloorClip(); m_Sector->AdjustFloorClip();
return crushed; return EMoveResult::crushed;
} }
m_Sector->floorplane.setD(lastpos); m_Sector->floorplane.setD(lastpos);
P_ChangeSector(m_Sector, crush, -speed, 0, true); P_ChangeSector(m_Sector, crush, -speed, 0, true);
MoveAttached(crush, -speed, 0, false); MoveAttached(crush, -speed, 0, false);
return crushed; return EMoveResult::crushed;
} }
m_Sector->ChangePlaneTexZ(sector_t::floor, m_Sector->floorplane.HeightDiff(lastpos)); m_Sector->ChangePlaneTexZ(sector_t::floor, m_Sector->floorplane.HeightDiff(lastpos));
m_Sector->AdjustFloorClip(); m_Sector->AdjustFloorClip();
} }
break; break;
} }
return ok; return EMoveResult::ok;
} }
DMover::EResult DMover::MoveCeiling(double speed, double dest, int crush, int direction, bool hexencrush) EMoveResult DMover::MoveCeiling(double speed, double dest, int crush, int direction, bool hexencrush)
{ {
bool flag; bool flag;
double lastpos; double lastpos;
@ -303,7 +303,7 @@ DMover::EResult DMover::MoveCeiling(double speed, double dest, int crush, int di
{ {
move = m_Sector->ceilingplane.HeightDiff (lastpos, dest); move = m_Sector->ceilingplane.HeightDiff (lastpos, dest);
if (!MoveAttached(crush, move, 1, true)) return crushed; if (!MoveAttached(crush, move, 1, true)) return EMoveResult::crushed;
m_Sector->ceilingplane.setD(dest); m_Sector->ceilingplane.setD(dest);
flag = P_ChangeSector (m_Sector, crush, move, 1, false); flag = P_ChangeSector (m_Sector, crush, move, 1, false);
@ -318,11 +318,11 @@ DMover::EResult DMover::MoveCeiling(double speed, double dest, int crush, int di
{ {
m_Sector->ChangePlaneTexZ(sector_t::ceiling, move); m_Sector->ChangePlaneTexZ(sector_t::ceiling, move);
} }
return pastdest; return EMoveResult::pastdest;
} }
else else
{ {
if (!MoveAttached(crush, -speed, 1, true)) return crushed; if (!MoveAttached(crush, -speed, 1, true)) return EMoveResult::crushed;
m_Sector->ceilingplane.setD(movedest); m_Sector->ceilingplane.setD(movedest);
@ -333,12 +333,12 @@ DMover::EResult DMover::MoveCeiling(double speed, double dest, int crush, int di
if (crush >= 0 && !hexencrush) if (crush >= 0 && !hexencrush)
{ {
m_Sector->ChangePlaneTexZ(sector_t::ceiling, m_Sector->ceilingplane.HeightDiff (lastpos)); m_Sector->ChangePlaneTexZ(sector_t::ceiling, m_Sector->ceilingplane.HeightDiff (lastpos));
return crushed; return EMoveResult::crushed;
} }
m_Sector->ceilingplane.setD(lastpos); m_Sector->ceilingplane.setD(lastpos);
P_ChangeSector (m_Sector, crush, speed, 1, true); P_ChangeSector (m_Sector, crush, speed, 1, true);
MoveAttached(crush, speed, 1, false); MoveAttached(crush, speed, 1, false);
return crushed; return EMoveResult::crushed;
} }
m_Sector->ChangePlaneTexZ(sector_t::ceiling, m_Sector->ceilingplane.HeightDiff (lastpos)); m_Sector->ChangePlaneTexZ(sector_t::ceiling, m_Sector->ceilingplane.HeightDiff (lastpos));
} }
@ -351,7 +351,7 @@ DMover::EResult DMover::MoveCeiling(double speed, double dest, int crush, int di
{ {
move = m_Sector->ceilingplane.HeightDiff (lastpos, dest); move = m_Sector->ceilingplane.HeightDiff (lastpos, dest);
if (!MoveAttached(crush, move, 1, true)) return crushed; if (!MoveAttached(crush, move, 1, true)) return EMoveResult::crushed;
m_Sector->ceilingplane.setD(dest); m_Sector->ceilingplane.setD(dest);
@ -366,11 +366,11 @@ DMover::EResult DMover::MoveCeiling(double speed, double dest, int crush, int di
{ {
m_Sector->ChangePlaneTexZ(sector_t::ceiling, move); m_Sector->ChangePlaneTexZ(sector_t::ceiling, move);
} }
return pastdest; return EMoveResult::pastdest;
} }
else else
{ {
if (!MoveAttached(crush, speed, 1, true)) return crushed; if (!MoveAttached(crush, speed, 1, true)) return EMoveResult::crushed;
m_Sector->ceilingplane.setD(movedest); m_Sector->ceilingplane.setD(movedest);
@ -380,11 +380,11 @@ DMover::EResult DMover::MoveCeiling(double speed, double dest, int crush, int di
m_Sector->ceilingplane.setD(lastpos); m_Sector->ceilingplane.setD(lastpos);
P_ChangeSector (m_Sector, crush, -speed, 1, true); P_ChangeSector (m_Sector, crush, -speed, 1, true);
MoveAttached(crush, -speed, 1, false); MoveAttached(crush, -speed, 1, false);
return crushed; return EMoveResult::crushed;
} }
m_Sector->ChangePlaneTexZ(sector_t::ceiling, m_Sector->ceilingplane.HeightDiff (lastpos)); m_Sector->ChangePlaneTexZ(sector_t::ceiling, m_Sector->ceilingplane.HeightDiff (lastpos));
} }
break; break;
} }
return ok; return EMoveResult::ok;
} }

View file

@ -27,7 +27,6 @@ class DMover : public DSectorEffect
public: public:
DMover (sector_t *sector); DMover (sector_t *sector);
protected: protected:
enum EResult { ok, crushed, pastdest };
TObjPtr<DInterpolation> interpolation; TObjPtr<DInterpolation> interpolation;
private: private:
bool MoveAttached(int crush, double move, int floorOrCeiling, bool resetfailed); bool MoveAttached(int crush, double move, int floorOrCeiling, bool resetfailed);
@ -36,15 +35,15 @@ protected:
void Serialize (FArchive &arc); void Serialize (FArchive &arc);
void Destroy(); void Destroy();
void StopInterpolation(bool force = false); void StopInterpolation(bool force = false);
EResult MoveFloor(double speed, double dest, int crush, int direction, bool hexencrush); EMoveResult MoveFloor(double speed, double dest, int crush, int direction, bool hexencrush);
EResult MoveCeiling(double speed, double dest, int crush, int direction, bool hexencrush); EMoveResult MoveCeiling(double speed, double dest, int crush, int direction, bool hexencrush);
inline EResult MoveFloor(double speed, double dest, int direction) inline EMoveResult MoveFloor(double speed, double dest, int direction)
{ {
return MoveFloor(speed, dest, -1, direction, false); return MoveFloor(speed, dest, -1, direction, false);
} }
inline EResult MoveCeiling(double speed, double dest, int direction) inline EMoveResult MoveCeiling(double speed, double dest, int direction)
{ {
return MoveCeiling(speed, dest, -1, direction, false); return MoveCeiling(speed, dest, -1, direction, false);
} }

View file

@ -1545,7 +1545,7 @@ public:
bool Move(double speed, double dest, int crush, int direction) bool Move(double speed, double dest, int crush, int direction)
{ {
bool res = DMover::crushed != MoveFloor(speed, dest, crush, direction, false); bool res = EMoveResult::crushed != MoveFloor(speed, dest, crush, direction, false);
Destroy(); Destroy();
m_Sector->floordata=NULL; m_Sector->floordata=NULL;
StopInterpolation(true); StopInterpolation(true);
@ -1694,7 +1694,7 @@ public:
bool Move(double speed, double dest, int crush, int direction) bool Move(double speed, double dest, int crush, int direction)
{ {
bool res = DMover::crushed != MoveCeiling(speed, dest, crush, direction, false); bool res = EMoveResult::crushed != MoveCeiling(speed, dest, crush, direction, false);
Destroy(); Destroy();
m_Sector->ceilingdata=NULL; m_Sector->ceilingdata=NULL;
StopInterpolation (true); StopInterpolation (true);

View file

@ -127,7 +127,7 @@ void DCeiling::PlayCeilingSound ()
void DCeiling::Tick () void DCeiling::Tick ()
{ {
EResult res; EMoveResult res;
switch (m_Direction) switch (m_Direction)
{ {
@ -138,7 +138,7 @@ void DCeiling::Tick ()
// UP // UP
res = MoveCeiling (m_Speed, m_TopHeight, m_Direction); res = MoveCeiling (m_Speed, m_TopHeight, m_Direction);
if (res == pastdest) if (res == EMoveResult::pastdest)
{ {
switch (m_Type) switch (m_Type)
{ {
@ -169,7 +169,7 @@ void DCeiling::Tick ()
// DOWN // DOWN
res = MoveCeiling (m_Speed, m_BottomHeight, m_Crush, m_Direction, m_CrushMode == ECrushMode::crushHexen); res = MoveCeiling (m_Speed, m_BottomHeight, m_Crush, m_Direction, m_CrushMode == ECrushMode::crushHexen);
if (res == pastdest) if (res == EMoveResult::pastdest)
{ {
switch (m_Type) switch (m_Type)
{ {
@ -198,7 +198,7 @@ void DCeiling::Tick ()
} }
else // ( res != pastdest ) else // ( res != pastdest )
{ {
if (res == crushed) if (res == EMoveResult::crushed)
{ {
switch (m_Type) switch (m_Type)
{ {

View file

@ -80,7 +80,7 @@ void DDoor::Serialize (FArchive &arc)
void DDoor::Tick () void DDoor::Tick ()
{ {
EResult res; EMoveResult res;
// Adjust bottom height - but only if there isn't an active lift attached to the floor. // Adjust bottom height - but only if there isn't an active lift attached to the floor.
if (m_Sector->floorplane.fD() != m_OldFloorDist) if (m_Sector->floorplane.fD() != m_OldFloorDist)
@ -146,7 +146,7 @@ void DDoor::Tick ()
(m_Sector->ceilingplane.fD() + m_Sector->floorplane.fD()) / (m_TopDist + m_Sector->floorplane.fD())); (m_Sector->ceilingplane.fD() + m_Sector->floorplane.fD()) / (m_TopDist + m_Sector->floorplane.fD()));
} }
if (res == pastdest) if (res == EMoveResult::pastdest)
{ {
SN_StopSequence (m_Sector, CHAN_CEILING); SN_StopSequence (m_Sector, CHAN_CEILING);
switch (m_Type) switch (m_Type)
@ -166,7 +166,7 @@ void DDoor::Tick ()
break; break;
} }
} }
else if (res == crushed) else if (res == EMoveResult::crushed)
{ {
switch (m_Type) switch (m_Type)
{ {
@ -192,7 +192,7 @@ void DDoor::Tick ()
(m_Sector->ceilingplane.fD() + m_Sector->floorplane.fD()) / (m_TopDist + m_Sector->floorplane.fD())); (m_Sector->ceilingplane.fD() + m_Sector->floorplane.fD()) / (m_TopDist + m_Sector->floorplane.fD()));
} }
if (res == pastdest) if (res == EMoveResult::pastdest)
{ {
SN_StopSequence (m_Sector, CHAN_CEILING); SN_StopSequence (m_Sector, CHAN_CEILING);
switch (m_Type) switch (m_Type)
@ -212,7 +212,7 @@ void DDoor::Tick ()
break; break;
} }
} }
else if (res == crushed) else if (res == EMoveResult::crushed)
{ {
switch (m_Type) switch (m_Type)
{ {
@ -560,7 +560,7 @@ bool DAnimatedDoor::StartClosing ()
} }
double topdist = m_Sector->ceilingplane.fD(); double topdist = m_Sector->ceilingplane.fD();
if (MoveCeiling (2048., m_BotDist, 0, -1, false) == crushed) if (MoveCeiling (2048., m_BotDist, 0, -1, false) == EMoveResult::crushed)
{ {
return false; return false;
} }

View file

@ -112,7 +112,7 @@ void DFloor::Serialize (FArchive &arc)
void DFloor::Tick () void DFloor::Tick ()
{ {
EResult res; EMoveResult res;
// [RH] Handle resetting stairs // [RH] Handle resetting stairs
if (m_Type == buildStair || m_Type == waitStair) if (m_Type == buildStair || m_Type == waitStair)
@ -146,7 +146,7 @@ void DFloor::Tick ()
res = MoveFloor (m_Speed, m_FloorDestDist, m_Crush, m_Direction, m_Hexencrush); res = MoveFloor (m_Speed, m_FloorDestDist, m_Crush, m_Direction, m_Hexencrush);
if (res == pastdest) if (res == EMoveResult::pastdest)
{ {
SN_StopSequence (m_Sector, CHAN_FLOOR); SN_StopSequence (m_Sector, CHAN_FLOOR);
@ -898,7 +898,7 @@ void DElevator::Destroy()
void DElevator::Tick () void DElevator::Tick ()
{ {
EResult res; EMoveResult res;
double oldfloor, oldceiling; double oldfloor, oldceiling;
@ -908,10 +908,10 @@ void DElevator::Tick ()
if (m_Direction < 0) // moving down if (m_Direction < 0) // moving down
{ {
res = MoveFloor (m_Speed, m_FloorDestDist, m_Direction); res = MoveFloor (m_Speed, m_FloorDestDist, m_Direction);
if (res == ok || res == pastdest) if (res == EMoveResult::ok || res == EMoveResult::pastdest)
{ {
res = MoveCeiling (m_Speed, m_CeilingDestDist, m_Direction); res = MoveCeiling (m_Speed, m_CeilingDestDist, m_Direction);
if (res == crushed) if (res == EMoveResult::crushed)
{ {
MoveFloor (m_Speed, oldfloor, -m_Direction); MoveFloor (m_Speed, oldfloor, -m_Direction);
} }
@ -920,17 +920,17 @@ void DElevator::Tick ()
else // up else // up
{ {
res = MoveCeiling (m_Speed, m_CeilingDestDist, m_Direction); res = MoveCeiling (m_Speed, m_CeilingDestDist, m_Direction);
if (res == ok || res == pastdest) if (res == EMoveResult::ok || res == EMoveResult::pastdest)
{ {
res = MoveFloor (m_Speed, m_FloorDestDist, m_Direction); res = MoveFloor (m_Speed, m_FloorDestDist, m_Direction);
if (res == crushed) if (res == EMoveResult::crushed)
{ {
MoveCeiling (m_Speed, oldceiling, -m_Direction); MoveCeiling (m_Speed, oldceiling, -m_Direction);
} }
} }
} }
if (res == pastdest) // if destination height acheived if (res == EMoveResult::pastdest) // if destination height acheived
{ {
// make floor stop sound // make floor stop sound
SN_StopSequence (m_Sector, CHAN_FLOOR); SN_StopSequence (m_Sector, CHAN_FLOOR);

View file

@ -88,7 +88,7 @@ void DPillar::Serialize (FArchive &arc)
void DPillar::Tick () void DPillar::Tick ()
{ {
int r, s; EMoveResult r, s;
double oldfloor, oldceiling; double oldfloor, oldceiling;
oldfloor = m_Sector->floorplane.fD(); oldfloor = m_Sector->floorplane.fD();
@ -105,18 +105,18 @@ void DPillar::Tick ()
s = MoveCeiling (m_CeilingSpeed, m_CeilingTarget, m_Crush, 1, m_Hexencrush); s = MoveCeiling (m_CeilingSpeed, m_CeilingTarget, m_Crush, 1, m_Hexencrush);
} }
if (r == pastdest && s == pastdest) if (r == EMoveResult::pastdest && s == EMoveResult::pastdest)
{ {
SN_StopSequence (m_Sector, CHAN_FLOOR); SN_StopSequence (m_Sector, CHAN_FLOOR);
Destroy (); Destroy ();
} }
else else
{ {
if (r == crushed) if (r == EMoveResult::crushed)
{ {
MoveFloor (m_FloorSpeed, oldfloor, -1, -1, m_Hexencrush); MoveFloor (m_FloorSpeed, oldfloor, -1, -1, m_Hexencrush);
} }
if (s == crushed) if (s == EMoveResult::crushed)
{ {
MoveCeiling (m_CeilingSpeed, oldceiling, -1, 1, m_Hexencrush); MoveCeiling (m_CeilingSpeed, oldceiling, -1, 1, m_Hexencrush);
} }

View file

@ -94,20 +94,20 @@ void DPlat::PlayPlatSound (const char *sound)
// //
void DPlat::Tick () void DPlat::Tick ()
{ {
EResult res; EMoveResult res;
switch (m_Status) switch (m_Status)
{ {
case up: case up:
res = MoveFloor (m_Speed, m_High, m_Crush, 1, false); res = MoveFloor (m_Speed, m_High, m_Crush, 1, false);
if (res == crushed && (m_Crush == -1)) if (res == EMoveResult::crushed && (m_Crush == -1))
{ {
m_Count = m_Wait; m_Count = m_Wait;
m_Status = down; m_Status = down;
PlayPlatSound ("Platform"); PlayPlatSound ("Platform");
} }
else if (res == pastdest) else if (res == EMoveResult::pastdest)
{ {
SN_StopSequence (m_Sector, CHAN_FLOOR); SN_StopSequence (m_Sector, CHAN_FLOOR);
if (m_Type != platToggle) if (m_Type != platToggle)
@ -146,7 +146,7 @@ void DPlat::Tick ()
case down: case down:
res = MoveFloor (m_Speed, m_Low, -1, -1, false); res = MoveFloor (m_Speed, m_Low, -1, -1, false);
if (res == pastdest) if (res == EMoveResult::pastdest)
{ {
SN_StopSequence (m_Sector, CHAN_FLOOR); SN_StopSequence (m_Sector, CHAN_FLOOR);
// if not an instant toggle, start waiting // if not an instant toggle, start waiting
@ -172,7 +172,7 @@ void DPlat::Tick ()
m_Status = in_stasis; //for reactivation of toggle m_Status = in_stasis; //for reactivation of toggle
} }
} }
else if (res == crushed && m_Crush < 0 && m_Type != platToggle) else if (res == EMoveResult::crushed && m_Crush < 0 && m_Type != platToggle)
{ {
m_Status = up; m_Status = up;
m_Count = m_Wait; m_Count = m_Wait;

View file

@ -616,6 +616,8 @@ struct secspecial_t
FArchive &operator<< (FArchive &arc, secspecial_t &p); FArchive &operator<< (FArchive &arc, secspecial_t &p);
enum class EMoveResult { ok, crushed, pastdest };
struct sector_t struct sector_t
{ {
// Member functions // Member functions