X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=65c6255871d133ba329e29f677649d03ef6a0429;hb=e6e7b00366bd426aaaad8f5175feabb0eafb4cb0;hp=6f2c96e21840bccbc7aefb193e3f0d710fe6b253;hpb=6d7ebf6db8a9a57f2e3e398da1d2f7d8d084523f;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index 6f2c96e2..65c62558 100644 --- a/src/tools.c +++ b/src/tools.c @@ -414,112 +414,48 @@ void FadeToFront() BackToFront(); } -#define FADE_MODE_FADE_IN 0 -#define FADE_MODE_FADE_OUT 1 -#define FADE_MODE_CROSSFADE 2 - -static void FadeExt(Bitmap *bitmap_cross, int fade_ms, int fade_mode) +void FadeIn(int fade_delay) { - SDL_Surface *surface_screen = backbuffer->surface; - SDL_Surface *surface_screen_copy = NULL; - SDL_Surface *surface_black = NULL; - SDL_Surface *surface_cross; /* initialized later */ - boolean fade_reverse; /* initialized later */ - unsigned int flags = SDL_SRCALPHA; - unsigned int time_last, time_current; - float alpha; - int alpha_final; - - /* use same surface type as screen surface */ - if ((surface_screen->flags & SDL_HWSURFACE)) - flags |= SDL_HWSURFACE; - else - flags |= SDL_SWSURFACE; - - /* create surface for copy of screen buffer */ - if ((surface_screen_copy = - SDL_CreateRGBSurface(flags, - surface_screen->w, - surface_screen->h, - surface_screen->format->BitsPerPixel, - surface_screen->format->Rmask, - surface_screen->format->Gmask, - surface_screen->format->Bmask, - surface_screen->format->Amask)) == NULL) - Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); - - SDL_BlitSurface(surface_screen, NULL, surface_screen_copy, NULL); - - /* create black surface for fading from/to black */ - if ((surface_black = - SDL_CreateRGBSurface(flags, - surface_screen->w, - surface_screen->h, - surface_screen->format->BitsPerPixel, - surface_screen->format->Rmask, - surface_screen->format->Gmask, - surface_screen->format->Bmask, - surface_screen->format->Amask)) == NULL) - Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); - - SDL_FillRect(surface_black, NULL, SDL_MapRGB(surface_screen->format, 0,0,0)); - - fade_reverse = (fade_mode == FADE_MODE_FADE_IN ? TRUE : FALSE); - surface_cross = (fade_mode == FADE_MODE_CROSSFADE ? bitmap_cross->surface : - surface_black); - - time_current = SDL_GetTicks(); - - for (alpha = 0.0; alpha < 255.0;) - { - time_last = time_current; - time_current = SDL_GetTicks(); - alpha += 255 * ((float)(time_current - time_last) / fade_ms); - alpha_final = (int)(fade_reverse ? 255.0 - alpha : alpha); - alpha_final = MIN(MAX(0, alpha_final), 255); - - /* draw existing image to screen buffer */ - SDL_BlitSurface(surface_screen_copy, NULL, surface_screen, NULL); - - /* draw new image to screen buffer using alpha blending */ - SDL_SetAlpha(surface_cross, SDL_SRCALPHA, alpha_final); - SDL_BlitSurface(surface_cross, NULL, surface_screen, NULL); - - /* draw screen buffer to visible display */ - SDL_Flip(surface_screen); + if (fade_delay == 0) + { + BackToFront(); + + return; } - SDL_FreeSurface(surface_screen_copy); - SDL_FreeSurface(surface_black); + FadeScreen(NULL, FADE_MODE_FADE_IN, fade_delay, 0); redraw_mask = REDRAW_NONE; } -void FadeIn(int fade_ms) +void FadeOut(int fade_delay, int post_delay) { -#ifdef TARGET_SDL - FadeExt(NULL, fade_ms, FADE_MODE_FADE_IN); -#else - BackToFront(); -#endif -} + if (fade_delay == 0) + { + ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE); + BackToFront(); -void FadeOut(int fade_ms) -{ -#ifdef TARGET_SDL - FadeExt(NULL, fade_ms, FADE_MODE_FADE_OUT); -#else - BackToFront(); -#endif + return; + } + + FadeScreen(NULL, FADE_MODE_FADE_OUT, fade_delay, post_delay); + + redraw_mask = REDRAW_NONE; } -void FadeCross(Bitmap *bitmap, int fade_ms) +void FadeCross(int fade_delay) { -#ifdef TARGET_SDL - FadeExt(bitmap, fade_ms, FADE_MODE_CROSSFADE); -#else - BackToFront(); -#endif + if (fade_delay == 0) + { + BlitBitmap(bitmap_db_title, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); + BackToFront(); + + return; + } + + FadeScreen(bitmap_db_title, FADE_MODE_CROSSFADE, fade_delay, 0); + + redraw_mask = REDRAW_NONE; } void SetMainBackgroundImageIfDefined(int graphic) @@ -1516,7 +1452,7 @@ void ShowEnvelope(int envelope_nr) game.envelope_active = TRUE; /* needed for RedrawPlayfield() events */ - PlaySoundStereo(sound_opening, SOUND_MIDDLE); + PlayMenuSoundStereo(sound_opening, SOUND_MIDDLE); if (anim_mode == ANIM_DEFAULT) AnimateEnvelope(envelope_nr, ANIM_DEFAULT, ACTION_OPENING); @@ -1528,7 +1464,7 @@ void ShowEnvelope(int envelope_nr) else WaitForEventToContinue(); - PlaySoundStereo(sound_closing, SOUND_MIDDLE); + PlayMenuSoundStereo(sound_closing, SOUND_MIDDLE); if (anim_mode != ANIM_NONE) AnimateEnvelope(envelope_nr, main_anim_mode, ACTION_CLOSING); @@ -2634,14 +2570,17 @@ unsigned int MoveDoor(unsigned int door_state) return (door1 | door2); } - if (door1 == DOOR_OPEN_1 && door_state & DOOR_OPEN_1) - door_state &= ~DOOR_OPEN_1; - else if (door1 == DOOR_CLOSE_1 && door_state & DOOR_CLOSE_1) - door_state &= ~DOOR_CLOSE_1; - if (door2 == DOOR_OPEN_2 && door_state & DOOR_OPEN_2) - door_state &= ~DOOR_OPEN_2; - else if (door2 == DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2) - door_state &= ~DOOR_CLOSE_2; + if (!(door_state & DOOR_FORCE_REDRAW)) + { + if (door1 == DOOR_OPEN_1 && door_state & DOOR_OPEN_1) + door_state &= ~DOOR_OPEN_1; + else if (door1 == DOOR_CLOSE_1 && door_state & DOOR_CLOSE_1) + door_state &= ~DOOR_CLOSE_1; + if (door2 == DOOR_OPEN_2 && door_state & DOOR_OPEN_2) + door_state &= ~DOOR_OPEN_2; + else if (door2 == DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2) + door_state &= ~DOOR_CLOSE_2; + } door_delay_value = (door_state & DOOR_ACTION_1 ? door_1.step_delay : door_2.step_delay); @@ -2690,9 +2629,9 @@ unsigned int MoveDoor(unsigned int door_state) { /* opening door sound has priority over simultaneously closing door */ if (door_state & (DOOR_OPEN_1 | DOOR_OPEN_2)) - PlaySoundStereo(SND_DOOR_OPENING, SOUND_MIDDLE); + PlayMenuSoundStereo(SND_DOOR_OPENING, SOUND_MIDDLE); else if (door_state & (DOOR_CLOSE_1 | DOOR_CLOSE_2)) - PlaySoundStereo(SND_DOOR_CLOSING, SOUND_MIDDLE); + PlayMenuSoundStereo(SND_DOOR_CLOSING, SOUND_MIDDLE); } for (k = start; k <= end && !(door_1_done && door_2_done); k += stepsize) @@ -5975,3 +5914,60 @@ void InitGraphicInfo_EM(void) exit(0); #endif } + +void PlayMenuSound() +{ + int sound = menu.sound[game_status]; + + if (sound == SND_UNDEFINED) + return; + + if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) || + (!setup.sound_loops && IS_LOOP_SOUND(sound))) + return; + + if (IS_LOOP_SOUND(sound)) + PlaySoundLoop(sound); + else + PlaySound(sound); +} + +void PlayMenuSoundStereo(int sound, int stereo_position) +{ + if (sound == SND_UNDEFINED) + return; + + if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) || + (!setup.sound_loops && IS_LOOP_SOUND(sound))) + return; + + if (IS_LOOP_SOUND(sound)) + PlaySoundExt(sound, SOUND_MAX_VOLUME, stereo_position, SND_CTRL_PLAY_LOOP); + else + PlaySoundStereo(sound, stereo_position); +} + +void PlayMenuSoundIfLoop() +{ + int sound = menu.sound[game_status]; + + if (sound == SND_UNDEFINED) + return; + + if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) || + (!setup.sound_loops && IS_LOOP_SOUND(sound))) + return; + + if (IS_LOOP_SOUND(sound)) + PlaySoundLoop(sound); +} + +void PlayMenuMusic() +{ + int music = menu.music[game_status]; + + if (music == MUS_UNDEFINED) + return; + + PlayMusic(music); +}