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