11 |
cycrow |
1 |
// TextureFile.h: interface for the CTextureFile class.
|
|
|
2 |
//
|
|
|
3 |
//////////////////////////////////////////////////////////////////////
|
|
|
4 |
|
|
|
5 |
#if !defined(AFX_TEXTUREFILE_H__07FEFD54_9847_4F3E_9BF1_20F80C6B5EA4__INCLUDED_)
|
|
|
6 |
#define AFX_TEXTUREFILE_H__07FEFD54_9847_4F3E_9BF1_20F80C6B5EA4__INCLUDED_
|
|
|
7 |
|
|
|
8 |
#if _MSC_VER > 1000
|
|
|
9 |
#pragma once
|
|
|
10 |
#endif // _MSC_VER > 1000
|
|
|
11 |
|
|
|
12 |
#define TEXTUREFILE_VERSION 1.20
|
|
|
13 |
|
|
|
14 |
#define DIRECT3D
|
|
|
15 |
|
|
|
16 |
enum {TEXTURELOAD_OK, TEXTURELOAD_NOFILE, TEXTURELOAD_INVALIDFORMAT, TEXTURELOAD_SIZEMISMATCH};
|
|
|
17 |
|
|
|
18 |
#include <Utils/String.h>
|
|
|
19 |
|
|
|
20 |
typedef struct {
|
|
|
21 |
unsigned char r;
|
|
|
22 |
unsigned char g;
|
|
|
23 |
unsigned char b;
|
|
|
24 |
unsigned char alpha;
|
|
|
25 |
} STextureData;
|
|
|
26 |
|
|
|
27 |
typedef struct {
|
|
|
28 |
int width;
|
|
|
29 |
int height;
|
|
|
30 |
int num;
|
|
|
31 |
} STextureSize;
|
|
|
32 |
|
|
|
33 |
typedef struct {
|
|
|
34 |
unsigned int cols;
|
|
|
35 |
unsigned int rows;
|
|
|
36 |
unsigned int x;
|
|
|
37 |
unsigned int y;
|
|
|
38 |
} STextureFrames;
|
|
|
39 |
|
|
|
40 |
typedef struct {
|
|
|
41 |
unsigned int minx;
|
|
|
42 |
unsigned int maxx;
|
|
|
43 |
unsigned int miny;
|
|
|
44 |
unsigned int maxy;
|
|
|
45 |
} SFrameBounds;
|
|
|
46 |
|
|
|
47 |
typedef struct {
|
|
|
48 |
char *name;
|
|
|
49 |
int delay;
|
|
|
50 |
int amt;
|
|
|
51 |
int *frames;
|
|
|
52 |
bool cont;
|
|
|
53 |
bool remove;
|
|
|
54 |
} SAnimation;
|
|
|
55 |
|
|
|
56 |
typedef struct {
|
|
|
57 |
SAnimation *anim;
|
|
|
58 |
int curframe;
|
|
|
59 |
int delay;
|
|
|
60 |
bool reverse;
|
|
|
61 |
} SPlayAnimation;
|
|
|
62 |
|
|
|
63 |
//#include "Visualisation.h"
|
|
|
64 |
#include <d3dx9.h>
|
|
|
65 |
|
|
|
66 |
class CTextureFile
|
|
|
67 |
{
|
|
|
68 |
public:
|
|
|
69 |
static std::string GetErrorText ( int error );
|
|
|
70 |
|
|
|
71 |
public:
|
|
|
72 |
bool CheckAlpha ( int x, int y, int frame, bool inccollisionmap = true );
|
|
|
73 |
int GetFrameHeight();
|
|
|
74 |
int GetFrameWidth();
|
|
|
75 |
void SetEditor();
|
|
|
76 |
SAnimation * GetAnimation ( int num );
|
|
|
77 |
SAnimation * FindAnimation ( const char *search );
|
|
|
78 |
int GetAnimationNum();
|
|
|
79 |
SAnimation * AddNewAnimation ( const char *name );
|
|
|
80 |
bool GetAlphaMap ( int *red, int *green, int *blue );
|
|
|
81 |
void SetAlphaMap ( int red, int green, int blue );
|
|
|
82 |
bool GetAlphaMap();
|
|
|
83 |
void EnableAlphamap ( bool enable = true );
|
|
|
84 |
void SetFrames ( int rows, int cols );
|
|
|
85 |
const STextureFrames * GetFrames();
|
|
|
86 |
void SetFrameSize ( int width, int height );
|
|
|
87 |
bool Load ( const char *filename );
|
|
|
88 |
bool Save ( const char *filename );
|
|
|
89 |
bool SaveTGA ( const char *filename );
|
|
|
90 |
|
|
|
91 |
int GetWidth() { return m_width; }
|
|
|
92 |
int GetHeight() { return m_height; }
|
|
|
93 |
|
|
|
94 |
int GetMinAlphaX ( int frame ) { return m_framebounds[frame].minx; }
|
|
|
95 |
int GetMaxAlphaX ( int frame ) { return m_framebounds[frame].maxx; }
|
|
|
96 |
int GetMinAlphaY ( int frame ) { return m_framebounds[frame].miny; }
|
|
|
97 |
int GetMaxAlphaY ( int frame ) { return m_framebounds[frame].maxy; }
|
|
|
98 |
|
|
|
99 |
#ifdef DIRECT3D
|
|
|
100 |
LPDIRECT3DTEXTURE9 CreateTexture ( LPDIRECT3DDEVICE9 device );
|
|
|
101 |
LPDIRECT3DTEXTURE9 CreateCollisionTexture(LPDIRECT3DDEVICE9 device, DWORD nRed, DWORD nGreen, DWORD nBlue);
|
|
|
102 |
#endif //DIRECT3D
|
|
|
103 |
|
|
|
104 |
int LoadTextureTGA(const char *filename );
|
|
|
105 |
int LoadCollisionTGA(const char *filename );
|
|
|
106 |
|
|
|
107 |
bool CollisionMap () { return m_collisionMap; }
|
|
|
108 |
|
|
|
109 |
void WipeCollisionMap () { if ( m_collisionData ) delete [] m_collisionData; m_collisionMap = false; m_collisionData = NULL; }
|
|
|
110 |
|
|
|
111 |
CTextureFile ( bool editor = false );
|
|
|
112 |
|
|
|
113 |
virtual ~CTextureFile();
|
|
|
114 |
|
|
|
115 |
private:
|
|
|
116 |
int ComputeMinAlphaX ( int frame );
|
|
|
117 |
int ComputeMaxAlphaX ( int frame );
|
|
|
118 |
int ComputeMinAlphaY ( int frame );
|
|
|
119 |
int ComputeMaxAlphaY ( int frame );
|
|
|
120 |
|
|
|
121 |
typedef struct {
|
|
|
122 |
bool alpha;
|
|
|
123 |
int alphamap[3];
|
|
|
124 |
bool frames;
|
|
|
125 |
int height;
|
|
|
126 |
int width;
|
|
|
127 |
} SFileHeader;
|
|
|
128 |
|
|
|
129 |
STextureData *m_data;
|
|
|
130 |
STextureFrames m_frames;
|
|
|
131 |
|
|
|
132 |
int m_numData; // number of entries in array (width * height)
|
|
|
133 |
int m_width; // width of texture file
|
|
|
134 |
int m_height; // height of texture file
|
|
|
135 |
bool m_alpha;
|
|
|
136 |
int m_alphamap[3];
|
|
|
137 |
|
|
|
138 |
int m_numframes;
|
|
|
139 |
SFrameBounds *m_framebounds;
|
|
|
140 |
|
|
|
141 |
void ClearHeader ( SFileHeader *header );
|
|
|
142 |
STextureData *LoadTGA(const char *filename, STextureSize *tsize, int *error );
|
|
|
143 |
STextureData *CreateData(int width, int height, STextureSize *size );
|
|
|
144 |
|
|
|
145 |
SAnimation *m_anim;
|
|
|
146 |
int m_animNum;
|
|
|
147 |
|
|
|
148 |
bool m_editor;
|
|
|
149 |
|
|
|
150 |
bool m_collisionMap;
|
|
|
151 |
bool *m_collisionData;
|
|
|
152 |
};
|
|
|
153 |
|
|
|
154 |
void IncAnimationFrame ( SPlayAnimation *anim, int *times = NULL );
|
|
|
155 |
void IncAnimationFrame ( SPlayAnimation *anim, bool endstop, int *times = NULL );
|
|
|
156 |
void DecAnimationFrame ( SPlayAnimation *anim, int *times = NULL );
|
|
|
157 |
void DecAnimationFrame ( SPlayAnimation *anim, bool endstop, int *times = NULL );
|
|
|
158 |
void DoAnimation ( SPlayAnimation *anim, bool endstopinc, bool endstopdec, int *times = NULL );
|
|
|
159 |
void ResetAnimation ( SPlayAnimation *anim );
|
|
|
160 |
|
|
|
161 |
#endif // !defined(AFX_TEXTUREFILE_H__07FEFD54_9847_4F3E_9BF1_20F80C6B5EA4__INCLUDED_)
|