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