X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=ab51dd9fef4ce8c6ffc1ddacf9df2da289f99fc4;hb=b9c7e4a42762c8526702726f1404d3e75dbc29f5;hp=6276e5bca5d80a22968c84ba2b5e3c638b165003;hpb=adaabca253f2e76597725cdc86fc1fff6f0de1d2;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 6276e5bc..ab51dd9f 100644 --- a/src/init.c +++ b/src/init.c @@ -79,8 +79,10 @@ void OpenAll(int argc, char *argv[]) InitDisplay(); InitWindow(argc, argv); +#ifndef USE_SDL_LIBRARY XMapWindow(display, window); - XFlush(display); + FlushDisplay(); +#endif InitGfx(); InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ @@ -298,6 +300,16 @@ void InitJoysticks() void InitDisplay() { +#ifdef USE_SDL_LIBRARY + /* initialize SDL */ + if (SDL_Init(SDL_INIT_VIDEO) < 0) + Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError()); + + /* automatically cleanup SDL stuff after exit() */ + atexit(SDL_Quit); + +#else /* !USE_SDL_LIBRARY */ + #ifndef MSDOS XVisualInfo vinfo_template, *vinfo; int num_visuals; @@ -339,11 +351,24 @@ void InitDisplay() printf("Sorry, cannot get appropriate visual.\n"); exit(-1); } -#endif +#endif /* !MSDOS */ +#endif /* !USE_SDL_LIBRARY */ } void InitWindow(int argc, char *argv[]) { +#ifdef USE_SDL_LIBRARY + /* open SDL video output device (window or fullscreen mode) */ + if ((window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH, + SDL_HWSURFACE)) + == NULL) + Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s\n", SDL_GetError()); + + /* set window and icon title */ + SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING); + +#else /* !USE_SDL_LIBRARY */ + unsigned int border_width = 4; XGCValues gc_values; unsigned long gc_valuemask; @@ -452,20 +477,26 @@ void InitWindow(int argc, char *argv[]) XSelectInput(display, window, window_event_mask); #endif - /* create GC for drawing with window depth */ + /* create GC for drawing with window depth and background color (black) */ gc_values.graphics_exposures = False; gc_values.foreground = pen_bg; gc_values.background = pen_bg; gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; gc = XCreateGC(display, window, gc_valuemask, &gc_values); +#endif /* !USE_SDL_LIBRARY */ } void InitGfx() { int i,j; + +#ifdef USE_SDL_LIBRARY + SDL_Surface *sdl_image_tmp; +#else GC copy_clipmask_gc; XGCValues clip_gc_values; unsigned long clip_gc_valuemask; +#endif #ifdef MSDOS static struct PictureFileInfo pic[NUM_PICTURES] = @@ -579,8 +610,6 @@ void InitGfx() #endif #endif - - LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]); DrawInitText(WINDOW_TITLE_STRING,20,FC_YELLOW); DrawInitText(COPYRIGHT_STRING,50,FC_RED); @@ -598,6 +627,83 @@ void InitGfx() debug_print_timestamp(0, "SUMMARY LOADING ALL GRAPHICS:"); #endif +#ifdef USE_SDL_LIBRARY + /* create some native image surfaces for double-buffer purposes */ + + /* create double-buffer surface for background image */ + if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, + WIN_XSIZE, WIN_YSIZE, + WIN_SDL_DEPTH, 0, 0, 0, 0)) + == NULL) + Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError()); + + if ((pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + + SDL_FreeSurface(sdl_image_tmp); + + /* create double-buffer surface for door image */ + if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, + 3 * DXSIZE, DYSIZE + VYSIZE, + WIN_SDL_DEPTH, 0, 0, 0, 0)) + == NULL) + Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError()); + + if ((pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + + SDL_FreeSurface(sdl_image_tmp); + + /* create double-buffer surface for field image */ + if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, + FXSIZE, FYSIZE, + WIN_SDL_DEPTH, 0, 0, 0, 0)) + == NULL) + Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError()); + + if ((pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + + SDL_FreeSurface(sdl_image_tmp); + + /* initialize surface array to 'NULL' */ + for(i=0; i=0; i++) + { + for(j=0; jformat, 0x00, 0x00, 0x00)); + if ((tile_masked[tile] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + + SDL_FreeSurface(sdl_image_tmp); + + BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0); + } + } + +#else /* !USE_SDL_LIBRARY */ + pix[PIX_DB_BACK] = XCreatePixmap(display, window, WIN_XSIZE,WIN_YSIZE, XDefaultDepth(display,screen)); @@ -646,7 +752,7 @@ void InitGfx() if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR]) Error(ERR_EXIT, "cannot create additional pixmaps"); - for(i=0; ipicture_filename) @@ -708,6 +819,26 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) debug_print_timestamp(1, NULL); /* initialize timestamp function */ #endif +#ifdef USE_SDL_LIBRARY + /* load image to temporary surface */ + if ((sdl_image_tmp = IMG_Load(filename)) == NULL) + Error(ERR_EXIT, "IMG_Load() failed: %s\n", SDL_GetError()); + + /* create native non-transparent surface for current image */ + if ((pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + + /* create native transparent surface for current image */ + SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY, + SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00)); + if ((pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + + /* free temporary surface */ + SDL_FreeSurface(sdl_image_tmp); + +#else /* !USE_SDL_LIBRARY */ + #ifdef USE_XPM_LIBRARY xpm_att[pos].valuemask = XpmCloseness; @@ -764,8 +895,15 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) if (!pix[pos]) Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename); + + /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always + use pix_masked[], although they are the same when not using SDL */ + pix_masked[pos] = pix[pos]; + +#endif /* !USE_SDL_LIBRARY */ } +#ifndef USE_SDL_LIBRARY /* zugehörige Maske laden (wenn vorhanden) */ if (pic->picture_with_mask) { @@ -807,6 +945,7 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) if (!clipmask[pos]) Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); } +#endif /* !USE_SDL_LIBRARY */ } void InitGadgets() @@ -910,14 +1049,14 @@ void InitElementProperties() EL_AMOEBE_BD, EL_MORAST_VOLL, EL_MORAST_LEER, - EL_SIEB_INAKTIV, - EL_SIEB_LEER, - EL_SIEB_VOLL, - EL_SIEB_TOT, - EL_SIEB2_INAKTIV, - EL_SIEB2_LEER, - EL_SIEB2_VOLL, - EL_SIEB2_TOT, + EL_MAGIC_WALL_OFF, + EL_MAGIC_WALL_EMPTY, + EL_MAGIC_WALL_FULL, + EL_MAGIC_WALL_DEAD, + EL_MAGIC_WALL_BD_OFF, + EL_MAGIC_WALL_BD_EMPTY, + EL_MAGIC_WALL_BD_FULL, + EL_MAGIC_WALL_BD_DEAD, EL_LIFE, EL_LIFE_ASYNC, EL_BADEWANNE1, @@ -1222,8 +1361,8 @@ void InitElementProperties() EL_KOKOSNUSS, EL_TROPFEN, EL_MORAST_VOLL, - EL_SIEB_VOLL, - EL_SIEB2_VOLL, + EL_MAGIC_WALL_FULL, + EL_MAGIC_WALL_BD_FULL, EL_ZEIT_VOLL, EL_ZEIT_LEER, EL_SP_ZONK, @@ -1394,7 +1533,7 @@ void InitElementProperties() EL_FELSBROCKEN, EL_BD_ROCK, EL_EDELSTEIN_BD, - EL_SIEB2_INAKTIV, + EL_MAGIC_WALL_BD_OFF, EL_AUSGANG_ZU, EL_AUSGANG_AUF, EL_BETON, @@ -1496,10 +1635,10 @@ void InitElementProperties() EL_BADEWANNE3, EL_BADEWANNE4, EL_BADEWANNE5, - EL_SIEB_INAKTIV, - EL_SIEB_TOT, - EL_SIEB2_INAKTIV, - EL_SIEB2_TOT, + EL_MAGIC_WALL_OFF, + EL_MAGIC_WALL_DEAD, + EL_MAGIC_WALL_BD_OFF, + EL_MAGIC_WALL_BD_DEAD, EL_AMOEBA2DIAM, EL_BLOCKED, EL_SP_EMPTY, @@ -1707,7 +1846,9 @@ void InitElementProperties() EL_SP_CHIP_UPPER, EL_SP_CHIP_LOWER, /* additional elements that appeared in newer Supaplex levels */ - EL_UNSICHTBAR + EL_UNSICHTBAR, + /* more than one murphy in a level results in an inactive clone */ + EL_SP_MURPHY_CLONE }; static int ep_sp_element_num = sizeof(ep_sp_element)/sizeof(int); @@ -1975,7 +2116,7 @@ void CloseAllAndExit(int exit_value) FreeSounds(NUM_SOUNDS); } - for(i=0; i