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.

190 lines
6.3 KiB

  1. //========= Copyright � 1996-2005, 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. extern ConVar sv_phys_props_block_movers;
  37. // HACKHACK: We treat anything >= 500kg as a special "large mass" that does more impact damage
  38. // and has special recovery on crushing/killing other objects
  39. // also causes screen shakes on impact with static/world objects
  40. const float VPHYSICS_LARGE_OBJECT_MASS = 500.0f;
  41. struct gamevcollisionevent_t : public vcollisionevent_t
  42. {
  43. Vector preVelocity[2];
  44. Vector postVelocity[2];
  45. AngularImpulse preAngularVelocity[2];
  46. CBaseEntity *pEntities[2];
  47. void Init( vcollisionevent_t *pEvent )
  48. {
  49. *((vcollisionevent_t *)this) = *pEvent;
  50. pEntities[0] = NULL;
  51. pEntities[1] = NULL;
  52. }
  53. };
  54. struct triggerevent_t
  55. {
  56. CBaseEntity *pTriggerEntity;
  57. IPhysicsObject *pTriggerPhysics;
  58. CBaseEntity *pEntity;
  59. IPhysicsObject *pObject;
  60. bool bStart;
  61. inline void Init( CBaseEntity *triggerEntity, IPhysicsObject *triggerPhysics, CBaseEntity *entity, IPhysicsObject *object, bool startTouch )
  62. {
  63. pTriggerEntity = triggerEntity;
  64. pTriggerPhysics= triggerPhysics;
  65. pEntity = entity;
  66. pObject = object;
  67. bStart = startTouch;
  68. }
  69. inline void Clear()
  70. {
  71. memset( this, 0, sizeof(*this) );
  72. }
  73. };
  74. // parse solid parameter overrides out of a string
  75. void PhysSolidOverride( solid_t &solid, string_t overrideScript );
  76. extern CEntityList *g_pShadowEntities;
  77. #ifdef PORTAL
  78. extern CEntityList *g_pShadowEntities_Main;
  79. #endif
  80. void PhysAddShadow( CBaseEntity *pEntity );
  81. void PhysRemoveShadow( CBaseEntity *pEntity );
  82. bool PhysHasShadow( CBaseEntity *pEntity );
  83. void PhysEnableFloating( IPhysicsObject *pObject, bool bEnable );
  84. void PhysCollisionSound( CBaseEntity *pEntity, IPhysicsObject *pPhysObject, int channel, int surfaceProps, int surfacePropsHit, float deltaTime, float speed );
  85. void PhysCollisionScreenShake( gamevcollisionevent_t *pEvent, int index );
  86. void PhysCollisionDust( gamevcollisionevent_t *pEvent, surfacedata_t *phit );
  87. #if HL2_EPISODIC
  88. void PhysCollisionWarpEffect( gamevcollisionevent_t *pEvent, surfacedata_t *phit );
  89. #endif
  90. void PhysBreakSound( CBaseEntity *pEntity, IPhysicsObject *pPhysObject, Vector vecOrigin );
  91. // plays the impact sound for a particular material
  92. void PhysicsImpactSound( CBaseEntity *pEntity, IPhysicsObject *pPhysObject, int channel, int surfaceProps, int surfacePropsHit, float volume, float impactSpeed );
  93. void PhysCallbackDamage( CBaseEntity *pEntity, const CTakeDamageInfo &info );
  94. void PhysCallbackDamage( CBaseEntity *pEntity, const CTakeDamageInfo &info, gamevcollisionevent_t &event, int hurtIndex );
  95. // Applies force impulses at a later time
  96. void PhysCallbackImpulse( IPhysicsObject *pPhysicsObject, const Vector &vecCenterForce, const AngularImpulse &vecCenterTorque );
  97. // Sets the velocity at a later time
  98. void PhysCallbackSetVelocity( IPhysicsObject *pPhysicsObject, const Vector &vecVelocity );
  99. // queue up a delete on this object
  100. void PhysCallbackRemove(IServerNetworkable *pRemove);
  101. bool PhysGetDamageInflictorVelocityStartOfFrame( IPhysicsObject *pInflictor, Vector &velocity, AngularImpulse &angVelocity );
  102. // force a physics entity to sleep immediately
  103. void PhysForceEntityToSleep( CBaseEntity *pEntity, IPhysicsObject *pObject );
  104. // teleport an entity to it's position relative to an object it's constrained to
  105. void PhysTeleportConstrainedEntity( CBaseEntity *pTeleportSource, IPhysicsObject *pObject0, IPhysicsObject *pObject1, const Vector &prevPosition, const QAngle &prevAngles, bool physicsRotate );
  106. void PhysGetListOfPenetratingEntities( CBaseEntity *pSearch, CUtlVector<CBaseEntity *> &list );
  107. bool PhysShouldCollide( IPhysicsObject *pObj0, IPhysicsObject *pObj1 );
  108. // returns true when processing a callback - so we can defer things that can't be done inside a callback
  109. bool PhysIsInCallback();
  110. bool PhysIsFinalTick();
  111. bool PhysGetTriggerEvent( triggerevent_t *pEvent, CBaseEntity *pTrigger );
  112. // note: pErrorEntity is used to report errors (object not found, more than one found). It can be NULL
  113. IPhysicsObject *FindPhysicsObjectByName( const char *pName, CBaseEntity *pErrorEntity );
  114. bool PhysFindOrAddVehicleScript( const char *pScriptName, struct vehicleparams_t *pParams, struct vehiclesounds_t *pSounds );
  115. void PhysFlushVehicleScripts();
  116. // this is called to flush all queues when the delete list is cleared
  117. void PhysOnCleanupDeleteList();
  118. struct masscenteroverride_t
  119. {
  120. enum align_type
  121. {
  122. ALIGN_POINT = 0,
  123. ALIGN_AXIS = 1,
  124. };
  125. void Defaults()
  126. {
  127. entityName = NULL_STRING;
  128. }
  129. void SnapToPoint( string_t name, const Vector &pointWS )
  130. {
  131. entityName = name;
  132. center = pointWS;
  133. axis.Init();
  134. alignType = ALIGN_POINT;
  135. }
  136. void SnapToAxis( string_t name, const Vector &axisStartWS, const Vector &unitAxisDirWS )
  137. {
  138. entityName = name;
  139. center = axisStartWS;
  140. axis = unitAxisDirWS;
  141. alignType = ALIGN_AXIS;
  142. }
  143. Vector center;
  144. Vector axis;
  145. int alignType;
  146. string_t entityName;
  147. };
  148. void PhysSetMassCenterOverride( masscenteroverride_t &override );
  149. // NOTE: this removes the entry from the table as well as retrieving it
  150. void PhysGetMassCenterOverride( CBaseEntity *pEntity, vcollide_t *pCollide, solid_t &solidOut );
  151. void PhysSetEntityGameFlags( CBaseEntity *pEntity, unsigned short flags );
  152. void DebugDrawContactPoints(IPhysicsObject *pPhysics);
  153. #endif // PHYSICS_H