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 #define DEFAULT_KEY_SNAP KSYM_Shift_L
55 #define DEFAULT_KEY_BOMB KSYM_Shift_R
56 #define DEFAULT_KEY_OKAY KSYM_Return
57 #define DEFAULT_KEY_CANCEL KSYM_Escape
59 /* default shortcut keys */
60 #define DEFAULT_KEY_SAVE_GAME KSYM_F1
61 #define DEFAULT_KEY_LOAD_GAME KSYM_F2
62 #define DEFAULT_KEY_TOGGLE_PAUSE KSYM_space
64 /* values for move directions and special "button" keys */
65 #define MV_NO_MOVING 0
66 #define MV_LEFT (1 << 0)
67 #define MV_RIGHT (1 << 1)
68 #define MV_UP (1 << 2)
69 #define MV_DOWN (1 << 3)
70 #define KEY_BUTTON_1 (1 << 4)
71 #define KEY_BUTTON_2 (1 << 5)
72 #define KEY_MOTION (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)
73 #define KEY_BUTTON (KEY_BUTTON_1 | KEY_BUTTON_2)
74 #define KEY_ACTION (KEY_MOTION | KEY_BUTTON)
76 /* values for button status */
77 #define MB_NOT_PRESSED FALSE
78 #define MB_NOT_RELEASED TRUE
79 #define MB_RELEASED FALSE
80 #define MB_PRESSED TRUE
81 #define MB_MENU_CHOICE FALSE
82 #define MB_MENU_MARK TRUE
83 #define MB_MENU_INITIALIZE (-1)
84 #define MB_MENU_LEAVE (-2)
85 #define MB_LEFTBUTTON 1
86 #define MB_MIDDLEBUTTON 2
87 #define MB_RIGHTBUTTON 3
89 /* values for redraw_mask */
90 #define REDRAW_NONE (0)
91 #define REDRAW_ALL (1 << 0)
92 #define REDRAW_FIELD (1 << 1)
93 #define REDRAW_TILES (1 << 2)
94 #define REDRAW_DOOR_1 (1 << 3)
95 #define REDRAW_VIDEO_1 (1 << 4)
96 #define REDRAW_VIDEO_2 (1 << 5)
97 #define REDRAW_VIDEO_3 (1 << 6)
98 #define REDRAW_MICROLEVEL (1 << 7)
99 #define REDRAW_MICROLABEL (1 << 8)
100 #define REDRAW_FROM_BACKBUFFER (1 << 9)
101 #define REDRAW_DOOR_2 (REDRAW_VIDEO_1 | \
104 #define REDRAW_DOOR_3 (1 << 10)
105 #define REDRAW_DOORS (REDRAW_DOOR_1 | \
108 #define REDRAW_MAIN (REDRAW_FIELD | \
111 #define REDRAW_FPS (1 << 11)
112 #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2)
114 /* maximum number of parallel players supported by libgame functions */
115 #define MAX_PLAYERS 4
117 /* maximum allowed length of player name */
118 #define MAX_PLAYER_NAME_LEN 10
120 /* default name for empty highscore entry */
121 #define EMPTY_PLAYER_NAME "no name"
123 /* default name for unknown player names */
124 #define ANONYMOUS_NAME "anonymous"
126 /* default text for non-existant artwork */
127 #define NOT_AVAILABLE "(not available)"
129 /* default name for new levels */
130 #define NAMELESS_LEVEL_NAME "nameless level"
132 /* definitions for game sub-directories */
134 #define RO_GAME_DIR "."
138 #define RW_GAME_DIR "."
141 #define RO_BASE_PATH RO_GAME_DIR
142 #define RW_BASE_PATH RW_GAME_DIR
144 #define GRAPHICS_DIRECTORY "graphics"
145 #define SOUNDS_DIRECTORY "sounds"
146 #define MUSIC_DIRECTORY "music"
147 #define LEVELS_DIRECTORY "levels"
148 #define TAPES_DIRECTORY "tapes"
149 #define SCORES_DIRECTORY "scores"
151 #if !defined(PLATFORM_MSDOS)
152 #define GRAPHICS_SUBDIR "gfx_classic"
153 #define SOUNDS_SUBDIR "snd_classic"
154 #define MUSIC_SUBDIR "mus_classic"
156 #define GRAPHICS_SUBDIR "gfx_orig"
157 #define SOUNDS_SUBDIR "snd_orig"
158 #define MUSIC_SUBDIR "mus_orig"
161 /* areas in bitmap PIX_DOOR */
162 /* meaning in PIX_DB_DOOR: (3 PAGEs)
163 PAGEX1: 1. buffer for DOOR_1
164 PAGEX2: 2. buffer for DOOR_1
165 PAGEX3: buffer for animations
168 #define DOOR_GFX_PAGESIZE (gfx.dxsize)
169 #define DOOR_GFX_PAGEX1 (0 * DOOR_GFX_PAGESIZE)
170 #define DOOR_GFX_PAGEX2 (1 * DOOR_GFX_PAGESIZE)
171 #define DOOR_GFX_PAGEX3 (2 * DOOR_GFX_PAGESIZE)
172 #define DOOR_GFX_PAGEX4 (3 * DOOR_GFX_PAGESIZE)
173 #define DOOR_GFX_PAGEX5 (4 * DOOR_GFX_PAGESIZE)
174 #define DOOR_GFX_PAGEX6 (5 * DOOR_GFX_PAGESIZE)
175 #define DOOR_GFX_PAGEX7 (6 * DOOR_GFX_PAGESIZE)
176 #define DOOR_GFX_PAGEX8 (7 * DOOR_GFX_PAGESIZE)
177 #define DOOR_GFX_PAGEY1 (0)
178 #define DOOR_GFX_PAGEY2 (gfx.dysize)
180 /* functions for version handling */
181 #define VERSION_IDENT(x,y,z) ((x) * 10000 + (y) * 100 + (z))
182 #define VERSION_MAJOR(x) ((x) / 10000)
183 #define VERSION_MINOR(x) (((x) % 10000) / 100)
184 #define VERSION_PATCH(x) ((x) % 100)
186 /* functions for parent/child process identification */
187 #define IS_PARENT_PROCESS(pid) ((pid) > 0)
188 #define IS_CHILD_PROCESS(pid) ((pid) == 0)
191 /* type definitions */
192 typedef int (*EventFilter)(const Event *);
195 /* structure definitions */
199 char *command_basename;
200 char *userdata_directory;
206 char *x11_icon_filename;
207 char *x11_iconmask_filename;
208 char *msdos_pointer_filename;
211 char *filename_prefix; /* prefix to cut off from DOS filenames */
217 void (*exit_function)(int);
225 char *ro_base_directory;
226 char *rw_base_directory;
227 char *level_directory;
228 char *graphics_directory;
229 char *sounds_directory;
230 char *music_directory;
238 struct VideoSystemInfo
241 int width, height, depth;
242 boolean fullscreen_available;
243 boolean fullscreen_enabled;
246 struct AudioSystemInfo
248 boolean sound_available;
249 boolean loops_available;
250 boolean music_available;
252 boolean sound_enabled;
253 boolean sound_deactivated; /* for temporarily disabling sound */
262 int first_sound_channel;
269 int real_sx, real_sy;
270 int full_sxsize, full_sysize;
271 int scrollbuffer_width, scrollbuffer_height;
279 boolean draw_deactivation_mask;
285 int fd[MAX_PLAYERS]; /* file descriptor of player's joystick */
288 struct SetupJoystickInfo
290 char *device_name; /* device name of player's joystick */
292 int xleft, xmiddle, xright;
293 int yupper, ymiddle, ylower;
298 struct SetupKeyboardInfo
308 struct SetupInputInfo
310 boolean use_joystick;
311 struct SetupJoystickInfo joy;
312 struct SetupKeyboardInfo key;
315 struct SetupShortcutInfo
329 boolean sound_simple;
331 boolean double_buffering;
332 boolean direct_draw; /* !double_buffering (redundant!) */
333 boolean scroll_delay;
334 boolean soft_scrolling;
342 boolean ask_on_escape;
347 boolean override_level_graphics;
348 boolean override_level_sounds;
349 boolean override_level_music;
351 struct SetupShortcutInfo shortcut;
352 struct SetupInputInfo input[MAX_PLAYERS];
355 #define TREE_TYPE_GENERIC 0
356 #define TREE_TYPE_LEVEL_DIR 1
357 #define TREE_TYPE_GRAPHICS_DIR 2
358 #define TREE_TYPE_SOUNDS_DIR 3
359 #define TREE_TYPE_MUSIC_DIR 4
363 struct TreeInfo **node_top; /* topmost node in tree */
364 struct TreeInfo *node_parent; /* parent level directory info */
365 struct TreeInfo *node_group; /* level group sub-directory info */
366 struct TreeInfo *next; /* next level series structure node */
368 int cl_first; /* internal control field for setup screen */
369 int cl_cursor; /* internal control field for setup screen */
371 int type; /* type of tree content */
373 /* fields for "type == TREE_TYPE_LEVEL_DIR" */
375 char *filename; /* level series single directory name */
376 char *fullpath; /* complete path relative to level directory */
377 char *basepath; /* absolute base path of level directory */
378 char *name; /* level series name, as displayed on main screen */
379 char *name_short; /* optional short name for level selection screen */
380 char *name_sorting; /* optional sorting name for correct level sorting */
381 char *author; /* level series author name levels without author */
382 char *imported_from; /* optional comment for imported level series */
383 int levels; /* number of levels in level series */
384 int first_level; /* first level number (to allow start with 0 or 1) */
385 int last_level; /* last level number (automatically calculated) */
386 int sort_priority; /* sort levels by 'sort_priority' and then by name */
387 boolean level_group; /* directory contains more level series directories */
388 boolean parent_link; /* entry links back to parent directory */
389 boolean user_defined; /* user defined levels are stored in home directory */
390 boolean readonly; /* readonly levels can not be changed with editor */
391 int color; /* color to use on selection screen for this level */
392 char *class_desc; /* description of level series class */
393 int handicap_level; /* number of the lowest unsolved level */
396 typedef struct TreeInfo TreeInfo;
397 typedef struct TreeInfo LevelDirTree;
398 typedef struct TreeInfo ArtworkDirTree;
399 typedef struct TreeInfo GraphicsDirTree;
400 typedef struct TreeInfo SoundsDirTree;
401 typedef struct TreeInfo MusicDirTree;
405 GraphicsDirTree *gfx_first;
406 GraphicsDirTree *gfx_current;
407 SoundsDirTree *snd_first;
408 SoundsDirTree *snd_current;
409 MusicDirTree *mus_first;
410 MusicDirTree *mus_current;
412 char *graphics_set_current_name;
413 char *sounds_set_current_name;
414 char *music_set_current_name;
418 /* ========================================================================= */
419 /* exported variables */
420 /* ========================================================================= */
422 extern struct ProgramInfo program;
423 extern struct OptionInfo options;
424 extern struct VideoSystemInfo video;
425 extern struct AudioSystemInfo audio;
426 extern struct GfxInfo gfx;
427 extern struct ArtworkInfo artwork;
428 extern struct JoystickInfo joystick;
429 extern struct SetupInfo setup;
431 extern LevelDirTree *leveldir_first;
432 extern LevelDirTree *leveldir_current;
435 extern Display *display;
436 extern Visual *visual;
438 extern Colormap cmap;
440 extern DrawWindow *window;
441 extern DrawBuffer *backbuffer;
442 extern DrawBuffer *drawto;
444 extern int button_status;
445 extern boolean motion_status;
447 extern int redraw_mask;
448 extern int redraw_tiles;
450 extern int FrameCounter;
453 /* function definitions */
455 void InitCommandName(char *);
456 void InitExitFunction(void (*exit_function)(int));
457 void InitPlatformDependantStuff(void);
458 void ClosePlatformDependantStuff(void);
460 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
461 char *, char *, int);
463 void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
464 void InitGfxDoor1Info(int, int, int, int);
465 void InitGfxDoor2Info(int, int, int, int);
466 void InitGfxScrollbufferInfo(int, int);
467 void SetDrawDeactivationMask(int );
469 inline void InitVideoDisplay(void);
470 inline void CloseVideoDisplay(void);
471 inline void InitVideoBuffer(DrawBuffer **,DrawWindow **, int,int,int, boolean);
472 inline Bitmap *CreateBitmapStruct(void);
473 inline Bitmap *CreateBitmap(int, int, int);
474 inline void FreeBitmap(Bitmap *);
475 inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
476 inline void ClearRectangle(Bitmap *, int, int, int, int);
477 inline void SetClipMask(Bitmap *, GC, Pixmap);
478 inline void SetClipOrigin(Bitmap *, GC, int, int);
479 inline void BlitBitmapMasked(Bitmap *, Bitmap *, int, int, int, int, int, int);
480 inline void DrawSimpleWhiteLine(Bitmap *, int, int, int, int);
481 inline void DrawLines(Bitmap *, struct XY *, int, Pixel);
482 inline Pixel GetPixel(Bitmap *, int, int);
483 inline Pixel GetPixelFromRGB(Bitmap *, unsigned int,unsigned int,unsigned int);
484 inline Pixel GetPixelFromRGBcompact(Bitmap *, unsigned int);
486 inline void FlushDisplay(void);
487 inline void SyncDisplay(void);
488 inline void KeyboardAutoRepeatOn(void);
489 inline void KeyboardAutoRepeatOff(void);
490 inline boolean PointerInWindow(DrawWindow *);
491 inline boolean SetVideoMode(boolean);
492 inline boolean ChangeVideoModeIfNeeded(boolean);
494 Bitmap *LoadImage(char *);
495 Bitmap *LoadCustomImage(char *);
496 void ReloadCustomImage(Bitmap *, char *);
498 inline void OpenAudio(void);
499 inline void CloseAudio(void);
500 inline void SetAudioMode(boolean);
502 inline void InitEventFilter(EventFilter);
503 inline boolean PendingEvent(void);
504 inline void NextEvent(Event *event);
505 inline Key GetEventKey(KeyEvent *, boolean);
506 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
508 inline void InitJoysticks();
509 inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
511 #endif /* SYSTEM_H */