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