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