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 */
70 #define MV_NO_MOVING 0
71 #define MV_LEFT (1 << 0)
72 #define MV_RIGHT (1 << 1)
73 #define MV_UP (1 << 2)
74 #define MV_DOWN (1 << 3)
75 #define KEY_BUTTON_1 (1 << 4)
76 #define KEY_BUTTON_2 (1 << 5)
77 #define KEY_MOTION (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
78 #define KEY_BUTTON (KEY_BUTTON_1 | KEY_BUTTON_2)
79 #define KEY_ACTION (KEY_MOTION | KEY_BUTTON)
81 /* values for button status */
82 #define MB_NOT_PRESSED FALSE
83 #define MB_NOT_RELEASED TRUE
84 #define MB_RELEASED FALSE
85 #define MB_PRESSED TRUE
86 #define MB_MENU_CHOICE FALSE
87 #define MB_MENU_MARK TRUE
88 #define MB_MENU_INITIALIZE (-1)
89 #define MB_MENU_LEAVE (-2)
90 #define MB_LEFTBUTTON 1
91 #define MB_MIDDLEBUTTON 2
92 #define MB_RIGHTBUTTON 3
94 /* values for redraw_mask */
95 #define REDRAW_NONE (0)
96 #define REDRAW_ALL (1 << 0)
97 #define REDRAW_FIELD (1 << 1)
98 #define REDRAW_TILES (1 << 2)
99 #define REDRAW_DOOR_1 (1 << 3)
100 #define REDRAW_VIDEO_1 (1 << 4)
101 #define REDRAW_VIDEO_2 (1 << 5)
102 #define REDRAW_VIDEO_3 (1 << 6)
103 #define REDRAW_MICROLEVEL (1 << 7)
104 #define REDRAW_MICROLABEL (1 << 8)
105 #define REDRAW_FROM_BACKBUFFER (1 << 9)
106 #define REDRAW_DOOR_2 (REDRAW_VIDEO_1 | \
109 #define REDRAW_DOOR_3 (1 << 10)
110 #define REDRAW_DOORS (REDRAW_DOOR_1 | \
113 #define REDRAW_MAIN (REDRAW_FIELD | \
116 #define REDRAW_FPS (1 << 11)
117 #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2)
119 /* maximum number of parallel players supported by libgame functions */
120 #define MAX_PLAYERS 4
122 /* maximum allowed length of player name */
123 #define MAX_PLAYER_NAME_LEN 10
125 /* default name for empty highscore entry */
126 #define EMPTY_PLAYER_NAME "no name"
128 /* default name for unknown player names */
129 #define ANONYMOUS_NAME "anonymous"
131 /* default text for non-existant artwork */
132 #define NOT_AVAILABLE "(not available)"
134 /* default name for new levels */
135 #define NAMELESS_LEVEL_NAME "nameless level"
137 /* definitions for game sub-directories */
139 #define RO_GAME_DIR "."
143 #define RW_GAME_DIR "."
146 #define RO_BASE_PATH RO_GAME_DIR
147 #define RW_BASE_PATH RW_GAME_DIR
149 #define GRAPHICS_DIRECTORY "graphics"
150 #define SOUNDS_DIRECTORY "sounds"
151 #define MUSIC_DIRECTORY "music"
152 #define LEVELS_DIRECTORY "levels"
153 #define TAPES_DIRECTORY "tapes"
154 #define SCORES_DIRECTORY "scores"
156 #if !defined(PLATFORM_MSDOS)
157 #define GRAPHICS_SUBDIR "gfx_classic"
158 #define SOUNDS_SUBDIR "snd_classic"
159 #define MUSIC_SUBDIR "mus_classic"
161 #define GRAPHICS_SUBDIR "gfx_orig"
162 #define SOUNDS_SUBDIR "snd_orig"
163 #define MUSIC_SUBDIR "mus_orig"
166 /* areas in bitmap PIX_DOOR */
167 /* meaning in PIX_DB_DOOR: (3 PAGEs)
168 PAGEX1: 1. buffer for DOOR_1
169 PAGEX2: 2. buffer for DOOR_1
170 PAGEX3: buffer for animations
173 #define DOOR_GFX_PAGESIZE (gfx.dxsize)
174 #define DOOR_GFX_PAGEX1 (0 * DOOR_GFX_PAGESIZE)
175 #define DOOR_GFX_PAGEX2 (1 * DOOR_GFX_PAGESIZE)
176 #define DOOR_GFX_PAGEX3 (2 * DOOR_GFX_PAGESIZE)
177 #define DOOR_GFX_PAGEX4 (3 * DOOR_GFX_PAGESIZE)
178 #define DOOR_GFX_PAGEX5 (4 * DOOR_GFX_PAGESIZE)
179 #define DOOR_GFX_PAGEX6 (5 * DOOR_GFX_PAGESIZE)
180 #define DOOR_GFX_PAGEX7 (6 * DOOR_GFX_PAGESIZE)
181 #define DOOR_GFX_PAGEX8 (7 * DOOR_GFX_PAGESIZE)
182 #define DOOR_GFX_PAGEY1 (0)
183 #define DOOR_GFX_PAGEY2 (gfx.dysize)
185 /* functions for version handling */
186 #define VERSION_IDENT(x,y,z) ((x) * 10000 + (y) * 100 + (z))
187 #define VERSION_MAJOR(x) ((x) / 10000)
188 #define VERSION_MINOR(x) (((x) % 10000) / 100)
189 #define VERSION_PATCH(x) ((x) % 100)
191 /* functions for parent/child process identification */
192 #define IS_PARENT_PROCESS(pid) ((pid) > 0)
193 #define IS_CHILD_PROCESS(pid) ((pid) == 0)
196 /* type definitions */
197 typedef int (*EventFilter)(const Event *);
200 /* structure definitions */
204 char *command_basename;
205 char *userdata_directory;
211 char *x11_icon_filename;
212 char *x11_iconmask_filename;
213 char *msdos_pointer_filename;
216 char *filename_prefix; /* prefix to cut off from DOS filenames */
222 void (*exit_function)(int);
230 char *ro_base_directory;
231 char *rw_base_directory;
232 char *level_directory;
233 char *graphics_directory;
234 char *sounds_directory;
235 char *music_directory;
243 struct VideoSystemInfo
246 int width, height, depth;
247 boolean fullscreen_available;
248 boolean fullscreen_enabled;
251 struct AudioSystemInfo
253 boolean sound_available;
254 boolean loops_available;
255 boolean music_available;
257 boolean sound_enabled;
258 boolean sound_deactivated; /* for temporarily disabling sound */
267 int first_sound_channel;
274 int real_sx, real_sy;
275 int full_sxsize, full_sysize;
276 int scrollbuffer_width, scrollbuffer_height;
284 boolean draw_deactivation_mask;
290 int fd[MAX_PLAYERS]; /* file descriptor of player's joystick */
293 struct SetupJoystickInfo
295 char *device_name; /* device name of player's joystick */
297 int xleft, xmiddle, xright;
298 int yupper, ymiddle, ylower;
303 struct SetupKeyboardInfo
313 struct SetupInputInfo
315 boolean use_joystick;
316 struct SetupJoystickInfo joy;
317 struct SetupKeyboardInfo key;
320 struct SetupShortcutInfo
334 boolean sound_simple;
336 boolean double_buffering;
337 boolean direct_draw; /* !double_buffering (redundant!) */
338 boolean scroll_delay;
339 boolean soft_scrolling;
347 boolean ask_on_escape;
352 boolean override_level_graphics;
353 boolean override_level_sounds;
354 boolean override_level_music;
356 struct SetupShortcutInfo shortcut;
357 struct SetupInputInfo input[MAX_PLAYERS];
360 #define TREE_TYPE_GENERIC 0
361 #define TREE_TYPE_LEVEL_DIR 1
362 #define TREE_TYPE_GRAPHICS_DIR 2
363 #define TREE_TYPE_SOUNDS_DIR 3
364 #define TREE_TYPE_MUSIC_DIR 4
368 struct TreeInfo **node_top; /* topmost node in tree */
369 struct TreeInfo *node_parent; /* parent level directory info */
370 struct TreeInfo *node_group; /* level group sub-directory info */
371 struct TreeInfo *next; /* next level series structure node */
373 int cl_first; /* internal control field for setup screen */
374 int cl_cursor; /* internal control field for setup screen */
376 int type; /* type of tree content */
378 /* fields for "type == TREE_TYPE_LEVEL_DIR" */
380 char *filename; /* level series single directory name */
381 char *fullpath; /* complete path relative to level directory */
382 char *basepath; /* absolute base path of level directory */
383 char *name; /* level series name, as displayed on main screen */
384 char *name_short; /* optional short name for level selection screen */
385 char *name_sorting; /* optional sorting name for correct level sorting */
386 char *author; /* level series author name levels without author */
387 char *imported_from; /* optional comment for imported level series */
388 int levels; /* number of levels in level series */
389 int first_level; /* first level number (to allow start with 0 or 1) */
390 int last_level; /* last level number (automatically calculated) */
391 int sort_priority; /* sort levels by 'sort_priority' and then by name */
392 boolean level_group; /* directory contains more level series directories */
393 boolean parent_link; /* entry links back to parent directory */
394 boolean user_defined; /* user defined levels are stored in home directory */
395 boolean readonly; /* readonly levels can not be changed with editor */
396 int color; /* color to use on selection screen for this level */
397 char *class_desc; /* description of level series class */
398 int handicap_level; /* number of the lowest unsolved level */
401 typedef struct TreeInfo TreeInfo;
402 typedef struct TreeInfo LevelDirTree;
403 typedef struct TreeInfo ArtworkDirTree;
404 typedef struct TreeInfo GraphicsDirTree;
405 typedef struct TreeInfo SoundsDirTree;
406 typedef struct TreeInfo MusicDirTree;
410 GraphicsDirTree *gfx_first;
411 GraphicsDirTree *gfx_current;
412 SoundsDirTree *snd_first;
413 SoundsDirTree *snd_current;
414 MusicDirTree *mus_first;
415 MusicDirTree *mus_current;
417 char *graphics_set_current_name;
418 char *sounds_set_current_name;
419 char *music_set_current_name;
423 /* ========================================================================= */
424 /* exported variables */
425 /* ========================================================================= */
427 extern struct ProgramInfo program;
428 extern struct OptionInfo options;
429 extern struct VideoSystemInfo video;
430 extern struct AudioSystemInfo audio;
431 extern struct GfxInfo gfx;
432 extern struct ArtworkInfo artwork;
433 extern struct JoystickInfo joystick;
434 extern struct SetupInfo setup;
436 extern LevelDirTree *leveldir_first;
437 extern LevelDirTree *leveldir_current;
440 extern Display *display;
441 extern Visual *visual;
443 extern Colormap cmap;
445 extern DrawWindow *window;
446 extern DrawBuffer *backbuffer;
447 extern DrawBuffer *drawto;
449 extern int button_status;
450 extern boolean motion_status;
452 extern int redraw_mask;
453 extern int redraw_tiles;
455 extern int FrameCounter;
458 /* function definitions */
460 void InitCommandName(char *);
461 void InitExitFunction(void (*exit_function)(int));
462 void InitPlatformDependantStuff(void);
463 void ClosePlatformDependantStuff(void);
465 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
466 char *, char *, int);
468 void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
469 void InitGfxDoor1Info(int, int, int, int);
470 void InitGfxDoor2Info(int, int, int, int);
471 void InitGfxScrollbufferInfo(int, int);
472 void SetDrawDeactivationMask(int );
474 inline void InitVideoDisplay(void);
475 inline void CloseVideoDisplay(void);
476 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
477 inline Bitmap *CreateBitmapStruct(void);
478 inline Bitmap *CreateBitmap(int, int, int);
479 inline void FreeBitmap(Bitmap *);
480 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
481 inline void ClearRectangle(Bitmap *, int, int, int, int);
482 inline void SetClipMask(Bitmap *, GC, Pixmap);
483 inline void SetClipOrigin(Bitmap *, GC, int, int);
484 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
485 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
486 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
487 inline Pixel GetPixel(Bitmap *, int, int);
488 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
489 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
491 inline void FlushDisplay(void);
492 inline void SyncDisplay(void);
493 inline void KeyboardAutoRepeatOn(void);
494 inline void KeyboardAutoRepeatOff(void);
495 inline boolean PointerInWindow(DrawWindow *);
496 inline boolean SetVideoMode(boolean);
497 inline boolean ChangeVideoModeIfNeeded(boolean);
499 Bitmap *LoadImage(char *);
500 Bitmap *LoadCustomImage(char *);
501 void ReloadCustomImage(Bitmap *, char *);
503 inline void OpenAudio(void);
504 inline void CloseAudio(void);
505 inline void SetAudioMode(boolean);
507 inline void InitEventFilter(EventFilter);
508 inline boolean PendingEvent(void);
509 inline void NextEvent(Event *event);
510 inline Key GetEventKey(KeyEvent *, boolean);
511 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
513 inline void InitJoysticks();
514 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
516 #endif /* SYSTEM_H */