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