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.

135 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CLIENT_THINKLIST_H
  8. #define CLIENT_THINKLIST_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "igamesystem.h"
  13. #include "utllinkedlist.h"
  14. #include "cliententitylist.h"
  15. #include "iclientthinkable.h"
  16. #include "utlrbtree.h"
  17. #define CLIENT_THINK_ALWAYS -1293
  18. #define CLIENT_THINK_NEVER -1
  19. #define INVALID_THINK_HANDLE ClientThinkList()->GetInvalidThinkHandle()
  20. class CClientThinkList : public IGameSystemPerFrame
  21. {
  22. public:
  23. CClientThinkList();
  24. virtual ~CClientThinkList();
  25. virtual char const *Name() { return "CClientThinkList"; }
  26. virtual bool IsPerFrame() { return true; }
  27. // Set the next time at which you want to think. You can also use
  28. // one of the CLIENT_THINK_ defines.
  29. void SetNextClientThink( ClientEntityHandle_t hEnt, float nextTime );
  30. // Remove an entity from the think list.
  31. void RemoveThinkable( ClientEntityHandle_t hEnt );
  32. // Use to initialize your think handles in IClientThinkables.
  33. ClientThinkHandle_t GetInvalidThinkHandle();
  34. // This is called after network updating and before rendering.
  35. void PerformThinkFunctions();
  36. // Call this to destroy a thinkable object - deletes the object post think.
  37. void AddToDeleteList( ClientEntityHandle_t hEnt );
  38. void RemoveFromDeleteList( ClientEntityHandle_t hEnt );
  39. // IClientSystem implementation.
  40. public:
  41. virtual bool Init();
  42. virtual void PostInit() {};
  43. virtual void Shutdown();
  44. virtual void LevelInitPreEntity();
  45. virtual void LevelInitPostEntity() {}
  46. virtual void LevelShutdownPreEntity();
  47. virtual void LevelShutdownPostEntity();
  48. virtual void PreRender();
  49. virtual void PostRender() { }
  50. virtual void Update( float frametime );
  51. virtual void OnSave() {}
  52. virtual void OnRestore() {}
  53. virtual void SafeRemoveIfDesired() {}
  54. private:
  55. struct ThinkEntry_t
  56. {
  57. ClientEntityHandle_t m_hEnt;
  58. float m_flNextClientThink;
  59. float m_flLastClientThink;
  60. int m_nIterEnum;
  61. };
  62. struct ThinkListChanges_t
  63. {
  64. ClientEntityHandle_t m_hEnt;
  65. ClientThinkHandle_t m_hThink;
  66. float m_flNextTime;
  67. };
  68. // Internal stuff.
  69. private:
  70. void SetNextClientThink( ClientThinkHandle_t hThink, float nextTime );
  71. void RemoveThinkable( ClientThinkHandle_t hThink );
  72. void PerformThinkFunction( ThinkEntry_t *pEntry, float curtime );
  73. ThinkEntry_t* GetThinkEntry( ClientThinkHandle_t hThink );
  74. void CleanUpDeleteList();
  75. // Add entity to frame think list
  76. void AddEntityToFrameThinkList( ThinkEntry_t *pEntry, bool bAlwaysChain, int &nCount, ThinkEntry_t **ppFrameThinkList );
  77. private:
  78. CUtlLinkedList<ThinkEntry_t, unsigned short> m_ThinkEntries;
  79. CUtlVector<ClientEntityHandle_t> m_aDeleteList;
  80. CUtlVector<ThinkListChanges_t> m_aChangeList;
  81. // Makes sure the entries are thinked once per frame in the face of hierarchy
  82. int m_nIterEnum;
  83. bool m_bInThinkLoop;
  84. };
  85. // -------------------------------------------------------------------------------- //
  86. // Inlines.
  87. // -------------------------------------------------------------------------------- //
  88. inline ClientThinkHandle_t CClientThinkList::GetInvalidThinkHandle()
  89. {
  90. return (ClientThinkHandle_t)(uintp)m_ThinkEntries.InvalidIndex();
  91. }
  92. inline CClientThinkList::ThinkEntry_t* CClientThinkList::GetThinkEntry( ClientThinkHandle_t hThink )
  93. {
  94. return &m_ThinkEntries[ (unsigned long)hThink ];
  95. }
  96. inline CClientThinkList* ClientThinkList()
  97. {
  98. extern CClientThinkList g_ClientThinkList;
  99. return &g_ClientThinkList;
  100. }
  101. #endif // CLIENT_THINKLIST_H