added graphics animation mode "random_static" (unchanged for each tile)
[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 //                  https://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 #elif defined(PLATFORM_EMSCRIPTEN)
26 #include "emscripten.h"
27 #endif
28
29 #include "sdl.h"
30
31
32 // the additional 'b' is needed for Win32 to open files in binary mode
33 #define MODE_READ                       "rb"
34 #define MODE_WRITE                      "wb"
35 #define MODE_APPEND                     "ab"
36
37 #define DEFAULT_DEPTH                   0
38
39 #define BLIT_OPAQUE                     0
40 #define BLIT_MASKED                     1
41 #define BLIT_INVERSE                    2
42 #define BLIT_ON_BACKGROUND              3
43
44 // values for fullscreen status
45 #define FULLSCREEN_NOT_AVAILABLE        FALSE
46 #define FULLSCREEN_AVAILABLE            TRUE
47
48 // values for window scaling
49 #define WINDOW_SCALING_NOT_AVAILABLE    FALSE
50 #define WINDOW_SCALING_AVAILABLE        TRUE
51
52 #define MIN_WINDOW_SCALING_PERCENT      30
53 #define STD_WINDOW_SCALING_PERCENT      100
54 #define MAX_WINDOW_SCALING_PERCENT      400
55 #define STEP_WINDOW_SCALING_PERCENT     10
56
57 // values for window scaling quality
58 #define SCALING_QUALITY_NEAREST         "nearest"
59 #define SCALING_QUALITY_LINEAR          "linear"
60 #define SCALING_QUALITY_BEST            "best"
61
62 #define SCALING_QUALITY_DEFAULT         SCALING_QUALITY_LINEAR
63
64 // values for screen rendering mode
65 #define STR_SPECIAL_RENDERING_OFF       "stream_texture_only"
66 #define STR_SPECIAL_RENDERING_BITMAP    "bitmap_and_stream_texture"
67 #define STR_SPECIAL_RENDERING_TARGET    "target_texture_only"
68 #define STR_SPECIAL_RENDERING_DOUBLE    "stream_and_target_texture"
69
70 #if defined(PLATFORM_EMSCRIPTEN)
71 #define STR_SPECIAL_RENDERING_DEFAULT   STR_SPECIAL_RENDERING_BITMAP
72 #else
73 #define STR_SPECIAL_RENDERING_DEFAULT   STR_SPECIAL_RENDERING_DOUBLE
74 #endif
75
76 #define SPECIAL_RENDERING_OFF           0
77 #define SPECIAL_RENDERING_BITMAP        1
78 #define SPECIAL_RENDERING_TARGET        2
79 #define SPECIAL_RENDERING_DOUBLE        3
80
81 // values for vertical screen retrace synchronization (vsync)
82 #define STR_VSYNC_MODE_OFF              "off"
83 #define STR_VSYNC_MODE_NORMAL           "normal"
84 #define STR_VSYNC_MODE_ADAPTIVE         "adaptive"
85
86 #define STR_VSYNC_MODE_DEFAULT          STR_VSYNC_MODE_OFF
87
88 #define VSYNC_MODE_OFF                  0
89 #define VSYNC_MODE_NORMAL               1
90 #define VSYNC_MODE_ADAPTIVE             -1
91
92 #define VSYNC_MODE_DEFAULT              VSYNC_MODE_OFF
93
94 #define VSYNC_MODE_STR_TO_INT(s)                                        \
95   (strEqual((s), STR_VSYNC_MODE_NORMAL)         ? VSYNC_MODE_NORMAL :   \
96    strEqual((s), STR_VSYNC_MODE_ADAPTIVE)       ? VSYNC_MODE_ADAPTIVE : \
97    VSYNC_MODE_OFF)
98
99 #define VSYNC_MODE_INT_TO_STR(i)                                        \
100   ((i) == VSYNC_MODE_NORMAL             ? STR_VSYNC_MODE_NORMAL :       \
101    (i) == VSYNC_MODE_ADAPTIVE           ? STR_VSYNC_MODE_ADAPTIVE :     \
102    STR_VSYNC_MODE_OFF)
103
104 // values for network server settings
105 #define STR_NETWORK_AUTO_DETECT         "auto_detect_network_server"
106 #define STR_NETWORK_AUTO_DETECT_SETUP   "(auto detect network server)"
107
108 // values for API server settings
109 #define API_SERVER_HOSTNAME             "api.artsoft.org"
110 #define API_SERVER_PORT                 80
111 #define API_SERVER_METHOD               "POST"
112 #define API_SERVER_URI_ADD              "/api/scores/add"
113 #define API_SERVER_URI_GET              "/api/scores/get"
114 #define API_SERVER_URI_RENAME           "/api/players/rename"
115 #define API_SERVER_URI_RESETUUID        "/api/players/resetuuid"
116
117 #if defined(TESTING)
118 #undef API_SERVER_HOSTNAME
119 #define API_SERVER_HOSTNAME             "api-test.artsoft.org"
120 #define TEST_PREFIX                     "test."
121 #else
122 #define TEST_PREFIX                     ""
123 #endif
124
125 // values for touch control
126 #define TOUCH_CONTROL_OFF               "off"
127 #define TOUCH_CONTROL_VIRTUAL_BUTTONS   "virtual_buttons"
128 #define TOUCH_CONTROL_WIPE_GESTURES     "wipe_gestures"
129 #define TOUCH_CONTROL_FOLLOW_FINGER     "follow_finger"
130
131 #if defined(PLATFORM_ANDROID)
132 #define TOUCH_CONTROL_DEFAULT           TOUCH_CONTROL_VIRTUAL_BUTTONS
133 #else
134 #define TOUCH_CONTROL_DEFAULT           TOUCH_CONTROL_OFF
135 #endif
136
137 #define TOUCH_MOVE_DISTANCE_DEFAULT     2
138 #define TOUCH_DROP_DISTANCE_DEFAULT     5
139 #define TOUCH_TRANSPARENCY_DEFAULT      50
140
141 #define ALPHA_FROM_TRANSPARENCY(x)      ((100 - x) * SDL_ALPHA_OPAQUE / 100)
142 #define ALPHA_FADING_STEPSIZE(x)        ((x) / 25)
143
144 // values for special settings for mobile devices
145 #if defined(PLATFORM_ANDROID)
146 #define HAS_TOUCH_DEVICE
147 #define USE_TOUCH_INPUT_OVERLAY
148 #define USE_COMPLETE_DISPLAY
149 #define HAS_SCREEN_KEYBOARD
150 #define SCREEN_KEYBOARD_POS(h)          ((h) / 2)
151 #endif
152
153 // values for drag-and-drop support (some parts not added before SDL 2.0.5)
154 #if !SDL_VERSION_ATLEAST(2,0,5)
155 #define SDL_DROPTEXT                    (SDL_DROPFILE + 1)
156 #define SDL_DROPBEGIN                   (SDL_DROPFILE + 2)
157 #define SDL_DROPCOMPLETE                (SDL_DROPFILE + 3)
158 #endif
159
160 // default input keys
161 #define DEFAULT_KEY_LEFT                KSYM_Left
162 #define DEFAULT_KEY_RIGHT               KSYM_Right
163 #define DEFAULT_KEY_UP                  KSYM_Up
164 #define DEFAULT_KEY_DOWN                KSYM_Down
165 #if defined(PLATFORM_MACOSX)
166 #define DEFAULT_KEY_SNAP                KSYM_Control_L
167 #define DEFAULT_KEY_DROP                KSYM_KP_Enter
168 #else
169 #define DEFAULT_KEY_SNAP                KSYM_Control_L
170 #define DEFAULT_KEY_DROP                KSYM_Control_R
171 #endif
172 #define DEFAULT_KEY_OKAY                KSYM_Return
173 #define DEFAULT_KEY_CANCEL              KSYM_Escape
174
175 // default shortcut keys
176 #define DEFAULT_KEY_SAVE_GAME           KSYM_F1
177 #define DEFAULT_KEY_LOAD_GAME           KSYM_F2
178 #define DEFAULT_KEY_TOGGLE_PAUSE        KSYM_space
179 #define DEFAULT_KEY_FOCUS_PLAYER_1      KSYM_F5
180 #define DEFAULT_KEY_FOCUS_PLAYER_2      KSYM_F6
181 #define DEFAULT_KEY_FOCUS_PLAYER_3      KSYM_F7
182 #define DEFAULT_KEY_FOCUS_PLAYER_4      KSYM_F8
183 #define DEFAULT_KEY_FOCUS_PLAYER_ALL    KSYM_F9
184 #define DEFAULT_KEY_TAPE_EJECT          KSYM_UNDEFINED
185 #define DEFAULT_KEY_TAPE_EXTRA          KSYM_UNDEFINED
186 #define DEFAULT_KEY_TAPE_STOP           KSYM_UNDEFINED
187 #define DEFAULT_KEY_TAPE_PAUSE          KSYM_UNDEFINED
188 #define DEFAULT_KEY_TAPE_RECORD         KSYM_UNDEFINED
189 #define DEFAULT_KEY_TAPE_PLAY           KSYM_UNDEFINED
190 #define DEFAULT_KEY_SOUND_SIMPLE        KSYM_UNDEFINED
191 #define DEFAULT_KEY_SOUND_LOOPS         KSYM_UNDEFINED
192 #define DEFAULT_KEY_SOUND_MUSIC         KSYM_UNDEFINED
193 #define DEFAULT_KEY_SNAP_LEFT           KSYM_UNDEFINED
194 #define DEFAULT_KEY_SNAP_RIGHT          KSYM_UNDEFINED
195 #define DEFAULT_KEY_SNAP_UP             KSYM_UNDEFINED
196 #define DEFAULT_KEY_SNAP_DOWN           KSYM_UNDEFINED
197
198 // default debug setup keys and values
199 #define DEFAULT_FRAME_DELAY_0           20              // 100 % speed
200 #define DEFAULT_FRAME_DELAY_1           500             // 4 % speed
201 #define DEFAULT_FRAME_DELAY_2           250             // 8 % speed
202 #define DEFAULT_FRAME_DELAY_3           125             // 16 % speed
203 #define DEFAULT_FRAME_DELAY_4           60              // 33 % speed
204 #define DEFAULT_FRAME_DELAY_5           40              // 50 % speed
205 #define DEFAULT_FRAME_DELAY_6           30              // 66 % speed
206 #define DEFAULT_FRAME_DELAY_7           10              // 200 % speed
207 #define DEFAULT_FRAME_DELAY_8           5               // 400 % speed
208 #define DEFAULT_FRAME_DELAY_9           0               // maximum speed
209
210 #define DEFAULT_KEY_FRAME_DELAY_0       KSYM_0
211 #define DEFAULT_KEY_FRAME_DELAY_1       KSYM_1
212 #define DEFAULT_KEY_FRAME_DELAY_2       KSYM_2
213 #define DEFAULT_KEY_FRAME_DELAY_3       KSYM_3
214 #define DEFAULT_KEY_FRAME_DELAY_4       KSYM_4
215 #define DEFAULT_KEY_FRAME_DELAY_5       KSYM_5
216 #define DEFAULT_KEY_FRAME_DELAY_6       KSYM_6
217 #define DEFAULT_KEY_FRAME_DELAY_7       KSYM_7
218 #define DEFAULT_KEY_FRAME_DELAY_8       KSYM_8
219 #define DEFAULT_KEY_FRAME_DELAY_9       KSYM_9
220
221 #define NUM_DEBUG_FRAME_DELAY_KEYS      10
222
223 #define DEFAULT_FRAME_DELAY_USE_MOD_KEY FALSE
224 #define DEFAULT_FRAME_DELAY_GAME_ONLY   TRUE
225
226 // values for key_status
227 #define KEY_NOT_PRESSED                 FALSE
228 #define KEY_RELEASED                    FALSE
229 #define KEY_PRESSED                     TRUE
230
231 // values for button status
232 #define MB_NOT_PRESSED                  FALSE
233 #define MB_NOT_RELEASED                 TRUE
234 #define MB_RELEASED                     FALSE
235 #define MB_PRESSED                      TRUE
236 #define MB_MENU_CHOICE                  FALSE
237 #define MB_MENU_MARK                    TRUE
238 #define MB_MENU_INITIALIZE              (-1)
239 #define MB_MENU_LEAVE                   (-2)
240 #define MB_LEFTBUTTON                   1
241 #define MB_MIDDLEBUTTON                 2
242 #define MB_RIGHTBUTTON                  3
243 #define MB_WHEEL_UP                     4
244 #define MB_WHEEL_DOWN                   5
245 #define MB_WHEEL_LEFT                   6
246 #define MB_WHEEL_RIGHT                  7
247 #define IS_WHEEL_BUTTON_VERTICAL(b)     ((b) == MB_WHEEL_UP ||          \
248                                          (b) == MB_WHEEL_DOWN)
249 #define IS_WHEEL_BUTTON_HORIZONTAL(b)   ((b) == MB_WHEEL_LEFT ||        \
250                                          (b) == MB_WHEEL_RIGHT)
251 #define IS_WHEEL_BUTTON(b)              (IS_WHEEL_BUTTON_VERTICAL(b) || \
252                                          IS_WHEEL_BUTTON_HORIZONTAL(b))
253 #define DEFAULT_WHEEL_STEPS             3
254
255 #define BUTTON_STEPSIZE(b)              ((b) == MB_LEFTBUTTON   ?  1 :  \
256                                          (b) == MB_MIDDLEBUTTON ?  5 :  \
257                                          (b) == MB_RIGHTBUTTON  ? 10 : 1)
258
259 // values for move directions
260 #define MV_BIT_LEFT                     0
261 #define MV_BIT_RIGHT                    1
262 #define MV_BIT_UP                       2
263 #define MV_BIT_DOWN                     3
264
265 #define NUM_DIRECTIONS                  4
266
267 // diagonal movement directions are used in a different contect than buttons
268 #define MV_BIT_UPLEFT                   4
269 #define MV_BIT_UPRIGHT                  5
270 #define MV_BIT_DOWNLEFT                 6
271 #define MV_BIT_DOWNRIGHT                7
272
273 #define NUM_DIRECTIONS_FULL             8
274
275 // values for special "button" bitmasks
276 #define BUTTON_1                        4
277 #define BUTTON_2                        5
278
279 #define NUM_PLAYER_ACTIONS              6
280
281 // values for special "focus player" bitmasks
282 #define BIT_SET_FOCUS                   6
283
284 // values for drawing stages for global animations
285 #define DRAW_GLOBAL_ANIM_STAGE_1        1
286 #define DRAW_GLOBAL_ANIM_STAGE_2        2
287
288 // values for drawing target (various functions)
289 #define DRAW_TO_BACKBUFFER              0
290 #define DRAW_TO_FIELDBUFFER             1
291 #define DRAW_TO_SCREEN                  2
292 #define DRAW_TO_FADE_SOURCE             3
293 #define DRAW_TO_FADE_TARGET             4
294
295 // values for move directions and special "button" key bitmasks
296 #define MV_NONE                 0
297 #define MV_LEFT                 (1 << MV_BIT_LEFT)
298 #define MV_RIGHT                (1 << MV_BIT_RIGHT)
299 #define MV_UP                   (1 << MV_BIT_UP)
300 #define MV_DOWN                 (1 << MV_BIT_DOWN)
301
302 #define MV_UPLEFT               (MV_UP   | MV_LEFT)
303 #define MV_UPRIGHT              (MV_UP   | MV_RIGHT)
304 #define MV_DOWNLEFT             (MV_DOWN | MV_LEFT)
305 #define MV_DOWNRIGHT            (MV_DOWN | MV_RIGHT)
306
307 #define MV_HORIZONTAL           (MV_LEFT | MV_RIGHT)
308 #define MV_VERTICAL             (MV_UP   | MV_DOWN)
309 #define MV_ALL_DIRECTIONS       (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
310 #define MV_ANY_DIRECTION        (MV_ALL_DIRECTIONS)
311 #define MV_NO_DIRECTION         (MV_NONE)
312
313 #define KEY_BUTTON_1            (1 << BUTTON_1)
314 #define KEY_BUTTON_2            (1 << BUTTON_2)
315 #define KEY_BUTTON_SNAP         KEY_BUTTON_1
316 #define KEY_BUTTON_DROP         KEY_BUTTON_2
317 #define KEY_MOTION              (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
318 #define KEY_BUTTON              (KEY_BUTTON_1 | KEY_BUTTON_2)
319 #define KEY_ACTION              (KEY_MOTION | KEY_BUTTON)
320
321 #define KEY_SET_FOCUS           (1 << BIT_SET_FOCUS)
322
323 #define MV_DIR_FROM_BIT(x)      ((x) < NUM_DIRECTIONS ? 1 << (x) :        \
324                                  (x) == MV_BIT_UPLEFT    ? MV_UPLEFT    : \
325                                  (x) == MV_BIT_UPRIGHT   ? MV_UPRIGHT   : \
326                                  (x) == MV_BIT_DOWNLEFT  ? MV_DOWNLEFT  : \
327                                  (x) == MV_BIT_DOWNRIGHT ? MV_DOWNRIGHT : \
328                                  MV_NONE)
329
330 #define MV_DIR_TO_BIT(x)        ((x) == MV_LEFT      ? MV_BIT_LEFT      : \
331                                  (x) == MV_RIGHT     ? MV_BIT_RIGHT     : \
332                                  (x) == MV_UP        ? MV_BIT_UP        : \
333                                  (x) == MV_DOWN      ? MV_BIT_DOWN      : \
334                                  (x) == MV_UPLEFT    ? MV_BIT_UPLEFT    : \
335                                  (x) == MV_UPRIGHT   ? MV_BIT_UPRIGHT   : \
336                                  (x) == MV_DOWNLEFT  ? MV_BIT_DOWNLEFT  : \
337                                  (x) == MV_DOWNRIGHT ? MV_BIT_DOWNRIGHT : \
338                                  MV_BIT_DOWN)
339
340 #define MV_DIR_OPPOSITE(x)      ((x) == MV_LEFT      ? MV_RIGHT     : \
341                                  (x) == MV_RIGHT     ? MV_LEFT      : \
342                                  (x) == MV_UP        ? MV_DOWN      : \
343                                  (x) == MV_DOWN      ? MV_UP        : \
344                                  (x) == MV_UPLEFT    ? MV_DOWNRIGHT : \
345                                  (x) == MV_UPRIGHT   ? MV_DOWNLEFT  : \
346                                  (x) == MV_DOWNLEFT  ? MV_UPRIGHT   : \
347                                  (x) == MV_DOWNRIGHT ? MV_UPLEFT    : \
348                                  MV_NONE)
349
350 // values for animation mode (frame order and direction)
351 // (stored in level files -- never change existing values)
352 #define ANIM_NONE               0
353 #define ANIM_LOOP               (1 << 0)
354 #define ANIM_LINEAR             (1 << 1)
355 #define ANIM_PINGPONG           (1 << 2)
356 #define ANIM_PINGPONG2          (1 << 3)
357 #define ANIM_RANDOM             (1 << 4)
358 #define ANIM_CE_VALUE           (1 << 5)
359 #define ANIM_CE_SCORE           (1 << 6)
360 #define ANIM_CE_DELAY           (1 << 7)
361 #define ANIM_REVERSE            (1 << 8)
362 #define ANIM_OPAQUE_PLAYER      (1 << 9)
363
364 // values for special (non game element) animation modes
365 // (not stored in level files -- can be changed, if needed)
366 #define ANIM_HORIZONTAL         (1 << 10)
367 #define ANIM_VERTICAL           (1 << 11)
368 #define ANIM_CENTERED           (1 << 12)
369 #define ANIM_STATIC_PANEL       (1 << 13)
370 #define ANIM_ALL                (1 << 14)
371 #define ANIM_ONCE               (1 << 15)
372 #define ANIM_TILED              (1 << 16)
373 #define ANIM_RANDOM_STATIC      (1 << 17)
374
375 #define ANIM_DEFAULT            ANIM_LOOP
376
377 // values for special drawing styles and event handling
378 #define STYLE_NONE              0
379
380 // values used for crumbled graphics
381 #define STYLE_ACCURATE_BORDERS  (1 << 0)
382 #define STYLE_INNER_CORNERS     (1 << 1)
383
384 // values used for game panel graphics
385 #define STYLE_REVERSE           (1 << 2)
386 #define STYLE_LEFTMOST_POSITION (1 << 3)
387
388 // values used for global animations
389 #define STYLE_BLOCK             (1 << 4)
390 #define STYLE_PASSTHROUGH       (1 << 5)
391 #define STYLE_MULTIPLE_ACTIONS  (1 << 6)
392
393 #define STYLE_DEFAULT           STYLE_NONE
394
395 // values for special global animation delay types
396 #define ANIM_DELAY_UNDEFINED    -1
397 #define ANIM_DELAY_NONE         0
398 #define ANIM_DELAY_INIT         1
399 #define ANIM_DELAY_ANIM         2
400 #define ANIM_DELAY_POST         3
401
402 // values for special global animation delay actions
403 #define ANIM_DELAY_ACTION_NONE  -1
404
405 // values for special global animation events
406 #define ANIM_EVENT_UNDEFINED    -1
407 #define ANIM_EVENT_NONE         0
408 #define ANIM_EVENT_SELF         (1 << 16)
409 #define ANIM_EVENT_ANY          (1 << 17)
410 #define ANIM_EVENT_CLICK        (1 << 18)
411 #define ANIM_EVENT_INIT         (1 << 19)
412 #define ANIM_EVENT_START        (1 << 20)
413 #define ANIM_EVENT_END          (1 << 21)
414 #define ANIM_EVENT_POST         (1 << 22)
415 #define ANIM_EVENT_UNCLICK_ANY  (1 << 23)
416
417 // anim number: bits 0-7
418 // part number: bits 8-15
419 #define ANIM_EVENT_ANIM_BIT     0
420 #define ANIM_EVENT_PART_BIT     8
421
422 #define ANIM_EVENT_ANIM_MASK    (0xff << ANIM_EVENT_ANIM_BIT)
423 #define ANIM_EVENT_PART_MASK    (0xff << ANIM_EVENT_PART_BIT)
424
425 #define ANIM_EVENT_DEFAULT      ANIM_EVENT_NONE
426
427 // values for special global animation event actions
428 #define ANIM_EVENT_ACTION_NONE  -1
429
430 // values for fade mode
431 #define FADE_TYPE_NONE          0
432 #define FADE_TYPE_FADE_IN       (1 << 0)
433 #define FADE_TYPE_FADE_OUT      (1 << 1)
434 #define FADE_TYPE_TRANSFORM     (1 << 2)
435 #define FADE_TYPE_CROSSFADE     (1 << 3)
436 #define FADE_TYPE_MELT          (1 << 4)
437 #define FADE_TYPE_CURTAIN       (1 << 5)
438 #define FADE_TYPE_SKIP          (1 << 6)
439
440 #define FADE_MODE_NONE          (FADE_TYPE_NONE)
441 #define FADE_MODE_FADE_IN       (FADE_TYPE_FADE_IN)
442 #define FADE_MODE_FADE_OUT      (FADE_TYPE_FADE_OUT)
443 #define FADE_MODE_FADE          (FADE_TYPE_FADE_IN | FADE_TYPE_FADE_OUT)
444 #define FADE_MODE_TRANSFORM     (FADE_TYPE_TRANSFORM | FADE_TYPE_FADE_IN)
445 #define FADE_MODE_CROSSFADE     (FADE_MODE_TRANSFORM | FADE_TYPE_CROSSFADE)
446 #define FADE_MODE_MELT          (FADE_MODE_TRANSFORM | FADE_TYPE_MELT)
447 #define FADE_MODE_CURTAIN       (FADE_MODE_TRANSFORM | FADE_TYPE_CURTAIN)
448 #define FADE_MODE_SKIP_FADE_IN  (FADE_TYPE_SKIP | FADE_TYPE_FADE_IN)
449 #define FADE_MODE_SKIP_FADE_OUT (FADE_TYPE_SKIP | FADE_TYPE_FADE_OUT)
450
451 #define FADE_MODE_DEFAULT       FADE_MODE_FADE
452
453 #define AUTO_DELAY_UNIT_MS      0
454 #define AUTO_DELAY_UNIT_FRAMES  1
455
456 #define AUTO_DELAY_UNIT_DEFAULT AUTO_DELAY_UNIT_MS
457
458 // values for toon positions
459 #define POS_UNDEFINED           -1
460 #define POS_LEFT                0
461 #define POS_RIGHT               1
462 #define POS_TOP                 2
463 #define POS_UPPER               3
464 #define POS_MIDDLE              4
465 #define POS_LOWER               5
466 #define POS_BOTTOM              6
467 #define POS_ANY                 7
468 #define POS_LAST                8
469
470 // values for text alignment
471 #define ALIGN_LEFT              (1 << 0)
472 #define ALIGN_RIGHT             (1 << 1)
473 #define ALIGN_CENTER            (1 << 2)
474 #define ALIGN_DEFAULT           ALIGN_LEFT
475
476 #define VALIGN_TOP              (1 << 0)
477 #define VALIGN_BOTTOM           (1 << 1)
478 #define VALIGN_MIDDLE           (1 << 2)
479 #define VALIGN_DEFAULT          VALIGN_TOP
480
481 #define ALIGNED_XPOS(x,w,a)     ((a) == ALIGN_CENTER  ? (x) - (w) / 2 : \
482                                  (a) == ALIGN_RIGHT   ? (x) - (w) : (x))
483 #define ALIGNED_YPOS(y,h,v)     ((v) == VALIGN_MIDDLE ? (y) - (h) / 2 : \
484                                  (v) == VALIGN_BOTTOM ? (y) - (h) : (y))
485 #define ALIGNED_TEXT_XPOS(p)    ALIGNED_XPOS((p)->x, (p)->width,  (p)->align)
486 #define ALIGNED_TEXT_YPOS(p)    ALIGNED_YPOS((p)->y, (p)->height, (p)->valign)
487 #define ALIGNED_VP_XPOS(p)      ALIGNED_TEXT_XPOS(p)
488 #define ALIGNED_VP_YPOS(p)      ALIGNED_TEXT_YPOS(p)
489
490 // values for redraw_mask
491 #define REDRAW_NONE             (0)
492 #define REDRAW_ALL              (1 << 0)
493 #define REDRAW_FIELD            (1 << 1)
494 #define REDRAW_DOOR_1           (1 << 2)
495 #define REDRAW_DOOR_2           (1 << 3)
496 #define REDRAW_DOOR_3           (1 << 4)
497 #define REDRAW_FPS              (1 << 5)
498
499 #define REDRAW_DOORS            (REDRAW_DOOR_1 | \
500                                  REDRAW_DOOR_2 | \
501                                  REDRAW_DOOR_3)
502
503 #define IN_GFX_FIELD_PLAY(x, y) (x >= gfx.sx && x < gfx.sx + gfx.sxsize && \
504                                  y >= gfx.sy && y < gfx.sy + gfx.sysize)
505 #define IN_GFX_FIELD_FULL(x, y) (x >= gfx.real_sx && \
506                                  x <  gfx.real_sx + gfx.full_sxsize && \
507                                  y >= gfx.real_sy && \
508                                  y <  gfx.real_sy + gfx.full_sysize)
509 #define IN_GFX_DOOR_1(x, y)     (x >= gfx.dx && x < gfx.dx + gfx.dxsize && \
510                                  y >= gfx.dy && y < gfx.dy + gfx.dysize)
511 #define IN_GFX_DOOR_2(x, y)     (x >= gfx.vx && x < gfx.vx + gfx.vxsize && \
512                                  y >= gfx.vy && y < gfx.vy + gfx.vysize)
513 #define IN_GFX_DOOR_3(x, y)     (x >= gfx.ex && x < gfx.ex + gfx.exsize && \
514                                  y >= gfx.ey && y < gfx.ey + gfx.eysize)
515
516 // values for mouse cursor
517 #define CURSOR_UNDEFINED        -1
518 #define CURSOR_DEFAULT          0
519 #define CURSOR_NONE             1
520 #define CURSOR_PLAYFIELD        2
521
522 // fundamental game speed values
523 #define ONE_SECOND_DELAY        1000    // delay value for one second
524 #define MENU_FRAME_DELAY        20      // frame delay in milliseconds
525 #define GAME_FRAME_DELAY        20      // frame delay in milliseconds
526 #define FFWD_FRAME_DELAY        10      // 200% speed for fast forward
527 #define MIN_VSYNC_FRAME_DELAY   15      // minimum value for vsync to keep
528 #define MAX_VSYNC_FRAME_DELAY   16      // maximum value for vsync to work
529 #define FRAMES_PER_SECOND       (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
530 #define FRAMES_PER_SECOND_SP    35
531
532 // maximum playfield size supported by libgame functions
533 #define MAX_PLAYFIELD_WIDTH     128
534 #define MAX_PLAYFIELD_HEIGHT    128
535
536 // maximum number of parallel players supported by libgame functions
537 #define MAX_PLAYERS             4
538
539 // maximum number of player names
540 #define MAX_PLAYER_NAMES        12
541
542 // maximum allowed length of player name
543 #define MAX_PLAYER_NAME_LEN     10
544
545 // maximum number of levels in a level set
546 #define MAX_LEVELS              1000
547
548 // maximum number of global animation and parts
549 #define MAX_GLOBAL_ANIMS                32
550 #define MAX_GLOBAL_ANIM_PARTS           32
551
552 // minimum/maximum/default x/y grid size for virtual buttons
553 #define MIN_GRID_XSIZE                  3
554 #define MIN_GRID_YSIZE                  3
555 #define MAX_GRID_XSIZE                  32
556 #define MAX_GRID_YSIZE                  32
557 #define GRID_REAL_WIDTH                 MAX(1, MAX(video.screen_width,  \
558                                                    video.screen_height))
559 #define GRID_REAL_HEIGHT                MAX(1, MIN(video.screen_width,  \
560                                                    video.screen_height))
561 #define DEFAULT_GRID_XSIZE_0            18
562 #define DEFAULT_GRID_YSIZE_0            MIN(MAX(MIN_GRID_YSIZE,         \
563                                                 DEFAULT_GRID_XSIZE_0 *  \
564                                                 GRID_REAL_HEIGHT /      \
565                                                 GRID_REAL_WIDTH),       \
566                                             MAX_GRID_YSIZE)
567 #define DEFAULT_GRID_XSIZE_1            13
568 #define DEFAULT_GRID_YSIZE_1            MIN(MAX(MIN_GRID_YSIZE,         \
569                                                 DEFAULT_GRID_XSIZE_1 *  \
570                                                 GRID_REAL_WIDTH /       \
571                                                 GRID_REAL_HEIGHT),      \
572                                             MAX_GRID_YSIZE)
573
574 #define DEFAULT_GRID_XSIZE(n)           ((n) == 0 ? DEFAULT_GRID_XSIZE_0 : \
575                                          DEFAULT_GRID_XSIZE_1)
576 #define DEFAULT_GRID_YSIZE(n)           ((n) == 0 ? DEFAULT_GRID_YSIZE_0 : \
577                                          DEFAULT_GRID_YSIZE_1)
578
579 #define GRID_ACTIVE_NR()                (video.screen_width >   \
580                                          video.screen_height ? 0 : 1)
581
582 // values for grid button characters for virtual buttons
583 #define CHAR_GRID_BUTTON_NONE           ' '
584 #define CHAR_GRID_BUTTON_LEFT           '<'
585 #define CHAR_GRID_BUTTON_RIGHT          '>'
586 #define CHAR_GRID_BUTTON_UP             '^'
587 #define CHAR_GRID_BUTTON_DOWN           'v'
588 #define CHAR_GRID_BUTTON_SNAP           '1'
589 #define CHAR_GRID_BUTTON_DROP           '2'
590
591 #define GET_ACTION_FROM_GRID_BUTTON(c)  ((c) == CHAR_GRID_BUTTON_LEFT ?  \
592                                          JOY_LEFT :                      \
593                                          (c) == CHAR_GRID_BUTTON_RIGHT ? \
594                                          JOY_RIGHT :                     \
595                                          (c) == CHAR_GRID_BUTTON_UP ?    \
596                                          JOY_UP :                        \
597                                          (c) == CHAR_GRID_BUTTON_DOWN ?  \
598                                          JOY_DOWN :                      \
599                                          (c) == CHAR_GRID_BUTTON_SNAP ?  \
600                                          JOY_BUTTON_1 :                  \
601                                          (c) == CHAR_GRID_BUTTON_DROP ?  \
602                                          JOY_BUTTON_2 :                  \
603                                          JOY_NO_ACTION)
604
605 // maximum number of level sets in the level set history
606 #define MAX_LEVELDIR_HISTORY    12
607
608 // default name for empty highscore entry
609 #define EMPTY_PLAYER_NAME       "no name"
610
611 // default name for unknown player names
612 #define ANONYMOUS_NAME          "anonymous"
613
614 // default for other unknown names
615 #define UNKNOWN_NAME            "unknown"
616
617 // default name for new levels
618 #define NAMELESS_LEVEL_NAME     "nameless level"
619
620 // default text for non-existant artwork
621 #define NOT_AVAILABLE           "(not available)"
622
623 // default value for undefined filename
624 #define UNDEFINED_FILENAME      "[NONE]"
625
626 // default value for undefined levelset
627 #define UNDEFINED_LEVELSET      "[NONE]"
628
629 // default value for undefined password
630 #define UNDEFINED_PASSWORD      "[undefined]"
631
632 // default value for undefined parameter
633 #define ARG_DEFAULT             "[DEFAULT]"
634
635 // default values for undefined configuration file parameters
636 #define ARG_UNDEFINED           "-1000000"
637 #define ARG_UNDEFINED_VALUE     (-1000000)
638
639 // default value for off-screen positions
640 #define POS_OFFSCREEN           (-1000000)
641
642 // definitions for game base path and sub-directories
643 #ifndef BASE_PATH
644 #define BASE_PATH               "."
645 #endif
646
647 // directory names
648 #define GRAPHICS_DIRECTORY      "graphics"
649 #define SOUNDS_DIRECTORY        "sounds"
650 #define MUSIC_DIRECTORY         "music"
651 #define LEVELS_DIRECTORY        "levels"
652 #define TAPES_DIRECTORY         "tapes"
653 #define SCORES_DIRECTORY        "scores"
654 #define DOCS_DIRECTORY          "docs"
655 #define CACHE_DIRECTORY         "cache"
656 #define CONF_DIRECTORY          "conf"
657 #define NETWORK_DIRECTORY       "network"
658 #define USERS_DIRECTORY         "users"
659
660 #define GFX_CLASSIC_SUBDIR      "gfx_classic"
661 #define SND_CLASSIC_SUBDIR      "snd_classic"
662 #define MUS_CLASSIC_SUBDIR      "mus_classic"
663
664 #define GFX_DEFAULT_SUBDIR      (setup.internal.default_graphics_set)
665 #define SND_DEFAULT_SUBDIR      (setup.internal.default_sounds_set)
666 #define MUS_DEFAULT_SUBDIR      (setup.internal.default_music_set)
667
668 #define GFX_FALLBACK_FILENAME   (setup.internal.fallback_graphics_file)
669 #define SND_FALLBACK_FILENAME   (setup.internal.fallback_sounds_file)
670 #define MUS_FALLBACK_FILENAME   (setup.internal.fallback_music_file)
671
672 #define DEFAULT_LEVELSET        (setup.internal.default_level_series)
673
674 // file names and filename extensions
675 #define LEVELSETUP_DIRECTORY    "levelsetup"
676 #define SETUP_FILENAME          "setup.conf"
677 #define USERSETUP_FILENAME      "usersetup.conf"
678 #define AUTOSETUP_FILENAME      "autosetup.conf"
679 #define LEVELSETUP_FILENAME     "levelsetup.conf"
680 #define SERVERSETUP_FILENAME    "serversetup.conf"
681 #define EDITORSETUP_FILENAME    "editorsetup.conf"
682 #define EDITORCASCADE_FILENAME  "editorcascade.conf"
683 #define HELPANIM_FILENAME       "helpanim.conf"
684 #define HELPTEXT_FILENAME       "helptext.conf"
685 #define LEVELINFO_FILENAME      "levelinfo.conf"
686 #define GRAPHICSINFO_FILENAME   "graphicsinfo.conf"
687 #define SOUNDSINFO_FILENAME     "soundsinfo.conf"
688 #define MUSICINFO_FILENAME      "musicinfo.conf"
689 #define ARTWORKINFO_CACHE_FILE  "artworkinfo.cache"
690 #define LEVELTEMPLATE_FILENAME  "template.level"
691 #define UPLOADED_FILENAME       ".uploaded"
692 #define LEVELFILE_EXTENSION     "level"
693 #define TAPEFILE_EXTENSION      "tape"
694 #define SCOREFILE_EXTENSION     "score"
695
696 #define GAMECONTROLLER_BASENAME "gamecontrollerdb.txt"
697
698 #define LOG_OUT_BASENAME        "stdout.txt"
699 #define LOG_ERR_BASENAME        "stderr.txt"
700
701 #define LOG_OUT_ID              0
702 #define LOG_ERR_ID              1
703 #define NUM_LOGS                2
704
705 #define STRING_PARENT_DIRECTORY         ".."
706 #define STRING_TOP_DIRECTORY            "/"
707
708 #define CHAR_PATH_SEPARATOR_UNIX        '/'
709 #define CHAR_PATH_SEPARATOR_DOS         '\\'
710
711 #define STRING_PATH_SEPARATOR_UNIX      "/"
712 #define STRING_PATH_SEPARATOR_DOS       "\\"
713
714 #define STRING_NEWLINE_UNIX             "\n"
715 #define STRING_NEWLINE_DOS              "\r\n"
716
717 #if defined(PLATFORM_WIN32)
718 #define CHAR_PATH_SEPARATOR     CHAR_PATH_SEPARATOR_DOS
719 #define STRING_PATH_SEPARATOR   STRING_PATH_SEPARATOR_DOS
720 #define STRING_NEWLINE          STRING_NEWLINE_DOS
721 #else
722 #define CHAR_PATH_SEPARATOR     CHAR_PATH_SEPARATOR_UNIX
723 #define STRING_PATH_SEPARATOR   STRING_PATH_SEPARATOR_UNIX
724 #define STRING_NEWLINE          STRING_NEWLINE_UNIX
725 #endif
726
727
728 // areas in bitmap PIX_DOOR
729 // meaning in PIX_DB_DOOR: (3 PAGEs)
730 // PAGEX1: 1. buffer for DOOR_1
731 // PAGEX2: 2. buffer for DOOR_1
732 // PAGEX3: buffer for animations
733
734 // these values are hard-coded to be able to use them in initialization
735 #define DOOR_GFX_PAGE_WIDTH     100     // should be set to "gfx.dxsize"
736 #define DOOR_GFX_PAGE_HEIGHT    280     // should be set to "gfx.dysize"
737
738 #define DOOR_GFX_PAGESIZE       (DOOR_GFX_PAGE_WIDTH)
739 #define DOOR_GFX_PAGEX1         (0 * DOOR_GFX_PAGESIZE)
740 #define DOOR_GFX_PAGEX2         (1 * DOOR_GFX_PAGESIZE)
741 #define DOOR_GFX_PAGEX3         (2 * DOOR_GFX_PAGESIZE)
742 #define DOOR_GFX_PAGEX4         (3 * DOOR_GFX_PAGESIZE)
743 #define DOOR_GFX_PAGEX5         (4 * DOOR_GFX_PAGESIZE)
744 #define DOOR_GFX_PAGEX6         (5 * DOOR_GFX_PAGESIZE)
745 #define DOOR_GFX_PAGEX7         (6 * DOOR_GFX_PAGESIZE)
746 #define DOOR_GFX_PAGEX8         (7 * DOOR_GFX_PAGESIZE)
747 #define DOOR_GFX_PAGEY1         (0)
748 #define DOOR_GFX_PAGEY2         (DOOR_GFX_PAGE_HEIGHT)
749
750
751 // macros for version handling
752 #define VERSION_PART_1(x)       ((x) / 1000000)
753 #define VERSION_PART_2(x)       (((x) % 1000000) / 10000)
754 #define VERSION_PART_3(x)       (((x) % 10000) / 100)
755 #define VERSION_PART_4(x)       ((x) % 100)
756
757 #define VERSION_SUPER(x)        VERSION_PART_1(x)
758 #define VERSION_MAJOR(x)        VERSION_PART_2(x)
759 #define VERSION_MINOR(x)        VERSION_PART_3(x)
760 #define VERSION_PATCH(x)        VERSION_PART_4(x)
761 #define VERSION_IDENT(a,b,c,d)  ((a) * 1000000 + (b) * 10000 + (c) * 100 + (d))
762
763
764 // macros for parent/child process identification
765 #if defined(PLATFORM_UNIX)
766 #define IS_PARENT_PROCESS()     (audio.mixer_pid != getpid())
767 #define IS_CHILD_PROCESS()      (audio.mixer_pid == getpid())
768 #define HAS_CHILD_PROCESS()     (audio.mixer_pid > 0)
769 #else
770 #define IS_PARENT_PROCESS()     TRUE
771 #define IS_CHILD_PROCESS()      FALSE
772 #define HAS_CHILD_PROCESS()     FALSE
773 #endif
774
775
776 // values for artwork type
777 #define ARTWORK_TYPE_GRAPHICS   0
778 #define ARTWORK_TYPE_SOUNDS     1
779 #define ARTWORK_TYPE_MUSIC      2
780
781 #define NUM_ARTWORK_TYPES       3
782
783
784 // values for tree type (chosen to match artwork type)
785 #define TREE_TYPE_UNDEFINED     -1
786 #define TREE_TYPE_GRAPHICS_DIR  ARTWORK_TYPE_GRAPHICS
787 #define TREE_TYPE_SOUNDS_DIR    ARTWORK_TYPE_SOUNDS
788 #define TREE_TYPE_MUSIC_DIR     ARTWORK_TYPE_MUSIC
789 #define TREE_TYPE_LEVEL_DIR     3
790 #define TREE_TYPE_LEVEL_NR      4
791 #define TREE_TYPE_PLAYER_NAME   5
792
793 #define NUM_BASE_TREE_TYPES     4
794 #define NUM_TREE_TYPES          6
795
796 #define TREE_TYPE_IS_DIR(type)  ((type) == TREE_TYPE_GRAPHICS_DIR ||    \
797                                  (type) == TREE_TYPE_SOUNDS_DIR ||      \
798                                  (type) == TREE_TYPE_MUSIC_DIR ||       \
799                                  (type) == TREE_TYPE_LEVEL_DIR)
800
801 #define INFOTEXT_UNDEFINED      ""
802 #define INFOTEXT_GRAPHICS_DIR   "Custom Graphics"
803 #define INFOTEXT_SOUNDS_DIR     "Custom Sounds"
804 #define INFOTEXT_MUSIC_DIR      "Custom Music"
805 #define INFOTEXT_LEVEL_DIR      "Level Sets"
806 #define INFOTEXT_LEVEL_NR       "Levels"
807 #define INFOTEXT_PLAYER_NAME    "Players & Teams"
808
809 #define BACKLINK_TEXT_MAIN      ".. (main menu)"
810 #define BACKLINK_TEXT_SETUP     ".. (setup menu)"
811 #define BACKLINK_TEXT_PARENT    ".. (parent directory)"
812
813 #define TREE_INFOTEXT(t)        ((t) == TREE_TYPE_PLAYER_NAME ?         \
814                                  INFOTEXT_PLAYER_NAME :                 \
815                                  (t) == TREE_TYPE_LEVEL_NR ?            \
816                                  INFOTEXT_LEVEL_NR :                    \
817                                  (t) == TREE_TYPE_LEVEL_DIR ?           \
818                                  INFOTEXT_LEVEL_DIR :                   \
819                                  (t) == TREE_TYPE_GRAPHICS_DIR ?        \
820                                  INFOTEXT_GRAPHICS_DIR :                \
821                                  (t) == TREE_TYPE_SOUNDS_DIR ?          \
822                                  INFOTEXT_SOUNDS_DIR :                  \
823                                  (t) == TREE_TYPE_MUSIC_DIR ?           \
824                                  INFOTEXT_MUSIC_DIR :                   \
825                                  INFOTEXT_UNDEFINED)
826
827 #define TREE_BACKLINK_TEXT(t)   ((t) == TREE_TYPE_LEVEL_DIR ?           \
828                                  BACKLINK_TEXT_MAIN :                   \
829                                  BACKLINK_TEXT_SETUP)
830
831 #define TREE_USERDIR(t)         ((t) == TREE_TYPE_LEVEL_DIR ?           \
832                                  getUserLevelDir(NULL) :                \
833                                  (t) == TREE_TYPE_GRAPHICS_DIR ?        \
834                                  getUserGraphicsDir() :                 \
835                                  (t) == TREE_TYPE_SOUNDS_DIR ?          \
836                                  getUserSoundsDir() :                   \
837                                  (t) == TREE_TYPE_MUSIC_DIR ?           \
838                                  getUserMusicDir() :                    \
839                                  NULL)
840
841 #define TREE_FIRST_NODE_PTR(t)  ((t) == TREE_TYPE_LEVEL_DIR ?           \
842                                  &leveldir_first :                      \
843                                  (t) == TREE_TYPE_GRAPHICS_DIR ?        \
844                                  &artwork.gfx_first :                   \
845                                  (t) == TREE_TYPE_SOUNDS_DIR ?          \
846                                  &artwork.snd_first :                   \
847                                  (t) == TREE_TYPE_MUSIC_DIR ?           \
848                                  &artwork.mus_first :                   \
849                                  NULL)
850
851 #define TREE_FIRST_NODE(t)      ((t) == TREE_TYPE_LEVEL_DIR ?           \
852                                  leveldir_first :                       \
853                                  (t) == TREE_TYPE_GRAPHICS_DIR ?        \
854                                  artwork.gfx_first :                    \
855                                  (t) == TREE_TYPE_SOUNDS_DIR ?          \
856                                  artwork.snd_first :                    \
857                                  (t) == TREE_TYPE_MUSIC_DIR ?           \
858                                  artwork.mus_first :                    \
859                                  NULL)
860
861 // values for artwork handling
862 #define LEVELDIR_ARTWORK_SET_PTR(leveldir, type)                        \
863                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
864                                  &(leveldir)->graphics_set :            \
865                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
866                                  &(leveldir)->sounds_set :              \
867                                  &(leveldir)->music_set)
868
869 #define LEVELDIR_ARTWORK_SET(leveldir, type)                            \
870                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
871                                  (leveldir)->graphics_set :             \
872                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
873                                  (leveldir)->sounds_set :               \
874                                  (leveldir)->music_set)
875
876 #define LEVELDIR_ARTWORK_PATH_PTR(leveldir, type)                       \
877                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
878                                  &(leveldir)->graphics_path :           \
879                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
880                                  &(leveldir)->sounds_path :             \
881                                  &(leveldir)->music_path)
882
883 #define LEVELDIR_ARTWORK_PATH(leveldir, type)                           \
884                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
885                                  (leveldir)->graphics_path :            \
886                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
887                                  (leveldir)->sounds_path :              \
888                                  (leveldir)->music_path)
889
890 #define SETUP_ARTWORK_SET(setup, type)                                  \
891                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
892                                  (setup).graphics_set :                 \
893                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
894                                  (setup).sounds_set :                   \
895                                  (setup).music_set)
896
897 #define SETUP_OVERRIDE_ARTWORK(setup, type)                             \
898                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
899                                  (setup).override_level_graphics :      \
900                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
901                                  (setup).override_level_sounds :        \
902                                  (setup).override_level_music)
903
904 #define GFX_OVERRIDE_ARTWORK(type)                                      \
905                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
906                                  gfx.override_level_graphics :          \
907                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
908                                  gfx.override_level_sounds :            \
909                                  gfx.override_level_music)
910
911 #define ARTWORK_FIRST_NODE(artwork, type)                               \
912                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
913                                  (artwork).gfx_first :                  \
914                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
915                                  (artwork).snd_first :                  \
916                                  (artwork).mus_first)
917
918 #define ARTWORK_CURRENT_PTR(artwork, type)                              \
919                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
920                                  &(artwork).gfx_current :               \
921                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
922                                  &(artwork).snd_current :               \
923                                  &(artwork).mus_current)
924
925 #define ARTWORK_CURRENT(artwork, type)                                  \
926                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
927                                  (artwork).gfx_current :                \
928                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
929                                  (artwork).snd_current :                \
930                                  (artwork).mus_current)
931
932 #define ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type)                   \
933                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
934                                  &(artwork).gfx_current_identifier :    \
935                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
936                                  &(artwork).snd_current_identifier :    \
937                                  &(artwork).mus_current_identifier)
938
939 #define ARTWORK_CURRENT_IDENTIFIER(artwork, type)                       \
940                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
941                                  (artwork).gfx_current_identifier :     \
942                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
943                                  (artwork).snd_current_identifier :     \
944                                  (artwork).mus_current_identifier)
945
946 #define ARTWORKINFO_FILENAME(type)                                      \
947                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
948                                  GRAPHICSINFO_FILENAME :                \
949                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
950                                  SOUNDSINFO_FILENAME :                  \
951                                  (type) == ARTWORK_TYPE_MUSIC ?         \
952                                  MUSICINFO_FILENAME : "")
953
954 #define ARTWORK_DIRECTORY(type)                                         \
955                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
956                                  GRAPHICS_DIRECTORY :                   \
957                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
958                                  SOUNDS_DIRECTORY :                     \
959                                  (type) == ARTWORK_TYPE_MUSIC ?         \
960                                  MUSIC_DIRECTORY : "")
961
962 #define OPTIONS_ARTWORK_DIRECTORY(type)                                 \
963                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
964                                  options.graphics_directory :           \
965                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
966                                  options.sounds_directory :             \
967                                  (type) == ARTWORK_TYPE_MUSIC ?         \
968                                  options.music_directory : "")
969
970 #define USER_ARTWORK_DIRECTORY(type)                                    \
971                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
972                                  getUserGraphicsDir() :                 \
973                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
974                                  getUserSoundsDir() :                   \
975                                  (type) == ARTWORK_TYPE_MUSIC ?         \
976                                  getUserMusicDir() : "")
977
978 #define ARTWORK_DEFAULT_SUBDIR(type)                                    \
979                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
980                                  GFX_DEFAULT_SUBDIR :                   \
981                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
982                                  SND_DEFAULT_SUBDIR :                   \
983                                  MUS_DEFAULT_SUBDIR)
984
985 #define UPDATE_BUSY_STATE()                     \
986 {                                               \
987   if (gfx.draw_busy_anim_function != NULL)      \
988     gfx.draw_busy_anim_function();              \
989 }
990
991
992 // structure definitions
993
994 struct ProgramInfo
995 {
996   char *command_basepath;       // path to the program binary
997   char *command_basename;       // base filename of the program binary
998
999   char *config_filename;        // optional global program config filename
1000
1001   char *maindata_path;          // main game data (installation) directory
1002
1003   char *userdata_subdir;        // personal user game data directory
1004   char *userdata_path;          // resulting full path to game data directory
1005
1006   char *program_title;
1007   char *window_title;
1008   char *icon_title;
1009
1010   char *icon_filename;
1011
1012   char *cookie_prefix;
1013
1014   char *log_filename[NUM_LOGS];         // log filenames for out/err messages
1015   FILE *log_file[NUM_LOGS];             // log file handles for out/err files
1016   FILE *log_file_default[NUM_LOGS];     // default log file handles (out/err)
1017
1018   int version_super;
1019   int version_major;
1020   int version_minor;
1021   int version_patch;
1022   int version_ident;
1023
1024   char *version_string;
1025
1026   char *(*window_title_function)(void);
1027   void (*exit_message_function)(char *, va_list);
1028   void (*exit_function)(int);
1029
1030   int api_thread_count;
1031
1032   boolean headless;
1033 };
1034
1035 struct NetworkInfo
1036 {
1037   boolean enabled;
1038   boolean connected;
1039   boolean serveronly;
1040
1041   char *server_host;
1042   int server_port;
1043
1044   SDL_Thread *server_thread;
1045   boolean is_server_thread;
1046 };
1047
1048 struct RuntimeInfo
1049 {
1050   boolean uses_touch_device;
1051
1052   boolean use_api_server;
1053 };
1054
1055 struct OptionInfo
1056 {
1057   char *server_host;
1058   int server_port;
1059
1060   char *base_directory;
1061   char *level_directory;
1062   char *graphics_directory;
1063   char *sounds_directory;
1064   char *music_directory;
1065   char *docs_directory;
1066   char *conf_directory;
1067
1068   char *execute_command;
1069   char *tape_log_filename;
1070
1071   char *special_flags;
1072   char *debug_mode;
1073
1074   char *player_name;
1075   char *identifier;
1076   char *level_nr;
1077
1078   boolean mytapes;
1079   boolean serveronly;
1080   boolean network;
1081   boolean verbose;
1082   boolean debug;
1083 };
1084
1085 struct VideoSystemInfo
1086 {
1087   int default_depth;
1088   int width, height, depth;
1089   int window_width, window_height;
1090   int display_width, display_height;
1091   int screen_width, screen_height;
1092   int screen_xoffset, screen_yoffset;
1093
1094   boolean fullscreen_available;
1095   boolean fullscreen_enabled;
1096   boolean fullscreen_initial;
1097
1098   boolean window_scaling_available;
1099   int window_scaling_percent;
1100   char *window_scaling_quality;
1101   int screen_rendering_mode;
1102   int vsync_mode;
1103
1104   unsigned int frame_counter;
1105   unsigned int frame_delay;
1106   unsigned int frame_delay_value;
1107
1108   boolean shifted_up;
1109   int shifted_up_pos;
1110   int shifted_up_pos_last;
1111   unsigned int shifted_up_delay;
1112   unsigned int shifted_up_delay_value;
1113
1114   boolean initialized;
1115 };
1116
1117 struct AudioSystemInfo
1118 {
1119   boolean sound_available;
1120   boolean loops_available;
1121   boolean music_available;
1122
1123   boolean sound_enabled;
1124   boolean sound_deactivated;    // for temporarily disabling sound
1125
1126   int mixer_pipe[2];
1127   int mixer_pid;
1128   char *device_name;
1129   int device_fd;
1130
1131   int num_channels;
1132   int music_channel;
1133   int first_sound_channel;
1134 };
1135
1136 struct FontBitmapInfo
1137 {
1138   Bitmap *bitmap;
1139
1140   int src_x, src_y;             // start position of font characters
1141   int width, height;            // width / height of font characters
1142
1143   int offset_x;                 // offset to next font character
1144   int offset_y;                 // offset to next font character
1145
1146   int draw_xoffset;             // offset for drawing font characters
1147   int draw_yoffset;             // offset for drawing font characters
1148
1149   int num_chars;
1150   int num_chars_per_line;
1151 };
1152
1153 struct GfxInfo
1154 {
1155   int sx, sy;
1156   int sxsize, sysize;
1157   int real_sx, real_sy;
1158   int full_sxsize, full_sysize;
1159   int scrollbuffer_width, scrollbuffer_height;
1160
1161   int game_tile_size, standard_tile_size;
1162
1163   int dx, dy;
1164   int dxsize, dysize;
1165
1166   int vx, vy;
1167   int vxsize, vysize;
1168
1169   int ex, ey;
1170   int exsize, eysize;
1171
1172   int win_xsize, win_ysize;
1173
1174   int draw_deactivation_mask;
1175   int draw_background_mask;
1176
1177   Bitmap *field_save_buffer;
1178
1179   Bitmap *background_bitmap;
1180   int background_bitmap_mask;
1181
1182   Bitmap *fade_bitmap_backup;
1183   Bitmap *fade_bitmap_source;
1184   Bitmap *fade_bitmap_target;
1185   Bitmap *fade_bitmap_black;
1186
1187   int fade_border_source_status;
1188   int fade_border_target_status;
1189   Bitmap *masked_border_bitmap_ptr;
1190
1191   Bitmap *final_screen_bitmap;
1192
1193   boolean clipping_enabled;
1194   int clip_x, clip_y;
1195   int clip_width, clip_height;
1196
1197   boolean override_level_graphics;
1198   boolean override_level_sounds;
1199   boolean override_level_music;
1200
1201   boolean draw_init_text;
1202
1203   int num_fonts;
1204   struct FontBitmapInfo *font_bitmap_info;
1205   int (*select_font_function)(int);
1206   int (*get_font_from_token_function)(char *);
1207
1208   int anim_random_frame;
1209
1210   void (*draw_busy_anim_function)(void);
1211   void (*draw_global_anim_function)(int, int);
1212   void (*draw_global_border_function)(int);
1213   void (*draw_tile_cursor_function)(int);
1214
1215   int cursor_mode;
1216   int cursor_mode_override;
1217   int cursor_mode_final;
1218   int mouse_x, mouse_y;
1219 };
1220
1221 struct TileCursorInfo
1222 {
1223   boolean enabled;              // tile cursor generally enabled or disabled
1224   boolean active;               // tile cursor activated (depending on game)
1225   boolean moving;               // tile cursor moving to target position
1226
1227   int xpos, ypos;               // tile cursor level playfield position
1228   int x, y;                     // tile cursor current screen position
1229   int target_x, target_y;       // tile cursor target screen position
1230
1231   int sx, sy;                   // tile cursor screen start position
1232
1233   boolean xsn_debug;            // enable or disable XSN debugging
1234 };
1235
1236 struct OverlayInfo
1237 {
1238   boolean enabled;              // overlay generally enabled or disabled
1239   boolean active;               // overlay activated (depending on game mode)
1240
1241   boolean show_grid;
1242
1243   int grid_xsize;
1244   int grid_ysize;
1245
1246   char grid_button[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
1247   char grid_button_highlight;
1248
1249   int grid_button_action;
1250 };
1251
1252 struct JoystickInfo
1253 {
1254   int status;
1255   int nr[MAX_PLAYERS];          // joystick number for each player
1256 };
1257
1258 struct SetupJoystickInfo
1259 {
1260   char *device_name;            // device name of player's joystick
1261
1262   int xleft, xmiddle, xright;
1263   int yupper, ymiddle, ylower;
1264   int snap, drop;
1265 };
1266
1267 struct SetupKeyboardInfo
1268 {
1269   Key left, right, up, down;
1270   Key snap, drop;
1271 };
1272
1273 struct SetupTouchInfo
1274 {
1275   char *control_type;
1276   int move_distance;
1277   int drop_distance;
1278
1279   int grid_xsize[2];
1280   int grid_ysize[2];
1281
1282   char grid_button[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE];
1283
1284   int transparency;             // in percent (0 == opaque, 100 == invisible)
1285   boolean draw_outlined;
1286   boolean draw_pressed;
1287
1288   boolean grid_initialized;
1289 };
1290
1291 struct SetupInputInfo
1292 {
1293   boolean use_joystick;
1294   struct SetupJoystickInfo joy;
1295   struct SetupKeyboardInfo key;
1296 };
1297
1298 struct SetupEditorInfo
1299 {
1300   boolean el_boulderdash;
1301   boolean el_emerald_mine;
1302   boolean el_emerald_mine_club;
1303   boolean el_more;
1304   boolean el_sokoban;
1305   boolean el_supaplex;
1306   boolean el_diamond_caves;
1307   boolean el_dx_boulderdash;
1308
1309   boolean el_mirror_magic;
1310   boolean el_deflektor;
1311
1312   boolean el_chars;
1313   boolean el_steel_chars;
1314
1315   boolean el_classic;
1316   boolean el_custom;
1317   boolean el_user_defined;
1318   boolean el_dynamic;
1319
1320   boolean el_headlines;
1321
1322   boolean el_by_game;
1323   boolean el_by_type;
1324
1325   boolean show_element_token;
1326
1327   boolean show_read_only_warning;
1328
1329   boolean use_template_for_new_levels;
1330 };
1331
1332 struct SetupAutoSetupInfo
1333 {
1334   int editor_zoom_tilesize;
1335 };
1336
1337 struct SetupLevelSetupInfo
1338 {
1339   char *last_level_series[MAX_LEVELDIR_HISTORY + 1];
1340 };
1341
1342 struct SetupEditorCascadeInfo
1343 {
1344   boolean el_bd;
1345   boolean el_em;
1346   boolean el_emc;
1347   boolean el_rnd;
1348   boolean el_sb;
1349   boolean el_sp;
1350   boolean el_dc;
1351   boolean el_dx;
1352   boolean el_mm;
1353   boolean el_df;
1354   boolean el_chars;
1355   boolean el_steel_chars;
1356   boolean el_ce;
1357   boolean el_ge;
1358   boolean el_ref;
1359   boolean el_user;
1360   boolean el_dynamic;
1361 };
1362
1363 struct SetupShortcutInfo
1364 {
1365   Key save_game;
1366   Key load_game;
1367   Key toggle_pause;
1368
1369   Key focus_player[MAX_PLAYERS];
1370   Key focus_player_all;
1371
1372   Key tape_eject;
1373   Key tape_extra;
1374   Key tape_stop;
1375   Key tape_pause;
1376   Key tape_record;
1377   Key tape_play;
1378
1379   Key sound_simple;
1380   Key sound_loops;
1381   Key sound_music;
1382
1383   Key snap_left;
1384   Key snap_right;
1385   Key snap_up;
1386   Key snap_down;
1387 };
1388
1389 struct SetupSystemInfo
1390 {
1391   char *sdl_renderdriver;
1392   char *sdl_videodriver;
1393   char *sdl_audiodriver;
1394   int audio_fragment_size;
1395 };
1396
1397 struct SetupInternalInfo
1398 {
1399   char *program_title;
1400   char *program_version;
1401   char *program_author;
1402   char *program_email;
1403   char *program_website;
1404   char *program_copyright;
1405   char *program_company;
1406
1407   char *program_icon_file;
1408
1409   char *default_graphics_set;
1410   char *default_sounds_set;
1411   char *default_music_set;
1412
1413   char *fallback_graphics_file;
1414   char *fallback_sounds_file;
1415   char *fallback_music_file;
1416
1417   char *default_level_series;
1418
1419   int default_window_width;
1420   int default_window_height;
1421
1422   boolean choose_from_top_leveldir;
1423   boolean show_scaling_in_title;
1424   boolean create_user_levelset;
1425
1426   boolean menu_game;
1427   boolean menu_engines;
1428   boolean menu_editor;
1429   boolean menu_graphics;
1430   boolean menu_sound;
1431   boolean menu_artwork;
1432   boolean menu_input;
1433   boolean menu_touch;
1434   boolean menu_shortcuts;
1435   boolean menu_exit;
1436   boolean menu_save_and_exit;
1437 };
1438
1439 struct SetupDebugInfo
1440 {
1441   int frame_delay[10];
1442   Key frame_delay_key[10];
1443   boolean frame_delay_use_mod_key;
1444   boolean frame_delay_game_only;
1445   boolean show_frames_per_second;
1446   int xsn_mode;
1447   int xsn_percent;
1448 };
1449
1450 struct SetupInfo
1451 {
1452   char *player_name;
1453   char *player_uuid;
1454   int player_version;
1455
1456   boolean multiple_users;
1457
1458   boolean sound;
1459   boolean sound_loops;
1460   boolean sound_music;
1461   boolean sound_simple;
1462   boolean toons;
1463   boolean scroll_delay;
1464   boolean forced_scroll_delay;
1465   int scroll_delay_value;
1466   char *engine_snapshot_mode;
1467   int engine_snapshot_memory;
1468   boolean fade_screens;
1469   boolean autorecord;
1470   boolean show_titlescreen;
1471   boolean quick_doors;
1472   boolean team_mode;
1473   boolean handicap;
1474   boolean skip_levels;
1475   boolean increment_levels;
1476   boolean auto_play_next_level;
1477   boolean count_score_after_game;
1478   boolean show_scores_after_game;
1479   boolean time_limit;
1480   boolean fullscreen;
1481   int window_scaling_percent;
1482   char *window_scaling_quality;
1483   char *screen_rendering_mode;
1484   char *vsync_mode;
1485   boolean ask_on_escape;
1486   boolean ask_on_escape_editor;
1487   boolean ask_on_game_over;
1488   boolean ask_on_quit_game;
1489   boolean ask_on_quit_program;
1490   boolean quick_switch;
1491   boolean input_on_focus;
1492   boolean prefer_aga_graphics;
1493   boolean prefer_lowpass_sounds;
1494   boolean prefer_extra_panel_items;
1495   boolean game_speed_extended;
1496   int game_frame_delay;
1497   boolean sp_show_border_elements;
1498   boolean small_game_graphics;
1499   boolean show_load_save_buttons;
1500   boolean show_undo_redo_buttons;
1501   char *scores_in_highscore_list;
1502
1503   char *graphics_set;
1504   char *sounds_set;
1505   char *music_set;
1506   int override_level_graphics;          // not boolean -- can also be "AUTO"
1507   int override_level_sounds;            // not boolean -- can also be "AUTO"
1508   int override_level_music;             // not boolean -- can also be "AUTO"
1509
1510   int volume_simple;
1511   int volume_loops;
1512   int volume_music;
1513
1514   boolean network_mode;
1515   int network_player_nr;
1516   char *network_server_hostname;
1517
1518   boolean use_api_server;
1519   char *api_server_hostname;
1520   char *api_server_password;
1521   boolean ask_for_uploading_tapes;
1522   boolean ask_for_remaining_tapes;
1523   boolean provide_uploading_tapes;
1524   boolean ask_for_using_api_server;
1525   boolean has_remaining_tapes;
1526
1527   struct SetupAutoSetupInfo auto_setup;
1528   struct SetupLevelSetupInfo level_setup;
1529
1530   struct SetupEditorInfo editor;
1531   struct SetupEditorCascadeInfo editor_cascade;
1532   struct SetupShortcutInfo shortcut;
1533   struct SetupInputInfo input[MAX_PLAYERS];
1534   struct SetupTouchInfo touch;
1535   struct SetupSystemInfo system;
1536   struct SetupInternalInfo internal;
1537   struct SetupDebugInfo debug;
1538
1539   struct OptionInfo options;
1540 };
1541
1542 struct UserInfo
1543 {
1544   int nr;
1545 };
1546
1547 struct TreeInfo
1548 {
1549   struct TreeInfo **node_top;           // topmost node in tree
1550   struct TreeInfo *node_parent;         // parent level directory info
1551   struct TreeInfo *node_group;          // level group sub-directory info
1552   struct TreeInfo *next;                // next level series structure node
1553
1554   int cl_first;         // internal control field for setup screen
1555   int cl_cursor;        // internal control field for setup screen
1556
1557   int type;             // type of tree content
1558
1559   // fields for "type == TREE_TYPE_LEVEL_DIR"
1560
1561   char *subdir;         // tree info sub-directory basename (may be ".")
1562   char *fullpath;       // complete path relative to tree base directory
1563   char *basepath;       // absolute base path of tree base directory
1564   char *identifier;     // identifier string for configuration files
1565   char *name;           // tree info name, as displayed in selection menues
1566   char *name_sorting;   // optional sorting name for correct name sorting
1567   char *author;         // level or artwork author name
1568   char *year;           // optional year of creation for levels or artwork
1569
1570   char *program_title;     // optional alternative text for program title
1571   char *program_copyright; // optional alternative text for program copyright
1572   char *program_company;   // optional alternative text for program company
1573
1574   char *imported_from;  // optional comment for imported levels or artwork
1575   char *imported_by;    // optional comment for imported levels or artwork
1576   char *tested_by;      // optional comment to name people who tested a set
1577
1578   char *graphics_set_ecs; // special EMC custom graphics set (ECS graphics)
1579   char *graphics_set_aga; // special EMC custom graphics set (AGA graphics)
1580   char *graphics_set;   // optional custom graphics set (level tree only)
1581   char *sounds_set_default; // default EMC custom sounds set
1582   char *sounds_set_lowpass; // special EMC custom sounds set (lowpass filter)
1583   char *sounds_set;     // optional custom sounds set (level tree only)
1584   char *music_set;      // optional custom music set (level tree only)
1585   char *graphics_path;  // path to optional custom graphics set (level only)
1586   char *sounds_path;    // path to optional custom sounds set (level only)
1587   char *music_path;     // path to optional custom music set (level only)
1588
1589   char *level_filename; // filename of level file (for packed level file)
1590   char *level_filetype; // type of levels in level directory or level file
1591
1592   char *special_flags;  // flags for special actions performed on level file
1593
1594   int levels;           // number of levels in level series
1595   int first_level;      // first level number (to allow start with 0 or 1)
1596   int last_level;       // last level number (automatically calculated)
1597   int sort_priority;    // sort levels by 'sort_priority' and then by name
1598
1599   boolean latest_engine;// force level set to use the latest game engine
1600
1601   boolean level_group;  // directory contains more level series directories
1602   boolean parent_link;  // entry links back to parent directory
1603   boolean is_copy;      // this entry is a copy of another entry in the tree
1604   boolean in_user_dir;  // user defined levels are stored in home directory
1605   boolean user_defined; // levels in user directory and marked as "private"
1606   boolean readonly;     // readonly levels can not be changed with editor
1607   boolean handicap;     // level set has no handicap when set to "false"
1608   boolean skip_levels;  // levels can be skipped when set to "true"
1609
1610   boolean use_emc_tiles;// use (swapped) V5/V6 EMC tiles when set to "true"
1611
1612   int color;            // color to use on selection screen for this level
1613   char *class_desc;     // description of level series class
1614   int handicap_level;   // number of the lowest unsolved level
1615
1616   char *infotext;       // optional text to describe the tree type (headline)
1617 };
1618
1619 typedef struct TreeInfo TreeInfo;
1620 typedef struct TreeInfo LevelDirTree;
1621 typedef struct TreeInfo ArtworkDirTree;
1622 typedef struct TreeInfo GraphicsDirTree;
1623 typedef struct TreeInfo SoundsDirTree;
1624 typedef struct TreeInfo MusicDirTree;
1625
1626 struct ArtworkInfo
1627 {
1628   GraphicsDirTree *gfx_first;
1629   GraphicsDirTree *gfx_current;
1630   SoundsDirTree *snd_first;
1631   SoundsDirTree *snd_current;
1632   MusicDirTree *mus_first;
1633   MusicDirTree *mus_current;
1634
1635   char *gfx_current_identifier;
1636   char *snd_current_identifier;
1637   char *mus_current_identifier;
1638 };
1639
1640 struct ValueTextInfo
1641 {
1642   int value;
1643   char *text;
1644 };
1645
1646 struct StringValueTextInfo
1647 {
1648   char *value;
1649   char *text;
1650 };
1651
1652 struct ConfigInfo
1653 {
1654   char *token;
1655   char *value;
1656 };
1657
1658 struct ConfigTypeInfo
1659 {
1660   char *token;
1661   char *value;
1662   int type;
1663 };
1664
1665 struct TokenIntPtrInfo
1666 {
1667   char *token;
1668   int *value;
1669 };
1670
1671 struct FileInfo
1672 {
1673   char *token;
1674
1675   char *default_filename;
1676   char *filename;
1677
1678   char **default_parameter;                     // array of file parameters
1679   char **parameter;                             // array of file parameters
1680
1681   boolean redefined;
1682   boolean fallback_to_default;
1683   boolean default_is_cloned;
1684 };
1685
1686 struct SetupFileList
1687 {
1688   char *token;
1689   char *value;
1690
1691   struct SetupFileList *next;
1692 };
1693
1694 struct ListNodeInfo
1695 {
1696   char *source_filename;                        // primary key for node list
1697   int num_references;
1698 };
1699
1700 struct PropertyMapping
1701 {
1702   int base_index;
1703   int ext1_index;
1704   int ext2_index;
1705   int ext3_index;
1706
1707   int artwork_index;
1708 };
1709
1710 struct ArtworkListInfo
1711 {
1712   int type;                                     // type of artwork
1713
1714   int num_file_list_entries;
1715   int num_dynamic_file_list_entries;
1716   struct FileInfo *file_list;                   // static artwork file array
1717   struct FileInfo *dynamic_file_list;           // dynamic artwrk file array
1718
1719   int num_suffix_list_entries;
1720   struct ConfigTypeInfo *suffix_list;           // parameter suffixes array
1721
1722   int num_base_prefixes;
1723   int num_ext1_suffixes;
1724   int num_ext2_suffixes;
1725   int num_ext3_suffixes;
1726   char **base_prefixes;                         // base token prefixes array
1727   char **ext1_suffixes;                         // property suffixes array 1
1728   char **ext2_suffixes;                         // property suffixes array 2
1729   char **ext3_suffixes;                         // property suffixes array 3
1730
1731   int num_ignore_tokens;
1732   char **ignore_tokens;                         // file tokens to be ignored
1733
1734   int num_property_mapping_entries;
1735   struct PropertyMapping *property_mapping;     // mapping token -> artwork
1736
1737   int sizeof_artwork_list_entry;
1738
1739   struct ListNodeInfo **artwork_list;           // static artwork node array
1740   struct ListNodeInfo **dynamic_artwork_list;   // dynamic artwrk node array
1741   struct ListNode *content_list;                // dynamic artwork node list
1742
1743   void *(*load_artwork)(char *);                // constructor function
1744   void (*free_artwork)(void *);                 // destructor function
1745 };
1746
1747 struct XY
1748 {
1749   int x, y;
1750 };
1751
1752 struct XYTileSize
1753 {
1754   int x, y;
1755   int tile_size;
1756 };
1757
1758 struct Rect
1759 {
1760   int x, y;
1761   int width, height;
1762 };
1763
1764 struct RectWithBorder
1765 {
1766   int x, y;
1767   int width, height;
1768   int min_width, min_height;
1769   int max_width, max_height;
1770   int margin_left;
1771   int margin_right;
1772   int margin_top;
1773   int margin_bottom;
1774   int border_left;
1775   int border_right;
1776   int border_top;
1777   int border_bottom;
1778   int border_size;
1779   int align_size;
1780   int align, valign;
1781 };
1782
1783 struct MenuPosInfo
1784 {
1785   int x, y;
1786   int width, height;
1787   int align, valign;
1788 };
1789
1790 struct DoorPartPosInfo
1791 {
1792   int x, y;
1793   int step_xoffset;
1794   int step_yoffset;
1795   int step_delay;
1796   int start_step;
1797   int start_step_opening;
1798   int start_step_closing;
1799   boolean draw_masked;
1800   int sort_priority;
1801 };
1802
1803 struct TextPosInfo
1804 {
1805   int x, y;
1806   int xoffset;                  // special case for tape date and time
1807   int xoffset2;                 // special case for tape date
1808   int yoffset;                  // special case for list of preview players
1809   int width, height;
1810   int align, valign;
1811   int size;                     // also used for suffix ".digits"
1812   int font, font_alt;
1813   boolean draw_masked;
1814   boolean draw_player;          // special case for network player buttons
1815   int sort_priority;            // also used for suffix ".draw_order"
1816   int id;
1817
1818   int direction;                // needed for panel time/health graphics
1819   int class;                    // needed for panel time/health graphics
1820   int style;                    // needed for panel time/health graphics
1821
1822   int tile_size;                // special case for list of network players
1823   int border_size;              // special case for list of preview players
1824   int vertical;                 // special case for list of preview players
1825
1826   boolean redefined;            // redefined by custom artwork
1827 };
1828
1829 struct MouseActionInfo
1830 {
1831   int lx, ly;
1832   int button;
1833   int button_hint;
1834 };
1835
1836 struct LevelSetInfo
1837 {
1838   int music[MAX_LEVELS];
1839
1840   char *identifier;
1841   int level_nr;
1842 };
1843
1844 struct LevelStats
1845 {
1846   int played;
1847   int solved;
1848 };
1849
1850
1851 // ============================================================================
1852 // exported variables
1853 // ============================================================================
1854
1855 extern struct ProgramInfo       program;
1856 extern struct NetworkInfo       network;
1857 extern struct RuntimeInfo       runtime;
1858 extern struct OptionInfo        options;
1859 extern struct VideoSystemInfo   video;
1860 extern struct AudioSystemInfo   audio;
1861 extern struct GfxInfo           gfx;
1862 extern struct TileCursorInfo    tile_cursor;
1863 extern struct OverlayInfo       overlay;
1864 extern struct AnimInfo          anim;
1865 extern struct ArtworkInfo       artwork;
1866 extern struct JoystickInfo      joystick;
1867 extern struct SetupInfo         setup;
1868 extern struct UserInfo          user;
1869
1870 extern LevelDirTree            *leveldir_first_all;
1871 extern LevelDirTree            *leveldir_first;
1872 extern LevelDirTree            *leveldir_current;
1873 extern int                      level_nr;
1874
1875 extern struct LevelSetInfo      levelset;
1876 extern struct LevelStats        level_stats[];
1877
1878 extern DrawWindow              *window;
1879 extern DrawBuffer              *backbuffer;
1880 extern DrawBuffer              *drawto;
1881
1882 extern int                      button_status;
1883 extern boolean                  motion_status;
1884 extern int                      wheel_steps;
1885 extern boolean                  keyrepeat_status;
1886 extern boolean                  textinput_status;
1887
1888 extern int                      redraw_mask;
1889
1890 extern int                      FrameCounter;
1891
1892
1893 // function definitions
1894
1895 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
1896                      char *, int);
1897 void InitNetworkInfo(boolean, boolean, boolean, char *, int);
1898 void InitRuntimeInfo(void);
1899
1900 void SetWindowTitle(void);
1901
1902 void InitWindowTitleFunction(char *(*window_title_function)(void));
1903 void InitExitMessageFunction(void (*exit_message_function)(char *, va_list));
1904 void InitExitFunction(void (*exit_function)(int));
1905 void InitPlatformDependentStuff(void);
1906 void ClosePlatformDependentStuff(void);
1907
1908 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
1909 void InitGfxTileSizeInfo(int, int);
1910 void InitGfxDoor1Info(int, int, int, int);
1911 void InitGfxDoor2Info(int, int, int, int);
1912 void InitGfxDoor3Info(int, int, int, int);
1913 void InitGfxWindowInfo(int, int);
1914 void InitGfxScrollbufferInfo(int, int);
1915 void InitGfxClipRegion(boolean, int, int, int, int);
1916 void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void));
1917 void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(int, int));
1918 void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int));
1919 void InitGfxDrawTileCursorFunction(void (*draw_tile_cursor_function)(int));
1920 void InitGfxCustomArtworkInfo(void);
1921 void InitGfxOtherSettings(void);
1922 void InitTileCursorInfo(void);
1923 void InitOverlayInfo(void);
1924 void SetOverlayGridSizeAndButtons(void);
1925 void SetTileCursorEnabled(boolean);
1926 void SetTileCursorActive(boolean);
1927 void SetTileCursorTargetXY(int, int);
1928 void SetTileCursorXY(int, int);
1929 void SetTileCursorSXSY(int, int);
1930 void SetOverlayEnabled(boolean);
1931 void SetOverlayActive(boolean);
1932 void SetOverlayShowGrid(boolean);
1933 boolean GetOverlayEnabled(void);
1934 boolean GetOverlayActive(void);
1935 void SetDrawDeactivationMask(int);
1936 int GetDrawDeactivationMask(void);
1937 void SetDrawBackgroundMask(int);
1938 void SetWindowBackgroundBitmap(Bitmap *);
1939 void SetMainBackgroundBitmap(Bitmap *);
1940 void SetDoorBackgroundBitmap(Bitmap *);
1941 void SetRedrawMaskFromArea(int, int, int, int);
1942
1943 void LimitScreenUpdates(boolean);
1944
1945 void InitVideoDefaults(void);
1946 void InitVideoDisplay(void);
1947 void CloseVideoDisplay(void);
1948 void InitVideoBuffer(int, int, int, boolean);
1949 Bitmap *CreateBitmapStruct(void);
1950 Bitmap *CreateBitmap(int, int, int);
1951 void ReCreateBitmap(Bitmap **, int, int);
1952 void FreeBitmap(Bitmap *);
1953 void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
1954 void BlitBitmapTiled(Bitmap *, Bitmap *, int, int, int, int, int, int, int,int);
1955 void FadeRectangle(int, int, int, int, int, int, int,
1956                    void (*draw_border_function)(void));
1957 void FillRectangle(Bitmap *, int, int, int, int, Pixel);
1958 void ClearRectangle(Bitmap *, int, int, int, int);
1959 void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
1960 void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
1961 boolean DrawingDeactivatedField(void);
1962 boolean DrawingDeactivated(int, int, int, int);
1963 boolean DrawingOnBackground(int, int);
1964 boolean DrawingAreaChanged(void);
1965 void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int, int);
1966 void BlitTexture(Bitmap *, int, int, int, int, int, int);
1967 void BlitTextureMasked(Bitmap *, int, int, int, int, int, int);
1968 void BlitToScreen(Bitmap *, int, int, int, int, int, int);
1969 void BlitToScreenMasked(Bitmap *, int, int, int, int, int, int);
1970 void DrawSimpleBlackLine(Bitmap *, int, int, int, int);
1971 void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
1972 void DrawLines(Bitmap *, struct XY *, int, Pixel);
1973 Pixel GetPixel(Bitmap *, int, int);
1974 Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
1975 Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
1976
1977 void KeyboardAutoRepeatOn(void);
1978 void KeyboardAutoRepeatOff(void);
1979 boolean SetVideoMode(boolean);
1980 void SetVideoFrameDelay(unsigned int);
1981 unsigned int GetVideoFrameDelay(void);
1982 boolean ChangeVideoModeIfNeeded(boolean);
1983
1984 Bitmap *LoadImage(char *);
1985 Bitmap *LoadCustomImage(char *);
1986 void ReloadCustomImage(Bitmap *, char *);
1987
1988 Bitmap *ZoomBitmap(Bitmap *, int, int);
1989 void ReCreateGameTileSizeBitmap(Bitmap **);
1990 void CreateBitmapWithSmallBitmaps(Bitmap **, int, int);
1991 void CreateBitmapTextures(Bitmap **);
1992 void FreeBitmapTextures(Bitmap **);
1993 void ScaleBitmap(Bitmap **, int);
1994
1995 void SetMouseCursor(int);
1996 void UpdateRawMousePosition(int, int);
1997 void UpdateMousePosition(void);
1998
1999 void OpenAudio(void);
2000 void CloseAudio(void);
2001 void SetAudioMode(boolean);
2002
2003 void InitEventFilter(EventFilter);
2004 boolean PendingEvent(void);
2005 void WaitEvent(Event *event);
2006 void PeekEvent(Event *event);
2007 void PumpEvents(void);
2008 void CheckQuitEvent(void);
2009 Key GetEventKey(KeyEvent *, boolean);
2010 KeyMod HandleKeyModState(Key, int);
2011 KeyMod GetKeyModState(void);
2012 KeyMod GetKeyModStateFromEvents(void);
2013 void StartTextInput(int, int, int, int);
2014 void StopTextInput(void);
2015 void PushUserEvent(int, int, int);
2016
2017 void InitJoysticks(void);
2018 boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
2019 boolean CheckJoystickOpened(int);
2020 void ClearJoystickState(void);
2021
2022 void InitEmscriptenFilesystem(void);
2023 void SyncEmscriptenFilesystem(void);
2024
2025 #endif // SYSTEM_H