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