rnd-20001125-3-src
[rocksndiamonds.git] / src / sdl.c
index 85a2760be1e96624810a4a8d9bef95f1b3cfc66b..ddf1137deca11805b06f36b10306a2a4e09b5a66 100644 (file)
--- a/src/sdl.c
+++ b/src/sdl.c
@@ -12,7 +12,7 @@
 *  sdl.c                                                   *
 ***********************************************************/
 
-#ifdef USE_SDL_LIBRARY
+#ifdef TARGET_SDL
 
 #include "main.h"
 #include "misc.h"
@@ -27,14 +27,13 @@ inline void SDLInitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
   atexit(SDL_Quit);
 
   /* open SDL video output device (window or fullscreen mode) */
-  if (!SDLSetVideoMode(backbuffer, window))
+  if (!SDLSetVideoMode(backbuffer))
     Error(ERR_EXIT, "setting video mode failed");
 
   /* set window and icon title */
   SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
 
   /* create additional buffer for double-buffering */
-
   pix[PIX_DB_BACK] = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
 
   /* SDL cannot directly draw to the visible video framebuffer like X11,
@@ -54,7 +53,7 @@ inline void SDLInitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
   pix[PIX_DB_BACK] = *backbuffer;      /* 'backbuffer' is SDL screen buffer */
 }
 
-inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, DrawWindow *window)
+inline boolean SDLSetVideoMode(DrawBuffer *backbuffer)
 {
   boolean success = TRUE;
 
@@ -184,4 +183,24 @@ inline void SDLDrawSimpleLine(SDL_Surface *surface, int from_x, int from_y,
                SDL_MapRGB(surface->format, color_r, color_g, color_b));
 }
 
-#endif /* USE_SDL_LIBRARY */
+inline boolean SDLInitAudio(void)
+{
+  if (SDL_Init(SDL_INIT_AUDIO) < 0)
+  {
+    Error(ERR_WARN, "SDL_Init() failed: %s", SDL_GetError());
+    return FALSE;
+  }
+
+  if (Mix_OpenAudio(22050, AUDIO_S16, 2, 512) < 0)
+  {
+    Error(ERR_WARN, "Mix_OpenAudio() failed: %s", SDL_GetError());
+    return FALSE;
+  }
+
+  Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
+  Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
+
+  return TRUE;
+}
+
+#endif /* TARGET_SDL */