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