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