rnd-20001204-3-src
[rocksndiamonds.git] / src / libgame / system.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2000 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * system.h                                                 *
12 ***********************************************************/
13
14 #ifndef SYSTEM_H
15 #define SYSTEM_H
16
17 #include "platform.h"
18 #include "types.h"
19
20 #if defined(PLATFORM_MSDOS)
21 #include "msdos.h"
22 #endif
23
24 #if defined(TARGET_SDL)
25 #include "sdl.h"
26 #elif defined(TARGET_X11)
27 #include "x11.h"
28 #endif
29
30
31 /* contant definitions */
32
33 #define DEFAULT_DEPTH                   0
34
35 #define FULLSCREEN_NOT_AVAILABLE        FALSE
36 #define FULLSCREEN_AVAILABLE            TRUE
37
38 /* values for button_status */
39 #define MB_NOT_PRESSED          FALSE
40 #define MB_RELEASED             FALSE
41 #define MB_PRESSED              TRUE
42 #define MB_MENU_CHOICE          FALSE
43 #define MB_MENU_MARK            TRUE
44 #define MB_MENU_INITIALIZE      (-1)
45 #define MB_LEFTBUTTON           1
46 #define MB_MIDDLEBUTTON         2
47 #define MB_RIGHTBUTTON          3
48
49 /* values for redraw_mask */
50 #define REDRAW_NONE             (0)
51 #define REDRAW_ALL              (1 << 0)
52 #define REDRAW_FIELD            (1 << 1)
53 #define REDRAW_TILES            (1 << 2)
54 #define REDRAW_DOOR_1           (1 << 3)
55 #define REDRAW_VIDEO_1          (1 << 4)
56 #define REDRAW_VIDEO_2          (1 << 5)
57 #define REDRAW_VIDEO_3          (1 << 6)
58 #define REDRAW_MICROLEVEL       (1 << 7)
59 #define REDRAW_MICROLABEL       (1 << 8)
60 #define REDRAW_FROM_BACKBUFFER  (1 << 9)
61 #define REDRAW_DOOR_2           (REDRAW_VIDEO_1 | \
62                                  REDRAW_VIDEO_2 | \
63                                  REDRAW_VIDEO_3)
64 #define REDRAW_DOOR_3           (1 << 10)
65 #define REDRAW_DOORS            (REDRAW_DOOR_1 | \
66                                  REDRAW_DOOR_2 | \
67                                  REDRAW_DOOR_3)
68 #define REDRAW_MAIN             (REDRAW_FIELD | \
69                                  REDRAW_TILES | \
70                                  REDRAW_MICROLEVEL)
71 #define REDRAW_FPS              (1 << 11)
72 #define REDRAWTILES_THRESHOLD   (SCR_FIELDX * SCR_FIELDY / 2)
73
74
75 /* default name for empty highscore entry */
76 #define EMPTY_PLAYER_NAME       "no name"
77
78 /* default name for unknown player names */
79 #define ANONYMOUS_NAME          "anonymous"
80
81 /* default name for new levels */
82 #define NAMELESS_LEVEL_NAME     "nameless level"
83
84 /* definitions for game sub-directories */
85 #ifndef RO_GAME_DIR
86 #define RO_GAME_DIR             "."
87 #endif
88
89 #ifndef RW_GAME_DIR
90 #define RW_GAME_DIR             "."
91 #endif
92
93 #define RO_BASE_PATH            RO_GAME_DIR
94 #define RW_BASE_PATH            RW_GAME_DIR
95
96 #define GRAPHICS_DIRECTORY      "graphics"
97 #define SOUNDS_DIRECTORY        "sounds"
98 #define LEVELS_DIRECTORY        "levels"
99 #define TAPES_DIRECTORY         "tapes"
100 #define SCORES_DIRECTORY        "scores"
101
102 /* areas in bitmap PIX_DOOR */
103 /* meaning in PIX_DB_DOOR: (3 PAGEs)
104    PAGEX1: 1. buffer for DOOR_1
105    PAGEX2: 2. buffer for DOOR_1
106    PAGEX3: buffer for animations
107 */
108
109 #define DOOR_GFX_PAGESIZE       (gfx.dxsize)
110 #define DOOR_GFX_PAGEX1         (0 * DOOR_GFX_PAGESIZE)
111 #define DOOR_GFX_PAGEX2         (1 * DOOR_GFX_PAGESIZE)
112 #define DOOR_GFX_PAGEX3         (2 * DOOR_GFX_PAGESIZE)
113 #define DOOR_GFX_PAGEX4         (3 * DOOR_GFX_PAGESIZE)
114 #define DOOR_GFX_PAGEX5         (4 * DOOR_GFX_PAGESIZE)
115 #define DOOR_GFX_PAGEX6         (5 * DOOR_GFX_PAGESIZE)
116 #define DOOR_GFX_PAGEX7         (6 * DOOR_GFX_PAGESIZE)
117 #define DOOR_GFX_PAGEX8         (7 * DOOR_GFX_PAGESIZE)
118 #define DOOR_GFX_PAGEY1         (0)
119 #define DOOR_GFX_PAGEY2         (gfx.dysize)
120
121
122 /* type definitions */
123
124 typedef int (*EventFilter)(const Event *);
125
126
127 /* structure definitions */
128
129 struct ProgramInfo
130 {
131   char *command_basename;
132   char *userdata_directory;
133
134   char *program_title;
135   char *window_title;
136   char *icon_title;
137   char *x11_icon_filename;
138   char *x11_iconmask_filename;
139   char *msdos_pointer_filename;
140
141   void (*exit_function)(int);
142 };
143
144 struct OptionInfo
145 {
146   char *display_name;
147   char *server_host;
148   int server_port;
149   char *ro_base_directory;
150   char *rw_base_directory;
151   char *level_directory;
152   boolean serveronly;
153   boolean network;
154   boolean verbose;
155   boolean debug;
156 };
157
158 struct VideoSystemInfo
159 {
160   int default_depth;
161   int width, height, depth;
162   boolean fullscreen_available;
163   boolean fullscreen_enabled;
164 };
165
166 struct AudioSystemInfo
167 {
168   boolean sound_available;
169   boolean loops_available;
170   boolean sound_enabled;
171   int soundserver_pipe[2];
172   int soundserver_pid;
173   char *device_name;
174   int device_fd;
175 };
176
177 struct GfxInfo
178 {
179   int sx, sy;
180   int sxsize, sysize;
181   int real_sx, real_sy;
182   int full_sxsize, full_sysize;
183   int scrollbuffer_width, scrollbuffer_height;
184
185   int dx, dy;
186   int dxsize, dysize;
187
188   int vx, vy;
189   int vxsize, vysize;
190 };
191
192 struct LevelDirInfo
193 {
194   char *filename;       /* level series single directory name */
195   char *fullpath;       /* complete path relative to level directory */
196   char *basepath;       /* absolute base path of level directory */
197   char *name;           /* level series name, as displayed on main screen */
198   char *name_short;     /* optional short name for level selection screen */
199   char *name_sorting;   /* optional sorting name for correct level sorting */
200   char *author;         /* level series author name levels without author */
201   char *imported_from;  /* optional comment for imported level series */
202   int levels;           /* number of levels in level series */
203   int first_level;      /* first level number (to allow start with 0 or 1) */
204   int last_level;       /* last level number (automatically calculated) */
205   int sort_priority;    /* sort levels by 'sort_priority' and then by name */
206   boolean level_group;  /* directory contains more level series directories */
207   boolean parent_link;  /* entry links back to parent directory */
208   boolean user_defined; /* user defined levels are stored in home directory */
209   boolean readonly;     /* readonly levels can not be changed with editor */
210   int color;            /* color to use on selection screen for this level */
211   char *class_desc;     /* description of level series class */
212   int handicap_level;   /* number of the lowest unsolved level */
213   int cl_first;         /* internal control field for "choose level" screen */
214   int cl_cursor;        /* internal control field for "choose level" screen */
215
216   struct LevelDirInfo *node_parent;     /* parent level directory info */
217   struct LevelDirInfo *node_group;      /* level group sub-directory info */
218   struct LevelDirInfo *next;            /* next level series structure node */
219 };
220
221
222 /* ========================================================================= */
223 /* exported variables                                                        */
224 /* ========================================================================= */
225
226 extern struct ProgramInfo       program;
227 extern struct OptionInfo        options;
228 extern struct VideoSystemInfo   video;
229 extern struct AudioSystemInfo   audio;
230 extern struct GfxInfo           gfx;
231
232 extern struct LevelDirInfo     *leveldir_first;
233 extern struct LevelDirInfo     *leveldir_current;
234
235 extern Display         *display;
236 extern Visual          *visual;
237 extern int              screen;
238 extern Colormap         cmap;
239
240 extern DrawWindow       window;
241 extern DrawBuffer       backbuffer;
242 extern DrawBuffer       drawto;
243
244 extern int              button_status;
245 extern boolean          motion_status;
246
247 extern int              redraw_mask;
248 extern int              redraw_tiles;
249
250 extern int              FrameCounter;
251
252
253 /* function definitions */
254
255 void InitCommandName(char *);
256 void InitExitFunction(void (*exit_function)(int));
257 void InitPlatformDependantStuff(void);
258
259 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *);
260
261 void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
262 void InitGfxDoor1Info(int, int, int, int);
263 void InitGfxDoor2Info(int, int, int, int);
264 void InitGfxScrollbufferInfo(int, int);
265
266 inline void InitVideoDisplay(void);
267 inline void InitVideoBuffer(DrawBuffer *,DrawWindow *, int, int, int, boolean);
268 inline Bitmap CreateBitmapStruct(void);
269 inline Bitmap CreateBitmap(int, int, int);
270 inline void FreeBitmap(Bitmap);
271 inline void BlitBitmap(Bitmap, Bitmap, int, int, int, int, int, int);
272 inline void ClearRectangle(Bitmap, int, int, int, int);
273 inline void SetClipMask(Bitmap, GC, Pixmap);
274 inline void SetClipOrigin(Bitmap, GC, int, int);
275 inline void BlitBitmapMasked(Bitmap, Bitmap, int, int, int, int, int, int);
276 inline void DrawSimpleWhiteLine(Bitmap, int, int, int, int);
277 inline void DrawLines(Bitmap, struct XY *, int, Pixel);
278 inline Pixel GetPixelFromRGB(Bitmap, unsigned int, unsigned int, unsigned int);
279 inline Pixel GetPixelFromRGBcompact(Bitmap, unsigned int);
280
281 inline void FlushDisplay(void);
282 inline void SyncDisplay(void);
283 inline void KeyboardAutoRepeatOn(void);
284 inline void KeyboardAutoRepeatOff(void);
285 inline boolean PointerInWindow(DrawWindow);
286 inline boolean SetVideoMode(boolean);
287 inline boolean ChangeVideoModeIfNeeded(boolean);
288
289 inline boolean OpenAudio(struct AudioSystemInfo *);
290 inline void CloseAudio(struct AudioSystemInfo *);
291 inline void SetAudioMode(boolean);
292
293 inline void InitEventFilter(EventFilter);
294 inline boolean PendingEvent(void);
295 inline void NextEvent(Event *event);
296 inline Key GetEventKey(KeyEvent *, boolean);
297 inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
298
299 #endif /* SYSTEM_H */