summaryrefslogtreecommitdiff
path: root/hammer/sprite.h
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /hammer/sprite.h
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'hammer/sprite.h')
-rw-r--r--hammer/sprite.h160
1 files changed, 160 insertions, 0 deletions
diff --git a/hammer/sprite.h b/hammer/sprite.h
new file mode 100644
index 0000000..ff63aae
--- /dev/null
+++ b/hammer/sprite.h
@@ -0,0 +1,160 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $Workfile: $
+// $Date: $
+// $NoKeywords: $
+//===========================================================================//
+
+#ifndef SPRITE_H
+#define SPRITE_H
+#pragma once
+
+#include "mathlib/mathlib.h"
+#include "materialsystem/imaterialsystem.h"
+
+class CTexture;
+class CMaterial;
+class IMaterialVar;
+class CRender;
+class CRender3D;
+
+
+// must match definition in modelgen.h
+enum synctype_t
+{
+ ST_SYNC=0,
+ ST_RAND
+};
+
+#define SPR_VP_PARALLEL_UPRIGHT 0
+#define SPR_FACING_UPRIGHT 1
+#define SPR_VP_PARALLEL 2
+#define SPR_ORIENTED 3
+#define SPR_VP_PARALLEL_ORIENTED 4
+
+#define SPR_NORMAL 0
+#define SPR_ADDITIVE 1
+#define SPR_INDEXALPHA 2
+#define SPR_ALPHATEST 3
+
+
+//-----------------------------------------------------------------------------
+// From engine\GL_MODEL.H:
+//-----------------------------------------------------------------------------
+
+class CSpriteModel
+{
+ public:
+
+ CSpriteModel(void);
+ ~CSpriteModel(void);
+
+ bool LoadSprite(const char *pszSpritePath);
+
+ int GetFrameCount(void);
+ int GetWidth() const;
+ int GetHeight() const;
+ int GetType() const;
+
+ void Bind( CRender* pRender, int frame );
+ void GetRect( float& left, float& up, float& right, float& down ) const;
+ void SetRenderMode( const int mode );
+
+ void SetMaterialPrimitiveType( const MaterialPrimitiveType_t type );
+ void SetOrigin( const Vector &v );
+ void GetOrigin( Vector &v );
+ void SetAngles( const QAngle& pfAngles );
+ void SetScale( const float fScale );
+ void SetInvert( const bool b );
+ inline void SetTextureExtent( Vector2D TexUL, Vector2D TexLR ) { m_TexUL = TexUL; m_TexLR = TexLR; }
+ inline void SetExtent( Vector2D UL, Vector2D LR ) { m_UL = UL; m_LR = LR; }
+ void DrawSprite3D( CRender3D *pRender, unsigned char color[3] );
+
+ protected:
+ void GetSpriteAxes(QAngle& Angles, int type, Vector& forward, Vector& right, Vector& up, Vector& ViewUp, Vector& ViewRight, Vector& ViewForward);
+
+ Vector m_Origin;
+ QAngle m_Angles;
+ float m_fScale;
+ MaterialPrimitiveType_t m_MaterialPrimitiveType;
+
+ CMaterial* m_pMaterial;
+ IMaterialVar* m_pFrameVar;
+ IMaterialVar* m_pRenderModeVar;
+ int m_NumFrames;
+ int m_Type;
+ int m_Width;
+ int m_Height;
+ bool m_bInvert;
+
+ Vector2D m_TexUL, m_TexLR;
+ Vector2D m_UL, m_LR;
+};
+
+
+//-----------------------------------------------------------------------------
+// inline methods
+//-----------------------------------------------------------------------------
+
+inline int CSpriteModel::GetWidth() const
+{
+ return m_Width;
+}
+
+inline int CSpriteModel::GetHeight() const
+{
+ return m_Height;
+}
+
+inline int CSpriteModel::GetType() const
+{
+ return m_Type;
+}
+
+inline void CSpriteModel::GetRect( float& left, float& up, float& right, float& down ) const
+{
+ left = m_UL.x;
+ right = m_LR.x;
+ up = m_UL.y;
+ down = m_LR.y;
+}
+
+//-----------------------------------------------------------------------------
+// Sprite cache
+//-----------------------------------------------------------------------------
+
+struct SpriteCache_t
+{
+ CSpriteModel *pSprite;
+ char *pszPath;
+ int nRefCount;
+};
+
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+#define SPRITE_CACHE_SIZE 1024
+
+class CSpriteCache
+{
+ public:
+
+ static CSpriteModel *CreateSprite(const char *pszSpritePath);
+ static void AddRef(CSpriteModel *pSprite);
+ static void Release(CSpriteModel *pSprite);
+
+ protected:
+
+ static bool AddSprite(CSpriteModel *pSprite, const char *pszSpritePath);
+ static void RemoveSprite(CSpriteModel *pSprite);
+
+ static SpriteCache_t m_Cache[SPRITE_CACHE_SIZE];
+ static int m_nItems;
+};
+
+
+#endif // SPRITE_H
+