1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
20 #if defined(PLATFORM_MSDOS)
24 #if defined(TARGET_SDL)
26 #elif defined(TARGET_X11)
30 #if defined(PLATFORM_MACOSX)
31 /* some symbols are already defined on Mac OS X */
32 #define Delay Delay_internal
33 #define DrawLine DrawLine_internal
34 #define DrawText DrawText_internal
35 #define GetPixel GetPixel_internal
39 /* the additional 'b' is needed for Win32 to open files in binary mode */
40 #define MODE_READ "rb"
41 #define MODE_WRITE "wb"
42 #define MODE_APPEND "ab"
44 #define DEFAULT_DEPTH 0
46 #define FULLSCREEN_NOT_AVAILABLE FALSE
47 #define FULLSCREEN_AVAILABLE TRUE
49 /* default input keys */
50 #define DEFAULT_KEY_LEFT KSYM_Left
51 #define DEFAULT_KEY_RIGHT KSYM_Right
52 #define DEFAULT_KEY_UP KSYM_Up
53 #define DEFAULT_KEY_DOWN KSYM_Down
54 #if defined(PLATFORM_MACOSX)
55 #define DEFAULT_KEY_SNAP KSYM_Control_L
56 #define DEFAULT_KEY_BOMB KSYM_KP_Enter
58 #define DEFAULT_KEY_SNAP KSYM_Shift_L
59 #define DEFAULT_KEY_BOMB KSYM_Shift_R
61 #define DEFAULT_KEY_OKAY KSYM_Return
62 #define DEFAULT_KEY_CANCEL KSYM_Escape
64 /* default shortcut keys */
65 #define DEFAULT_KEY_SAVE_GAME KSYM_F1
66 #define DEFAULT_KEY_LOAD_GAME KSYM_F2
67 #define DEFAULT_KEY_TOGGLE_PAUSE KSYM_space
69 /* values for move directions and special "button" keys */
71 #define MV_BIT_RIGHT 1
74 #define NUM_DIRECTIONS 4
76 #define MV_NO_MOVING 0
77 #define MV_LEFT (1 << MV_BIT_LEFT)
78 #define MV_RIGHT (1 << MV_BIT_RIGHT)
79 #define MV_UP (1 << MV_BIT_UP)
80 #define MV_DOWN (1 << MV_BIT_DOWN)
81 #define KEY_BUTTON_1 (1 << 4)
82 #define KEY_BUTTON_2 (1 << 5)
83 #define KEY_MOTION (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
84 #define KEY_BUTTON (KEY_BUTTON_1 | KEY_BUTTON_2)
85 #define KEY_ACTION (KEY_MOTION | KEY_BUTTON)
87 #define MV_DIR_BIT(x) ((x) == MV_LEFT ? MV_BIT_LEFT : \
88 (x) == MV_RIGHT ? MV_BIT_RIGHT : \
89 (x) == MV_UP ? MV_BIT_UP : MV_BIT_DOWN)
91 /* values for button status */
92 #define MB_NOT_PRESSED FALSE
93 #define MB_NOT_RELEASED TRUE
94 #define MB_RELEASED FALSE
95 #define MB_PRESSED TRUE
96 #define MB_MENU_CHOICE FALSE
97 #define MB_MENU_MARK TRUE
98 #define MB_MENU_INITIALIZE (-1)
99 #define MB_MENU_LEAVE (-2)
100 #define MB_LEFTBUTTON 1
101 #define MB_MIDDLEBUTTON 2
102 #define MB_RIGHTBUTTON 3
104 /* values for redraw_mask */
105 #define REDRAW_NONE (0)
106 #define REDRAW_ALL (1 << 0)
107 #define REDRAW_FIELD (1 << 1)
108 #define REDRAW_TILES (1 << 2)
109 #define REDRAW_DOOR_1 (1 << 3)
110 #define REDRAW_VIDEO_1 (1 << 4)
111 #define REDRAW_VIDEO_2 (1 << 5)
112 #define REDRAW_VIDEO_3 (1 << 6)
113 #define REDRAW_MICROLEVEL (1 << 7)
114 #define REDRAW_MICROLABEL (1 << 8)
115 #define REDRAW_FROM_BACKBUFFER (1 << 9)
116 #define REDRAW_DOOR_2 (REDRAW_VIDEO_1 | \
119 #define REDRAW_DOOR_3 (1 << 10)
120 #define REDRAW_DOORS (REDRAW_DOOR_1 | \
123 #define REDRAW_MAIN (REDRAW_FIELD | \
126 #define REDRAW_FPS (1 << 11)
127 #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2)
129 /* maximum number of parallel players supported by libgame functions */
130 #define MAX_PLAYERS 4
132 /* maximum allowed length of player name */
133 #define MAX_PLAYER_NAME_LEN 10
135 /* default name for empty highscore entry */
136 #define EMPTY_PLAYER_NAME "no name"
138 /* default name for unknown player names */
139 #define ANONYMOUS_NAME "anonymous"
141 /* default name for new levels */
142 #define NAMELESS_LEVEL_NAME "nameless level"
144 /* default text for non-existant artwork */
145 #define NOT_AVAILABLE "(not available)"
147 /* default value for undefined filename */
148 #define UNDEFINED_FILENAME "[NONE]"
150 /* default values for undefined configuration file parameters */
151 #define ARG_UNDEFINED "-1000000"
152 #define ARG_UNDEFINED_VALUE (atoi(ARG_UNDEFINED))
154 /* definitions for game sub-directories */
156 #define RO_GAME_DIR "."
160 #define RW_GAME_DIR "."
163 #define RO_BASE_PATH RO_GAME_DIR
164 #define RW_BASE_PATH RW_GAME_DIR
166 #define GRAPHICS_DIRECTORY "graphics"
167 #define SOUNDS_DIRECTORY "sounds"
168 #define MUSIC_DIRECTORY "music"
169 #define LEVELS_DIRECTORY "levels"
170 #define TAPES_DIRECTORY "tapes"
171 #define SCORES_DIRECTORY "scores"
173 #if !defined(PLATFORM_MSDOS)
174 #define GRAPHICS_SUBDIR "gfx_classic"
175 #define SOUNDS_SUBDIR "snd_classic"
176 #define MUSIC_SUBDIR "mus_classic"
178 #define GRAPHICS_SUBDIR "gfx_orig"
179 #define SOUNDS_SUBDIR "snd_orig"
180 #define MUSIC_SUBDIR "mus_orig"
183 /* areas in bitmap PIX_DOOR */
184 /* meaning in PIX_DB_DOOR: (3 PAGEs)
185 PAGEX1: 1. buffer for DOOR_1
186 PAGEX2: 2. buffer for DOOR_1
187 PAGEX3: buffer for animations
190 #define DOOR_GFX_PAGESIZE (gfx.dxsize)
191 #define DOOR_GFX_PAGEX1 (0 * DOOR_GFX_PAGESIZE)
192 #define DOOR_GFX_PAGEX2 (1 * DOOR_GFX_PAGESIZE)
193 #define DOOR_GFX_PAGEX3 (2 * DOOR_GFX_PAGESIZE)
194 #define DOOR_GFX_PAGEX4 (3 * DOOR_GFX_PAGESIZE)
195 #define DOOR_GFX_PAGEX5 (4 * DOOR_GFX_PAGESIZE)
196 #define DOOR_GFX_PAGEX6 (5 * DOOR_GFX_PAGESIZE)
197 #define DOOR_GFX_PAGEX7 (6 * DOOR_GFX_PAGESIZE)
198 #define DOOR_GFX_PAGEX8 (7 * DOOR_GFX_PAGESIZE)
199 #define DOOR_GFX_PAGEY1 (0)
200 #define DOOR_GFX_PAGEY2 (gfx.dysize)
202 /* functions for version handling */
203 #define VERSION_IDENT(x,y,z) ((x) * 10000 + (y) * 100 + (z))
204 #define VERSION_MAJOR(x) ((x) / 10000)
205 #define VERSION_MINOR(x) (((x) % 10000) / 100)
206 #define VERSION_PATCH(x) ((x) % 100)
208 /* functions for parent/child process identification */
209 #define IS_PARENT_PROCESS() (audio.mixer_pid != getpid())
210 #define IS_CHILD_PROCESS() (audio.mixer_pid == getpid())
213 /* type definitions */
214 typedef int (*EventFilter)(const Event *);
217 /* structure definitions */
221 char *command_basename;
222 char *userdata_directory;
228 char *x11_icon_filename;
229 char *x11_iconmask_filename;
230 char *msdos_pointer_filename;
233 char *filename_prefix; /* prefix to cut off from DOS filenames */
239 void (*exit_function)(int);
248 char *ro_base_directory;
249 char *rw_base_directory;
250 char *level_directory;
251 char *graphics_directory;
252 char *sounds_directory;
253 char *music_directory;
254 char *execute_command;
262 struct VideoSystemInfo
265 int width, height, depth;
266 boolean fullscreen_available;
267 boolean fullscreen_enabled;
270 struct AudioSystemInfo
272 boolean sound_available;
273 boolean loops_available;
274 boolean music_available;
276 boolean sound_enabled;
277 boolean sound_deactivated; /* for temporarily disabling sound */
286 int first_sound_channel;
293 int real_sx, real_sy;
294 int full_sxsize, full_sysize;
295 int scrollbuffer_width, scrollbuffer_height;
303 int draw_deactivation_mask;
304 int draw_background_mask;
306 Bitmap *background_bitmap;
307 int background_bitmap_mask;
309 boolean menu_main_hide_static_text;
314 Bitmap *bitmap_initial;
316 Bitmap *bitmap_medium;
317 Bitmap *bitmap_small;
329 int fd[MAX_PLAYERS]; /* file descriptor of player's joystick */
332 struct SetupJoystickInfo
334 char *device_name; /* device name of player's joystick */
336 int xleft, xmiddle, xright;
337 int yupper, ymiddle, ylower;
342 struct SetupKeyboardInfo
352 struct SetupInputInfo
354 boolean use_joystick;
355 struct SetupJoystickInfo joy;
356 struct SetupKeyboardInfo key;
359 struct SetupEditorInfo
361 boolean el_boulderdash;
362 boolean el_emerald_mine;
366 boolean el_diamond_caves;
367 boolean el_dx_boulderdash;
372 struct SetupShortcutInfo
386 boolean sound_simple;
388 boolean double_buffering;
389 boolean direct_draw; /* !double_buffering (redundant!) */
390 boolean scroll_delay;
391 boolean soft_scrolling;
399 boolean ask_on_escape;
404 boolean override_level_graphics;
405 boolean override_level_sounds;
406 boolean override_level_music;
408 struct SetupEditorInfo editor;
409 struct SetupShortcutInfo shortcut;
410 struct SetupInputInfo input[MAX_PLAYERS];
413 #define TREE_TYPE_GENERIC 0
414 #define TREE_TYPE_GRAPHICS_DIR 1
415 #define TREE_TYPE_SOUNDS_DIR 2
416 #define TREE_TYPE_MUSIC_DIR 3
417 #define TREE_TYPE_LEVEL_DIR 4
419 #define ARTWORK_TYPE_GRAPHICS TREE_TYPE_GRAPHICS_DIR
420 #define ARTWORK_TYPE_SOUNDS TREE_TYPE_SOUNDS_DIR
421 #define ARTWORK_TYPE_MUSIC TREE_TYPE_MUSIC_DIR
425 struct TreeInfo **node_top; /* topmost node in tree */
426 struct TreeInfo *node_parent; /* parent level directory info */
427 struct TreeInfo *node_group; /* level group sub-directory info */
428 struct TreeInfo *next; /* next level series structure node */
430 int cl_first; /* internal control field for setup screen */
431 int cl_cursor; /* internal control field for setup screen */
433 int type; /* type of tree content */
435 /* fields for "type == TREE_TYPE_LEVEL_DIR" */
437 char *filename; /* tree info sub-directory basename (may be ".") */
438 char *fullpath; /* complete path relative to tree base directory */
439 char *basepath; /* absolute base path of tree base directory */
440 char *identifier; /* identifier string for configuration files */
441 char *name; /* tree info name, as displayed in selection menues */
442 char *name_sorting; /* optional sorting name for correct name sorting */
443 char *author; /* level or artwork author name */
444 char *imported_from; /* optional comment for imported levels or artwork */
446 char *graphics_set; /* optional custom graphics set (level tree only) */
447 char *sounds_set; /* optional custom sounds set (level tree only) */
448 char *music_set; /* optional custom music set (level tree only) */
449 char *graphics_path; /* path to optional custom graphics set (level only) */
450 char *sounds_path; /* path to optional custom sounds set (level only) */
451 char *music_path; /* path to optional custom music set (level only) */
453 int levels; /* number of levels in level series */
454 int first_level; /* first level number (to allow start with 0 or 1) */
455 int last_level; /* last level number (automatically calculated) */
456 int sort_priority; /* sort levels by 'sort_priority' and then by name */
458 boolean level_group; /* directory contains more level series directories */
459 boolean parent_link; /* entry links back to parent directory */
460 boolean user_defined; /* user defined levels are stored in home directory */
461 boolean readonly; /* readonly levels can not be changed with editor */
463 int color; /* color to use on selection screen for this level */
464 char *class_desc; /* description of level series class */
465 int handicap_level; /* number of the lowest unsolved level */
468 typedef struct TreeInfo TreeInfo;
469 typedef struct TreeInfo LevelDirTree;
470 typedef struct TreeInfo ArtworkDirTree;
471 typedef struct TreeInfo GraphicsDirTree;
472 typedef struct TreeInfo SoundsDirTree;
473 typedef struct TreeInfo MusicDirTree;
477 GraphicsDirTree *gfx_first;
478 GraphicsDirTree *gfx_current;
479 SoundsDirTree *snd_first;
480 SoundsDirTree *snd_current;
481 MusicDirTree *mus_first;
482 MusicDirTree *mus_current;
484 char *gfx_current_identifier;
485 char *snd_current_identifier;
486 char *mus_current_identifier;
500 char *default_filename;
503 char **default_parameter; /* array of file parameters */
504 char **parameter; /* array of file parameters */
514 struct SetupFileList *next;
519 char *source_filename; /* primary key for node list */
523 struct PropertyMapping
533 struct ArtworkListInfo
535 int type; /* type of artwork */
537 int num_file_list_entries;
538 int num_dynamic_file_list_entries;
540 struct FileInfo *file_list; /* static artwork file array */
541 struct FileInfo *dynamic_file_list; /* dynamic artwrk file array */
543 int num_suffix_list_entries;
545 struct ConfigInfo *suffix_list; /* parameter suffixes array */
547 int num_base_prefixes;
548 int num_ext1_suffixes;
549 int num_ext2_suffixes;
550 int num_ext3_suffixes;
552 char **base_prefixes; /* base token prefixes array */
553 char **ext1_suffixes; /* property suffixes array 1 */
554 char **ext2_suffixes; /* property suffixes array 2 */
555 char **ext3_suffixes; /* property suffixes array 3 */
557 int num_property_mapping_entries;
559 struct PropertyMapping *property_mapping; /* mapping token -> artwork */
561 int sizeof_artwork_list_entry;
563 struct ListNodeInfo **artwork_list; /* static artwork node array */
564 struct ListNodeInfo **dynamic_artwork_list; /* dynamic artwrk node array */
565 struct ListNode *content_list; /* dynamic artwork node list */
567 void *(*load_artwork)(char *); /* constructor function */
568 void (*free_artwork)(void *); /* destructor function */
572 /* ========================================================================= */
573 /* exported variables */
574 /* ========================================================================= */
576 extern struct ProgramInfo program;
577 extern struct OptionInfo options;
578 extern struct VideoSystemInfo video;
579 extern struct AudioSystemInfo audio;
580 extern struct GfxInfo gfx;
581 extern struct FontInfo font;
582 extern struct AnimInfo anim;
583 extern struct ArtworkInfo artwork;
584 extern struct JoystickInfo joystick;
585 extern struct SetupInfo setup;
587 extern LevelDirTree *leveldir_first;
588 extern LevelDirTree *leveldir_current;
591 extern Display *display;
592 extern Visual *visual;
594 extern Colormap cmap;
596 extern DrawWindow *window;
597 extern DrawBuffer *backbuffer;
598 extern DrawBuffer *drawto;
600 extern int button_status;
601 extern boolean motion_status;
603 extern int redraw_mask;
604 extern int redraw_tiles;
606 extern int FrameCounter;
609 /* function definitions */
611 void InitCommandName(char *);
612 void InitExitFunction(void (*exit_function)(int));
613 void InitPlatformDependantStuff(void);
614 void ClosePlatformDependantStuff(void);
616 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
617 char *, char *, int);
619 void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
620 void InitGfxDoor1Info(int, int, int, int);
621 void InitGfxDoor2Info(int, int, int, int);
622 void InitGfxScrollbufferInfo(int, int);
623 void SetDrawDeactivationMask(int);
624 void SetDrawBackgroundMask(int);
625 void SetMainBackgroundBitmap(Bitmap *);
626 void SetDoorBackgroundBitmap(Bitmap *);
628 inline void InitVideoDisplay(void);
629 inline void CloseVideoDisplay(void);
630 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
631 inline Bitmap *CreateBitmapStruct(void);
632 inline Bitmap *CreateBitmap(int, int, int);
633 inline void FreeBitmap(Bitmap *);
634 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
635 inline void ClearRectangle(Bitmap *, int, int, int, int);
636 inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
637 inline void SetClipMask(Bitmap *, GC, Pixmap);
638 inline void SetClipOrigin(Bitmap *, GC, int, int);
639 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
640 inline boolean DrawingOnBackground(int, int);
641 inline void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int,
643 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
644 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
645 inline Pixel GetPixel(Bitmap *, int, int);
646 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
647 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
649 inline void FlushDisplay(void);
650 inline void SyncDisplay(void);
651 inline void KeyboardAutoRepeatOn(void);
652 inline void KeyboardAutoRepeatOff(void);
653 inline boolean PointerInWindow(DrawWindow *);
654 inline boolean SetVideoMode(boolean);
655 inline boolean ChangeVideoModeIfNeeded(boolean);
657 Bitmap *LoadImage(char *);
658 Bitmap *LoadCustomImage(char *);
659 void ReloadCustomImage(Bitmap *, char *);
661 Bitmap *ZoomBitmap(Bitmap *, int, int);
662 void CreateBitmapWithSmallBitmaps(Bitmap *);
664 inline void OpenAudio(void);
665 inline void CloseAudio(void);
666 inline void SetAudioMode(boolean);
668 inline void InitEventFilter(EventFilter);
669 inline boolean PendingEvent(void);
670 inline void NextEvent(Event *event);
671 inline Key GetEventKey(KeyEvent *, boolean);
672 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
674 inline void InitJoysticks();
675 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
677 #endif /* SYSTEM_H */