/** * Play the intro. */ void IntroState::init() { State::init(); Options::keepAspectRatio = _wasLetterBoxed; if (CrossPlatform::fileExists(_introFile) && (CrossPlatform::fileExists(_introSoundFileDOS) || CrossPlatform::fileExists(_introSoundFileWin))) { audioSequence = new AudioSequence(_game->getResourcePack()); Flc::flc.realscreen = _game->getScreen(); Flc::FlcInit(_introFile.c_str()); Flc::flc.dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2; Flc::flc.dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2; Flc::flc.loop = 0; // just the one time, please Flc::FlcMain(&audioHandler); Flc::FlcDeInit(); delete audioSequence; #ifndef __NO_MUSIC // fade out! Mix_FadeOutChannel(-1, 45 * 20); if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(45 * 20); func_fade(); } // SDL_Mixer has trouble with native midi and volume on windows, which is the most likely use case, so f@%# it. else { Mix_HaltMusic(); } #endif SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = 20; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; pal2[color].unused = pal[color].unused; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(45); } _game->getScreen()->clear(); _game->getScreen()->flip(); Options::musicVolume = _oldMusic; Options::soundVolume = _oldSound; _game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume); #ifndef __NO_MUSIC Sound::stop(); Music::stop(); #endif } Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true); _game->getScreen()->resetDisplay(false); _game->setState(new MainMenuState); }
void VideoState::init() { State::init(); bool wasLetterboxed = CutsceneState::initDisplay(); bool ufoIntroSoundFileDosExists = false; bool ufoIntroSoundFileWinExists = false; int prevMusicVol = Options::musicVolume; int prevSoundVol = Options::soundVolume; if (_useUfoAudioSequence) { const std::set<std::string> &soundDir = FileMap::getVFolderContents("SOUND"); ufoIntroSoundFileDosExists = soundDir.end() != soundDir.find("intro.cat"); ufoIntroSoundFileWinExists = soundDir.end() != soundDir.find("sample3.cat"); if (!ufoIntroSoundFileDosExists && !ufoIntroSoundFileWinExists) { _useUfoAudioSequence = false; } else { // ensure user can hear both music and sound effects for the // vanilla intro sequence Options::musicVolume = Options::soundVolume = std::max(prevMusicVol, prevSoundVol); _game->setVolume(Options::soundVolume, Options::musicVolume, -1); } } _game->getCursor()->setVisible(false); int dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2; int dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2; FlcPlayer *flcPlayer = NULL; for (std::vector<std::string>::const_iterator it = _videos->begin(); it != _videos->end(); ++it) { std::string videoFileName = FileMap::getFilePath(*it); if (!CrossPlatform::fileExists(videoFileName)) { continue; } if (!flcPlayer) { flcPlayer = new FlcPlayer(); } if (_useUfoAudioSequence) { audioSequence = new AudioSequence(_game->getMod(), flcPlayer); } flcPlayer->init(videoFileName.c_str(), _useUfoAudioSequence ? &audioHandler : NULL, _game, dx, dy); flcPlayer->play(_useUfoAudioSequence); if (_useUfoAudioSequence) { flcPlayer->delay(10000); delete audioSequence; audioSequence = NULL; } flcPlayer->deInit(); if (flcPlayer->wasSkipped()) { break; } } if (flcPlayer) { delete flcPlayer; } // We can only do a fade out in 8bpp, otherwise instantly end it bool fade = (_game->getScreen()->getSurface()->getSurface()->format->BitsPerPixel == 8); const int FADE_DELAY = 45; const int FADE_STEPS = 20; #ifndef __NO_MUSIC // fade out! if (fade) { Mix_FadeOutChannel(-1, FADE_DELAY * FADE_STEPS); // SDL_Mixer has trouble with native midi and volume on windows, // which is the most likely use case, so f@%# it. if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(FADE_DELAY * FADE_STEPS); func_fade(); } else { Mix_HaltMusic(); } } else { Mix_HaltChannel(-1); Mix_HaltMusic(); } #endif if (fade) { SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = FADE_STEPS; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; pal2[color].unused = pal[color].unused; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(FADE_DELAY); } } _game->getScreen()->clear(); _game->getScreen()->flip(); if (_useUfoAudioSequence) { Options::musicVolume = prevMusicVol; Options::soundVolume = prevSoundVol; _game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume); } #ifndef __NO_MUSIC Sound::stop(); Music::stop(); #endif _game->getCursor()->setVisible(true); CutsceneState::resetDisplay(wasLetterboxed); _game->popState(); }
/** * Play the intro. */ void IntroState::init() { State::init(); Options::keepAspectRatio = _wasLetterBoxed; if (CrossPlatform::fileExists(_introFile) && (CrossPlatform::fileExists(_introSoundFileDOS) || CrossPlatform::fileExists(_introSoundFileWin))) { audioSequence = new AudioSequence(_game->getResourcePack()); Flc::flc.realscreen = _game->getScreen(); Flc::FlcInit(_introFile.c_str()); Flc::flc.dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2; Flc::flc.dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2; Flc::flc.loop = 0; // just the one time, please Flc::FlcMain(&audioHandler); Flc::FlcDeInit(); delete audioSequence; #ifndef __NO_MUSIC // fade out! Mix_FadeOutChannel(-1, 45 * 20); if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(45 * 20); func_fade(); } // SDL_Mixer has trouble with native midi and volume on windows, which is the most likely use case, so f@%# it. else { Mix_HaltMusic(); } #endif SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = 20; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; pal2[color].a = 255; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(45); } _game->getScreen()->clear(); _game->getScreen()->flip(); Options::musicVolume = _oldMusic; Options::soundVolume = _oldSound; _game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume); #ifndef __NO_MUSIC Sound::stop(); Music::stop(); #endif } // FIXME: This should go to the Game.cpp probably #ifdef __ANDROID__ // We don't need to process mouse events, so we can probably save some cycles on it SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE); SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE); SDL_EventState(SDL_MOUSEWHEEL, SDL_IGNORE); // We're not really using the Dollar Gesture events either SDL_EventState(SDL_DOLLARGESTURE, SDL_IGNORE); SDL_EventState(SDL_DOLLARRECORD, SDL_IGNORE); #endif Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true); _game->getScreen()->resetDisplay(false); _game->setState(new MainMenuState); }