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 #define _copy24bitp(pd, ps) (pd)[0] = (ps)[0]; (pd)[1] = (ps)[1]; (pd)[2] = (ps)[2];
40 #define _copy24bit(pd, v) (pd)[0] = ((unsigned char*)(&(v)))[0]; (pd)[1] = ((unsigned char*)(&(v)))[1]; (pd)[2] = ((unsigned char*)(&(v)))[2];
41 */
42 extern int pixelformat;
43 extern int screenformat;
44 // in bitmap.c
45 extern int pixelbytes[(int)5];
46 
47 #define PAL_BYTES (screenformat==PIXEL_8?768:(pixelbytes[(int)screenformat]*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 typedef int32_t s32;
62 typedef uint32_t u32;
63 typedef int64_t s64;
64 typedef uint64_t u64;
65 #else // MSVC - no C99 support :(
66 typedef signed char s8;
67 typedef unsigned char u8;
68 typedef signed short s16;
69 typedef unsigned short u16;
70 typedef signed int s32;
71 typedef unsigned int u32;
72 typedef signed long long s64; // FIXME: not sure if this will have the correct length in MSVC 64-bit mode
73 typedef unsigned long long u64;
74 #endif
75 
76 // Define the "bool" type and standard values for "true" and "false"
77 #if (__STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (__GNUC__ >= 3))
78 #include <stdbool.h>
79 #else // MSVC again... :(
80 #if !defined(bool)
81 #define bool s8
82 #endif
83 #if !defined(true) && !defined(false)
84 #define true 1
85 #define false 0
86 #endif
87 #endif
88 
89 //scr
90 #define screen_magic ((int)0x726373)
91 
92 typedef struct
93 {
94     int magic;
95     int	width;
96     int	height;
97     int pixelformat;
98 #if PSP
99     int dummy[3]; //temporary debug values
100 #endif
101     unsigned char *palette;
102     unsigned char data[ANYNUMBER];
103 } s_screen;
104 
105 
106 typedef struct
107 {
108     int	width;
109     int	height;
110     int	planar;
111     int	banked;		// Still unused
112     unsigned char 	*data;
113 } s_vram;
114 
115 
116 //bmp
117 #define bitmap_magic ((int)0x706d62)
118 
119 typedef struct
120 {
121     int magic;
122     int	width;
123     int	height;
124     int pixelformat;
125 #if PSP
126     int dummy[3]; //temporary debug values
127 #endif
128     unsigned char *palette;
129     unsigned char data[ANYNUMBER];
130 } s_bitmap;
131 
132 //spr
133 #define sprite_magic ((int)0x727073)
134 
135 typedef struct spritestruct
136 {
137     int magic;
138     int	centerx;
139     int	centery;
140     int offsetx;
141     int offsety;
142     int srcwidth;
143     int srcheight;
144     int	width;
145     int	height;
146     int pixelformat;
147     struct spritestruct *mask;
148     unsigned char *palette;
149     int data[ANYNUMBER];
150 } s_sprite;
151 
152 struct sprite_list
153 {
154     char *filename;
155     s_sprite *sprite;
156     int ref;
157     struct sprite_list *next;
158 };
159 typedef struct sprite_list s_sprite_list;
160 
161 typedef struct
162 {
163     s_sprite_list *node;
164     int  centerx;
165     int  centery;
166 } s_sprite_map;
167 
168 void set_blendtables(unsigned char *tables[]); // set global blend tables for 8bit mode
169 
170 typedef unsigned char (*transpixelfunc)(unsigned char *table, unsigned char src, unsigned char dest);
171 typedef unsigned short (*blend16fp)(unsigned short, unsigned short);
172 typedef unsigned (*blend32fp)(unsigned, unsigned);
173 
174 blend16fp getblendfunction16(int alpha);
175 blend32fp getblendfunction32(int alpha);
176 
177 extern blend16fp blendfunctions16[MAX_BLENDINGS];
178 extern blend32fp blendfunctions32[MAX_BLENDINGS];
179 extern unsigned char *blendtables[MAX_BLENDINGS];
180 extern unsigned channelr, channelg, channelb, tintmode, tintcolor;
181 extern int usechannel;
182 extern int useclip, clipx1, clipx2, clipy1, clipy2;
183 extern blend16fp tint16fp1, tint16fp2;
184 extern blend32fp tint32fp1, tint32fp2;
185 
186 unsigned short colour16(unsigned char r, unsigned char g, unsigned char b);
187 unsigned colour32(unsigned char r, unsigned char g, unsigned char b);
188 
189 #if 0
190 void u8revcpy(unsigned char *pa, const unsigned char *pb, unsigned len);
191 void u8revpcpy(unsigned char *pa, const unsigned char *pb, unsigned char *pp, unsigned len);
192 void u8pcpy(unsigned char *pa, const unsigned char *pb, unsigned char *pp, unsigned len);
193 
194 void u16revpcpy(unsigned short *pdest, const unsigned char *psrc, unsigned short *pp, unsigned len);
195 void u16pcpy(unsigned short *pdest, const unsigned char *psrc, unsigned short *pp, unsigned len);
196 
197 void u32revpcpy(unsigned *pdest, const unsigned char *psrc, unsigned *pp, unsigned len);
198 void u32pcpy(unsigned *pdest, const unsigned char *psrc, unsigned *pp, unsigned len);
199 #endif
200 
201 typedef struct
202 {
203     union
204     {
205         int amplitude;
206         float beginsize;
207     };
208     union
209     {
210         float wavelength;
211         float endsize;
212     };
213     int wavetime;
214     union
215     {
216         float wavespeed;
217         int	perspective;
218     };
219     int watermode;
220 } water_transform;
221 
222 typedef struct
223 {
224     unsigned char *table;
225     void *fp;
226     unsigned fillcolor;
227     int flag;
228     int alpha;
229     int remap;
230     int flipx;
231     int flipy;
232     int transbg;
233     int fliprotate; // entity only, whether the flip is affected by the entity's facing(not the sprite's flip )
234     float rotate; // 360 degrees
235     int scalex;
236     int scaley;
237     int shiftx;
238     int centerx;   // shift centerx
239     int centery;   //shift centery
240     int xrepeat;
241     int yrepeat;
242     int xspan;
243     int yspan;
244     unsigned channelr;
245     unsigned channelg;
246     unsigned channelb;
247     unsigned tintmode; //tint the sprite with color
248     unsigned tintcolor;
249     //unsigned clipmode; //0 sprite clip, 1 center,  2 screen clip
250     int clipx;
251     int clipy;
252     int clipw;
253     int cliph;
254     water_transform water;
255 } s_drawmethod;
256 extern const s_drawmethod plainmethod;
257 void drawmethod_global_init(s_drawmethod *drawmethod);
258 
259 typedef enum
260 {
261     gfx_screen,
262     gfx_bitmap,
263     gfx_sprite
264 } gfx_type;
265 
266 
267 typedef struct
268 {
269     union
270     {
271         s_screen *screen;
272         s_sprite *sprite;
273         s_bitmap *bitmap;
274         void      *handle;
275     };
276 } gfx_entry;
277 
278 
279 typedef struct
280 {
281     short hRes;        // Horizontal Resolution
282     short vRes;		 // Vertical Resolution
283     short hShift;	     // Offset for X-Axis Text
284     short vShift;	     // Offset for Y-Axis Text
285     short dOffset;	 // Offset for Debug Text
286     short shiftpos[4];
287     char filter;
288     char mode;
289     char pixel;
290     float hScale;    // Multiplier for X-Axis
291     float vScale;    // Multiplier for Y-Axis
292 
293 } s_videomodes;
294 
295 #if SYMBIAN
296 #pragma pack(0)
297 #elif SDL
298 #pragma pack(pop)
299 #endif
300 
301 #endif
302 
303 
304 
305