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.

83 lines
2.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef CLIENTFRAME_H
  7. #define CLIENTFRAME_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <bitvec.h>
  12. #include <const.h>
  13. #include <tier1/mempool.h>
  14. class CFrameSnapshot;
  15. #define MAX_CLIENT_FRAMES 128
  16. class CClientFrame
  17. {
  18. public:
  19. CClientFrame( void );
  20. CClientFrame( int tickcount );
  21. CClientFrame( CFrameSnapshot *pSnapshot );
  22. virtual ~CClientFrame();
  23. void Init( CFrameSnapshot *pSnapshot );
  24. void Init( int tickcount );
  25. // Accessors to snapshots. The data is protected because the snapshots are reference-counted.
  26. inline CFrameSnapshot* GetSnapshot() const { return m_pSnapshot; };
  27. void SetSnapshot( CFrameSnapshot *pSnapshot );
  28. void CopyFrame( CClientFrame &frame );
  29. virtual bool IsMemPoolAllocated() { return true; }
  30. public:
  31. // State of entities this frame from the POV of the client.
  32. int last_entity; // highest entity index
  33. int tick_count; // server tick of this snapshot
  34. CClientFrame* m_pNext;
  35. // Used by server to indicate if the entity was in the player's pvs
  36. CBitVec<MAX_EDICTS> transmit_entity; // if bit n is set, entity n will be send to client
  37. CBitVec<MAX_EDICTS> *from_baseline; // if bit n is set, this entity was send as update from baseline
  38. CBitVec<MAX_EDICTS> *transmit_always; // if bit is set, don't do PVS checks before sending (HLTV only)
  39. private:
  40. // Index of snapshot entry that stores the entities that were active and the serial numbers
  41. // for the frame number this packed entity corresponds to
  42. // m_pSnapshot MUST be private to force using SetSnapshot(), see reference counters
  43. CFrameSnapshot *m_pSnapshot;
  44. };
  45. // TODO substitute CClientFrameManager with an intelligent structure (Tree, hash, cache, etc)
  46. class CClientFrameManager
  47. {
  48. public:
  49. CClientFrameManager(void) : m_ClientFramePool( MAX_CLIENT_FRAMES, CUtlMemoryPool::GROW_SLOW ) { m_Frames = NULL; }
  50. virtual ~CClientFrameManager(void) { DeleteClientFrames(-1); }
  51. int AddClientFrame( CClientFrame *pFrame ); // returns current count
  52. CClientFrame *GetClientFrame( int nTick, bool bExact = true );
  53. void DeleteClientFrames( int nTick ); // -1 for all
  54. int CountClientFrames( void ); // returns number of frames in list
  55. void RemoveOldestFrame( void ); // removes the oldest frame in list
  56. bool DeleteUnusedClientFrame( CClientFrame* pFrame );
  57. int GetOldestTick()const{ return m_Frames ? m_Frames->tick_count : 0; }
  58. CClientFrame* AllocateFrame();
  59. CClientFrame* AllocateAndInitFrame( int nTick );
  60. private:
  61. void FreeFrame( CClientFrame* pFrame );
  62. CClientFrame *m_Frames; // updates can be delta'ed from here
  63. CClassMemoryPool< CClientFrame > m_ClientFramePool;
  64. };
  65. #endif // CLIENTFRAME_H