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 animation mode (frame order and direction) */
106 #define ANIM_LOOP (1 << 0)
107 #define ANIM_LINEAR (1 << 1)
108 #define ANIM_PINGPONG (1 << 2)
109 #define ANIM_PINGPONG2 (1 << 3)
110 #define ANIM_RANDOM (1 << 4)
111 #define ANIM_REVERSE (1 << 5)
113 /* values for redraw_mask */
114 #define REDRAW_NONE (0)
115 #define REDRAW_ALL (1 << 0)
116 #define REDRAW_FIELD (1 << 1)
117 #define REDRAW_TILES (1 << 2)
118 #define REDRAW_DOOR_1 (1 << 3)
119 #define REDRAW_VIDEO_1 (1 << 4)
120 #define REDRAW_VIDEO_2 (1 << 5)
121 #define REDRAW_VIDEO_3 (1 << 6)
122 #define REDRAW_MICROLEVEL (1 << 7)
123 #define REDRAW_MICROLABEL (1 << 8)
124 #define REDRAW_FROM_BACKBUFFER (1 << 9)
125 #define REDRAW_DOOR_2 (REDRAW_VIDEO_1 | \
128 #define REDRAW_DOOR_3 (1 << 10)
129 #define REDRAW_DOORS (REDRAW_DOOR_1 | \
132 #define REDRAW_MAIN (REDRAW_FIELD | \
135 #define REDRAW_FPS (1 << 11)
136 #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2)
138 /* maximum number of parallel players supported by libgame functions */
139 #define MAX_PLAYERS 4
141 /* maximum allowed length of player name */
142 #define MAX_PLAYER_NAME_LEN 10
144 /* default name for empty highscore entry */
145 #define EMPTY_PLAYER_NAME "no name"
147 /* default name for unknown player names */
148 #define ANONYMOUS_NAME "anonymous"
150 /* default name for new levels */
151 #define NAMELESS_LEVEL_NAME "nameless level"
153 /* default text for non-existant artwork */
154 #define NOT_AVAILABLE "(not available)"
156 /* default value for undefined filename */
157 #define UNDEFINED_FILENAME "[NONE]"
159 /* default value for undefined parameter */
160 #define ARG_DEFAULT "[DEFAULT]"
162 /* default values for undefined configuration file parameters */
163 #define ARG_UNDEFINED "-1000000"
164 #define ARG_UNDEFINED_VALUE (atoi(ARG_UNDEFINED))
166 /* definitions for game sub-directories */
168 #define RO_GAME_DIR "."
172 #define RW_GAME_DIR "."
175 #define RO_BASE_PATH RO_GAME_DIR
176 #define RW_BASE_PATH RW_GAME_DIR
178 #define GRAPHICS_DIRECTORY "graphics"
179 #define SOUNDS_DIRECTORY "sounds"
180 #define MUSIC_DIRECTORY "music"
181 #define LEVELS_DIRECTORY "levels"
182 #define TAPES_DIRECTORY "tapes"
183 #define SCORES_DIRECTORY "scores"
185 #if !defined(PLATFORM_MSDOS)
186 #define GRAPHICS_SUBDIR "gfx_classic"
187 #define SOUNDS_SUBDIR "snd_classic"
188 #define MUSIC_SUBDIR "mus_classic"
190 #define GRAPHICS_SUBDIR "gfx_orig"
191 #define SOUNDS_SUBDIR "snd_orig"
192 #define MUSIC_SUBDIR "mus_orig"
195 /* areas in bitmap PIX_DOOR */
196 /* meaning in PIX_DB_DOOR: (3 PAGEs)
197 PAGEX1: 1. buffer for DOOR_1
198 PAGEX2: 2. buffer for DOOR_1
199 PAGEX3: buffer for animations
202 #define DOOR_GFX_PAGESIZE (gfx.dxsize)
203 #define DOOR_GFX_PAGEX1 (0 * DOOR_GFX_PAGESIZE)
204 #define DOOR_GFX_PAGEX2 (1 * DOOR_GFX_PAGESIZE)
205 #define DOOR_GFX_PAGEX3 (2 * DOOR_GFX_PAGESIZE)
206 #define DOOR_GFX_PAGEX4 (3 * DOOR_GFX_PAGESIZE)
207 #define DOOR_GFX_PAGEX5 (4 * DOOR_GFX_PAGESIZE)
208 #define DOOR_GFX_PAGEX6 (5 * DOOR_GFX_PAGESIZE)
209 #define DOOR_GFX_PAGEX7 (6 * DOOR_GFX_PAGESIZE)
210 #define DOOR_GFX_PAGEX8 (7 * DOOR_GFX_PAGESIZE)
211 #define DOOR_GFX_PAGEY1 (0)
212 #define DOOR_GFX_PAGEY2 (gfx.dysize)
214 /* functions for version handling */
215 #define VERSION_IDENT(x,y,z) ((x) * 10000 + (y) * 100 + (z))
216 #define VERSION_MAJOR(x) ((x) / 10000)
217 #define VERSION_MINOR(x) (((x) % 10000) / 100)
218 #define VERSION_PATCH(x) ((x) % 100)
220 /* functions for parent/child process identification */
221 #if defined(PLATFORM_UNIX)
222 #define IS_PARENT_PROCESS() (audio.mixer_pid != getpid())
223 #define IS_CHILD_PROCESS() (audio.mixer_pid == getpid())
225 #define IS_PARENT_PROCESS() TRUE
226 #define IS_CHILD_PROCESS() FALSE
229 /* type definitions */
230 typedef int (*EventFilter)(const Event *);
233 /* structure definitions */
237 char *command_basename;
238 char *userdata_directory;
244 char *x11_icon_filename;
245 char *x11_iconmask_filename;
246 char *msdos_pointer_filename;
249 char *filename_prefix; /* prefix to cut off from DOS filenames */
255 void (*exit_function)(int);
264 char *ro_base_directory;
265 char *rw_base_directory;
266 char *level_directory;
267 char *graphics_directory;
268 char *sounds_directory;
269 char *music_directory;
270 char *execute_command;
278 struct VideoSystemInfo
281 int width, height, depth;
282 boolean fullscreen_available;
283 boolean fullscreen_enabled;
286 struct AudioSystemInfo
288 boolean sound_available;
289 boolean loops_available;
290 boolean music_available;
292 boolean sound_enabled;
293 boolean sound_deactivated; /* for temporarily disabling sound */
302 int first_sound_channel;
305 struct FontBitmapInfo
308 int src_x, src_y; /* start position of animation frames */
309 int width, height; /* width/height of each animation frame */
310 int draw_x, draw_y; /* offset for drawing font characters */
312 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
313 Pixmap *clip_mask; /* single-char-only clip mask array for X11 */
321 int real_sx, real_sy;
322 int full_sxsize, full_sysize;
323 int scrollbuffer_width, scrollbuffer_height;
331 int draw_deactivation_mask;
332 int draw_background_mask;
334 Bitmap *background_bitmap;
335 int background_bitmap_mask;
338 struct FontBitmapInfo *font_bitmap_info;
339 int (*select_font_function)(int);
341 int anim_random_frame;
347 int fd[MAX_PLAYERS]; /* file descriptor of player's joystick */
350 struct SetupJoystickInfo
352 char *device_name; /* device name of player's joystick */
354 int xleft, xmiddle, xright;
355 int yupper, ymiddle, ylower;
360 struct SetupKeyboardInfo
370 struct SetupInputInfo
372 boolean use_joystick;
373 struct SetupJoystickInfo joy;
374 struct SetupKeyboardInfo key;
377 struct SetupEditorInfo
379 boolean el_boulderdash;
380 boolean el_emerald_mine;
384 boolean el_diamond_caves;
385 boolean el_dx_boulderdash;
390 struct SetupShortcutInfo
397 struct SetupSystemInfo
399 char *sdl_audiodriver;
400 int audio_fragment_size;
410 boolean sound_simple;
412 boolean double_buffering;
413 boolean direct_draw; /* !double_buffering (redundant!) */
414 boolean scroll_delay;
415 boolean soft_scrolling;
423 boolean ask_on_escape;
428 boolean override_level_graphics;
429 boolean override_level_sounds;
430 boolean override_level_music;
432 struct SetupEditorInfo editor;
433 struct SetupShortcutInfo shortcut;
434 struct SetupInputInfo input[MAX_PLAYERS];
435 struct SetupSystemInfo system;
436 struct OptionInfo options;
439 #define TREE_TYPE_GENERIC 0
440 #define TREE_TYPE_GRAPHICS_DIR 1
441 #define TREE_TYPE_SOUNDS_DIR 2
442 #define TREE_TYPE_MUSIC_DIR 3
443 #define TREE_TYPE_LEVEL_DIR 4
445 #define ARTWORK_TYPE_GRAPHICS TREE_TYPE_GRAPHICS_DIR
446 #define ARTWORK_TYPE_SOUNDS TREE_TYPE_SOUNDS_DIR
447 #define ARTWORK_TYPE_MUSIC TREE_TYPE_MUSIC_DIR
451 struct TreeInfo **node_top; /* topmost node in tree */
452 struct TreeInfo *node_parent; /* parent level directory info */
453 struct TreeInfo *node_group; /* level group sub-directory info */
454 struct TreeInfo *next; /* next level series structure node */
456 int cl_first; /* internal control field for setup screen */
457 int cl_cursor; /* internal control field for setup screen */
459 int type; /* type of tree content */
461 /* fields for "type == TREE_TYPE_LEVEL_DIR" */
463 char *filename; /* tree info sub-directory basename (may be ".") */
464 char *fullpath; /* complete path relative to tree base directory */
465 char *basepath; /* absolute base path of tree base directory */
466 char *identifier; /* identifier string for configuration files */
467 char *name; /* tree info name, as displayed in selection menues */
468 char *name_sorting; /* optional sorting name for correct name sorting */
469 char *author; /* level or artwork author name */
470 char *imported_from; /* optional comment for imported levels or artwork */
472 char *graphics_set; /* optional custom graphics set (level tree only) */
473 char *sounds_set; /* optional custom sounds set (level tree only) */
474 char *music_set; /* optional custom music set (level tree only) */
475 char *graphics_path; /* path to optional custom graphics set (level only) */
476 char *sounds_path; /* path to optional custom sounds set (level only) */
477 char *music_path; /* path to optional custom music set (level only) */
479 int levels; /* number of levels in level series */
480 int first_level; /* first level number (to allow start with 0 or 1) */
481 int last_level; /* last level number (automatically calculated) */
482 int sort_priority; /* sort levels by 'sort_priority' and then by name */
484 boolean level_group; /* directory contains more level series directories */
485 boolean parent_link; /* entry links back to parent directory */
486 boolean user_defined; /* user defined levels are stored in home directory */
487 boolean readonly; /* readonly levels can not be changed with editor */
489 int color; /* color to use on selection screen for this level */
490 char *class_desc; /* description of level series class */
491 int handicap_level; /* number of the lowest unsolved level */
494 typedef struct TreeInfo TreeInfo;
495 typedef struct TreeInfo LevelDirTree;
496 typedef struct TreeInfo ArtworkDirTree;
497 typedef struct TreeInfo GraphicsDirTree;
498 typedef struct TreeInfo SoundsDirTree;
499 typedef struct TreeInfo MusicDirTree;
503 GraphicsDirTree *gfx_first;
504 GraphicsDirTree *gfx_current;
505 SoundsDirTree *snd_first;
506 SoundsDirTree *snd_current;
507 MusicDirTree *mus_first;
508 MusicDirTree *mus_current;
510 char *gfx_current_identifier;
511 char *snd_current_identifier;
512 char *mus_current_identifier;
526 char *default_filename;
529 char **default_parameter; /* array of file parameters */
530 char **parameter; /* array of file parameters */
540 struct SetupFileList *next;
545 char *source_filename; /* primary key for node list */
549 struct PropertyMapping
559 struct ArtworkListInfo
561 int type; /* type of artwork */
563 int num_file_list_entries;
564 int num_dynamic_file_list_entries;
565 struct FileInfo *file_list; /* static artwork file array */
566 struct FileInfo *dynamic_file_list; /* dynamic artwrk file array */
568 int num_suffix_list_entries;
569 struct ConfigInfo *suffix_list; /* parameter suffixes array */
571 int num_base_prefixes;
572 int num_ext1_suffixes;
573 int num_ext2_suffixes;
574 int num_ext3_suffixes;
575 char **base_prefixes; /* base token prefixes array */
576 char **ext1_suffixes; /* property suffixes array 1 */
577 char **ext2_suffixes; /* property suffixes array 2 */
578 char **ext3_suffixes; /* property suffixes array 3 */
580 int num_ignore_tokens;
581 char **ignore_tokens; /* file tokens to be ignored */
583 int num_property_mapping_entries;
584 struct PropertyMapping *property_mapping; /* mapping token -> artwork */
586 int sizeof_artwork_list_entry;
588 struct ListNodeInfo **artwork_list; /* static artwork node array */
589 struct ListNodeInfo **dynamic_artwork_list; /* dynamic artwrk node array */
590 struct ListNode *content_list; /* dynamic artwork node list */
592 void *(*load_artwork)(char *); /* constructor function */
593 void (*free_artwork)(void *); /* destructor function */
597 /* ========================================================================= */
598 /* exported variables */
599 /* ========================================================================= */
601 extern struct ProgramInfo program;
602 extern struct OptionInfo options;
603 extern struct VideoSystemInfo video;
604 extern struct AudioSystemInfo audio;
605 extern struct GfxInfo gfx;
606 extern struct AnimInfo anim;
607 extern struct ArtworkInfo artwork;
608 extern struct JoystickInfo joystick;
609 extern struct SetupInfo setup;
611 extern LevelDirTree *leveldir_first;
612 extern LevelDirTree *leveldir_current;
615 extern Display *display;
616 extern Visual *visual;
618 extern Colormap cmap;
620 extern DrawWindow *window;
621 extern DrawBuffer *backbuffer;
622 extern DrawBuffer *drawto;
624 extern int button_status;
625 extern boolean motion_status;
627 extern int redraw_mask;
628 extern int redraw_tiles;
630 extern int FrameCounter;
633 /* function definitions */
635 void InitCommandName(char *);
636 void InitExitFunction(void (*exit_function)(int));
637 void InitPlatformDependantStuff(void);
638 void ClosePlatformDependantStuff(void);
640 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
641 char *, char *, int);
643 void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
644 void InitGfxDoor1Info(int, int, int, int);
645 void InitGfxDoor2Info(int, int, int, int);
646 void InitGfxScrollbufferInfo(int, int);
647 void SetDrawDeactivationMask(int);
648 void SetDrawBackgroundMask(int);
649 void SetMainBackgroundBitmap(Bitmap *);
650 void SetDoorBackgroundBitmap(Bitmap *);
652 inline void InitVideoDisplay(void);
653 inline void CloseVideoDisplay(void);
654 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
655 inline Bitmap *CreateBitmapStruct(void);
656 inline Bitmap *CreateBitmap(int, int, int);
657 inline void FreeBitmap(Bitmap *);
658 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
659 inline void ClearRectangle(Bitmap *, int, int, int, int);
660 inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int);
661 inline void SetClipMask(Bitmap *, GC, Pixmap);
662 inline void SetClipOrigin(Bitmap *, GC, int, int);
663 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
664 inline boolean DrawingOnBackground(int, int);
665 inline void BlitBitmapOnBackground(Bitmap *, Bitmap *, int, int, int, int, int,
667 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
668 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
669 inline Pixel GetPixel(Bitmap *, int, int);
670 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
671 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
673 inline void FlushDisplay(void);
674 inline void SyncDisplay(void);
675 inline void KeyboardAutoRepeatOn(void);
676 inline void KeyboardAutoRepeatOff(void);
677 inline boolean PointerInWindow(DrawWindow *);
678 inline boolean SetVideoMode(boolean);
679 inline boolean ChangeVideoModeIfNeeded(boolean);
681 Bitmap *LoadImage(char *);
682 Bitmap *LoadCustomImage(char *);
683 void ReloadCustomImage(Bitmap *, char *);
685 Bitmap *ZoomBitmap(Bitmap *, int, int);
686 void CreateBitmapWithSmallBitmaps(Bitmap *);
688 inline void OpenAudio(void);
689 inline void CloseAudio(void);
690 inline void SetAudioMode(boolean);
692 inline void InitEventFilter(EventFilter);
693 inline boolean PendingEvent(void);
694 inline void NextEvent(Event *event);
695 inline Key GetEventKey(KeyEvent *, boolean);
696 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
698 inline void InitJoysticks();
699 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
701 #endif /* SYSTEM_H */