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