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