1 /*
2  * OpenBOR - http://www.chronocrash.com
3  * -----------------------------------------------------------------------
4  * All rights reserved, see LICENSE in OpenBOR root for details.
5  *
6  * Copyright (c) 2004 - 2014 OpenBOR Team
7  */
8 
9 #ifndef GAMELIB_TYPES_H
10 #define GAMELIB_TYPES_H
11 
12 #ifndef TRANSPARENT_IDX
13 #define		TRANSPARENT_IDX		0x00
14 #endif
15 
16 #define	ANYNUMBER		 2
17 
18 #if SYMBIAN
19 #pragma pack(4)
20 #elif SDL
21 #pragma pack(push,4)
22 #endif
23 
24 #define PIXEL_8          0
25 #define PIXEL_x8         1
26 #define PIXEL_16         2
27 #define PIXEL_32         4
28 
29 
30 #define BLEND_SCREEN     0
31 #define BLEND_MULTIPLY   1
32 #define BLEND_OVERLAY    2
33 #define BLEND_HARDLIGHT  3
34 #define BLEND_DODGE      4
35 #define BLEND_HALF       5
36 
37 #define MAX_BLENDINGS    6
38 
39 /*
40 #define _copy24bitp(pd, ps) (pd)[0] = (ps)[0]; (pd)[1] = (ps)[1]; (pd)[2] = (ps)[2];
41 #define _copy24bit(pd, v) (pd)[0] = ((unsigned char*)(&(v)))[0]; (pd)[1] = ((unsigned char*)(&(v)))[1]; (pd)[2] = ((unsigned char*)(&(v)))[2];
42 */
43 extern int pixelformat;
44 // in bitmap.c
45 extern int pixelbytes[(int)5];
46 
47 #define PAL_BYTES ((pixelbytes[(int)PIXEL_32]*256))
48 
49 // Define fixed-size integer types - these used to be in gfxtypes.h
50 // TODO: use these for throughout the engine where fixed-length types are needed
51 #if PSP
52 #include "psptypes.h"
53 #elif WII
54 #include "gctypes.h"
55 #elif ((__STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (__GNUC__ >= 3))) && (!defined(DC))
56 #include <stdint.h>
57 typedef int8_t s8;
58 typedef uint8_t u8;
59 typedef int16_t s16;
60 typedef uint16_t u16;
61 #if VITA // silly compiler...
62 typedef int s32;
63 typedef unsigned int u32;
64 #else
65 typedef int32_t s32;
66 typedef uint32_t u32;
67 #endif
68 typedef int64_t s64;
69 typedef uint64_t u64;
70 #else // MSVC - no C99 support :(
71 typedef signed char s8;
72 typedef unsigned char u8;
73 typedef signed short s16;
74 typedef unsigned short u16;
75 typedef signed int s32;
76 typedef unsigned int u32;
77 typedef signed long long s64; // FIXME: not sure if this will have the correct length in MSVC 64-bit mode
78 typedef unsigned long long u64;
79 #endif
80 
81 // Define the "bool" type and standard values for "true" and "false"
82 #if (__STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (__GNUC__ >= 3))
83 #include <stdbool.h>
84 #else // MSVC again... :(
85 #if !defined(bool)
86 #define bool s8
87 #endif
88 #if !defined(true) && !defined(false)
89 #define true 1
90 #define false 0
91 #endif
92 #endif
93 
94 //scr
95 #define screen_magic ((int)0x726373)
96 
97 typedef struct
98 {
99     int magic;
100     int	width;
101     int	height;
102     int pixelformat;
103 #if PSP
104     int dummy[3]; //temporary debug values
105 #endif
106     unsigned char *palette;
107     unsigned char data[ANYNUMBER];
108 } s_screen;
109 
110 
111 typedef struct
112 {
113     int	width;
114     int	height;
115     int	planar;
116     int	banked;		// Still unused
117     unsigned char 	*data;
118 } s_vram;
119 
120 
121 //bmp
122 #define bitmap_magic ((int)0x706d62)
123 
124 typedef struct
125 {
126     int magic;
127     int	width;
128     int	height;
129     int pixelformat;
130     int clipped_x_offset;
131     int clipped_y_offset;
132     int clipped_width;
133     int clipped_height;
134 #if PSP
135     int dummy[3]; //temporary debug values
136 #endif
137     unsigned char *palette;
138     unsigned char data[ANYNUMBER];
139 } s_bitmap;
140 
141 //spr
142 #define sprite_magic ((int)0x727073)
143 
144 typedef struct spritestruct
145 {
146     int magic;
147     int	centerx;
148     int	centery;
149     int offsetx;
150     int offsety;
151     int srcwidth;
152     int srcheight;
153     int	width;
154     int	height;
155     int pixelformat;
156     struct spritestruct *mask;
157     unsigned char *palette;
158     int data[ANYNUMBER];
159 } s_sprite;
160 
161 struct sprite_list
162 {
163     char *filename;
164     s_sprite *sprite;
165     int ref;
166     struct sprite_list *next;
167 };
168 typedef struct sprite_list s_sprite_list;
169 
170 typedef struct
171 {
172     s_sprite_list *node;
173     int  centerx;
174     int  centery;
175 } s_sprite_map;
176 
177 void set_blendtables(unsigned char *tables[]); // set global blend tables for 8bit mode
178 
179 typedef unsigned char (*transpixelfunc)(unsigned char *table, unsigned char src, unsigned char dest);
180 typedef unsigned short (*blend16fp)(unsigned short, unsigned short);
181 typedef unsigned (*blend32fp)(unsigned, unsigned);
182 
183 blend16fp getblendfunction16(int alpha);
184 blend32fp getblendfunction32(int alpha);
185 
186 extern blend16fp blendfunctions16[MAX_BLENDINGS];
187 extern blend32fp blendfunctions32[MAX_BLENDINGS];
188 extern unsigned char *blendtables[MAX_BLENDINGS];
189 extern unsigned channelr, channelg, channelb, tintmode, tintcolor;
190 extern int usechannel;
191 extern int useclip, clipx1, clipx2, clipy1, clipy2;
192 extern blend16fp tint16fp1, tint16fp2;
193 extern blend32fp tint32fp1, tint32fp2;
194 
195 unsigned short colour16(unsigned char r, unsigned char g, unsigned char b);
196 unsigned colour32(unsigned char r, unsigned char g, unsigned char b);
197 
198 #if 0
199 void u8revcpy(unsigned char *pa, const unsigned char *pb, unsigned len);
200 void u8revpcpy(unsigned char *pa, const unsigned char *pb, unsigned char *pp, unsigned len);
201 void u8pcpy(unsigned char *pa, const unsigned char *pb, unsigned char *pp, unsigned len);
202 
203 void u16revpcpy(unsigned short *pdest, const unsigned char *psrc, unsigned short *pp, unsigned len);
204 void u16pcpy(unsigned short *pdest, const unsigned char *psrc, unsigned short *pp, unsigned len);
205 
206 void u32revpcpy(unsigned *pdest, const unsigned char *psrc, unsigned *pp, unsigned len);
207 void u32pcpy(unsigned *pdest, const unsigned char *psrc, unsigned *pp, unsigned len);
208 #endif
209 
210 typedef enum
211 {
212 	WATER_MODE_NONE,
213 	WATER_MODE_SINE = 1,
214 	WATER_MODE_SHEAR = 3
215 } e_water_mode;
216 
217 
218 typedef enum
219 {
220 	WATER_PERSPECTIVE_NONE,
221 	WATER_PERSPECTIVE_TILE,
222 	WATER_PERSPECTIVE_STRETCH
223 } e_water_perspective;
224 
225 typedef struct
226 {
227     union
228     {
229         int amplitude;
230         float beginsize;
231     };
232     union
233     {
234         float wavelength;
235         float endsize;
236     };
237     int wavetime;
238     union
239     {
240         float wavespeed;
241 		e_water_perspective	perspective;
242     };
243     e_water_mode watermode;
244 } water_transform;
245 
246 typedef struct
247 {
248     unsigned char *table;	// ~~
249     //void *fp;
250     unsigned fillcolor;		// ~~
251     int flag;				// When 0, the global plainmethod is used. ~~
252     int alpha;				// ~~
253     int remap;				// ~~
254     int flipx;				// ~~
255     int flipy;				// ~~
256     int transbg;			// ~~
257     int fliprotate;			// entity only, whether the flip is affected by the entity's facing(not the sprite's flip ) ~~
258     float rotate;			// 360 degrees ~~
259     int scalex;				// ~~
260     int scaley;				// ~~
261     int shiftx;				// ~~
262     int centerx;			// shift centerx ~~
263     int centery;			// shift centery ~~
264     int xrepeat;			// ~~
265     int yrepeat;			// ~~
266     int xspan;				// ~~
267     int yspan;				// ~~
268     unsigned char channelr;	// ~~
269     unsigned char channelg; // ~~
270     unsigned char channelb;	// ~~
271     unsigned tintmode;		// tint the sprite with color ~~
272     unsigned tintcolor;		// ~~
273     int clipx;				// ~~
274     int clipy;				// ~~
275     int clipw;				// ~~
276     int cliph;				// ~~
277     water_transform water;
278 	int tag;				// ~~
279 } s_drawmethod;
280 extern const s_drawmethod plainmethod;
281 void drawmethod_global_init(s_drawmethod *drawmethod);
282 
283 typedef enum
284 {
285     gfx_screen,
286     gfx_bitmap,
287     gfx_sprite
288 } gfx_type;
289 
290 
291 typedef struct
292 {
293     union
294     {
295         s_screen *screen;
296         s_sprite *sprite;
297         s_bitmap *bitmap;
298         void      *handle;
299     };
300 } gfx_entry;
301 
302 
303 typedef struct
304 {
305     short hRes;        // Horizontal Resolution
306     short vRes;		 // Vertical Resolution
307     short hShift;	     // Offset for X-Axis Text
308     short vShift;	     // Offset for Y-Axis Text
309     short dOffset;	 // Offset for Debug Text
310     short shiftpos[4];
311     char filter;
312     char mode;
313     char pixel;
314     float hScale;    // Multiplier for X-Axis
315     float vScale;    // Multiplier for Y-Axis
316 
317 } s_videomodes;
318 
319 #if SYMBIAN
320 #pragma pack(0)
321 #elif SDL
322 #pragma pack(pop)
323 #endif
324 
325 #endif
326 
327 
328 
329