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