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.

90 lines
2.9 KiB

  1. //====== Copyright c 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef ECON_ITEM_VIEW_HELPERS_H
  7. #define ECON_ITEM_VIEW_HELPERS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. // These helpers are used to abstract away the distinction between inventory items with legitimate itemIDs
  12. // and items that are expressed as definition index + paint index.
  13. // returns an itemID that encodes the definition index and paint id
  14. inline uint64 CombinedItemIdMakeFromDefIndexAndPaint( uint16 iDefIndex, uint16 iPaint, uint8 ub1 = 0 )
  15. {
  16. if ( iDefIndex == 0 && iPaint == 0 )
  17. return 0;
  18. else
  19. return 0xF000000000000000ull | ( uint64( ub1 ) << 32 ) | ( uint64( iPaint ) << 16 ) | ( uint64( iDefIndex ) );
  20. }
  21. // Returns whether the itemID in question is really an encoded base item
  22. inline bool CombinedItemIdIsDefIndexAndPaint( uint64 ullItemId )
  23. {
  24. return ullItemId >= 0xF000000000000000ull;
  25. }
  26. // Extracts the definition index from an encoded itemID
  27. inline uint16 CombinedItemIdGetDefIndex( uint64 ullItemId )
  28. {
  29. return uint16( ullItemId );
  30. }
  31. // Extracts the paint index from an encoded itemID
  32. inline uint16 CombinedItemIdGetPaint( uint64 ullItemId )
  33. {
  34. return uint16( ullItemId >> 16 );
  35. }
  36. // Extracts the extra byte from an encoded itemID
  37. inline uint16 CombinedItemIdGetUB1( uint64 ullItemId )
  38. {
  39. return uint8( ullItemId >> 32 );
  40. }
  41. ///////////////////////////////////////////////////////////////////////////
  42. //
  43. // Tint ID manipulators
  44. //
  45. // Fomat of the TintID int32 value from low bits towards high bits:
  46. // low byte (TintID & 0xFF) = bucket containing HSV subspace definition
  47. // ((TintID >> 8)&0x7F): 7-bits indicating hue location from minhue(0) to maxhue(0x7F) in the HSV subspace
  48. // ((TintID >> 15)&0x7F): 7-bits indicating saturation location in hue-interpolated minsat(0) to maxsat(0x7F) range in the HSV subspace
  49. // ((TintID >> 22)&0x7F): 7-bits indicating value location in hue-interpolated minval(0) to maxval(0x7F) range in the HSV subspace
  50. // ((TintID >> 29)&0x7): 3-bits reserved (must be zero)
  51. //
  52. #if ECON_SPRAY_TINT_IDS_FLOAT_COLORSPACE
  53. inline uint32 CombinedTintIDMakeFromIDHSVf( uint8 unID, float fH, float fS, float fV )
  54. {
  55. return
  56. uint32( unID & 0xFF )
  57. | ( ( uint32( fH * 0x7F ) & 0x7F ) << ( 8 + 7 * 0 ) )
  58. | ( ( uint32( fS * 0x7F ) & 0x7F ) << ( 8 + 7 * 1 ) )
  59. | ( ( uint32( fV * 0x7F ) & 0x7F ) << ( 8 + 7 * 2 ) )
  60. ;
  61. }
  62. inline uint32 CombinedTintIDMakeFromIDHSVu( uint8 unID, uint32 fH, uint32 fS, uint32 fV )
  63. {
  64. return
  65. uint32( unID & 0xFF )
  66. | ( ( uint32( fH ) & 0x7F ) << ( 8 + 7 * 0 ) )
  67. | ( ( uint32( fS ) & 0x7F ) << ( 8 + 7 * 1 ) )
  68. | ( ( uint32( fV ) & 0x7F ) << ( 8 + 7 * 2 ) )
  69. ;
  70. }
  71. inline float CombinedTintIDGetHSVc( uint32 unTintID, int c )
  72. {
  73. return ( ( unTintID >> ( 8 + 7 * c ) ) & 0x7F ) / float( 0x7F );
  74. }
  75. #endif
  76. inline uint8 CombinedTintIDGetHSVID( uint32 unTintID )
  77. {
  78. return unTintID & 0xFF;
  79. }
  80. #endif // ECON_ITEM_VIEW_HELPERS_H