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
89 #define MV_BIT_TURNING_LEFT 10
90 #define MV_BIT_TURNING_RIGHT 11
92 /* values for move direction/pattern and special "button" key bitmasks */
93 #define MV_NO_MOVING 0
94 #define MV_LEFT (1 << MV_BIT_LEFT)
95 #define MV_RIGHT (1 << MV_BIT_RIGHT)
96 #define MV_UP (1 << MV_BIT_UP)
97 #define MV_DOWN (1 << MV_BIT_DOWN)
99 #define KEY_BUTTON_1 (1 << BUTTON_1)
100 #define KEY_BUTTON_2 (1 << BUTTON_2)
101 #define KEY_MOTION (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
102 #define KEY_BUTTON (KEY_BUTTON_1 | KEY_BUTTON_2)
103 #define KEY_ACTION (KEY_MOTION | KEY_BUTTON)
105 #define MV_DIR_BIT(x) ((x) == MV_LEFT ? MV_BIT_LEFT : \
106 (x) == MV_RIGHT ? MV_BIT_RIGHT : \
107 (x) == MV_UP ? MV_BIT_UP : MV_BIT_DOWN)
109 #define MV_HORIZONTAL (MV_LEFT | MV_RIGHT)
110 #define MV_VERTICAL (MV_UP | MV_DOWN)
111 #define MV_ALL_DIRECTIONS (MV_HORIZONTAL | MV_VERTICAL)
112 #define MV_ANY_DIRECTION (MV_ALL_DIRECTIONS)
113 #define MV_TOWARDS_PLAYER (1 << MV_BIT_TOWARDS_PLAYER)
114 #define MV_AWAY_FROM_PLAYER (1 << MV_BIT_AWAY_FROM_PLAYER)
115 #define MV_ALONG_LEFT_SIDE (1 << MV_BIT_ALONG_LEFT_SIDE)
116 #define MV_ALONG_RIGHT_SIDE (1 << MV_BIT_ALONG_RIGHT_SIDE)
117 #define MV_TURNING_LEFT (1 << MV_BIT_TURNING_LEFT)
118 #define MV_TURNING_RIGHT (1 << MV_BIT_TURNING_RIGHT)
120 /* values for button status */
121 #define MB_NOT_PRESSED FALSE
122 #define MB_NOT_RELEASED TRUE
123 #define MB_RELEASED FALSE
124 #define MB_PRESSED TRUE
125 #define MB_MENU_CHOICE FALSE
126 #define MB_MENU_MARK TRUE
127 #define MB_MENU_INITIALIZE (-1)
128 #define MB_MENU_LEAVE (-2)
129 #define MB_LEFTBUTTON 1
130 #define MB_MIDDLEBUTTON 2
131 #define MB_RIGHTBUTTON 3
134 /* values for animation mode (frame order and direction) */
136 #define ANIM_LOOP (1 << 0)
137 #define ANIM_LINEAR (1 << 1)
138 #define ANIM_PINGPONG (1 << 2)
139 #define ANIM_PINGPONG2 (1 << 3)
140 #define ANIM_RANDOM (1 << 4)
141 #define ANIM_REVERSE (1 << 5)
144 /* values for redraw_mask */
145 #define REDRAW_NONE (0)
146 #define REDRAW_ALL (1 << 0)
147 #define REDRAW_FIELD (1 << 1)
148 #define REDRAW_TILES (1 << 2)
149 #define REDRAW_DOOR_1 (1 << 3)
150 #define REDRAW_VIDEO_1 (1 << 4)
151 #define REDRAW_VIDEO_2 (1 << 5)
152 #define REDRAW_VIDEO_3 (1 << 6)
153 #define REDRAW_MICROLEVEL (1 << 7)
154 #define REDRAW_MICROLABEL (1 << 8)
155 #define REDRAW_FROM_BACKBUFFER (1 << 9)
156 #define REDRAW_DOOR_2 (REDRAW_VIDEO_1 | \
159 #define REDRAW_DOOR_3 (1 << 10)
160 #define REDRAW_DOORS (REDRAW_DOOR_1 | \
163 #define REDRAW_MAIN (REDRAW_FIELD | \
166 #define REDRAW_FPS (1 << 11)
167 #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2)
170 /* values for mouse cursor */
171 #define CURSOR_DEFAULT 0
172 #define CURSOR_PLAYFIELD 1
175 /* maximum number of parallel players supported by libgame functions */
176 #define MAX_PLAYERS 4
178 /* maximum allowed length of player name */
179 #define MAX_PLAYER_NAME_LEN 10
181 /* default name for empty highscore entry */
182 #define EMPTY_PLAYER_NAME "no name"
184 /* default name for unknown player names */
185 #define ANONYMOUS_NAME "anonymous"
187 /* default name for new levels */
188 #define NAMELESS_LEVEL_NAME "nameless level"
190 /* default text for non-existant artwork */
191 #define NOT_AVAILABLE "(not available)"
193 /* default value for undefined filename */
194 #define UNDEFINED_FILENAME "[NONE]"
196 /* default value for undefined parameter */
197 #define ARG_DEFAULT "[DEFAULT]"
199 /* default values for undefined configuration file parameters */
200 #define ARG_UNDEFINED "-1000000"
201 #define ARG_UNDEFINED_VALUE (atoi(ARG_UNDEFINED))
203 /* definitions for game sub-directories */
205 #define RO_GAME_DIR "."
209 #define RW_GAME_DIR "."
212 #define RO_BASE_PATH RO_GAME_DIR
213 #define RW_BASE_PATH RW_GAME_DIR
215 #define GRAPHICS_DIRECTORY "graphics"
216 #define SOUNDS_DIRECTORY "sounds"
217 #define MUSIC_DIRECTORY "music"
218 #define LEVELS_DIRECTORY "levels"
219 #define TAPES_DIRECTORY "tapes"
220 #define SCORES_DIRECTORY "scores"
221 #define DOCS_DIRECTORY "docs"
223 #if !defined(PLATFORM_MSDOS)
224 #define GRAPHICS_SUBDIR "gfx_classic"
225 #define SOUNDS_SUBDIR "snd_classic"
226 #define MUSIC_SUBDIR "mus_classic"
228 #define GRAPHICS_SUBDIR "gfx_orig"
229 #define SOUNDS_SUBDIR "snd_orig"
230 #define MUSIC_SUBDIR "mus_orig"
233 /* areas in bitmap PIX_DOOR */
234 /* meaning in PIX_DB_DOOR: (3 PAGEs)
235 PAGEX1: 1. buffer for DOOR_1
236 PAGEX2: 2. buffer for DOOR_1
237 PAGEX3: buffer for animations
240 #define DOOR_GFX_PAGESIZE (gfx.dxsize)
241 #define DOOR_GFX_PAGEX1 (0 * DOOR_GFX_PAGESIZE)
242 #define DOOR_GFX_PAGEX2 (1 * DOOR_GFX_PAGESIZE)
243 #define DOOR_GFX_PAGEX3 (2 * DOOR_GFX_PAGESIZE)
244 #define DOOR_GFX_PAGEX4 (3 * DOOR_GFX_PAGESIZE)
245 #define DOOR_GFX_PAGEX5 (4 * DOOR_GFX_PAGESIZE)
246 #define DOOR_GFX_PAGEX6 (5 * DOOR_GFX_PAGESIZE)
247 #define DOOR_GFX_PAGEX7 (6 * DOOR_GFX_PAGESIZE)
248 #define DOOR_GFX_PAGEX8 (7 * DOOR_GFX_PAGESIZE)
249 #define DOOR_GFX_PAGEY1 (0)
250 #define DOOR_GFX_PAGEY2 (gfx.dysize)
252 /* functions for version handling */
253 #define VERSION_IDENT(x,y,z) ((x) * 1000000 + (y) * 10000 + (z) * 100)
254 #define RELEASE_IDENT(x,y,z,r) (VERSION_IDENT(x,y,z) + (r))
255 #define VERSION_MAJOR(x) ((x) / 1000000)
256 #define VERSION_MINOR(x) (((x) % 1000000) / 10000)
257 #define VERSION_PATCH(x) (((x) % 10000) / 100)
258 #define VERSION_RELEASE(x) ((x) % 100)
260 /* functions for parent/child process identification */
261 #if defined(PLATFORM_UNIX)
262 #define IS_PARENT_PROCESS() (audio.mixer_pid != getpid())
263 #define IS_CHILD_PROCESS() (audio.mixer_pid == getpid())
264 #define HAS_CHILD_PROCESS() (audio.mixer_pid > 0)
266 #define IS_PARENT_PROCESS() TRUE
267 #define IS_CHILD_PROCESS() FALSE
268 #define HAS_CHILD_PROCESS() FALSE
271 /* type definitions */
272 typedef int (*EventFilter)(const Event *);
275 /* structure definitions */
279 char *command_basename;
280 char *userdata_directory;
286 char *x11_icon_filename;
287 char *x11_iconmask_filename;
288 char *msdos_cursor_filename;
291 char *filename_prefix; /* prefix to cut off from DOS filenames */
297 void (*exit_function)(int);
306 char *ro_base_directory;
307 char *rw_base_directory;
308 char *level_directory;
309 char *graphics_directory;
310 char *sounds_directory;
311 char *music_directory;
312 char *docs_directory;
313 char *execute_command;
321 struct VideoSystemInfo
324 int width, height, depth;
325 boolean fullscreen_available;
326 boolean fullscreen_enabled;
329 struct AudioSystemInfo
331 boolean sound_available;
332 boolean loops_available;
333 boolean music_available;
335 boolean sound_enabled;
336 boolean sound_deactivated; /* for temporarily disabling sound */
345 int first_sound_channel;
348 struct FontBitmapInfo
351 int src_x, src_y; /* start position of animation frames */
352 int width, height; /* width/height of each animation frame */
353 int draw_x, draw_y; /* offset for drawing font characters */
355 int num_chars_per_line;
357 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
358 Pixmap *clip_mask; /* single-char-only clip mask array for X11 */
366 int real_sx, real_sy;
367 int full_sxsize, full_sysize;
368 int scrollbuffer_width, scrollbuffer_height;
376 int draw_deactivation_mask;
377 int draw_background_mask;
379 Bitmap *field_save_buffer;
381 Bitmap *background_bitmap;
382 int background_bitmap_mask;
385 struct FontBitmapInfo *font_bitmap_info;
386 int (*select_font_function)(int);
388 int anim_random_frame;
394 int fd[MAX_PLAYERS]; /* file descriptor of player's joystick */
397 struct SetupJoystickInfo
399 char *device_name; /* device name of player's joystick */
401 int xleft, xmiddle, xright;
402 int yupper, ymiddle, ylower;
407 struct SetupKeyboardInfo
417 struct SetupInputInfo
419 boolean use_joystick;
420 struct SetupJoystickInfo joy;
421 struct SetupKeyboardInfo key;
424 struct SetupEditorInfo
426 boolean el_boulderdash;
427 boolean el_emerald_mine;
431 boolean el_diamond_caves;
432 boolean el_dx_boulderdash;
437 struct SetupShortcutInfo
444 struct SetupSystemInfo
446 char *sdl_audiodriver;
447 int audio_fragment_size;
457 boolean sound_simple;
459 boolean double_buffering;
460 boolean direct_draw; /* !double_buffering (redundant!) */
461 boolean scroll_delay;
462 boolean soft_scrolling;
470 boolean ask_on_escape;
475 boolean override_level_graphics;
476 boolean override_level_sounds;
477 boolean override_level_music;
479 struct SetupEditorInfo editor;
480 struct SetupShortcutInfo shortcut;
481 struct SetupInputInfo input[MAX_PLAYERS];
482 struct SetupSystemInfo system;
483 struct OptionInfo options;
486 #define TREE_TYPE_GENERIC 0
487 #define TREE_TYPE_GRAPHICS_DIR 1
488 #define TREE_TYPE_SOUNDS_DIR 2
489 #define TREE_TYPE_MUSIC_DIR 3
490 #define TREE_TYPE_LEVEL_DIR 4
492 #define ARTWORK_TYPE_GRAPHICS TREE_TYPE_GRAPHICS_DIR
493 #define ARTWORK_TYPE_SOUNDS TREE_TYPE_SOUNDS_DIR
494 #define ARTWORK_TYPE_MUSIC TREE_TYPE_MUSIC_DIR
498 struct TreeInfo **node_top; /* topmost node in tree */
499 struct TreeInfo *node_parent; /* parent level directory info */
500 struct TreeInfo *node_group; /* level group sub-directory info */
501 struct TreeInfo *next; /* next level series structure node */
503 int cl_first; /* internal control field for setup screen */
504 int cl_cursor; /* internal control field for setup screen */
506 int type; /* type of tree content */
508 /* fields for "type == TREE_TYPE_LEVEL_DIR" */
510 char *filename; /* tree info sub-directory basename (may be ".") */
511 char *fullpath; /* complete path relative to tree base directory */
512 char *basepath; /* absolute base path of tree base directory */
513 char *identifier; /* identifier string for configuration files */
514 char *name; /* tree info name, as displayed in selection menues */
515 char *name_sorting; /* optional sorting name for correct name sorting */
516 char *author; /* level or artwork author name */
517 char *imported_from; /* optional comment for imported levels or artwork */
519 char *graphics_set; /* optional custom graphics set (level tree only) */
520 char *sounds_set; /* optional custom sounds set (level tree only) */
521 char *music_set; /* optional custom music set (level tree only) */
522 char *graphics_path; /* path to optional custom graphics set (level only) */
523 char *sounds_path; /* path to optional custom sounds set (level only) */
524 char *music_path; /* path to optional custom music set (level only) */
526 int levels; /* number of levels in level series */
527 int first_level; /* first level number (to allow start with 0 or 1) */
528 int last_level; /* last level number (automatically calculated) */
529 int sort_priority; /* sort levels by 'sort_priority' and then by name */
531 boolean level_group; /* directory contains more level series directories */
532 boolean parent_link; /* entry links back to parent directory */
533 boolean user_defined; /* user defined levels are stored in home directory */
534 boolean readonly; /* readonly levels can not be changed with editor */
536 int color; /* color to use on selection screen for this level */
537 char *class_desc; /* description of level series class */
538 int handicap_level; /* number of the lowest unsolved level */
541 typedef struct TreeInfo TreeInfo;
542 typedef struct TreeInfo LevelDirTree;
543 typedef struct TreeInfo ArtworkDirTree;
544 typedef struct TreeInfo GraphicsDirTree;
545 typedef struct TreeInfo SoundsDirTree;
546 typedef struct TreeInfo MusicDirTree;
550 GraphicsDirTree *gfx_first;
551 GraphicsDirTree *gfx_current;
552 SoundsDirTree *snd_first;
553 SoundsDirTree *snd_current;
554 MusicDirTree *mus_first;
555 MusicDirTree *mus_current;
557 char *gfx_current_identifier;
558 char *snd_current_identifier;
559 char *mus_current_identifier;
575 struct TokenIntPtrInfo
585 char *default_filename;
588 char **default_parameter; /* array of file parameters */
589 char **parameter; /* array of file parameters */
599 struct SetupFileList *next;
604 char *source_filename; /* primary key for node list */
608 struct PropertyMapping
618 struct ArtworkListInfo
620 int type; /* type of artwork */
622 int num_file_list_entries;
623 int num_dynamic_file_list_entries;
624 struct FileInfo *file_list; /* static artwork file array */
625 struct FileInfo *dynamic_file_list; /* dynamic artwrk file array */
627 int num_suffix_list_entries;
628 struct ConfigInfo *suffix_list; /* parameter suffixes array */
630 int num_base_prefixes;
631 int num_ext1_suffixes;
632 int num_ext2_suffixes;
633 int num_ext3_suffixes;
634 char **base_prefixes; /* base token prefixes array */
635 char **ext1_suffixes; /* property suffixes array 1 */
636 char **ext2_suffixes; /* property suffixes array 2 */
637 char **ext3_suffixes; /* property suffixes array 3 */
639 int num_ignore_tokens;
640 char **ignore_tokens; /* file tokens to be ignored */
642 int num_property_mapping_entries;
643 struct PropertyMapping *property_mapping; /* mapping token -> artwork */
645 int sizeof_artwork_list_entry;
647 struct ListNodeInfo **artwork_list; /* static artwork node array */
648 struct ListNodeInfo **dynamic_artwork_list; /* dynamic artwrk node array */
649 struct ListNode *content_list; /* dynamic artwork node list */
651 void *(*load_artwork)(char *); /* constructor function */
652 void (*free_artwork)(void *); /* destructor function */
656 /* ========================================================================= */
657 /* exported variables */
658 /* ========================================================================= */
660 extern struct ProgramInfo program;
661 extern struct OptionInfo options;
662 extern struct VideoSystemInfo video;
663 extern struct AudioSystemInfo audio;
664 extern struct GfxInfo gfx;
665 extern struct AnimInfo anim;
666 extern struct ArtworkInfo artwork;
667 extern struct JoystickInfo joystick;
668 extern struct SetupInfo setup;
670 extern LevelDirTree *leveldir_first;
671 extern LevelDirTree *leveldir_current;
674 extern Display *display;
675 extern Visual *visual;
677 extern Colormap cmap;
679 extern DrawWindow *window;
680 extern DrawBuffer *backbuffer;
681 extern DrawBuffer *drawto;
683 extern int button_status;
684 extern boolean motion_status;
686 extern int redraw_mask;
687 extern int redraw_tiles;
689 extern int FrameCounter;
692 /* function definitions */
694 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
695 char *, char *, char *, int);
697 void InitExitFunction(void (*exit_function)(int));
698 void InitPlatformDependantStuff(void);
699 void ClosePlatformDependantStuff(void);
701 void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *);
702 void InitGfxDoor1Info(int, int, int, int);
703 void InitGfxDoor2Info(int, int, int, int);
704 void InitGfxScrollbufferInfo(int, int);
705 void SetDrawDeactivationMask(int);
706 void SetDrawBackgroundMask(int);
707 void SetMainBackgroundBitmap(Bitmap *);
708 void SetDoorBackgroundBitmap(Bitmap *);
710 inline void InitVideoDisplay(void);
711 inline void CloseVideoDisplay(void);
712 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
713 inline Bitmap *CreateBitmapStruct(void);
714 inline Bitmap *CreateBitmap(int, int, int);
715 inline void FreeBitmap(Bitmap *);
716 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
717 inline void FillRectangle(Bitmap *, int, int, int, int, Pixel);
718 inline void ClearRectangle(Bitmap *, int, int, int, int);
719 inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
720 inline void SetClipMask(Bitmap *, GC, Pixmap);
721 inline void SetClipOrigin(Bitmap *, GC, int, int);
722 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
723 inline boolean DrawingOnBackground(int, int);
724 inline void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int,
726 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
727 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
728 inline Pixel GetPixel(Bitmap *, int, int);
729 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
730 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
732 inline void FlushDisplay(void);
733 inline void SyncDisplay(void);
734 inline void KeyboardAutoRepeatOn(void);
735 inline void KeyboardAutoRepeatOff(void);
736 inline boolean PointerInWindow(DrawWindow *);
737 inline boolean SetVideoMode(boolean);
738 inline boolean ChangeVideoModeIfNeeded(boolean);
740 Bitmap *LoadImage(char *);
741 Bitmap *LoadCustomImage(char *);
742 void ReloadCustomImage(Bitmap *, char *);
744 Bitmap *ZoomBitmap(Bitmap *, int, int);
745 void CreateBitmapWithSmallBitmaps(Bitmap *);
747 void SetMouseCursor(int);
749 inline void OpenAudio(void);
750 inline void CloseAudio(void);
751 inline void SetAudioMode(boolean);
753 inline void InitEventFilter(EventFilter);
754 inline boolean PendingEvent(void);
755 inline void NextEvent(Event *event);
756 inline Key GetEventKey(KeyEvent *, boolean);
757 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
759 inline void InitJoysticks();
760 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
762 #endif /* SYSTEM_H */