1 /*
2  * OpenBOR - http://www.LavaLit.com
3  * -----------------------------------------------------------------------
4  * All rights reserved, see LICENSE in OpenBOR root for details.
5  *
6  * Copyright (c) 2004 - 2011 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 DOS || 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 	int magic;
94 	int	width;
95 	int	height;
96 	int pixelformat;
97 #if PSP
98 	int dummy[3]; //temporary debug values
99 #endif
100 	unsigned char* palette;
101 	unsigned char data[ANYNUMBER];
102 }s_screen;
103 
104 
105 typedef struct{
106 	int	width;
107 	int	height;
108 	int	planar;
109 	int	banked;		// Still unused
110 	unsigned char *	data;
111 }s_vram;
112 
113 
114 //bmp
115 #define bitmap_magic ((int)0x706d62)
116 
117 typedef struct{
118 	int magic;
119 	int	width;
120 	int	height;
121 	int pixelformat;
122 #if PSP
123 	int dummy[3]; //temporary debug values
124 #endif
125 	unsigned char* palette;
126 	unsigned char data[ANYNUMBER];
127 }s_bitmap;
128 
129 //spr
130 #define sprite_magic ((int)0x727073)
131 
132 typedef struct spritestruct{
133 	int magic;
134 	int	centerx;
135 	int	centery;
136 	int offsetx;
137 	int offsety;
138 	int srcwidth;
139 	int srcheight;
140 	int	width;
141 	int	height;
142 	int pixelformat;
143 	struct spritestruct* mask;
144 	unsigned char* palette;
145 	int data[ANYNUMBER];
146 }s_sprite;
147 
148 struct sprite_list{
149 	char *filename;
150 	s_sprite *sprite;
151 	int ref;
152 	struct sprite_list *next;
153 };
154 typedef struct sprite_list s_sprite_list;
155 
156 typedef struct{
157 	s_sprite_list *node;
158 	int  centerx;
159 	int  centery;
160 }s_sprite_map;
161 
162 void set_blendtables(unsigned char* tables[]); // set global blend tables for 8bit mode
163 
164 typedef unsigned char (*transpixelfunc)(unsigned char* table, unsigned char src, unsigned char dest);
165 typedef unsigned short (*blend16fp)(unsigned short, unsigned short);
166 typedef unsigned (*blend32fp)(unsigned, unsigned);
167 
168 extern blend16fp blendfunctions16[MAX_BLENDINGS];
169 extern blend32fp blendfunctions32[MAX_BLENDINGS];
170 extern unsigned char* blendtables[MAX_BLENDINGS];
171 
172 unsigned short colour16(unsigned char r, unsigned char g, unsigned char b);
173 unsigned colour32(unsigned char r, unsigned char g, unsigned char b);
174 
175 void u8revcpy(unsigned char*pa, const unsigned char*pb, unsigned len);
176 void u8revpcpy(unsigned char*pa, const unsigned char*pb, unsigned char*pp, unsigned len);
177 void u8pcpy(unsigned char*pa, const unsigned char*pb, unsigned char* pp, unsigned len);
178 
179 void u16revpcpy(unsigned short* pdest, const unsigned char* psrc, unsigned short* pp, unsigned len);
180 void u16pcpy(unsigned short* pdest, const unsigned char* psrc, unsigned short* pp, unsigned len);
181 
182 void u32revpcpy(unsigned* pdest, const unsigned char* psrc, unsigned* pp, unsigned len);
183 void u32pcpy(unsigned* pdest, const unsigned char* psrc, unsigned* pp, unsigned len);
184 
185 typedef struct{
186 	union
187 	{
188 	int amplitude;
189 	float beginsize;
190 	};
191 	union{
192 	float wavelength;
193 	float endsize;
194 	};
195 	int wavetime;
196 	union{
197 	float wavespeed;
198 	int	perspective;
199 	};
200 	int watermode;
201 }water_transform;
202 
203 typedef struct
204 {
205 	unsigned char* table;
206 	void* fp;
207 	unsigned fillcolor;
208 	int flag:1;
209 	int alpha:8;
210 	int remap:8;
211 	int flipx:1;
212 	int flipy:1;
213 	int transbg:1;
214 	int fliprotate:1; // entity only, whether the flip is affected by the entity's facing(not the sprite's flip )
215 	int rotate:11; // 360 degrees
216 	int scalex;
217 	int scaley;
218 	int shiftx;
219 	int centerx;   // shift centerx
220 	int centery;   //shift centery
221 	int xrepeat;
222 	int yrepeat;
223 	int xspan;
224 	int yspan;
225 	water_transform water;
226 }s_drawmethod;
227 
228 typedef enum
229 {
230 	gfx_screen,
231 	gfx_bitmap,
232 	gfx_sprite
233 }gfx_type;
234 
235 /*
236 typedef enum
237 {
238 	ct_rectangle,
239 	ct_mask_screen
240 
241 }clipping_type;
242 
243 
244 //screen clipping array clipp
245 typedef struct
246 {
247 	int type;
248 	int x;
249 	int y;
250 	int width;
251 	int height;
252 	s_screen mask_screen;
253 }s_clipping;
254 */
255 
256 typedef struct
257 {
258 	union{
259 		s_screen * screen;
260 		s_sprite * sprite;
261 		s_bitmap * bitmap;
262 		void*      handle;
263 	};
264 }gfx_entry;
265 
266 typedef struct
267 {
268 	int x; //x
269 	int y; //y
270 	int tx; //texture coords x
271 	int ty; //texture coords y
272 }vert2d;
273 
274 typedef struct
275 {
276 	int ulx; //upper left x
277 	int uly; //upper left y
278 	int lrx; //lower right x
279 	int lry; //lower right y
280 }rect2d;
281 
282 
283 typedef struct
284 {
285 	short hRes;        // Horizontal Resolution
286 	short vRes;		 // Vertical Resolution
287 	short hShift;	     // Offset for X-Axis Text
288 	short vShift;	     // Offset for Y-Axis Text
289 	short dOffset;	 // Offset for Debug Text
290 	short shiftpos[4];
291 	char filter;
292 	char mode;
293 	char pixel;
294 	float hScale;    // Multiplier for X-Axis
295 	float vScale;    // Multiplier for Y-Axis
296 
297 }s_videomodes;
298 
299 #if SYMBIAN
300 #pragma pack(0)
301 #elif DOS || SDL
302 #pragma pack(pop)
303 #endif
304 
305 #endif
306 
307 
308 
309