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.

99 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef QUERYCACHE_H
  8. #define QUERYCACHE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier0/platform.h"
  13. #include "mathlib/vector.h"
  14. // this system provides several piece of functionality to ai or other systems which wish to do
  15. // traces and other trace-like queries.
  16. // a. By maintaining a set of incrementally updated trace results, it makes it simple to have ai
  17. // code use hyteresis on traces as an optimization method.
  18. // b. By updating the cache entries outside of the entity think functions, the update is done in a
  19. // fully multi-threaded fashion
  20. enum EQueryType_t
  21. {
  22. EQUERY_INVALID = 0, // an invalid or unused entry
  23. EQUERY_TRACELINE,
  24. EQUERY_ENTITY_LOS_CHECK,
  25. };
  26. enum EEntityOffsetMode_t
  27. {
  28. EOFFSET_MODE_WORLDSPACE_CENTER,
  29. EOFFSET_MODE_EYEPOSITION,
  30. EOFFSET_MODE_NONE, // nop
  31. };
  32. #define QCACHE_MAXPNTS 3 // maximum number of points/entities
  33. // involved in a query
  34. struct QueryCacheKey_t
  35. {
  36. EQueryType_t m_Type;
  37. int m_nNumValidPoints;
  38. Vector m_Points[QCACHE_MAXPNTS];
  39. EHANDLE m_pEntities[QCACHE_MAXPNTS];
  40. EEntityOffsetMode_t m_nOffsetMode[QCACHE_MAXPNTS];
  41. unsigned int m_nTraceMask;
  42. unsigned int m_nHashIdx;
  43. int m_nCollisionGroup;
  44. ShouldHitFunc_t m_pTraceFilterFunction;
  45. float m_flMinimumUpdateInterval;
  46. void ComputeHashIndex( void );
  47. bool Matches( QueryCacheKey_t const *pNode ) const ;
  48. };
  49. struct QueryCacheEntry_t
  50. {
  51. QueryCacheEntry_t *m_pNext;
  52. QueryCacheEntry_t *m_pPrev;
  53. QueryCacheKey_t m_QueryParams;
  54. float m_flLastUpdateTime;
  55. bool m_bUsedSinceUpdated; // was this cell referenced?
  56. bool m_bSpeculativelyDone;
  57. bool m_bResult; // for queries with a boolean result
  58. void IssueQuery( void );
  59. };
  60. bool IsLineOfSightBetweenTwoEntitiesClear( CBaseEntity *pSrcEntity,
  61. EEntityOffsetMode_t nSrcOffsetMode,
  62. CBaseEntity *pDestEntity,
  63. EEntityOffsetMode_t nDestOffsetMode,
  64. CBaseEntity *pSkipEntity,
  65. int nCollisionGroup,
  66. unsigned int nTraceMask,
  67. ShouldHitFunc_t pTraceFilterCallback,
  68. float flMinimumUpdateInterval = 0.2
  69. );
  70. // call during main loop for threaded update of the query cache
  71. void UpdateQueryCache( void );
  72. // call on level transition or other significant step-functions
  73. void InvalidateQueryCache( void );
  74. #endif // querycache_h