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_MV_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 text for non-existant artwork */
142 #define NOT_AVAILABLE "(not available)"
144 /* default value for undefined filename */
145 #define UNDEFINED_FILENAME "[NONE]"
147 /* default name for new levels */
148 #define NAMELESS_LEVEL_NAME "nameless level"
150 /* definitions for game sub-directories */
152 #define RO_GAME_DIR "."
156 #define RW_GAME_DIR "."
159 #define RO_BASE_PATH RO_GAME_DIR
160 #define RW_BASE_PATH RW_GAME_DIR
162 #define GRAPHICS_DIRECTORY "graphics"
163 #define SOUNDS_DIRECTORY "sounds"
164 #define MUSIC_DIRECTORY "music"
165 #define LEVELS_DIRECTORY "levels"
166 #define TAPES_DIRECTORY "tapes"
167 #define SCORES_DIRECTORY "scores"
169 #if !defined(PLATFORM_MSDOS)
170 #define GRAPHICS_SUBDIR "gfx_classic"
171 #define SOUNDS_SUBDIR "snd_classic"
172 #define MUSIC_SUBDIR "mus_classic"
174 #define GRAPHICS_SUBDIR "gfx_orig"
175 #define SOUNDS_SUBDIR "snd_orig"
176 #define MUSIC_SUBDIR "mus_orig"
179 /* areas in bitmap PIX_DOOR */
180 /* meaning in PIX_DB_DOOR: (3 PAGEs)
181 PAGEX1: 1. buffer for DOOR_1
182 PAGEX2: 2. buffer for DOOR_1
183 PAGEX3: buffer for animations
186 #define DOOR_GFX_PAGESIZE (gfx.dxsize)
187 #define DOOR_GFX_PAGEX1 (0 * DOOR_GFX_PAGESIZE)
188 #define DOOR_GFX_PAGEX2 (1 * DOOR_GFX_PAGESIZE)
189 #define DOOR_GFX_PAGEX3 (2 * DOOR_GFX_PAGESIZE)
190 #define DOOR_GFX_PAGEX4 (3 * DOOR_GFX_PAGESIZE)
191 #define DOOR_GFX_PAGEX5 (4 * DOOR_GFX_PAGESIZE)
192 #define DOOR_GFX_PAGEX6 (5 * DOOR_GFX_PAGESIZE)
193 #define DOOR_GFX_PAGEX7 (6 * DOOR_GFX_PAGESIZE)
194 #define DOOR_GFX_PAGEX8 (7 * DOOR_GFX_PAGESIZE)
195 #define DOOR_GFX_PAGEY1 (0)
196 #define DOOR_GFX_PAGEY2 (gfx.dysize)
198 /* functions for version handling */
199 #define VERSION_IDENT(x,y,z) ((x) * 10000 + (y) * 100 + (z))
200 #define VERSION_MAJOR(x) ((x) / 10000)
201 #define VERSION_MINOR(x) (((x) % 10000) / 100)
202 #define VERSION_PATCH(x) ((x) % 100)
204 /* functions for parent/child process identification */
205 #define IS_PARENT_PROCESS(pid) ((pid) > 0)
206 #define IS_CHILD_PROCESS(pid) ((pid) == 0)
209 /* type definitions */
210 typedef int (*EventFilter)(const Event *);
213 /* structure definitions */
217 char *command_basename;
218 char *userdata_directory;
224 char *x11_icon_filename;
225 char *x11_iconmask_filename;
226 char *msdos_pointer_filename;
229 char *filename_prefix; /* prefix to cut off from DOS filenames */
235 void (*exit_function)(int);
244 char *ro_base_directory;
245 char *rw_base_directory;
246 char *level_directory;
247 char *graphics_directory;
248 char *sounds_directory;
249 char *music_directory;
250 char *execute_command;
258 struct VideoSystemInfo
261 int width, height, depth;
262 boolean fullscreen_available;
263 boolean fullscreen_enabled;
266 struct AudioSystemInfo
268 boolean sound_available;
269 boolean loops_available;
270 boolean music_available;
272 boolean sound_enabled;
273 boolean sound_deactivated; /* for temporarily disabling sound */
282 int first_sound_channel;
289 int real_sx, real_sy;
290 int full_sxsize, full_sysize;
291 int scrollbuffer_width, scrollbuffer_height;
299 boolean draw_deactivation_mask;
305 int fd[MAX_PLAYERS]; /* file descriptor of player's joystick */
308 struct SetupJoystickInfo
310 char *device_name; /* device name of player's joystick */
312 int xleft, xmiddle, xright;
313 int yupper, ymiddle, ylower;
318 struct SetupKeyboardInfo
328 struct SetupInputInfo
330 boolean use_joystick;
331 struct SetupJoystickInfo joy;
332 struct SetupKeyboardInfo key;
335 struct SetupShortcutInfo
349 boolean sound_simple;
351 boolean double_buffering;
352 boolean direct_draw; /* !double_buffering (redundant!) */
353 boolean scroll_delay;
354 boolean soft_scrolling;
362 boolean ask_on_escape;
367 boolean override_level_graphics;
368 boolean override_level_sounds;
369 boolean override_level_music;
371 struct SetupShortcutInfo shortcut;
372 struct SetupInputInfo input[MAX_PLAYERS];
375 #define TREE_TYPE_GENERIC 0
376 #define TREE_TYPE_GRAPHICS_DIR 1
377 #define TREE_TYPE_SOUNDS_DIR 2
378 #define TREE_TYPE_MUSIC_DIR 3
379 #define TREE_TYPE_LEVEL_DIR 4
381 #define ARTWORK_TYPE_GRAPHICS TREE_TYPE_GRAPHICS_DIR
382 #define ARTWORK_TYPE_SOUNDS TREE_TYPE_SOUNDS_DIR
383 #define ARTWORK_TYPE_MUSIC TREE_TYPE_MUSIC_DIR
387 struct TreeInfo **node_top; /* topmost node in tree */
388 struct TreeInfo *node_parent; /* parent level directory info */
389 struct TreeInfo *node_group; /* level group sub-directory info */
390 struct TreeInfo *next; /* next level series structure node */
392 int cl_first; /* internal control field for setup screen */
393 int cl_cursor; /* internal control field for setup screen */
395 int type; /* type of tree content */
397 /* fields for "type == TREE_TYPE_LEVEL_DIR" */
399 char *filename; /* tree info sub-directory basename (may be ".") */
400 char *fullpath; /* complete path relative to tree base directory */
401 char *basepath; /* absolute base path of tree base directory */
402 char *identifier; /* identifier string for configuration files */
403 char *name; /* tree info name, as displayed in selection menues */
404 char *name_sorting; /* optional sorting name for correct name sorting */
405 char *author; /* level or artwork author name */
406 char *imported_from; /* optional comment for imported levels or artwork */
408 char *graphics_set; /* optional custom graphics set (level tree only) */
409 char *sounds_set; /* optional custom sounds set (level tree only) */
410 char *music_set; /* optional custom music set (level tree only) */
411 char *graphics_path; /* path to optional custom graphics set (level only) */
412 char *sounds_path; /* path to optional custom sounds set (level only) */
413 char *music_path; /* path to optional custom music set (level only) */
415 int levels; /* number of levels in level series */
416 int first_level; /* first level number (to allow start with 0 or 1) */
417 int last_level; /* last level number (automatically calculated) */
418 int sort_priority; /* sort levels by 'sort_priority' and then by name */
420 boolean level_group; /* directory contains more level series directories */
421 boolean parent_link; /* entry links back to parent directory */
422 boolean user_defined; /* user defined levels are stored in home directory */
423 boolean readonly; /* readonly levels can not be changed with editor */
425 int color; /* color to use on selection screen for this level */
426 char *class_desc; /* description of level series class */
427 int handicap_level; /* number of the lowest unsolved level */
430 typedef struct TreeInfo TreeInfo;
431 typedef struct TreeInfo LevelDirTree;
432 typedef struct TreeInfo ArtworkDirTree;
433 typedef struct TreeInfo GraphicsDirTree;
434 typedef struct TreeInfo SoundsDirTree;
435 typedef struct TreeInfo MusicDirTree;
439 GraphicsDirTree *gfx_first;
440 GraphicsDirTree *gfx_current;
441 SoundsDirTree *snd_first;
442 SoundsDirTree *snd_current;
443 MusicDirTree *mus_first;
444 MusicDirTree *mus_current;
446 char *gfx_current_identifier;
447 char *snd_current_identifier;
448 char *mus_current_identifier;
461 char *default_filename;
464 int *default_parameter; /* array of file parameters */
465 int *parameter; /* array of file parameters */
470 char *source_filename; /* primary key for node list */
474 struct ArtworkListInfo
476 int type; /* type of artwork */
478 int num_file_list_entries;
479 int num_suffix_list_entries;
481 struct FileInfo *file_list; /* static artwork file array */
482 struct ConfigInfo *suffix_list; /* parameter suffixes array */
484 struct ListNodeInfo **artwork_list; /* static artwork node array */
486 struct ListNode *content_list; /* dynamic artwork node list */
488 void *(*load_artwork)(char *); /* constructor function */
489 void (*free_artwork)(void *); /* destructor function */
493 /* ========================================================================= */
494 /* exported variables */
495 /* ========================================================================= */
497 extern struct ProgramInfo program;
498 extern struct OptionInfo options;
499 extern struct VideoSystemInfo video;
500 extern struct AudioSystemInfo audio;
501 extern struct GfxInfo gfx;
502 extern struct ArtworkInfo artwork;
503 extern struct JoystickInfo joystick;
504 extern struct SetupInfo setup;
506 extern LevelDirTree *leveldir_first;
507 extern LevelDirTree *leveldir_current;
510 extern Display *display;
511 extern Visual *visual;
513 extern Colormap cmap;
515 extern DrawWindow *window;
516 extern DrawBuffer *backbuffer;
517 extern DrawBuffer *drawto;
519 extern int button_status;
520 extern boolean motion_status;
522 extern int redraw_mask;
523 extern int redraw_tiles;
525 extern int FrameCounter;
528 /* function definitions */
530 void InitCommandName(char *);
531 void InitExitFunction(void (*exit_function)(int));
532 void InitPlatformDependantStuff(void);
533 void ClosePlatformDependantStuff(void);
535 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
536 char *, char *, int);
538 void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
539 void InitGfxDoor1Info(int, int, int, int);
540 void InitGfxDoor2Info(int, int, int, int);
541 void InitGfxScrollbufferInfo(int, int);
542 void SetDrawDeactivationMask(int );
544 inline void InitVideoDisplay(void);
545 inline void CloseVideoDisplay(void);
546 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
547 inline Bitmap *CreateBitmapStruct(void);
548 inline Bitmap *CreateBitmap(int, int, int);
549 inline void FreeBitmap(Bitmap *);
550 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
551 inline void ClearRectangle(Bitmap *, int, int, int, int);
552 inline void SetClipMask(Bitmap *, GC, Pixmap);
553 inline void SetClipOrigin(Bitmap *, GC, int, int);
554 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
555 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
556 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
557 inline Pixel GetPixel(Bitmap *, int, int);
558 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
559 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
561 inline void FlushDisplay(void);
562 inline void SyncDisplay(void);
563 inline void KeyboardAutoRepeatOn(void);
564 inline void KeyboardAutoRepeatOff(void);
565 inline boolean PointerInWindow(DrawWindow *);
566 inline boolean SetVideoMode(boolean);
567 inline boolean ChangeVideoModeIfNeeded(boolean);
569 Bitmap *LoadImage(char *);
570 Bitmap *LoadCustomImage(char *);
571 void ReloadCustomImage(Bitmap *, char *);
573 inline void OpenAudio(void);
574 inline void CloseAudio(void);
575 inline void SetAudioMode(boolean);
577 inline void InitEventFilter(EventFilter);
578 inline boolean PendingEvent(void);
579 inline void NextEvent(Event *event);
580 inline Key GetEventKey(KeyEvent *, boolean);
581 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
583 inline void InitJoysticks();
584 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
586 #endif /* SYSTEM_H */