rnd-20060117-1-src
[rocksndiamonds.git] / src / libgame / system.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * system.h                                                 *
12 ***********************************************************/
13
14 #ifndef SYSTEM_H
15 #define SYSTEM_H
16
17 #include "platform.h"
18 #include "types.h"
19
20
21 #if defined(PLATFORM_MACOSX)
22 #include "macosx.h"
23 #elif defined(PLATFORM_WIN32)
24 #include "windows.h"
25 #elif defined(PLATFORM_MSDOS)
26 #include "msdos.h"
27 #endif
28
29 #if defined(TARGET_SDL)
30 #include "sdl.h"
31 #elif defined(TARGET_X11)
32 #include "x11.h"
33 #endif
34
35
36 /* the additional 'b' is needed for Win32 to open files in binary mode */
37 #define MODE_READ               "rb"
38 #define MODE_WRITE              "wb"
39 #define MODE_APPEND             "ab"
40
41 #define DEFAULT_DEPTH           0
42
43 #define BLIT_OPAQUE             0
44 #define BLIT_MASKED             1
45 #define BLIT_INVERSE            2
46 #define BLIT_ON_BACKGROUND      3
47
48 #define FULLSCREEN_NOT_AVAILABLE FALSE
49 #define FULLSCREEN_AVAILABLE     TRUE
50
51 /* default input keys */
52 #define DEFAULT_KEY_LEFT        KSYM_Left
53 #define DEFAULT_KEY_RIGHT       KSYM_Right
54 #define DEFAULT_KEY_UP          KSYM_Up
55 #define DEFAULT_KEY_DOWN        KSYM_Down
56 #if defined(PLATFORM_MACOSX)
57 #define DEFAULT_KEY_SNAP        KSYM_Control_L
58 #define DEFAULT_KEY_DROP        KSYM_KP_Enter
59 #else
60 #define DEFAULT_KEY_SNAP        KSYM_Control_L
61 #define DEFAULT_KEY_DROP        KSYM_Control_R
62 #endif
63 #define DEFAULT_KEY_OKAY        KSYM_Return
64 #define DEFAULT_KEY_CANCEL      KSYM_Escape
65
66 /* default shortcut keys */
67 #define DEFAULT_KEY_SAVE_GAME   KSYM_F1
68 #define DEFAULT_KEY_LOAD_GAME   KSYM_F2
69 #define DEFAULT_KEY_TOGGLE_PAUSE KSYM_space
70
71 /* values for key_status */
72 #define KEY_NOT_PRESSED         FALSE
73 #define KEY_RELEASED            FALSE
74 #define KEY_PRESSED             TRUE
75
76 /* values for button status */
77 #define MB_NOT_PRESSED          FALSE
78 #define MB_NOT_RELEASED         TRUE
79 #define MB_RELEASED             FALSE
80 #define MB_PRESSED              TRUE
81 #define MB_MENU_CHOICE          FALSE
82 #define MB_MENU_MARK            TRUE
83 #define MB_MENU_INITIALIZE      (-1)
84 #define MB_MENU_LEAVE           (-2)
85 #define MB_LEFTBUTTON           1
86 #define MB_MIDDLEBUTTON         2
87 #define MB_RIGHTBUTTON          3
88
89
90 /* values for move directions */
91 #define MV_BIT_LEFT             0
92 #define MV_BIT_RIGHT            1
93 #define MV_BIT_UP               2
94 #define MV_BIT_DOWN             3
95
96 #define NUM_DIRECTIONS          4
97
98 /* values for special "button" bitmasks */
99 #define BUTTON_1                4
100 #define BUTTON_2                5
101
102 /* values for move directions and special "button" key bitmasks */
103 #define MV_NONE                 0
104 #define MV_LEFT                 (1 << MV_BIT_LEFT)
105 #define MV_RIGHT                (1 << MV_BIT_RIGHT)
106 #define MV_UP                   (1 << MV_BIT_UP)
107 #define MV_DOWN                 (1 << MV_BIT_DOWN)
108
109 #define MV_HORIZONTAL           (MV_LEFT | MV_RIGHT)
110 #define MV_VERTICAL             (MV_UP   | MV_DOWN)
111 #define MV_ALL_DIRECTIONS       (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
112 #define MV_ANY_DIRECTION        (MV_ALL_DIRECTIONS)
113 #define MV_NO_DIRECTION         (MV_NONE)
114
115 #define KEY_BUTTON_1            (1 << BUTTON_1)
116 #define KEY_BUTTON_2            (1 << BUTTON_2)
117 #define KEY_MOTION              (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
118 #define KEY_BUTTON              (KEY_BUTTON_1 | KEY_BUTTON_2)
119 #define KEY_ACTION              (KEY_MOTION | KEY_BUTTON)
120
121 #define MV_DIR_BIT(x)           ((x) == MV_LEFT  ? MV_BIT_LEFT  :       \
122                                  (x) == MV_RIGHT ? MV_BIT_RIGHT :       \
123                                  (x) == MV_UP    ? MV_BIT_UP    : MV_BIT_DOWN)
124
125 #define MV_DIR_OPPOSITE(x)      ((x) == MV_LEFT  ? MV_RIGHT :           \
126                                  (x) == MV_RIGHT ? MV_LEFT  :           \
127                                  (x) == MV_UP    ? MV_DOWN  :           \
128                                  (x) == MV_DOWN  ? MV_UP    : MV_NONE)
129
130
131 /* values for animation mode (frame order and direction) */
132 #define ANIM_NONE               0
133 #define ANIM_LOOP               (1 << 0)
134 #define ANIM_LINEAR             (1 << 1)
135 #define ANIM_PINGPONG           (1 << 2)
136 #define ANIM_PINGPONG2          (1 << 3)
137 #define ANIM_RANDOM             (1 << 4)
138 #define ANIM_CE_VALUE           (1 << 5)
139 #define ANIM_CE_SCORE           (1 << 6)
140 #define ANIM_REVERSE            (1 << 7)
141
142 /* values for special (non game element) animation modes */
143 #define ANIM_HORIZONTAL         (1 << 8)
144 #define ANIM_VERTICAL           (1 << 9)
145 #define ANIM_STATIC_PANEL       (1 << 10)
146
147 #define ANIM_DEFAULT            ANIM_LOOP
148
149 /* values for redraw_mask */
150 #define REDRAW_NONE             (0)
151 #define REDRAW_ALL              (1 << 0)
152 #define REDRAW_FIELD            (1 << 1)
153 #define REDRAW_TILES            (1 << 2)
154 #define REDRAW_DOOR_1           (1 << 3)
155 #define REDRAW_VIDEO_1          (1 << 4)
156 #define REDRAW_VIDEO_2          (1 << 5)
157 #define REDRAW_VIDEO_3          (1 << 6)
158 #define REDRAW_MICROLEVEL       (1 << 7)
159 #define REDRAW_MICROLABEL       (1 << 8)
160 #define REDRAW_FROM_BACKBUFFER  (1 << 9)
161 #define REDRAW_DOOR_2           (REDRAW_VIDEO_1 | \
162                                  REDRAW_VIDEO_2 | \
163                                  REDRAW_VIDEO_3)
164 #define REDRAW_DOOR_3           (1 << 10)
165 #define REDRAW_DOORS            (REDRAW_DOOR_1 | \
166                                  REDRAW_DOOR_2 | \
167                                  REDRAW_DOOR_3)
168 #define REDRAW_MAIN             (REDRAW_FIELD | \
169                                  REDRAW_TILES | \
170                                  REDRAW_MICROLEVEL)
171 #define REDRAW_FPS              (1 << 11)
172 #define REDRAWTILES_THRESHOLD   (SCR_FIELDX * SCR_FIELDY / 2)
173
174 #define IN_GFX_SCREEN(x, y)     (x >= gfx.sx && x < gfx.sx + gfx.sxsize && \
175                                  y >= gfx.sy && y < gfx.sy + gfx.sysize)
176 #define IN_GFX_DOOR(x, y)       (x >= gfx.dx && x < gfx.dx + gfx.dxsize && \
177                                  y >= gfx.dy && y < gfx.dy + gfx.dysize)
178 #define IN_GFX_VIDEO(x, y)      (x >= gfx.vx && x < gfx.vx + gfx.vxsize && \
179                                  y >= gfx.vy && y < gfx.vy + gfx.vysize)
180
181 /* values for mouse cursor */
182 #define CURSOR_DEFAULT          0
183 #define CURSOR_PLAYFIELD        1
184
185
186 /* maximum number of parallel players supported by libgame functions */
187 #define MAX_PLAYERS             4
188
189 /* maximum allowed length of player name */
190 #define MAX_PLAYER_NAME_LEN     10
191
192 /* default name for empty highscore entry */
193 #define EMPTY_PLAYER_NAME       "no name"
194
195 /* default name for unknown player names */
196 #define ANONYMOUS_NAME          "anonymous"
197
198 /* default for other unknown names */
199 #define UNKNOWN_NAME            "unknown"
200
201 /* default name for new levels */
202 #define NAMELESS_LEVEL_NAME     "nameless level"
203
204 /* default text for non-existant artwork */
205 #define NOT_AVAILABLE           "(not available)"
206
207 /* default value for undefined filename */
208 #define UNDEFINED_FILENAME      "[NONE]"
209
210 /* default value for undefined parameter */
211 #define ARG_DEFAULT             "[DEFAULT]"
212
213 /* default values for undefined configuration file parameters */
214 #define ARG_UNDEFINED           "-1000000"
215 #define ARG_UNDEFINED_VALUE     (atoi(ARG_UNDEFINED))
216
217 /* definitions for game sub-directories */
218 #ifndef RO_GAME_DIR
219 #define RO_GAME_DIR             "."
220 #endif
221
222 #ifndef RW_GAME_DIR
223 #define RW_GAME_DIR             "."
224 #endif
225
226 #define RO_BASE_PATH            RO_GAME_DIR
227 #define RW_BASE_PATH            RW_GAME_DIR
228
229 /* directory names */
230 #define GRAPHICS_DIRECTORY      "graphics"
231 #define SOUNDS_DIRECTORY        "sounds"
232 #define MUSIC_DIRECTORY         "music"
233 #define LEVELS_DIRECTORY        "levels"
234 #define TAPES_DIRECTORY         "tapes"
235 #define SCORES_DIRECTORY        "scores"
236 #define DOCS_DIRECTORY          "docs"
237
238 #if !defined(PLATFORM_MSDOS)
239 #define GFX_CLASSIC_SUBDIR      "gfx_classic"
240 #define SND_CLASSIC_SUBDIR      "snd_classic"
241 #define MUS_CLASSIC_SUBDIR      "mus_classic"
242 #else
243 #define GFX_CLASSIC_SUBDIR      "gfx_orig"
244 #define SND_CLASSIC_SUBDIR      "snd_orig"
245 #define MUS_CLASSIC_SUBDIR      "mus_orig"
246 #endif
247
248 /* file names and filename extensions */
249 #if !defined(PLATFORM_MSDOS)
250 #define LEVELSETUP_DIRECTORY    "levelsetup"
251 #define SETUP_FILENAME          "setup.conf"
252 #define LEVELSETUP_FILENAME     "levelsetup.conf"
253 #define EDITORSETUP_FILENAME    "editorsetup.conf"
254 #define EDITORCASCADE_FILENAME  "editorcascade.conf"
255 #define HELPANIM_FILENAME       "helpanim.conf"
256 #define HELPTEXT_FILENAME       "helptext.conf"
257 #define LEVELINFO_FILENAME      "levelinfo.conf"
258 #define GRAPHICSINFO_FILENAME   "graphicsinfo.conf"
259 #define SOUNDSINFO_FILENAME     "soundsinfo.conf"
260 #define MUSICINFO_FILENAME      "musicinfo.conf"
261 #define LEVELFILE_EXTENSION     "level"
262 #define TAPEFILE_EXTENSION      "tape"
263 #define SCOREFILE_EXTENSION     "score"
264 #else
265 #define LEVELSETUP_DIRECTORY    "lvlsetup"
266 #define SETUP_FILENAME          "setup.cnf"
267 #define LEVELSETUP_FILENAME     "lvlsetup.cnf"
268 #define EDITORSETUP_FILENAME    "edsetup.cnf"
269 #define EDITORCASCADE_FILENAME  "edcascad.conf"
270 #define HELPANIM_FILENAME       "helpanim.cnf"
271 #define HELPTEXT_FILENAME       "helptext.cnf"
272 #define LEVELINFO_FILENAME      "lvlinfo.cnf"
273 #define GRAPHICSINFO_FILENAME   "gfxinfo.cnf"
274 #define SOUNDSINFO_FILENAME     "sndinfo.cnf"
275 #define MUSICINFO_FILENAME      "musinfo.cnf"
276 #define LEVELFILE_EXTENSION     "lvl"
277 #define TAPEFILE_EXTENSION      "tap"
278 #define SCOREFILE_EXTENSION     "sco"
279 #endif
280
281
282 /* areas in bitmap PIX_DOOR */
283 /* meaning in PIX_DB_DOOR: (3 PAGEs)
284    PAGEX1: 1. buffer for DOOR_1
285    PAGEX2: 2. buffer for DOOR_1
286    PAGEX3: buffer for animations
287 */
288
289 /* these values are hard-coded to be able to use them in initialization */
290 #define DOOR_GFX_PAGE_WIDTH     100     /* should be set to "gfx.dxsize" */
291 #define DOOR_GFX_PAGE_HEIGHT    280     /* should be set to "gfx.dysize" */
292
293 #define DOOR_GFX_PAGESIZE       (DOOR_GFX_PAGE_WIDTH)
294 #define DOOR_GFX_PAGEX1         (0 * DOOR_GFX_PAGESIZE)
295 #define DOOR_GFX_PAGEX2         (1 * DOOR_GFX_PAGESIZE)
296 #define DOOR_GFX_PAGEX3         (2 * DOOR_GFX_PAGESIZE)
297 #define DOOR_GFX_PAGEX4         (3 * DOOR_GFX_PAGESIZE)
298 #define DOOR_GFX_PAGEX5         (4 * DOOR_GFX_PAGESIZE)
299 #define DOOR_GFX_PAGEX6         (5 * DOOR_GFX_PAGESIZE)
300 #define DOOR_GFX_PAGEX7         (6 * DOOR_GFX_PAGESIZE)
301 #define DOOR_GFX_PAGEX8         (7 * DOOR_GFX_PAGESIZE)
302 #define DOOR_GFX_PAGEY1         (0)
303 #define DOOR_GFX_PAGEY2         (DOOR_GFX_PAGE_HEIGHT)
304
305
306 /* macros for version handling */
307 #define VERSION_MAJOR(x)        ((x) / 1000000)
308 #define VERSION_MINOR(x)        (((x) % 1000000) / 10000)
309 #define VERSION_PATCH(x)        (((x) % 10000) / 100)
310 #define VERSION_BUILD(x)        ((x) % 100)
311 #define VERSION_IDENT(a,b,c,d)  ((a) * 1000000 + (b) * 10000 + (c) * 100 + (d))
312
313
314 /* macros for parent/child process identification */
315 #if defined(PLATFORM_UNIX)
316 #define IS_PARENT_PROCESS()     (audio.mixer_pid != getpid())
317 #define IS_CHILD_PROCESS()      (audio.mixer_pid == getpid())
318 #define HAS_CHILD_PROCESS()     (audio.mixer_pid > 0)
319 #else
320 #define IS_PARENT_PROCESS()     TRUE
321 #define IS_CHILD_PROCESS()      FALSE
322 #define HAS_CHILD_PROCESS()     FALSE
323 #endif
324
325
326 /* values for artwork type */
327 #define ARTWORK_TYPE_GRAPHICS   0
328 #define ARTWORK_TYPE_SOUNDS     1
329 #define ARTWORK_TYPE_MUSIC      2
330
331 #define NUM_ARTWORK_TYPES       3
332
333
334 /* values for tree type (chosen to match artwork type) */
335 #define TREE_TYPE_UNDEFINED     -1
336 #define TREE_TYPE_GRAPHICS_DIR  ARTWORK_TYPE_GRAPHICS
337 #define TREE_TYPE_SOUNDS_DIR    ARTWORK_TYPE_SOUNDS
338 #define TREE_TYPE_MUSIC_DIR     ARTWORK_TYPE_MUSIC
339 #define TREE_TYPE_LEVEL_DIR     3
340
341 #define NUM_TREE_TYPES          4
342
343
344 /* values for artwork handling */
345 #define LEVELDIR_ARTWORK_SET_PTR(leveldir, type)                        \
346                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
347                                  &(leveldir)->graphics_set :            \
348                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
349                                  &(leveldir)->sounds_set :              \
350                                  &(leveldir)->music_set)
351
352 #define LEVELDIR_ARTWORK_SET(leveldir, type)                            \
353                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
354                                  (leveldir)->graphics_set :             \
355                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
356                                  (leveldir)->sounds_set :               \
357                                  (leveldir)->music_set)
358
359 #define LEVELDIR_ARTWORK_PATH_PTR(leveldir, type)                       \
360                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
361                                  &(leveldir)->graphics_path :           \
362                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
363                                  &(leveldir)->sounds_path :             \
364                                  &(leveldir)->music_path)
365
366 #define LEVELDIR_ARTWORK_PATH(leveldir, type)                           \
367                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
368                                  (leveldir)->graphics_path :            \
369                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
370                                  (leveldir)->sounds_path :              \
371                                  (leveldir)->music_path)
372
373 #define SETUP_ARTWORK_SET(setup, type)                                  \
374                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
375                                  (setup).graphics_set :                 \
376                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
377                                  (setup).sounds_set :                   \
378                                  (setup).music_set)
379
380 #define SETUP_OVERRIDE_ARTWORK(setup, type)                             \
381                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
382                                  (setup).override_level_graphics :      \
383                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
384                                  (setup).override_level_sounds :        \
385                                  (setup).override_level_music)
386
387 #define ARTWORK_FIRST_NODE(artwork, type)                               \
388                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
389                                  (artwork).gfx_first :  \
390                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
391                                  (artwork).snd_first :  \
392                                  (artwork).mus_first)
393
394 #define ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type)                   \
395                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
396                                  &(artwork).gfx_current_identifier :    \
397                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
398                                  &(artwork).snd_current_identifier :    \
399                                  &(artwork).mus_current_identifier)
400
401 #define ARTWORK_CURRENT_IDENTIFIER(artwork, type)                       \
402                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
403                                  (artwork).gfx_current_identifier :     \
404                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
405                                  (artwork).snd_current_identifier :     \
406                                  (artwork).mus_current_identifier)
407
408 #define ARTWORKINFO_FILENAME(type)                                      \
409                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
410                                  GRAPHICSINFO_FILENAME :                \
411                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
412                                  SOUNDSINFO_FILENAME :                  \
413                                  (type) == ARTWORK_TYPE_MUSIC ?         \
414                                  MUSICINFO_FILENAME : "")
415
416 #define ARTWORK_DIRECTORY(type)                                         \
417                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
418                                  GRAPHICS_DIRECTORY :                   \
419                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
420                                  SOUNDS_DIRECTORY :                     \
421                                  (type) == ARTWORK_TYPE_MUSIC ?         \
422                                  MUSIC_DIRECTORY : "")
423
424 #define OPTIONS_ARTWORK_DIRECTORY(type)                                 \
425                                 ((type) == ARTWORK_TYPE_GRAPHICS ?      \
426                                  options.graphics_directory :           \
427                                  (type) == ARTWORK_TYPE_SOUNDS ?        \
428                                  options.sounds_directory :             \
429                                  (type) == ARTWORK_TYPE_MUSIC ?         \
430                                  options.music_directory : "")
431
432
433 /* type definitions */
434 typedef int (*EventFilter)(const Event *);
435
436
437 /* structure definitions */
438
439 struct ProgramInfo
440 {
441   char *command_basepath;       /* directory that contains the program */
442   char *command_basename;       /* base filename of the program binary */
443   char *userdata_directory;     /* personal user data directory */
444
445   char *program_title;
446   char *window_title;
447   char *icon_title;
448
449   char *x11_icon_filename;
450   char *x11_iconmask_filename;
451   char *msdos_cursor_filename;
452
453   char *cookie_prefix;
454   char *filename_prefix;        /* prefix to cut off from DOS filenames */
455
456   int version_major;
457   int version_minor;
458   int version_patch;
459
460   void (*exit_function)(int);
461 };
462
463 struct OptionInfo
464 {
465   char *display_name;
466   char *server_host;
467   int server_port;
468
469   char *ro_base_directory;
470   char *rw_base_directory;
471   char *level_directory;
472   char *graphics_directory;
473   char *sounds_directory;
474   char *music_directory;
475   char *docs_directory;
476   char *execute_command;
477
478   boolean serveronly;
479   boolean network;
480   boolean verbose;
481   boolean debug;
482 };
483
484 struct VideoSystemInfo
485 {
486   int default_depth;
487   int width, height, depth;
488   boolean fullscreen_available;
489   boolean fullscreen_enabled;
490 };
491
492 struct AudioSystemInfo
493 {
494   boolean sound_available;
495   boolean loops_available;
496   boolean music_available;
497
498   boolean sound_enabled;
499   boolean sound_deactivated;    /* for temporarily disabling sound */
500
501   int mixer_pipe[2];
502   int mixer_pid;
503   char *device_name;
504   int device_fd;
505
506   int num_channels;
507   int music_channel;
508   int first_sound_channel;
509 };
510
511 struct FontBitmapInfo
512 {
513   Bitmap *bitmap;
514   int src_x, src_y;             /* start position of animation frames */
515   int width, height;            /* width/height of each animation frame */
516   int draw_x, draw_y;           /* offset for drawing font characters */
517   int num_chars;
518   int num_chars_per_line;
519
520 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
521   Pixmap *clip_mask;            /* single-char-only clip mask array for X11 */
522 #endif
523 };
524
525 struct GfxInfo
526 {
527   int sx, sy;
528   int sxsize, sysize;
529   int real_sx, real_sy;
530   int full_sxsize, full_sysize;
531   int scrollbuffer_width, scrollbuffer_height;
532
533   int dx, dy;
534   int dxsize, dysize;
535
536   int vx, vy;
537   int vxsize, vysize;
538
539   int draw_deactivation_mask;
540   int draw_background_mask;
541
542   Bitmap *field_save_buffer;
543
544   Bitmap *background_bitmap;
545   int background_bitmap_mask;
546
547   int num_fonts;
548   struct FontBitmapInfo *font_bitmap_info;
549   int (*select_font_function)(int);
550
551   int anim_random_frame;
552 };
553
554 struct JoystickInfo
555 {
556   int status;
557   int fd[MAX_PLAYERS];          /* file descriptor of player's joystick */
558 };
559
560 struct SetupJoystickInfo
561 {
562   char *device_name;            /* device name of player's joystick */
563
564   int xleft, xmiddle, xright;
565   int yupper, ymiddle, ylower;
566   int snap, drop;
567 };
568
569 struct SetupKeyboardInfo
570 {
571   Key left, right, up, down;
572   Key snap, drop;
573 };
574
575 struct SetupInputInfo
576 {
577   boolean use_joystick;
578   struct SetupJoystickInfo joy;
579   struct SetupKeyboardInfo key;
580 };
581
582 struct SetupEditorInfo
583 {
584   boolean el_boulderdash;
585   boolean el_emerald_mine;
586   boolean el_emerald_mine_club;
587   boolean el_more;
588   boolean el_sokoban;
589   boolean el_supaplex;
590   boolean el_diamond_caves;
591   boolean el_dx_boulderdash;
592   boolean el_chars;
593   boolean el_custom;
594   boolean el_user_defined;
595   boolean el_dynamic;
596
597   boolean el_headlines;
598 };
599
600 struct SetupEditorCascadeInfo
601 {
602   boolean el_bd;
603   boolean el_em;
604   boolean el_emc;
605   boolean el_rnd;
606   boolean el_sb;
607   boolean el_sp;
608   boolean el_dc;
609   boolean el_dx;
610   boolean el_chars;
611   boolean el_ce;
612   boolean el_ge;
613   boolean el_user;
614   boolean el_generic;
615   boolean el_dynamic;
616 };
617
618 struct SetupShortcutInfo
619 {
620   Key save_game;
621   Key load_game;
622   Key toggle_pause;
623 };
624
625 struct SetupSystemInfo
626 {
627   char *sdl_audiodriver;
628   int audio_fragment_size;
629 };
630
631 struct SetupInfo
632 {
633   char *player_name;
634
635   boolean sound;
636   boolean sound_loops;
637   boolean sound_music;
638   boolean sound_simple;
639   boolean toons;
640   boolean double_buffering;
641   boolean direct_draw;          /* !double_buffering (redundant!) */
642   boolean scroll_delay;
643   boolean soft_scrolling;
644   boolean fading;
645   boolean autorecord;
646   boolean quick_doors;
647   boolean team_mode;
648   boolean handicap;
649   boolean skip_levels;
650   boolean time_limit;
651   boolean fullscreen;
652   boolean ask_on_escape;
653
654   char *graphics_set;
655   char *sounds_set;
656   char *music_set;
657   boolean override_level_graphics;
658   boolean override_level_sounds;
659   boolean override_level_music;
660
661   struct SetupEditorInfo editor;
662   struct SetupEditorCascadeInfo editor_cascade;
663   struct SetupShortcutInfo shortcut;
664   struct SetupInputInfo input[MAX_PLAYERS];
665   struct SetupSystemInfo system;
666   struct OptionInfo options;
667 };
668
669 struct TreeInfo
670 {
671   struct TreeInfo **node_top;           /* topmost node in tree */
672   struct TreeInfo *node_parent;         /* parent level directory info */
673   struct TreeInfo *node_group;          /* level group sub-directory info */
674   struct TreeInfo *next;                /* next level series structure node */
675
676   int cl_first;         /* internal control field for setup screen */
677   int cl_cursor;        /* internal control field for setup screen */
678
679   int type;             /* type of tree content */
680
681   /* fields for "type == TREE_TYPE_LEVEL_DIR" */
682
683   char *subdir;         /* tree info sub-directory basename (may be ".") */
684   char *fullpath;       /* complete path relative to tree base directory */
685   char *basepath;       /* absolute base path of tree base directory */
686   char *identifier;     /* identifier string for configuration files */
687   char *name;           /* tree info name, as displayed in selection menues */
688   char *name_sorting;   /* optional sorting name for correct name sorting */
689   char *author;         /* level or artwork author name */
690   char *imported_from;  /* optional comment for imported levels or artwork */
691   char *imported_by;    /* optional comment for imported levels or artwork */
692
693   char *graphics_set;   /* optional custom graphics set (level tree only) */
694   char *sounds_set;     /* optional custom sounds set (level tree only) */
695   char *music_set;      /* optional custom music set (level tree only) */
696   char *graphics_path;  /* path to optional custom graphics set (level only) */
697   char *sounds_path;    /* path to optional custom sounds set (level only) */
698   char *music_path;     /* path to optional custom music set (level only) */
699
700   char *level_filename; /* filename of level file (for packed level file) */
701   char *level_filetype; /* type of levels in level directory or level file */
702
703   int levels;           /* number of levels in level series */
704   int first_level;      /* first level number (to allow start with 0 or 1) */
705   int last_level;       /* last level number (automatically calculated) */
706   int sort_priority;    /* sort levels by 'sort_priority' and then by name */
707
708   boolean latest_engine;/* force level set to use the latest game engine */
709
710   boolean level_group;  /* directory contains more level series directories */
711   boolean parent_link;  /* entry links back to parent directory */
712   boolean in_user_dir;  /* user defined levels are stored in home directory */
713   boolean user_defined; /* levels in user directory and marked as "private" */
714   boolean readonly;     /* readonly levels can not be changed with editor */
715   boolean handicap;     /* level set has no handicap when set to "false" */
716   boolean skip_levels;  /* levels can be skipped when set to "true" */
717
718   int color;            /* color to use on selection screen for this level */
719   char *class_desc;     /* description of level series class */
720   int handicap_level;   /* number of the lowest unsolved level */
721 };
722
723 typedef struct TreeInfo TreeInfo;
724 typedef struct TreeInfo LevelDirTree;
725 typedef struct TreeInfo ArtworkDirTree;
726 typedef struct TreeInfo GraphicsDirTree;
727 typedef struct TreeInfo SoundsDirTree;
728 typedef struct TreeInfo MusicDirTree;
729
730 struct ArtworkInfo
731 {
732   GraphicsDirTree *gfx_first;
733   GraphicsDirTree *gfx_current;
734   SoundsDirTree *snd_first;
735   SoundsDirTree *snd_current;
736   MusicDirTree *mus_first;
737   MusicDirTree *mus_current;
738
739   char *gfx_current_identifier;
740   char *snd_current_identifier;
741   char *mus_current_identifier;
742 };
743
744 struct ValueTextInfo
745 {
746   int value;
747   char *text;
748 };
749
750 struct ConfigInfo
751 {
752   char *token;
753   char *value;
754 };
755
756 struct ConfigTypeInfo
757 {
758   char *token;
759   char *value;
760   int type;
761 };
762
763 struct TokenIntPtrInfo
764 {
765   char *token;
766   int *value;
767 };
768
769 struct FileInfo
770 {
771   char *token;
772
773   char *default_filename;
774   char *filename;
775
776   char **default_parameter;                     /* array of file parameters */
777   char **parameter;                             /* array of file parameters */
778
779   boolean redefined;
780   boolean fallback_to_default;
781 };
782
783 struct SetupFileList
784 {
785   char *token;
786   char *value;
787
788   struct SetupFileList *next;
789 };
790
791 struct ListNodeInfo
792 {
793   char *source_filename;                        /* primary key for node list */
794   int num_references;
795 };
796
797 struct PropertyMapping
798 {
799   int base_index;
800   int ext1_index;
801   int ext2_index;
802   int ext3_index;
803
804   int artwork_index;
805 };
806
807 struct ArtworkListInfo
808 {
809   int type;                                     /* type of artwork */
810
811   int num_file_list_entries;
812   int num_dynamic_file_list_entries;
813   struct FileInfo *file_list;                   /* static artwork file array */
814   struct FileInfo *dynamic_file_list;           /* dynamic artwrk file array */
815
816   int num_suffix_list_entries;
817   struct ConfigTypeInfo *suffix_list;           /* parameter suffixes array */
818
819   int num_base_prefixes;
820   int num_ext1_suffixes;
821   int num_ext2_suffixes;
822   int num_ext3_suffixes;
823   char **base_prefixes;                         /* base token prefixes array */
824   char **ext1_suffixes;                         /* property suffixes array 1 */
825   char **ext2_suffixes;                         /* property suffixes array 2 */
826   char **ext3_suffixes;                         /* property suffixes array 3 */
827
828   int num_ignore_tokens;
829   char **ignore_tokens;                         /* file tokens to be ignored */
830
831   int num_property_mapping_entries;
832   struct PropertyMapping *property_mapping;     /* mapping token -> artwork */
833
834   int sizeof_artwork_list_entry;
835
836   struct ListNodeInfo **artwork_list;           /* static artwork node array */
837   struct ListNodeInfo **dynamic_artwork_list;   /* dynamic artwrk node array */
838   struct ListNode *content_list;                /* dynamic artwork node list */
839
840   void *(*load_artwork)(char *);                /* constructor function */
841   void (*free_artwork)(void *);                 /* destructor function */
842 };
843
844
845 /* ========================================================================= */
846 /* exported variables                                                        */
847 /* ========================================================================= */
848
849 extern struct ProgramInfo       program;
850 extern struct OptionInfo        options;
851 extern struct VideoSystemInfo   video;
852 extern struct AudioSystemInfo   audio;
853 extern struct GfxInfo           gfx;
854 extern struct AnimInfo          anim;
855 extern struct ArtworkInfo       artwork;
856 extern struct JoystickInfo      joystick;
857 extern struct SetupInfo         setup;
858
859 extern LevelDirTree            *leveldir_first;
860 extern LevelDirTree            *leveldir_current;
861 extern int                      level_nr;
862
863 extern Display                 *display;
864 extern Visual                  *visual;
865 extern int                      screen;
866 extern Colormap                 cmap;
867
868 extern DrawWindow              *window;
869 extern DrawBuffer              *backbuffer;
870 extern DrawBuffer              *drawto;
871
872 extern int                      button_status;
873 extern boolean                  motion_status;
874
875 extern int                      redraw_mask;
876 extern int                      redraw_tiles;
877
878 extern int                      FrameCounter;
879
880
881 /* function definitions */
882
883 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
884                      char *, char *, char *, int);
885
886 void InitExitFunction(void (*exit_function)(int));
887 void InitPlatformDependentStuff(void);
888 void ClosePlatformDependentStuff(void);
889
890 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
891 void InitGfxDoor1Info(int, int, int, int);
892 void InitGfxDoor2Info(int, int, int, int);
893 void InitGfxScrollbufferInfo(int, int);
894 void SetDrawDeactivationMask(int);
895 void SetDrawBackgroundMask(int);
896 void SetMainBackgroundBitmap(Bitmap *);
897 void SetDoorBackgroundBitmap(Bitmap *);
898
899 inline void InitVideoDisplay(void);
900 inline void CloseVideoDisplay(void);
901 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
902 inline Bitmap *CreateBitmapStruct(void);
903 inline Bitmap *CreateBitmap(int, int, int);
904 inline void FreeBitmap(Bitmap *);
905 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
906 inline void FillRectangle(Bitmap *, int, int, int, int, Pixel);
907 inline void ClearRectangle(Bitmap *, int, int, int, int);
908 inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
909 inline void SetClipMask(Bitmap *, GC, Pixmap);
910 inline void SetClipOrigin(Bitmap *, GC, int, int);
911 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
912 inline boolean DrawingOnBackground(int, int);
913 inline void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int,
914                                    int);
915 inline void DrawSimpleBlackLine(Bitmap *, int, int, int, int);
916 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
917 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
918 inline Pixel GetPixel(Bitmap *, int, int);
919 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
920 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
921
922 inline void FlushDisplay(void);
923 inline void SyncDisplay(void);
924 inline void KeyboardAutoRepeatOn(void);
925 inline void KeyboardAutoRepeatOff(void);
926 inline boolean PointerInWindow(DrawWindow *);
927 inline boolean SetVideoMode(boolean);
928 inline boolean ChangeVideoModeIfNeeded(boolean);
929
930 Bitmap *LoadImage(char *);
931 Bitmap *LoadCustomImage(char *);
932 void ReloadCustomImage(Bitmap *, char *);
933
934 Bitmap *ZoomBitmap(Bitmap *, int, int);
935 void CreateBitmapWithSmallBitmaps(Bitmap *, int);
936
937 void SetMouseCursor(int);
938
939 inline void OpenAudio(void);
940 inline void CloseAudio(void);
941 inline void SetAudioMode(boolean);
942
943 inline void InitEventFilter(EventFilter);
944 inline boolean PendingEvent(void);
945 inline void NextEvent(Event *event);
946 inline void PeekEvent(Event *event);
947 inline Key GetEventKey(KeyEvent *, boolean);
948 inline KeyMod HandleKeyModState(Key, int);
949 inline KeyMod GetKeyModState();
950 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
951
952 inline void InitJoysticks();
953 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
954
955 #endif /* SYSTEM_H */