X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=fed2a65e122f58ce3b70a59fbac3cff08e3e374e;hb=3d07b68a314ce189f207e42d95f786979662410d;hp=8e2ec948071686a17ba5f047c1edf16e28117bc0;hpb=da14f69fd95c7bd5a0d70cdf4935af06f1f20a04;p=rocksndiamonds.git diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 8e2ec948..fed2a65e 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -12,28 +12,34 @@ * sdl.c * ***********************************************************/ -#include "libgame.h" +#include "system.h" +#include "misc.h" -#ifdef TARGET_SDL -inline void SDLInitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window) +#if defined(TARGET_SDL) + +inline void SDLInitVideoDisplay(void) { /* initialize SDL video */ if (SDL_Init(SDL_INIT_VIDEO) < 0) Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError()); - /* automatically cleanup SDL stuff after exit() */ + /* set default SDL depth */ + video.default_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; + + /* set exit function to automatically cleanup SDL stuff after exit() */ atexit(SDL_Quit); +} +inline void SDLInitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window, + boolean fullscreen) +{ /* open SDL video output device (window or fullscreen mode) */ - if (!SDLSetVideoMode(backbuffer)) + if (!SDLSetVideoMode(backbuffer, fullscreen)) 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_WM_SetCaption(program.window_title, program.window_title); /* SDL cannot directly draw to the visible video framebuffer like X11, but always uses a backbuffer, which is then blitted to the visible @@ -48,22 +54,23 @@ inline void SDLInitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window) buffer 'window' at the same size as the SDL backbuffer. Although it should never be drawn to directly, it would do no harm nevertheless. */ - *window = pix[PIX_DB_BACK]; /* 'window' is only symbolic buffer */ - pix[PIX_DB_BACK] = *backbuffer; /* 'backbuffer' is SDL screen buffer */ + /* create additional (symbolic) buffer for double-buffering */ + *window = CreateBitmap(video.width, video.height, video.depth); } inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen) { boolean success = TRUE; + int surface_flags = SDL_HWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0); if (fullscreen && !video.fullscreen_enabled && video.fullscreen_available) { /* switch display to fullscreen mode, if available */ DrawWindow window_old = *backbuffer; - DrawWindow window_new; + DrawWindow window_new = CreateBitmapStruct(); - if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH, - SDL_HWSURFACE|SDL_FULLSCREEN)) + if ((window_new->surface = SDL_SetVideoMode(video.width, video.height, + video.depth, surface_flags)) == NULL) { /* switching display to fullscreen mode failed */ @@ -76,7 +83,7 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen) else { if (window_old) - SDL_FreeSurface(window_old); + FreeBitmap(window_old); *backbuffer = window_new; video.fullscreen_enabled = TRUE; @@ -88,10 +95,10 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen) { /* switch display to window mode */ DrawWindow window_old = *backbuffer; - DrawWindow window_new; + DrawWindow window_new = CreateBitmapStruct(); - if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH, - SDL_HWSURFACE)) + if ((window_new->surface = SDL_SetVideoMode(video.width, video.height, + video.depth, surface_flags)) == NULL) { /* switching display to window mode failed -- should not happen */ @@ -102,7 +109,7 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen) else { if (window_old) - SDL_FreeSurface(window_old); + FreeBitmap(window_old); *backbuffer = window_new; video.fullscreen_enabled = FALSE; @@ -113,12 +120,12 @@ inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen) return success; } -inline void SDLCopyArea(SDL_Surface *src_surface, SDL_Surface *dst_surface, +inline void SDLCopyArea(Bitmap src_bitmap, Bitmap dst_bitmap, int src_x, int src_y, int width, int height, - int dst_x, int dst_y) + int dst_x, int dst_y, int copy_mode) { - SDL_Surface *surface = (dst_surface == window ? backbuffer : dst_surface); + Bitmap real_dst_bitmap = (dst_bitmap == window ? backbuffer : dst_bitmap); SDL_Rect src_rect, dst_rect; src_rect.x = src_x; @@ -131,17 +138,19 @@ inline void SDLCopyArea(SDL_Surface *src_surface, SDL_Surface *dst_surface, dst_rect.w = width; dst_rect.h = height; - if (src_surface != backbuffer || dst_surface != window) - SDL_BlitSurface(src_surface, &src_rect, surface, &dst_rect); + if (src_bitmap != backbuffer || dst_bitmap != window) + SDL_BlitSurface((copy_mode == SDLCOPYAREA_MASKED ? + src_bitmap->surface_masked : src_bitmap->surface), + &src_rect, real_dst_bitmap->surface, &dst_rect); - if (dst_surface == window) - SDL_UpdateRect(backbuffer, dst_x, dst_y, width, height); + if (dst_bitmap == window) + SDL_UpdateRect(backbuffer->surface, dst_x, dst_y, width, height); } -inline void SDLFillRectangle(SDL_Surface *dst_surface, int x, int y, +inline void SDLFillRectangle(Bitmap dst_bitmap, int x, int y, int width, int height, unsigned int color) { - SDL_Surface *surface = (dst_surface == window ? backbuffer : dst_surface); + Bitmap real_dst_bitmap = (dst_bitmap == window ? backbuffer : dst_bitmap); SDL_Rect rect; unsigned int color_r = (color >> 16) && 0xff; unsigned int color_g = (color >> 8) && 0xff; @@ -152,11 +161,12 @@ inline void SDLFillRectangle(SDL_Surface *dst_surface, int x, int y, rect.w = width; rect.h = height; - SDL_FillRect(surface, &rect, - SDL_MapRGB(surface->format, color_r, color_g, color_b)); + SDL_FillRect(real_dst_bitmap->surface, &rect, + SDL_MapRGB(real_dst_bitmap->surface->format, + color_r, color_g, color_b)); - if (dst_surface == window) - SDL_UpdateRect(backbuffer, x, y, width, height); + if (dst_bitmap == window) + SDL_UpdateRect(backbuffer->surface, x, y, width, height); } inline void SDLDrawSimpleLine(SDL_Surface *surface, int from_x, int from_y,