2006-02-24 04:48:15 +00:00
//**************************************************************************
//**
//** PO_MAN.C : Heretic 2 : Raven Software, Corp.
//**
//** $RCSfile: po_man.c,v $
//** $Revision: 1.22 $
//** $Date: 95/09/28 18:20:56 $
//** $Author: cjr $
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
# include "doomdef.h"
# include "p_local.h"
# include "i_system.h"
# include "w_wad.h"
# include "m_swap.h"
# include "m_bbox.h"
# include "tables.h"
# include "s_sndseq.h"
# include "a_sharedglobal.h"
2011-11-25 21:49:03 +00:00
# include "p_3dmidtex.h"
2008-05-22 19:35:38 +00:00
# include "p_lnspec.h"
2011-07-06 08:50:15 +00:00
# include "r_data/r_interpolate.h"
2009-05-15 17:21:45 +00:00
# include "g_level.h"
2010-07-23 05:56:25 +00:00
# include "po_man.h"
2010-08-01 05:16:09 +00:00
# include "p_setup.h"
2010-08-01 19:14:10 +00:00
# include "vectors.h"
2011-07-06 14:20:54 +00:00
# include "farchive.h"
2006-02-24 04:48:15 +00:00
// MACROS ------------------------------------------------------------------
# define PO_MAXPOLYSEGS 64
// TYPES -------------------------------------------------------------------
2010-07-23 05:56:25 +00:00
inline vertex_t * side_t : : V1 ( ) const
{
return this = = linedef - > sidedef [ 0 ] ? linedef - > v1 : linedef - > v2 ;
}
inline vertex_t * side_t : : V2 ( ) const
{
return this = = linedef - > sidedef [ 0 ] ? linedef - > v2 : linedef - > v1 ;
}
2011-07-06 14:20:54 +00:00
FArchive & operator < < ( FArchive & arc , FPolyObj * & poly )
{
return arc . SerializePointer ( polyobjs , ( BYTE * * ) & poly , sizeof ( FPolyObj ) ) ;
}
FArchive & operator < < ( FArchive & arc , const FPolyObj * & poly )
{
return arc . SerializePointer ( polyobjs , ( BYTE * * ) & poly , sizeof ( FPolyObj ) ) ;
}
2008-06-01 20:43:02 +00:00
inline FArchive & operator < < ( FArchive & arc , podoortype_t & type )
{
BYTE val = ( BYTE ) type ;
arc < < val ;
type = ( podoortype_t ) val ;
return arc ;
}
class DPolyAction : public DThinker
{
DECLARE_CLASS ( DPolyAction , DThinker )
2008-06-04 17:53:15 +00:00
HAS_OBJECT_POINTERS
2008-06-01 20:43:02 +00:00
public :
DPolyAction ( int polyNum ) ;
void Serialize ( FArchive & arc ) ;
2008-06-04 17:53:15 +00:00
void Destroy ( ) ;
2010-08-01 19:14:10 +00:00
void Stop ( ) ;
2010-07-23 05:56:25 +00:00
int GetSpeed ( ) const { return m_Speed ; }
2008-06-01 20:43:02 +00:00
void StopInterpolation ( ) ;
protected :
DPolyAction ( ) ;
int m_PolyObj ;
int m_Speed ;
int m_Dist ;
2008-06-04 17:53:15 +00:00
TObjPtr < DInterpolation > m_Interpolation ;
2008-06-01 20:43:02 +00:00
void SetInterpolation ( ) ;
} ;
class DRotatePoly : public DPolyAction
{
DECLARE_CLASS ( DRotatePoly , DPolyAction )
public :
DRotatePoly ( int polyNum ) ;
void Tick ( ) ;
private :
DRotatePoly ( ) ;
friend bool EV_RotatePoly ( line_t * line , int polyNum , int speed , int byteAngle , int direction , bool overRide ) ;
} ;
class DMovePoly : public DPolyAction
{
DECLARE_CLASS ( DMovePoly , DPolyAction )
public :
DMovePoly ( int polyNum ) ;
void Serialize ( FArchive & arc ) ;
void Tick ( ) ;
protected :
DMovePoly ( ) ;
int m_Angle ;
fixed_t m_xSpeed ; // for sliding walls
fixed_t m_ySpeed ;
friend bool EV_MovePoly ( line_t * line , int polyNum , int speed , angle_t angle , fixed_t dist , bool overRide ) ;
} ;
2010-08-01 19:14:10 +00:00
class DMovePolyTo : public DPolyAction
{
DECLARE_CLASS ( DMovePolyTo , DPolyAction )
public :
DMovePolyTo ( int polyNum ) ;
void Serialize ( FArchive & arc ) ;
void Tick ( ) ;
protected :
DMovePolyTo ( ) ;
fixed_t m_xSpeed ;
fixed_t m_ySpeed ;
fixed_t m_xTarget ;
fixed_t m_yTarget ;
2010-08-10 19:06:33 +00:00
friend bool EV_MovePolyTo ( line_t * line , int polyNum , int speed , fixed_t x , fixed_t y , bool overRide ) ;
2010-08-01 19:14:10 +00:00
} ;
2008-06-01 20:43:02 +00:00
class DPolyDoor : public DMovePoly
{
DECLARE_CLASS ( DPolyDoor , DMovePoly )
public :
DPolyDoor ( int polyNum , podoortype_t type ) ;
void Serialize ( FArchive & arc ) ;
void Tick ( ) ;
protected :
int m_Direction ;
int m_TotalDist ;
int m_Tics ;
int m_WaitTics ;
podoortype_t m_Type ;
bool m_Close ;
friend bool EV_OpenPolyDoor ( line_t * line , int polyNum , int speed , angle_t angle , int delay , int distance , podoortype_t type ) ;
private :
DPolyDoor ( ) ;
} ;
2012-03-02 02:23:37 +00:00
class FPolyMirrorIterator
{
FPolyObj * CurPoly ;
int UsedPolys [ 100 ] ; // tracks mirrored polyobjects we've seen
int NumUsedPolys ;
public :
FPolyMirrorIterator ( FPolyObj * poly ) ;
FPolyObj * NextMirror ( ) ;
} ;
2006-02-24 04:48:15 +00:00
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void PO_Init ( void ) ;
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void RotatePt ( int an , fixed_t * x , fixed_t * y , fixed_t startSpotX ,
fixed_t startSpotY ) ;
2008-06-01 20:43:02 +00:00
static void UnLinkPolyobj ( FPolyObj * po ) ;
static void LinkPolyobj ( FPolyObj * po ) ;
2010-07-23 05:56:25 +00:00
static bool CheckMobjBlocking ( side_t * seg , FPolyObj * po ) ;
2006-02-24 04:48:15 +00:00
static void InitBlockMap ( void ) ;
2010-07-25 21:38:34 +00:00
static void IterFindPolySides ( FPolyObj * po , side_t * side ) ;
2006-02-24 04:48:15 +00:00
static void SpawnPolyobj ( int index , int tag , int type ) ;
static void TranslateToStartSpot ( int tag , int originX , int originY ) ;
2008-06-01 20:43:02 +00:00
static void DoMovePolyobj ( FPolyObj * po , int x , int y ) ;
2006-02-24 04:48:15 +00:00
static void InitSegLists ( ) ;
static void KillSegLists ( ) ;
2010-08-01 02:41:56 +00:00
static FPolyNode * NewPolyNode ( ) ;
static void FreePolyNode ( ) ;
static void ReleaseAllPolyNodes ( ) ;
2006-02-24 04:48:15 +00:00
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern seg_t * segs ;
// PUBLIC DATA DEFINITIONS -------------------------------------------------
polyblock_t * * PolyBlockMap ;
2008-06-01 20:43:02 +00:00
FPolyObj * polyobjs ; // list of all poly-objects on the level
2006-02-24 04:48:15 +00:00
int po_NumPolyobjs ;
polyspawns_t * polyspawns ; // [RH] Let P_SpawnMapThings() find our thingies for us
// PRIVATE DATA DEFINITIONS ------------------------------------------------
2010-07-23 05:56:25 +00:00
static TArray < SDWORD > KnownPolySides ;
2010-08-01 02:41:56 +00:00
static FPolyNode * FreePolyNodes ;
2006-02-24 04:48:15 +00:00
// CODE --------------------------------------------------------------------
2010-07-23 05:56:25 +00:00
//==========================================================================
//
//
//
//==========================================================================
2008-06-04 17:53:15 +00:00
IMPLEMENT_POINTY_CLASS ( DPolyAction )
DECLARE_POINTER ( m_Interpolation )
END_POINTERS
2006-02-24 04:48:15 +00:00
DPolyAction : : DPolyAction ( )
{
}
void DPolyAction : : Serialize ( FArchive & arc )
{
Super : : Serialize ( arc ) ;
2008-06-04 17:53:15 +00:00
arc < < m_PolyObj < < m_Speed < < m_Dist < < m_Interpolation ;
2006-02-24 04:48:15 +00:00
}
DPolyAction : : DPolyAction ( int polyNum )
{
m_PolyObj = polyNum ;
m_Speed = 0 ;
m_Dist = 0 ;
SetInterpolation ( ) ;
}
2008-06-04 17:53:15 +00:00
void DPolyAction : : Destroy ( )
2006-02-24 04:48:15 +00:00
{
2009-10-27 02:43:00 +00:00
FPolyObj * poly = PO_GetPolyobj ( m_PolyObj ) ;
2006-02-24 04:48:15 +00:00
2010-08-01 19:14:10 +00:00
if ( poly - > specialdata = = this )
2006-02-24 04:48:15 +00:00
{
poly - > specialdata = NULL ;
}
2008-06-04 17:53:15 +00:00
StopInterpolation ( ) ;
Super : : Destroy ( ) ;
2006-02-24 04:48:15 +00:00
}
2010-08-01 19:14:10 +00:00
void DPolyAction : : Stop ( )
{
FPolyObj * poly = PO_GetPolyobj ( m_PolyObj ) ;
SN_StopSequence ( poly ) ;
Destroy ( ) ;
}
2006-02-24 04:48:15 +00:00
void DPolyAction : : SetInterpolation ( )
{
2009-10-27 02:43:00 +00:00
FPolyObj * poly = PO_GetPolyobj ( m_PolyObj ) ;
2008-06-04 17:53:15 +00:00
m_Interpolation = poly - > SetInterpolation ( ) ;
2006-02-24 04:48:15 +00:00
}
void DPolyAction : : StopInterpolation ( )
{
2008-06-04 17:53:15 +00:00
if ( m_Interpolation ! = NULL )
2006-02-24 04:48:15 +00:00
{
2008-06-04 17:53:15 +00:00
m_Interpolation - > DelRef ( ) ;
m_Interpolation = NULL ;
2006-02-24 04:48:15 +00:00
}
}
2010-07-23 05:56:25 +00:00
//==========================================================================
//
//
//
//==========================================================================
IMPLEMENT_CLASS ( DRotatePoly )
2006-02-24 04:48:15 +00:00
DRotatePoly : : DRotatePoly ( )
{
}
DRotatePoly : : DRotatePoly ( int polyNum )
: Super ( polyNum )
{
}
2010-07-23 05:56:25 +00:00
//==========================================================================
//
//
//
//==========================================================================
IMPLEMENT_CLASS ( DMovePoly )
2006-02-24 04:48:15 +00:00
DMovePoly : : DMovePoly ( )
{
}
void DMovePoly : : Serialize ( FArchive & arc )
{
Super : : Serialize ( arc ) ;
arc < < m_Angle < < m_xSpeed < < m_ySpeed ;
}
DMovePoly : : DMovePoly ( int polyNum )
: Super ( polyNum )
{
m_Angle = 0 ;
m_xSpeed = 0 ;
m_ySpeed = 0 ;
}
2010-08-01 19:14:10 +00:00
//==========================================================================
//
//
//
//
//==========================================================================
IMPLEMENT_CLASS ( DMovePolyTo )
DMovePolyTo : : DMovePolyTo ( )
{
}
void DMovePolyTo : : Serialize ( FArchive & arc )
{
Super : : Serialize ( arc ) ;
arc < < m_xSpeed < < m_ySpeed < < m_xTarget < < m_yTarget ;
}
DMovePolyTo : : DMovePolyTo ( int polyNum )
: Super ( polyNum )
{
m_xSpeed = 0 ;
m_ySpeed = 0 ;
m_xTarget = 0 ;
m_yTarget = 0 ;
}
2010-07-23 05:56:25 +00:00
//==========================================================================
//
//
//
//==========================================================================
IMPLEMENT_CLASS ( DPolyDoor )
2006-02-24 04:48:15 +00:00
DPolyDoor : : DPolyDoor ( )
{
}
void DPolyDoor : : Serialize ( FArchive & arc )
{
Super : : Serialize ( arc ) ;
arc < < m_Direction < < m_TotalDist < < m_Tics < < m_WaitTics < < m_Type < < m_Close ;
}
DPolyDoor : : DPolyDoor ( int polyNum , podoortype_t type )
: Super ( polyNum ) , m_Type ( type )
{
m_Direction = 0 ;
m_TotalDist = 0 ;
m_Tics = 0 ;
m_WaitTics = 0 ;
m_Close = false ;
}
// ===== Polyobj Event Code =====
//==========================================================================
//
// T_RotatePoly
//
//==========================================================================
void DRotatePoly : : Tick ( )
{
2010-07-23 05:56:25 +00:00
FPolyObj * poly = PO_GetPolyobj ( m_PolyObj ) ;
if ( poly = = NULL ) return ;
2013-06-06 20:08:56 +00:00
// Don't let non-perpetual polyobjs overshoot their targets.
if ( m_Dist ! = - 1 & & ( unsigned int ) m_Dist < ( unsigned int ) abs ( m_Speed ) )
2006-02-24 04:48:15 +00:00
{
2013-06-06 20:08:56 +00:00
m_Speed = m_Speed < 0 ? - m_Dist : m_Dist ;
}
2006-02-24 04:48:15 +00:00
2013-06-06 20:08:56 +00:00
if ( poly - > RotatePolyobj ( m_Speed ) )
{
2006-04-11 16:27:41 +00:00
if ( m_Dist = = - 1 )
2006-02-24 04:48:15 +00:00
{ // perpetual polyobj
return ;
}
2013-06-06 20:08:56 +00:00
m_Dist - = abs ( m_Speed ) ;
2006-05-07 00:27:22 +00:00
if ( m_Dist = = 0 )
2006-02-24 04:48:15 +00:00
{
SN_StopSequence ( poly ) ;
Destroy ( ) ;
}
}
}
//==========================================================================
//
// EV_RotatePoly
//
//==========================================================================
bool EV_RotatePoly ( line_t * line , int polyNum , int speed , int byteAngle ,
2006-09-14 00:02:31 +00:00
int direction , bool overRide )
2006-02-24 04:48:15 +00:00
{
2012-03-02 02:23:37 +00:00
DRotatePoly * pe = NULL ;
2008-06-01 20:43:02 +00:00
FPolyObj * poly ;
2006-02-24 04:48:15 +00:00
2012-03-02 02:23:37 +00:00
if ( ( poly = PO_GetPolyobj ( polyNum ) ) = = NULL )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
Printf ( " EV_RotatePoly: Invalid polyobj num: %d \n " , polyNum ) ;
return false ;
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
FPolyMirrorIterator it ( poly ) ;
while ( ( poly = it . NextMirror ( ) ) ! = NULL )
2006-02-24 04:48:15 +00:00
{
2012-03-02 02:23:37 +00:00
if ( poly - > specialdata ! = NULL & & ! overRide )
{ // poly is already in motion
2010-07-23 05:56:25 +00:00
break ;
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
pe = new DRotatePoly ( poly - > tag ) ;
2006-02-24 04:48:15 +00:00
poly - > specialdata = pe ;
2012-03-02 02:23:37 +00:00
if ( byteAngle ! = 0 )
2006-02-24 04:48:15 +00:00
{
if ( byteAngle = = 255 )
{
pe - > m_Dist = ~ 0 ;
}
else
{
pe - > m_Dist = byteAngle * ( ANGLE_90 / 64 ) ; // Angle
}
}
else
{
pe - > m_Dist = ANGLE_MAX - 1 ;
}
2013-06-06 20:08:56 +00:00
pe - > m_Speed = speed * direction * ( ANGLE_90 / ( 64 < < 3 ) ) ;
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
SN_StartSequence ( poly , poly - > seqType , SEQ_DOOR , 0 ) ;
2012-03-02 02:23:37 +00:00
direction = - direction ; // Reverse the direction
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
return pe ! = NULL ; // Return true if something started moving.
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// T_MovePoly
//
//==========================================================================
void DMovePoly : : Tick ( )
{
2010-07-23 05:56:25 +00:00
FPolyObj * poly = PO_GetPolyobj ( m_PolyObj ) ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
if ( poly ! = NULL )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
if ( poly - > MovePolyobj ( m_xSpeed , m_ySpeed ) )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
int absSpeed = abs ( m_Speed ) ;
m_Dist - = absSpeed ;
if ( m_Dist < = 0 )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
SN_StopSequence ( poly ) ;
Destroy ( ) ;
}
else if ( m_Dist < absSpeed )
{
m_Speed = m_Dist * ( m_Speed < 0 ? - 1 : 1 ) ;
m_xSpeed = FixedMul ( m_Speed , finecosine [ m_Angle ] ) ;
m_ySpeed = FixedMul ( m_Speed , finesine [ m_Angle ] ) ;
2006-02-24 04:48:15 +00:00
}
}
}
}
//==========================================================================
//
// EV_MovePoly
//
//==========================================================================
bool EV_MovePoly ( line_t * line , int polyNum , int speed , angle_t angle ,
2006-09-14 00:02:31 +00:00
fixed_t dist , bool overRide )
2006-02-24 04:48:15 +00:00
{
2012-03-02 02:23:37 +00:00
DMovePoly * pe = NULL ;
2008-06-01 20:43:02 +00:00
FPolyObj * poly ;
2012-03-02 02:23:37 +00:00
angle_t an = angle ;
2006-02-24 04:48:15 +00:00
2012-03-02 02:23:37 +00:00
if ( ( poly = PO_GetPolyobj ( polyNum ) ) = = NULL )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
Printf ( " EV_MovePoly: Invalid polyobj num: %d \n " , polyNum ) ;
return false ;
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
FPolyMirrorIterator it ( poly ) ;
2006-02-24 04:48:15 +00:00
2012-03-02 02:23:37 +00:00
while ( ( poly = it . NextMirror ( ) ) ! = NULL )
2006-02-24 04:48:15 +00:00
{
2012-03-02 02:23:37 +00:00
if ( poly - > specialdata ! = NULL & & ! overRide )
{ // poly is already in motion
2006-02-24 04:48:15 +00:00
break ;
}
2012-03-02 02:23:37 +00:00
pe = new DMovePoly ( poly - > tag ) ;
2006-02-24 04:48:15 +00:00
poly - > specialdata = pe ;
pe - > m_Dist = dist ; // Distance
pe - > m_Speed = speed ;
2012-03-02 02:23:37 +00:00
pe - > m_Angle = an > > ANGLETOFINESHIFT ;
2006-02-24 04:48:15 +00:00
pe - > m_xSpeed = FixedMul ( pe - > m_Speed , finecosine [ pe - > m_Angle ] ) ;
pe - > m_ySpeed = FixedMul ( pe - > m_Speed , finesine [ pe - > m_Angle ] ) ;
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
SN_StartSequence ( poly , poly - > seqType , SEQ_DOOR , 0 ) ;
2012-03-02 02:23:37 +00:00
// Do not interpolate very fast moving polyobjects. The minimum tic count is
// 3 instead of 2, because the moving crate effect in Massmouth 2, Hostitality
// that this fixes isn't quite fast enough to move the crate back to its start
// in just 1 tic.
2006-02-24 04:48:15 +00:00
if ( dist / speed < = 2 )
{
pe - > StopInterpolation ( ) ;
}
2012-03-02 02:23:37 +00:00
an = an + ANGLE_180 ; // Reverse the angle.
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
return pe ! = NULL ; // Return true if something started moving.
2006-02-24 04:48:15 +00:00
}
2010-08-01 19:14:10 +00:00
//==========================================================================
//
// DMovePolyTo :: Tick
//
//==========================================================================
void DMovePolyTo : : Tick ( )
{
FPolyObj * poly = PO_GetPolyobj ( m_PolyObj ) ;
if ( poly ! = NULL )
{
if ( poly - > MovePolyobj ( m_xSpeed , m_ySpeed ) )
{
int absSpeed = abs ( m_Speed ) ;
m_Dist - = absSpeed ;
if ( m_Dist < = 0 )
{
SN_StopSequence ( poly ) ;
Destroy ( ) ;
}
else if ( m_Dist < absSpeed )
{
m_Speed = m_Dist * ( m_Speed < 0 ? - 1 : 1 ) ;
m_xSpeed = m_xTarget - poly - > StartSpot . x ;
m_ySpeed = m_yTarget - poly - > StartSpot . y ;
}
}
}
}
//==========================================================================
//
// EV_MovePolyTo
//
//==========================================================================
2010-08-10 19:06:33 +00:00
bool EV_MovePolyTo ( line_t * line , int polyNum , int speed , fixed_t targx , fixed_t targy , bool overRide )
2010-08-01 19:14:10 +00:00
{
2012-03-02 02:23:37 +00:00
DMovePolyTo * pe = NULL ;
2010-08-01 19:14:10 +00:00
FPolyObj * poly ;
TVector2 < double > dist ;
double distlen ;
2012-03-02 02:23:37 +00:00
if ( ( poly = PO_GetPolyobj ( polyNum ) ) = = NULL )
2010-08-01 19:14:10 +00:00
{
Printf ( " EV_MovePolyTo: Invalid polyobj num: %d \n " , polyNum ) ;
return false ;
}
2012-03-02 02:23:37 +00:00
FPolyMirrorIterator it ( poly ) ;
2010-08-01 19:14:10 +00:00
dist . X = targx - poly - > StartSpot . x ;
dist . Y = targy - poly - > StartSpot . y ;
2012-03-02 02:23:37 +00:00
distlen = dist . MakeUnit ( ) ;
while ( ( poly = it . NextMirror ( ) ) ! = NULL )
2010-08-01 19:14:10 +00:00
{
2012-03-02 02:23:37 +00:00
if ( poly - > specialdata ! = NULL & & ! overRide )
{ // poly is already in motion
2010-08-01 19:14:10 +00:00
break ;
}
2012-03-02 02:23:37 +00:00
pe = new DMovePolyTo ( poly - > tag ) ;
2010-08-01 19:14:10 +00:00
poly - > specialdata = pe ;
pe - > m_Dist = xs_RoundToInt ( distlen ) ;
pe - > m_Speed = speed ;
pe - > m_xSpeed = xs_RoundToInt ( speed * dist . X ) ;
pe - > m_ySpeed = xs_RoundToInt ( speed * dist . Y ) ;
pe - > m_xTarget = xs_RoundToInt ( poly - > StartSpot . x + distlen * dist . X ) ;
pe - > m_yTarget = xs_RoundToInt ( poly - > StartSpot . y + distlen * dist . Y ) ;
2012-03-02 02:23:37 +00:00
if ( ( pe - > m_Dist / pe - > m_Speed ) < = 2 )
2010-08-01 19:14:10 +00:00
{
pe - > StopInterpolation ( ) ;
}
2012-03-02 02:23:37 +00:00
dist = - dist ; // reverse the direction
2010-08-01 19:14:10 +00:00
}
2012-03-02 02:23:37 +00:00
return pe ! = NULL ; // Return true if something started moving.
2010-08-01 19:14:10 +00:00
}
2006-02-24 04:48:15 +00:00
//==========================================================================
//
// T_PolyDoor
//
//==========================================================================
void DPolyDoor : : Tick ( )
{
int absSpeed ;
2010-07-23 05:56:25 +00:00
FPolyObj * poly = PO_GetPolyobj ( m_PolyObj ) ;
if ( poly = = NULL ) return ;
2006-02-24 04:48:15 +00:00
if ( m_Tics )
{
if ( ! - - m_Tics )
{
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
SN_StartSequence ( poly , poly - > seqType , SEQ_DOOR , m_Close ) ;
2006-02-24 04:48:15 +00:00
}
return ;
}
switch ( m_Type )
{
case PODOOR_SLIDE :
2010-07-23 05:56:25 +00:00
if ( m_Dist < = 0 | | poly - > MovePolyobj ( m_xSpeed , m_ySpeed ) )
2006-02-24 04:48:15 +00:00
{
absSpeed = abs ( m_Speed ) ;
m_Dist - = absSpeed ;
if ( m_Dist < = 0 )
{
SN_StopSequence ( poly ) ;
if ( ! m_Close )
{
m_Dist = m_TotalDist ;
m_Close = true ;
m_Tics = m_WaitTics ;
2010-07-23 05:56:25 +00:00
m_Direction = ( ANGLE_MAX > > ANGLETOFINESHIFT ) - m_Direction ;
2006-02-24 04:48:15 +00:00
m_xSpeed = - m_xSpeed ;
m_ySpeed = - m_ySpeed ;
}
else
{
Destroy ( ) ;
}
}
}
else
{
if ( poly - > crush | | ! m_Close )
{ // continue moving if the poly is a crusher, or is opening
return ;
}
else
{ // open back up
m_Dist = m_TotalDist - m_Dist ;
m_Direction = ( ANGLE_MAX > > ANGLETOFINESHIFT ) -
m_Direction ;
m_xSpeed = - m_xSpeed ;
m_ySpeed = - m_ySpeed ;
m_Close = false ;
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
SN_StartSequence ( poly , poly - > seqType , SEQ_DOOR , 0 ) ;
2006-02-24 04:48:15 +00:00
}
}
break ;
case PODOOR_SWING :
2015-01-26 01:20:54 +00:00
if ( m_Dist < = 0 | | poly - > RotatePolyobj ( m_Speed ) )
2006-02-24 04:48:15 +00:00
{
absSpeed = abs ( m_Speed ) ;
m_Dist - = absSpeed ;
if ( m_Dist < = 0 )
{
SN_StopSequence ( poly ) ;
if ( ! m_Close )
{
m_Dist = m_TotalDist ;
m_Close = true ;
m_Tics = m_WaitTics ;
m_Speed = - m_Speed ;
}
else
{
Destroy ( ) ;
}
}
}
else
{
if ( poly - > crush | | ! m_Close )
{ // continue moving if the poly is a crusher, or is opening
return ;
}
else
{ // open back up and rewait
m_Dist = m_TotalDist - m_Dist ;
m_Speed = - m_Speed ;
m_Close = false ;
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
SN_StartSequence ( poly , poly - > seqType , SEQ_DOOR , 0 ) ;
2006-02-24 04:48:15 +00:00
}
}
break ;
default :
break ;
}
}
//==========================================================================
//
// EV_OpenPolyDoor
//
//==========================================================================
bool EV_OpenPolyDoor ( line_t * line , int polyNum , int speed , angle_t angle ,
int delay , int distance , podoortype_t type )
{
2012-03-02 02:23:37 +00:00
DPolyDoor * pd = NULL ;
2008-06-01 20:43:02 +00:00
FPolyObj * poly ;
2012-03-02 02:23:37 +00:00
int swingdir = 1 ; // ADD: PODOOR_SWINGL, PODOOR_SWINGR
2006-02-24 04:48:15 +00:00
2012-03-02 02:23:37 +00:00
if ( ( poly = PO_GetPolyobj ( polyNum ) ) = = NULL )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
Printf ( " EV_OpenPolyDoor: Invalid polyobj num: %d \n " , polyNum ) ;
return false ;
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
FPolyMirrorIterator it ( poly ) ;
2006-02-24 04:48:15 +00:00
2012-03-02 02:23:37 +00:00
while ( ( poly = it . NextMirror ( ) ) ! = NULL )
2006-02-24 04:48:15 +00:00
{
2012-03-02 02:23:37 +00:00
if ( poly - > specialdata ! = NULL )
{ // poly is already moving
2006-02-24 04:48:15 +00:00
break ;
}
2012-03-02 02:23:37 +00:00
pd = new DPolyDoor ( poly - > tag , type ) ;
2006-02-24 04:48:15 +00:00
poly - > specialdata = pd ;
if ( type = = PODOOR_SLIDE )
{
pd - > m_WaitTics = delay ;
pd - > m_Speed = speed ;
pd - > m_Dist = pd - > m_TotalDist = distance ; // Distance
2012-03-02 02:23:37 +00:00
pd - > m_Direction = angle > > ANGLETOFINESHIFT ;
2006-02-24 04:48:15 +00:00
pd - > m_xSpeed = FixedMul ( pd - > m_Speed , finecosine [ pd - > m_Direction ] ) ;
pd - > m_ySpeed = FixedMul ( pd - > m_Speed , finesine [ pd - > m_Direction ] ) ;
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
SN_StartSequence ( poly , poly - > seqType , SEQ_DOOR , 0 ) ;
2012-03-02 02:23:37 +00:00
angle + = ANGLE_180 ; // reverse the angle
2006-02-24 04:48:15 +00:00
}
else if ( type = = PODOOR_SWING )
{
pd - > m_WaitTics = delay ;
2012-03-02 02:23:37 +00:00
pd - > m_Direction = swingdir ;
2006-02-24 04:48:15 +00:00
pd - > m_Speed = ( speed * pd - > m_Direction * ( ANGLE_90 / 64 ) ) > > 3 ;
pd - > m_Dist = pd - > m_TotalDist = angle ;
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
SN_StartSequence ( poly , poly - > seqType , SEQ_DOOR , 0 ) ;
2012-03-02 02:23:37 +00:00
swingdir = - swingdir ; // reverse the direction
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
2006-02-24 04:48:15 +00:00
}
2012-03-02 02:23:37 +00:00
return pd ! = NULL ; // Return true if something started moving.
2006-02-24 04:48:15 +00:00
}
2010-08-01 19:14:10 +00:00
//==========================================================================
//
// EV_StopPoly
//
//==========================================================================
bool EV_StopPoly ( int polynum )
{
FPolyObj * poly ;
if ( NULL ! = ( poly = PO_GetPolyobj ( polynum ) ) )
{
if ( poly - > specialdata ! = NULL )
{
poly - > specialdata - > Stop ( ) ;
}
return true ;
}
return false ;
}
2006-02-24 04:48:15 +00:00
// ===== Higher Level Poly Interface code =====
//==========================================================================
//
2009-10-27 02:43:00 +00:00
// PO_GetPolyobj
2006-02-24 04:48:15 +00:00
//
//==========================================================================
2009-10-27 02:43:00 +00:00
FPolyObj * PO_GetPolyobj ( int polyNum )
2006-02-24 04:48:15 +00:00
{
int i ;
for ( i = 0 ; i < po_NumPolyobjs ; i + + )
{
if ( polyobjs [ i ] . tag = = polyNum )
{
return & polyobjs [ i ] ;
}
}
return NULL ;
}
2010-07-23 05:56:25 +00:00
2006-02-24 04:48:15 +00:00
//==========================================================================
//
2010-07-23 05:56:25 +00:00
//
2006-02-24 04:48:15 +00:00
//
//==========================================================================
2010-07-23 05:56:25 +00:00
FPolyObj : : FPolyObj ( )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
StartSpot . x = StartSpot . y = 0 ;
angle = 0 ;
tag = 0 ;
memset ( bbox , 0 , sizeof ( bbox ) ) ;
validcount = 0 ;
crush = 0 ;
bHurtOnTouch = false ;
seqType = 0 ;
size = 0 ;
subsectorlinks = NULL ;
specialdata = NULL ;
interpolation = NULL ;
}
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
//==========================================================================
//
// GetPolyobjMirror
//
//==========================================================================
int FPolyObj : : GetMirror ( )
{
2013-06-23 03:35:03 +00:00
return MirrorNum ;
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// ThrustMobj
//
//==========================================================================
2010-07-23 05:56:25 +00:00
void FPolyObj : : ThrustMobj ( AActor * actor , side_t * side )
2006-02-24 04:48:15 +00:00
{
int thrustAngle ;
int thrustX ;
int thrustY ;
DPolyAction * pe ;
int force ;
if ( ! ( actor - > flags & MF_SHOOTABLE ) & & ! actor - > player )
{
return ;
}
2010-07-23 05:56:25 +00:00
vertex_t * v1 = side - > V1 ( ) ;
vertex_t * v2 = side - > V2 ( ) ;
thrustAngle = ( R_PointToAngle2 ( v1 - > x , v1 - > y , v2 - > x , v2 - > y ) - ANGLE_90 ) > > ANGLETOFINESHIFT ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
pe = static_cast < DPolyAction * > ( specialdata ) ;
2006-02-24 04:48:15 +00:00
if ( pe )
{
if ( pe - > IsKindOf ( RUNTIME_CLASS ( DRotatePoly ) ) )
{
2010-07-23 05:56:25 +00:00
force = pe - > GetSpeed ( ) > > 8 ;
2006-02-24 04:48:15 +00:00
}
else
{
2010-07-23 05:56:25 +00:00
force = pe - > GetSpeed ( ) > > 3 ;
2006-02-24 04:48:15 +00:00
}
if ( force < FRACUNIT )
{
force = FRACUNIT ;
}
else if ( force > 4 * FRACUNIT )
{
force = 4 * FRACUNIT ;
}
}
else
{
force = FRACUNIT ;
}
thrustX = FixedMul ( force , finecosine [ thrustAngle ] ) ;
thrustY = FixedMul ( force , finesine [ thrustAngle ] ) ;
2009-06-30 20:57:51 +00:00
actor - > velx + = thrustX ;
actor - > vely + = thrustY ;
2010-07-23 05:56:25 +00:00
if ( crush )
2006-02-24 04:48:15 +00:00
{
2016-01-20 00:48:57 +00:00
fixedvec2 pos = actor - > Vec2Offset ( thrustX , thrustY ) ;
if ( bHurtOnTouch | | ! P_CheckMove ( actor , pos . x , pos . y ) )
2006-02-24 04:48:15 +00:00
{
2013-01-02 04:39:59 +00:00
int newdam = P_DamageMobj ( actor , NULL , NULL , crush , NAME_Crush ) ;
P_TraceBleed ( newdam > 0 ? newdam : crush , actor ) ;
2006-02-24 04:48:15 +00:00
}
}
2009-05-15 17:21:45 +00:00
if ( level . flags2 & LEVEL2_POLYGRIND ) actor - > Grind ( false ) ; // crush corpses that get caught in a polyobject's way
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// UpdateSegBBox
//
//==========================================================================
2010-07-23 05:56:25 +00:00
void FPolyObj : : UpdateBBox ( )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
for ( unsigned i = 0 ; i < Linedefs . Size ( ) ; i + + )
{
line_t * line = Linedefs [ i ] ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
if ( line - > v1 - > x < line - > v2 - > x )
{
line - > bbox [ BOXLEFT ] = line - > v1 - > x ;
line - > bbox [ BOXRIGHT ] = line - > v2 - > x ;
}
else
{
line - > bbox [ BOXLEFT ] = line - > v2 - > x ;
line - > bbox [ BOXRIGHT ] = line - > v1 - > x ;
}
if ( line - > v1 - > y < line - > v2 - > y )
{
line - > bbox [ BOXBOTTOM ] = line - > v1 - > y ;
line - > bbox [ BOXTOP ] = line - > v2 - > y ;
}
else
{
line - > bbox [ BOXBOTTOM ] = line - > v2 - > y ;
line - > bbox [ BOXTOP ] = line - > v1 - > y ;
}
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
// Update the line's slopetype
line - > dx = line - > v2 - > x - line - > v1 - > x ;
line - > dy = line - > v2 - > y - line - > v1 - > y ;
2006-02-24 04:48:15 +00:00
}
2010-07-23 05:56:25 +00:00
CalcCenter ( ) ;
}
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
void FPolyObj : : CalcCenter ( )
{
SQWORD cx = 0 , cy = 0 ;
for ( unsigned i = 0 ; i < Vertices . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
cx + = Vertices [ i ] - > x ;
cy + = Vertices [ i ] - > y ;
2006-02-24 04:48:15 +00:00
}
2010-07-23 05:56:25 +00:00
CenterSpot . x = ( fixed_t ) ( cx / Vertices . Size ( ) ) ;
CenterSpot . y = ( fixed_t ) ( cy / Vertices . Size ( ) ) ;
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// PO_MovePolyobj
//
//==========================================================================
2010-07-23 05:56:25 +00:00
bool FPolyObj : : MovePolyobj ( int x , int y , bool force )
2006-02-24 04:48:15 +00:00
{
2013-03-21 02:07:42 +00:00
FBoundingBox oldbounds = Bounds ;
2010-07-23 05:56:25 +00:00
UnLinkPolyobj ( ) ;
DoMovePolyobj ( x , y ) ;
2006-02-24 04:48:15 +00:00
2006-11-21 05:43:34 +00:00
if ( ! force )
2006-02-24 04:48:15 +00:00
{
2006-11-21 05:43:34 +00:00
bool blocked = false ;
2010-07-23 05:56:25 +00:00
for ( unsigned i = 0 ; i < Sidedefs . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
if ( CheckMobjBlocking ( Sidedefs [ i ] ) )
2006-11-21 05:43:34 +00:00
{
blocked = true ;
}
}
if ( blocked )
{
2010-07-23 05:56:25 +00:00
DoMovePolyobj ( - x , - y ) ;
LinkPolyobj ( ) ;
2006-11-21 05:43:34 +00:00
return false ;
2006-02-24 04:48:15 +00:00
}
}
2010-07-23 05:56:25 +00:00
StartSpot . x + = x ;
StartSpot . y + = y ;
CenterSpot . x + = x ;
CenterSpot . y + = y ;
LinkPolyobj ( ) ;
ClearSubsectorLinks ( ) ;
2013-03-21 02:07:42 +00:00
RecalcActorFloorCeil ( Bounds | oldbounds ) ;
2006-02-24 04:48:15 +00:00
return true ;
}
//==========================================================================
//
// DoMovePolyobj
//
//==========================================================================
2010-07-23 05:56:25 +00:00
void FPolyObj : : DoMovePolyobj ( int x , int y )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
for ( unsigned i = 0 ; i < Vertices . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
Vertices [ i ] - > x + = x ;
Vertices [ i ] - > y + = y ;
PrevPts [ i ] . x + = x ;
PrevPts [ i ] . y + = y ;
}
for ( unsigned i = 0 ; i < Linedefs . Size ( ) ; i + + )
{
Linedefs [ i ] - > bbox [ BOXTOP ] + = y ;
Linedefs [ i ] - > bbox [ BOXBOTTOM ] + = y ;
Linedefs [ i ] - > bbox [ BOXLEFT ] + = x ;
Linedefs [ i ] - > bbox [ BOXRIGHT ] + = x ;
2006-02-24 04:48:15 +00:00
}
}
//==========================================================================
//
// RotatePt
//
//==========================================================================
static void RotatePt ( int an , fixed_t * x , fixed_t * y , fixed_t startSpotX , fixed_t startSpotY )
{
fixed_t tr_x = * x ;
fixed_t tr_y = * y ;
2012-02-28 03:05:31 +00:00
* x = ( DMulScale16 ( tr_x , finecosine [ an ] , - tr_y , finesine [ an ] ) & 0xFFFFFE00 ) + startSpotX ;
* y = ( DMulScale16 ( tr_x , finesine [ an ] , tr_y , finecosine [ an ] ) & 0xFFFFFE00 ) + startSpotY ;
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// PO_RotatePolyobj
//
//==========================================================================
2014-12-25 17:46:50 +00:00
bool FPolyObj : : RotatePolyobj ( angle_t angle , bool fromsave )
2006-02-24 04:48:15 +00:00
{
int an ;
2006-09-14 00:02:31 +00:00
bool blocked ;
2013-03-21 02:07:42 +00:00
FBoundingBox oldbounds = Bounds ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
an = ( this - > angle + angle ) > > ANGLETOFINESHIFT ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
UnLinkPolyobj ( ) ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
for ( unsigned i = 0 ; i < Vertices . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
PrevPts [ i ] . x = Vertices [ i ] - > x ;
PrevPts [ i ] . y = Vertices [ i ] - > y ;
Vertices [ i ] - > x = OriginalPts [ i ] . x ;
Vertices [ i ] - > y = OriginalPts [ i ] . y ;
RotatePt ( an , & Vertices [ i ] - > x , & Vertices [ i ] - > y , StartSpot . x , StartSpot . y ) ;
2006-02-24 04:48:15 +00:00
}
blocked = false ;
validcount + + ;
2010-07-23 05:56:25 +00:00
UpdateBBox ( ) ;
2014-12-25 17:46:50 +00:00
// If we are loading a savegame we do not really want to damage actors and be blocked by them. This can also cause crashes when trying to damage incompletely deserialized player pawns.
if ( ! fromsave )
2006-02-24 04:48:15 +00:00
{
2014-12-25 17:46:50 +00:00
for ( unsigned i = 0 ; i < Sidedefs . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2014-12-25 17:46:50 +00:00
if ( CheckMobjBlocking ( Sidedefs [ i ] ) )
{
blocked = true ;
}
2006-02-24 04:48:15 +00:00
}
2014-12-25 17:46:50 +00:00
if ( blocked )
2006-02-24 04:48:15 +00:00
{
2014-12-25 17:46:50 +00:00
for ( unsigned i = 0 ; i < Vertices . Size ( ) ; i + + )
{
Vertices [ i ] - > x = PrevPts [ i ] . x ;
Vertices [ i ] - > y = PrevPts [ i ] . y ;
}
UpdateBBox ( ) ;
LinkPolyobj ( ) ;
return false ;
2006-02-24 04:48:15 +00:00
}
}
2010-07-23 05:56:25 +00:00
this - > angle + = angle ;
LinkPolyobj ( ) ;
ClearSubsectorLinks ( ) ;
2013-03-21 02:07:42 +00:00
RecalcActorFloorCeil ( Bounds | oldbounds ) ;
2006-02-24 04:48:15 +00:00
return true ;
}
//==========================================================================
//
// UnLinkPolyobj
//
//==========================================================================
2010-07-23 05:56:25 +00:00
void FPolyObj : : UnLinkPolyobj ( )
2006-02-24 04:48:15 +00:00
{
polyblock_t * link ;
int i , j ;
int index ;
// remove the polyobj from each blockmap section
2010-07-23 05:56:25 +00:00
for ( j = bbox [ BOXBOTTOM ] ; j < = bbox [ BOXTOP ] ; j + + )
2006-02-24 04:48:15 +00:00
{
index = j * bmapwidth ;
2010-07-23 05:56:25 +00:00
for ( i = bbox [ BOXLEFT ] ; i < = bbox [ BOXRIGHT ] ; i + + )
2006-02-24 04:48:15 +00:00
{
if ( i > = 0 & & i < bmapwidth & & j > = 0 & & j < bmapheight )
{
link = PolyBlockMap [ index + i ] ;
2010-07-23 05:56:25 +00:00
while ( link ! = NULL & & link - > polyobj ! = this )
2006-02-24 04:48:15 +00:00
{
link = link - > next ;
}
if ( link = = NULL )
{ // polyobj not located in the link cell
continue ;
}
link - > polyobj = NULL ;
}
}
}
}
//==========================================================================
//
// CheckMobjBlocking
//
//==========================================================================
2010-07-23 05:56:25 +00:00
bool FPolyObj : : CheckMobjBlocking ( side_t * sd )
2006-02-24 04:48:15 +00:00
{
static TArray < AActor * > checker ;
FBlockNode * block ;
AActor * mobj ;
int i , j , k ;
int left , right , top , bottom ;
line_t * ld ;
2006-09-14 00:02:31 +00:00
bool blocked ;
2012-05-08 19:55:26 +00:00
bool performBlockingThrust ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
ld = sd - > linedef ;
2010-08-28 12:57:23 +00:00
2012-03-28 03:49:38 +00:00
top = GetSafeBlockY ( ld - > bbox [ BOXTOP ] - bmaporgy ) ;
bottom = GetSafeBlockY ( ld - > bbox [ BOXBOTTOM ] - bmaporgy ) ;
left = GetSafeBlockX ( ld - > bbox [ BOXLEFT ] - bmaporgx ) ;
right = GetSafeBlockX ( ld - > bbox [ BOXRIGHT ] - bmaporgx ) ;
2006-02-24 04:48:15 +00:00
blocked = false ;
checker . Clear ( ) ;
bottom = bottom < 0 ? 0 : bottom ;
bottom = bottom > = bmapheight ? bmapheight - 1 : bottom ;
top = top < 0 ? 0 : top ;
top = top > = bmapheight ? bmapheight - 1 : top ;
left = left < 0 ? 0 : left ;
left = left > = bmapwidth ? bmapwidth - 1 : left ;
right = right < 0 ? 0 : right ;
right = right > = bmapwidth ? bmapwidth - 1 : right ;
for ( j = bottom * bmapwidth ; j < = top * bmapwidth ; j + = bmapwidth )
{
for ( i = left ; i < = right ; i + + )
{
for ( block = blocklinks [ j + i ] ; block ! = NULL ; block = block - > NextActor )
{
mobj = block - > Me ;
for ( k = ( int ) checker . Size ( ) - 1 ; k > = 0 ; - - k )
{
if ( checker [ k ] = = mobj )
{
break ;
}
}
if ( k < 0 )
{
checker . Push ( mobj ) ;
if ( ( mobj - > flags & MF_SOLID ) & & ! ( mobj - > flags & MF_NOCLIP ) )
{
2012-03-29 05:09:56 +00:00
FLineOpening open ;
2012-05-08 19:55:26 +00:00
open . top = INT_MAX ;
open . bottom = - INT_MAX ;
2011-11-25 21:49:03 +00:00
// [TN] Check wether this actor gets blocked by the line.
2012-02-11 01:17:09 +00:00
if ( ld - > backsector ! = NULL & &
! ( ld - > flags & ( ML_BLOCKING | ML_BLOCKEVERYTHING ) )
2011-11-25 21:49:03 +00:00
& & ! ( ld - > flags & ML_BLOCK_PLAYERS & & mobj - > player )
& & ! ( ld - > flags & ML_BLOCKMONSTERS & & mobj - > flags3 & MF3_ISMONSTER )
& & ! ( ( mobj - > flags & MF_FLOAT ) & & ( ld - > flags & ML_BLOCK_FLOATERS ) )
& & ( ! ( ld - > flags & ML_3DMIDTEX ) | |
2012-03-29 05:09:56 +00:00
( ! P_LineOpening_3dMidtex ( mobj , ld , open ) & &
2016-01-20 00:48:57 +00:00
( mobj - > Top ( ) < open . top )
) | | ( open . abovemidtex & & mobj - > Z ( ) > mobj - > floorz ) )
2011-11-25 21:49:03 +00:00
)
{
2012-05-08 19:55:26 +00:00
// [BL] We can't just continue here since we must
// determine if the line's backsector is going to
// be blocked.
performBlockingThrust = false ;
}
else
{
performBlockingThrust = true ;
2011-11-25 21:49:03 +00:00
}
2016-01-20 00:48:57 +00:00
FBoundingBox box ( mobj - > X ( ) , mobj - > Y ( ) , mobj - > radius ) ;
2008-04-06 17:33:43 +00:00
if ( box . Right ( ) < = ld - > bbox [ BOXLEFT ]
| | box . Left ( ) > = ld - > bbox [ BOXRIGHT ]
| | box . Top ( ) < = ld - > bbox [ BOXBOTTOM ]
| | box . Bottom ( ) > = ld - > bbox [ BOXTOP ] )
2006-02-24 04:48:15 +00:00
{
continue ;
}
2008-04-06 17:33:43 +00:00
if ( box . BoxOnLineSide ( ld ) ! = - 1 )
2006-02-24 04:48:15 +00:00
{
continue ;
}
2010-08-28 12:57:23 +00:00
// We have a two-sided linedef so we should only check one side
// so that the thrust from both sides doesn't cancel each other out.
// Best use the one facing the player and ignore the back side.
if ( ld - > sidedef [ 1 ] ! = NULL )
{
2016-01-20 00:48:57 +00:00
int side = P_PointOnLineSidePrecise ( mobj - > X ( ) , mobj - > Y ( ) , ld ) ;
2010-08-28 12:57:23 +00:00
if ( ld - > sidedef [ side ] ! = sd )
{
continue ;
}
2012-05-08 19:55:26 +00:00
// [BL] See if we hit below the floor/ceiling of the poly.
else if ( ! performBlockingThrust & & (
2016-01-20 00:48:57 +00:00
mobj - > Z ( ) < ld - > sidedef [ ! side ] - > sector - > GetSecPlane ( sector_t : : floor ) . ZatPoint ( mobj ) | |
mobj - > Top ( ) > ld - > sidedef [ ! side ] - > sector - > GetSecPlane ( sector_t : : ceiling ) . ZatPoint ( mobj )
2012-05-08 19:55:26 +00:00
) )
{
performBlockingThrust = true ;
}
2010-08-28 12:57:23 +00:00
}
2012-05-08 19:55:26 +00:00
if ( performBlockingThrust )
{
ThrustMobj ( mobj , sd ) ;
blocked = true ;
}
else
continue ;
2006-02-24 04:48:15 +00:00
}
}
}
}
}
return blocked ;
}
//==========================================================================
//
2010-07-23 05:56:25 +00:00
// LinkPolyobj
2006-02-24 04:48:15 +00:00
//
//==========================================================================
2010-07-23 05:56:25 +00:00
void FPolyObj : : LinkPolyobj ( )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
polyblock_t * * link ;
polyblock_t * tempLink ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
// calculate the polyobj bbox
Bounds . ClearBox ( ) ;
2010-08-01 19:50:41 +00:00
for ( unsigned i = 0 ; i < Sidedefs . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-08-01 19:50:41 +00:00
vertex_t * vt ;
vt = Sidedefs [ i ] - > linedef - > v1 ;
Bounds . AddToBox ( vt - > x , vt - > y ) ;
vt = Sidedefs [ i ] - > linedef - > v2 ;
2010-07-23 05:56:25 +00:00
Bounds . AddToBox ( vt - > x , vt - > y ) ;
2006-02-24 04:48:15 +00:00
}
2012-03-28 03:49:38 +00:00
bbox [ BOXRIGHT ] = GetSafeBlockX ( Bounds . Right ( ) - bmaporgx ) ;
bbox [ BOXLEFT ] = GetSafeBlockX ( Bounds . Left ( ) - bmaporgx ) ;
bbox [ BOXTOP ] = GetSafeBlockY ( Bounds . Top ( ) - bmaporgy ) ;
bbox [ BOXBOTTOM ] = GetSafeBlockY ( Bounds . Bottom ( ) - bmaporgy ) ;
2010-07-23 05:56:25 +00:00
// add the polyobj to each blockmap section
for ( int j = bbox [ BOXBOTTOM ] * bmapwidth ; j < = bbox [ BOXTOP ] * bmapwidth ;
j + = bmapwidth )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
for ( int i = bbox [ BOXLEFT ] ; i < = bbox [ BOXRIGHT ] ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
if ( i > = 0 & & i < bmapwidth & & j > = 0 & & j < bmapheight * bmapwidth )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
link = & PolyBlockMap [ j + i ] ;
if ( ! ( * link ) )
{ // Create a new link at the current block cell
* link = new polyblock_t ;
( * link ) - > next = NULL ;
( * link ) - > prev = NULL ;
( * link ) - > polyobj = this ;
continue ;
}
else
{
tempLink = * link ;
while ( tempLink - > next ! = NULL & & tempLink - > polyobj ! = NULL )
{
tempLink = tempLink - > next ;
}
}
if ( tempLink - > polyobj = = NULL )
{
tempLink - > polyobj = this ;
continue ;
}
else
{
tempLink - > next = new polyblock_t ;
tempLink - > next - > next = NULL ;
tempLink - > next - > prev = tempLink ;
tempLink - > next - > polyobj = this ;
}
}
// else, don't link the polyobj, since it's off the map
}
}
}
2013-03-21 02:07:42 +00:00
//===========================================================================
//
// FPolyObj :: RecalcActorFloorCeil
//
// For each actor within the bounding box, recalculate its floorz, ceilingz,
// and related values.
//
//===========================================================================
void FPolyObj : : RecalcActorFloorCeil ( FBoundingBox bounds ) const
{
FBlockThingsIterator it ( bounds ) ;
AActor * actor ;
while ( ( actor = it . Next ( ) ) ! = NULL )
{
P_FindFloorCeiling ( actor ) ;
}
}
2010-07-23 05:56:25 +00:00
//===========================================================================
2006-02-24 04:48:15 +00:00
//
2010-07-23 05:56:25 +00:00
// PO_ClosestPoint
//
// Given a point (x,y), returns the point (ox,oy) on the polyobject's walls
// that is nearest to (x,y). Also returns the seg this point came from.
//
//===========================================================================
void FPolyObj : : ClosestPoint ( fixed_t fx , fixed_t fy , fixed_t & ox , fixed_t & oy , side_t * * side ) const
{
unsigned int i ;
double x = fx , y = fy ;
double bestdist = HUGE_VAL ;
double bestx = 0 , besty = 0 ;
side_t * bestline = NULL ;
for ( i = 0 ; i < Sidedefs . Size ( ) ; + + i )
{
vertex_t * v1 = Sidedefs [ i ] - > V1 ( ) ;
vertex_t * v2 = Sidedefs [ i ] - > V2 ( ) ;
double a = v2 - > x - v1 - > x ;
double b = v2 - > y - v1 - > y ;
double den = a * a + b * b ;
double ix , iy , dist ;
if ( den = = 0 )
{ // Line is actually a point!
ix = v1 - > x ;
iy = v1 - > y ;
}
else
{
double num = ( x - v1 - > x ) * a + ( y - v1 - > y ) * b ;
double u = num / den ;
if ( u < = 0 )
{
ix = v1 - > x ;
iy = v1 - > y ;
}
else if ( u > = 1 )
{
ix = v2 - > x ;
iy = v2 - > y ;
}
else
{
ix = v1 - > x + u * a ;
iy = v1 - > y + u * b ;
}
}
a = ( ix - x ) ;
b = ( iy - y ) ;
dist = a * a + b * b ;
if ( dist < bestdist )
{
bestdist = dist ;
bestx = ix ;
besty = iy ;
bestline = Sidedefs [ i ] ;
}
}
ox = fixed_t ( bestx ) ;
oy = fixed_t ( besty ) ;
if ( side ! = NULL )
{
* side = bestline ;
}
}
//==========================================================================
//
// InitBlockMap
2006-02-24 04:48:15 +00:00
//
//==========================================================================
2010-07-23 05:56:25 +00:00
static void InitBlockMap ( void )
{
int i ;
PolyBlockMap = new polyblock_t * [ bmapwidth * bmapheight ] ;
memset ( PolyBlockMap , 0 , bmapwidth * bmapheight * sizeof ( polyblock_t * ) ) ;
for ( i = 0 ; i < po_NumPolyobjs ; i + + )
{
polyobjs [ i ] . LinkPolyobj ( ) ;
}
}
//==========================================================================
//
// InitSideLists [RH]
//
// Group sides by vertex and collect side that are known to belong to a
// polyobject so that they can be initialized fast.
//==========================================================================
static void InitSideLists ( )
{
2010-07-25 21:38:34 +00:00
for ( int i = 0 ; i < numsides ; + + i )
2010-07-23 05:56:25 +00:00
{
2010-07-25 21:38:34 +00:00
if ( sides [ i ] . linedef ! = NULL & &
( sides [ i ] . linedef - > special = = Polyobj_StartLine | |
sides [ i ] . linedef - > special = = Polyobj_ExplicitLine ) )
2010-07-23 05:56:25 +00:00
{
2010-07-25 21:38:34 +00:00
KnownPolySides . Push ( i ) ;
2010-07-23 05:56:25 +00:00
}
}
}
//==========================================================================
//
// KillSideLists [RH]
//
//==========================================================================
static void KillSideLists ( )
{
KnownPolySides . Clear ( ) ;
KnownPolySides . ShrinkToFit ( ) ;
}
2010-08-01 05:16:09 +00:00
//==========================================================================
//
// AddPolyVert
//
// Helper function for IterFindPolySides()
//
//==========================================================================
static void AddPolyVert ( TArray < DWORD > & vnum , DWORD vert )
{
for ( unsigned int i = vnum . Size ( ) - 1 ; i - - ! = 0 ; )
{
if ( vnum [ i ] = = vert )
{ // Already in the set. No need to add it.
return ;
}
}
vnum . Push ( vert ) ;
}
2010-07-23 05:56:25 +00:00
//==========================================================================
//
// IterFindPolySides
//
2010-08-01 05:16:09 +00:00
// Beginning with the first vertex of the starting side, for each vertex
// in vnum, add all the sides that use it as a first vertex to the polyobj,
// and add all their second vertices to vnum. This continues until there
// are no new vertices in vnum.
//
2010-07-23 05:56:25 +00:00
//==========================================================================
static void IterFindPolySides ( FPolyObj * po , side_t * side )
2006-02-24 04:48:15 +00:00
{
2010-08-01 05:16:09 +00:00
static TArray < DWORD > vnum ;
unsigned int vnumat ;
2010-07-23 05:56:25 +00:00
2010-08-01 05:16:09 +00:00
assert ( sidetemp ! = NULL ) ;
2006-02-24 04:48:15 +00:00
2010-08-01 05:16:09 +00:00
vnum . Clear ( ) ;
vnum . Push ( DWORD ( side - > V1 ( ) - vertexes ) ) ;
vnumat = 0 ;
2006-02-24 04:48:15 +00:00
2010-08-01 05:16:09 +00:00
while ( vnum . Size ( ) ! = vnumat )
{
DWORD sidenum = sidetemp [ vnum [ vnumat + + ] ] . b . first ;
while ( sidenum ! = NO_SIDE )
2006-02-24 04:48:15 +00:00
{
2010-08-01 05:16:09 +00:00
po - > Sidedefs . Push ( & sides [ sidenum ] ) ;
AddPolyVert ( vnum , DWORD ( sides [ sidenum ] . V2 ( ) - vertexes ) ) ;
sidenum = sidetemp [ sidenum ] . b . next ;
2006-02-24 04:48:15 +00:00
}
}
}
//==========================================================================
//
// SpawnPolyobj
//
//==========================================================================
2016-01-09 00:23:00 +00:00
static int STACK_ARGS posicmp ( const void * a , const void * b )
{
return ( * ( const side_t * * ) a ) - > linedef - > args [ 1 ] - ( * ( const side_t * * ) b ) - > linedef - > args [ 1 ] ;
}
2006-02-24 04:48:15 +00:00
static void SpawnPolyobj ( int index , int tag , int type )
{
unsigned int ii ;
int i ;
2010-07-23 05:56:25 +00:00
FPolyObj * po = & polyobjs [ index ] ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
for ( ii = 0 ; ii < KnownPolySides . Size ( ) ; + + ii )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
i = KnownPolySides [ ii ] ;
2006-02-24 04:48:15 +00:00
if ( i < 0 )
{
continue ;
}
2010-07-23 05:56:25 +00:00
side_t * sd = & sides [ i ] ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
if ( sd - > linedef - > special = = Polyobj_StartLine & &
sd - > linedef - > args [ 0 ] = = tag )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
if ( po - > Sidedefs . Size ( ) > 0 )
2006-02-24 04:48:15 +00:00
{
I_Error ( " SpawnPolyobj: Polyobj %d already spawned. \n " , tag ) ;
}
2010-07-23 05:56:25 +00:00
sd - > linedef - > special = 0 ;
sd - > linedef - > args [ 0 ] = 0 ;
IterFindPolySides ( & polyobjs [ index ] , sd ) ;
2013-06-23 03:35:03 +00:00
po - > MirrorNum = sd - > linedef - > args [ 1 ] ;
2015-04-04 08:25:01 +00:00
po - > crush = ( type ! = SMT_PolySpawn ) ? 3 : 0 ;
po - > bHurtOnTouch = ( type = = SMT_PolySpawnHurt ) ;
2010-07-23 05:56:25 +00:00
po - > tag = tag ;
po - > seqType = sd - > linedef - > args [ 2 ] ;
if ( po - > seqType < 0 | | po - > seqType > 63 )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
po - > seqType = 0 ;
2006-02-24 04:48:15 +00:00
}
break ;
}
}
2010-07-23 05:56:25 +00:00
if ( po - > Sidedefs . Size ( ) = = 0 )
{
// didn't find a polyobj through PO_LINE_START
TArray < side_t * > polySideList ;
2006-08-24 19:19:15 +00:00
unsigned int psIndexOld ;
2016-01-09 00:23:00 +00:00
psIndexOld = po - > Sidedefs . Size ( ) ;
for ( ii = 0 ; ii < KnownPolySides . Size ( ) ; + + ii )
2006-02-24 04:48:15 +00:00
{
2016-01-09 00:23:00 +00:00
i = KnownPolySides [ ii ] ;
2006-02-24 04:48:15 +00:00
2016-01-09 00:23:00 +00:00
if ( i > = 0 & &
sides [ i ] . linedef - > special = = Polyobj_ExplicitLine & &
sides [ i ] . linedef - > args [ 0 ] = = tag )
2006-02-24 04:48:15 +00:00
{
2016-01-09 00:23:00 +00:00
if ( ! sides [ i ] . linedef - > args [ 1 ] )
2006-02-24 04:48:15 +00:00
{
2016-01-09 00:23:00 +00:00
I_Error ( " SpawnPolyobj: Explicit line missing order number in poly %d, linedef %d. \n " , tag , int ( sides [ i ] . linedef - lines ) ) ;
2006-02-24 04:48:15 +00:00
}
2016-01-09 00:23:00 +00:00
po - > Sidedefs . Push ( & sides [ i ] ) ;
2006-02-24 04:48:15 +00:00
}
}
2016-01-09 00:23:00 +00:00
qsort ( & po - > Sidedefs [ 0 ] , po - > Sidedefs . Size ( ) , sizeof ( po - > Sidedefs [ 0 ] ) , posicmp ) ;
2010-07-23 05:56:25 +00:00
if ( po - > Sidedefs . Size ( ) > 0 )
2006-02-24 04:48:15 +00:00
{
2015-04-04 08:25:01 +00:00
po - > crush = ( type ! = SMT_PolySpawn ) ? 3 : 0 ;
po - > bHurtOnTouch = ( type = = SMT_PolySpawnHurt ) ;
2010-07-23 05:56:25 +00:00
po - > tag = tag ;
po - > seqType = po - > Sidedefs [ 0 ] - > linedef - > args [ 3 ] ;
2013-06-23 03:35:03 +00:00
po - > MirrorNum = po - > Sidedefs [ 0 ] - > linedef - > args [ 2 ] ;
2006-02-24 04:48:15 +00:00
}
else
I_Error ( " SpawnPolyobj: Poly %d does not exist \n " , tag ) ;
}
2008-06-03 14:38:42 +00:00
2010-07-23 05:56:25 +00:00
validcount + + ;
for ( unsigned int i = 0 ; i < po - > Sidedefs . Size ( ) ; i + + )
2008-06-03 14:38:42 +00:00
{
2010-07-23 05:56:25 +00:00
line_t * l = po - > Sidedefs [ i ] - > linedef ;
2008-06-03 14:38:42 +00:00
2010-07-23 05:56:25 +00:00
if ( l - > validcount ! = validcount )
2008-06-03 14:38:42 +00:00
{
2010-07-23 05:56:25 +00:00
l - > validcount = validcount ;
po - > Linedefs . Push ( l ) ;
2008-06-03 14:38:42 +00:00
2010-07-23 05:56:25 +00:00
vertex_t * v = l - > v1 ;
int j ;
for ( j = po - > Vertices . Size ( ) - 1 ; j > = 0 ; j - - )
{
if ( po - > Vertices [ j ] = = v ) break ;
}
if ( j < 0 ) po - > Vertices . Push ( v ) ;
2008-06-03 14:38:42 +00:00
2010-07-23 05:56:25 +00:00
v = l - > v2 ;
for ( j = po - > Vertices . Size ( ) - 1 ; j > = 0 ; j - - )
{
if ( po - > Vertices [ j ] = = v ) break ;
}
if ( j < 0 ) po - > Vertices . Push ( v ) ;
2008-06-03 14:38:42 +00:00
}
}
2010-07-23 05:56:25 +00:00
po - > Sidedefs . ShrinkToFit ( ) ;
po - > Linedefs . ShrinkToFit ( ) ;
po - > Vertices . ShrinkToFit ( ) ;
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// TranslateToStartSpot
//
//==========================================================================
static void TranslateToStartSpot ( int tag , int originX , int originY )
{
2008-06-01 20:43:02 +00:00
FPolyObj * po ;
2006-02-24 04:48:15 +00:00
int deltaX ;
int deltaY ;
po = NULL ;
2010-07-23 05:56:25 +00:00
for ( int i = 0 ; i < po_NumPolyobjs ; i + + )
2006-02-24 04:48:15 +00:00
{
if ( polyobjs [ i ] . tag = = tag )
{
po = & polyobjs [ i ] ;
break ;
}
}
if ( po = = NULL )
{ // didn't match the tag with a polyobj tag
2010-07-23 05:56:25 +00:00
I_Error ( " TranslateToStartSpot: Unable to match polyobj tag: %d \n " , tag ) ;
2006-02-24 04:48:15 +00:00
}
2010-07-23 05:56:25 +00:00
if ( po - > Sidedefs . Size ( ) = = 0 )
2006-02-24 04:48:15 +00:00
{
I_Error ( " TranslateToStartSpot: Anchor point located without a StartSpot point: %d \n " , tag ) ;
}
2010-07-23 05:56:25 +00:00
po - > OriginalPts . Resize ( po - > Sidedefs . Size ( ) ) ;
po - > PrevPts . Resize ( po - > Sidedefs . Size ( ) ) ;
deltaX = originX - po - > StartSpot . x ;
deltaY = originY - po - > StartSpot . y ;
2006-02-24 04:48:15 +00:00
2010-07-23 05:56:25 +00:00
for ( unsigned i = 0 ; i < po - > Sidedefs . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
po - > Sidedefs [ i ] - > Flags | = WALLF_POLYOBJ ;
2006-02-24 04:48:15 +00:00
}
2010-07-23 05:56:25 +00:00
for ( unsigned i = 0 ; i < po - > Linedefs . Size ( ) ; i + + )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
po - > Linedefs [ i ] - > bbox [ BOXTOP ] - = deltaY ;
po - > Linedefs [ i ] - > bbox [ BOXBOTTOM ] - = deltaY ;
po - > Linedefs [ i ] - > bbox [ BOXLEFT ] - = deltaX ;
po - > Linedefs [ i ] - > bbox [ BOXRIGHT ] - = deltaX ;
2006-02-24 04:48:15 +00:00
}
2010-07-23 05:56:25 +00:00
for ( unsigned i = 0 ; i < po - > Vertices . Size ( ) ; i + + )
{
po - > Vertices [ i ] - > x - = deltaX ;
po - > Vertices [ i ] - > y - = deltaY ;
po - > OriginalPts [ i ] . x = po - > Vertices [ i ] - > x - po - > StartSpot . x ;
po - > OriginalPts [ i ] . y = po - > Vertices [ i ] - > y - po - > StartSpot . y ;
}
po - > CalcCenter ( ) ;
2010-08-15 10:02:10 +00:00
// For compatibility purposes
po - > CenterSubsector = R_PointInSubsector ( po - > CenterSpot . x , po - > CenterSpot . y ) ;
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// PO_Init
//
//==========================================================================
void PO_Init ( void )
{
// [RH] Hexen found the polyobject-related things by reloading the map's
// THINGS lump here and scanning through it. I have P_SpawnMapThing()
// record those things instead, so that in here we simply need to
// look at the polyspawns list.
polyspawns_t * polyspawn , * * prev ;
int polyIndex ;
// [RH] Make this faster
2010-07-23 05:56:25 +00:00
InitSideLists ( ) ;
2006-02-24 04:48:15 +00:00
2008-06-01 20:43:02 +00:00
polyobjs = new FPolyObj [ po_NumPolyobjs ] ;
2006-02-24 04:48:15 +00:00
polyIndex = 0 ; // index polyobj number
// Find the startSpot points, and spawn each polyobj
for ( polyspawn = polyspawns , prev = & polyspawns ; polyspawn ; )
{
// 9301 (3001) = no crush, 9302 (3002) = crushing, 9303 = hurting touch
2015-04-04 08:25:01 +00:00
if ( polyspawn - > type > = SMT_PolySpawn & & polyspawn - > type < = SMT_PolySpawnHurt )
2010-07-23 05:56:25 +00:00
{
// Polyobj StartSpot Pt.
polyobjs [ polyIndex ] . StartSpot . x = polyspawn - > x ;
polyobjs [ polyIndex ] . StartSpot . y = polyspawn - > y ;
2006-02-24 04:48:15 +00:00
SpawnPolyobj ( polyIndex , polyspawn - > angle , polyspawn - > type ) ;
polyIndex + + ;
* prev = polyspawn - > next ;
delete polyspawn ;
polyspawn = * prev ;
2010-07-23 05:56:25 +00:00
}
else
{
2006-02-24 04:48:15 +00:00
prev = & polyspawn - > next ;
polyspawn = polyspawn - > next ;
}
}
for ( polyspawn = polyspawns ; polyspawn ; )
{
polyspawns_t * next = polyspawn - > next ;
2015-04-04 08:25:01 +00:00
if ( polyspawn - > type = = SMT_PolyAnchor )
2010-07-23 05:56:25 +00:00
{
// Polyobj Anchor Pt.
2006-02-24 04:48:15 +00:00
TranslateToStartSpot ( polyspawn - > angle , polyspawn - > x , polyspawn - > y ) ;
}
delete polyspawn ;
polyspawn = next ;
}
polyspawns = NULL ;
// check for a startspot without an anchor point
for ( polyIndex = 0 ; polyIndex < po_NumPolyobjs ; polyIndex + + )
{
2010-07-23 05:56:25 +00:00
if ( polyobjs [ polyIndex ] . OriginalPts . Size ( ) = = 0 )
2006-02-24 04:48:15 +00:00
{
I_Error ( " PO_Init: StartSpot located without an Anchor point: %d \n " ,
polyobjs [ polyIndex ] . tag ) ;
}
}
InitBlockMap ( ) ;
// [RH] Don't need the seg lists anymore
2010-07-23 05:56:25 +00:00
KillSideLists ( ) ;
for ( int i = 0 ; i < numnodes ; i + + )
{
node_t * no = & nodes [ i ] ;
double fdx = ( double ) no - > dx ;
double fdy = ( double ) no - > dy ;
no - > len = ( float ) sqrt ( fdx * fdx + fdy * fdy ) ;
}
2010-08-28 16:51:41 +00:00
// mark all subsectors which have a seg belonging to a polyobj
// These ones should not be rendered on the textured automap.
for ( int i = 0 ; i < numsubsectors ; i + + )
{
subsector_t * ss = & subsectors [ i ] ;
for ( DWORD j = 0 ; j < ss - > numlines ; j + + )
{
if ( ss - > firstline [ j ] . sidedef ! = NULL & &
ss - > firstline [ j ] . sidedef - > Flags & WALLF_POLYOBJ )
{
ss - > flags | = SSECF_POLYORG ;
break ;
}
}
}
2006-02-24 04:48:15 +00:00
}
//==========================================================================
//
// PO_Busy
//
//==========================================================================
2006-09-14 00:02:31 +00:00
bool PO_Busy ( int polyobj )
2006-02-24 04:48:15 +00:00
{
2008-06-01 20:43:02 +00:00
FPolyObj * poly ;
2006-02-24 04:48:15 +00:00
2009-10-27 02:43:00 +00:00
poly = PO_GetPolyobj ( polyobj ) ;
2010-07-23 05:56:25 +00:00
return ( poly ! = NULL & & poly - > specialdata ! = NULL ) ;
}
//==========================================================================
//
//
//
//==========================================================================
void FPolyObj : : ClearSubsectorLinks ( )
{
while ( subsectorlinks ! = NULL )
2006-02-24 04:48:15 +00:00
{
2010-07-23 05:56:25 +00:00
assert ( subsectorlinks - > state = = 1337 ) ;
FPolyNode * next = subsectorlinks - > snext ;
if ( subsectorlinks - > pnext ! = NULL )
{
assert ( subsectorlinks - > pnext - > state = = 1337 ) ;
subsectorlinks - > pnext - > pprev = subsectorlinks - > pprev ;
}
if ( subsectorlinks - > pprev ! = NULL )
{
assert ( subsectorlinks - > pprev - > state = = 1337 ) ;
subsectorlinks - > pprev - > pnext = subsectorlinks - > pnext ;
}
else
{
subsectorlinks - > subsector - > polys = subsectorlinks - > pnext ;
}
2010-08-01 02:41:56 +00:00
if ( subsectorlinks - > subsector - > BSP ! = NULL )
{
subsectorlinks - > subsector - > BSP - > bDirty = true ;
}
2010-07-23 05:56:25 +00:00
subsectorlinks - > state = - 1 ;
delete subsectorlinks ;
subsectorlinks = next ;
2006-02-24 04:48:15 +00:00
}
2010-07-23 05:56:25 +00:00
subsectorlinks = NULL ;
2006-02-24 04:48:15 +00:00
}
2008-06-03 14:38:42 +00:00
2010-07-23 05:56:25 +00:00
void FPolyObj : : ClearAllSubsectorLinks ( )
{
2010-08-01 02:41:56 +00:00
for ( int i = 0 ; i < po_NumPolyobjs ; i + + )
2010-07-23 05:56:25 +00:00
{
polyobjs [ i ] . ClearSubsectorLinks ( ) ;
}
2010-08-01 02:41:56 +00:00
ReleaseAllPolyNodes ( ) ;
2010-07-23 05:56:25 +00:00
}
//==========================================================================
2008-07-02 03:50:17 +00:00
//
2010-07-23 05:56:25 +00:00
// GetIntersection
2008-07-02 03:50:17 +00:00
//
2010-07-23 05:56:25 +00:00
// adapted from P_InterceptVector
2008-07-02 03:50:17 +00:00
//
2010-07-23 05:56:25 +00:00
//==========================================================================
2008-07-02 03:50:17 +00:00
2010-08-01 02:41:56 +00:00
static bool GetIntersection ( FPolySeg * seg , node_t * bsp , FPolyVertex * v )
2008-07-02 03:50:17 +00:00
{
2010-07-23 05:56:25 +00:00
double frac ;
double num ;
double den ;
2010-08-01 02:41:56 +00:00
double v2x = ( double ) seg - > v1 . x ;
double v2y = ( double ) seg - > v1 . y ;
double v2dx = ( double ) ( seg - > v2 . x - seg - > v1 . x ) ;
double v2dy = ( double ) ( seg - > v2 . y - seg - > v1 . y ) ;
2010-07-23 05:56:25 +00:00
double v1x = ( double ) bsp - > x ;
double v1y = ( double ) bsp - > y ;
double v1dx = ( double ) bsp - > dx ;
double v1dy = ( double ) bsp - > dy ;
den = v1dy * v2dx - v1dx * v2dy ;
if ( den = = 0 )
return false ; // parallel
num = ( v1x - v2x ) * v1dy + ( v2y - v1y ) * v1dx ;
frac = num / den ;
if ( frac < 0. | | frac > 1. ) return false ;
v - > x = xs_RoundToInt ( v2x + frac * v2dx ) ;
v - > y = xs_RoundToInt ( v2y + frac * v2dy ) ;
return true ;
}
2008-07-02 03:50:17 +00:00
2010-07-23 05:56:25 +00:00
//==========================================================================
//
// PartitionDistance
//
// Determine the distance of a vertex to a node's partition line.
//
//==========================================================================
2010-08-01 02:41:56 +00:00
static double PartitionDistance ( FPolyVertex * vt , node_t * node )
2010-07-23 05:56:25 +00:00
{
return fabs ( double ( - node - > dy ) * ( vt - > x - node - > x ) + double ( node - > dx ) * ( vt - > y - node - > y ) ) / node - > len ;
}
//==========================================================================
//
// AddToBBox
//
//==========================================================================
static void AddToBBox ( fixed_t child [ 4 ] , fixed_t parent [ 4 ] )
{
if ( child [ BOXTOP ] > parent [ BOXTOP ] )
2008-07-02 03:50:17 +00:00
{
2010-07-23 05:56:25 +00:00
parent [ BOXTOP ] = child [ BOXTOP ] ;
}
if ( child [ BOXBOTTOM ] < parent [ BOXBOTTOM ] )
{
parent [ BOXBOTTOM ] = child [ BOXBOTTOM ] ;
}
if ( child [ BOXLEFT ] < parent [ BOXLEFT ] )
{
parent [ BOXLEFT ] = child [ BOXLEFT ] ;
}
if ( child [ BOXRIGHT ] > parent [ BOXRIGHT ] )
{
parent [ BOXRIGHT ] = child [ BOXRIGHT ] ;
}
}
2008-07-02 03:50:17 +00:00
2010-07-23 05:56:25 +00:00
//==========================================================================
//
// AddToBBox
//
//==========================================================================
2010-08-01 02:41:56 +00:00
static void AddToBBox ( FPolyVertex * v , fixed_t bbox [ 4 ] )
2010-07-23 05:56:25 +00:00
{
if ( v - > x < bbox [ BOXLEFT ] )
{
bbox [ BOXLEFT ] = v - > x ;
}
if ( v - > x > bbox [ BOXRIGHT ] )
{
bbox [ BOXRIGHT ] = v - > x ;
}
if ( v - > y < bbox [ BOXBOTTOM ] )
{
bbox [ BOXBOTTOM ] = v - > y ;
}
if ( v - > y > bbox [ BOXTOP ] )
{
bbox [ BOXTOP ] = v - > y ;
}
}
//==========================================================================
//
// SplitPoly
//
//==========================================================================
static void SplitPoly ( FPolyNode * pnode , void * node , fixed_t bbox [ 4 ] )
{
2010-08-01 02:41:56 +00:00
static TArray < FPolySeg > lists [ 2 ] ;
2010-07-23 05:56:25 +00:00
static const double POLY_EPSILON = 0.3125 ;
if ( ! ( ( size_t ) node & 1 ) ) // Keep going until found a subsector
{
node_t * bsp = ( node_t * ) node ;
int centerside = R_PointOnSide ( pnode - > poly - > CenterSpot . x , pnode - > poly - > CenterSpot . y , bsp ) ;
lists [ 0 ] . Clear ( ) ;
lists [ 1 ] . Clear ( ) ;
for ( unsigned i = 0 ; i < pnode - > segs . Size ( ) ; i + + )
2008-07-02 03:50:17 +00:00
{
2010-08-01 02:41:56 +00:00
FPolySeg * seg = & pnode - > segs [ i ] ;
2010-07-23 05:56:25 +00:00
// Parts of the following code were taken from Eternity and are
// being used with permission.
// get distance of vertices from partition line
// If the distance is too small, we may decide to
// change our idea of sidedness.
2010-08-01 02:41:56 +00:00
double dist_v1 = PartitionDistance ( & seg - > v1 , bsp ) ;
double dist_v2 = PartitionDistance ( & seg - > v2 , bsp ) ;
2010-07-23 05:56:25 +00:00
// If the distances are less than epsilon, consider the points as being
// on the same side as the polyobj origin. Why? People like to build
// polyobject doors flush with their door tracks. This breaks using the
// usual assumptions.
// Addition to Eternity code: We must also check any seg with only one
// vertex inside the epsilon threshold. If not, these lines will get split but
// adjoining ones with both vertices inside the threshold won't thus messing up
// the order in which they get drawn.
if ( dist_v1 < = POLY_EPSILON )
2008-07-02 03:50:17 +00:00
{
2010-07-23 05:56:25 +00:00
if ( dist_v2 < = POLY_EPSILON )
{
lists [ centerside ] . Push ( * seg ) ;
}
else
{
2010-08-01 02:41:56 +00:00
int side = R_PointOnSide ( seg - > v2 . x , seg - > v2 . y , bsp ) ;
2010-07-23 05:56:25 +00:00
lists [ side ] . Push ( * seg ) ;
}
2008-07-02 03:50:17 +00:00
}
2010-07-23 05:56:25 +00:00
else if ( dist_v2 < = POLY_EPSILON )
2008-07-02 03:50:17 +00:00
{
2010-08-01 02:41:56 +00:00
int side = R_PointOnSide ( seg - > v1 . x , seg - > v1 . y , bsp ) ;
2010-07-23 05:56:25 +00:00
lists [ side ] . Push ( * seg ) ;
2008-07-02 03:50:17 +00:00
}
2010-07-23 05:56:25 +00:00
else
2008-07-02 03:50:17 +00:00
{
2010-08-01 02:41:56 +00:00
int side1 = R_PointOnSide ( seg - > v1 . x , seg - > v1 . y , bsp ) ;
int side2 = R_PointOnSide ( seg - > v2 . x , seg - > v2 . y , bsp ) ;
2010-07-23 05:56:25 +00:00
if ( side1 ! = side2 )
{
// if the partition line crosses this seg, we must split it.
2010-08-01 02:41:56 +00:00
FPolyVertex vert ;
2010-07-23 05:56:25 +00:00
2010-08-01 02:41:56 +00:00
if ( GetIntersection ( seg , bsp , & vert ) )
2010-07-23 05:56:25 +00:00
{
lists [ 0 ] . Push ( * seg ) ;
lists [ 1 ] . Push ( * seg ) ;
lists [ side1 ] . Last ( ) . v2 = vert ;
lists [ side2 ] . Last ( ) . v1 = vert ;
}
else
{
// should never happen
lists [ side1 ] . Push ( * seg ) ;
}
}
else
{
// both points on the same side.
lists [ side1 ] . Push ( * seg ) ;
}
2008-07-02 03:50:17 +00:00
}
}
2010-07-23 05:56:25 +00:00
if ( lists [ 1 ] . Size ( ) = = 0 )
2008-07-02 03:50:17 +00:00
{
2010-07-23 05:56:25 +00:00
SplitPoly ( pnode , bsp - > children [ 0 ] , bsp - > bbox [ 0 ] ) ;
AddToBBox ( bsp - > bbox [ 0 ] , bbox ) ;
}
else if ( lists [ 0 ] . Size ( ) = = 0 )
{
SplitPoly ( pnode , bsp - > children [ 1 ] , bsp - > bbox [ 1 ] ) ;
AddToBBox ( bsp - > bbox [ 1 ] , bbox ) ;
}
else
{
// create the new node
2010-08-01 02:41:56 +00:00
FPolyNode * newnode = NewPolyNode ( ) ;
2010-07-23 05:56:25 +00:00
newnode - > poly = pnode - > poly ;
newnode - > segs = lists [ 1 ] ;
// set segs for original node
pnode - > segs = lists [ 0 ] ;
// recurse back side
SplitPoly ( newnode , bsp - > children [ 1 ] , bsp - > bbox [ 1 ] ) ;
// recurse front side
SplitPoly ( pnode , bsp - > children [ 0 ] , bsp - > bbox [ 0 ] ) ;
AddToBBox ( bsp - > bbox [ 0 ] , bbox ) ;
AddToBBox ( bsp - > bbox [ 1 ] , bbox ) ;
2008-07-02 03:50:17 +00:00
}
}
2010-07-23 05:56:25 +00:00
else
2008-07-02 03:50:17 +00:00
{
2010-07-23 05:56:25 +00:00
// we reached a subsector so we can link the node with this subsector
subsector_t * sub = ( subsector_t * ) ( ( BYTE * ) node - 1 ) ;
// Link node to subsector
pnode - > pnext = sub - > polys ;
if ( pnode - > pnext ! = NULL )
{
assert ( pnode - > pnext - > state = = 1337 ) ;
pnode - > pnext - > pprev = pnode ;
}
pnode - > pprev = NULL ;
sub - > polys = pnode ;
// link node to polyobject
pnode - > snext = pnode - > poly - > subsectorlinks ;
pnode - > poly - > subsectorlinks = pnode ;
pnode - > subsector = sub ;
// calculate bounding box for this polynode
assert ( pnode - > segs . Size ( ) ! = 0 ) ;
fixed_t subbbox [ 4 ] = { FIXED_MIN , FIXED_MAX , FIXED_MAX , FIXED_MIN } ;
for ( unsigned i = 0 ; i < pnode - > segs . Size ( ) ; + + i )
{
2010-08-01 02:41:56 +00:00
AddToBBox ( & pnode - > segs [ i ] . v1 , subbbox ) ;
AddToBBox ( & pnode - > segs [ i ] . v2 , subbbox ) ;
2010-07-23 05:56:25 +00:00
}
// Potentially expand the parent node's bounding box to contain these bits of polyobject.
AddToBBox ( subbbox , bbox ) ;
2008-07-02 03:50:17 +00:00
}
}
2008-06-03 14:38:42 +00:00
2010-07-23 05:56:25 +00:00
//==========================================================================
//
//
//
//==========================================================================
void FPolyObj : : CreateSubsectorLinks ( )
{
2010-08-01 02:41:56 +00:00
FPolyNode * node = NewPolyNode ( ) ;
// Even though we don't care about it, we need to initialize this
// bounding box to something so that Valgrind won't complain about it
// when SplitPoly modifies it.
fixed_t dummybbox [ 4 ] = { 0 } ;
2010-07-23 05:56:25 +00:00
node - > poly = this ;
node - > segs . Resize ( Sidedefs . Size ( ) ) ;
for ( unsigned i = 0 ; i < Sidedefs . Size ( ) ; i + + )
{
2010-08-01 02:41:56 +00:00
FPolySeg * seg = & node - > segs [ i ] ;
2010-07-23 05:56:25 +00:00
side_t * side = Sidedefs [ i ] ;
seg - > v1 = side - > V1 ( ) ;
seg - > v2 = side - > V2 ( ) ;
2010-08-01 02:41:56 +00:00
seg - > wall = side ;
2010-07-23 05:56:25 +00:00
}
2010-08-15 10:02:10 +00:00
if ( ! ( i_compatflags & COMPATF_POLYOBJ ) )
{
SplitPoly ( node , nodes + numnodes - 1 , dummybbox ) ;
}
else
{
subsector_t * sub = CenterSubsector ;
// Link node to subsector
node - > pnext = sub - > polys ;
if ( node - > pnext ! = NULL )
{
assert ( node - > pnext - > state = = 1337 ) ;
node - > pnext - > pprev = node ;
}
node - > pprev = NULL ;
sub - > polys = node ;
// link node to polyobject
node - > snext = node - > poly - > subsectorlinks ;
node - > poly - > subsectorlinks = node ;
node - > subsector = sub ;
}
2010-07-23 05:56:25 +00:00
}
//==========================================================================
//
//
//
//==========================================================================
void PO_LinkToSubsectors ( )
2008-06-03 14:38:42 +00:00
{
2010-07-23 05:56:25 +00:00
for ( int i = 0 ; i < po_NumPolyobjs ; i + + )
2008-06-03 14:38:42 +00:00
{
2010-07-23 05:56:25 +00:00
if ( polyobjs [ i ] . subsectorlinks = = NULL )
{
polyobjs [ i ] . CreateSubsectorLinks ( ) ;
}
2008-06-03 14:38:42 +00:00
}
2010-08-01 02:41:56 +00:00
}
//==========================================================================
//
// NewPolyNode
//
//==========================================================================
static FPolyNode * NewPolyNode ( )
{
FPolyNode * node ;
if ( FreePolyNodes ! = NULL )
{
node = FreePolyNodes ;
FreePolyNodes = node - > pnext ;
}
else
{
node = new FPolyNode ;
}
node - > state = 1337 ;
node - > poly = NULL ;
node - > pnext = NULL ;
node - > pprev = NULL ;
node - > subsector = NULL ;
node - > snext = NULL ;
return node ;
}
//==========================================================================
//
// FreePolyNode
//
//==========================================================================
void FreePolyNode ( FPolyNode * node )
{
node - > segs . Clear ( ) ;
node - > pnext = FreePolyNodes ;
FreePolyNodes = node ;
}
//==========================================================================
//
// ReleaseAllPolyNodes
//
//==========================================================================
void ReleaseAllPolyNodes ( )
{
FPolyNode * node , * next ;
for ( node = FreePolyNodes ; node ! = NULL ; node = next )
{
next = node - > pnext ;
delete node ;
}
}
2012-03-02 02:23:37 +00:00
//==========================================================================
//
// FPolyMirrorIterator Constructor
//
// This class is used to avoid infinitely looping on cyclical chains of
// mirrored polyobjects.
//
//==========================================================================
FPolyMirrorIterator : : FPolyMirrorIterator ( FPolyObj * poly )
{
CurPoly = poly ;
if ( poly ! = NULL )
{
UsedPolys [ 0 ] = poly - > tag ;
NumUsedPolys = 1 ;
}
else
{
NumUsedPolys = 0 ;
}
}
//==========================================================================
//
// FPolyMirrorIterator :: NextMirror
//
// Returns the polyobject that mirrors the current one, or NULL if there
// is no mirroring polyobject, or there is a mirroring polyobject but it was
// already returned.
//
//==========================================================================
FPolyObj * FPolyMirrorIterator : : NextMirror ( )
{
FPolyObj * poly = CurPoly , * nextpoly ;
if ( poly = = NULL )
{
return NULL ;
}
// Do the work to decide which polyobject to return the next time this
// function is called.
int mirror = poly - > GetMirror ( ) , i ;
nextpoly = NULL ;
// Is there a mirror and we have room to remember it?
if ( mirror ! = 0 & & NumUsedPolys ! = countof ( UsedPolys ) )
{
// Has this polyobject been returned already?
for ( i = 0 ; i < NumUsedPolys ; + + i )
{
if ( UsedPolys [ i ] = = mirror )
{
break ; // Yes, it has been returned.
}
}
if ( i = = NumUsedPolys )
{ // No, it has not been returned.
UsedPolys [ NumUsedPolys + + ] = mirror ;
nextpoly = PO_GetPolyobj ( mirror ) ;
if ( nextpoly = = NULL )
{
Printf ( " Invalid mirror polyobj num %d for polyobj num %d \n " , mirror , UsedPolys [ i - 1 ] ) ;
}
}
}
CurPoly = nextpoly ;
return poly ;
}