Team Fortress 2 Source Code as on 22/4/2020
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.

189 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: This is the abstraction layer for the physics simulation system
  4. // Any calls to the external physics library (ipion) should be made through this
  5. // layer. Eventually, the physics system will probably become a DLL and made
  6. // accessible to the client & server side code.
  7. //
  8. // $Workfile: $
  9. // $Date: $
  10. // $NoKeywords: $
  11. //=============================================================================//
  12. #ifndef PHYSICS_H
  13. #define PHYSICS_H
  14. #ifdef _WIN32
  15. #pragma once
  16. #endif
  17. #include "physics_shared.h"
  18. class CBaseEntity;
  19. class IPhysicsMaterial;
  20. class IPhysicsConstraint;
  21. class IPhysicsSpring;
  22. class IPhysicsSurfaceProps;
  23. class CTakeDamageInfo;
  24. class ConVar;
  25. extern IPhysicsMaterial *g_Material;
  26. extern ConVar phys_pushscale;
  27. extern ConVar phys_timescale;
  28. struct objectparams_t;
  29. extern IPhysicsGameTrace *physgametrace;
  30. class IPhysicsCollisionSolver;
  31. class IPhysicsCollisionEvent;
  32. class IPhysicsObjectEvent;
  33. extern IPhysicsCollisionSolver * const g_pCollisionSolver;
  34. extern IPhysicsCollisionEvent * const g_pCollisionEventHandler;
  35. extern IPhysicsObjectEvent * const g_pObjectEventHandler;
  36. // HACKHACK: We treat anything >= 500kg as a special "large mass" that does more impact damage
  37. // and has special recovery on crushing/killing other objects
  38. // also causes screen shakes on impact with static/world objects
  39. const float VPHYSICS_LARGE_OBJECT_MASS = 500.0f;
  40. struct gamevcollisionevent_t : public vcollisionevent_t
  41. {
  42. Vector preVelocity[2];
  43. Vector postVelocity[2];
  44. AngularImpulse preAngularVelocity[2];
  45. CBaseEntity *pEntities[2];
  46. void Init( vcollisionevent_t *pEvent )
  47. {
  48. *((vcollisionevent_t *)this) = *pEvent;
  49. pEntities[0] = NULL;
  50. pEntities[1] = NULL;
  51. }
  52. };
  53. struct triggerevent_t
  54. {
  55. CBaseEntity *pTriggerEntity;
  56. IPhysicsObject *pTriggerPhysics;
  57. CBaseEntity *pEntity;
  58. IPhysicsObject *pObject;
  59. bool bStart;
  60. inline void Init( CBaseEntity *triggerEntity, IPhysicsObject *triggerPhysics, CBaseEntity *entity, IPhysicsObject *object, bool startTouch )
  61. {
  62. pTriggerEntity = triggerEntity;
  63. pTriggerPhysics= triggerPhysics;
  64. pEntity = entity;
  65. pObject = object;
  66. bStart = startTouch;
  67. }
  68. inline void Clear()
  69. {
  70. memset( this, 0, sizeof(*this) );
  71. }
  72. };
  73. // parse solid parameter overrides out of a string
  74. void PhysSolidOverride( solid_t &solid, string_t overrideScript );
  75. extern CEntityList *g_pShadowEntities;
  76. #ifdef PORTAL
  77. extern CEntityList *g_pShadowEntities_Main;
  78. #endif
  79. void PhysAddShadow( CBaseEntity *pEntity );
  80. void PhysRemoveShadow( CBaseEntity *pEntity );
  81. bool PhysHasShadow( CBaseEntity *pEntity );
  82. void PhysEnableFloating( IPhysicsObject *pObject, bool bEnable );
  83. void PhysCollisionSound( CBaseEntity *pEntity, IPhysicsObject *pPhysObject, int channel, int surfaceProps, int surfacePropsHit, float deltaTime, float speed );
  84. void PhysCollisionScreenShake( gamevcollisionevent_t *pEvent, int index );
  85. void PhysCollisionDust( gamevcollisionevent_t *pEvent, surfacedata_t *phit );
  86. #if HL2_EPISODIC
  87. void PhysCollisionWarpEffect( gamevcollisionevent_t *pEvent, surfacedata_t *phit );
  88. #endif
  89. void PhysBreakSound( CBaseEntity *pEntity, IPhysicsObject *pPhysObject, Vector vecOrigin );
  90. // plays the impact sound for a particular material
  91. void PhysicsImpactSound( CBaseEntity *pEntity, IPhysicsObject *pPhysObject, int channel, int surfaceProps, int surfacePropsHit, float volume, float impactSpeed );
  92. void PhysCallbackDamage( CBaseEntity *pEntity, const CTakeDamageInfo &info );
  93. void PhysCallbackDamage( CBaseEntity *pEntity, const CTakeDamageInfo &info, gamevcollisionevent_t &event, int hurtIndex );
  94. // Applies force impulses at a later time
  95. void PhysCallbackImpulse( IPhysicsObject *pPhysicsObject, const Vector &vecCenterForce, const AngularImpulse &vecCenterTorque );
  96. // Sets the velocity at a later time
  97. void PhysCallbackSetVelocity( IPhysicsObject *pPhysicsObject, const Vector &vecVelocity );
  98. // queue up a delete on this object
  99. void PhysCallbackRemove(IServerNetworkable *pRemove);
  100. bool PhysGetDamageInflictorVelocityStartOfFrame( IPhysicsObject *pInflictor, Vector &velocity, AngularImpulse &angVelocity );
  101. // force a physics entity to sleep immediately
  102. void PhysForceEntityToSleep( CBaseEntity *pEntity, IPhysicsObject *pObject );
  103. // teleport an entity to it's position relative to an object it's constrained to
  104. void PhysTeleportConstrainedEntity( CBaseEntity *pTeleportSource, IPhysicsObject *pObject0, IPhysicsObject *pObject1, const Vector &prevPosition, const QAngle &prevAngles, bool physicsRotate );
  105. void PhysGetListOfPenetratingEntities( CBaseEntity *pSearch, CUtlVector<CBaseEntity *> &list );
  106. bool PhysShouldCollide( IPhysicsObject *pObj0, IPhysicsObject *pObj1 );
  107. // returns true when processing a callback - so we can defer things that can't be done inside a callback
  108. bool PhysIsInCallback();
  109. bool PhysIsFinalTick();
  110. bool PhysGetTriggerEvent( triggerevent_t *pEvent, CBaseEntity *pTrigger );
  111. // note: pErrorEntity is used to report errors (object not found, more than one found). It can be NULL
  112. IPhysicsObject *FindPhysicsObjectByName( const char *pName, CBaseEntity *pErrorEntity );
  113. bool PhysFindOrAddVehicleScript( const char *pScriptName, struct vehicleparams_t *pParams, struct vehiclesounds_t *pSounds );
  114. void PhysFlushVehicleScripts();
  115. // this is called to flush all queues when the delete list is cleared
  116. void PhysOnCleanupDeleteList();
  117. struct masscenteroverride_t
  118. {
  119. enum align_type
  120. {
  121. ALIGN_POINT = 0,
  122. ALIGN_AXIS = 1,
  123. };
  124. void Defaults()
  125. {
  126. entityName = NULL_STRING;
  127. }
  128. void SnapToPoint( string_t name, const Vector &pointWS )
  129. {
  130. entityName = name;
  131. center = pointWS;
  132. axis.Init();
  133. alignType = ALIGN_POINT;
  134. }
  135. void SnapToAxis( string_t name, const Vector &axisStartWS, const Vector &unitAxisDirWS )
  136. {
  137. entityName = name;
  138. center = axisStartWS;
  139. axis = unitAxisDirWS;
  140. alignType = ALIGN_AXIS;
  141. }
  142. Vector center;
  143. Vector axis;
  144. int alignType;
  145. string_t entityName;
  146. };
  147. void PhysSetMassCenterOverride( masscenteroverride_t &override );
  148. // NOTE: this removes the entry from the table as well as retrieving it
  149. void PhysGetMassCenterOverride( CBaseEntity *pEntity, vcollide_t *pCollide, solid_t &solidOut );
  150. float PhysGetEntityMass( CBaseEntity *pEntity );
  151. void PhysSetEntityGameFlags( CBaseEntity *pEntity, unsigned short flags );
  152. void DebugDrawContactPoints(IPhysicsObject *pPhysics);
  153. #endif // PHYSICS_H