Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
10 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef PORTAL_BASE2D_H
  8. #define PORTAL_BASE2D_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "baseanimating.h"
  13. #include "PortalSimulation.h"
  14. #include "pvs_extender.h"
  15. #include "portal_base2d_shared.h"
  16. // FIX ME
  17. #include "portal_shareddefs.h"
  18. class CPhysicsCloneArea;
  19. class CPortal_Base2D : public CBaseAnimating, public CPortalSimulatorEventCallbacks, public CPVS_Extender, public CPortal_Base2D_Shared
  20. {
  21. public:
  22. DECLARE_CLASS( CPortal_Base2D, CBaseAnimating );
  23. DECLARE_SERVERCLASS();
  24. DECLARE_DATADESC();
  25. CPortal_Base2D( void );
  26. virtual ~CPortal_Base2D( void );
  27. CNetworkHandle( CPortal_Base2D, m_hLinkedPortal ); //the portal this portal is linked to
  28. VMatrix m_matrixThisToLinked; //the matrix that will transform a point relative to this portal, to a point relative to the linked portal
  29. CNetworkVar( bool, m_bIsPortal2 ); //For teleportation, this doesn't matter, but for drawing and moving, it matters
  30. Vector m_vPrevForward; //used for the indecisive push in find closest passable spaces when portal is moved
  31. bool m_bSharedEnvironmentConfiguration; //this will be set by an instance of CPortal_Environment when two environments are in close proximity
  32. EHANDLE m_hMicrophone; //the microphone for teleporting sound
  33. EHANDLE m_hSpeaker; //the speaker for teleported sound
  34. bool m_bMicAndSpeakersLinkedToRemote;
  35. Vector m_vAudioOrigin;
  36. Vector m_vDelayedPosition;
  37. QAngle m_qDelayedAngles;
  38. int m_iDelayedFailure;
  39. Vector m_vOldPosition;
  40. QAngle m_qOldAngles;
  41. EHANDLE m_hPlacedBy;
  42. int m_nPortalColor;
  43. COutputEvent m_OnPlacedSuccessfully; // Output in hammer for when this portal was successfully placed (not attempted and fizzed).
  44. COutputEvent m_OnEntityTeleportFromMe;
  45. COutputEvent m_OnPlayerTeleportFromMe;
  46. COutputEvent m_OnEntityTeleportToMe;
  47. COutputEvent m_OnPlayerTeleportToMe;
  48. CNetworkVector( m_ptOrigin );
  49. Vector m_vForward, m_vUp, m_vRight;
  50. CNetworkQAngle( m_qAbsAngle );
  51. cplane_t m_plane_Origin; //a portal plane on the entity origin
  52. CPhysicsCloneArea *m_pAttachedCloningArea;
  53. bool IsPortal2() const;
  54. void SetIsPortal2( bool bIsPortal2 );
  55. const VMatrix& MatrixThisToLinked() const;
  56. virtual int UpdateTransmitState( void ) // set transmit filter to transmit always
  57. {
  58. return SetTransmitState( FL_EDICT_ALWAYS );
  59. }
  60. virtual void Spawn( void );
  61. virtual void Activate( void );
  62. virtual void OnRestore( void );
  63. virtual bool IsActive( void ) const { return m_bActivated; }
  64. virtual bool GetOldActiveState( void ) const { return m_bOldActivatedState; }
  65. virtual void SetActive( bool bActive );
  66. virtual void UpdateOnRemove( void );
  67. void TestRestingSurfaceThink( void );
  68. static const char * s_szTestRestingSurfaceThinkContext;
  69. void DeactivatePortalOnThink( void );
  70. void DeactivatePortalNow( void );
  71. static const char * s_szDeactivatePortalNowContext;
  72. virtual void OnPortalDeactivated( void );
  73. bool IsActivedAndLinked( void ) const;
  74. bool IsFloorPortal( float fThreshold = 0.8f ) const;
  75. bool IsCeilingPortal( float fThreshold = -0.8f ) const;
  76. void WakeNearbyEntities( void ); //wakes all nearby entities in-case there's been a significant change in how they can rest near a portal
  77. void ForceEntityToFitInPortalWall( CBaseEntity *pEntity ); //projects an object's center into the middle of the portal wall hall, and traces back to where it wants to be
  78. virtual void NewLocation( const Vector &vOrigin, const QAngle &qAngles );
  79. void PunchPenetratingPlayer( CBasePlayer *pPlayer ); // adds outward force to player intersecting the portal plane
  80. void PunchAllPenetratingPlayers( void ); // adds outward force to player intersecting the portal plane
  81. virtual void StartTouch( CBaseEntity *pOther );
  82. virtual void Touch( CBaseEntity *pOther );
  83. virtual void EndTouch( CBaseEntity *pOther );
  84. bool ShouldTeleportTouchingEntity( CBaseEntity *pOther ); //assuming the entity is or was just touching the portal, check for teleportation conditions
  85. void TeleportTouchingEntity( CBaseEntity *pOther );
  86. virtual void PreTeleportTouchingEntity( CBaseEntity *pOther ) {};
  87. virtual void PostTeleportTouchingEntity( CBaseEntity *pOther ) {};
  88. virtual void PhysicsSimulate( void );
  89. virtual void UpdatePortalLinkage( void );
  90. void UpdatePortalTeleportMatrix( void ); //computes the transformation from this portal to the linked portal, and will update the remote matrix as well
  91. //void SendInteractionMessage( CBaseEntity *pEntity, bool bEntering ); //informs clients that the entity is interacting with a portal (mostly used for clip planes)
  92. bool SharedEnvironmentCheck( CBaseEntity *pEntity ); //does all testing to verify that the object is better handled with this portal instead of the other
  93. // The four corners of the portal in worldspace, updated on placement. The four points will be coplanar on the portal plane.
  94. Vector m_vPortalCorners[4];
  95. CNetworkVarEmbedded( CPortalSimulator, m_PortalSimulator );
  96. //virtual bool CreateVPhysics( void );
  97. //virtual void VPhysicsDestroyObject( void );
  98. virtual bool TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  99. virtual void PortalSimulator_TookOwnershipOfEntity( CBaseEntity *pEntity );
  100. virtual void PortalSimulator_ReleasedOwnershipOfEntity( CBaseEntity *pEntity );
  101. virtual void CreateMicAndSpeaker( void );
  102. // Add or remove listeners
  103. void AddPortalEventListener( EHANDLE hListener );
  104. void RemovePortalEventListener( EHANDLE hListener );
  105. void OnEntityTeleportedToPortal( CBaseEntity *pEntity );
  106. void OnEntityTeleportedFromPortal( CBaseEntity *pEntity );
  107. protected:
  108. CNetworkVar( bool, m_bActivated ); //a portal can exist and not be active
  109. CNetworkVar( bool, m_bOldActivatedState ); //the old state
  110. void BroadcastPortalEvent( PortalEvent_t nEventType );
  111. CUtlVector<EHANDLE> m_PortalEventListeners; // Collection of entities (by handle) who wish to receive notification of portal events (fizzle, moved, etc)
  112. void RemovePortalMicAndSpeaker(); // Cleans up the portal's internal audio members
  113. void UpdateCorners( void ); // Updates the four corners of this portal on spawn and placement
  114. void UpdateClientCheckPVS( void ); // Tells clients to update the cached PVS in g_ClientCheck
  115. void UpdateCollisionShape( void );
  116. CNetworkVar( float, m_fNetworkHalfWidth );
  117. CNetworkVar( float, m_fNetworkHalfHeight );
  118. CNetworkVar( bool, m_bIsMobile ); //is this portal currently making small movements along with whatever brush it's attached to? Portal physics are disabled while nudging and resume when stabilized
  119. CPhysCollide *m_pCollisionShape;
  120. public:
  121. CPortal_Base2D *GetLinkedPortal( void ) { return m_hLinkedPortal; }
  122. inline float GetHalfWidth( void ) const { return m_fNetworkHalfWidth; }
  123. inline float GetHalfHeight( void ) const { return m_fNetworkHalfHeight; }
  124. inline Vector GetLocalMins( void ) const { return Vector( 0.0f, -m_fNetworkHalfWidth, -m_fNetworkHalfHeight ); }
  125. inline Vector GetLocalMaxs( void ) const { return Vector( 64.0f, m_fNetworkHalfWidth, m_fNetworkHalfHeight ); }
  126. //inline void SetHalfSizes( float fHalfWidth, float fHalfHeight ) { m_fHalfWidth = fHalfWidth; m_fHalfHeight = fHalfHeight; }
  127. inline bool IsMobile( void ) const { return m_bIsMobile; }
  128. void SetMobileState( bool bSet );
  129. void Resize( float fHalfWidth, float fHalfHeight );
  130. virtual CServerNetworkProperty *GetExtenderNetworkProp( void );
  131. virtual const edict_t *GetExtenderEdict( void ) const;
  132. virtual Vector GetExtensionPVSOrigin( void );
  133. virtual bool IsExtenderValid( void );
  134. //to whittle down views through recursive portals, we clip the portal's planar polygon by a frustum, then fit a new (smaller) frustum to that polygon. These two let you specify the polygon we clip and fit to
  135. virtual int GetPolyVertCount( void );
  136. virtual int ComputeFrustumThroughPolygon( const Vector &vVisOrigin, const VPlane *pInputFrustum, int iInputFrustumPlanes, VPlane *pOutputFrustum, int iOutputFrustumMaxPlanes );
  137. //This portal is decidedly visible, recursively extend the visibility problem
  138. virtual void ComputeSubVisibility( CPVS_Extender **pExtenders, int iExtenderCount, unsigned char *outputPVS, int pvssize, const Vector &vVisOrigin, const VPlane *pVisFrustum, int iVisFrustumPlanes, VisExtensionChain_t *pVisChain, int iAreasNetworked[MAX_MAP_AREAS], int iMaxRecursionsLeft );
  139. //it shouldn't matter, but the convention should be that we query the exit portal for these values
  140. virtual float GetMinimumExitSpeed( bool bPlayer, bool bEntranceOnFloor, bool bExitOnFloor, const Vector &vEntityCenterAtExit, CBaseEntity *pEntity ); //return -FLT_MAX for no minimum
  141. virtual float GetMaximumExitSpeed( bool bPlayer, bool bEntranceOnFloor, bool bExitOnFloor, const Vector &vEntityCenterAtExit, CBaseEntity *pEntity ); //return FLT_MAX for no maximum
  142. //does all the gruntwork of figuring out flooriness and calling the two above
  143. static void GetExitSpeedRange( CPortal_Base2D *pEntrancePortal, bool bPlayer, float &fExitMinimum, float &fExitMaximum, const Vector &vEntityCenterAtExit, CBaseEntity *pEntity );
  144. private:
  145. Vector m_vPortalSpawnLocation; // use this position to check against portal->AbsOrigin of the portal to see if it's moving too far (moving portal is very bad)
  146. };
  147. //-----------------------------------------------------------------------------
  148. // inline state querying methods
  149. //-----------------------------------------------------------------------------
  150. inline bool CPortal_Base2D::IsPortal2() const
  151. {
  152. return m_bIsPortal2;
  153. }
  154. inline void CPortal_Base2D::SetIsPortal2( bool bIsPortal2 )
  155. {
  156. m_bIsPortal2 = bIsPortal2;
  157. }
  158. inline const VMatrix& CPortal_Base2D::MatrixThisToLinked() const
  159. {
  160. return m_matrixThisToLinked;
  161. }
  162. void AddPortalVisibilityToPVS( CPortal_Base2D* pPortal, int outputpvslength, unsigned char *outputpvs );
  163. void EntityPortalled( CPortal_Base2D *pPortal, CBaseEntity *pOther, const Vector &vNewOrigin, const QAngle &qNewAngles, bool bForcedDuck );
  164. extern ConVar sv_allow_mobile_portals;
  165. #endif //#ifndef PORTAL_BASE2D_H