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