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