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