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