Fade palette in/out when entering/leaving a location

svn-id: r50409
This commit is contained in:
Robert Špalek 2010-06-28 04:59:13 +00:00
parent d4a0c8a1ad
commit 76b8c33aaf
3 changed files with 36 additions and 8 deletions

View file

@ -176,6 +176,9 @@ void Game::start() {
// Call the outer loop doing all the hard job. // Call the outer loop doing all the hard job.
loop(kOuterLoop, false); loop(kOuterLoop, false);
// Fade out the palette after leaving the location.
fadePalette(true);
if (!isReloaded()) { if (!isReloaded()) {
// We are changing location. Run the hero's LOOK // We are changing location. Run the hero's LOOK
// program to trigger a possible cut-scene. This is // program to trigger a possible cut-scene. This is
@ -428,6 +431,22 @@ void Game::handleDialogueLoop() {
} }
} }
void Game::fadePalette(bool fading_out) {
const byte *startPal = NULL;
const byte *endPal = _currentRoom._palette >= 0
? _vm->_paletteArchive->getFile(_currentRoom._palette)->_data
: NULL;
if (fading_out) {
startPal = endPal;
endPal = NULL;
}
for (int i = 1; i <= kBlackFadingIterations; ++i) {
_vm->_system->delayMillis(kBlackFadingTimeUnit);
_vm->_screen->interpolatePalettes(startPal, endPal, 0, kNumColours, i, kBlackFadingIterations);
_vm->_screen->copyToScreen();
}
}
void Game::advanceAnimationsAndTestLoopExit() { void Game::advanceAnimationsAndTestLoopExit() {
// Fade the palette if requested // Fade the palette if requested
if (_fadePhase > 0 && (_vm->_system->getMillis() - _fadeTick) >= kFadingTimeUnit) { if (_fadePhase > 0 && (_vm->_system->getMillis() - _fadeTick) >= kFadingTimeUnit) {
@ -485,7 +504,7 @@ void Game::advanceAnimationsAndTestLoopExit() {
// callbacks) and redraw screen // callbacks) and redraw screen
_vm->_anims->drawScene(_vm->_screen->getSurface()); _vm->_anims->drawScene(_vm->_screen->getSurface());
_vm->_screen->copyToScreen(); _vm->_screen->copyToScreen();
_vm->_system->delayMillis(20); _vm->_system->delayMillis(kTimeUnit);
// If the hero has arrived at his destination, after even the last // If the hero has arrived at his destination, after even the last
// phase was correctly animated, run the callback. // phase was correctly animated, run the callback.
@ -1364,10 +1383,11 @@ void Game::enterNewRoom() {
loadRoomObjects(); loadRoomObjects();
loadOverlays(); loadOverlays();
// Set room palette // Draw the scene with the black palette and slowly fade into the right palette.
const BAFile *f; _vm->_screen->setPalette(NULL, 0, kNumColours);
f = _vm->_paletteArchive->getFile(_currentRoom._palette); _vm->_anims->drawScene(_vm->_screen->getSurface());
_vm->_screen->setPalette(f->_data, 0, kNumColours); _vm->_screen->copyToScreen();
fadePalette(false);
// Run the program for the gate the dragon came through // Run the program for the gate the dragon came through
debugC(6, kDraciLogicDebugLevel, "Running program for gate %d", _newGate); debugC(6, kDraciLogicDebugLevel, "Running program for gate %d", _newGate);

View file

@ -65,9 +65,16 @@ enum SpeechConstants {
kStandardSpeed = 60 kStandardSpeed = 60
}; };
// One fading phase is 50ms.
enum FadeConstants { enum FadeConstants {
kFadingTimeUnit = 50 // One fading phase called from the game scripts is 50ms.
kFadingTimeUnit = 50,
// Fading in/out when entering/leaving a location takes 15 iterations of (at least) 7ms each.
kBlackFadingIterations = 15,
kBlackFadingTimeUnit = 7
};
enum AnimationConstants {
kTimeUnit = 20
}; };
/** Inventory related magical constants */ /** Inventory related magical constants */
@ -334,6 +341,7 @@ private:
void handleDialogueLoop(); void handleDialogueLoop();
void updateTitle(int x, int y); void updateTitle(int x, int y);
void updateCursor(); void updateCursor();
void fadePalette(bool fading_out);
void advanceAnimationsAndTestLoopExit(); void advanceAnimationsAndTestLoopExit();
void handleStatusChangeByMouse(); void handleStatusChangeByMouse();

View file

@ -881,7 +881,7 @@ void Script::setPalette(const Common::Array<int> &params) {
} }
// Immediately update the palette // Immediately update the palette
_vm->_screen->copyToScreen(); _vm->_screen->copyToScreen();
_vm->_system->delayMillis(20); _vm->_system->delayMillis(kTimeUnit);
} }
void Script::quitGame(const Common::Array<int> &params) { void Script::quitGame(const Common::Array<int> &params) {