rnd-20060430-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 KEY_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
565   int src_x, src_y;             /* start position of animation frames */
566   int width, height;            /* width/height of each animation frame */
567
568   int draw_xoffset;             /* offset for drawing font characters */
569   int draw_yoffset;             /* offset for drawing font characters */
570
571   int num_chars;
572   int num_chars_per_line;
573
574 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
575   Pixmap *clip_mask;            /* single-char-only clip mask array for X11 */
576 #endif
577 };
578
579 struct GfxInfo
580 {
581   int sx, sy;
582   int sxsize, sysize;
583   int real_sx, real_sy;
584   int full_sxsize, full_sysize;
585   int scrollbuffer_width, scrollbuffer_height;
586
587   int dx, dy;
588   int dxsize, dysize;
589
590   int vx, vy;
591   int vxsize, vysize;
592
593   int draw_deactivation_mask;
594   int draw_background_mask;
595
596   Bitmap *field_save_buffer;
597
598   Bitmap *background_bitmap;
599   int background_bitmap_mask;
600
601   int num_fonts;
602   struct FontBitmapInfo *font_bitmap_info;
603   int (*select_font_function)(int);
604
605   int anim_random_frame;
606 };
607
608 struct JoystickInfo
609 {
610   int status;
611   int fd[MAX_PLAYERS];          /* file descriptor of player's joystick */
612 };
613
614 struct SetupJoystickInfo
615 {
616   char *device_name;            /* device name of player's joystick */
617
618   int xleft, xmiddle, xright;
619   int yupper, ymiddle, ylower;
620   int snap, drop;
621 };
622
623 struct SetupKeyboardInfo
624 {
625   Key left, right, up, down;
626   Key snap, drop;
627 };
628
629 struct SetupInputInfo
630 {
631   boolean use_joystick;
632   struct SetupJoystickInfo joy;
633   struct SetupKeyboardInfo key;
634 };
635
636 struct SetupEditorInfo
637 {
638   boolean el_boulderdash;
639   boolean el_emerald_mine;
640   boolean el_emerald_mine_club;
641   boolean el_more;
642   boolean el_sokoban;
643   boolean el_supaplex;
644   boolean el_diamond_caves;
645   boolean el_dx_boulderdash;
646   boolean el_chars;
647   boolean el_custom;
648   boolean el_user_defined;
649   boolean el_dynamic;
650
651   boolean el_headlines;
652
653   boolean show_element_token;
654 };
655
656 struct SetupEditorCascadeInfo
657 {
658   boolean el_bd;
659   boolean el_em;
660   boolean el_emc;
661   boolean el_rnd;
662   boolean el_sb;
663   boolean el_sp;
664   boolean el_dc;
665   boolean el_dx;
666   boolean el_chars;
667   boolean el_ce;
668   boolean el_ge;
669   boolean el_user;
670   boolean el_dynamic;
671 };
672
673 struct SetupShortcutInfo
674 {
675   Key save_game;
676   Key load_game;
677   Key toggle_pause;
678
679   Key focus_player[MAX_PLAYERS];
680   Key focus_player_all;
681 };
682
683 struct SetupSystemInfo
684 {
685   char *sdl_audiodriver;
686   int audio_fragment_size;
687 };
688
689 struct SetupInfo
690 {
691   char *player_name;
692
693   boolean sound;
694   boolean sound_loops;
695   boolean sound_music;
696   boolean sound_simple;
697   boolean toons;
698   boolean double_buffering;
699   boolean direct_draw;          /* !double_buffering (redundant!) */
700   boolean scroll_delay;
701   boolean soft_scrolling;
702   boolean fading;
703   boolean autorecord;
704   boolean quick_doors;
705   boolean team_mode;
706   boolean handicap;
707   boolean skip_levels;
708   boolean time_limit;
709   boolean fullscreen;
710   boolean ask_on_escape;
711   boolean ask_on_escape_editor;
712   boolean quick_switch;
713   boolean input_on_focus;
714   boolean prefer_aga_graphics;
715
716   char *graphics_set;
717   char *sounds_set;
718   char *music_set;
719   boolean override_level_graphics;
720   boolean override_level_sounds;
721   boolean override_level_music;
722
723   struct SetupEditorInfo editor;
724   struct SetupEditorCascadeInfo editor_cascade;
725   struct SetupShortcutInfo shortcut;
726   struct SetupInputInfo input[MAX_PLAYERS];
727   struct SetupSystemInfo system;
728   struct OptionInfo options;
729 };
730
731 struct TreeInfo
732 {
733   struct TreeInfo **node_top;           /* topmost node in tree */
734   struct TreeInfo *node_parent;         /* parent level directory info */
735   struct TreeInfo *node_group;          /* level group sub-directory info */
736   struct TreeInfo *next;                /* next level series structure node */
737
738   int cl_first;         /* internal control field for setup screen */
739   int cl_cursor;        /* internal control field for setup screen */
740
741   int type;             /* type of tree content */
742
743   /* fields for "type == TREE_TYPE_LEVEL_DIR" */
744
745   char *subdir;         /* tree info sub-directory basename (may be ".") */
746   char *fullpath;       /* complete path relative to tree base directory */
747   char *basepath;       /* absolute base path of tree base directory */
748   char *identifier;     /* identifier string for configuration files */
749   char *name;           /* tree info name, as displayed in selection menues */
750   char *name_sorting;   /* optional sorting name for correct name sorting */
751   char *author;         /* level or artwork author name */
752   char *imported_from;  /* optional comment for imported levels or artwork */
753   char *imported_by;    /* optional comment for imported levels or artwork */
754
755   char *graphics_set_ecs; /* special EMC custom graphics set (ECS graphics) */
756   char *graphics_set_aga; /* special EMC custom graphics set (AGA graphics) */
757   char *graphics_set;   /* optional custom graphics set (level tree only) */
758   char *sounds_set;     /* optional custom sounds set (level tree only) */
759   char *music_set;      /* optional custom music set (level tree only) */
760   char *graphics_path;  /* path to optional custom graphics set (level only) */
761   char *sounds_path;    /* path to optional custom sounds set (level only) */
762   char *music_path;     /* path to optional custom music set (level only) */
763
764   char *level_filename; /* filename of level file (for packed level file) */
765   char *level_filetype; /* type of levels in level directory or level file */
766
767   int levels;           /* number of levels in level series */
768   int first_level;      /* first level number (to allow start with 0 or 1) */
769   int last_level;       /* last level number (automatically calculated) */
770   int sort_priority;    /* sort levels by 'sort_priority' and then by name */
771
772   boolean latest_engine;/* force level set to use the latest game engine */
773
774   boolean level_group;  /* directory contains more level series directories */
775   boolean parent_link;  /* entry links back to parent directory */
776   boolean in_user_dir;  /* user defined levels are stored in home directory */
777   boolean user_defined; /* levels in user directory and marked as "private" */
778   boolean readonly;     /* readonly levels can not be changed with editor */
779   boolean handicap;     /* level set has no handicap when set to "false" */
780   boolean skip_levels;  /* levels can be skipped when set to "true" */
781
782   int color;            /* color to use on selection screen for this level */
783   char *class_desc;     /* description of level series class */
784   int handicap_level;   /* number of the lowest unsolved level */
785 };
786
787 typedef struct TreeInfo TreeInfo;
788 typedef struct TreeInfo LevelDirTree;
789 typedef struct TreeInfo ArtworkDirTree;
790 typedef struct TreeInfo GraphicsDirTree;
791 typedef struct TreeInfo SoundsDirTree;
792 typedef struct TreeInfo MusicDirTree;
793
794 struct ArtworkInfo
795 {
796   GraphicsDirTree *gfx_first;
797   GraphicsDirTree *gfx_current;
798   SoundsDirTree *snd_first;
799   SoundsDirTree *snd_current;
800   MusicDirTree *mus_first;
801   MusicDirTree *mus_current;
802
803   char *gfx_current_identifier;
804   char *snd_current_identifier;
805   char *mus_current_identifier;
806 };
807
808 struct ValueTextInfo
809 {
810   int value;
811   char *text;
812 };
813
814 struct ConfigInfo
815 {
816   char *token;
817   char *value;
818 };
819
820 struct ConfigTypeInfo
821 {
822   char *token;
823   char *value;
824   int type;
825 };
826
827 struct TokenIntPtrInfo
828 {
829   char *token;
830   int *value;
831 };
832
833 struct FileInfo
834 {
835   char *token;
836
837   char *default_filename;
838   char *filename;
839
840   char **default_parameter;                     /* array of file parameters */
841   char **parameter;                             /* array of file parameters */
842
843   boolean redefined;
844   boolean fallback_to_default;
845 };
846
847 struct SetupFileList
848 {
849   char *token;
850   char *value;
851
852   struct SetupFileList *next;
853 };
854
855 struct ListNodeInfo
856 {
857   char *source_filename;                        /* primary key for node list */
858   int num_references;
859 };
860
861 struct PropertyMapping
862 {
863   int base_index;
864   int ext1_index;
865   int ext2_index;
866   int ext3_index;
867
868   int artwork_index;
869 };
870
871 struct ArtworkListInfo
872 {
873   int type;                                     /* type of artwork */
874
875   int num_file_list_entries;
876   int num_dynamic_file_list_entries;
877   struct FileInfo *file_list;                   /* static artwork file array */
878   struct FileInfo *dynamic_file_list;           /* dynamic artwrk file array */
879
880   int num_suffix_list_entries;
881   struct ConfigTypeInfo *suffix_list;           /* parameter suffixes array */
882
883   int num_base_prefixes;
884   int num_ext1_suffixes;
885   int num_ext2_suffixes;
886   int num_ext3_suffixes;
887   char **base_prefixes;                         /* base token prefixes array */
888   char **ext1_suffixes;                         /* property suffixes array 1 */
889   char **ext2_suffixes;                         /* property suffixes array 2 */
890   char **ext3_suffixes;                         /* property suffixes array 3 */
891
892   int num_ignore_tokens;
893   char **ignore_tokens;                         /* file tokens to be ignored */
894
895   int num_property_mapping_entries;
896   struct PropertyMapping *property_mapping;     /* mapping token -> artwork */
897
898   int sizeof_artwork_list_entry;
899
900   struct ListNodeInfo **artwork_list;           /* static artwork node array */
901   struct ListNodeInfo **dynamic_artwork_list;   /* dynamic artwrk node array */
902   struct ListNode *content_list;                /* dynamic artwork node list */
903
904   void *(*load_artwork)(char *);                /* constructor function */
905   void (*free_artwork)(void *);                 /* destructor function */
906 };
907
908
909 /* ========================================================================= */
910 /* exported variables                                                        */
911 /* ========================================================================= */
912
913 extern struct ProgramInfo       program;
914 extern struct OptionInfo        options;
915 extern struct VideoSystemInfo   video;
916 extern struct AudioSystemInfo   audio;
917 extern struct GfxInfo           gfx;
918 extern struct AnimInfo          anim;
919 extern struct ArtworkInfo       artwork;
920 extern struct JoystickInfo      joystick;
921 extern struct SetupInfo         setup;
922
923 extern LevelDirTree            *leveldir_first_all;
924 extern LevelDirTree            *leveldir_first;
925 extern LevelDirTree            *leveldir_current;
926 extern int                      level_nr;
927
928 extern Display                 *display;
929 extern Visual                  *visual;
930 extern int                      screen;
931 extern Colormap                 cmap;
932
933 extern DrawWindow              *window;
934 extern DrawBuffer              *backbuffer;
935 extern DrawBuffer              *drawto;
936
937 extern int                      button_status;
938 extern boolean                  motion_status;
939
940 extern int                      redraw_mask;
941 extern int                      redraw_tiles;
942
943 extern int                      FrameCounter;
944
945
946 /* function definitions */
947
948 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
949                      char *, char *, char *, int);
950
951 void InitExitFunction(void (*exit_function)(int));
952 void InitPlatformDependentStuff(void);
953 void ClosePlatformDependentStuff(void);
954
955 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
956 void InitGfxDoor1Info(int, int, int, int);
957 void InitGfxDoor2Info(int, int, int, int);
958 void InitGfxScrollbufferInfo(int, int);
959 void SetDrawDeactivationMask(int);
960 void SetDrawBackgroundMask(int);
961 void SetMainBackgroundBitmap(Bitmap *);
962 void SetDoorBackgroundBitmap(Bitmap *);
963
964 inline void InitVideoDisplay(void);
965 inline void CloseVideoDisplay(void);
966 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
967 inline Bitmap *CreateBitmapStruct(void);
968 inline Bitmap *CreateBitmap(int, int, int);
969 inline void FreeBitmap(Bitmap *);
970 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
971 inline void FillRectangle(Bitmap *, int, int, int, int, Pixel);
972 inline void ClearRectangle(Bitmap *, int, int, int, int);
973 inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
974 inline void SetClipMask(Bitmap *, GC, Pixmap);
975 inline void SetClipOrigin(Bitmap *, GC, int, int);
976 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
977 inline boolean DrawingOnBackground(int, int);
978 inline void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int,
979                                    int);
980 inline void DrawSimpleBlackLine(Bitmap *, int, int, int, int);
981 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
982 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
983 inline Pixel GetPixel(Bitmap *, int, int);
984 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
985 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
986
987 inline void FlushDisplay(void);
988 inline void SyncDisplay(void);
989 inline void KeyboardAutoRepeatOn(void);
990 inline void KeyboardAutoRepeatOff(void);
991 inline boolean PointerInWindow(DrawWindow *);
992 inline boolean SetVideoMode(boolean);
993 inline boolean ChangeVideoModeIfNeeded(boolean);
994
995 Bitmap *LoadImage(char *);
996 Bitmap *LoadCustomImage(char *);
997 void ReloadCustomImage(Bitmap *, char *);
998
999 Bitmap *ZoomBitmap(Bitmap *, int, int);
1000 void CreateBitmapWithSmallBitmaps(Bitmap *, int);
1001 void ScaleBitmap(Bitmap *, int);
1002
1003 void SetMouseCursor(int);
1004
1005 inline void OpenAudio(void);
1006 inline void CloseAudio(void);
1007 inline void SetAudioMode(boolean);
1008
1009 inline void InitEventFilter(EventFilter);
1010 inline boolean PendingEvent(void);
1011 inline void NextEvent(Event *event);
1012 inline void PeekEvent(Event *event);
1013 inline Key GetEventKey(KeyEvent *, boolean);
1014 inline KeyMod HandleKeyModState(Key, int);
1015 inline KeyMod GetKeyModState();
1016 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
1017
1018 inline void InitJoysticks();
1019 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
1020
1021 #endif /* SYSTEM_H */