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.

68 lines
2.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CHANGEFRAMELIST_H
  8. #define CHANGEFRAMELIST_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "mempool.h"
  13. #include "dt_common.h"
  14. // This class holds the last tick (from host_tickcount) that each property in
  15. // a datatable changed at.
  16. //
  17. // It provides fast access to a list of properties that changed within a certain frame range.
  18. //
  19. // These are created once per entity per frame. Since usually a very small percentage of an
  20. // entity's properties actually change each frame, this allows you to get a small set of
  21. // properties to delta for each client.
  22. class CChangeFrameList
  23. {
  24. public:
  25. //properties are bucketed into batches to keep the iteration through change frames fast. This
  26. //allows for a time stamp to be checked on a bucket, and thereby skip the entire bucket
  27. static const uint32 knBucketSize = 32;
  28. CChangeFrameList( int nProperties, int iCurTick );
  29. ~CChangeFrameList();
  30. CChangeFrameList( const CChangeFrameList &rhs );
  31. // Call this to delete the object.
  32. void Release();
  33. // This just returns the value you passed into AllocChangeFrameList().
  34. int GetNumProps() const { return m_nNumProps; }
  35. int GetPropTick( int nProp ) const { return m_ChangeTicks[ nProp ]; }
  36. // Sets the change frames for the specified properties to iFrame.
  37. void SetChangeTick( const int* RESTRICT pProps, int nNumProps, const int iTick );
  38. void SetChangeTick( const int nProp, const int iTick ) { m_ChangeTicks[ nProp ] = iTick; m_ChangeTicks[ m_nNumProps + nProp / knBucketSize ] = iTick; }
  39. //given a bucket index, this will determine the lastest tick on that bucket
  40. const int GetNumBuckets() const { return m_ChangeTicks.Count() - m_nNumProps; }
  41. const int* GetBucketChangeTicks() const { return m_ChangeTicks.Base() + m_nNumProps; }
  42. const int* GetChangeTicks() const { return m_ChangeTicks.Base(); }
  43. // Given a tick and a property index, this will determine if it was changed after that time
  44. bool DidPropChangeAfterTick( int iTick, int nProp ) const { return m_ChangeTicks[ nProp ] > iTick; }
  45. CChangeFrameList* Copy(); // return a copy of itself
  46. private:
  47. // Change frames for each property. The buckets for the property set are appended onto the end.
  48. CUtlVector< int > m_ChangeTicks;
  49. int m_nNumProps;
  50. CChangeFrameList &operator=( const CChangeFrameList &rhs );
  51. DECLARE_FIXEDSIZE_ALLOCATOR_MT( CChangeFrameList );
  52. };
  53. #endif // CHANGEFRAMELIST_H