X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=7d97072ef0ac2b236aafdbc5019135e943632810;hb=bb2ddcf13df18d69e4472d4697da173981970e9d;hp=ab51dd9fef4ce8c6ffc1ddacf9df2da289f99fc4;hpb=36357e8399d0a42ac45a1cd096aee24a9008b5f5;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index ab51dd9f..7d97072e 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(); @@ -87,7 +97,7 @@ void OpenAll(int argc, char *argv[]) InitGfx(); InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ - InitLevelAndPlayerInfo(); + InitLevelInfo(); InitGadgets(); /* needs to know number of level series */ DrawMainMenu(); @@ -95,7 +105,7 @@ void OpenAll(int argc, char *argv[]) InitNetworkServer(); } -void InitLevelAndPlayerInfo() +void InitPlayerInfo() { int i; @@ -110,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)) @@ -146,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, 256) < 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"); @@ -172,28 +211,31 @@ 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_LIBRARY */ + #ifndef MSDOS for (i=0; iformat, 0x00, 0x00, 0x00)); if ((tile_masked[tile] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); SDL_FreeSurface(sdl_image_tmp); @@ -822,17 +924,17 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) #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()); + 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\n", SDL_GetError()); + 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\n", SDL_GetError()); + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); /* free temporary surface */ SDL_FreeSurface(sdl_image_tmp); @@ -2109,12 +2211,17 @@ 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