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