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 ***********************************************************/
21 #if defined(PLATFORM_MACOSX)
23 #elif defined(PLATFORM_WIN32)
25 #elif defined(PLATFORM_MSDOS)
29 #if defined(TARGET_SDL)
31 #elif defined(TARGET_X11)
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"
41 #define DEFAULT_DEPTH 0
45 #define BLIT_INVERSE 2
46 #define BLIT_ON_BACKGROUND 3
48 #define FULLSCREEN_NOT_AVAILABLE FALSE
49 #define FULLSCREEN_AVAILABLE TRUE
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_BOMB KSYM_KP_Enter
60 #define DEFAULT_KEY_SNAP KSYM_Shift_L
61 #define DEFAULT_KEY_BOMB KSYM_Shift_R
63 #define DEFAULT_KEY_OKAY KSYM_Return
64 #define DEFAULT_KEY_CANCEL KSYM_Escape
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
72 /* values for basic move directions (effective at runtime) */
74 #define MV_BIT_RIGHT 1
78 #define NUM_DIRECTIONS 4
80 /* values for special "button" bitmasks (effective at runtime) */
84 /* values for special move patterns (stored in level files) */
85 #define MV_BIT_TOWARDS_PLAYER 6
86 #define MV_BIT_AWAY_FROM_PLAYER 7
87 #define MV_BIT_ALONG_LEFT_SIDE 8
88 #define MV_BIT_ALONG_RIGHT_SIDE 9
90 /* values for move direction/pattern and special "button" key bitmasks */
91 #define MV_NO_MOVING 0
92 #define MV_LEFT (1 << MV_BIT_LEFT)
93 #define MV_RIGHT (1 << MV_BIT_RIGHT)
94 #define MV_UP (1 << MV_BIT_UP)
95 #define MV_DOWN (1 << MV_BIT_DOWN)
97 #define KEY_BUTTON_1 (1 << BUTTON_1)
98 #define KEY_BUTTON_2 (1 << BUTTON_2)
99 #define KEY_MOTION (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
100 #define KEY_BUTTON (KEY_BUTTON_1 | KEY_BUTTON_2)
101 #define KEY_ACTION (KEY_MOTION | KEY_BUTTON)
103 #define MV_DIR_BIT(x) ((x) == MV_LEFT ? MV_BIT_LEFT : \
104 (x) == MV_RIGHT ? MV_BIT_RIGHT : \
105 (x) == MV_UP ? MV_BIT_UP : MV_BIT_DOWN)
107 #define MV_HORIZONTAL (MV_LEFT | MV_RIGHT)
108 #define MV_VERTICAL (MV_UP | MV_DOWN)
109 #define MV_ALL_DIRECTIONS (MV_HORIZONTAL | MV_VERTICAL)
110 #define MV_ANY_DIRECTION (MV_ALL_DIRECTIONS)
111 #define MV_TOWARDS_PLAYER (1 << MV_BIT_TOWARDS_PLAYER)
112 #define MV_AWAY_FROM_PLAYER (1 << MV_BIT_AWAY_FROM_PLAYER)
113 #define MV_ALONG_LEFT_SIDE (1 << MV_BIT_ALONG_LEFT_SIDE)
114 #define MV_ALONG_RIGHT_SIDE (1 << MV_BIT_ALONG_RIGHT_SIDE)
116 /* values for button status */
117 #define MB_NOT_PRESSED FALSE
118 #define MB_NOT_RELEASED TRUE
119 #define MB_RELEASED FALSE
120 #define MB_PRESSED TRUE
121 #define MB_MENU_CHOICE FALSE
122 #define MB_MENU_MARK TRUE
123 #define MB_MENU_INITIALIZE (-1)
124 #define MB_MENU_LEAVE (-2)
125 #define MB_LEFTBUTTON 1
126 #define MB_MIDDLEBUTTON 2
127 #define MB_RIGHTBUTTON 3
130 /* values for animation mode (frame order and direction) */
132 #define ANIM_LOOP (1 << 0)
133 #define ANIM_LINEAR (1 << 1)
134 #define ANIM_PINGPONG (1 << 2)
135 #define ANIM_PINGPONG2 (1 << 3)
136 #define ANIM_RANDOM (1 << 4)
137 #define ANIM_REVERSE (1 << 5)
140 /* values for redraw_mask */
141 #define REDRAW_NONE (0)
142 #define REDRAW_ALL (1 << 0)
143 #define REDRAW_FIELD (1 << 1)
144 #define REDRAW_TILES (1 << 2)
145 #define REDRAW_DOOR_1 (1 << 3)
146 #define REDRAW_VIDEO_1 (1 << 4)
147 #define REDRAW_VIDEO_2 (1 << 5)
148 #define REDRAW_VIDEO_3 (1 << 6)
149 #define REDRAW_MICROLEVEL (1 << 7)
150 #define REDRAW_MICROLABEL (1 << 8)
151 #define REDRAW_FROM_BACKBUFFER (1 << 9)
152 #define REDRAW_DOOR_2 (REDRAW_VIDEO_1 | \
155 #define REDRAW_DOOR_3 (1 << 10)
156 #define REDRAW_DOORS (REDRAW_DOOR_1 | \
159 #define REDRAW_MAIN (REDRAW_FIELD | \
162 #define REDRAW_FPS (1 << 11)
163 #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2)
166 /* values for mouse cursor */
167 #define CURSOR_DEFAULT 0
168 #define CURSOR_PLAYFIELD 1
171 /* maximum number of parallel players supported by libgame functions */
172 #define MAX_PLAYERS 4
174 /* maximum allowed length of player name */
175 #define MAX_PLAYER_NAME_LEN 10
177 /* default name for empty highscore entry */
178 #define EMPTY_PLAYER_NAME "no name"
180 /* default name for unknown player names */
181 #define ANONYMOUS_NAME "anonymous"
183 /* default name for new levels */
184 #define NAMELESS_LEVEL_NAME "nameless level"
186 /* default text for non-existant artwork */
187 #define NOT_AVAILABLE "(not available)"
189 /* default value for undefined filename */
190 #define UNDEFINED_FILENAME "[NONE]"
192 /* default value for undefined parameter */
193 #define ARG_DEFAULT "[DEFAULT]"
195 /* default values for undefined configuration file parameters */
196 #define ARG_UNDEFINED "-1000000"
197 #define ARG_UNDEFINED_VALUE (atoi(ARG_UNDEFINED))
199 /* definitions for game sub-directories */
201 #define RO_GAME_DIR "."
205 #define RW_GAME_DIR "."
208 #define RO_BASE_PATH RO_GAME_DIR
209 #define RW_BASE_PATH RW_GAME_DIR
211 #define GRAPHICS_DIRECTORY "graphics"
212 #define SOUNDS_DIRECTORY "sounds"
213 #define MUSIC_DIRECTORY "music"
214 #define LEVELS_DIRECTORY "levels"
215 #define TAPES_DIRECTORY "tapes"
216 #define SCORES_DIRECTORY "scores"
217 #define DOCS_DIRECTORY "docs"
219 #if !defined(PLATFORM_MSDOS)
220 #define GRAPHICS_SUBDIR "gfx_classic"
221 #define SOUNDS_SUBDIR "snd_classic"
222 #define MUSIC_SUBDIR "mus_classic"
224 #define GRAPHICS_SUBDIR "gfx_orig"
225 #define SOUNDS_SUBDIR "snd_orig"
226 #define MUSIC_SUBDIR "mus_orig"
229 /* areas in bitmap PIX_DOOR */
230 /* meaning in PIX_DB_DOOR: (3 PAGEs)
231 PAGEX1: 1. buffer for DOOR_1
232 PAGEX2: 2. buffer for DOOR_1
233 PAGEX3: buffer for animations
236 #define DOOR_GFX_PAGESIZE (gfx.dxsize)
237 #define DOOR_GFX_PAGEX1 (0 * DOOR_GFX_PAGESIZE)
238 #define DOOR_GFX_PAGEX2 (1 * DOOR_GFX_PAGESIZE)
239 #define DOOR_GFX_PAGEX3 (2 * DOOR_GFX_PAGESIZE)
240 #define DOOR_GFX_PAGEX4 (3 * DOOR_GFX_PAGESIZE)
241 #define DOOR_GFX_PAGEX5 (4 * DOOR_GFX_PAGESIZE)
242 #define DOOR_GFX_PAGEX6 (5 * DOOR_GFX_PAGESIZE)
243 #define DOOR_GFX_PAGEX7 (6 * DOOR_GFX_PAGESIZE)
244 #define DOOR_GFX_PAGEX8 (7 * DOOR_GFX_PAGESIZE)
245 #define DOOR_GFX_PAGEY1 (0)
246 #define DOOR_GFX_PAGEY2 (gfx.dysize)
248 /* functions for version handling */
249 #define VERSION_IDENT(x,y,z) ((x) * 1000000 + (y) * 10000 + (z) * 100)
250 #define RELEASE_IDENT(x,y,z,r) (VERSION_IDENT(x,y,z) + (r))
251 #define VERSION_MAJOR(x) ((x) / 1000000)
252 #define VERSION_MINOR(x) (((x) % 1000000) / 10000)
253 #define VERSION_PATCH(x) (((x) % 10000) / 100)
254 #define VERSION_RELEASE(x) ((x) % 100)
256 /* functions for parent/child process identification */
257 #if defined(PLATFORM_UNIX)
258 #define IS_PARENT_PROCESS() (audio.mixer_pid != getpid())
259 #define IS_CHILD_PROCESS() (audio.mixer_pid == getpid())
260 #define HAS_CHILD_PROCESS() (audio.mixer_pid > 0)
262 #define IS_PARENT_PROCESS() TRUE
263 #define IS_CHILD_PROCESS() FALSE
264 #define HAS_CHILD_PROCESS() FALSE
267 /* type definitions */
268 typedef int (*EventFilter)(const Event *);
271 /* structure definitions */
275 char *command_basename;
276 char *userdata_directory;
282 char *x11_icon_filename;
283 char *x11_iconmask_filename;
284 char *msdos_cursor_filename;
287 char *filename_prefix; /* prefix to cut off from DOS filenames */
293 void (*exit_function)(int);
302 char *ro_base_directory;
303 char *rw_base_directory;
304 char *level_directory;
305 char *graphics_directory;
306 char *sounds_directory;
307 char *music_directory;
308 char *docs_directory;
309 char *execute_command;
317 struct VideoSystemInfo
320 int width, height, depth;
321 boolean fullscreen_available;
322 boolean fullscreen_enabled;
325 struct AudioSystemInfo
327 boolean sound_available;
328 boolean loops_available;
329 boolean music_available;
331 boolean sound_enabled;
332 boolean sound_deactivated; /* for temporarily disabling sound */
341 int first_sound_channel;
344 struct FontBitmapInfo
347 int src_x, src_y; /* start position of animation frames */
348 int width, height; /* width/height of each animation frame */
349 int draw_x, draw_y; /* offset for drawing font characters */
351 int num_chars_per_line;
353 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
354 Pixmap *clip_mask; /* single-char-only clip mask array for X11 */
362 int real_sx, real_sy;
363 int full_sxsize, full_sysize;
364 int scrollbuffer_width, scrollbuffer_height;
372 int draw_deactivation_mask;
373 int draw_background_mask;
375 Bitmap *field_save_buffer;
377 Bitmap *background_bitmap;
378 int background_bitmap_mask;
381 struct FontBitmapInfo *font_bitmap_info;
382 int (*select_font_function)(int);
384 int anim_random_frame;
390 int fd[MAX_PLAYERS]; /* file descriptor of player's joystick */
393 struct SetupJoystickInfo
395 char *device_name; /* device name of player's joystick */
397 int xleft, xmiddle, xright;
398 int yupper, ymiddle, ylower;
403 struct SetupKeyboardInfo
413 struct SetupInputInfo
415 boolean use_joystick;
416 struct SetupJoystickInfo joy;
417 struct SetupKeyboardInfo key;
420 struct SetupEditorInfo
422 boolean el_boulderdash;
423 boolean el_emerald_mine;
427 boolean el_diamond_caves;
428 boolean el_dx_boulderdash;
433 struct SetupShortcutInfo
440 struct SetupSystemInfo
442 char *sdl_audiodriver;
443 int audio_fragment_size;
453 boolean sound_simple;
455 boolean double_buffering;
456 boolean direct_draw; /* !double_buffering (redundant!) */
457 boolean scroll_delay;
458 boolean soft_scrolling;
466 boolean ask_on_escape;
471 boolean override_level_graphics;
472 boolean override_level_sounds;
473 boolean override_level_music;
475 struct SetupEditorInfo editor;
476 struct SetupShortcutInfo shortcut;
477 struct SetupInputInfo input[MAX_PLAYERS];
478 struct SetupSystemInfo system;
479 struct OptionInfo options;
482 #define TREE_TYPE_GENERIC 0
483 #define TREE_TYPE_GRAPHICS_DIR 1
484 #define TREE_TYPE_SOUNDS_DIR 2
485 #define TREE_TYPE_MUSIC_DIR 3
486 #define TREE_TYPE_LEVEL_DIR 4
488 #define ARTWORK_TYPE_GRAPHICS TREE_TYPE_GRAPHICS_DIR
489 #define ARTWORK_TYPE_SOUNDS TREE_TYPE_SOUNDS_DIR
490 #define ARTWORK_TYPE_MUSIC TREE_TYPE_MUSIC_DIR
494 struct TreeInfo **node_top; /* topmost node in tree */
495 struct TreeInfo *node_parent; /* parent level directory info */
496 struct TreeInfo *node_group; /* level group sub-directory info */
497 struct TreeInfo *next; /* next level series structure node */
499 int cl_first; /* internal control field for setup screen */
500 int cl_cursor; /* internal control field for setup screen */
502 int type; /* type of tree content */
504 /* fields for "type == TREE_TYPE_LEVEL_DIR" */
506 char *filename; /* tree info sub-directory basename (may be ".") */
507 char *fullpath; /* complete path relative to tree base directory */
508 char *basepath; /* absolute base path of tree base directory */
509 char *identifier; /* identifier string for configuration files */
510 char *name; /* tree info name, as displayed in selection menues */
511 char *name_sorting; /* optional sorting name for correct name sorting */
512 char *author; /* level or artwork author name */
513 char *imported_from; /* optional comment for imported levels or artwork */
515 char *graphics_set; /* optional custom graphics set (level tree only) */
516 char *sounds_set; /* optional custom sounds set (level tree only) */
517 char *music_set; /* optional custom music set (level tree only) */
518 char *graphics_path; /* path to optional custom graphics set (level only) */
519 char *sounds_path; /* path to optional custom sounds set (level only) */
520 char *music_path; /* path to optional custom music set (level only) */
522 int levels; /* number of levels in level series */
523 int first_level; /* first level number (to allow start with 0 or 1) */
524 int last_level; /* last level number (automatically calculated) */
525 int sort_priority; /* sort levels by 'sort_priority' and then by name */
527 boolean level_group; /* directory contains more level series directories */
528 boolean parent_link; /* entry links back to parent directory */
529 boolean user_defined; /* user defined levels are stored in home directory */
530 boolean readonly; /* readonly levels can not be changed with editor */
532 int color; /* color to use on selection screen for this level */
533 char *class_desc; /* description of level series class */
534 int handicap_level; /* number of the lowest unsolved level */
537 typedef struct TreeInfo TreeInfo;
538 typedef struct TreeInfo LevelDirTree;
539 typedef struct TreeInfo ArtworkDirTree;
540 typedef struct TreeInfo GraphicsDirTree;
541 typedef struct TreeInfo SoundsDirTree;
542 typedef struct TreeInfo MusicDirTree;
546 GraphicsDirTree *gfx_first;
547 GraphicsDirTree *gfx_current;
548 SoundsDirTree *snd_first;
549 SoundsDirTree *snd_current;
550 MusicDirTree *mus_first;
551 MusicDirTree *mus_current;
553 char *gfx_current_identifier;
554 char *snd_current_identifier;
555 char *mus_current_identifier;
571 struct TokenIntPtrInfo
581 char *default_filename;
584 char **default_parameter; /* array of file parameters */
585 char **parameter; /* array of file parameters */
595 struct SetupFileList *next;
600 char *source_filename; /* primary key for node list */
604 struct PropertyMapping
614 struct ArtworkListInfo
616 int type; /* type of artwork */
618 int num_file_list_entries;
619 int num_dynamic_file_list_entries;
620 struct FileInfo *file_list; /* static artwork file array */
621 struct FileInfo *dynamic_file_list; /* dynamic artwrk file array */
623 int num_suffix_list_entries;
624 struct ConfigInfo *suffix_list; /* parameter suffixes array */
626 int num_base_prefixes;
627 int num_ext1_suffixes;
628 int num_ext2_suffixes;
629 int num_ext3_suffixes;
630 char **base_prefixes; /* base token prefixes array */
631 char **ext1_suffixes; /* property suffixes array 1 */
632 char **ext2_suffixes; /* property suffixes array 2 */
633 char **ext3_suffixes; /* property suffixes array 3 */
635 int num_ignore_tokens;
636 char **ignore_tokens; /* file tokens to be ignored */
638 int num_property_mapping_entries;
639 struct PropertyMapping *property_mapping; /* mapping token -> artwork */
641 int sizeof_artwork_list_entry;
643 struct ListNodeInfo **artwork_list; /* static artwork node array */
644 struct ListNodeInfo **dynamic_artwork_list; /* dynamic artwrk node array */
645 struct ListNode *content_list; /* dynamic artwork node list */
647 void *(*load_artwork)(char *); /* constructor function */
648 void (*free_artwork)(void *); /* destructor function */
652 /* ========================================================================= */
653 /* exported variables */
654 /* ========================================================================= */
656 extern struct ProgramInfo program;
657 extern struct OptionInfo options;
658 extern struct VideoSystemInfo video;
659 extern struct AudioSystemInfo audio;
660 extern struct GfxInfo gfx;
661 extern struct AnimInfo anim;
662 extern struct ArtworkInfo artwork;
663 extern struct JoystickInfo joystick;
664 extern struct SetupInfo setup;
666 extern LevelDirTree *leveldir_first;
667 extern LevelDirTree *leveldir_current;
670 extern Display *display;
671 extern Visual *visual;
673 extern Colormap cmap;
675 extern DrawWindow *window;
676 extern DrawBuffer *backbuffer;
677 extern DrawBuffer *drawto;
679 extern int button_status;
680 extern boolean motion_status;
682 extern int redraw_mask;
683 extern int redraw_tiles;
685 extern int FrameCounter;
688 /* function definitions */
690 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
691 char *, char *, char *, int);
693 void InitExitFunction(void (*exit_function)(int));
694 void InitPlatformDependantStuff(void);
695 void ClosePlatformDependantStuff(void);
697 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
698 void InitGfxDoor1Info(int, int, int, int);
699 void InitGfxDoor2Info(int, int, int, int);
700 void InitGfxScrollbufferInfo(int, int);
701 void SetDrawDeactivationMask(int);
702 void SetDrawBackgroundMask(int);
703 void SetMainBackgroundBitmap(Bitmap *);
704 void SetDoorBackgroundBitmap(Bitmap *);
706 inline void InitVideoDisplay(void);
707 inline void CloseVideoDisplay(void);
708 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
709 inline Bitmap *CreateBitmapStruct(void);
710 inline Bitmap *CreateBitmap(int, int, int);
711 inline void FreeBitmap(Bitmap *);
712 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
713 inline void FillRectangle(Bitmap *, int, int, int, int, Pixel);
714 inline void ClearRectangle(Bitmap *, int, int, int, int);
715 inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
716 inline void SetClipMask(Bitmap *, GC, Pixmap);
717 inline void SetClipOrigin(Bitmap *, GC, int, int);
718 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
719 inline boolean DrawingOnBackground(int, int);
720 inline void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int,
722 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
723 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
724 inline Pixel GetPixel(Bitmap *, int, int);
725 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
726 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
728 inline void FlushDisplay(void);
729 inline void SyncDisplay(void);
730 inline void KeyboardAutoRepeatOn(void);
731 inline void KeyboardAutoRepeatOff(void);
732 inline boolean PointerInWindow(DrawWindow *);
733 inline boolean SetVideoMode(boolean);
734 inline boolean ChangeVideoModeIfNeeded(boolean);
736 Bitmap *LoadImage(char *);
737 Bitmap *LoadCustomImage(char *);
738 void ReloadCustomImage(Bitmap *, char *);
740 Bitmap *ZoomBitmap(Bitmap *, int, int);
741 void CreateBitmapWithSmallBitmaps(Bitmap *);
743 void SetMouseCursor(int);
745 inline void OpenAudio(void);
746 inline void CloseAudio(void);
747 inline void SetAudioMode(boolean);
749 inline void InitEventFilter(EventFilter);
750 inline boolean PendingEvent(void);
751 inline void NextEvent(Event *event);
752 inline Key GetEventKey(KeyEvent *, boolean);
753 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
755 inline void InitJoysticks();
756 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
758 #endif /* SYSTEM_H */