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