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