Advertisement
encoree1996

Untitled

Apr 20th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.16 KB | None | 0 0
  1.  
  2. #define CHAR_TEX_CONCRETE 'C'
  3. #define CHAR_TEX_METAL 'M'
  4. #define CHAR_TEX_DIRT 'D'
  5. #define CHAR_TEX_VENT 'V'
  6. #define CHAR_TEX_GRATE 'G'
  7. #define CHAR_TEX_TILE 'T'
  8. #define CHAR_TEX_SLOSH 'S'
  9. #define CHAR_TEX_WOOD 'W'
  10. #define CHAR_TEX_COMPUTER 'P'
  11. #define CHAR_TEX_GLASS 'Y'
  12. #define CHAR_TEX_FLESH 'F'
  13. #define CHAR_TEX_BLOODYFLESH 'B'
  14. #define CHAR_TEX_CLIP 'I'
  15. #define CHAR_TEX_ANTLION 'A'
  16. #define CHAR_TEX_ALIENFLESH 'H'
  17. #define CHAR_TEX_FOLIAGE 'O'
  18. #define CHAR_TEX_SAND 'N'
  19. #define CHAR_TEX_PLASTIC 'L'
  20.  
  21. typedef void*   (*CreateClientClassFn)(int entnum, int serialNum);
  22. typedef void*   (*CreateEventFn)();
  23.  
  24. typedef float vec_t;
  25.  
  26. class __declspec(align(16)) VectorAligned: public Vector
  27. {
  28. public:
  29.     inline VectorAligned(void) {};
  30.     inline VectorAligned(vec_t X, vec_t Y, vec_t Z)
  31.     {
  32.         Init(X, Y, Z);
  33.     }
  34. public:
  35.     explicit VectorAligned(const Vector &vOther)
  36.     {
  37.         Init(vOther.X, vOther.Y, vOther.Z);
  38.     }
  39.  
  40.     VectorAligned& operator=(const Vector &vOther)
  41.     {
  42.         Init(vOther.X, vOther.Y, vOther.Z);
  43.         return *this;
  44.     }
  45.  
  46.     float w;    // this space is used anyway
  47. };
  48.  
  49.  
  50. struct Ray_t
  51. {
  52.     VectorAligned   m_Start;
  53.     VectorAligned   m_Delta;
  54.     VectorAligned   m_StartOffset;
  55.     VectorAligned   m_Extents;
  56.  
  57.     const   matrix3x4_t* m_pWorldAxisTransform;
  58.  
  59.     bool    m_IsRay;
  60.     bool    m_IsSwept;
  61.  
  62.     Ray_t(): m_pWorldAxisTransform(NULL) {}
  63.  
  64.     void Init(Vector& vecStart, Vector& vecEnd)
  65.     {
  66.         m_Delta = vecEnd - vecStart;
  67.  
  68.         m_IsSwept = (m_Delta.X != 0 && m_Delta.Y != 0 && m_Delta.Z != 0);
  69.  
  70.         m_Extents.X = m_Extents.Y = m_Extents.Z = 0.0f;
  71.  
  72.         m_pWorldAxisTransform = NULL;
  73.  
  74.         m_IsRay = true;
  75.  
  76.         m_StartOffset.X = m_StartOffset.Y = m_StartOffset.Z = 0.0f;
  77.  
  78.         m_Start = vecStart;
  79.     }
  80. };
  81.  
  82.  
  83. template< typename Function > Function call_vfunc(PVOID Base, DWORD Index)
  84. {
  85.     PDWORD* VTablePointer = (PDWORD*)Base;
  86.     PDWORD VTableFunctionBase = *VTablePointer;
  87.     DWORD dwAddress = VTableFunctionBase[Index];
  88.     return (Function)(dwAddress);
  89. }
  90.  
  91. struct cplane_t
  92. {
  93.     Vector       normal;
  94.     float        dist;
  95.     BYTE        type;
  96.     BYTE        signbits;
  97.     BYTE        pad[2];
  98. };
  99. struct csurface_t
  100. {
  101.     const char    *name;
  102.     short        surfaceProps;
  103.     unsigned short    flags;
  104. };
  105.  
  106. struct trace_t
  107. {
  108.     Vector            startpos;
  109.     Vector            endpos;
  110.     cplane_t        plane;
  111.     float            fraction;
  112.     int                contents;
  113.     unsigned int    dispFlags;
  114.     bool            allsolid;
  115.     bool            startsolid;
  116.     float        fractionleftsolid;
  117.     csurface_t    surface;
  118.     int            hitgroup;
  119.     short        physicsbone;
  120.     unsigned short    worldSurfaceIndex;
  121.     DWORD*        m_pEntityHit;
  122.     int            hitbox;
  123. };
  124.  
  125.  
  126. struct surfacephysicsparams_t
  127. {
  128.     // vphysics physical properties
  129.     float           friction;
  130.     float           elasticity;             // collision elasticity - used to compute coefficient of restitution
  131.     float           density;                // physical density (in kg / m^3)
  132.     float           thickness;              // material thickness if not solid (sheet materials) in inches
  133.     float           dampening;
  134. };
  135.  
  136. struct surfaceaudioparams_t
  137. {
  138.     // sounds / audio data
  139.     float           reflectivity;       // like elasticity, but how much sound should be reflected by this surface
  140.     float           hardnessFactor; // like elasticity, but only affects impact sound choices
  141.     float           roughnessFactor;    // like friction, but only affects scrape sound choices
  142.  
  143.     // audio thresholds
  144.     float           roughThreshold; // surface roughness > this causes "rough" scrapes, < this causes "smooth" scrapes
  145.     float           hardThreshold;  // surface hardness > this causes "hard" impacts, < this causes "soft" impacts
  146.     float           hardVelocityThreshold;  // collision velocity > this causes "hard" impacts, < this causes "soft" impacts
  147.     // NOTE: Hard impacts must meet both hardnessFactor AND velocity thresholds
  148. };
  149.  
  150. struct surfacesoundnames_t
  151. {
  152.     unsigned short  stepleft;
  153.     unsigned short  stepright;
  154.  
  155.     unsigned short  impactSoft;
  156.     unsigned short  impactHard;
  157.  
  158.     unsigned short  scrapeSmooth;
  159.     unsigned short  scrapeRough;
  160.  
  161.     unsigned short  bulletImpact;
  162.     unsigned short  rolling;
  163.  
  164.     unsigned short  breakSound;
  165.     unsigned short  strainSound;
  166. };
  167.  
  168. struct surfacesoundhandles_t
  169. {
  170.     short   stepleft;
  171.     short   stepright;
  172.  
  173.     short   impactSoft;
  174.     short   impactHard;
  175.  
  176.     short   scrapeSmooth;
  177.     short   scrapeRough;
  178.  
  179.     short   bulletImpact;
  180.     short   rolling;
  181.  
  182.     short   breakSound;
  183.     short   strainSound;
  184. };
  185.  
  186. struct surfacegameprops_t
  187. {
  188.     // game movement data
  189.     float           maxSpeedFactor;         // Modulates player max speed when walking on this surface
  190.     float           jumpFactor;             // Indicates how much higher the player should jump when on the surface
  191.     // Game-specific data
  192.     unsigned short  material;
  193.     // Indicates whether or not the player is on a ladder.
  194.     unsigned char   climbable;
  195.     unsigned char   pad;
  196. };
  197.  
  198. //-----------------------------------------------------------------------------
  199. // Purpose: Each different material has an entry like this
  200. //-----------------------------------------------------------------------------
  201. struct surfacedata_t
  202. {
  203.     surfacephysicsparams_t  physics;    // physics parameters
  204.     surfaceaudioparams_t    audio;      // audio parameters
  205.     surfacesoundnames_t     sounds;     // names of linked sounds
  206.     surfacegameprops_t      game;       // Game data / properties
  207.  
  208.     surfacesoundhandles_t       soundhandles;
  209. };
  210.  
  211. #define VPHYSICS_SURFACEPROPS_INTERFACE_VERSION "VPhysicsSurfaceProps001"
  212. class IPhysicsSurfaceProps
  213. {
  214. public:
  215.     virtual ~IPhysicsSurfaceProps(void) {}
  216.  
  217.     // parses a text file containing surface prop keys
  218.     virtual int     ParseSurfaceData(const char *pFilename, const char *pTextfile) = 0;
  219.     // current number of entries in the database
  220.     virtual int     SurfacePropCount(void) const = 0;
  221.  
  222.     virtual int     GetSurfaceIndex(const char *pSurfacePropName) const = 0;
  223.     virtual void    GetPhysicsProperties(int surfaceDataIndex, float *density, float *thickness, float *friction, float *elasticity) const = 0;
  224.  
  225.     virtual surfacedata_t   *GetSurfaceData(int surfaceDataIndex) = 0;
  226.     virtual const char      *GetString(unsigned short stringTableIndex) const = 0;
  227.  
  228.  
  229.     virtual const char      *GetPropName(int surfaceDataIndex) const = 0;
  230.  
  231.     // sets the global index table for world materials
  232.     // UNDONE: Make this per-CPhysCollide
  233.     virtual void    SetWorldMaterialIndexTable(int *pMapArray, int mapSize) = 0;
  234.  
  235.     // NOTE: Same as GetPhysicsProperties, but maybe more convenient
  236.     virtual void    GetPhysicsParameters(int surfaceDataIndex, surfacephysicsparams_t *pParamsOut) const = 0;
  237. };
  238.  
  239. enum TraceType_t
  240. {
  241.     TRACE_EVERYTHING = 0,
  242.     TRACE_WORLD_ONLY,
  243.     TRACE_ENTITIES_ONLY,
  244.     TRACE_EVERYTHING_FILTER_PROPS,
  245. };
  246.  
  247.  
  248. //class ITraceFilter
  249. //{
  250. //public:
  251. //  virtual bool ShouldHitEntity(IClientEntity *pEntity, int contentsMask) = 0;
  252. //  virtual int    GetTraceType() const;
  253. //};
  254. class ITraceFilter
  255. {
  256. public:
  257.     virtual bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask) = 0;
  258.     virtual TraceType_t GetTraceType() const = 0;
  259. };
  260.  
  261.  
  262. //-----------------------------------------------------------------------------
  263. // Classes are expected to inherit these + implement the ShouldHitEntity method
  264. //-----------------------------------------------------------------------------
  265.  
  266. // This is the one most normal traces will inherit from
  267. class CTraceFilter: public ITraceFilter
  268. {
  269. public:
  270.     bool ShouldHitEntity(IHandleEntity* pEntityHandle, int contentsMask)
  271.     {
  272.         return !(pEntityHandle == pSkip);
  273.     }
  274.     virtual TraceType_t GetTraceType() const
  275.     {
  276.         return TRACE_EVERYTHING;
  277.     }
  278.     void *pSkip;
  279. };
  280.  
  281. class CTraceFilterEntitiesOnly: public ITraceFilter
  282. {
  283. public:
  284.     virtual TraceType_t GetTraceType() const
  285.     {
  286.         return TRACE_ENTITIES_ONLY;
  287.     }
  288. };
  289.  
  290.  
  291. //-----------------------------------------------------------------------------
  292. // Classes need not inherit from these
  293. //-----------------------------------------------------------------------------
  294. class CTraceFilterWorldOnly: public ITraceFilter
  295. {
  296. public:
  297.     bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask)
  298.     {
  299.         return false;
  300.     }
  301.     virtual TraceType_t GetTraceType() const
  302.     {
  303.         return TRACE_WORLD_ONLY;
  304.     }
  305. };
  306.  
  307. class CTraceFilterWorldAndPropsOnly: public ITraceFilter
  308. {
  309. public:
  310.     bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask)
  311.     {
  312.         return false;
  313.     }
  314.     virtual TraceType_t GetTraceType() const
  315.     {
  316.         return TRACE_EVERYTHING;
  317.     }
  318. };
  319.  
  320. class CTraceFilterHitAll: public CTraceFilter
  321. {
  322. public:
  323.     virtual bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask)
  324.     {
  325.         return true;
  326.     }
  327. };
  328.  
  329.  
  330. class IEngineTrace
  331. {
  332. public:
  333.     // Returns the contents mask + entity at a particular world-space position
  334.     virtual int         GetPointContents(const Vector &vecAbsPosition, int** ppEntity = NULL) = 0;
  335.     virtual int            GetPointContents_WorldOnly(const Vector &vecAbsPosition, int contentsMask = 0) = 0;
  336.     virtual int         GetPointContents_Collideable(int *pCollide, const Vector &vecAbsPosition) = 0;
  337.     virtual void        ClipRayToEntity(const Ray_t &ray, unsigned int fMask, int *pEnt, trace_t *pTrace) = 0;
  338.     virtual void        ClipRayToCollideable(const Ray_t &ray, unsigned int fMask, int *pCollide, trace_t *pTrace) = 0;
  339.  
  340.     // A version that simply accepts a ray (can work as a traceline or tracehull)
  341.     virtual void        TraceRay(const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace) = 0;
  342. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement