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