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.

78 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PREDICTABLEID_H
  8. #define PREDICTABLEID_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #if !defined( NO_ENTITY_PREDICTION )
  13. //-----------------------------------------------------------------------------
  14. // Purpose: Wraps 32bit predictID to allow access and creation
  15. //-----------------------------------------------------------------------------
  16. class CPredictableId
  17. {
  18. public:
  19. // Construction
  20. CPredictableId( void );
  21. static void ResetInstanceCounters( void );
  22. // Is the Id being used
  23. bool IsActive( void ) const;
  24. // Call this to set from data
  25. void Init( int player, int command, const char *classname, const char *module, int line );
  26. // Get player index
  27. int GetPlayer( void ) const;
  28. // Get hash value
  29. int GetHash( void ) const;
  30. // Get index number
  31. int GetInstanceNumber( void ) const;
  32. // Get command number
  33. int GetCommandNumber( void ) const;
  34. // Check command number
  35. // bool IsCommandNumberEqual( int testNumber ) const;
  36. // Client only
  37. void SetAcknowledged( bool ack );
  38. bool GetAcknowledged( void ) const;
  39. // For conversion to/from integer
  40. int GetRaw( void ) const;
  41. void SetRaw( int raw );
  42. char const *Describe( void ) const;
  43. // Equality test
  44. bool operator ==( const CPredictableId& other ) const;
  45. bool operator !=( const CPredictableId& other ) const;
  46. private:
  47. void SetCommandNumber( int commandNumber );
  48. void SetPlayer( int playerIndex );
  49. void SetInstanceNumber( int counter );
  50. // Encoding bits, should total 32
  51. struct bitfields
  52. {
  53. unsigned int ack : 1; // 1
  54. unsigned int player : 5; // 6
  55. unsigned int command : 10; // 16
  56. unsigned int hash : 12; // 28
  57. unsigned int instance : 4; // 32
  58. } m_PredictableID;
  59. };
  60. // This can be empty, the class has a proper constructor
  61. FORCEINLINE void NetworkVarConstruct( CPredictableId &x ) {}
  62. #endif
  63. #endif // PREDICTABLEID_H