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.

76 lines
1.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef __UNISIGNALS_H__
  7. #define __UNISIGNALS_H__
  8. // Unified signals allow state updating to be performed at one point in the
  9. // calling code. The sequence of events is:
  10. //
  11. // 1. Signal( whatever ), Signal( whatever ), etc.
  12. // 2. ( GetState() & Update() ) to get only the changes since the last update
  13. // 3. Goto 1
  14. //
  15. // Or, alternately:
  16. //
  17. // 1. Signal( whatever ), Signal( whatever ), etc.
  18. // 2. Update()
  19. // 3. GetState()
  20. // 4. Goto 1
  21. class CUnifiedSignals
  22. {
  23. public:
  24. inline CUnifiedSignals();
  25. inline int Update(); // Returns a mask for the changed state bits; signals are cleared after this update is performed
  26. inline void Signal( int flSignal ); // ORed combo of BPSIG_xxx bits
  27. inline int GetState(); // Returns the current state (ORed combo of BPSIG_xxx flags)
  28. private:
  29. int m_flSignal; // States to trigger
  30. int m_flState; // States after the previous update
  31. };
  32. inline CUnifiedSignals::CUnifiedSignals()
  33. {
  34. m_flSignal = 0;
  35. m_flState = 0;
  36. }
  37. inline int CUnifiedSignals::Update()
  38. {
  39. int old = m_flState;
  40. m_flState = m_flSignal;
  41. m_flSignal = 0;
  42. return m_flState ^ old;
  43. }
  44. inline void CUnifiedSignals::Signal( int flSignal )
  45. {
  46. m_flSignal |= flSignal;
  47. }
  48. inline int CUnifiedSignals::GetState()
  49. {
  50. return m_flState;
  51. }
  52. #endif // __UNISIGNALS_H__