X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Finit.c;h=c591c0db5634dd3f660c7c404c2e9aac58cbc7a2;hp=6276e5bca5d80a22968c84ba2b5e3c638b165003;hb=8be31c2781126204470171aff7af45713ec42e9e;hpb=adaabca253f2e76597725cdc86fc1fff6f0de1d2 diff --git a/src/init.c b/src/init.c index 6276e5bc..c591c0db 100644 --- a/src/init.c +++ b/src/init.c @@ -14,6 +14,7 @@ #include #include "init.h" +#include "events.h" #include "misc.h" #include "sound.h" #include "screens.h" @@ -40,9 +41,12 @@ struct IconFileInfo char *picturemask_filename; }; +#ifndef USE_SDL_LIBRARY static int sound_process_id = 0; +#endif -static void InitLevelAndPlayerInfo(void); +static void InitPlayerInfo(void); +static void InitLevelInfo(void); static void InitNetworkServer(void); static void InitDisplay(void); static void InitSound(void); @@ -55,18 +59,24 @@ static void InitElementProperties(void); void OpenAll(int argc, char *argv[]) { -#ifdef MSDOS +#if defined(MSDOS) || defined(WIN32) initErrorFile(); #endif if (options.serveronly) { +#ifdef WIN32 + Error(ERR_WARN, "networking not supported in Windows version"); +#else NetworkServer(options.server_port, options.serveronly); +#endif /* never reached */ exit(0); } + InitPlayerInfo(); + InitCounter(); InitSound(); InitSoundServer(); @@ -79,13 +89,15 @@ 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() */ - InitLevelAndPlayerInfo(); + InitLevelInfo(); InitGadgets(); /* needs to know number of level series */ DrawMainMenu(); @@ -93,7 +105,7 @@ void OpenAll(int argc, char *argv[]) InitNetworkServer(); } -void InitLevelAndPlayerInfo() +void InitPlayerInfo() { int i; @@ -108,22 +120,26 @@ void InitLevelAndPlayerInfo() local_player->connected = TRUE; - LoadLevelInfo(); /* global level info */ LoadSetup(); /* global setup info */ +} + +void InitLevelInfo() +{ + LoadLevelInfo(); /* global level info */ LoadLevelSetup_LastSeries(); /* last played series info */ LoadLevelSetup_SeriesInfo(); /* last played level info */ } void InitNetworkServer() { -#ifndef MSDOS +#if !defined(MSDOS) && !defined(WIN32) int nr_wanted; #endif if (!options.network) return; -#ifndef MSDOS +#if !defined(MSDOS) && !defined(WIN32) nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); if (!ConnectToServer(options.server_host, options.server_port)) @@ -144,7 +160,32 @@ void InitSound() if (sound_status == SOUND_OFF) return; -#ifndef MSDOS +#ifdef USE_SDL_LIBRARY + /* initialize SDL audio */ + + if (SDL_Init(SDL_INIT_AUDIO) < 0) + { + Error(ERR_WARN, "SDL_Init() failed: %s", SDL_GetError()); + sound_status = SOUND_OFF; + return; + } + + if (Mix_OpenAudio(22050, AUDIO_S16, 2, 512) < 0) + { + Error(ERR_WARN, "Mix_OpenAudio() failed: %s", SDL_GetError()); + sound_status = SOUND_OFF; + return; + } + + Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4); + Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4); + + sound_status = SOUND_AVAILABLE; + sound_loops_allowed = TRUE; + +#else /* !USE_SDL_LIBRARY */ + +#if !defined(MSDOS) && !defined(WIN32) if (access(sound_device_name, W_OK) != 0) { Error(ERR_WARN, "cannot access sound device - no sounds"); @@ -170,28 +211,32 @@ void InitSound() */ #endif -#else /* MSDOS */ +#else /* MSDOS || WIN32 */ sound_loops_allowed = TRUE; /* setup.sound_loops_on = TRUE; */ -#endif /* MSDOS */ +#endif /* MSDOS || WIN32 */ +#endif /* !USE_SDL_LIBRARY */ for(i=0; i= SDL_NumJoysticks()) + joystick_nr = -1; + + /* misuse joystick file descriptor variable to store joystick number */ + stored_player[i].joystick_fd = joystick_nr; + + /* this allows subsequent calls to 'InitJoysticks' for re-initialization */ + if (Check_SDL_JoystickOpened(joystick_nr)) + Close_SDL_Joystick(joystick_nr); + + if (!setup.input[i].use_joystick) + continue; + + if (!Open_SDL_Joystick(joystick_nr)) + { + Error(ERR_WARN, "cannot open joystick %d", joystick_nr); + continue; + } + + joystick_status = JOYSTICK_AVAILABLE; + } + +#else /* !USE_SDL_JOYSTICK */ + #ifndef MSDOS 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", 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 +855,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 +922,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", 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", 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", 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 +998,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 +1048,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 +1152,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 +1464,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 +1636,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 +1738,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 +1949,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); @@ -1968,14 +2212,19 @@ void CloseAllAndExit(int exit_value) { int i; +#ifdef USE_SDL_LIBRARY + StopSounds(); + FreeSounds(NUM_SOUNDS); +#else if (sound_process_id) { StopSounds(); kill(sound_process_id, SIGTERM); FreeSounds(NUM_SOUNDS); } +#endif - for(i=0; i