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