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