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 ***********************************************************/
19 #if defined(PLATFORM_MSDOS)
30 /* ========================================================================= */
31 /* exported variables */
32 /* ========================================================================= */
34 struct ProgramInfo program;
35 struct OptionInfo options;
36 struct VideoSystemInfo video;
37 struct AudioSystemInfo audio;
39 struct ArtworkInfo artwork;
40 struct JoystickInfo joystick;
41 struct SetupInfo setup;
43 LevelDirTree *leveldir_first = NULL;
44 LevelDirTree *leveldir_current = NULL;
47 Display *display = NULL;
48 Visual *visual = NULL;
52 DrawWindow *window = NULL;
53 DrawBuffer *backbuffer = NULL;
54 DrawBuffer *drawto = NULL;
56 int button_status = MB_NOT_PRESSED;
57 boolean motion_status = FALSE;
59 int redraw_mask = REDRAW_NONE;
65 /* ========================================================================= */
66 /* init/close functions */
67 /* ========================================================================= */
69 void InitCommandName(char *argv0)
71 program.command_basename =
72 (strrchr(argv0, '/') ? strrchr(argv0, '/') + 1 : argv0);
75 void InitExitFunction(void (*exit_function)(int))
77 program.exit_function = exit_function;
79 /* set signal handlers to custom exit function */
80 signal(SIGINT, exit_function);
81 signal(SIGTERM, exit_function);
83 #if defined(TARGET_SDL)
84 /* set exit function to automatically cleanup SDL stuff after exit() */
89 void InitPlatformDependantStuff(void)
91 #if defined(PLATFORM_MSDOS)
95 #if !defined(PLATFORM_UNIX)
96 program.userdata_directory = "userdata";
99 #if defined(PLATFORM_MSDOS)
103 #if defined(TARGET_SDL)
104 if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0)
105 Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
109 void ClosePlatformDependantStuff(void)
111 #if defined(PLATFORM_MSDOS)
116 void InitProgramInfo(char *unix_userdata_directory, char *program_title,
117 char *window_title, char *icon_title,
118 char *x11_icon_filename, char *x11_iconmask_filename,
119 char *msdos_pointer_filename,
120 char *cookie_prefix, char *filename_prefix,
123 #if defined(PLATFORM_UNIX)
124 program.userdata_directory = unix_userdata_directory;
126 program.userdata_directory = "userdata";
129 program.program_title = program_title;
130 program.window_title = window_title;
131 program.icon_title = icon_title;
132 program.x11_icon_filename = x11_icon_filename;
133 program.x11_iconmask_filename = x11_iconmask_filename;
134 program.msdos_pointer_filename = msdos_pointer_filename;
136 program.cookie_prefix = cookie_prefix;
137 program.filename_prefix = filename_prefix;
139 program.version_major = VERSION_MAJOR(program_version);
140 program.version_minor = VERSION_MINOR(program_version);
141 program.version_patch = VERSION_PATCH(program_version);
144 void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
145 int real_sx, int real_sy,
146 int full_sxsize, int full_sysize)
152 gfx.real_sx = real_sx;
153 gfx.real_sy = real_sy;
154 gfx.full_sxsize = full_sxsize;
155 gfx.full_sysize = full_sysize;
157 gfx.background_bitmap = NULL;
158 gfx.background_bitmap_mask = REDRAW_NONE;
160 SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */
161 SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */
164 void InitGfxDoor1Info(int dx, int dy, int dxsize, int dysize)
172 void InitGfxDoor2Info(int vx, int vy, int vxsize, int vysize)
180 void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height)
182 /* currently only used by MSDOS code to alloc VRAM buffer, if available */
183 gfx.scrollbuffer_width = scrollbuffer_width;
184 gfx.scrollbuffer_height = scrollbuffer_height;
187 void SetDrawDeactivationMask(int draw_deactivation_mask)
189 gfx.draw_deactivation_mask = draw_deactivation_mask;
192 void SetDrawBackgroundMask(int draw_background_mask)
194 gfx.draw_background_mask = draw_background_mask;
197 static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile,
198 int dest_x, int dest_y, int width, int height)
200 int bitmap_xsize = width;
201 int bitmap_ysize = height;
202 int tile_xsize = tile->width;
203 int tile_ysize = tile->height;
204 int tile_xsteps = (bitmap_xsize + tile_xsize - 1) / tile_xsize;
205 int tile_ysteps = (bitmap_ysize + tile_ysize - 1) / tile_ysize;
208 for (y=0; y < tile_ysteps; y++)
210 for (x=0; x < tile_xsteps; x++)
212 int draw_x = dest_x + x * tile_xsize;
213 int draw_y = dest_y + y * tile_ysize;
214 int draw_xsize = MIN(tile_xsize, bitmap_xsize - x * tile_xsize);
215 int draw_ysize = MIN(tile_ysize, bitmap_ysize - y * tile_ysize);
217 BlitBitmap(tile, bitmap, 0, 0, draw_xsize, draw_ysize, draw_x, draw_y);
222 void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask)
224 static Bitmap *main_bitmap_tile = NULL;
225 static Bitmap *door_bitmap_tile = NULL;
227 if (mask == REDRAW_FIELD)
229 if (background_bitmap_tile == main_bitmap_tile)
230 return; /* main background tile has not changed */
232 main_bitmap_tile = background_bitmap_tile;
234 else if (mask == REDRAW_DOOR_1)
236 if (background_bitmap_tile == door_bitmap_tile)
237 return; /* main background tile has not changed */
239 door_bitmap_tile = background_bitmap_tile;
241 else /* should not happen */
244 if (background_bitmap_tile)
245 gfx.background_bitmap_mask |= mask;
247 gfx.background_bitmap_mask &= ~mask;
249 if (gfx.background_bitmap == NULL)
250 gfx.background_bitmap = CreateBitmap(video.width, video.height,
253 if (background_bitmap_tile == NULL) /* empty background requested */
256 if (mask == REDRAW_FIELD)
257 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
258 gfx.real_sx, gfx.real_sy,
259 gfx.full_sxsize, gfx.full_sysize);
261 DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile,
263 gfx.dxsize, gfx.dysize);
266 void SetMainBackgroundBitmap(Bitmap *background_bitmap_tile)
268 SetBackgroundBitmap(background_bitmap_tile, REDRAW_FIELD);
271 void SetDoorBackgroundBitmap(Bitmap *background_bitmap_tile)
273 SetBackgroundBitmap(background_bitmap_tile, REDRAW_DOOR_1);
277 /* ========================================================================= */
278 /* video functions */
279 /* ========================================================================= */
281 inline static int GetRealDepth(int depth)
283 return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
286 inline void InitVideoDisplay(void)
288 #if defined(TARGET_SDL)
289 SDLInitVideoDisplay();
291 X11InitVideoDisplay();
295 inline void CloseVideoDisplay(void)
297 KeyboardAutoRepeatOn();
299 #if defined(TARGET_SDL)
300 SDL_QuitSubSystem(SDL_INIT_VIDEO);
304 XCloseDisplay(display);
308 inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window,
309 int width, int height, int depth,
313 video.height = height;
314 video.depth = GetRealDepth(depth);
315 video.fullscreen_available = FULLSCREEN_STATUS;
316 video.fullscreen_enabled = FALSE;
319 SDLInitVideoBuffer(backbuffer, window, fullscreen);
321 X11InitVideoBuffer(backbuffer, window);
325 inline Bitmap *CreateBitmapStruct(void)
328 return checked_calloc(sizeof(struct SDLSurfaceInfo));
330 return checked_calloc(sizeof(struct X11DrawableInfo));
334 inline Bitmap *CreateBitmap(int width, int height, int depth)
336 Bitmap *new_bitmap = CreateBitmapStruct();
337 int real_depth = GetRealDepth(depth);
340 SDL_Surface *surface_tmp, *surface_native;
342 if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height,
343 real_depth, 0, 0, 0, 0))
345 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
347 if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL)
348 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
350 SDL_FreeSurface(surface_tmp);
352 new_bitmap->surface = surface_native;
356 if ((pixmap = XCreatePixmap(display, window->drawable,
357 width, height, real_depth))
359 Error(ERR_EXIT, "cannot create pixmap");
361 new_bitmap->drawable = pixmap;
364 Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first");
366 new_bitmap->gc = window->gc;
368 new_bitmap->line_gc[0] = window->line_gc[0];
369 new_bitmap->line_gc[1] = window->line_gc[1];
372 new_bitmap->width = width;
373 new_bitmap->height = height;
378 inline static void FreeBitmapPointers(Bitmap *bitmap)
385 SDL_FreeSurface(bitmap->surface);
386 if (bitmap->surface_masked)
387 SDL_FreeSurface(bitmap->surface_masked);
388 bitmap->surface = NULL;
389 bitmap->surface_masked = NULL;
391 /* The X11 version seems to have a memory leak here -- although
392 "XFreePixmap()" is called, the corresponding memory seems not
393 to be freed (according to "ps"). The SDL version apparently
394 does not have this problem. */
396 if (bitmap->drawable)
397 XFreePixmap(display, bitmap->drawable);
398 if (bitmap->clip_mask)
399 XFreePixmap(display, bitmap->clip_mask);
400 if (bitmap->stored_clip_gc)
401 XFreeGC(display, bitmap->stored_clip_gc);
402 /* the other GCs are only pointers to GCs used elsewhere */
403 bitmap->drawable = None;
404 bitmap->clip_mask = None;
405 bitmap->stored_clip_gc = None;
408 if (bitmap->source_filename)
409 free(bitmap->source_filename);
410 bitmap->source_filename = NULL;
413 inline static void TransferBitmapPointers(Bitmap *src_bitmap,
416 if (src_bitmap == NULL || dst_bitmap == NULL)
419 FreeBitmapPointers(dst_bitmap);
421 *dst_bitmap = *src_bitmap;
424 inline void FreeBitmap(Bitmap *bitmap)
429 FreeBitmapPointers(bitmap);
434 inline void CloseWindow(DrawWindow *window)
437 if (window->drawable)
439 XUnmapWindow(display, window->drawable);
440 XDestroyWindow(display, window->drawable);
443 XFreeGC(display, window->gc);
447 static inline boolean CheckDrawingArea(int x, int y, int width, int height,
450 if (draw_mask == REDRAW_NONE)
453 if (draw_mask & REDRAW_ALL)
456 if ((draw_mask & REDRAW_FIELD) && x < gfx.real_sx + gfx.full_sxsize)
459 if ((draw_mask & REDRAW_DOOR_1) && x >= gfx.dx && y < gfx.dy + gfx.dysize)
462 if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy)
468 inline boolean DrawingDeactivated(int x, int y, int width, int height)
470 return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
473 inline boolean DrawingOnBackground(int x, int y)
475 return ((gfx.draw_background_mask & gfx.background_bitmap_mask) &&
476 CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
479 inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
480 int src_x, int src_y,
481 int width, int height,
482 int dst_x, int dst_y)
484 if (DrawingDeactivated(dst_x, dst_y, width, height))
488 SDLCopyArea(src_bitmap, dst_bitmap,
489 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_OPAQUE);
491 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
492 dst_bitmap->gc, src_x, src_y, width, height, dst_x, dst_y);
496 inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
498 if (DrawingDeactivated(x, y, width, height))
502 SDLFillRectangle(bitmap, x, y, width, height, 0x000000);
504 XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height);
508 inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
509 int width, int height)
511 if (DrawingOnBackground(x, y))
512 BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
514 ClearRectangle(bitmap, x, y, width, height);
519 static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */
523 inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap)
528 bitmap->clip_gc = clip_gc;
529 XSetClipMask(display, bitmap->clip_gc, clip_pixmap);
532 last_clip_gc = clip_gc;
537 inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y)
542 bitmap->clip_gc = clip_gc;
543 XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y);
546 last_clip_gc = clip_gc;
551 inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
552 int src_x, int src_y,
553 int width, int height,
554 int dst_x, int dst_y)
556 if (DrawingDeactivated(dst_x, dst_y, width, height))
560 SDLCopyArea(src_bitmap, dst_bitmap,
561 src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_MASKED);
563 XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable,
564 src_bitmap->clip_gc, src_x, src_y, width, height, dst_x, dst_y);
568 inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
569 int src_x, int src_y,
570 int width, int height,
571 int dst_x, int dst_y)
573 if (DrawingOnBackground(dst_x, dst_y))
575 /* draw background */
576 BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
579 /* draw foreground */
580 SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc,
581 dst_x - src_x, dst_y - src_y);
582 BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
586 BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
590 inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
594 SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff);
596 XSetForeground(display, bitmap->gc, WhitePixel(display, screen));
597 XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y);
598 XSetForeground(display, bitmap->gc, BlackPixel(display, screen));
602 #if !defined(TARGET_X11_NATIVE)
603 inline void DrawLine(Bitmap *bitmap, int from_x, int from_y,
604 int to_x, int to_y, Pixel pixel, int line_width)
608 for (x=0; x<line_width; x++)
610 for (y=0; y<line_width; y++)
612 int dx = x - line_width / 2;
613 int dy = y - line_width / 2;
615 if ((x == 0 && y == 0) ||
616 (x == 0 && y == line_width - 1) ||
617 (x == line_width - 1 && y == 0) ||
618 (x == line_width - 1 && y == line_width - 1))
621 #if defined(TARGET_SDL)
623 from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
624 #elif defined(TARGET_ALLEGRO)
625 AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy,
626 to_x + dx, to_y + dy, pixel);
633 inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points,
636 #if !defined(TARGET_X11_NATIVE)
640 for (i=0; i<num_points - 1; i++)
641 DrawLine(bitmap, points[i].x, points[i].y,
642 points[i + 1].x, points[i + 1].y, pixel, line_width);
645 SDLDrawLines(bitmap->surface, points, num_points, pixel);
648 XSetForeground(display, bitmap->line_gc[1], pixel);
649 XDrawLines(display, bitmap->drawable, bitmap->line_gc[1],
650 (XPoint *)points, num_points, CoordModeOrigin);
652 XSetForeground(display, gc, BlackPixel(display, screen));
657 inline Pixel GetPixel(Bitmap *bitmap, int x, int y)
659 #if defined(TARGET_SDL)
660 return SDLGetPixel(bitmap, x, y);
661 #elif defined(TARGET_ALLEGRO)
662 return AllegroGetPixel(bitmap->drawable, x, y);
664 unsigned long pixel_value;
667 pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1,
669 pixel_value = XGetPixel(pixel_image, 0, 0);
671 XDestroyImage(pixel_image);
677 inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
678 unsigned int color_g, unsigned int color_b)
682 #if defined(TARGET_SDL)
683 pixel = SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
684 #elif defined(TARGET_ALLEGRO)
685 pixel = AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8);
686 #elif defined(TARGET_X11_NATIVE)
689 xcolor.flags = DoRed | DoGreen | DoBlue;
690 xcolor.red = (color_r << 8);
691 xcolor.green = (color_g << 8);
692 xcolor.blue = (color_b << 8);
693 XAllocColor(display, cmap, &xcolor);
694 pixel = xcolor.pixel;
700 inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
702 unsigned int color_r = (color >> 16) & 0xff;
703 unsigned int color_g = (color >> 8) & 0xff;
704 unsigned int color_b = (color >> 0) & 0xff;
706 return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
709 /* execute all pending screen drawing operations */
710 inline void FlushDisplay(void)
717 /* execute and wait for all pending screen drawing operations */
718 inline void SyncDisplay(void)
721 XSync(display, FALSE);
725 inline void KeyboardAutoRepeatOn(void)
728 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
729 SDL_DEFAULT_REPEAT_INTERVAL / 2);
730 SDL_EnableUNICODE(1);
733 XAutoRepeatOn(display);
737 inline void KeyboardAutoRepeatOff(void)
740 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
741 SDL_EnableUNICODE(0);
744 XAutoRepeatOff(display);
748 inline boolean PointerInWindow(DrawWindow *window)
758 /* if XQueryPointer() returns False, the pointer
759 is not on the same screen as the specified window */
760 return XQueryPointer(display, window->drawable, &root, &child,
761 &root_x, &root_y, &win_x, &win_y, &mask);
765 inline boolean SetVideoMode(boolean fullscreen)
768 return SDLSetVideoMode(&backbuffer, fullscreen);
770 boolean success = TRUE;
772 if (fullscreen && video.fullscreen_available)
774 Error(ERR_WARN, "fullscreen not available in X11 version");
776 /* display error message only once */
777 video.fullscreen_available = FALSE;
786 inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
789 if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)||
790 (!fullscreen && video.fullscreen_enabled))
791 fullscreen = SetVideoMode(fullscreen);
797 Bitmap *LoadImage(char *filename)
801 #if defined(TARGET_SDL)
802 new_bitmap = SDLLoadImage(filename);
804 new_bitmap = X11LoadImage(filename);
808 new_bitmap->source_filename = getStringCopy(filename);
813 Bitmap *LoadCustomImage(char *basename)
815 char *filename = getCustomImageFilename(basename);
818 if (filename == NULL)
819 Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
821 if ((new_bitmap = LoadImage(filename)) == NULL)
822 Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
827 void ReloadCustomImage(Bitmap *bitmap, char *basename)
829 char *filename = getCustomImageFilename(basename);
832 if (filename == NULL) /* (should never happen) */
834 Error(ERR_WARN, "ReloadCustomImage(): cannot find file '%s'", basename);
838 if (strcmp(filename, bitmap->source_filename) == 0)
840 /* The old and new image are the same (have the same filename and path).
841 This usually means that this image does not exist in this graphic set
842 and a fallback to the existing image is done. */
847 if ((new_bitmap = LoadImage(filename)) == NULL)
849 Error(ERR_WARN, "LoadImage() failed: %s", GetError());
853 if (bitmap->width != new_bitmap->width ||
854 bitmap->height != new_bitmap->height)
856 Error(ERR_WARN, "ReloadCustomImage: new image '%s' has wrong dimensions",
858 FreeBitmap(new_bitmap);
862 TransferBitmapPointers(new_bitmap, bitmap);
866 Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
868 Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH);
870 #if defined(TARGET_SDL)
871 SDLZoomBitmap(src_bitmap, dst_bitmap);
873 X11ZoomBitmap(src_bitmap, dst_bitmap);
879 void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap)
881 Bitmap *tmp_bitmap, *tmp_bitmap_2, *tmp_bitmap_8;
882 int src_width, src_height;
883 int tmp_width, tmp_height;
885 src_width = src_bitmap->width;
886 src_height = src_bitmap->height;
888 tmp_width = src_width;
889 tmp_height = src_height + src_height / 2;
891 tmp_bitmap = CreateBitmap(tmp_width, tmp_height, DEFAULT_DEPTH);
893 tmp_bitmap_2 = ZoomBitmap(src_bitmap, src_width / 2, src_height / 2);
894 tmp_bitmap_8 = ZoomBitmap(src_bitmap, src_width / 8, src_height / 8);
896 BlitBitmap(src_bitmap, tmp_bitmap, 0, 0, src_width, src_height, 0, 0);
897 BlitBitmap(tmp_bitmap_2, tmp_bitmap, 0, 0, src_width / 2, src_height / 2,
899 BlitBitmap(tmp_bitmap_8, tmp_bitmap, 0, 0, src_width / 8, src_height / 8,
900 3 * src_width / 4, src_height);
902 FreeBitmap(tmp_bitmap_2);
903 FreeBitmap(tmp_bitmap_8);
906 src_bitmap->surface = tmp_bitmap->surface;
907 tmp_bitmap->surface = NULL;
909 src_bitmap->drawable = tmp_bitmap->drawable;
910 tmp_bitmap->drawable = None;
913 src_bitmap->height = tmp_bitmap->height;
915 FreeBitmap(tmp_bitmap);
919 /* ========================================================================= */
920 /* audio functions */
921 /* ========================================================================= */
923 inline void OpenAudio(void)
925 /* always start with reliable default values */
926 audio.sound_available = FALSE;
927 audio.music_available = FALSE;
928 audio.loops_available = FALSE;
930 audio.sound_enabled = FALSE;
931 audio.sound_deactivated = FALSE;
933 audio.mixer_pipe[0] = audio.mixer_pipe[1] = 0;
935 audio.device_name = NULL;
936 audio.device_fd = -1;
938 audio.num_channels = 0;
939 audio.music_channel = 0;
940 audio.first_sound_channel = 0;
942 #if defined(TARGET_SDL)
944 #elif defined(PLATFORM_UNIX)
946 #elif defined(PLATFORM_MSDOS)
951 inline void CloseAudio(void)
953 #if defined(TARGET_SDL)
955 #elif defined(PLATFORM_UNIX)
957 #elif defined(PLATFORM_MSDOS)
961 audio.sound_enabled = FALSE;
964 inline void SetAudioMode(boolean enabled)
966 if (!audio.sound_available)
969 audio.sound_enabled = enabled;
973 /* ========================================================================= */
974 /* event functions */
975 /* ========================================================================= */
977 inline void InitEventFilter(EventFilter filter_function)
980 /* set event filter to filter out certain events */
981 SDL_SetEventFilter(filter_function);
985 inline boolean PendingEvent(void)
988 return (SDL_PollEvent(NULL) ? TRUE : FALSE);
990 return (XPending(display) ? TRUE : FALSE);
994 inline void NextEvent(Event *event)
999 XNextEvent(display, event);
1003 inline Key GetEventKey(KeyEvent *event, boolean with_modifiers)
1007 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n",
1008 (int)event->keysym.unicode,
1009 (int)event->keysym.sym,
1010 (int)SDL_GetModState());
1013 if (with_modifiers &&
1014 event->keysym.unicode > 0x0000 &&
1015 event->keysym.unicode < 0x2000)
1016 return event->keysym.unicode;
1018 return event->keysym.sym;
1021 printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n",
1022 (int)XLookupKeysym(event, event->state),
1023 (int)XLookupKeysym(event, 0));
1027 return XLookupKeysym(event, event->state);
1029 return XLookupKeysym(event, 0);
1033 inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
1035 if (event->type != EVENT_CLIENTMESSAGE)
1038 #if defined(TARGET_SDL)
1039 return TRUE; /* the only possible message here is SDL_QUIT */
1040 #elif defined(PLATFORM_UNIX)
1041 if ((event->window == window->drawable) &&
1042 (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
1050 /* ========================================================================= */
1051 /* joystick functions */
1052 /* ========================================================================= */
1054 inline void InitJoysticks()
1059 return; /* joysticks generally deactivated by compile-time directive */
1062 /* always start with reliable default values */
1063 joystick.status = JOYSTICK_NOT_AVAILABLE;
1064 for (i=0; i<MAX_PLAYERS; i++)
1065 joystick.fd[i] = -1; /* joystick device closed */
1067 #if defined(TARGET_SDL)
1069 #elif defined(PLATFORM_UNIX)
1070 UnixInitJoysticks();
1071 #elif defined(PLATFORM_MSDOS)
1072 MSDOSInitJoysticks();
1076 inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
1078 #if defined(TARGET_SDL)
1079 return SDLReadJoystick(nr, x, y, b1, b2);
1080 #elif defined(PLATFORM_UNIX)
1081 return UnixReadJoystick(nr, x, y, b1, b2);
1082 #elif defined(PLATFORM_MSDOS)
1083 return MSDOSReadJoystick(nr, x, y, b1, b2);