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