arsa  2.7
cdxsprite.h
Go to the documentation of this file.
1 // $Source: /cvsroot/cdx/cdx3.0/src/cdx/cdxsprite.h,v $
3 // $Author: mindcry $
4 //
5 // $Log: cdxsprite.h,v $
6 // Revision 1.11 2001/01/11 14:38:49 mindcry
7 // Added CountFrames, which tells you the number of frames in a CDXSprite.
8 //
9 // Revision 1.10 2000/11/29 21:37:47 wasteland
10 // Changed m_angle from an int to a double to match up with what is passed to CDXSurface::RotoZoom
11 //
12 // Revision 1.9 2000/09/30 19:30:08 istan
13 // Moved private vars to be protected instead for subclasses.
14 //
15 // Revision 1.8 2000/09/07 05:06:52 istan
16 // Added default value for MemoryType in Create()
17 //
18 // Revision 1.7 2000/05/31 17:47:55 hebertjo
19 // Added some Accessor functions
20 //
21 // Revision 1.6 2000/05/12 22:48:02 hebertjo
22 // I added RotoZoomimg to CDXSurface and CDXSprite. I ripped this code from NukeDX.
23 // IT works and as been debuged by them but it is slow. CDX definitely needed this
24 // feature and it did not take long to CDX'ize their code so I added it. I plan
25 // on changing this to a faster implementation once I finish it.
26 //
27 // Revision 1.5 2000/05/10 23:29:26 hebertjo
28 // Cleaned up all the old code that was commented out. Version 3.0 is getting
29 // very close to release.
30 //
31 // Revision 1.4 2000/05/09 01:22:06 hebertjo
32 // Moved the CDXBLT_XXXX #defines to cdxsurface.h. This is where they belong, thanks
33 // to who ever pointed that out.
34 //
35 // Revision 1.3 2000/05/01 17:06:26 hebertjo
36 // Many small changes. Fixed a few problems identified by BoundsChecker.
37 // Removed some old code that was commented out. Cleaned up the look of
38 // some of the code.
39 //
40 // Revision 1.2 2000/04/26 18:45:43 hebertjo
41 // Made many small changes to fix numerous bugs and some enhancements.
42 //
43 // Revision 1.1.1.1 2000/04/22 16:12:01 hebertjo
44 // Initial checkin of v3.0 to SourceForge CVS.
45 //
46 // Revision 2.10 2000/03/20 21:11:23 wasteland
47 // Added methods to get the Position and Velocity
48 //
49 // Revision 2.9 2000/01/21 01:34:25 jhebert
50 // Changed m_Tile to GetTile().
51 //
52 // Revision 2.8 2000/01/13 23:43:17 jhebert
53 // First checkin for v3.0. No major changes, added some safety chacks and all
54 // the functions have headers.
55 //
56 //
57 //
58 // $Revision: 1.11 $
60 #ifndef CDXSPRITE_H
61 #define CDXSPRITE_H
62 
63 #include "cdx.h"
64 
65 // push avoid dll warning
66 #ifdef __WIN32__
67 # pragma warning( push )
68 # pragma warning( disable: 4251 )
69 #endif
70 
80 {
81 public:
82  static bool saveCache(CDXSurface* tile, bool overwrite = true );
83  static CDXSurface* loadCache(const irr::io::path& filename_ext );
84 
85  CDXSprite(void);
86  //CDXSprite(const char* Filename, int w, int h, int num=0);
87  //CDXSprite(const char* Filename, int num = 0 );
88 
90  CDXSprite(void* pScreen, const char* Filename, int w, int h, int num, int memoryType = 0);
91  virtual ~CDXSprite(void);
92 
93  virtual int Create(const char* Filename, int w, int h, int num=0);
94  virtual int Create(const char* Filename, int num=0);
95  virtual bool Create( int Width, int Height, int Bpp, DWORD Flags );
96  virtual bool CreateSameSrc( CDXSurface*src, int Width, int Height, DWORD Flags );
97  virtual void Destroy( );
98  virtual void SetColorKey(const irr::core::vector2di& pos = irr::core::vector2di(0, 0));
99  virtual void SetColorKey(const CDX_Color& color);
100 
101  virtual void SetAlpha( WORD alpha ) { return m_Pal.setAlpha(alpha); }
102  virtual void SetShadow( bool Enable, const CDX_Color& color ) { }
103  virtual void SetPal( const CDX_Color& pal ) { m_Pal = pal; }
104 
105  virtual void SetOrder(irr::u32 order) { m_Order = order; }
106  virtual irr::u32 GetOrder() const { return m_Order; }
107  virtual void SetPos(int pX, int pY) { m_PosX = pX; m_PosY = pY; }
108  virtual void SetPosX(int pX) { m_PosX = pX; }
109  virtual void SetPosY(int pY) { m_PosY = pY; }
110  virtual void GetPos(int &pX, int &pY) const { pX = m_PosX; pY = m_PosY; }
111  virtual int GetPosX(void) const { return m_PosX; }
112  virtual int GetPosY(void) const { return m_PosY; }
113  virtual void SetVel(int vX, int vY) { m_VelX = vX; m_VelY = vY; }
114  virtual void SetVelX(int vX) { m_VelX = vX; }
115  virtual void SetVelY(int vY) { m_VelY = vY; }
116  virtual void GetVel(int &vX, int &vY) const { vX = m_VelX; vY = m_VelY; }
117  virtual int GetVelX(void) const { return m_VelX; }
118  virtual int GetVelY(void) const { return m_VelY; }
119  virtual void SetFrame(int frame) { m_Frame = frame; }
120  virtual int GetFrame(void) { return m_Frame; }
121  //int CountFrames(void) { return m_Tile->GetBlockCount(); }
122  virtual void SetDelay(int delay) { m_Delay = delay; }
123  virtual int GetDelay(void) {return m_Delay;}
124  virtual void SetState(int state) { m_State = state; }
125  virtual int GetState(void) {return m_State;}
126  virtual void SetType(int type) { m_Type = type; }
127  virtual int GetType(void) {return m_Type;}
128  virtual void SetAngle(double angle) { m_Angle = angle; }
129  virtual double GetAngle(void) {return m_Angle;}
130  virtual void SetScale(float scale) { m_ScaleFactor = scale; }
131  virtual float GetScale(void) {return m_ScaleFactor;}
132  virtual void SetShadowValue(WORD Shade) { m_ShadowValue = Shade; }
133  virtual WORD GetShadowValue(void) { return m_ShadowValue; }
134  virtual void SetAlphaValue(WORD Shade) { m_AlphaValue = Shade; }
135  virtual WORD GetAlphaValue(void) { return m_AlphaValue; }
136  virtual void SetStretchWidth(WORD width) { m_StretchedWidth = width; }
137  virtual WORD GetStretchWidth(void) { return m_StretchedWidth; }
138  virtual void SetStretchHeight(WORD height) { m_StretchedHeight = height; }
139  virtual WORD GetStretchHeight(void) { return m_StretchedHeight; }
140  virtual CDXSurface* GetTile(void) const { return m_Tile; }
141  // see E_KEY_STATE in CARSAInput.h
142  virtual bool SpriteHitTouch( int touch_flag, int ext = 10);
143  virtual bool SpriteHit( int x, int y, int ext = 10 );
144  virtual bool SpriteHit(CDXSprite* pSprite);
145  virtual bool SpriteHitPixel(CDXSprite* pSprite);
146  virtual bool IsFlipped(void) { return m_Flipped; }
147  virtual int Draw(CDXSurface* lpCDXS = 0, DWORD ScrnWorldX = 0, DWORD ScrnWorldY = 0, WORD BltType = 0, PRECT rect = 0, CDX_Color* Pal = 0, bool mem_alloc = false );
148  virtual int Draw(PRECT rect, CDX_Color* Pal = 0, bool mem_alloc = false);
149  virtual int GetBlockWidth() { return m_BlockWidth; }
150  virtual int GetBlockHeight() { return m_BlockHeight; }
151  virtual int GetBlockCount() { return m_BlockNum; }
152  virtual int GetWidth() { return GetBlockWidth(); }
153  virtual int GetHeight() { return GetBlockHeight(); }
154  virtual bool GetBoundingBox( PRECT out_rect );
155  virtual const CDX_Color& GetPal() const { return m_Pal; }
156  virtual const char* GetName() const;
157  virtual bool isOk() const { return m_Tile ? true : false; }
158 
159  //===========================//
160  // clone
161  //===========================//
162  virtual CDXSprite* clone(void); // MUST delete
163  virtual void clone(CDXSprite* dest);
164 
165  void setDebug(int debug) { m_Debug = debug; }
166  int getDebug() const { return m_Debug; }
167 
168 protected:
169  virtual void Init(void);
170 
171 // MichaelR: Did on request so subclasses would be able to access these variables
172 // instead of having to use the slower accessor function, but of course at their own
173 // risk of them changing in later revs.
174 //protected:
175 public:
176  int m_PosX; // The sprite's X position
177  int m_PosY; // The sprite's Y position
178  int m_PosZ; // The sprite's Z position
179  int m_VelX; // The sprite's X velocity
180  int m_VelY; // The sprite's Y velocity
181  int m_Frame; // The current frame
182  int m_Delay; // Used for game timing, the time till the next frame
183  int m_State; // User defined state. Walking, jumping, etc
184  int m_Type; // User defined type. Health, weapon, etc
185  double m_Angle; // The sprite's angle of rotation
186  float m_ScaleFactor; // The amount by which to scale the sprite if Drawing with CDXBLT_XXXSCALED
187  bool m_Flipped; // Is the sprite flipped?
188  LONG m_ShadowOffsetX; // Amount to offset the shadow in the X direction
189  LONG m_ShadowOffsetY; // Amount to offset the shadow in the Y direction
190  WORD m_ShadowValue; // Alpha value used in drawing the shadow 0-256
191  WORD m_AlphaValue; // Alpha value used when alpha blending 0-256
192  bool m_TileCreated; // Used internal to determine if the class created the CDXTile object or not
193  WORD m_StretchedHeight; // Used to define the height of the stretched sprite
194  WORD m_StretchedWidth; // Used to define the width of the stretched sprite
195  CDXSurface* m_Tile; // irr::video::ITexture*, A CDXTile pointer to the sprite's bitmap data
196  int m_BlockWidth; // The width of one tile, in pixels
197  int m_BlockHeight; // The height of one tile, in pixels
198  int m_BlockNum; // The number of tiles in the bitmap file
199 
202  int m_Debug;
203 
207 };
208 
209 // pop avoid dll warning
210 #ifdef __WIN32__
211 # pragma warning( pop )
212 #endif
213 
214 #endif
int m_VelY
Definition: cdxsprite.h:180
virtual void SetAngle(double angle)
Definition: cdxsprite.h:128
GLenum GLenum GLenum GLenum GLenum scale
int m_BlockWidth
Definition: cdxsprite.h:196
virtual void SetAlpha(WORD alpha)
Definition: cdxsprite.h:101
virtual int GetVelY(void) const
Definition: cdxsprite.h:118
Template implementation of the IMeshBuffer interface.
Definition: CMeshBuffer.h:17
virtual void SetShadowValue(WORD Shade)
Definition: cdxsprite.h:132
virtual void SetPosY(int pY)
Definition: cdxsprite.h:109
GLuint num
virtual void SetState(int state)
Definition: cdxsprite.h:124
int m_Type
Definition: cdxsprite.h:184
int m_PosY
Definition: cdxsprite.h:177
void setDebug(int debug)
Definition: cdxsprite.h:165
virtual void SetVelX(int vX)
Definition: cdxsprite.h:114
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
virtual WORD GetShadowValue(void)
Definition: cdxsprite.h:133
GLfloat GLfloat GLfloat GLfloat h
virtual void SetStretchWidth(WORD width)
Definition: cdxsprite.h:136
virtual float GetScale(void)
Definition: cdxsprite.h:131
virtual WORD GetStretchWidth(void)
Definition: cdxsprite.h:137
virtual int GetVelX(void) const
Definition: cdxsprite.h:117
virtual int GetBlockCount()
Definition: cdxsprite.h:151
virtual void SetFrame(int frame)
Definition: cdxsprite.h:119
int getDebug() const
Definition: cdxsprite.h:166
irr::scene::SMeshBuffer m_Mb
Definition: cdxsprite.h:206
WORD m_AlphaValue
Definition: cdxsprite.h:191
CDXSurface * m_Tile
Definition: cdxsprite.h:195
GLfixed GLfixed GLint GLint order
#define CDX_Color
2015_7_21 add type for cdx port
Definition: cdx.h:33
irr::u32 m_Order
Definition: cdxsprite.h:204
int m_Frame
Definition: cdxsprite.h:181
bool m_FromCache
Definition: cdxsprite.h:201
virtual void SetVelY(int vY)
Definition: cdxsprite.h:115
virtual int GetState(void)
Definition: cdxsprite.h:125
GLfloat GLfloat GLfloat alpha
LONG m_ShadowOffsetY
Definition: cdxsprite.h:189
int m_BlockHeight
Definition: cdxsprite.h:197
virtual CDXSurface * GetTile(void) const
Definition: cdxsprite.h:140
virtual void SetScale(float scale)
Definition: cdxsprite.h:130
#define CDXSurface
Definition: cdx.h:34
virtual int GetHeight()
Definition: cdxsprite.h:153
bool m_TileCreated
Definition: cdxsprite.h:192
WORD m_StretchedWidth
Definition: cdxsprite.h:194
virtual bool IsFlipped(void)
Definition: cdxsprite.h:146
virtual double GetAngle(void)
Definition: cdxsprite.h:129
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
#define LONG
Definition: cdx.h:164
double m_Angle
Definition: cdxsprite.h:185
virtual WORD GetStretchHeight(void)
Definition: cdxsprite.h:139
virtual int GetWidth()
Definition: cdxsprite.h:152
virtual void GetVel(int &vX, int &vY) const
Definition: cdxsprite.h:116
virtual void SetPal(const CDX_Color &pal)
Definition: cdxsprite.h:103
int m_Debug
Definition: cdxsprite.h:202
WORD m_StretchedHeight
Definition: cdxsprite.h:193
virtual bool isOk() const
Definition: cdxsprite.h:157
int m_PosZ
Definition: cdxsprite.h:178
virtual void SetAlphaValue(WORD Shade)
Definition: cdxsprite.h:134
WORD m_ShadowValue
Definition: cdxsprite.h:190
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
virtual irr::u32 GetOrder() const
Definition: cdxsprite.h:106
virtual void SetType(int type)
Definition: cdxsprite.h:126
virtual void SetDelay(int delay)
Definition: cdxsprite.h:122
virtual int GetBlockWidth()
Definition: cdxsprite.h:149
bool m_Flipped
Definition: cdxsprite.h:187
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition: matrix4.h:45
virtual void GetPos(int &pX, int &pY) const
Definition: cdxsprite.h:110
float m_ScaleFactor
Definition: cdxsprite.h:186
LONG m_ShadowOffsetX
Definition: cdxsprite.h:188
virtual void SetPosX(int pX)
Definition: cdxsprite.h:108
int m_State
Definition: cdxsprite.h:183
#define ARSA_API
virtual int GetBlockHeight()
Definition: cdxsprite.h:150
int m_PosX
Definition: cdxsprite.h:176
virtual WORD GetAlphaValue(void)
Definition: cdxsprite.h:135
virtual void SetPos(int pX, int pY)
Definition: cdxsprite.h:107
2d vector template class with lots of operators and methods.
Definition: dimension2d.h:16
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
virtual void SetShadow(bool Enable, const CDX_Color &color)
Definition: cdxsprite.h:102
irr::core::matrix4 m_World
Definition: cdxsprite.h:205
GLuint color
virtual void SetOrder(irr::u32 order)
Definition: cdxsprite.h:105
GLfloat angle
int m_Delay
Definition: cdxsprite.h:182
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
CDX_Color m_Pal
Definition: cdxsprite.h:200
#define WORD
Definition: cdx.h:158
Definition: cdx.h:122
virtual void SetStretchHeight(WORD height)
Definition: cdxsprite.h:138
GLubyte GLubyte GLubyte GLubyte w
int m_VelX
Definition: cdxsprite.h:179
virtual void SetVel(int vX, int vY)
Definition: cdxsprite.h:113
virtual int GetFrame(void)
Definition: cdxsprite.h:120
GLenum src
virtual int GetPosY(void) const
Definition: cdxsprite.h:112
virtual int GetPosX(void) const
Definition: cdxsprite.h:111
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
virtual int GetDelay(void)
Definition: cdxsprite.h:123
virtual const CDX_Color & GetPal() const
Definition: cdxsprite.h:155
int m_BlockNum
Definition: cdxsprite.h:198
#define DWORD
Definition: cdx.h:162
virtual int GetType(void)
Definition: cdxsprite.h:127