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