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.

93 lines
1.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef TIMEDEVENTMGR_H
  7. #define TIMEDEVENTMGR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "utlpriorityqueue.h"
  12. //
  13. //
  14. // These classes provide fast timed event callbacks. To use them, make a CTimedEventMgr
  15. // and put CEventRegister objects in your objects that want the timed events.
  16. //
  17. //
  18. class CTimedEventMgr;
  19. abstract_class IEventRegisterCallback
  20. {
  21. public:
  22. virtual void FireEvent() = 0;
  23. };
  24. class CEventRegister
  25. {
  26. friend bool TimedEventMgr_LessFunc( CEventRegister* const &a, CEventRegister* const &b );
  27. friend class CTimedEventMgr;
  28. public:
  29. CEventRegister();
  30. ~CEventRegister();
  31. // Call this before ever calling SetUpdateInterval().
  32. void Init( CTimedEventMgr *pMgr, IEventRegisterCallback *pCallback );
  33. // Use these to start and stop getting updates.
  34. void SetUpdateInterval( float interval );
  35. void StopUpdates();
  36. inline bool IsRegistered() const { return m_bRegistered; }
  37. private:
  38. void Reregister(); // After having an event processed, this is called to have it register for the next one.
  39. void Term();
  40. private:
  41. CTimedEventMgr *m_pEventMgr;
  42. float m_flNextEventTime;
  43. float m_flUpdateInterval;
  44. IEventRegisterCallback *m_pCallback;
  45. bool m_bRegistered;
  46. };
  47. class CTimedEventMgr
  48. {
  49. friend class CEventRegister;
  50. public:
  51. CTimedEventMgr();
  52. // Call this each frame to fire events.
  53. void FireEvents();
  54. private:
  55. // Things used by CEventRegister.
  56. void RegisterForNextEvent( CEventRegister *pEvent );
  57. void RemoveEvent( CEventRegister *pEvent );
  58. private:
  59. // Events, sorted by the time at which they will fire.
  60. CUtlPriorityQueue<CEventRegister*> m_Events;
  61. };
  62. #endif // TIMEDEVENTMGR_H