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