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.

66 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //----------------------------------------------------------------------------------------
  4. #ifndef PLAYERSPAWNCACHE_H
  5. #define PLAYERSPAWNCACHE_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //--------------------------------------------------------------------------------
  10. #include "GameEventListener.h"
  11. //--------------------------------------------------------------------------------
  12. //
  13. // I�m not sure if player spawn cache is the most descriptive name, but essentially
  14. // there is a singleton instance of CPlayerSpawnCache for the local player which has
  15. // a set of counters/pointers/etc. that get cleared every time a map loads. This
  16. // can be useful for situations where a player�s net connection chokes and they get
  17. // a full update, which recreates their C_TF_Player entirely or otherwise invalidates
  18. // a bunch of data in the local player. I believe it�s already known that there is
  19. // a class of bugs stemming from this behavior.
  20. //
  21. // Right now the cache is used as a way to display a message to the player if they
  22. // connect to a server that�s recording replays. As soon as they choose their player
  23. // class, a counter is checked, and if it�s zero the message is displayed. The counter
  24. // is then incremented. This is a sort of odd use for it actually. A better example
  25. // would be what I�m going to do next, which is that if the player�s net connection
  26. // chokes (or if you host_timescale at too great a speed and cause a full update on the
  27. // client), the replay system will think that you�ve already saved a replay for that life.
  28. // So this example will be a perfect time to use the player spawn cache because you can
  29. // maintain some level of persistence in the face of your entire local player getting
  30. // nuked.
  31. //
  32. // Just add any data members you'd like to access to the CPlayerSpawnCache::Data_t
  33. // struct and it will be cleared automatically (via a memset) whenever a new map is
  34. // loaded.
  35. //
  36. // It's possible that PreReset()/PostReset() or the like will be necessary for this
  37. // class to reach its full potential.
  38. //
  39. class CPlayerSpawnCache : public CGameEventListener
  40. {
  41. public:
  42. static CPlayerSpawnCache &Instance();
  43. // Counters
  44. struct Data_t
  45. {
  46. int m_nDisplayedConnectedRecording;
  47. int m_nDisplaySaveReplay; // Don't display the "Press [f6] to save this life" the first time the spectator GUI is shown
  48. } m_Data;
  49. private:
  50. CPlayerSpawnCache();
  51. virtual void FireGameEvent( IGameEvent *pEvent );
  52. void Reset();
  53. };
  54. //--------------------------------------------------------------------------------
  55. #endif // PLAYERSPAWNCACHE_H