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