added setup value for maximum allowed engine snapshot memory usage
[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_backup;
841   Bitmap *fade_bitmap_source;
842   Bitmap *fade_bitmap_target;
843   Bitmap *fade_bitmap_black;
844
845   int fade_border_source_status;
846   int fade_border_target_status;
847   Bitmap *masked_border_bitmap_ptr;
848
849   Bitmap *final_screen_bitmap;
850
851   boolean clipping_enabled;
852   int clip_x, clip_y;
853   int clip_width, clip_height;
854
855   boolean override_level_graphics;
856   boolean override_level_sounds;
857   boolean override_level_music;
858
859   boolean draw_init_text;
860
861   int num_fonts;
862   struct FontBitmapInfo *font_bitmap_info;
863   int (*select_font_function)(int);
864   int (*get_font_from_token_function)(char *);
865
866   int anim_random_frame;
867
868   void (*draw_busy_anim_function)(void);
869   void (*draw_global_anim_function)(int, int);
870   void (*draw_global_border_function)(int);
871
872   int cursor_mode;
873 };
874
875 struct JoystickInfo
876 {
877   int status;
878   int fd[MAX_PLAYERS];          /* file descriptor of player's joystick */
879 };
880
881 struct SetupJoystickInfo
882 {
883   char *device_name;            /* device name of player's joystick */
884
885   int xleft, xmiddle, xright;
886   int yupper, ymiddle, ylower;
887   int snap, drop;
888 };
889
890 struct SetupKeyboardInfo
891 {
892   Key left, right, up, down;
893   Key snap, drop;
894 };
895
896 struct SetupTouchInfo
897 {
898   char *control_type;
899   int move_distance;
900   int drop_distance;
901 };
902
903 struct SetupInputInfo
904 {
905   boolean use_joystick;
906   struct SetupJoystickInfo joy;
907   struct SetupKeyboardInfo key;
908 };
909
910 struct SetupEditorInfo
911 {
912   boolean el_boulderdash;
913   boolean el_emerald_mine;
914   boolean el_emerald_mine_club;
915   boolean el_more;
916   boolean el_sokoban;
917   boolean el_supaplex;
918   boolean el_diamond_caves;
919   boolean el_dx_boulderdash;
920   boolean el_chars;
921   boolean el_steel_chars;
922   boolean el_custom;
923   boolean el_user_defined;
924   boolean el_dynamic;
925
926   boolean el_headlines;
927
928   boolean el_by_game;
929   boolean el_by_type;
930
931   boolean show_element_token;
932 };
933
934 struct SetupEditorCascadeInfo
935 {
936   boolean el_bd;
937   boolean el_em;
938   boolean el_emc;
939   boolean el_rnd;
940   boolean el_sb;
941   boolean el_sp;
942   boolean el_dc;
943   boolean el_dx;
944   boolean el_chars;
945   boolean el_steel_chars;
946   boolean el_ce;
947   boolean el_ge;
948   boolean el_ref;
949   boolean el_user;
950   boolean el_dynamic;
951 };
952
953 struct SetupShortcutInfo
954 {
955   Key save_game;
956   Key load_game;
957   Key toggle_pause;
958
959   Key focus_player[MAX_PLAYERS];
960   Key focus_player_all;
961
962   Key tape_eject;
963   Key tape_extra;
964   Key tape_stop;
965   Key tape_pause;
966   Key tape_record;
967   Key tape_play;
968
969   Key sound_simple;
970   Key sound_loops;
971   Key sound_music;
972
973   Key snap_left;
974   Key snap_right;
975   Key snap_up;
976   Key snap_down;
977 };
978
979 struct SetupSystemInfo
980 {
981   char *sdl_videodriver;
982   char *sdl_audiodriver;
983   int audio_fragment_size;
984 };
985
986 struct SetupInternalInfo
987 {
988   char *program_title;
989   char *program_author;
990   char *program_email;
991   char *program_website;
992   char *program_copyright;
993   char *program_company;
994
995   char *program_icon_file;
996
997   char *default_graphics_set;
998   char *default_sounds_set;
999   char *default_music_set;
1000
1001   char *fallback_graphics_file;
1002   char *fallback_sounds_file;
1003   char *fallback_music_file;
1004
1005   char *default_level_series;
1006
1007   int default_window_width;
1008   int default_window_height;
1009
1010   boolean choose_from_top_leveldir;
1011 };
1012
1013 struct SetupInfo
1014 {
1015   char *player_name;
1016
1017   boolean sound;
1018   boolean sound_loops;
1019   boolean sound_music;
1020   boolean sound_simple;
1021   boolean toons;
1022   boolean scroll_delay;
1023   boolean scroll_delay_value;
1024   char *engine_snapshot_mode;
1025   int engine_snapshot_memory;
1026   boolean fade_screens;
1027   boolean autorecord;
1028   boolean show_titlescreen;
1029   boolean quick_doors;
1030   boolean team_mode;
1031   boolean handicap;
1032   boolean skip_levels;
1033   boolean time_limit;
1034   boolean fullscreen;
1035   int window_scaling_percent;
1036   char *window_scaling_quality;
1037   char *screen_rendering_mode;
1038   boolean ask_on_escape;
1039   boolean ask_on_escape_editor;
1040   boolean quick_switch;
1041   boolean input_on_focus;
1042   boolean prefer_aga_graphics;
1043   int game_frame_delay;
1044   boolean sp_show_border_elements;
1045   boolean small_game_graphics;
1046   boolean show_snapshot_buttons;
1047
1048   char *graphics_set;
1049   char *sounds_set;
1050   char *music_set;
1051   int override_level_graphics;          /* not boolean -- can also be "AUTO" */
1052   int override_level_sounds;            /* not boolean -- can also be "AUTO" */
1053   int override_level_music;             /* not boolean -- can also be "AUTO" */
1054
1055   int volume_simple;
1056   int volume_loops;
1057   int volume_music;
1058
1059   struct SetupEditorInfo editor;
1060   struct SetupEditorCascadeInfo editor_cascade;
1061   struct SetupShortcutInfo shortcut;
1062   struct SetupInputInfo input[MAX_PLAYERS];
1063   struct SetupTouchInfo touch;
1064   struct SetupSystemInfo system;
1065   struct SetupInternalInfo internal;
1066   struct OptionInfo options;
1067 };
1068
1069 struct TreeInfo
1070 {
1071   struct TreeInfo **node_top;           /* topmost node in tree */
1072   struct TreeInfo *node_parent;         /* parent level directory info */
1073   struct TreeInfo *node_group;          /* level group sub-directory info */
1074   struct TreeInfo *next;                /* next level series structure node */
1075
1076   int cl_first;         /* internal control field for setup screen */
1077   int cl_cursor;        /* internal control field for setup screen */
1078
1079   int type;             /* type of tree content */
1080
1081   /* fields for "type == TREE_TYPE_LEVEL_DIR" */
1082
1083   char *subdir;         /* tree info sub-directory basename (may be ".") */
1084   char *fullpath;       /* complete path relative to tree base directory */
1085   char *basepath;       /* absolute base path of tree base directory */
1086   char *identifier;     /* identifier string for configuration files */
1087   char *name;           /* tree info name, as displayed in selection menues */
1088   char *name_sorting;   /* optional sorting name for correct name sorting */
1089   char *author;         /* level or artwork author name */
1090   char *year;           /* optional year of creation for levels or artwork */
1091   char *imported_from;  /* optional comment for imported levels or artwork */
1092   char *imported_by;    /* optional comment for imported levels or artwork */
1093   char *tested_by;      /* optional comment to name people who tested a set */
1094
1095   char *graphics_set_ecs; /* special EMC custom graphics set (ECS graphics) */
1096   char *graphics_set_aga; /* special EMC custom graphics set (AGA graphics) */
1097   char *graphics_set;   /* optional custom graphics set (level tree only) */
1098   char *sounds_set;     /* optional custom sounds set (level tree only) */
1099   char *music_set;      /* optional custom music set (level tree only) */
1100   char *graphics_path;  /* path to optional custom graphics set (level only) */
1101   char *sounds_path;    /* path to optional custom sounds set (level only) */
1102   char *music_path;     /* path to optional custom music set (level only) */
1103
1104   char *level_filename; /* filename of level file (for packed level file) */
1105   char *level_filetype; /* type of levels in level directory or level file */
1106
1107   char *special_flags;  /* flags for special actions performed on level file */
1108
1109   int levels;           /* number of levels in level series */
1110   int first_level;      /* first level number (to allow start with 0 or 1) */
1111   int last_level;       /* last level number (automatically calculated) */
1112   int sort_priority;    /* sort levels by 'sort_priority' and then by name */
1113
1114   boolean latest_engine;/* force level set to use the latest game engine */
1115
1116   boolean level_group;  /* directory contains more level series directories */
1117   boolean parent_link;  /* entry links back to parent directory */
1118   boolean in_user_dir;  /* user defined levels are stored in home directory */
1119   boolean user_defined; /* levels in user directory and marked as "private" */
1120   boolean readonly;     /* readonly levels can not be changed with editor */
1121   boolean handicap;     /* level set has no handicap when set to "false" */
1122   boolean skip_levels;  /* levels can be skipped when set to "true" */
1123
1124   int color;            /* color to use on selection screen for this level */
1125   char *class_desc;     /* description of level series class */
1126   int handicap_level;   /* number of the lowest unsolved level */
1127
1128   char *infotext;       /* optional text to describe the tree type (headline) */
1129 };
1130
1131 typedef struct TreeInfo TreeInfo;
1132 typedef struct TreeInfo LevelDirTree;
1133 typedef struct TreeInfo ArtworkDirTree;
1134 typedef struct TreeInfo GraphicsDirTree;
1135 typedef struct TreeInfo SoundsDirTree;
1136 typedef struct TreeInfo MusicDirTree;
1137
1138 struct ArtworkInfo
1139 {
1140   GraphicsDirTree *gfx_first;
1141   GraphicsDirTree *gfx_current;
1142   SoundsDirTree *snd_first;
1143   SoundsDirTree *snd_current;
1144   MusicDirTree *mus_first;
1145   MusicDirTree *mus_current;
1146
1147   char *gfx_current_identifier;
1148   char *snd_current_identifier;
1149   char *mus_current_identifier;
1150 };
1151
1152 struct ValueTextInfo
1153 {
1154   int value;
1155   char *text;
1156 };
1157
1158 struct ConfigInfo
1159 {
1160   char *token;
1161   char *value;
1162 };
1163
1164 struct ConfigTypeInfo
1165 {
1166   char *token;
1167   char *value;
1168   int type;
1169 };
1170
1171 struct TokenIntPtrInfo
1172 {
1173   char *token;
1174   int *value;
1175 };
1176
1177 struct FileInfo
1178 {
1179   char *token;
1180
1181   char *default_filename;
1182   char *filename;
1183
1184   char **default_parameter;                     /* array of file parameters */
1185   char **parameter;                             /* array of file parameters */
1186
1187   boolean redefined;
1188   boolean fallback_to_default;
1189   boolean default_is_cloned;
1190 };
1191
1192 struct SetupFileList
1193 {
1194   char *token;
1195   char *value;
1196
1197   struct SetupFileList *next;
1198 };
1199
1200 struct ListNodeInfo
1201 {
1202   char *source_filename;                        /* primary key for node list */
1203   int num_references;
1204 };
1205
1206 struct PropertyMapping
1207 {
1208   int base_index;
1209   int ext1_index;
1210   int ext2_index;
1211   int ext3_index;
1212
1213   int artwork_index;
1214 };
1215
1216 struct ArtworkListInfo
1217 {
1218   int type;                                     /* type of artwork */
1219
1220   int num_file_list_entries;
1221   int num_dynamic_file_list_entries;
1222   struct FileInfo *file_list;                   /* static artwork file array */
1223   struct FileInfo *dynamic_file_list;           /* dynamic artwrk file array */
1224
1225   int num_suffix_list_entries;
1226   struct ConfigTypeInfo *suffix_list;           /* parameter suffixes array */
1227
1228   int num_base_prefixes;
1229   int num_ext1_suffixes;
1230   int num_ext2_suffixes;
1231   int num_ext3_suffixes;
1232   char **base_prefixes;                         /* base token prefixes array */
1233   char **ext1_suffixes;                         /* property suffixes array 1 */
1234   char **ext2_suffixes;                         /* property suffixes array 2 */
1235   char **ext3_suffixes;                         /* property suffixes array 3 */
1236
1237   int num_ignore_tokens;
1238   char **ignore_tokens;                         /* file tokens to be ignored */
1239
1240   int num_property_mapping_entries;
1241   struct PropertyMapping *property_mapping;     /* mapping token -> artwork */
1242
1243   int sizeof_artwork_list_entry;
1244
1245   struct ListNodeInfo **artwork_list;           /* static artwork node array */
1246   struct ListNodeInfo **dynamic_artwork_list;   /* dynamic artwrk node array */
1247   struct ListNode *content_list;                /* dynamic artwork node list */
1248
1249   void *(*load_artwork)(char *);                /* constructor function */
1250   void (*free_artwork)(void *);                 /* destructor function */
1251 };
1252
1253 struct XY
1254 {
1255   int x, y;
1256 };
1257
1258 struct Rect
1259 {
1260   int x, y;
1261   int width, height;
1262 };
1263
1264 struct RectWithBorder
1265 {
1266   int x, y;
1267   int width, height;
1268   int border_size;
1269 };
1270
1271 struct MenuPosInfo
1272 {
1273   int x, y;
1274   int width, height;
1275   int align, valign;
1276 };
1277
1278 struct DoorPartPosInfo
1279 {
1280   int x, y;
1281   int step_xoffset;
1282   int step_yoffset;
1283   int step_delay;
1284   int start_step;
1285   int start_step_opening;
1286   int start_step_closing;
1287   boolean draw_masked;
1288   int sort_priority;
1289 };
1290
1291 struct TextPosInfo
1292 {
1293   int x, y;
1294   int xoffset;                  /* special case for tape date and time */
1295   int xoffset2;                 /* special case for tape date */
1296   int width, height;
1297   int align, valign;
1298   int size;                     /* also used for suffix ".digits" */
1299   int font, font_alt;
1300   boolean draw_masked;
1301   boolean draw_player;          /* special case for network player buttons */
1302   int sort_priority;            /* also used for suffix ".draw_order" */
1303   int id;
1304 };
1305
1306 struct LevelStats
1307 {
1308   int played;
1309   int solved;
1310 };
1311
1312
1313 /* ========================================================================= */
1314 /* exported variables                                                        */
1315 /* ========================================================================= */
1316
1317 extern struct ProgramInfo       program;
1318 extern struct OptionInfo        options;
1319 extern struct VideoSystemInfo   video;
1320 extern struct AudioSystemInfo   audio;
1321 extern struct GfxInfo           gfx;
1322 extern struct AnimInfo          anim;
1323 extern struct ArtworkInfo       artwork;
1324 extern struct JoystickInfo      joystick;
1325 extern struct SetupInfo         setup;
1326
1327 extern LevelDirTree            *leveldir_first_all;
1328 extern LevelDirTree            *leveldir_first;
1329 extern LevelDirTree            *leveldir_current;
1330 extern int                      level_nr;
1331
1332 extern struct LevelStats        level_stats[];
1333
1334 extern DrawWindow              *window;
1335 extern DrawBuffer              *backbuffer;
1336 extern DrawBuffer              *drawto;
1337
1338 extern int                      button_status;
1339 extern boolean                  motion_status;
1340 #if defined(TARGET_SDL2)
1341 extern boolean                  keyrepeat_status;
1342 #endif
1343
1344 extern int                      redraw_mask;
1345
1346 extern int                      FrameCounter;
1347
1348
1349 /* function definitions */
1350
1351 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
1352                      int);
1353
1354 void SetWindowTitle();
1355
1356 void InitWindowTitleFunction(char *(*window_title_function)(void));
1357 void InitExitMessageFunction(void (*exit_message_function)(char *, va_list));
1358 void InitExitFunction(void (*exit_function)(int));
1359 void InitPlatformDependentStuff(void);
1360 void ClosePlatformDependentStuff(void);
1361
1362 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
1363 void InitGfxTileSizeInfo(int, int);
1364 void InitGfxDoor1Info(int, int, int, int);
1365 void InitGfxDoor2Info(int, int, int, int);
1366 void InitGfxDoor3Info(int, int, int, int);
1367 void InitGfxWindowInfo(int, int);
1368 void InitGfxScrollbufferInfo(int, int);
1369 void InitGfxClipRegion(boolean, int, int, int, int);
1370 void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void));
1371 void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(int, int));
1372 void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int));
1373 void InitGfxCustomArtworkInfo();
1374 void InitGfxOtherSettings();
1375 void SetDrawDeactivationMask(int);
1376 void SetDrawBackgroundMask(int);
1377 void SetWindowBackgroundBitmap(Bitmap *);
1378 void SetMainBackgroundBitmap(Bitmap *);
1379 void SetDoorBackgroundBitmap(Bitmap *);
1380 void SetRedrawMaskFromArea(int, int, int, int);
1381
1382 void LimitScreenUpdates(boolean);
1383
1384 void InitVideoDisplay(void);
1385 void CloseVideoDisplay(void);
1386 void InitVideoBuffer(int, int, int, boolean);
1387 Bitmap *CreateBitmapStruct(void);
1388 Bitmap *CreateBitmap(int, int, int);
1389 void ReCreateBitmap(Bitmap **, int, int);
1390 void FreeBitmap(Bitmap *);
1391 void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
1392 void BlitBitmapTiled(Bitmap *, Bitmap *, int, int, int, int, int, int, int,int);
1393 void FadeRectangle(int, int, int, int, int, int, int,
1394                    void (*draw_border_function)(void));
1395 void FillRectangle(Bitmap *, int, int, int, int, Pixel);
1396 void ClearRectangle(Bitmap *, int, int, int, int);
1397 void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
1398 void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
1399 boolean DrawingDeactivated(int, int, int, int);
1400 boolean DrawingOnBackground(int, int);
1401 boolean DrawingAreaChanged();
1402 void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int, int);
1403 void BlitTexture(Bitmap *, int, int, int, int, int, int);
1404 void BlitTextureMasked(Bitmap *, int, int, int, int, int, int);
1405 void BlitToScreen(Bitmap *, int, int, int, int, int, int);
1406 void BlitToScreenMasked(Bitmap *, int, int, int, int, int, int);
1407 void DrawSimpleBlackLine(Bitmap *, int, int, int, int);
1408 void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
1409 void DrawLines(Bitmap *, struct XY *, int, Pixel);
1410 Pixel GetPixel(Bitmap *, int, int);
1411 Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
1412 Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
1413
1414 void KeyboardAutoRepeatOn(void);
1415 void KeyboardAutoRepeatOff(void);
1416 boolean SetVideoMode(boolean);
1417 void SetVideoFrameDelay(unsigned int);
1418 unsigned int GetVideoFrameDelay();
1419 boolean ChangeVideoModeIfNeeded(boolean);
1420
1421 Bitmap *LoadImage(char *);
1422 Bitmap *LoadCustomImage(char *);
1423 void ReloadCustomImage(Bitmap *, char *);
1424
1425 Bitmap *ZoomBitmap(Bitmap *, int, int);
1426 void ReCreateGameTileSizeBitmap(Bitmap **);
1427 void CreateBitmapWithSmallBitmaps(Bitmap **, int, int);
1428 void CreateBitmapTextures(Bitmap **);
1429 void FreeBitmapTextures(Bitmap **);
1430 void ScaleBitmap(Bitmap **, int);
1431
1432 void SetMouseCursor(int);
1433
1434 void OpenAudio(void);
1435 void CloseAudio(void);
1436 void SetAudioMode(boolean);
1437
1438 void InitEventFilter(EventFilter);
1439 boolean PendingEvent(void);
1440 void NextEvent(Event *event);
1441 void PeekEvent(Event *event);
1442 Key GetEventKey(KeyEvent *, boolean);
1443 KeyMod HandleKeyModState(Key, int);
1444 KeyMod GetKeyModState();
1445 KeyMod GetKeyModStateFromEvents();
1446 boolean CheckCloseWindowEvent(ClientMessageEvent *);
1447
1448 void InitJoysticks();
1449 boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
1450
1451 #endif /* SYSTEM_H */