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.

160 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #ifndef SPRITE_H
  10. #define SPRITE_H
  11. #pragma once
  12. #include "mathlib/mathlib.h"
  13. #include "materialsystem/imaterialsystem.h"
  14. class CTexture;
  15. class CMaterial;
  16. class IMaterialVar;
  17. class CRender;
  18. class CRender3D;
  19. // must match definition in modelgen.h
  20. enum synctype_t
  21. {
  22. ST_SYNC=0,
  23. ST_RAND
  24. };
  25. #define SPR_VP_PARALLEL_UPRIGHT 0
  26. #define SPR_FACING_UPRIGHT 1
  27. #define SPR_VP_PARALLEL 2
  28. #define SPR_ORIENTED 3
  29. #define SPR_VP_PARALLEL_ORIENTED 4
  30. #define SPR_NORMAL 0
  31. #define SPR_ADDITIVE 1
  32. #define SPR_INDEXALPHA 2
  33. #define SPR_ALPHATEST 3
  34. //-----------------------------------------------------------------------------
  35. // From engine\GL_MODEL.H:
  36. //-----------------------------------------------------------------------------
  37. class CSpriteModel
  38. {
  39. public:
  40. CSpriteModel(void);
  41. ~CSpriteModel(void);
  42. bool LoadSprite(const char *pszSpritePath);
  43. int GetFrameCount(void);
  44. int GetWidth() const;
  45. int GetHeight() const;
  46. int GetType() const;
  47. void Bind( CRender* pRender, int frame );
  48. void GetRect( float& left, float& up, float& right, float& down ) const;
  49. void SetRenderMode( const int mode );
  50. void SetMaterialPrimitiveType( const MaterialPrimitiveType_t type );
  51. void SetOrigin( const Vector &v );
  52. void GetOrigin( Vector &v );
  53. void SetAngles( const QAngle& pfAngles );
  54. void SetScale( const float fScale );
  55. void SetInvert( const bool b );
  56. inline void SetTextureExtent( Vector2D TexUL, Vector2D TexLR ) { m_TexUL = TexUL; m_TexLR = TexLR; }
  57. inline void SetExtent( Vector2D UL, Vector2D LR ) { m_UL = UL; m_LR = LR; }
  58. void DrawSprite3D( CRender3D *pRender, unsigned char color[3] );
  59. protected:
  60. void GetSpriteAxes(QAngle& Angles, int type, Vector& forward, Vector& right, Vector& up, Vector& ViewUp, Vector& ViewRight, Vector& ViewForward);
  61. Vector m_Origin;
  62. QAngle m_Angles;
  63. float m_fScale;
  64. MaterialPrimitiveType_t m_MaterialPrimitiveType;
  65. CMaterial* m_pMaterial;
  66. IMaterialVar* m_pFrameVar;
  67. IMaterialVar* m_pRenderModeVar;
  68. int m_NumFrames;
  69. int m_Type;
  70. int m_Width;
  71. int m_Height;
  72. bool m_bInvert;
  73. Vector2D m_TexUL, m_TexLR;
  74. Vector2D m_UL, m_LR;
  75. };
  76. //-----------------------------------------------------------------------------
  77. // inline methods
  78. //-----------------------------------------------------------------------------
  79. inline int CSpriteModel::GetWidth() const
  80. {
  81. return m_Width;
  82. }
  83. inline int CSpriteModel::GetHeight() const
  84. {
  85. return m_Height;
  86. }
  87. inline int CSpriteModel::GetType() const
  88. {
  89. return m_Type;
  90. }
  91. inline void CSpriteModel::GetRect( float& left, float& up, float& right, float& down ) const
  92. {
  93. left = m_UL.x;
  94. right = m_LR.x;
  95. up = m_UL.y;
  96. down = m_LR.y;
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Sprite cache
  100. //-----------------------------------------------------------------------------
  101. struct SpriteCache_t
  102. {
  103. CSpriteModel *pSprite;
  104. char *pszPath;
  105. int nRefCount;
  106. };
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. //-----------------------------------------------------------------------------
  110. #define SPRITE_CACHE_SIZE 1024
  111. class CSpriteCache
  112. {
  113. public:
  114. static CSpriteModel *CreateSprite(const char *pszSpritePath);
  115. static void AddRef(CSpriteModel *pSprite);
  116. static void Release(CSpriteModel *pSprite);
  117. protected:
  118. static bool AddSprite(CSpriteModel *pSprite, const char *pszSpritePath);
  119. static void RemoveSprite(CSpriteModel *pSprite);
  120. static SpriteCache_t m_Cache[SPRITE_CACHE_SIZE];
  121. static int m_nItems;
  122. };
  123. #endif // SPRITE_H