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