- cleaned up p_ceiling.cpp

SVN r3077 (trunk)
This commit is contained in:
Christoph Oelckers 2010-12-26 00:21:19 +00:00
parent 231e7a1c6d
commit cc287d35a6
2 changed files with 283 additions and 247 deletions

View file

@ -30,9 +30,11 @@
#include "r_state.h" #include "r_state.h"
#include "gi.h" #include "gi.h"
//============================================================================
// //
// CEILINGS // CEILINGS
// //
//============================================================================
IMPLEMENT_CLASS (DCeiling) IMPLEMENT_CLASS (DCeiling)
@ -40,6 +42,12 @@ DCeiling::DCeiling ()
{ {
} }
//============================================================================
//
//
//
//============================================================================
void DCeiling::Serialize (FArchive &arc) void DCeiling::Serialize (FArchive &arc)
{ {
Super::Serialize (arc); Super::Serialize (arc);
@ -59,6 +67,12 @@ void DCeiling::Serialize (FArchive &arc)
<< m_Hexencrush; << m_Hexencrush;
} }
//============================================================================
//
//
//
//============================================================================
void DCeiling::PlayCeilingSound () void DCeiling::PlayCeilingSound ()
{ {
if (m_Sector->seqType >= 0) if (m_Sector->seqType >= 0)
@ -80,9 +94,12 @@ void DCeiling::PlayCeilingSound ()
} }
} }
//============================================================================
// //
// T_MoveCeiling // DCeiling :: Tick
// //
//============================================================================
void DCeiling::Tick () void DCeiling::Tick ()
{ {
EResult res; EResult res;
@ -176,6 +193,12 @@ void DCeiling::Tick ()
} }
} }
//============================================================================
//
//
//
//============================================================================
DCeiling::DCeiling (sector_t *sec) DCeiling::DCeiling (sector_t *sec)
: DMovingCeiling (sec) : DMovingCeiling (sec)
{ {
@ -191,78 +214,41 @@ DCeiling::DCeiling (sector_t *sec, fixed_t speed1, fixed_t speed2, int silent)
m_Silent = silent; m_Silent = silent;
} }
//============================================================================
// //
// EV_DoCeiling
// Move a ceiling up/down and all around!
// //
// [RH] Added tag, speed, speed2, height, crush, silent, change params //
bool EV_DoCeiling (DCeiling::ECeiling type, line_t *line, //============================================================================
int tag, fixed_t speed, fixed_t speed2, fixed_t height,
DCeiling *DCeiling::Create(sector_t *sec, DCeiling::ECeiling type, line_t *line, int tag,
fixed_t speed, fixed_t speed2, fixed_t height,
int crush, int silent, int change, bool hexencrush) int crush, int silent, int change, bool hexencrush)
{ {
int secnum;
bool rtn;
sector_t* sec;
DCeiling* ceiling;
bool manual = false;
fixed_t targheight = 0; // Silence, GCC fixed_t targheight = 0; // Silence, GCC
vertex_t* spot;
rtn = false;
// check if a manual trigger, if so do just the sector on the backside
if (tag == 0)
{
if (!line || !(sec = line->backsector))
return rtn;
secnum = (int)(sec-sectors);
manual = true;
// [RH] Hack to let manual crushers be retriggerable, too
tag ^= secnum | 0x1000000;
P_ActivateInStasisCeiling (tag);
goto manual_ceiling;
}
// Reactivate in-stasis ceilings...for certain types.
// This restarts a crusher after it has been stopped
if (type == DCeiling::ceilCrushAndRaise)
{
P_ActivateInStasisCeiling (tag);
}
secnum = -1;
// affects all sectors with the same tag as the linedef
while ((secnum = P_FindSectorFromTag (tag, secnum)) >= 0)
{
sec = &sectors[secnum];
manual_ceiling:
// if ceiling already moving, don't start a second function on it // if ceiling already moving, don't start a second function on it
if (sec->PlaneMoving(sector_t::ceiling)) if (sec->PlaneMoving(sector_t::ceiling))
{ {
if (!manual) return NULL;
continue;
else
return false;
} }
// new door thinker // new door thinker
rtn = 1; DCeiling *ceiling = new DCeiling (sec, speed, speed2, silent);
ceiling = new DCeiling (sec, speed, speed2, silent); vertex_t *spot = sec->lines[0]->v1;
spot = sec->lines[0]->v1;
switch (type) switch (type)
{ {
case DCeiling::ceilCrushAndRaise: case ceilCrushAndRaise:
case DCeiling::ceilCrushRaiseAndStay: case ceilCrushRaiseAndStay:
ceiling->m_TopHeight = sec->ceilingplane.d; ceiling->m_TopHeight = sec->ceilingplane.d;
case DCeiling::ceilLowerAndCrush: case ceilLowerAndCrush:
case DCeiling::ceilLowerAndCrushDist: case ceilLowerAndCrushDist:
targheight = sec->FindHighestFloorPoint (&spot); targheight = sec->FindHighestFloorPoint (&spot);
if (type == DCeiling::ceilLowerAndCrush) if (type == ceilLowerAndCrush)
{ {
targheight += 8*FRACUNIT; targheight += 8*FRACUNIT;
} }
else if (type == DCeiling::ceilLowerAndCrushDist) else if (type == ceilLowerAndCrushDist)
{ {
targheight += height; targheight += height;
} }
@ -270,25 +256,25 @@ manual_ceiling:
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilRaiseToHighest: case ceilRaiseToHighest:
targheight = sec->FindHighestCeilingSurrounding (&spot); targheight = sec->FindHighestCeilingSurrounding (&spot);
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
break; break;
case DCeiling::ceilLowerByValue: case ceilLowerByValue:
targheight = sec->ceilingplane.ZatPoint (spot) - height; targheight = sec->ceilingplane.ZatPoint (spot) - height;
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilRaiseByValue: case ceilRaiseByValue:
targheight = sec->ceilingplane.ZatPoint (spot) + height; targheight = sec->ceilingplane.ZatPoint (spot) + height;
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
break; break;
case DCeiling::ceilMoveToValue: case ceilMoveToValue:
{ {
int diff = height - sec->ceilingplane.ZatPoint (spot); int diff = height - sec->ceilingplane.ZatPoint (spot);
@ -306,81 +292,81 @@ manual_ceiling:
} }
break; break;
case DCeiling::ceilLowerToHighestFloor: case ceilLowerToHighestFloor:
targheight = sec->FindHighestFloorSurrounding (&spot); targheight = sec->FindHighestFloorSurrounding (&spot);
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilRaiseToHighestFloor: case ceilRaiseToHighestFloor:
targheight = sec->FindHighestFloorSurrounding (&spot); targheight = sec->FindHighestFloorSurrounding (&spot);
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
break; break;
case DCeiling::ceilLowerInstant: case ceilLowerInstant:
targheight = sec->ceilingplane.ZatPoint (spot) - height; targheight = sec->ceilingplane.ZatPoint (spot) - height;
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
ceiling->m_Speed = height; ceiling->m_Speed = height;
break; break;
case DCeiling::ceilRaiseInstant: case ceilRaiseInstant:
targheight = sec->ceilingplane.ZatPoint (spot) + height; targheight = sec->ceilingplane.ZatPoint (spot) + height;
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
ceiling->m_Speed = height; ceiling->m_Speed = height;
break; break;
case DCeiling::ceilLowerToNearest: case ceilLowerToNearest:
targheight = sec->FindNextLowestCeiling (&spot); targheight = sec->FindNextLowestCeiling (&spot);
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilRaiseToNearest: case ceilRaiseToNearest:
targheight = sec->FindNextHighestCeiling (&spot); targheight = sec->FindNextHighestCeiling (&spot);
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
break; break;
case DCeiling::ceilLowerToLowest: case ceilLowerToLowest:
targheight = sec->FindLowestCeilingSurrounding (&spot); targheight = sec->FindLowestCeilingSurrounding (&spot);
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilRaiseToLowest: case ceilRaiseToLowest:
targheight = sec->FindLowestCeilingSurrounding (&spot); targheight = sec->FindLowestCeilingSurrounding (&spot);
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
break; break;
case DCeiling::ceilLowerToFloor: case ceilLowerToFloor:
targheight = sec->FindHighestFloorPoint (&spot); targheight = sec->FindHighestFloorPoint (&spot);
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilRaiseToFloor: // [RH] What's this for? case ceilRaiseToFloor: // [RH] What's this for?
targheight = sec->FindHighestFloorPoint (&spot); targheight = sec->FindHighestFloorPoint (&spot);
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
break; break;
case DCeiling::ceilLowerToHighest: case ceilLowerToHighest:
targheight = sec->FindHighestCeilingSurrounding (&spot); targheight = sec->FindHighestCeilingSurrounding (&spot);
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilLowerByTexture: case ceilLowerByTexture:
targheight = sec->ceilingplane.ZatPoint (spot) - sec->FindShortestUpperAround (); targheight = sec->ceilingplane.ZatPoint (spot) - sec->FindShortestUpperAround ();
ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_BottomHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = -1; ceiling->m_Direction = -1;
break; break;
case DCeiling::ceilRaiseByTexture: case ceilRaiseByTexture:
targheight = sec->ceilingplane.ZatPoint (spot) + sec->FindShortestUpperAround (); targheight = sec->ceilingplane.ZatPoint (spot) + sec->FindShortestUpperAround ();
ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight); ceiling->m_TopHeight = sec->ceilingplane.PointToDist (spot, targheight);
ceiling->m_Direction = 1; ceiling->m_Direction = 1;
@ -422,10 +408,10 @@ manual_ceiling:
//jff 5/23/98 find model with floor at target height if target //jff 5/23/98 find model with floor at target height if target
//is a floor type //is a floor type
modelsec = (/*type == DCeiling::ceilRaiseToHighest ||*/ modelsec = (/*type == ceilRaiseToHighest ||*/
type == DCeiling::ceilRaiseToFloor || type == ceilRaiseToFloor ||
/*type == DCeiling::ceilLowerToHighest ||*/ /*type == ceilLowerToHighest ||*/
type == DCeiling::ceilLowerToFloor) ? type == ceilLowerToFloor) ?
sec->FindModelFloorSector (targheight) : sec->FindModelFloorSector (targheight) :
sec->FindModelCeilingSector (targheight); sec->FindModelCeilingSector (targheight);
if (modelsec != NULL) if (modelsec != NULL)
@ -435,14 +421,14 @@ manual_ceiling:
{ {
case 1: // type is zeroed case 1: // type is zeroed
ceiling->m_NewSpecial = 0; ceiling->m_NewSpecial = 0;
ceiling->m_Type = DCeiling::genCeilingChg0; ceiling->m_Type = genCeilingChg0;
break; break;
case 2: // type is copied case 2: // type is copied
ceiling->m_NewSpecial = sec->special; ceiling->m_NewSpecial = sec->special;
ceiling->m_Type = DCeiling::genCeilingChgT; ceiling->m_Type = genCeilingChgT;
break; break;
case 3: // type is left alone case 3: // type is left alone
ceiling->m_Type = DCeiling::genCeilingChg; ceiling->m_Type = genCeilingChg;
break; break;
} }
} }
@ -454,32 +440,78 @@ manual_ceiling:
{ {
case 1: // type is zeroed case 1: // type is zeroed
ceiling->m_NewSpecial = 0; ceiling->m_NewSpecial = 0;
ceiling->m_Type = DCeiling::genCeilingChg0; ceiling->m_Type = genCeilingChg0;
break; break;
case 2: // type is copied case 2: // type is copied
ceiling->m_NewSpecial = line->frontsector->special; ceiling->m_NewSpecial = line->frontsector->special;
ceiling->m_Type = DCeiling::genCeilingChgT; ceiling->m_Type = genCeilingChgT;
break; break;
case 3: // type is left alone case 3: // type is left alone
ceiling->m_Type = DCeiling::genCeilingChg; ceiling->m_Type = genCeilingChg;
break; break;
} }
} }
} }
ceiling->PlayCeilingSound (); ceiling->PlayCeilingSound ();
return ceiling;
}
if (manual) //============================================================================
//
// EV_DoCeiling
// Move a ceiling up/down and all around!
//
// [RH] Added tag, speed, speed2, height, crush, silent, change params
//
//============================================================================
bool EV_DoCeiling (DCeiling::ECeiling type, line_t *line,
int tag, fixed_t speed, fixed_t speed2, fixed_t height,
int crush, int silent, int change, bool hexencrush)
{
int secnum;
bool rtn;
sector_t* sec;
rtn = false;
// check if a manual trigger, if so do just the sector on the backside
if (tag == 0)
{
if (!line || !(sec = line->backsector))
return rtn; return rtn;
secnum = (int)(sec-sectors);
// [RH] Hack to let manual crushers be retriggerable, too
tag ^= secnum | 0x1000000;
P_ActivateInStasisCeiling (tag);
return !!DCeiling::Create(sec, type, line, tag, speed, speed2, height, crush, silent, change, hexencrush);
}
// Reactivate in-stasis ceilings...for certain types.
// This restarts a crusher after it has been stopped
if (type == DCeiling::ceilCrushAndRaise)
{
P_ActivateInStasisCeiling (tag);
}
secnum = -1;
// affects all sectors with the same tag as the linedef
while ((secnum = P_FindSectorFromTag (tag, secnum)) >= 0)
{
rtn |= !!DCeiling::Create(&sectors[secnum], type, line, tag, speed, speed2, height, crush, silent, change, hexencrush);
} }
return rtn; return rtn;
} }
//============================================================================
// //
// Restart a ceiling that's in-stasis // Restart a ceiling that's in-stasis
// [RH] Passed a tag instead of a line and rewritten to use a list // [RH] Passed a tag instead of a line and rewritten to use a list
// //
//============================================================================
void P_ActivateInStasisCeiling (int tag) void P_ActivateInStasisCeiling (int tag)
{ {
DCeiling *scan; DCeiling *scan;
@ -495,11 +527,14 @@ void P_ActivateInStasisCeiling (int tag)
} }
} }
//============================================================================
// //
// EV_CeilingCrushStop // EV_CeilingCrushStop
// Stop a ceiling from crushing! // Stop a ceiling from crushing!
// [RH] Passed a tag instead of a line and rewritten to use a list // [RH] Passed a tag instead of a line and rewritten to use a list
// //
//============================================================================
bool EV_CeilingCrushStop (int tag) bool EV_CeilingCrushStop (int tag)
{ {
bool rtn = false; bool rtn = false;

View file

@ -677,6 +677,10 @@ public:
void Serialize (FArchive &arc); void Serialize (FArchive &arc);
void Tick (); void Tick ();
static DCeiling *Create(sector_t *sec, DCeiling::ECeiling type, line_t *line, int tag,
fixed_t speed, fixed_t speed2, fixed_t height,
int crush, int silent, int change, bool hexencrush);
protected: protected:
ECeiling m_Type; ECeiling m_Type;
fixed_t m_BottomHeight; fixed_t m_BottomHeight;
@ -702,9 +706,6 @@ protected:
private: private:
DCeiling (); DCeiling ();
friend bool EV_DoCeiling (DCeiling::ECeiling type, line_t *line,
int tag, fixed_t speed, fixed_t speed2, fixed_t height,
int crush, int silent, int change, bool hexencrush);
friend bool EV_CeilingCrushStop (int tag); friend bool EV_CeilingCrushStop (int tag);
friend void P_ActivateInStasisCeiling (int tag); friend void P_ActivateInStasisCeiling (int tag);
}; };