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