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