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