added event action parameter for global animations (no functionality yet)
[rocksndiamonds.git] / src / libgame / system.h
1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // system.h
10 // ============================================================================
11
12 #ifndef SYSTEM_H
13 #define SYSTEM_H
14
15 #include "platform.h"
16 #include "types.h"
17
18
19 #if defined(PLATFORM_MACOSX)
20 #include "macosx.h"
21 #elif defined(PLATFORM_WIN32)
22 #include "windows.h"
23 #elif defined(PLATFORM_ANDROID)
24 #include "android.h"
25 #endif
26
27 #include "sdl.h"
28
29
30 /* the additional 'b' is needed for Win32 to open files in binary mode */
31 #define MODE_READ                       "rb"
32 #define MODE_WRITE                      "wb"
33 #define MODE_APPEND                     "ab"
34
35 #define DEFAULT_DEPTH                   0
36
37 #define BLIT_OPAQUE                     0
38 #define BLIT_MASKED                     1
39 #define BLIT_INVERSE                    2
40 #define BLIT_ON_BACKGROUND              3
41
42 /* values for fullscreen status */
43 #define FULLSCREEN_NOT_AVAILABLE        FALSE
44 #define FULLSCREEN_AVAILABLE            TRUE
45
46 /* values for window scaling */
47 #define WINDOW_SCALING_NOT_AVAILABLE    FALSE
48 #define WINDOW_SCALING_AVAILABLE        TRUE
49
50 #define MIN_WINDOW_SCALING_PERCENT      30
51 #define STD_WINDOW_SCALING_PERCENT      100
52 #define MAX_WINDOW_SCALING_PERCENT      400
53 #define STEP_WINDOW_SCALING_PERCENT     10
54
55 /* values for window scaling quality */
56 #define SCALING_QUALITY_NEAREST         "nearest"
57 #define SCALING_QUALITY_LINEAR          "linear"
58 #define SCALING_QUALITY_BEST            "best"
59
60 #define SCALING_QUALITY_DEFAULT         SCALING_QUALITY_LINEAR
61
62 /* values for screen rendering mode */
63 #define STR_SPECIAL_RENDERING_OFF       "stream_texture_only"
64 #define STR_SPECIAL_RENDERING_BITMAP    "bitmap_and_stream_texture"
65 #define STR_SPECIAL_RENDERING_TARGET    "target_texture_only"
66 #define STR_SPECIAL_RENDERING_DOUBLE    "stream_and_target_texture"
67
68 #if defined(TARGET_SDL2)
69 #define STR_SPECIAL_RENDERING_DEFAULT   STR_SPECIAL_RENDERING_DOUBLE
70 #else
71 #define STR_SPECIAL_RENDERING_DEFAULT   STR_SPECIAL_RENDERING_BITMAP
72 #endif
73
74 #define SPECIAL_RENDERING_OFF           0
75 #define SPECIAL_RENDERING_BITMAP        1
76 #define SPECIAL_RENDERING_TARGET        2
77 #define SPECIAL_RENDERING_DOUBLE        3
78
79 #if defined(TARGET_SDL2)
80 #define SPECIAL_RENDERING_DEFAULT       SPECIAL_RENDERING_DOUBLE
81 #else
82 #define SPECIAL_RENDERING_DEFAULT       SPECIAL_RENDERING_BITMAP
83 #endif
84
85 /* values for touch control */
86 #define TOUCH_CONTROL_OFF               "off"
87 #define TOUCH_CONTROL_VIRTUAL_BUTTONS   "virtual_buttons"
88 #define TOUCH_CONTROL_WIPE_GESTURES     "wipe_gestures"
89 #define TOUCH_CONTROL_FOLLOW_FINGER     "follow_finger"
90
91 #if defined(PLATFORM_ANDROID)
92 #define TOUCH_CONTROL_DEFAULT           TOUCH_CONTROL_VIRTUAL_BUTTONS
93 #else
94 #define TOUCH_CONTROL_DEFAULT           TOUCH_CONTROL_OFF
95 #endif
96
97 #define TOUCH_MOVE_DISTANCE_DEFAULT     2
98 #define TOUCH_DROP_DISTANCE_DEFAULT     5
99 #define TOUCH_TRANSPARENCY_DEFAULT      50
100
101 #define ALPHA_FROM_TRANSPARENCY(x)      ((100 - x) * SDL_ALPHA_OPAQUE / 100)
102 #define ALPHA_FADING_STEPSIZE(x)        ((x) / 25)
103
104 /* values for special settings for mobile devices */
105 #if defined(PLATFORM_ANDROID)
106 #define USE_TOUCH_INPUT_OVERLAY
107 #define USE_COMPLETE_DISPLAY
108 #define HAS_SCREEN_KEYBOARD
109 #define SCREEN_KEYBOARD_POS(h)          ((h) / 2)
110 #endif
111
112 /* default input keys */
113 #define DEFAULT_KEY_LEFT                KSYM_Left
114 #define DEFAULT_KEY_RIGHT               KSYM_Right
115 #define DEFAULT_KEY_UP                  KSYM_Up
116 #define DEFAULT_KEY_DOWN                KSYM_Down
117 #if defined(PLATFORM_MACOSX)
118 #define DEFAULT_KEY_SNAP                KSYM_Control_L
119 #define DEFAULT_KEY_DROP                KSYM_KP_Enter
120 #else
121 #define DEFAULT_KEY_SNAP                KSYM_Control_L
122 #define DEFAULT_KEY_DROP                KSYM_Control_R
123 #endif
124 #define DEFAULT_KEY_OKAY                KSYM_Return
125 #define DEFAULT_KEY_CANCEL              KSYM_Escape
126
127 /* default shortcut keys */
128 #define DEFAULT_KEY_SAVE_GAME           KSYM_F1
129 #define DEFAULT_KEY_LOAD_GAME           KSYM_F2
130 #define DEFAULT_KEY_TOGGLE_PAUSE        KSYM_space
131 #define DEFAULT_KEY_FOCUS_PLAYER_1      KSYM_F5
132 #define DEFAULT_KEY_FOCUS_PLAYER_2      KSYM_F6
133 #define DEFAULT_KEY_FOCUS_PLAYER_3      KSYM_F7
134 #define DEFAULT_KEY_FOCUS_PLAYER_4      KSYM_F8
135 #define DEFAULT_KEY_FOCUS_PLAYER_ALL    KSYM_F9
136 #define DEFAULT_KEY_TAPE_EJECT          KSYM_UNDEFINED
137 #define DEFAULT_KEY_TAPE_EXTRA          KSYM_UNDEFINED
138 #define DEFAULT_KEY_TAPE_STOP           KSYM_UNDEFINED
139 #define DEFAULT_KEY_TAPE_PAUSE          KSYM_UNDEFINED
140 #define DEFAULT_KEY_TAPE_RECORD         KSYM_UNDEFINED
141 #define DEFAULT_KEY_TAPE_PLAY           KSYM_UNDEFINED
142 #define DEFAULT_KEY_SOUND_SIMPLE        KSYM_UNDEFINED
143 #define DEFAULT_KEY_SOUND_LOOPS         KSYM_UNDEFINED
144 #define DEFAULT_KEY_SOUND_MUSIC         KSYM_UNDEFINED
145 #define DEFAULT_KEY_SNAP_LEFT           KSYM_UNDEFINED
146 #define DEFAULT_KEY_SNAP_RIGHT          KSYM_UNDEFINED
147 #define DEFAULT_KEY_SNAP_UP             KSYM_UNDEFINED
148 #define DEFAULT_KEY_SNAP_DOWN           KSYM_UNDEFINED
149
150 /* default debug setup keys and values */
151 #define DEFAULT_FRAME_DELAY_0           20              // 100 % speed
152 #define DEFAULT_FRAME_DELAY_1           500             // 4 % speed
153 #define DEFAULT_FRAME_DELAY_2           250             // 8 % speed
154 #define DEFAULT_FRAME_DELAY_3           125             // 16 % speed
155 #define DEFAULT_FRAME_DELAY_4           60              // 33 % speed
156 #define DEFAULT_FRAME_DELAY_5           40              // 50 % speed
157 #define DEFAULT_FRAME_DELAY_6           30              // 66 % speed
158 #define DEFAULT_FRAME_DELAY_7           10              // 200 % speed
159 #define DEFAULT_FRAME_DELAY_8           5               // 400 % speed
160 #define DEFAULT_FRAME_DELAY_9           0               // maximum speed
161
162 #define DEFAULT_KEY_FRAME_DELAY_0       KSYM_0
163 #define DEFAULT_KEY_FRAME_DELAY_1       KSYM_1
164 #define DEFAULT_KEY_FRAME_DELAY_2       KSYM_2
165 #define DEFAULT_KEY_FRAME_DELAY_3       KSYM_3
166 #define DEFAULT_KEY_FRAME_DELAY_4       KSYM_4
167 #define DEFAULT_KEY_FRAME_DELAY_5       KSYM_5
168 #define DEFAULT_KEY_FRAME_DELAY_6       KSYM_6
169 #define DEFAULT_KEY_FRAME_DELAY_7       KSYM_7
170 #define DEFAULT_KEY_FRAME_DELAY_8       KSYM_8
171 #define DEFAULT_KEY_FRAME_DELAY_9       KSYM_9
172
173 #define NUM_DEBUG_FRAME_DELAY_KEYS      10
174
175 #define DEFAULT_FRAME_DELAY_USE_MOD_KEY FALSE
176 #define DEFAULT_FRAME_DELAY_GAME_ONLY   TRUE
177
178 /* values for key_status */
179 #define KEY_NOT_PRESSED                 FALSE
180 #define KEY_RELEASED                    FALSE
181 #define KEY_PRESSED                     TRUE
182
183 /* values for button status */
184 #define MB_NOT_PRESSED                  FALSE
185 #define MB_NOT_RELEASED                 TRUE
186 #define MB_RELEASED                     FALSE
187 #define MB_PRESSED                      TRUE
188 #define MB_MENU_CHOICE                  FALSE
189 #define MB_MENU_MARK                    TRUE
190 #define MB_MENU_INITIALIZE              (-1)
191 #define MB_MENU_LEAVE                   (-2)
192 #define MB_LEFTBUTTON                   1
193 #define MB_MIDDLEBUTTON                 2
194 #define MB_RIGHTBUTTON                  3
195 #define MB_WHEEL_UP                     4
196 #define MB_WHEEL_DOWN                   5
197 #define MB_WHEEL_LEFT                   6
198 #define MB_WHEEL_RIGHT                  7
199 #define IS_WHEEL_BUTTON_VERTICAL(b)     ((b) == MB_WHEEL_UP ||          \
200                                          (b) == MB_WHEEL_DOWN)
201 #define IS_WHEEL_BUTTON_HORIZONTAL(b)   ((b) == MB_WHEEL_LEFT ||        \
202                                          (b) == MB_WHEEL_RIGHT)
203 #define IS_WHEEL_BUTTON(b)              (IS_WHEEL_BUTTON_VERTICAL(b) || \
204                                          IS_WHEEL_BUTTON_HORIZONTAL(b))
205 #define DEFAULT_WHEEL_STEPS             3
206
207 #define BUTTON_STEPSIZE(b)              ((b) == MB_LEFTBUTTON   ?  1 :  \
208                                          (b) == MB_MIDDLEBUTTON ?  5 :  \
209                                          (b) == MB_RIGHTBUTTON  ? 10 : 1)
210
211 /* values for move directions */
212 #define MV_BIT_LEFT                     0
213 #define MV_BIT_RIGHT                    1
214 #define MV_BIT_UP                       2
215 #define MV_BIT_DOWN                     3
216
217 #define NUM_DIRECTIONS                  4
218
219 /* diagonal movement directions are used in a different contect than buttons */
220 #define MV_BIT_UPLEFT                   4
221 #define MV_BIT_UPRIGHT                  5
222 #define MV_BIT_DOWNLEFT                 6
223 #define MV_BIT_DOWNRIGHT                7
224
225 #define NUM_DIRECTIONS_FULL             8
226
227 /* values for special "button" bitmasks */
228 #define BUTTON_1                        4
229 #define BUTTON_2                        5
230
231 #define NUM_PLAYER_ACTIONS              6
232
233 /* values for special "focus player" bitmasks */
234 #define BIT_SET_FOCUS                   6
235
236 /* values for drawing stages for global animations */
237 #define DRAW_GLOBAL_ANIM_STAGE_1        1
238 #define DRAW_GLOBAL_ANIM_STAGE_2        2
239
240 /* values for drawing target (various functions) */
241 #define DRAW_TO_BACKBUFFER              0
242 #define DRAW_TO_FIELDBUFFER             1
243 #define DRAW_TO_SCREEN                  2
244 #define DRAW_TO_FADE_SOURCE             3
245 #define DRAW_TO_FADE_TARGET             4
246
247 /* values for move directions and special "button" key bitmasks */
248 #define MV_NONE                 0
249 #define MV_LEFT                 (1 << MV_BIT_LEFT)
250 #define MV_RIGHT                (1 << MV_BIT_RIGHT)
251 #define MV_UP                   (1 << MV_BIT_UP)
252 #define MV_DOWN                 (1 << MV_BIT_DOWN)
253
254 #define MV_UPLEFT               (MV_UP   | MV_LEFT)
255 #define MV_UPRIGHT              (MV_UP   | MV_RIGHT)
256 #define MV_DOWNLEFT             (MV_DOWN | MV_LEFT)
257 #define MV_DOWNRIGHT            (MV_DOWN | MV_RIGHT)
258
259 #define MV_HORIZONTAL           (MV_LEFT | MV_RIGHT)
260 #define MV_VERTICAL             (MV_UP   | MV_DOWN)
261 #define MV_ALL_DIRECTIONS       (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
262 #define MV_ANY_DIRECTION        (MV_ALL_DIRECTIONS)
263 #define MV_NO_DIRECTION         (MV_NONE)
264
265 #define KEY_BUTTON_1            (1 << BUTTON_1)
266 #define KEY_BUTTON_2            (1 << BUTTON_2)
267 #define KEY_BUTTON_SNAP         KEY_BUTTON_1
268 #define KEY_BUTTON_DROP         KEY_BUTTON_2
269 #define KEY_MOTION              (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
270 #define KEY_BUTTON              (KEY_BUTTON_1 | KEY_BUTTON_2)
271 #define KEY_ACTION              (KEY_MOTION | KEY_BUTTON)
272
273 #define KEY_SET_FOCUS           (1 << BIT_SET_FOCUS)
274
275 #define MV_DIR_FROM_BIT(x)      ((x) < NUM_DIRECTIONS ? 1 << (x) :        \
276                                  (x) == MV_BIT_UPLEFT    ? MV_UPLEFT    : \
277                                  (x) == MV_BIT_UPRIGHT   ? MV_UPRIGHT   : \
278                                  (x) == MV_BIT_DOWNLEFT  ? MV_DOWNLEFT  : \
279                                  (x) == MV_BIT_DOWNRIGHT ? MV_DOWNRIGHT : \
280                                  MV_NONE)
281
282 #define MV_DIR_TO_BIT(x)        ((x) == MV_LEFT      ? MV_BIT_LEFT      : \
283                                  (x) == MV_RIGHT     ? MV_BIT_RIGHT     : \
284                                  (x) == MV_UP        ? MV_BIT_UP        : \
285                                  (x) == MV_DOWN      ? MV_BIT_DOWN      : \
286                                  (x) == MV_UPLEFT    ? MV_BIT_UPLEFT    : \
287                                  (x) == MV_UPRIGHT   ? MV_BIT_UPRIGHT   : \
288                                  (x) == MV_DOWNLEFT  ? MV_BIT_DOWNLEFT  : \
289                                  (x) == MV_DOWNRIGHT ? MV_BIT_DOWNRIGHT : \
290                                  MV_BIT_DOWN)
291
292 #define MV_DIR_OPPOSITE(x)      ((x) == MV_LEFT      ? MV_RIGHT     : \
293                                  (x) == MV_RIGHT     ? MV_LEFT      : \
294                                  (x) == MV_UP        ? MV_DOWN      : \
295                                  (x) == MV_DOWN      ? MV_UP        : \
296                                  (x) == MV_UPLEFT    ? MV_DOWNRIGHT : \
297                                  (x) == MV_UPRIGHT   ? MV_DOWNLEFT  : \
298                                  (x) == MV_DOWNLEFT  ? MV_UPRIGHT   : \
299                                  (x) == MV_DOWNRIGHT ? MV_UPLEFT    : \
300                                  MV_NONE)
301
302 /* values for animation mode (frame order and direction) */
303 /* (stored in level files -- never change existing values) */
304 #define ANIM_NONE               0
305 #define ANIM_LOOP               (1 << 0)
306 #define ANIM_LINEAR             (1 << 1)
307 #define ANIM_PINGPONG           (1 << 2)
308 #define ANIM_PINGPONG2          (1 << 3)
309 #define ANIM_RANDOM             (1 << 4)
310 #define ANIM_CE_VALUE           (1 << 5)
311 #define ANIM_CE_SCORE           (1 << 6)
312 #define ANIM_CE_DELAY           (1 << 7)
313 #define ANIM_REVERSE            (1 << 8)
314 #define ANIM_OPAQUE_PLAYER      (1 << 9)
315
316 /* values for special (non game element) animation modes */
317 /* (not stored in level files -- can be changed, if needed) */
318 #define ANIM_HORIZONTAL         (1 << 10)
319 #define ANIM_VERTICAL           (1 << 11)
320 #define ANIM_CENTERED           (1 << 12)
321 #define ANIM_STATIC_PANEL       (1 << 13)
322 #define ANIM_ALL                (1 << 14)
323 #define ANIM_ONCE               (1 << 15)
324
325 #define ANIM_DEFAULT            ANIM_LOOP
326
327 /* values for special drawing styles (currently only for crumbled graphics) */
328 #define STYLE_NONE              0
329 #define STYLE_ACCURATE_BORDERS  (1 << 0)
330 #define STYLE_INNER_CORNERS     (1 << 1)
331 #define STYLE_REVERSE           (1 << 2)
332
333 #define STYLE_DEFAULT           STYLE_NONE
334
335 /* values for special global animation events */
336 #define ANIM_EVENT_NONE         0
337 #define ANIM_EVENT_SELF         (1 << 16)
338 #define ANIM_EVENT_ANY          (1 << 17)
339
340 #define ANIM_EVENT_ANIM_BIT     0
341 #define ANIM_EVENT_PART_BIT     8
342
343 #define ANIM_EVENT_ANIM_MASK    (0xff << ANIM_EVENT_ANIM_BIT)
344 #define ANIM_EVENT_PART_MASK    (0xff << ANIM_EVENT_PART_BIT)
345
346 #define ANIM_EVENT_DEFAULT      ANIM_EVENT_NONE
347
348 /* values for special global animation event actions */
349 #define ANIM_EVENT_ACTION_NONE  -1
350
351 /* values for fade mode */
352 #define FADE_TYPE_NONE          0
353 #define FADE_TYPE_FADE_IN       (1 << 0)
354 #define FADE_TYPE_FADE_OUT      (1 << 1)
355 #define FADE_TYPE_TRANSFORM     (1 << 2)
356 #define FADE_TYPE_CROSSFADE     (1 << 3)
357 #define FADE_TYPE_MELT          (1 << 4)
358 #define FADE_TYPE_CURTAIN       (1 << 5)
359 #define FADE_TYPE_SKIP          (1 << 6)
360
361 #define FADE_MODE_NONE          (FADE_TYPE_NONE)
362 #define FADE_MODE_FADE_IN       (FADE_TYPE_FADE_IN)
363 #define FADE_MODE_FADE_OUT      (FADE_TYPE_FADE_OUT)
364 #define FADE_MODE_FADE          (FADE_TYPE_FADE_IN | FADE_TYPE_FADE_OUT)
365 #define FADE_MODE_TRANSFORM     (FADE_TYPE_TRANSFORM | FADE_TYPE_FADE_IN)
366 #define FADE_MODE_CROSSFADE     (FADE_MODE_TRANSFORM | FADE_TYPE_CROSSFADE)
367 #define FADE_MODE_MELT          (FADE_MODE_TRANSFORM | FADE_TYPE_MELT)
368 #define FADE_MODE_CURTAIN       (FADE_MODE_TRANSFORM | FADE_TYPE_CURTAIN)
369 #define FADE_MODE_SKIP_FADE_IN  (FADE_TYPE_SKIP | FADE_TYPE_FADE_IN)
370 #define FADE_MODE_SKIP_FADE_OUT (FADE_TYPE_SKIP | FADE_TYPE_FADE_OUT)
371
372 #define FADE_MODE_DEFAULT       FADE_MODE_FADE
373
374 /* values for toon positions */
375 #define POS_UNDEFINED           -1
376 #define POS_LEFT                0
377 #define POS_RIGHT               1
378 #define POS_TOP                 2
379 #define POS_UPPER               3
380 #define POS_MIDDLE              4
381 #define POS_LOWER               5
382 #define POS_BOTTOM              6
383 #define POS_ANY                 7
384 #define POS_LAST                8
385
386 /* values for text alignment */
387 #define ALIGN_LEFT              (1 << 0)
388 #define ALIGN_RIGHT             (1 << 1)
389 #define ALIGN_CENTER            (1 << 2)
390 #define ALIGN_DEFAULT           ALIGN_LEFT
391
392 #define VALIGN_TOP              (1 << 0)
393 #define VALIGN_BOTTOM           (1 << 1)
394 #define VALIGN_MIDDLE           (1 << 2)
395 #define VALIGN_DEFAULT          VALIGN_TOP
396
397 #define ALIGNED_XPOS(x,w,a)     ((a) == ALIGN_CENTER  ? (x) - (w) / 2 : \
398                                  (a) == ALIGN_RIGHT   ? (x) - (w) : (x))
399 #define ALIGNED_YPOS(y,h,v)     ((v) == VALIGN_MIDDLE ? (y) - (h) / 2 : \
400                                  (v) == VALIGN_BOTTOM ? (y) - (h) : (y))
401 #define ALIGNED_TEXT_XPOS(p)    ALIGNED_XPOS((p)->x, (p)->width,  (p)->align)
402 #define ALIGNED_TEXT_YPOS(p)    ALIGNED_YPOS((p)->y, (p)->height, (p)->valign)
403
404 /* values for redraw_mask */
405 #define REDRAW_NONE             (0)
406 #define REDRAW_ALL              (1 << 0)
407 #define REDRAW_FIELD            (1 << 1)
408 #define REDRAW_DOOR_1           (1 << 2)
409 #define REDRAW_DOOR_2           (1 << 3)
410 #define REDRAW_DOOR_3           (1 << 4)
411 #define REDRAW_FPS              (1 << 5)
412
413 #define REDRAW_DOORS            (REDRAW_DOOR_1 | \
414                                  REDRAW_DOOR_2 | \
415                                  REDRAW_DOOR_3)
416
417 #define IN_GFX_FIELD_PLAY(x, y) (x >= gfx.sx && x < gfx.sx + gfx.sxsize && \
418                                  y >= gfx.sy && y < gfx.sy + gfx.sysize)
419 #define IN_GFX_FIELD_FULL(x, y) (x >= gfx.real_sx && \
420                                  x <  gfx.real_sx + gfx.full_sxsize && \
421                                  y >= gfx.real_sy && \
422                                  y <  gfx.real_sy + gfx.full_sysize)
423 #define IN_GFX_DOOR_1(x, y)     (x >= gfx.dx && x < gfx.dx + gfx.dxsize && \
424                                  y >= gfx.dy && y < gfx.dy + gfx.dysize)
425 #define IN_GFX_DOOR_2(x, y)     (x >= gfx.vx && x < gfx.vx + gfx.vxsize && \
426                                  y >= gfx.vy && y < gfx.vy + gfx.vysize)
427 #define IN_GFX_DOOR_3(x, y)     (x >= gfx.ex && x < gfx.ex + gfx.exsize && \
428                                  y >= gfx.ey && y < gfx.ey + gfx.eysize)
429
430 /* values for mouse cursor */
431 #define CURSOR_DEFAULT          0
432 #define CURSOR_NONE             1
433 #define CURSOR_PLAYFIELD        2
434
435 /* fundamental game speed values */
436 #define ONE_SECOND_DELAY        1000    /* delay value for one second */
437 #define MENU_FRAME_DELAY        20      /* frame delay in milliseconds */
438 #define GAME_FRAME_DELAY        20      /* frame delay in milliseconds */
439 #define FFWD_FRAME_DELAY        10      /* 200% speed for fast forward */
440 #define FRAMES_PER_SECOND       (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
441 #define FRAMES_PER_SECOND_SP    35
442
443 /* maximum playfield size supported by libgame functions */
444 #define MAX_PLAYFIELD_WIDTH     128
445 #define MAX_PLAYFIELD_HEIGHT    128
446
447 /* maximum number of parallel players supported by libgame functions */
448 #define MAX_PLAYERS             4
449
450 /* maximum allowed length of player name */
451 #define MAX_PLAYER_NAME_LEN     10
452
453 /* maximum number of levels in a level set */
454 #define MAX_LEVELS              1000
455
456 /* maximum number of global animation and parts */
457 #define MAX_GLOBAL_ANIMS                32
458 #define MAX_GLOBAL_ANIM_PARTS           32
459
460 /* minimum/maximum/default x/y grid size for virtual buttons */
461 #define MIN_GRID_XSIZE                  3
462 #define MIN_GRID_YSIZE                  3
463 #define MAX_GRID_XSIZE                  32
464 #define MAX_GRID_YSIZE                  32
465 #define GRID_REAL_WIDTH                 MAX(1, MAX(video.screen_width,  \
466                                                    video.screen_height))
467 #define GRID_REAL_HEIGHT                MAX(1, MIN(video.screen_width,  \
468                                                    video.screen_height))
469 #define DEFAULT_GRID_XSIZE_0            18
470 #define DEFAULT_GRID_YSIZE_0            MIN(MAX(MIN_GRID_YSIZE,         \
471                                                 DEFAULT_GRID_XSIZE_0 *  \
472                                                 GRID_REAL_HEIGHT /      \
473                                                 GRID_REAL_WIDTH),       \
474                                             MAX_GRID_YSIZE)
475 #define DEFAULT_GRID_XSIZE_1            13
476 #define DEFAULT_GRID_YSIZE_1            MIN(MAX(MIN_GRID_YSIZE,         \
477                                                 DEFAULT_GRID_XSIZE_1 *  \
478                                                 GRID_REAL_WIDTH /       \
479                                                 GRID_REAL_HEIGHT),      \
480                                             MAX_GRID_YSIZE)
481
482 #define DEFAULT_GRID_XSIZE(n)           ((n) == 0 ? DEFAULT_GRID_XSIZE_0 : \
483                                          DEFAULT_GRID_XSIZE_1)
484 #define DEFAULT_GRID_YSIZE(n)           ((n) == 0 ? DEFAULT_GRID_YSIZE_0 : \
485                                          DEFAULT_GRID_YSIZE_1)
486
487 #define GRID_ACTIVE_NR()                (video.screen_width >   \
488                                          video.screen_height ? 0 : 1)
489
490 /* values for grid button characters for virtual buttons */
491 #define CHAR_GRID_BUTTON_NONE           ' '
492 #define CHAR_GRID_BUTTON_LEFT           '<'
493 #define CHAR_GRID_BUTTON_RIGHT          '>'
494 #define CHAR_GRID_BUTTON_UP             '^'
495 #define CHAR_GRID_BUTTON_DOWN           'v'
496 #define CHAR_GRID_BUTTON_SNAP           '1'
497 #define CHAR_GRID_BUTTON_DROP           '2'
498
499 #define GET_ACTION_FROM_GRID_BUTTON(c)  ((c) == CHAR_GRID_BUTTON_LEFT ?  \
500                                          JOY_LEFT :                      \
501                                          (c) == CHAR_GRID_BUTTON_RIGHT ? \
502                                          JOY_RIGHT :                     \
503                                          (c) == CHAR_GRID_BUTTON_UP ?    \
504                                          JOY_UP :                        \
505                                          (c) == CHAR_GRID_BUTTON_DOWN ?  \
506                                          JOY_DOWN :                      \
507                                          (c) == CHAR_GRID_BUTTON_SNAP ?  \
508                                          JOY_BUTTON_1 :                  \
509                                          (c) == CHAR_GRID_BUTTON_DROP ?  \
510                                          JOY_BUTTON_2 :                  \
511                                          JOY_NO_ACTION)
512
513 /* default name for empty highscore entry */
514 #define EMPTY_PLAYER_NAME       "no name"
515
516 /* default name for unknown player names */
517 #define ANONYMOUS_NAME          "anonymous"
518
519 /* default for other unknown names */
520 #define UNKNOWN_NAME            "unknown"
521
522 /* default name for new levels */
523 #define NAMELESS_LEVEL_NAME     "nameless level"
524
525 /* default text for non-existant artwork */
526 #define NOT_AVAILABLE           "(not available)"
527
528 /* default value for undefined filename */
529 #define UNDEFINED_FILENAME      "[NONE]"
530
531 /* default value for undefined levelset */
532 #define UNDEFINED_LEVELSET      "[NONE]"
533
534 /* default value for undefined parameter */
535 #define ARG_DEFAULT             "[DEFAULT]"
536
537 /* default values for undefined configuration file parameters */
538 #define ARG_UNDEFINED           "-1000000"
539 #define ARG_UNDEFINED_VALUE     (-1000000)
540
541 /* default value for off-screen positions */
542 #define POS_OFFSCREEN           (-1000000)
543
544 /* definitions for game sub-directories */
545 #ifndef RO_GAME_DIR
546 #define RO_GAME_DIR             "."
547 #endif
548
549 #ifndef RW_GAME_DIR
550 #define RW_GAME_DIR             "."
551 #endif
552
553 #define RO_BASE_PATH            RO_GAME_DIR
554 #define RW_BASE_PATH            RW_GAME_DIR
555
556 /* directory names */
557 #define GRAPHICS_DIRECTORY      "graphics"
558 #define SOUNDS_DIRECTORY        "sounds"
559 #define MUSIC_DIRECTORY         "music"
560 #define LEVELS_DIRECTORY        "levels"
561 #define TAPES_DIRECTORY         "tapes"
562 #define SCORES_DIRECTORY        "scores"
563 #define DOCS_DIRECTORY          "docs"
564 #define CACHE_DIRECTORY         "cache"
565 #define CONF_DIRECTORY          "conf"
566
567 #define GFX_CLASSIC_SUBDIR      "gfx_classic"
568 #define SND_CLASSIC_SUBDIR      "snd_classic"
569 #define MUS_CLASSIC_SUBDIR      "mus_classic"
570
571 #define GFX_DEFAULT_SUBDIR      (setup.internal.default_graphics_set)
572 #define SND_DEFAULT_SUBDIR      (setup.internal.default_sounds_set)
573 #define MUS_DEFAULT_SUBDIR      (setup.internal.default_music_set)
574
575 #define GFX_FALLBACK_FILENAME   (setup.internal.fallback_graphics_file)
576 #define SND_FALLBACK_FILENAME   (setup.internal.fallback_sounds_file)
577 #define MUS_FALLBACK_FILENAME   (setup.internal.fallback_music_file)
578
579 #define DEFAULT_LEVELSET        (setup.internal.default_level_series)
580
581 /* file names and filename extensions */
582 #define LEVELSETUP_DIRECTORY    "levelsetup"
583 #define SETUP_FILENAME          "setup.conf"
584 #define AUTOSETUP_FILENAME      "autosetup.conf"
585 #define LEVELSETUP_FILENAME     "levelsetup.conf"
586 #define EDITORSETUP_FILENAME    "editorsetup.conf"
587 #define EDITORCASCADE_FILENAME  "editorcascade.conf"
588 #define HELPANIM_FILENAME       "helpanim.conf"
589 #define HELPTEXT_FILENAME       "helptext.conf"
590 #define LEVELINFO_FILENAME      "levelinfo.conf"
591 #define GRAPHICSINFO_FILENAME   "graphicsinfo.conf"
592 #define SOUNDSINFO_FILENAME     "soundsinfo.conf"
593 #define MUSICINFO_FILENAME      "musicinfo.conf"
594 #define ARTWORKINFO_CACHE_FILE  "artworkinfo.cache"
595 #define LEVELTEMPLATE_FILENAME  "template.level"
596 #define LEVELFILE_EXTENSION     "level"
597 #define TAPEFILE_EXTENSION      "tape"
598 #define SCOREFILE_EXTENSION     "score"
599
600 #define GAMECONTROLLER_BASENAME "gamecontrollerdb.txt"
601
602 #define LOG_OUT_BASENAME        "stdout.txt"
603 #define LOG_ERR_BASENAME        "stderr.txt"
604
605 #define LOG_OUT_ID              0
606 #define LOG_ERR_ID              1
607 #define NUM_LOGS                2
608
609 #define STRING_PARENT_DIRECTORY         ".."
610 #define STRING_TOP_DIRECTORY            "/"
611
612 #define CHAR_PATH_SEPARATOR_UNIX        '/'
613 #define CHAR_PATH_SEPARATOR_DOS         '\\'
614
615 #define STRING_PATH_SEPARATOR_UNIX      "/"
616 #define STRING_PATH_SEPARATOR_DOS       "\\"
617
618 #define STRING_NEWLINE_UNIX             "\n"
619 #define STRING_NEWLINE_DOS              "\r\n"
620
621 #if defined(PLATFORM_WIN32)
622 #define CHAR_PATH_SEPARATOR     CHAR_PATH_SEPARATOR_DOS
623 #define STRING_PATH_SEPARATOR   STRING_PATH_SEPARATOR_DOS
624 #define STRING_NEWLINE          STRING_NEWLINE_DOS
625 #else
626 #define CHAR_PATH_SEPARATOR     CHAR_PATH_SEPARATOR_UNIX
627 #define STRING_PATH_SEPARATOR   STRING_PATH_SEPARATOR_UNIX
628 #define STRING_NEWLINE          STRING_NEWLINE_UNIX
629 #endif
630
631
632 /* areas in bitmap PIX_DOOR */
633 /* meaning in PIX_DB_DOOR: (3 PAGEs)
634    PAGEX1: 1. buffer for DOOR_1
635    PAGEX2: 2. buffer for DOOR_1
636    PAGEX3: buffer for animations
637 */
638
639 /* these values are hard-coded to be able to use them in initialization */
640 #define DOOR_GFX_PAGE_WIDTH     100     /* should be set to "gfx.dxsize" */
641 #define DOOR_GFX_PAGE_HEIGHT    280     /* should be set to "gfx.dysize" */
642
643 #define DOOR_GFX_PAGESIZE       (DOOR_GFX_PAGE_WIDTH)
644 #define DOOR_GFX_PAGEX1         (0 * DOOR_GFX_PAGESIZE)
645 #define DOOR_GFX_PAGEX2         (1 * DOOR_GFX_PAGESIZE)
646 #define DOOR_GFX_PAGEX3         (2 * DOOR_GFX_PAGESIZE)
647 #define DOOR_GFX_PAGEX4         (3 * DOOR_GFX_PAGESIZE)
648 #define DOOR_GFX_PAGEX5         (4 * DOOR_GFX_PAGESIZE)
649 #define DOOR_GFX_PAGEX6         (5 * DOOR_GFX_PAGESIZE)
650 #define DOOR_GFX_PAGEX7         (6 * DOOR_GFX_PAGESIZE)
651 #define DOOR_GFX_PAGEX8         (7 * DOOR_GFX_PAGESIZE)
652 #define DOOR_GFX_PAGEY1         (0)
653 #define DOOR_GFX_PAGEY2         (DOOR_GFX_PAGE_HEIGHT)
654
655
656 /* macros for version handling */
657 #define VERSION_PART_1(x)       ((x) / 1000000)
658 #define VERSION_PART_2(x)       (((x) % 1000000) / 10000)
659 #define VERSION_PART_3(x)       (((x) % 10000) / 100)
660 #define VERSION_PART_4(x)       ((x) % 100)
661
662 #define VERSION_SUPER(x)        VERSION_PART_1(x)
663 #define VERSION_MAJOR(x)        VERSION_PART_2(x)
664 #define VERSION_MINOR(x)        VERSION_PART_3(x)
665 #define VERSION_PATCH(x)        VERSION_PART_4(x)
666 #define VERSION_IDENT(a,b,c,d)  ((a) * 1000000 + (b) * 10000 + (c) * 100 + (d))
667
668
669 /* macros for parent/child process identification */
670 #if defined(PLATFORM_UNIX)
671 #define IS_PARENT_PROCESS()     (audio.mixer_pid != getpid())
672 #define IS_CHILD_PROCESS()      (audio.mixer_pid == getpid())
673 #define HAS_CHILD_PROCESS()     (audio.mixer_pid > 0)
674 #else
675 #define IS_PARENT_PROCESS()     TRUE
676 #define IS_CHILD_PROCESS()      FALSE
677 #define HAS_CHILD_PROCESS()     FALSE
678 #endif
679
680
681 /* values for artwork type */
682 #define ARTWORK_TYPE_GRAPHICS   0
683 #define ARTWORK_TYPE_SOUNDS     1
684 #define ARTWORK_TYPE_MUSIC      2
685
686 #define NUM_ARTWORK_TYPES       3
687
688
689 /* values for tree type (chosen to match artwork type) */
690 #define TREE_TYPE_UNDEFINED     -1
691 #define TREE_TYPE_GRAPHICS_DIR  ARTWORK_TYPE_GRAPHICS
692 #define TREE_TYPE_SOUNDS_DIR    ARTWORK_TYPE_SOUNDS
693 #define TREE_TYPE_MUSIC_DIR     ARTWORK_TYPE_MUSIC
694 #define TREE_TYPE_LEVEL_DIR     3
695 #define TREE_TYPE_LEVEL_NR      4
696
697 #define NUM_TREE_TYPES          5
698
699 #define INFOTEXT_UNDEFINED      ""
700 #define INFOTEXT_GRAPHICS_DIR   "Custom Graphics"
701 #define INFOTEXT_SOUNDS_DIR     "Custom Sounds"
702 #define INFOTEXT_MUSIC_DIR      "Custom Music"
703 #define INFOTEXT_LEVEL_DIR      "Level Sets"
704 #define INFOTEXT_LEVEL_NR       "Levels"
705
706 #define TREE_INFOTEXT(t)        ((t) == TREE_TYPE_LEVEL_NR ?            \
707                                  INFOTEXT_LEVEL_NR :                    \
708                                  (t) == TREE_TYPE_LEVEL_DIR ?           \
709                                  INFOTEXT_LEVEL_DIR :                   \
710                                  (t) == TREE_TYPE_GRAPHICS_DIR ?        \
711                                  INFOTEXT_GRAPHICS_DIR :                \
712                                  (t) == TREE_TYPE_SOUNDS_DIR ?          \
713                                  INFOTEXT_SOUNDS_DIR :                  \
714                                  (t) == TREE_TYPE_MUSIC_DIR ?           \
715                                  INFOTEXT_MUSIC_DIR :                   \
716                                  INFOTEXT_UNDEFINED)
717
718 /* values for artwork handling */
719 #define LEVELDIR_ARTWORK_SET_PTR(leveldir, type)                        \
720                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
721                                  &(leveldir)->graphics_set :            \
722                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
723                                  &(leveldir)->sounds_set :              \
724                                  &(leveldir)->music_set)
725
726 #define LEVELDIR_ARTWORK_SET(leveldir, type)                            \
727                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
728                                  (leveldir)->graphics_set :             \
729                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
730                                  (leveldir)->sounds_set :               \
731                                  (leveldir)->music_set)
732
733 #define LEVELDIR_ARTWORK_PATH_PTR(leveldir, type)                       \
734                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
735                                  &(leveldir)->graphics_path :           \
736                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
737                                  &(leveldir)->sounds_path :             \
738                                  &(leveldir)->music_path)
739
740 #define LEVELDIR_ARTWORK_PATH(leveldir, type)                           \
741                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
742                                  (leveldir)->graphics_path :            \
743                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
744                                  (leveldir)->sounds_path :              \
745                                  (leveldir)->music_path)
746
747 #define SETUP_ARTWORK_SET(setup, type)                                  \
748                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
749                                  (setup).graphics_set :                 \
750                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
751                                  (setup).sounds_set :                   \
752                                  (setup).music_set)
753
754 #define SETUP_OVERRIDE_ARTWORK(setup, type)                             \
755                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
756                                  (setup).override_level_graphics :      \
757                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
758                                  (setup).override_level_sounds :        \
759                                  (setup).override_level_music)
760
761 #define GFX_OVERRIDE_ARTWORK(type)                                      \
762                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
763                                  gfx.override_level_graphics :          \
764                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
765                                  gfx.override_level_sounds :            \
766                                  gfx.override_level_music)
767
768 #define ARTWORK_FIRST_NODE(artwork, type)                               \
769                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
770                                  (artwork).gfx_first :                  \
771                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
772                                  (artwork).snd_first :                  \
773                                  (artwork).mus_first)
774
775 #define ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type)                   \
776                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
777                                  &(artwork).gfx_current_identifier :    \
778                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
779                                  &(artwork).snd_current_identifier :    \
780                                  &(artwork).mus_current_identifier)
781
782 #define ARTWORK_CURRENT_IDENTIFIER(artwork, type)                       \
783                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
784                                  (artwork).gfx_current_identifier :     \
785                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
786                                  (artwork).snd_current_identifier :     \
787                                  (artwork).mus_current_identifier)
788
789 #define ARTWORKINFO_FILENAME(type)                                      \
790                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
791                                  GRAPHICSINFO_FILENAME :                \
792                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
793                                  SOUNDSINFO_FILENAME :                  \
794                                  (type) == ARTWORK_TYPE_MUSIC ?         \
795                                  MUSICINFO_FILENAME : "")
796
797 #define ARTWORK_DIRECTORY(type)                                         \
798                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
799                                  GRAPHICS_DIRECTORY :                   \
800                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
801                                  SOUNDS_DIRECTORY :                     \
802                                  (type) == ARTWORK_TYPE_MUSIC ?         \
803                                  MUSIC_DIRECTORY : "")
804
805 #define OPTIONS_ARTWORK_DIRECTORY(type)                                 \
806                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
807                                  options.graphics_directory :           \
808                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
809                                  options.sounds_directory :             \
810                                  (type) == ARTWORK_TYPE_MUSIC ?         \
811                                  options.music_directory : "")
812
813 #define UPDATE_BUSY_STATE()                     \
814 {                                               \
815   if (gfx.draw_busy_anim_function != NULL)      \
816     gfx.draw_busy_anim_function();              \
817 }
818
819
820 /* structure definitions */
821
822 struct ProgramInfo
823 {
824   char *command_basepath;       /* path to the program binary */
825   char *command_basename;       /* base filename of the program binary */
826
827   char *config_filename;        /* optional global program config filename */
828
829   char *maindata_path;          /* main game data (installation) directory */
830
831   char *userdata_subdir;        /* personal user game data directory */
832   char *userdata_path;          /* resulting full path to game data directory */
833
834   char *program_title;
835   char *window_title;
836   char *icon_title;
837
838   char *icon_filename;
839
840   char *cookie_prefix;
841
842   char *log_filename[NUM_LOGS];         /* log filenames for out/err messages */
843   FILE *log_file[NUM_LOGS];             /* log file handles for out/err files */
844   FILE *log_file_default[NUM_LOGS];     /* default log file handles (out/err) */
845
846   int version_super;
847   int version_major;
848   int version_minor;
849   int version_patch;
850   int version_ident;
851
852   char *version_string;
853
854   char *(*window_title_function)(void);
855   void (*exit_message_function)(char *, va_list);
856   void (*exit_function)(int);
857
858   boolean global_scores;
859   boolean many_scores_per_name;
860
861   boolean headless;
862 };
863
864 struct OptionInfo
865 {
866   char *server_host;
867   int server_port;
868
869   char *ro_base_directory;
870   char *rw_base_directory;
871   char *level_directory;
872   char *graphics_directory;
873   char *sounds_directory;
874   char *music_directory;
875   char *docs_directory;
876   char *conf_directory;
877
878   char *execute_command;
879
880   char *special_flags;
881
882   boolean mytapes;
883   boolean serveronly;
884   boolean network;
885   boolean verbose;
886   boolean debug;
887 };
888
889 struct VideoSystemInfo
890 {
891   int default_depth;
892   int width, height, depth;
893   int window_width, window_height;
894   int display_width, display_height;
895   int screen_width, screen_height;
896   int screen_xoffset, screen_yoffset;
897
898   boolean fullscreen_available;
899   boolean fullscreen_enabled;
900   boolean fullscreen_initial;
901
902   boolean window_scaling_available;
903   int window_scaling_percent;
904   char *window_scaling_quality;
905   int screen_rendering_mode;
906
907   unsigned int frame_delay;
908   unsigned int frame_delay_value;
909
910   boolean shifted_up;
911   int shifted_up_pos;
912   int shifted_up_pos_last;
913   unsigned int shifted_up_delay;
914   unsigned int shifted_up_delay_value;
915
916   boolean initialized;
917 };
918
919 struct AudioSystemInfo
920 {
921   boolean sound_available;
922   boolean loops_available;
923   boolean music_available;
924
925   boolean sound_enabled;
926   boolean sound_deactivated;    /* for temporarily disabling sound */
927
928   int mixer_pipe[2];
929   int mixer_pid;
930   char *device_name;
931   int device_fd;
932
933   int num_channels;
934   int music_channel;
935   int first_sound_channel;
936 };
937
938 struct FontBitmapInfo
939 {
940   Bitmap *bitmap;
941
942   int src_x, src_y;             /* start position of font characters */
943   int width, height;            /* width / height of font characters */
944
945   int offset_x;                 /* offset to next font character */
946   int offset_y;                 /* offset to next font character */
947
948   int draw_xoffset;             /* offset for drawing font characters */
949   int draw_yoffset;             /* offset for drawing font characters */
950
951   int num_chars;
952   int num_chars_per_line;
953 };
954
955 struct GfxInfo
956 {
957   int sx, sy;
958   int sxsize, sysize;
959   int real_sx, real_sy;
960   int full_sxsize, full_sysize;
961   int scrollbuffer_width, scrollbuffer_height;
962
963   int game_tile_size, standard_tile_size;
964
965   int dx, dy;
966   int dxsize, dysize;
967
968   int vx, vy;
969   int vxsize, vysize;
970
971   int ex, ey;
972   int exsize, eysize;
973
974   int win_xsize, win_ysize;
975
976   int draw_deactivation_mask;
977   int draw_background_mask;
978
979   Bitmap *field_save_buffer;
980
981   Bitmap *background_bitmap;
982   int background_bitmap_mask;
983
984   Bitmap *fade_bitmap_backup;
985   Bitmap *fade_bitmap_source;
986   Bitmap *fade_bitmap_target;
987   Bitmap *fade_bitmap_black;
988
989   int fade_border_source_status;
990   int fade_border_target_status;
991   Bitmap *masked_border_bitmap_ptr;
992
993   Bitmap *final_screen_bitmap;
994
995   boolean clipping_enabled;
996   int clip_x, clip_y;
997   int clip_width, clip_height;
998
999   boolean override_level_graphics;
1000   boolean override_level_sounds;
1001   boolean override_level_music;
1002
1003   boolean draw_init_text;
1004
1005   int num_fonts;
1006   struct FontBitmapInfo *font_bitmap_info;
1007   int (*select_font_function)(int);
1008   int (*get_font_from_token_function)(char *);
1009
1010   int anim_random_frame;
1011
1012   void (*draw_busy_anim_function)(void);
1013   void (*draw_global_anim_function)(int, int);
1014   void (*draw_global_border_function)(int);
1015   void (*draw_tile_cursor_function)(int);
1016
1017   int cursor_mode;
1018 };
1019
1020 struct TileCursorInfo
1021 {
1022   boolean enabled;              /* tile cursor generally enabled or disabled */
1023   boolean active;               /* tile cursor activated (depending on game) */
1024   boolean moving;               /* tile cursor moving to target position */
1025
1026   int xpos, ypos;               /* tile cursor level playfield position */
1027   int x, y;                     /* tile cursor current screen position */
1028   int target_x, target_y;       /* tile cursor target screen position */
1029
1030   int sx, sy;                   /* tile cursor screen start position */
1031 };
1032
1033 struct OverlayInfo
1034 {
1035   boolean enabled;              /* overlay generally enabled or disabled */
1036   boolean active;               /* overlay activated (depending on game mode) */
1037
1038   boolean show_grid;
1039
1040   int grid_xsize;
1041   int grid_ysize;
1042
1043   char grid_button[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
1044   char grid_button_highlight;
1045
1046   int grid_button_action;
1047 };
1048
1049 struct JoystickInfo
1050 {
1051   int status;
1052   int nr[MAX_PLAYERS];          /* joystick number for each player */
1053 };
1054
1055 struct SetupJoystickInfo
1056 {
1057   char *device_name;            /* device name of player's joystick */
1058
1059   int xleft, xmiddle, xright;
1060   int yupper, ymiddle, ylower;
1061   int snap, drop;
1062 };
1063
1064 struct SetupKeyboardInfo
1065 {
1066   Key left, right, up, down;
1067   Key snap, drop;
1068 };
1069
1070 struct SetupTouchInfo
1071 {
1072   char *control_type;
1073   int move_distance;
1074   int drop_distance;
1075
1076   int grid_xsize[2];
1077   int grid_ysize[2];
1078
1079   char grid_button[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE];
1080
1081   int transparency;             /* in percent (0 == opaque, 100 == invisible) */
1082   boolean draw_outlined;
1083   boolean draw_pressed;
1084
1085   boolean grid_initialized;
1086 };
1087
1088 struct SetupInputInfo
1089 {
1090   boolean use_joystick;
1091   struct SetupJoystickInfo joy;
1092   struct SetupKeyboardInfo key;
1093 };
1094
1095 struct SetupEditorInfo
1096 {
1097   boolean el_boulderdash;
1098   boolean el_emerald_mine;
1099   boolean el_emerald_mine_club;
1100   boolean el_more;
1101   boolean el_sokoban;
1102   boolean el_supaplex;
1103   boolean el_diamond_caves;
1104   boolean el_dx_boulderdash;
1105
1106   boolean el_mirror_magic;
1107   boolean el_deflektor;
1108
1109   boolean el_chars;
1110   boolean el_steel_chars;
1111
1112   boolean el_classic;
1113   boolean el_custom;
1114   boolean el_user_defined;
1115   boolean el_dynamic;
1116
1117   boolean el_headlines;
1118
1119   boolean el_by_game;
1120   boolean el_by_type;
1121
1122   boolean show_element_token;
1123
1124   boolean use_template_for_new_levels;
1125 };
1126
1127 struct SetupAutoSetupInfo
1128 {
1129   int editor_zoom_tilesize;
1130 };
1131
1132 struct SetupEditorCascadeInfo
1133 {
1134   boolean el_bd;
1135   boolean el_em;
1136   boolean el_emc;
1137   boolean el_rnd;
1138   boolean el_sb;
1139   boolean el_sp;
1140   boolean el_dc;
1141   boolean el_dx;
1142   boolean el_mm;
1143   boolean el_df;
1144   boolean el_chars;
1145   boolean el_steel_chars;
1146   boolean el_ce;
1147   boolean el_ge;
1148   boolean el_ref;
1149   boolean el_user;
1150   boolean el_dynamic;
1151 };
1152
1153 struct SetupShortcutInfo
1154 {
1155   Key save_game;
1156   Key load_game;
1157   Key toggle_pause;
1158
1159   Key focus_player[MAX_PLAYERS];
1160   Key focus_player_all;
1161
1162   Key tape_eject;
1163   Key tape_extra;
1164   Key tape_stop;
1165   Key tape_pause;
1166   Key tape_record;
1167   Key tape_play;
1168
1169   Key sound_simple;
1170   Key sound_loops;
1171   Key sound_music;
1172
1173   Key snap_left;
1174   Key snap_right;
1175   Key snap_up;
1176   Key snap_down;
1177 };
1178
1179 struct SetupSystemInfo
1180 {
1181   char *sdl_videodriver;
1182   char *sdl_audiodriver;
1183   int audio_fragment_size;
1184 };
1185
1186 struct SetupInternalInfo
1187 {
1188   char *program_title;
1189   char *program_version;
1190   char *program_author;
1191   char *program_email;
1192   char *program_website;
1193   char *program_copyright;
1194   char *program_company;
1195
1196   char *program_icon_file;
1197
1198   char *default_graphics_set;
1199   char *default_sounds_set;
1200   char *default_music_set;
1201
1202   char *fallback_graphics_file;
1203   char *fallback_sounds_file;
1204   char *fallback_music_file;
1205
1206   char *default_level_series;
1207
1208   int default_window_width;
1209   int default_window_height;
1210
1211   boolean choose_from_top_leveldir;
1212   boolean show_scaling_in_title;
1213 };
1214
1215 struct SetupDebugInfo
1216 {
1217   int frame_delay[10];
1218   Key frame_delay_key[10];
1219   boolean frame_delay_use_mod_key;
1220   boolean frame_delay_game_only;
1221   boolean show_frames_per_second;
1222 };
1223
1224 struct SetupInfo
1225 {
1226   char *player_name;
1227
1228   boolean sound;
1229   boolean sound_loops;
1230   boolean sound_music;
1231   boolean sound_simple;
1232   boolean toons;
1233   boolean scroll_delay;
1234   boolean scroll_delay_value;
1235   char *engine_snapshot_mode;
1236   int engine_snapshot_memory;
1237   boolean fade_screens;
1238   boolean autorecord;
1239   boolean show_titlescreen;
1240   boolean quick_doors;
1241   boolean team_mode;
1242   boolean handicap;
1243   boolean skip_levels;
1244   boolean increment_levels;
1245   boolean time_limit;
1246   boolean fullscreen;
1247   int window_scaling_percent;
1248   char *window_scaling_quality;
1249   char *screen_rendering_mode;
1250   boolean ask_on_escape;
1251   boolean ask_on_escape_editor;
1252   boolean quick_switch;
1253   boolean input_on_focus;
1254   boolean prefer_aga_graphics;
1255   int game_frame_delay;
1256   boolean sp_show_border_elements;
1257   boolean small_game_graphics;
1258   boolean show_snapshot_buttons;
1259
1260   char *graphics_set;
1261   char *sounds_set;
1262   char *music_set;
1263   int override_level_graphics;          /* not boolean -- can also be "AUTO" */
1264   int override_level_sounds;            /* not boolean -- can also be "AUTO" */
1265   int override_level_music;             /* not boolean -- can also be "AUTO" */
1266
1267   int volume_simple;
1268   int volume_loops;
1269   int volume_music;
1270
1271   struct SetupAutoSetupInfo auto_setup;
1272   struct SetupEditorInfo editor;
1273   struct SetupEditorCascadeInfo editor_cascade;
1274   struct SetupShortcutInfo shortcut;
1275   struct SetupInputInfo input[MAX_PLAYERS];
1276   struct SetupTouchInfo touch;
1277   struct SetupSystemInfo system;
1278   struct SetupInternalInfo internal;
1279   struct SetupDebugInfo debug;
1280
1281   struct OptionInfo options;
1282 };
1283
1284 struct TreeInfo
1285 {
1286   struct TreeInfo **node_top;           /* topmost node in tree */
1287   struct TreeInfo *node_parent;         /* parent level directory info */
1288   struct TreeInfo *node_group;          /* level group sub-directory info */
1289   struct TreeInfo *next;                /* next level series structure node */
1290
1291   int cl_first;         /* internal control field for setup screen */
1292   int cl_cursor;        /* internal control field for setup screen */
1293
1294   int type;             /* type of tree content */
1295
1296   /* fields for "type == TREE_TYPE_LEVEL_DIR" */
1297
1298   char *subdir;         /* tree info sub-directory basename (may be ".") */
1299   char *fullpath;       /* complete path relative to tree base directory */
1300   char *basepath;       /* absolute base path of tree base directory */
1301   char *identifier;     /* identifier string for configuration files */
1302   char *name;           /* tree info name, as displayed in selection menues */
1303   char *name_sorting;   /* optional sorting name for correct name sorting */
1304   char *author;         /* level or artwork author name */
1305   char *year;           /* optional year of creation for levels or artwork */
1306
1307   char *program_title;     /* optional alternative text for program title */
1308   char *program_copyright; /* optional alternative text for program copyright */
1309   char *program_company;   /* optional alternative text for program company */
1310
1311   char *imported_from;  /* optional comment for imported levels or artwork */
1312   char *imported_by;    /* optional comment for imported levels or artwork */
1313   char *tested_by;      /* optional comment to name people who tested a set */
1314
1315   char *graphics_set_ecs; /* special EMC custom graphics set (ECS graphics) */
1316   char *graphics_set_aga; /* special EMC custom graphics set (AGA graphics) */
1317   char *graphics_set;   /* optional custom graphics set (level tree only) */
1318   char *sounds_set;     /* optional custom sounds set (level tree only) */
1319   char *music_set;      /* optional custom music set (level tree only) */
1320   char *graphics_path;  /* path to optional custom graphics set (level only) */
1321   char *sounds_path;    /* path to optional custom sounds set (level only) */
1322   char *music_path;     /* path to optional custom music set (level only) */
1323
1324   char *level_filename; /* filename of level file (for packed level file) */
1325   char *level_filetype; /* type of levels in level directory or level file */
1326
1327   char *special_flags;  /* flags for special actions performed on level file */
1328
1329   int levels;           /* number of levels in level series */
1330   int first_level;      /* first level number (to allow start with 0 or 1) */
1331   int last_level;       /* last level number (automatically calculated) */
1332   int sort_priority;    /* sort levels by 'sort_priority' and then by name */
1333
1334   boolean latest_engine;/* force level set to use the latest game engine */
1335
1336   boolean level_group;  /* directory contains more level series directories */
1337   boolean parent_link;  /* entry links back to parent directory */
1338   boolean in_user_dir;  /* user defined levels are stored in home directory */
1339   boolean user_defined; /* levels in user directory and marked as "private" */
1340   boolean readonly;     /* readonly levels can not be changed with editor */
1341   boolean handicap;     /* level set has no handicap when set to "false" */
1342   boolean skip_levels;  /* levels can be skipped when set to "true" */
1343
1344   int color;            /* color to use on selection screen for this level */
1345   char *class_desc;     /* description of level series class */
1346   int handicap_level;   /* number of the lowest unsolved level */
1347
1348   char *infotext;       /* optional text to describe the tree type (headline) */
1349 };
1350
1351 typedef struct TreeInfo TreeInfo;
1352 typedef struct TreeInfo LevelDirTree;
1353 typedef struct TreeInfo ArtworkDirTree;
1354 typedef struct TreeInfo GraphicsDirTree;
1355 typedef struct TreeInfo SoundsDirTree;
1356 typedef struct TreeInfo MusicDirTree;
1357
1358 struct ArtworkInfo
1359 {
1360   GraphicsDirTree *gfx_first;
1361   GraphicsDirTree *gfx_current;
1362   SoundsDirTree *snd_first;
1363   SoundsDirTree *snd_current;
1364   MusicDirTree *mus_first;
1365   MusicDirTree *mus_current;
1366
1367   char *gfx_current_identifier;
1368   char *snd_current_identifier;
1369   char *mus_current_identifier;
1370 };
1371
1372 struct ValueTextInfo
1373 {
1374   int value;
1375   char *text;
1376 };
1377
1378 struct ConfigInfo
1379 {
1380   char *token;
1381   char *value;
1382 };
1383
1384 struct ConfigTypeInfo
1385 {
1386   char *token;
1387   char *value;
1388   int type;
1389 };
1390
1391 struct TokenIntPtrInfo
1392 {
1393   char *token;
1394   int *value;
1395 };
1396
1397 struct FileInfo
1398 {
1399   char *token;
1400
1401   char *default_filename;
1402   char *filename;
1403
1404   char **default_parameter;                     /* array of file parameters */
1405   char **parameter;                             /* array of file parameters */
1406
1407   boolean redefined;
1408   boolean fallback_to_default;
1409   boolean default_is_cloned;
1410 };
1411
1412 struct SetupFileList
1413 {
1414   char *token;
1415   char *value;
1416
1417   struct SetupFileList *next;
1418 };
1419
1420 struct ListNodeInfo
1421 {
1422   char *source_filename;                        /* primary key for node list */
1423   int num_references;
1424 };
1425
1426 struct PropertyMapping
1427 {
1428   int base_index;
1429   int ext1_index;
1430   int ext2_index;
1431   int ext3_index;
1432
1433   int artwork_index;
1434 };
1435
1436 struct ArtworkListInfo
1437 {
1438   int type;                                     /* type of artwork */
1439
1440   int num_file_list_entries;
1441   int num_dynamic_file_list_entries;
1442   struct FileInfo *file_list;                   /* static artwork file array */
1443   struct FileInfo *dynamic_file_list;           /* dynamic artwrk file array */
1444
1445   int num_suffix_list_entries;
1446   struct ConfigTypeInfo *suffix_list;           /* parameter suffixes array */
1447
1448   int num_base_prefixes;
1449   int num_ext1_suffixes;
1450   int num_ext2_suffixes;
1451   int num_ext3_suffixes;
1452   char **base_prefixes;                         /* base token prefixes array */
1453   char **ext1_suffixes;                         /* property suffixes array 1 */
1454   char **ext2_suffixes;                         /* property suffixes array 2 */
1455   char **ext3_suffixes;                         /* property suffixes array 3 */
1456
1457   int num_ignore_tokens;
1458   char **ignore_tokens;                         /* file tokens to be ignored */
1459
1460   int num_property_mapping_entries;
1461   struct PropertyMapping *property_mapping;     /* mapping token -> artwork */
1462
1463   int sizeof_artwork_list_entry;
1464
1465   struct ListNodeInfo **artwork_list;           /* static artwork node array */
1466   struct ListNodeInfo **dynamic_artwork_list;   /* dynamic artwrk node array */
1467   struct ListNode *content_list;                /* dynamic artwork node list */
1468
1469   void *(*load_artwork)(char *);                /* constructor function */
1470   void (*free_artwork)(void *);                 /* destructor function */
1471 };
1472
1473 struct XY
1474 {
1475   int x, y;
1476 };
1477
1478 struct XYTileSize
1479 {
1480   int x, y;
1481   int tile_size;
1482 };
1483
1484 struct Rect
1485 {
1486   int x, y;
1487   int width, height;
1488 };
1489
1490 struct RectWithBorder
1491 {
1492   int x, y;
1493   int width, height;
1494   int border_size;
1495 };
1496
1497 struct MenuPosInfo
1498 {
1499   int x, y;
1500   int width, height;
1501   int align, valign;
1502 };
1503
1504 struct DoorPartPosInfo
1505 {
1506   int x, y;
1507   int step_xoffset;
1508   int step_yoffset;
1509   int step_delay;
1510   int start_step;
1511   int start_step_opening;
1512   int start_step_closing;
1513   boolean draw_masked;
1514   int sort_priority;
1515 };
1516
1517 struct TextPosInfo
1518 {
1519   int x, y;
1520   int xoffset;                  /* special case for tape date and time */
1521   int xoffset2;                 /* special case for tape date */
1522   int width, height;
1523   int align, valign;
1524   int size;                     /* also used for suffix ".digits" */
1525   int font, font_alt;
1526   boolean draw_masked;
1527   boolean draw_player;          /* special case for network player buttons */
1528   int sort_priority;            /* also used for suffix ".draw_order" */
1529   int id;
1530
1531   int direction;                /* needed for panel time/health graphics */
1532   int class;                    /* needed for panel time/health graphics */
1533   int style;                    /* needed for panel time/health graphics */
1534 };
1535
1536 struct MouseActionInfo
1537 {
1538   int lx, ly;
1539   int button;
1540   int button_hint;
1541 };
1542
1543 struct LevelStats
1544 {
1545   int played;
1546   int solved;
1547 };
1548
1549
1550 /* ========================================================================= */
1551 /* exported variables                                                        */
1552 /* ========================================================================= */
1553
1554 extern struct ProgramInfo       program;
1555 extern struct OptionInfo        options;
1556 extern struct VideoSystemInfo   video;
1557 extern struct AudioSystemInfo   audio;
1558 extern struct GfxInfo           gfx;
1559 extern struct TileCursorInfo    tile_cursor;
1560 extern struct OverlayInfo       overlay;
1561 extern struct AnimInfo          anim;
1562 extern struct ArtworkInfo       artwork;
1563 extern struct JoystickInfo      joystick;
1564 extern struct SetupInfo         setup;
1565
1566 extern LevelDirTree            *leveldir_first_all;
1567 extern LevelDirTree            *leveldir_first;
1568 extern LevelDirTree            *leveldir_current;
1569 extern int                      level_nr;
1570
1571 extern struct LevelStats        level_stats[];
1572
1573 extern DrawWindow              *window;
1574 extern DrawBuffer              *backbuffer;
1575 extern DrawBuffer              *drawto;
1576
1577 extern int                      button_status;
1578 extern boolean                  motion_status;
1579 extern int                      wheel_steps;
1580 #if defined(TARGET_SDL2)
1581 extern boolean                  keyrepeat_status;
1582 #endif
1583
1584 extern int                      redraw_mask;
1585
1586 extern int                      FrameCounter;
1587
1588
1589 /* function definitions */
1590
1591 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
1592                      char *, int);
1593
1594 void InitScoresInfo();
1595 void SetWindowTitle();
1596
1597 void InitWindowTitleFunction(char *(*window_title_function)(void));
1598 void InitExitMessageFunction(void (*exit_message_function)(char *, va_list));
1599 void InitExitFunction(void (*exit_function)(int));
1600 void InitPlatformDependentStuff(void);
1601 void ClosePlatformDependentStuff(void);
1602
1603 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
1604 void InitGfxTileSizeInfo(int, int);
1605 void InitGfxDoor1Info(int, int, int, int);
1606 void InitGfxDoor2Info(int, int, int, int);
1607 void InitGfxDoor3Info(int, int, int, int);
1608 void InitGfxWindowInfo(int, int);
1609 void InitGfxScrollbufferInfo(int, int);
1610 void InitGfxClipRegion(boolean, int, int, int, int);
1611 void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void));
1612 void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(int, int));
1613 void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int));
1614 void InitGfxDrawTileCursorFunction(void (*draw_tile_cursor_function)(int));
1615 void InitGfxCustomArtworkInfo();
1616 void InitGfxOtherSettings();
1617 void InitTileCursorInfo();
1618 void InitOverlayInfo();
1619 void SetTileCursorEnabled(boolean);
1620 void SetTileCursorActive(boolean);
1621 void SetTileCursorTargetXY(int, int);
1622 void SetTileCursorXY(int, int);
1623 void SetTileCursorSXSY(int, int);
1624 void SetOverlayEnabled(boolean);
1625 void SetOverlayActive(boolean);
1626 void SetOverlayShowGrid(boolean);
1627 boolean GetOverlayActive();
1628 void SetDrawDeactivationMask(int);
1629 int GetDrawDeactivationMask(void);
1630 void SetDrawBackgroundMask(int);
1631 void SetWindowBackgroundBitmap(Bitmap *);
1632 void SetMainBackgroundBitmap(Bitmap *);
1633 void SetDoorBackgroundBitmap(Bitmap *);
1634 void SetRedrawMaskFromArea(int, int, int, int);
1635
1636 void LimitScreenUpdates(boolean);
1637
1638 void InitVideoDefaults(void);
1639 void InitVideoDisplay(void);
1640 void CloseVideoDisplay(void);
1641 void InitVideoBuffer(int, int, int, boolean);
1642 Bitmap *CreateBitmapStruct(void);
1643 Bitmap *CreateBitmap(int, int, int);
1644 void ReCreateBitmap(Bitmap **, int, int);
1645 void FreeBitmap(Bitmap *);
1646 void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
1647 void BlitBitmapTiled(Bitmap *, Bitmap *, int, int, int, int, int, int, int,int);
1648 void FadeRectangle(int, int, int, int, int, int, int,
1649                    void (*draw_border_function)(void));
1650 void FillRectangle(Bitmap *, int, int, int, int, Pixel);
1651 void ClearRectangle(Bitmap *, int, int, int, int);
1652 void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
1653 void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
1654 boolean DrawingDeactivatedField(void);
1655 boolean DrawingDeactivated(int, int, int, int);
1656 boolean DrawingOnBackground(int, int);
1657 boolean DrawingAreaChanged();
1658 void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int, int);
1659 void BlitTexture(Bitmap *, int, int, int, int, int, int);
1660 void BlitTextureMasked(Bitmap *, int, int, int, int, int, int);
1661 void BlitToScreen(Bitmap *, int, int, int, int, int, int);
1662 void BlitToScreenMasked(Bitmap *, int, int, int, int, int, int);
1663 void DrawSimpleBlackLine(Bitmap *, int, int, int, int);
1664 void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
1665 void DrawLines(Bitmap *, struct XY *, int, Pixel);
1666 Pixel GetPixel(Bitmap *, int, int);
1667 Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
1668 Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
1669
1670 void KeyboardAutoRepeatOn(void);
1671 void KeyboardAutoRepeatOff(void);
1672 boolean SetVideoMode(boolean);
1673 void SetVideoFrameDelay(unsigned int);
1674 unsigned int GetVideoFrameDelay();
1675 boolean ChangeVideoModeIfNeeded(boolean);
1676
1677 Bitmap *LoadImage(char *);
1678 Bitmap *LoadCustomImage(char *);
1679 void ReloadCustomImage(Bitmap *, char *);
1680
1681 void ReCreateGameTileSizeBitmap(Bitmap **);
1682 void CreateBitmapWithSmallBitmaps(Bitmap **, int, int);
1683 void CreateBitmapTextures(Bitmap **);
1684 void FreeBitmapTextures(Bitmap **);
1685 void ScaleBitmap(Bitmap **, int);
1686
1687 void SetMouseCursor(int);
1688
1689 void OpenAudio(void);
1690 void CloseAudio(void);
1691 void SetAudioMode(boolean);
1692
1693 boolean PendingEvent(void);
1694 void WaitEvent(Event *event);
1695 void PeekEvent(Event *event);
1696 void CheckQuitEvent(void);
1697 Key GetEventKey(KeyEvent *, boolean);
1698 KeyMod HandleKeyModState(Key, int);
1699 KeyMod GetKeyModState();
1700 KeyMod GetKeyModStateFromEvents();
1701 void StartTextInput(int, int, int, int);
1702 void StopTextInput();
1703 boolean CheckCloseWindowEvent(ClientMessageEvent *);
1704
1705 void InitJoysticks();
1706 boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
1707 boolean CheckJoystickOpened(int);
1708 void ClearJoystickState();
1709
1710 #endif /* SYSTEM_H */