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.

122 lines
3.5 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================//
  4. #ifndef PAINTABLE_ENTITY_BASE_H
  5. #define PAINTABLE_ENTITY_BASE_H
  6. #ifndef CLIENT_DLL
  7. #include "paint_database.h"
  8. #endif // ifndef CLIENT_DLL
  9. #include "paint_color_manager.h"
  10. abstract_class IPaintableEntity
  11. {
  12. public:
  13. virtual ~IPaintableEntity() {}
  14. virtual PaintPowerType GetPaintPowerAtPoint( const Vector& contact ) const = 0;
  15. virtual void Paint( PaintPowerType type, const Vector& worldContactPt ) = 0;
  16. virtual void CleansePaint() = 0;
  17. virtual PaintPowerType GetPaintedPower() const = 0;
  18. };
  19. template< typename BaseEntityType >
  20. class CPaintableEntity : public BaseEntityType, public IPaintableEntity
  21. {
  22. DECLARE_CLASS( CPaintableEntity, BaseEntityType );
  23. DECLARE_DATADESC();
  24. static const datamap_t DataMapInit();
  25. public:
  26. CPaintableEntity();
  27. virtual ~CPaintableEntity();
  28. virtual PaintPowerType GetPaintPowerAtPoint( const Vector& worldContactPt ) const;
  29. virtual void Paint( PaintPowerType type, const Vector& worldContactPt );
  30. virtual void CleansePaint();
  31. virtual PaintPowerType GetPaintedPower() const;
  32. private:
  33. PaintPowerType m_iPaintPower;
  34. };
  35. // OMFG HACK: Define the data description table. The current macros don't work with templatized classes.
  36. // OMFG TODO: Write a generic macro to work with templatized classes.
  37. template< typename BaseEntityType >
  38. datamap_t CPaintableEntity<BaseEntityType>::m_DataMap = CPaintableEntity<BaseEntityType>::DataMapInit();
  39. template< typename BaseEntityType >
  40. datamap_t* CPaintableEntity<BaseEntityType>::GetDataDescMap()
  41. {
  42. return &m_DataMap;
  43. }
  44. template< typename BaseEntityType >
  45. datamap_t* CPaintableEntity<BaseEntityType>::GetBaseMap()
  46. {
  47. datamap_t *pResult;
  48. DataMapAccess((BaseClass *)NULL, &pResult);
  49. return pResult;
  50. }
  51. const char PAINTABLE_ENTITY_USER_DATA_CLASS_NAME[] = "PaintableEntity";
  52. template< typename BaseEntityType >
  53. const datamap_t CPaintableEntity<BaseEntityType>::DataMapInit()
  54. {
  55. typedef CPaintableEntity<BaseEntityType> classNameTypedef;
  56. static CDatadescGeneratedNameHolder nameHolder(PAINTABLE_ENTITY_USER_DATA_CLASS_NAME);
  57. static typedescription_t dataDesc[] =
  58. {
  59. DEFINE_FIELD( m_iPaintPower, FIELD_INTEGER )
  60. };
  61. datamap_t dataMap = { dataDesc, SIZE_OF_ARRAY(dataDesc), PAINTABLE_ENTITY_USER_DATA_CLASS_NAME, CPaintableEntity<BaseEntityType>::GetBaseMap() };
  62. return dataMap;
  63. }
  64. template< typename BaseEntityType >
  65. CPaintableEntity< BaseEntityType >::CPaintableEntity()
  66. : m_iPaintPower( NO_POWER )
  67. {
  68. }
  69. template< typename BaseEntityType >
  70. CPaintableEntity< BaseEntityType >::~CPaintableEntity()
  71. {
  72. #ifndef CLIENT_DLL
  73. //PaintDatabase.RemovePaintedEntity( this );
  74. #endif // ifndef CLIENT_DLL
  75. }
  76. template< typename BaseEntityType >
  77. PaintPowerType CPaintableEntity< BaseEntityType >::GetPaintPowerAtPoint( const Vector& worldContactPt ) const
  78. {
  79. return m_iPaintPower;
  80. }
  81. template< typename BaseEntityType >
  82. void CPaintableEntity< BaseEntityType >::Paint( PaintPowerType type, const Vector& worldContactPt )
  83. {
  84. m_iPaintPower = type;
  85. }
  86. template< typename BaseEntityType >
  87. void CPaintableEntity< BaseEntityType >::CleansePaint()
  88. {
  89. this->Paint( NO_POWER, vec3_origin );
  90. }
  91. template< typename BaseEntityType >
  92. PaintPowerType CPaintableEntity< BaseEntityType >::GetPaintedPower() const
  93. {
  94. return m_iPaintPower;
  95. }
  96. #endif //PAINTABLE_ENTITY_BASE_H