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.

236 lines
8.9 KiB

  1. //========= Copyright c 1996-2008, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Physics2 interfaces to vphysics DLL
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef VPHYSICS2_INTERFACE_HDR
  8. #define VPHYSICS2_INTERFACE_HDR
  9. #include "datalinker_interface.h"
  10. #include "mathlib/ssemath.h"
  11. #include "appframework/iappsystem.h"
  12. class Vector4DAligned;
  13. class CPhysics2Shape{};
  14. class CPhysics2Polytope: public CPhysics2Shape{}; // maps to CPhysics2PolytopeShape
  15. class CPhysics2Polysoup: public CPhysics2Shape{}; // maps to CPhysics2PolysoupShape (hkpSimpleMeshShape)
  16. class CPhysics2Box: public CPhysics2Shape{};
  17. class CPhysics2Mopp: public CPhysics2Shape{}; // includes Mopp and vertex, triangle and convex data
  18. class CPhysics2Actor; // maps to hkpRigidBody
  19. class CPhysics2Inertia; // maps to hkpMassProperties
  20. abstract_class IPhysics2CookedMeshBase
  21. {
  22. public:
  23. virtual uint GetType()const = 0;
  24. virtual uint NumVertices() const = 0;
  25. virtual uint NumTriangles() const = 0;
  26. virtual void GetVertices(float *pVertsOut, uint nByteStride, const fltx4 & factor = Four_Ones) = 0;
  27. virtual void GetTriangles(int *pTrisOut, uint nByteStride) = 0;
  28. virtual uint GetSizeOf()const = 0;
  29. };
  30. abstract_class IPhysics2CookedPolytope : public IPhysics2CookedMeshBase
  31. {
  32. public:
  33. virtual CPhysics2Polytope* GetPolytope() = 0;
  34. protected:
  35. virtual ~IPhysics2CookedPolytope(){}
  36. };
  37. abstract_class IPhysics2CookedPolysoup : public IPhysics2CookedMeshBase
  38. {
  39. public:
  40. virtual CPhysics2Polysoup* GetPolysoup() = 0;
  41. virtual void ExportObj(const char *szPath) = 0;
  42. protected:
  43. virtual ~IPhysics2CookedPolysoup(){}
  44. };
  45. abstract_class IPhysics2CookedMopp: public IPhysics2CookedMeshBase
  46. {
  47. public:
  48. virtual CPhysics2Mopp* GetMopp() = 0;
  49. protected:
  50. virtual ~IPhysics2CookedMopp(){}
  51. };
  52. abstract_class IPhysics2CookedInertia
  53. {
  54. public:
  55. virtual CPhysics2Inertia* GetInertia() = 0;
  56. protected:
  57. virtual ~IPhysics2CookedInertia() {}
  58. };
  59. abstract_class IPhysics2Level
  60. {
  61. public:
  62. virtual bool HasMopp() = 0;
  63. };
  64. //
  65. // all flags to these interfaces are located in vphysics2_interface_flags.h
  66. // so it's easy to change/add flags without recompiling everything
  67. //
  68. abstract_class IPhysics2Cook;
  69. abstract_class IPhysics2World;
  70. abstract_class IPhysics2ResourceManager;
  71. abstract_class IPhysics2Collision;
  72. abstract_class IPhysics2ActorManager;
  73. abstract_class IPhysics2: public IAppSystem
  74. {
  75. public:
  76. virtual IPhysics2World* CreateWorld(uint flags = 0) = 0; // NewWorld ?
  77. virtual int NumWorlds() = 0;
  78. virtual IPhysics2World * GetWorld(int nWorld) = 0;
  79. virtual void Destroy(IPhysics2World *pWorld) = 0; // Free? Release? Delete? Destruct?
  80. virtual IPhysics2Cook *GetCook() = 0;
  81. virtual IPhysics2ResourceManager *GetResourceManager() = 0;
  82. virtual IPhysics2Collision *GetCollision() = 0;
  83. virtual IPhysics2ActorManager *GetActorManager() = 0;
  84. // what version of binary data does this build generate?
  85. virtual int GetSerializeVersion() = 0;
  86. virtual int NumThreads() = 0;
  87. };
  88. abstract_class IPhysics2ActorManager
  89. {
  90. public:
  91. virtual uintp GetUserData(const CPhysics2Actor *pActor) = 0;
  92. virtual void SetUserData(CPhysics2Actor *pActor, uintp userData) = 0;
  93. virtual const fltx4 GetPosition(const CPhysics2Actor *pActor) = 0;
  94. virtual const QuaternionAligned GetOrientation(const CPhysics2Actor *pActor) = 0;
  95. virtual void SetPosition(const CPhysics2Actor *pActor, const fltx4 &vel) = 0;
  96. virtual void SetOrientation(const CPhysics2Actor *pActor, const QuaternionAligned &orientation) = 0;
  97. virtual void SetVelocity(const CPhysics2Actor *pActor, const fltx4 &vel) = 0;
  98. // this is here temporarily..
  99. //virtual void Destroy(CPhysics2Actor *pActor) = 0;
  100. };
  101. abstract_class IPhysics2Collision
  102. {
  103. public:
  104. virtual void Login(IPhysics2Level*) = 0;
  105. //virtual IPhysics2Level* Login(struct dphyslevelV0_t *pRoot) = 0; // Unserialize() then Login()
  106. virtual void Logout(IPhysics2Level*) = 0; // Logout() then Release()
  107. // static collision queries may go here, like in old physics
  108. // but it's probably better to keep them all in World and just have a flag to do...
  109. //virtual void Raytrace(...){}
  110. //virtual void SphereCast(...){}
  111. };
  112. // heavy-cooking interface, should not be used at runtime
  113. abstract_class IPhysics2Cook
  114. {
  115. public:
  116. // produce a convex element from planes (csg of planes). ax+by+cz-d==0, the normal (a,b,c) shows OUTSIDE the polytope
  117. virtual IPhysics2CookedPolytope *CookPolytopeFromPlanes( const Vector4DAligned*pPlanes, int planeCount, float mergeDistance = 0.001f) = 0;
  118. virtual IPhysics2CookedPolytope *CookPolytopeFromVertices( const Vector4DAligned*pVertices, int vertexCount, float mergeDistance = 0.001f) = 0;
  119. virtual IPhysics2CookedPolytope *CookPolytope(IPhysics2CookedMeshBase *pMesh) = 0;
  120. virtual void* Serialize(CPhysics2Polytope *pShape, DataLinker::IStream *pStream) = 0;
  121. virtual void Destroy(IPhysics2CookedPolytope *pShape, unsigned flags = 0) = 0; // Cook and World interfaces may use different memory pools, so Release/Destroy methods are separate for both
  122. virtual IPhysics2CookedPolysoup *CookPolysoupFromMeshes( IPhysics2CookedMeshBase *const* ppMeshes, int numMeshes ) = 0;
  123. virtual void* Serialize(CPhysics2Polysoup *pPolysoup, DataLinker::IStream *pStream) = 0;
  124. virtual void Destroy(IPhysics2CookedPolysoup *) = 0;
  125. virtual IPhysics2CookedInertia *CookInertia(CPhysics2Shape *pShape) = 0;
  126. virtual void* Serialize(CPhysics2Inertia *pInertia, DataLinker::IStream *pStream) = 0;
  127. virtual void Destroy(IPhysics2CookedInertia *pInertia, unsigned flags = 0) = 0;
  128. virtual IPhysics2CookedMopp *CookMopp(IPhysics2CookedMeshBase *const*ppMeshes, int numMeshes) = 0;
  129. virtual void* Serialize(CPhysics2Mopp *pMopp, DataLinker::IStream *pStream) = 0;
  130. virtual void Destroy(IPhysics2CookedMopp *) = 0;
  131. virtual void ExportObj(const char *szFileName, IPhysics2CookedMeshBase *const*ppMeshes, int numMeshes) = 0;
  132. };
  133. //
  134. // all Unserialize () functions retain pointers to the original buffer, which must exist until final release of the object created
  135. // all new objects are created with refCount == 1; you must release them when you are done with them. When you add them to the worlds, they add their refCounts.
  136. // Release() has a flag that allows you to Assert if it does NOT actually free the object
  137. //
  138. abstract_class IPhysics2ResourceManager // Data? Manager?
  139. {
  140. public:
  141. virtual CPhysics2Polytope *UnserializePolytope(const void *pBuffer/*, unsigned nSize*/) = 0;
  142. virtual void Release(CPhysics2Polytope *pShape, unsigned flag = 0) = 0; // Cook and World interfaces may use different memory pools, so Release methods are separate for both
  143. // pBuffer may be NULL
  144. virtual CPhysics2Inertia *UnserializeInertia(const void *pBuffer) = 0;
  145. // pInertia may be NULL
  146. virtual void Release(CPhysics2Inertia *pInertia, unsigned flag = 0) = 0;
  147. virtual CPhysics2Polysoup *UnserializePolysoup(const void* pBuffer) = 0;
  148. virtual void Release(CPhysics2Polysoup* pPolysoup, unsigned flag = 0) = 0;
  149. virtual CPhysics2Mopp *UnserializeMopp(const void* pBuffer) = 0;
  150. virtual void Release(CPhysics2Mopp* pPolysoup, unsigned flag = 0) = 0;
  151. virtual IPhysics2Level* UnserializeLevel(const struct dphyslevelV0_t *pRoot) = 0;
  152. virtual void Release(IPhysics2Level*) = 0;
  153. virtual CPhysics2Box *CreateBoxShape(const fltx4& halfSize) = 0;
  154. virtual void Release(CPhysics2Box *pBox) = 0;
  155. virtual CPhysics2Shape *GetStockShape(uint nShape) = 0; // there's no need to release the stock shapes
  156. virtual void Release(CPhysics2Shape* pShape, unsigned flag = 0) = 0;
  157. };
  158. // interface to individual worlds, there may be multiple worlds at the same time (e.g. client and server)
  159. abstract_class IPhysics2World
  160. {
  161. public:
  162. // pInertia may be NULL - especially when flags make the actor static
  163. virtual CPhysics2Actor* AddActor(CPhysics2Shape *pShape, CPhysics2Inertia *pInertia, uint flags = 0) = 0;
  164. virtual void Destroy(CPhysics2Actor*) = 0;
  165. virtual int NumActiveActors() = 0;
  166. virtual void GetActiveActors(CPhysics2Actor **ppActors) = 0;
  167. virtual void Reset() = 0; // I don't know what this should do yet - look at PhysicsReset() in physics.cpp
  168. virtual void Simulate ( float deltaTime ) = 0;
  169. };
  170. DECLARE_TIER1_INTERFACE( IPhysics2, g_pPhysics2 ); // this is extern from tier1
  171. DECLARE_TIER1_INTERFACE( IPhysics2ActorManager, g_pPhysics2ActorManager );
  172. DECLARE_TIER1_INTERFACE( IPhysics2ResourceManager, g_pPhysics2ResourceManager );
  173. class CPhysics2Actor
  174. {
  175. public:
  176. inline uintp GetUserData()const{return g_pPhysics2ActorManager->GetUserData(this);}
  177. inline void SetUserData(uintp userData){g_pPhysics2ActorManager->SetUserData(this, userData);}
  178. inline const fltx4 GetPosition()const { return g_pPhysics2ActorManager->GetPosition(this);}
  179. inline const QuaternionAligned GetOrientation()const {return g_pPhysics2ActorManager->GetOrientation(this);}
  180. inline void SetPosition(const fltx4 &pos){return g_pPhysics2ActorManager->SetPosition(this, pos);}
  181. inline void SetOrientation(const QuaternionAligned &q){g_pPhysics2ActorManager->SetOrientation(this, q);}
  182. inline void SetVelocity(const fltx4 &vel){return g_pPhysics2ActorManager->SetVelocity(this, vel);}
  183. };
  184. #endif