rnd-20061019-2-src
[rocksndiamonds.git] / src / libgame / system.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * system.h                                                 *
12 ***********************************************************/
13
14 #ifndef SYSTEM_H
15 #define SYSTEM_H
16
17 #include "platform.h"
18 #include "types.h"
19
20
21 #if defined(PLATFORM_MACOSX)
22 #include "macosx.h"
23 #elif defined(PLATFORM_WIN32)
24 #include "windows.h"
25 #elif defined(PLATFORM_MSDOS)
26 #include "msdos.h"
27 #endif
28
29 #if defined(TARGET_SDL)
30 #include "sdl.h"
31 #elif defined(TARGET_X11)
32 #include "x11.h"
33 #endif
34
35
36 /* the additional 'b' is needed for Win32 to open files in binary mode */
37 #define MODE_READ                       "rb"
38 #define MODE_WRITE                      "wb"
39 #define MODE_APPEND                     "ab"
40
41 #define DEFAULT_DEPTH                   0
42
43 #define BLIT_OPAQUE                     0
44 #define BLIT_MASKED                     1
45 #define BLIT_INVERSE                    2
46 #define BLIT_ON_BACKGROUND              3
47
48 #define FULLSCREEN_NOT_AVAILABLE        FALSE
49 #define FULLSCREEN_AVAILABLE            TRUE
50
51 /* default input keys */
52 #define DEFAULT_KEY_LEFT                KSYM_Left
53 #define DEFAULT_KEY_RIGHT               KSYM_Right
54 #define DEFAULT_KEY_UP                  KSYM_Up
55 #define DEFAULT_KEY_DOWN                KSYM_Down
56 #if defined(PLATFORM_MACOSX)
57 #define DEFAULT_KEY_SNAP                KSYM_Control_L
58 #define DEFAULT_KEY_DROP                KSYM_KP_Enter
59 #else
60 #define DEFAULT_KEY_SNAP                KSYM_Control_L
61 #define DEFAULT_KEY_DROP                KSYM_Control_R
62 #endif
63 #define DEFAULT_KEY_OKAY                KSYM_Return
64 #define DEFAULT_KEY_CANCEL              KSYM_Escape
65
66 /* default shortcut keys */
67 #define DEFAULT_KEY_SAVE_GAME           KSYM_F1
68 #define DEFAULT_KEY_LOAD_GAME           KSYM_F2
69 #define DEFAULT_KEY_TOGGLE_PAUSE        KSYM_space
70 #define DEFAULT_KEY_FOCUS_PLAYER_1      KSYM_F5
71 #define DEFAULT_KEY_FOCUS_PLAYER_2      KSYM_F6
72 #define DEFAULT_KEY_FOCUS_PLAYER_3      KSYM_F7
73 #define DEFAULT_KEY_FOCUS_PLAYER_4      KSYM_F8
74 #define DEFAULT_KEY_FOCUS_PLAYER_ALL    KSYM_F9
75
76 /* values for key_status */
77 #define KEY_NOT_PRESSED                 FALSE
78 #define KEY_RELEASED                    FALSE
79 #define KEY_PRESSED                     TRUE
80
81 /* values for button status */
82 #define MB_NOT_PRESSED                  FALSE
83 #define MB_NOT_RELEASED                 TRUE
84 #define MB_RELEASED                     FALSE
85 #define MB_PRESSED                      TRUE
86 #define MB_MENU_CHOICE                  FALSE
87 #define MB_MENU_MARK                    TRUE
88 #define MB_MENU_INITIALIZE              (-1)
89 #define MB_MENU_LEAVE                   (-2)
90 #define MB_LEFTBUTTON                   1
91 #define MB_MIDDLEBUTTON                 2
92 #define MB_RIGHTBUTTON                  3
93 #define MB_WHEEL_UP                     4
94 #define MB_WHEEL_DOWN                   5
95 #define MB_WHEEL_LEFT                   6
96 #define MB_WHEEL_RIGHT                  7
97 #define IS_WHEEL_BUTTON_VERTICAL(b)     ((b) >= MB_WHEEL_UP &&          \
98                                          (b) <= MB_WHEEL_DOWN)
99 #define IS_WHEEL_BUTTON_HORIZONTAL(b)   ((b) >= MB_WHEEL_LEFT &&        \
100                                          (b) <= MB_WHEEL_RIGHT)
101 #define IS_WHEEL_BUTTON(b)              ((b) >= MB_WHEEL_UP &&          \
102                                          (b) <= MB_WHEEL_DOWN)
103 #define DEFAULT_WHEEL_STEPS             3
104
105 /* values for move directions */
106 #define MV_BIT_LEFT                     0
107 #define MV_BIT_RIGHT                    1
108 #define MV_BIT_UP                       2
109 #define MV_BIT_DOWN                     3
110
111 #define NUM_DIRECTIONS                  4
112
113 /* diagonal movement directions are used in a different contect than buttons */
114 #define MV_BIT_UPLEFT                   4
115 #define MV_BIT_UPRIGHT                  5
116 #define MV_BIT_DOWNLEFT                 6
117 #define MV_BIT_DOWNRIGHT                7
118
119 #define NUM_DIRECTIONS_FULL             8
120
121 /* values for special "button" bitmasks */
122 #define BUTTON_1                        4
123 #define BUTTON_2                        5
124
125 /* values for special "focus player" bitmasks */
126 #define BIT_SET_FOCUS                   6
127
128 /* values for move directions and special "button" key bitmasks */
129 #define MV_NONE                 0
130 #define MV_LEFT                 (1 << MV_BIT_LEFT)
131 #define MV_RIGHT                (1 << MV_BIT_RIGHT)
132 #define MV_UP                   (1 << MV_BIT_UP)
133 #define MV_DOWN                 (1 << MV_BIT_DOWN)
134
135 #define MV_UPLEFT               (MV_UP   | MV_LEFT)
136 #define MV_UPRIGHT              (MV_UP   | MV_RIGHT)
137 #define MV_DOWNLEFT             (MV_DOWN | MV_LEFT)
138 #define MV_DOWNRIGHT            (MV_DOWN | MV_RIGHT)
139
140 #define MV_HORIZONTAL           (MV_LEFT | MV_RIGHT)
141 #define MV_VERTICAL             (MV_UP   | MV_DOWN)
142 #define MV_ALL_DIRECTIONS       (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
143 #define MV_ANY_DIRECTION        (MV_ALL_DIRECTIONS)
144 #define MV_NO_DIRECTION         (MV_NONE)
145
146 #define KEY_BUTTON_1            (1 << BUTTON_1)
147 #define KEY_BUTTON_2            (1 << BUTTON_2)
148 #define KEY_MOTION              (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
149 #define KEY_BUTTON              (KEY_BUTTON_1 | KEY_BUTTON_2)
150 #define KEY_ACTION              (KEY_MOTION | KEY_BUTTON)
151
152 #define KEY_SET_FOCUS           (1 << BIT_SET_FOCUS)
153
154 #define MV_DIR_FROM_BIT(x)      ((x) < NUM_DIRECTIONS ? 1 << (x) :        \
155                                  (x) == MV_BIT_UPLEFT    ? MV_UPLEFT    : \
156                                  (x) == MV_BIT_UPRIGHT   ? MV_UPRIGHT   : \
157                                  (x) == MV_BIT_DOWNLEFT  ? MV_DOWNLEFT  : \
158                                  (x) == MV_BIT_DOWNRIGHT ? MV_DOWNRIGHT : \
159                                  MV_NONE)
160
161 #define MV_DIR_TO_BIT(x)        ((x) == MV_LEFT      ? MV_BIT_LEFT      : \
162                                  (x) == MV_RIGHT     ? MV_BIT_RIGHT     : \
163                                  (x) == MV_UP        ? MV_BIT_UP        : \
164                                  (x) == MV_DOWN      ? MV_BIT_DOWN      : \
165                                  (x) == MV_UPLEFT    ? MV_BIT_UPLEFT    : \
166                                  (x) == MV_UPRIGHT   ? MV_BIT_UPRIGHT   : \
167                                  (x) == MV_DOWNLEFT  ? MV_BIT_DOWNLEFT  : \
168                                  (x) == MV_DOWNRIGHT ? MV_BIT_DOWNRIGHT : \
169                                  MV_BIT_DOWN)
170
171 #define MV_DIR_OPPOSITE(x)      ((x) == MV_LEFT      ? MV_RIGHT     : \
172                                  (x) == MV_RIGHT     ? MV_LEFT      : \
173                                  (x) == MV_UP        ? MV_DOWN      : \
174                                  (x) == MV_DOWN      ? MV_UP        : \
175                                  (x) == MV_UPLEFT    ? MV_DOWNRIGHT : \
176                                  (x) == MV_UPRIGHT   ? MV_DOWNLEFT  : \
177                                  (x) == MV_DOWNLEFT  ? MV_UPRIGHT   : \
178                                  (x) == MV_DOWNRIGHT ? MV_UPLEFT    : \
179                                  MV_NONE)
180
181 /* values for animation mode (frame order and direction) */
182 #define ANIM_NONE               0
183 #define ANIM_LOOP               (1 << 0)
184 #define ANIM_LINEAR             (1 << 1)
185 #define ANIM_PINGPONG           (1 << 2)
186 #define ANIM_PINGPONG2          (1 << 3)
187 #define ANIM_RANDOM             (1 << 4)
188 #define ANIM_CE_VALUE           (1 << 5)
189 #define ANIM_CE_SCORE           (1 << 6)
190 #define ANIM_CE_DELAY           (1 << 7)
191 #define ANIM_REVERSE            (1 << 8)
192 #define ANIM_OPAQUE_PLAYER      (1 << 9)
193
194 /* values for special (non game element) animation modes */
195 #define ANIM_HORIZONTAL         (1 << 10)
196 #define ANIM_VERTICAL           (1 << 11)
197 #define ANIM_CENTERED           (1 << 12)
198 #define ANIM_STATIC_PANEL       (1 << 13)
199 #define ANIM_FADE               (1 << 14)
200 #define ANIM_CROSSFADE          (1 << 15)
201
202 #define ANIM_DEFAULT            ANIM_LOOP
203
204 /* values for text alignment */
205 #define ALIGN_LEFT              (1 << 0)
206 #define ALIGN_RIGHT             (1 << 1)
207 #define ALIGN_CENTER            (1 << 2)
208
209 #define ALIGN_DEFAULT           ALIGN_LEFT
210
211 #define ALIGNED_XPOS(x,w,a)     ((a) == ALIGN_CENTER ? (x) - (w) / 2 :  \
212                                  (a) == ALIGN_RIGHT  ? (x) - (w) : (x))
213
214 /* values for redraw_mask */
215 #define REDRAW_NONE             (0)
216 #define REDRAW_ALL              (1 << 0)
217 #define REDRAW_FIELD            (1 << 1)
218 #define REDRAW_TILES            (1 << 2)
219 #define REDRAW_DOOR_1           (1 << 3)
220 #define REDRAW_VIDEO_1          (1 << 4)
221 #define REDRAW_VIDEO_2          (1 << 5)
222 #define REDRAW_VIDEO_3          (1 << 6)
223 #define REDRAW_MICROLEVEL       (1 << 7)
224 #define REDRAW_MICROLABEL       (1 << 8)
225 #define REDRAW_FROM_BACKBUFFER  (1 << 9)
226 #define REDRAW_DOOR_2           (REDRAW_VIDEO_1 | \
227                                  REDRAW_VIDEO_2 | \
228                                  REDRAW_VIDEO_3)
229 #define REDRAW_DOOR_3           (1 << 10)
230 #define REDRAW_DOORS            (REDRAW_DOOR_1 | \
231                                  REDRAW_DOOR_2 | \
232                                  REDRAW_DOOR_3)
233 #define REDRAW_MAIN             (REDRAW_FIELD | \
234                                  REDRAW_TILES | \
235                                  REDRAW_MICROLEVEL)
236 #define REDRAW_FPS              (1 << 11)
237 #define REDRAWTILES_THRESHOLD   (SCR_FIELDX * SCR_FIELDY / 2)
238
239 #define FADE_MODE_FADE_IN       0
240 #define FADE_MODE_FADE_OUT      1
241 #define FADE_MODE_CROSSFADE     2
242
243 #define IN_GFX_SCREEN(x, y)     (x >= gfx.sx && x < gfx.sx + gfx.sxsize && \
244                                  y >= gfx.sy && y < gfx.sy + gfx.sysize)
245 #define IN_GFX_DOOR(x, y)       (x >= gfx.dx && x < gfx.dx + gfx.dxsize && \
246                                  y >= gfx.dy && y < gfx.dy + gfx.dysize)
247 #define IN_GFX_VIDEO(x, y)      (x >= gfx.vx && x < gfx.vx + gfx.vxsize && \
248                                  y >= gfx.vy && y < gfx.vy + gfx.vysize)
249
250 /* values for mouse cursor */
251 #define CURSOR_DEFAULT          0
252 #define CURSOR_PLAYFIELD        1
253
254 /* fundamental game speed values */
255 #define ONE_SECOND_DELAY        1000    /* delay value for one second */
256 #define GAME_FRAME_DELAY        20      /* frame delay in milliseconds */
257 #define FFWD_FRAME_DELAY        10      /* 200% speed for fast forward */
258 #define FRAMES_PER_SECOND       (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
259
260 /* maximum playfield size supported by libgame functions */
261 #define MAX_PLAYFIELD_WIDTH     128
262 #define MAX_PLAYFIELD_HEIGHT    128
263
264 /* maximum number of parallel players supported by libgame functions */
265 #define MAX_PLAYERS             4
266
267 /* maximum allowed length of player name */
268 #define MAX_PLAYER_NAME_LEN     10
269
270 /* default name for empty highscore entry */
271 #define EMPTY_PLAYER_NAME       "no name"
272
273 /* default name for unknown player names */
274 #define ANONYMOUS_NAME          "anonymous"
275
276 /* default for other unknown names */
277 #define UNKNOWN_NAME            "unknown"
278
279 /* default name for new levels */
280 #define NAMELESS_LEVEL_NAME     "nameless level"
281
282 /* default text for non-existant artwork */
283 #define NOT_AVAILABLE           "(not available)"
284
285 /* default value for undefined filename */
286 #define UNDEFINED_FILENAME      "[NONE]"
287
288 /* default value for undefined parameter */
289 #define ARG_DEFAULT             "[DEFAULT]"
290
291 /* default values for undefined configuration file parameters */
292 #define ARG_UNDEFINED           "-1000000"
293 #define ARG_UNDEFINED_VALUE     (atoi(ARG_UNDEFINED))
294
295 /* definitions for game sub-directories */
296 #ifndef RO_GAME_DIR
297 #define RO_GAME_DIR             "."
298 #endif
299
300 #ifndef RW_GAME_DIR
301 #define RW_GAME_DIR             "."
302 #endif
303
304 #define RO_BASE_PATH            RO_GAME_DIR
305 #define RW_BASE_PATH            RW_GAME_DIR
306
307 /* directory names */
308 #define GRAPHICS_DIRECTORY      "graphics"
309 #define SOUNDS_DIRECTORY        "sounds"
310 #define MUSIC_DIRECTORY         "music"
311 #define LEVELS_DIRECTORY        "levels"
312 #define TAPES_DIRECTORY         "tapes"
313 #define SCORES_DIRECTORY        "scores"
314 #define DOCS_DIRECTORY          "docs"
315
316 #if !defined(PLATFORM_MSDOS)
317 #define GFX_CLASSIC_SUBDIR      "gfx_classic"
318 #define SND_CLASSIC_SUBDIR      "snd_classic"
319 #define MUS_CLASSIC_SUBDIR      "mus_classic"
320 #else
321 #define GFX_CLASSIC_SUBDIR      "gfx_orig"
322 #define SND_CLASSIC_SUBDIR      "snd_orig"
323 #define MUS_CLASSIC_SUBDIR      "mus_orig"
324 #endif
325
326 /* file names and filename extensions */
327 #if !defined(PLATFORM_MSDOS)
328 #define LEVELSETUP_DIRECTORY    "levelsetup"
329 #define SETUP_FILENAME          "setup.conf"
330 #define LEVELSETUP_FILENAME     "levelsetup.conf"
331 #define EDITORSETUP_FILENAME    "editorsetup.conf"
332 #define EDITORCASCADE_FILENAME  "editorcascade.conf"
333 #define HELPANIM_FILENAME       "helpanim.conf"
334 #define HELPTEXT_FILENAME       "helptext.conf"
335 #define LEVELINFO_FILENAME      "levelinfo.conf"
336 #define GRAPHICSINFO_FILENAME   "graphicsinfo.conf"
337 #define SOUNDSINFO_FILENAME     "soundsinfo.conf"
338 #define MUSICINFO_FILENAME      "musicinfo.conf"
339 #define LEVELFILE_EXTENSION     "level"
340 #define TAPEFILE_EXTENSION      "tape"
341 #define SCOREFILE_EXTENSION     "score"
342 #else
343 #define LEVELSETUP_DIRECTORY    "lvlsetup"
344 #define SETUP_FILENAME          "setup.cnf"
345 #define LEVELSETUP_FILENAME     "lvlsetup.cnf"
346 #define EDITORSETUP_FILENAME    "edsetup.cnf"
347 #define EDITORCASCADE_FILENAME  "edcascad.conf"
348 #define HELPANIM_FILENAME       "helpanim.cnf"
349 #define HELPTEXT_FILENAME       "helptext.cnf"
350 #define LEVELINFO_FILENAME      "lvlinfo.cnf"
351 #define GRAPHICSINFO_FILENAME   "gfxinfo.cnf"
352 #define SOUNDSINFO_FILENAME     "sndinfo.cnf"
353 #define MUSICINFO_FILENAME      "musinfo.cnf"
354 #define LEVELFILE_EXTENSION     "lvl"
355 #define TAPEFILE_EXTENSION      "tap"
356 #define SCOREFILE_EXTENSION     "sco"
357 #endif
358
359 #define ERROR_BASENAME          "stderr.txt"
360
361 #define CHAR_PATH_SEPARATOR_UNIX        '/'
362 #define CHAR_PATH_SEPARATOR_DOS         '\\'
363
364 #define STRING_PATH_SEPARATOR_UNIX      "/"
365 #define STRING_PATH_SEPARATOR_DOS       "\\"
366
367 #define STRING_NEWLINE_UNIX             "\n"
368 #define STRING_NEWLINE_DOS              "\r\n"
369
370 #if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS)
371 #define CHAR_PATH_SEPARATOR     CHAR_PATH_SEPARATOR_DOS
372 #define STRING_PATH_SEPARATOR   STRING_PATH_SEPARATOR_DOS
373 #define STRING_NEWLINE          STRING_NEWLINE_DOS
374 #else
375 #define CHAR_PATH_SEPARATOR     CHAR_PATH_SEPARATOR_UNIX
376 #define STRING_PATH_SEPARATOR   STRING_PATH_SEPARATOR_UNIX
377 #define STRING_NEWLINE          STRING_NEWLINE_UNIX
378 #endif
379
380
381 /* areas in bitmap PIX_DOOR */
382 /* meaning in PIX_DB_DOOR: (3 PAGEs)
383    PAGEX1: 1. buffer for DOOR_1
384    PAGEX2: 2. buffer for DOOR_1
385    PAGEX3: buffer for animations
386 */
387
388 /* these values are hard-coded to be able to use them in initialization */
389 #define DOOR_GFX_PAGE_WIDTH     100     /* should be set to "gfx.dxsize" */
390 #define DOOR_GFX_PAGE_HEIGHT    280     /* should be set to "gfx.dysize" */
391
392 #define DOOR_GFX_PAGESIZE       (DOOR_GFX_PAGE_WIDTH)
393 #define DOOR_GFX_PAGEX1         (0 * DOOR_GFX_PAGESIZE)
394 #define DOOR_GFX_PAGEX2         (1 * DOOR_GFX_PAGESIZE)
395 #define DOOR_GFX_PAGEX3         (2 * DOOR_GFX_PAGESIZE)
396 #define DOOR_GFX_PAGEX4         (3 * DOOR_GFX_PAGESIZE)
397 #define DOOR_GFX_PAGEX5         (4 * DOOR_GFX_PAGESIZE)
398 #define DOOR_GFX_PAGEX6         (5 * DOOR_GFX_PAGESIZE)
399 #define DOOR_GFX_PAGEX7         (6 * DOOR_GFX_PAGESIZE)
400 #define DOOR_GFX_PAGEX8         (7 * DOOR_GFX_PAGESIZE)
401 #define DOOR_GFX_PAGEY1         (0)
402 #define DOOR_GFX_PAGEY2         (DOOR_GFX_PAGE_HEIGHT)
403
404
405 /* macros for version handling */
406 #define VERSION_MAJOR(x)        ((x) / 1000000)
407 #define VERSION_MINOR(x)        (((x) % 1000000) / 10000)
408 #define VERSION_PATCH(x)        (((x) % 10000) / 100)
409 #define VERSION_BUILD(x)        ((x) % 100)
410 #define VERSION_IDENT(a,b,c,d)  ((a) * 1000000 + (b) * 10000 + (c) * 100 + (d))
411
412
413 /* macros for parent/child process identification */
414 #if defined(PLATFORM_UNIX)
415 #define IS_PARENT_PROCESS()     (audio.mixer_pid != getpid())
416 #define IS_CHILD_PROCESS()      (audio.mixer_pid == getpid())
417 #define HAS_CHILD_PROCESS()     (audio.mixer_pid > 0)
418 #else
419 #define IS_PARENT_PROCESS()     TRUE
420 #define IS_CHILD_PROCESS()      FALSE
421 #define HAS_CHILD_PROCESS()     FALSE
422 #endif
423
424
425 /* values for artwork type */
426 #define ARTWORK_TYPE_GRAPHICS   0
427 #define ARTWORK_TYPE_SOUNDS     1
428 #define ARTWORK_TYPE_MUSIC      2
429
430 #define NUM_ARTWORK_TYPES       3
431
432
433 /* values for tree type (chosen to match artwork type) */
434 #define TREE_TYPE_UNDEFINED     -1
435 #define TREE_TYPE_GRAPHICS_DIR  ARTWORK_TYPE_GRAPHICS
436 #define TREE_TYPE_SOUNDS_DIR    ARTWORK_TYPE_SOUNDS
437 #define TREE_TYPE_MUSIC_DIR     ARTWORK_TYPE_MUSIC
438 #define TREE_TYPE_LEVEL_DIR     3
439
440 #define NUM_TREE_TYPES          4
441
442 #define INFOTEXT_UNDEFINED      ""
443 #define INFOTEXT_GRAPHICS_DIR   "Custom Graphics"
444 #define INFOTEXT_SOUNDS_DIR     "Custom Sounds"
445 #define INFOTEXT_MUSIC_DIR      "Custom Music"
446 #define INFOTEXT_LEVEL_DIR      "Level Sets"
447
448 #define TREE_INFOTEXT(t)        ((t) == TREE_TYPE_LEVEL_DIR ?           \
449                                  INFOTEXT_LEVEL_DIR :                   \
450                                  (t) == TREE_TYPE_GRAPHICS_DIR ?        \
451                                  INFOTEXT_GRAPHICS_DIR :                \
452                                  (t) == TREE_TYPE_SOUNDS_DIR ?          \
453                                  INFOTEXT_SOUNDS_DIR :                  \
454                                  (t) == TREE_TYPE_MUSIC_DIR ?           \
455                                  INFOTEXT_MUSIC_DIR :                   \
456                                  INFOTEXT_UNDEFINED)
457
458 /* values for artwork handling */
459 #define LEVELDIR_ARTWORK_SET_PTR(leveldir, type)                        \
460                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
461                                  &(leveldir)->graphics_set :            \
462                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
463                                  &(leveldir)->sounds_set :              \
464                                  &(leveldir)->music_set)
465
466 #define LEVELDIR_ARTWORK_SET(leveldir, type)                            \
467                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
468                                  (leveldir)->graphics_set :             \
469                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
470                                  (leveldir)->sounds_set :               \
471                                  (leveldir)->music_set)
472
473 #define LEVELDIR_ARTWORK_PATH_PTR(leveldir, type)                       \
474                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
475                                  &(leveldir)->graphics_path :           \
476                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
477                                  &(leveldir)->sounds_path :             \
478                                  &(leveldir)->music_path)
479
480 #define LEVELDIR_ARTWORK_PATH(leveldir, type)                           \
481                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
482                                  (leveldir)->graphics_path :            \
483                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
484                                  (leveldir)->sounds_path :              \
485                                  (leveldir)->music_path)
486
487 #define SETUP_ARTWORK_SET(setup, type)                                  \
488                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
489                                  (setup).graphics_set :                 \
490                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
491                                  (setup).sounds_set :                   \
492                                  (setup).music_set)
493
494 #define SETUP_OVERRIDE_ARTWORK(setup, type)                             \
495                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
496                                  (setup).override_level_graphics :      \
497                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
498                                  (setup).override_level_sounds :        \
499                                  (setup).override_level_music)
500
501 #define ARTWORK_FIRST_NODE(artwork, type)                               \
502                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
503                                  (artwork).gfx_first :                  \
504                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
505                                  (artwork).snd_first :                  \
506                                  (artwork).mus_first)
507
508 #define ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type)                   \
509                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
510                                  &(artwork).gfx_current_identifier :    \
511                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
512                                  &(artwork).snd_current_identifier :    \
513                                  &(artwork).mus_current_identifier)
514
515 #define ARTWORK_CURRENT_IDENTIFIER(artwork, type)                       \
516                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
517                                  (artwork).gfx_current_identifier :     \
518                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
519                                  (artwork).snd_current_identifier :     \
520                                  (artwork).mus_current_identifier)
521
522 #define ARTWORKINFO_FILENAME(type)                                      \
523                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
524                                  GRAPHICSINFO_FILENAME :                \
525                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
526                                  SOUNDSINFO_FILENAME :                  \
527                                  (type) == ARTWORK_TYPE_MUSIC ?         \
528                                  MUSICINFO_FILENAME : "")
529
530 #define ARTWORK_DIRECTORY(type)                                         \
531                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
532                                  GRAPHICS_DIRECTORY :                   \
533                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
534                                  SOUNDS_DIRECTORY :                     \
535                                  (type) == ARTWORK_TYPE_MUSIC ?         \
536                                  MUSIC_DIRECTORY : "")
537
538 #define OPTIONS_ARTWORK_DIRECTORY(type)                                 \
539                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
540                                  options.graphics_directory :           \
541                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
542                                  options.sounds_directory :             \
543                                  (type) == ARTWORK_TYPE_MUSIC ?         \
544                                  options.music_directory : "")
545
546
547 /* type definitions */
548 typedef int (*EventFilter)(const Event *);
549
550
551 /* structure definitions */
552
553 struct ProgramInfo
554 {
555   char *command_basepath;       /* directory that contains the program */
556   char *command_basename;       /* base filename of the program binary */
557
558   char *userdata_subdir;        /* personal user game data directory */
559   char *userdata_subdir_unix;   /* personal user game data directory (Unix) */
560   char *userdata_path;          /* resulting full path to game data directory */
561
562   char *program_title;
563   char *window_title;
564   char *icon_title;
565
566   char *x11_icon_filename;
567   char *x11_iconmask_filename;
568   char *sdl_icon_filename;
569   char *msdos_cursor_filename;
570
571   char *cookie_prefix;
572   char *filename_prefix;        /* prefix to cut off from DOS filenames */
573
574   char *error_filename;         /* filename where to write error messages to */
575   FILE *error_file;             /* (used instead of 'stderr' on some systems) */
576
577   int version_major;
578   int version_minor;
579   int version_patch;
580
581   void (*exit_function)(int);
582 };
583
584 struct OptionInfo
585 {
586   char *display_name;
587   char *server_host;
588   int server_port;
589
590   char *ro_base_directory;
591   char *rw_base_directory;
592   char *level_directory;
593   char *graphics_directory;
594   char *sounds_directory;
595   char *music_directory;
596   char *docs_directory;
597   char *execute_command;
598
599   boolean serveronly;
600   boolean network;
601   boolean verbose;
602   boolean debug;
603 };
604
605 struct ScreenModeInfo
606 {
607   int width, height;
608 };
609
610 struct VideoSystemInfo
611 {
612   int default_depth;
613   int width, height, depth;
614
615   boolean fullscreen_available;
616   boolean fullscreen_enabled;
617   struct ScreenModeInfo *fullscreen_modes;
618   char *fullscreen_mode_current;
619 };
620
621 struct AudioSystemInfo
622 {
623   boolean sound_available;
624   boolean loops_available;
625   boolean music_available;
626
627   boolean sound_enabled;
628   boolean sound_deactivated;    /* for temporarily disabling sound */
629
630   int mixer_pipe[2];
631   int mixer_pid;
632   char *device_name;
633   int device_fd;
634
635   int num_channels;
636   int music_channel;
637   int first_sound_channel;
638 };
639
640 struct FontBitmapInfo
641 {
642   Bitmap *bitmap;
643
644   int src_x, src_y;             /* start position of animation frames */
645   int width, height;            /* width/height of each animation frame */
646
647   int draw_xoffset;             /* offset for drawing font characters */
648   int draw_yoffset;             /* offset for drawing font characters */
649
650   int num_chars;
651   int num_chars_per_line;
652
653 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
654   Pixmap *clip_mask;            /* single-char-only clip mask array for X11 */
655 #endif
656 };
657
658 struct GfxInfo
659 {
660   int sx, sy;
661   int sxsize, sysize;
662   int real_sx, real_sy;
663   int full_sxsize, full_sysize;
664   int scrollbuffer_width, scrollbuffer_height;
665
666   int dx, dy;
667   int dxsize, dysize;
668
669   int vx, vy;
670   int vxsize, vysize;
671
672   int draw_deactivation_mask;
673   int draw_background_mask;
674
675   Bitmap *field_save_buffer;
676
677   Bitmap *background_bitmap;
678   int background_bitmap_mask;
679
680   int num_fonts;
681   struct FontBitmapInfo *font_bitmap_info;
682   int (*select_font_function)(int);
683
684   int anim_random_frame;
685 };
686
687 struct JoystickInfo
688 {
689   int status;
690   int fd[MAX_PLAYERS];          /* file descriptor of player's joystick */
691 };
692
693 struct SetupJoystickInfo
694 {
695   char *device_name;            /* device name of player's joystick */
696
697   int xleft, xmiddle, xright;
698   int yupper, ymiddle, ylower;
699   int snap, drop;
700 };
701
702 struct SetupKeyboardInfo
703 {
704   Key left, right, up, down;
705   Key snap, drop;
706 };
707
708 struct SetupInputInfo
709 {
710   boolean use_joystick;
711   struct SetupJoystickInfo joy;
712   struct SetupKeyboardInfo key;
713 };
714
715 struct SetupEditorInfo
716 {
717   boolean el_boulderdash;
718   boolean el_emerald_mine;
719   boolean el_emerald_mine_club;
720   boolean el_more;
721   boolean el_sokoban;
722   boolean el_supaplex;
723   boolean el_diamond_caves;
724   boolean el_dx_boulderdash;
725   boolean el_chars;
726   boolean el_custom;
727   boolean el_user_defined;
728   boolean el_dynamic;
729
730   boolean el_headlines;
731
732   boolean el_by_game;
733   boolean el_by_type;
734
735   boolean show_element_token;
736 };
737
738 struct SetupEditorCascadeInfo
739 {
740   boolean el_bd;
741   boolean el_em;
742   boolean el_emc;
743   boolean el_rnd;
744   boolean el_sb;
745   boolean el_sp;
746   boolean el_dc;
747   boolean el_dx;
748   boolean el_chars;
749   boolean el_ce;
750   boolean el_ge;
751   boolean el_ref;
752   boolean el_user;
753   boolean el_dynamic;
754 };
755
756 struct SetupShortcutInfo
757 {
758   Key save_game;
759   Key load_game;
760   Key toggle_pause;
761
762   Key focus_player[MAX_PLAYERS];
763   Key focus_player_all;
764 };
765
766 struct SetupSystemInfo
767 {
768   char *sdl_audiodriver;
769   int audio_fragment_size;
770 };
771
772 struct SetupInfo
773 {
774   char *player_name;
775
776   boolean sound;
777   boolean sound_loops;
778   boolean sound_music;
779   boolean sound_simple;
780   boolean toons;
781   boolean double_buffering;
782   boolean direct_draw;          /* !double_buffering (redundant!) */
783   boolean scroll_delay;
784   boolean soft_scrolling;
785   boolean fade_screens;
786   boolean autorecord;
787   boolean show_titlescreen;
788   boolean quick_doors;
789   boolean team_mode;
790   boolean handicap;
791   boolean skip_levels;
792   boolean time_limit;
793   boolean fullscreen;
794   char *fullscreen_mode;
795   boolean ask_on_escape;
796   boolean ask_on_escape_editor;
797   boolean quick_switch;
798   boolean input_on_focus;
799   boolean prefer_aga_graphics;
800
801   char *graphics_set;
802   char *sounds_set;
803   char *music_set;
804   boolean override_level_graphics;
805   boolean override_level_sounds;
806   boolean override_level_music;
807
808   struct SetupEditorInfo editor;
809   struct SetupEditorCascadeInfo editor_cascade;
810   struct SetupShortcutInfo shortcut;
811   struct SetupInputInfo input[MAX_PLAYERS];
812   struct SetupSystemInfo system;
813   struct OptionInfo options;
814 };
815
816 struct TreeInfo
817 {
818   struct TreeInfo **node_top;           /* topmost node in tree */
819   struct TreeInfo *node_parent;         /* parent level directory info */
820   struct TreeInfo *node_group;          /* level group sub-directory info */
821   struct TreeInfo *next;                /* next level series structure node */
822
823   int cl_first;         /* internal control field for setup screen */
824   int cl_cursor;        /* internal control field for setup screen */
825
826   int type;             /* type of tree content */
827
828   /* fields for "type == TREE_TYPE_LEVEL_DIR" */
829
830   char *subdir;         /* tree info sub-directory basename (may be ".") */
831   char *fullpath;       /* complete path relative to tree base directory */
832   char *basepath;       /* absolute base path of tree base directory */
833   char *identifier;     /* identifier string for configuration files */
834   char *name;           /* tree info name, as displayed in selection menues */
835   char *name_sorting;   /* optional sorting name for correct name sorting */
836   char *author;         /* level or artwork author name */
837   char *imported_from;  /* optional comment for imported levels or artwork */
838   char *imported_by;    /* optional comment for imported levels or artwork */
839
840   char *graphics_set_ecs; /* special EMC custom graphics set (ECS graphics) */
841   char *graphics_set_aga; /* special EMC custom graphics set (AGA graphics) */
842   char *graphics_set;   /* optional custom graphics set (level tree only) */
843   char *sounds_set;     /* optional custom sounds set (level tree only) */
844   char *music_set;      /* optional custom music set (level tree only) */
845   char *graphics_path;  /* path to optional custom graphics set (level only) */
846   char *sounds_path;    /* path to optional custom sounds set (level only) */
847   char *music_path;     /* path to optional custom music set (level only) */
848
849   char *level_filename; /* filename of level file (for packed level file) */
850   char *level_filetype; /* type of levels in level directory or level file */
851
852   int levels;           /* number of levels in level series */
853   int first_level;      /* first level number (to allow start with 0 or 1) */
854   int last_level;       /* last level number (automatically calculated) */
855   int sort_priority;    /* sort levels by 'sort_priority' and then by name */
856
857   boolean latest_engine;/* force level set to use the latest game engine */
858
859   boolean level_group;  /* directory contains more level series directories */
860   boolean parent_link;  /* entry links back to parent directory */
861   boolean in_user_dir;  /* user defined levels are stored in home directory */
862   boolean user_defined; /* levels in user directory and marked as "private" */
863   boolean readonly;     /* readonly levels can not be changed with editor */
864   boolean handicap;     /* level set has no handicap when set to "false" */
865   boolean skip_levels;  /* levels can be skipped when set to "true" */
866
867   int color;            /* color to use on selection screen for this level */
868   char *class_desc;     /* description of level series class */
869   int handicap_level;   /* number of the lowest unsolved level */
870
871   char *infotext;       /* optional text to describe the tree type (headline) */
872 };
873
874 typedef struct TreeInfo TreeInfo;
875 typedef struct TreeInfo LevelDirTree;
876 typedef struct TreeInfo ArtworkDirTree;
877 typedef struct TreeInfo GraphicsDirTree;
878 typedef struct TreeInfo SoundsDirTree;
879 typedef struct TreeInfo MusicDirTree;
880
881 struct ArtworkInfo
882 {
883   GraphicsDirTree *gfx_first;
884   GraphicsDirTree *gfx_current;
885   SoundsDirTree *snd_first;
886   SoundsDirTree *snd_current;
887   MusicDirTree *mus_first;
888   MusicDirTree *mus_current;
889
890   char *gfx_current_identifier;
891   char *snd_current_identifier;
892   char *mus_current_identifier;
893 };
894
895 struct ValueTextInfo
896 {
897   int value;
898   char *text;
899 };
900
901 struct ConfigInfo
902 {
903   char *token;
904   char *value;
905 };
906
907 struct ConfigTypeInfo
908 {
909   char *token;
910   char *value;
911   int type;
912 };
913
914 struct TokenIntPtrInfo
915 {
916   char *token;
917   int *value;
918 };
919
920 struct FileInfo
921 {
922   char *token;
923
924   char *default_filename;
925   char *filename;
926
927   char **default_parameter;                     /* array of file parameters */
928   char **parameter;                             /* array of file parameters */
929
930   boolean redefined;
931   boolean fallback_to_default;
932 };
933
934 struct SetupFileList
935 {
936   char *token;
937   char *value;
938
939   struct SetupFileList *next;
940 };
941
942 struct ListNodeInfo
943 {
944   char *source_filename;                        /* primary key for node list */
945   int num_references;
946 };
947
948 struct PropertyMapping
949 {
950   int base_index;
951   int ext1_index;
952   int ext2_index;
953   int ext3_index;
954
955   int artwork_index;
956 };
957
958 struct ArtworkListInfo
959 {
960   int type;                                     /* type of artwork */
961
962   int num_file_list_entries;
963   int num_dynamic_file_list_entries;
964   struct FileInfo *file_list;                   /* static artwork file array */
965   struct FileInfo *dynamic_file_list;           /* dynamic artwrk file array */
966
967   int num_suffix_list_entries;
968   struct ConfigTypeInfo *suffix_list;           /* parameter suffixes array */
969
970   int num_base_prefixes;
971   int num_ext1_suffixes;
972   int num_ext2_suffixes;
973   int num_ext3_suffixes;
974   char **base_prefixes;                         /* base token prefixes array */
975   char **ext1_suffixes;                         /* property suffixes array 1 */
976   char **ext2_suffixes;                         /* property suffixes array 2 */
977   char **ext3_suffixes;                         /* property suffixes array 3 */
978
979   int num_ignore_tokens;
980   char **ignore_tokens;                         /* file tokens to be ignored */
981
982   int num_property_mapping_entries;
983   struct PropertyMapping *property_mapping;     /* mapping token -> artwork */
984
985   int sizeof_artwork_list_entry;
986
987   struct ListNodeInfo **artwork_list;           /* static artwork node array */
988   struct ListNodeInfo **dynamic_artwork_list;   /* dynamic artwrk node array */
989   struct ListNode *content_list;                /* dynamic artwork node list */
990
991   void *(*load_artwork)(char *);                /* constructor function */
992   void (*free_artwork)(void *);                 /* destructor function */
993 };
994
995 struct XY
996 {
997   int x, y;
998 };
999
1000 struct Rect
1001 {
1002   int x, y;
1003   int width, height;
1004 };
1005
1006
1007 /* ========================================================================= */
1008 /* exported variables                                                        */
1009 /* ========================================================================= */
1010
1011 extern struct ProgramInfo       program;
1012 extern struct OptionInfo        options;
1013 extern struct VideoSystemInfo   video;
1014 extern struct AudioSystemInfo   audio;
1015 extern struct GfxInfo           gfx;
1016 extern struct AnimInfo          anim;
1017 extern struct ArtworkInfo       artwork;
1018 extern struct JoystickInfo      joystick;
1019 extern struct SetupInfo         setup;
1020
1021 extern LevelDirTree            *leveldir_first_all;
1022 extern LevelDirTree            *leveldir_first;
1023 extern LevelDirTree            *leveldir_current;
1024 extern int                      level_nr;
1025
1026 extern Display                 *display;
1027 extern Visual                  *visual;
1028 extern int                      screen;
1029 extern Colormap                 cmap;
1030
1031 extern DrawWindow              *window;
1032 extern DrawBuffer              *backbuffer;
1033 extern DrawBuffer              *drawto;
1034
1035 extern int                      button_status;
1036 extern boolean                  motion_status;
1037
1038 extern int                      redraw_mask;
1039 extern int                      redraw_tiles;
1040
1041 extern int                      FrameCounter;
1042
1043
1044 /* function definitions */
1045
1046 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
1047                      char *, char *, char *, char *, char *, int);
1048
1049 void InitExitFunction(void (*exit_function)(int));
1050 void InitPlatformDependentStuff(void);
1051 void ClosePlatformDependentStuff(void);
1052
1053 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
1054 void InitGfxDoor1Info(int, int, int, int);
1055 void InitGfxDoor2Info(int, int, int, int);
1056 void InitGfxScrollbufferInfo(int, int);
1057 void SetDrawDeactivationMask(int);
1058 void SetDrawBackgroundMask(int);
1059 void SetMainBackgroundBitmap(Bitmap *);
1060 void SetDoorBackgroundBitmap(Bitmap *);
1061
1062 void InitVideoDisplay(void);
1063 void CloseVideoDisplay(void);
1064 void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
1065 Bitmap *CreateBitmapStruct(void);
1066 Bitmap *CreateBitmap(int, int, int);
1067 void FreeBitmap(Bitmap *);
1068 void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
1069 void FadeRectangle(Bitmap *bitmap, int, int, int, int, int, int, int,
1070                    void (*draw_border_function)(void));
1071 void FillRectangle(Bitmap *, int, int, int, int, Pixel);
1072 void ClearRectangle(Bitmap *, int, int, int, int);
1073 void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
1074 void SetClipMask(Bitmap *, GC, Pixmap);
1075 void SetClipOrigin(Bitmap *, GC, int, int);
1076 void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
1077 boolean DrawingOnBackground(int, int);
1078 void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int, int);
1079 void DrawSimpleBlackLine(Bitmap *, int, int, int, int);
1080 void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
1081 void DrawLines(Bitmap *, struct XY *, int, Pixel);
1082 Pixel GetPixel(Bitmap *, int, int);
1083 Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
1084 Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
1085
1086 void FlushDisplay(void);
1087 void SyncDisplay(void);
1088 void KeyboardAutoRepeatOn(void);
1089 void KeyboardAutoRepeatOff(void);
1090 boolean PointerInWindow(DrawWindow *);
1091 boolean SetVideoMode(boolean);
1092 boolean ChangeVideoModeIfNeeded(boolean);
1093
1094 Bitmap *LoadImage(char *);
1095 Bitmap *LoadCustomImage(char *);
1096 void ReloadCustomImage(Bitmap *, char *);
1097
1098 Bitmap *ZoomBitmap(Bitmap *, int, int);
1099 void CreateBitmapWithSmallBitmaps(Bitmap *, int);
1100 void ScaleBitmap(Bitmap *, int);
1101
1102 void SetMouseCursor(int);
1103
1104 void OpenAudio(void);
1105 void CloseAudio(void);
1106 void SetAudioMode(boolean);
1107
1108 void InitEventFilter(EventFilter);
1109 boolean PendingEvent(void);
1110 void NextEvent(Event *event);
1111 void PeekEvent(Event *event);
1112 Key GetEventKey(KeyEvent *, boolean);
1113 KeyMod HandleKeyModState(Key, int);
1114 KeyMod GetKeyModState();
1115 KeyMod GetKeyModStateFromEvents();
1116 boolean CheckCloseWindowEvent(ClientMessageEvent *);
1117
1118 void InitJoysticks();
1119 boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
1120
1121 #endif /* SYSTEM_H */