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