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