X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=9c842f45fe52f9aab168dc0700ba33be5bbe71b1;hb=adebc3d223c1611d7c947adba6a8b34885033aec;hp=f77bd79ef23bb37dcf915ef4fe78e2b0cee4a249;hpb=8d46c5298f0fcce7bdb52f3835b2fbbdc403dfe0;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index f77bd79e..9c842f45 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(); @@ -81,14 +91,13 @@ void OpenAll(int argc, char *argv[]) #ifndef USE_SDL_LIBRARY XMapWindow(display, window); - XFlush(display); + FlushDisplay(); #endif InitGfx(); InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ - InitLevelAndPlayerInfo(); - return; + InitLevelInfo(); InitGadgets(); /* needs to know number of level series */ DrawMainMenu(); @@ -96,7 +105,7 @@ void OpenAll(int argc, char *argv[]) InitNetworkServer(); } -void InitLevelAndPlayerInfo() +void InitPlayerInfo() { int i; @@ -111,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)) @@ -147,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"); @@ -173,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_JOYSTICK */ + #ifndef MSDOS for (i=0; i=0; i++) @@ -680,33 +778,31 @@ void InitGfx() 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_drawto = sdl_backbuffer = sdl_pix[PIX_DB_BACK]; - sdl_fieldbuffer = sdl_pix[PIX_DB_FIELD]; - SetDrawtoField(DRAW_BACKBUFFER); + SDL_FreeSurface(sdl_image_tmp); - SDLCopyArea(sdl_pix[PIX_BACK], sdl_backbuffer, - 0,0, WIN_XSIZE,WIN_YSIZE, 0,0); - SDLFillRectangle(sdl_pix[PIX_DB_BACK], - REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, 0x000000); - SDLFillRectangle(sdl_pix[PIX_DB_DOOR], - 0,0, 3*DXSIZE,DYSIZE+VYSIZE, 0x000000); + BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0); + } + } #else /* !USE_SDL_LIBRARY */ @@ -758,7 +854,7 @@ void InitGfx() if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR]) Error(ERR_EXIT, "cannot create additional pixmaps"); - for(i=0; iformat, 0x00, 0x00, 0x00)); - if ((sdl_pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + 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); @@ -903,6 +997,11 @@ 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 */ } @@ -2112,14 +2211,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