Improve the palette fading (timing and factor calculation), which fixes the introduction synchronization as a result
svn-id: r35492
This commit is contained in:
parent
d0738d553a
commit
95833732b3
1 changed files with 29 additions and 23 deletions
|
@ -47,26 +47,21 @@ void GraphicsMan::update() {
|
||||||
uint32 time = _vm->_system->getMillis() - _fadeStartTime;
|
uint32 time = _vm->_system->getMillis() - _fadeStartTime;
|
||||||
|
|
||||||
// Scale the time
|
// Scale the time
|
||||||
int step = time / 4;
|
int step = (time * 15 << 3) / 1000;
|
||||||
if (step > 256) {
|
if (step > 256) {
|
||||||
step = 256;
|
step = 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_fading == 1) {
|
// Apply the current fading
|
||||||
// Apply the fade in
|
|
||||||
applyFading(step);
|
applyFading(step);
|
||||||
} else if (_fading == 2) {
|
|
||||||
// Apply the fade out
|
|
||||||
applyFading(256 - step);
|
|
||||||
|
|
||||||
// Clear the buffer when ending the fade out
|
|
||||||
if (step == 256)
|
|
||||||
_foreground.fillRect(Common::Rect::Rect(640, 320), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for the end
|
// Check for the end
|
||||||
if (step == 256) {
|
if (step == 256) {
|
||||||
_fading = 0;
|
_fading = 0;
|
||||||
|
|
||||||
|
// Clear the buffer when ending the fade out
|
||||||
|
if (_fading == 2)
|
||||||
|
_foreground.fillRect(Common::Rect::Rect(640, 320), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +91,6 @@ void GraphicsMan::mergeFgAndBg() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicsMan::updateScreen(Graphics::Surface *source) {
|
void GraphicsMan::updateScreen(Graphics::Surface *source) {
|
||||||
_vm->_system->copyRectToScreen((byte *)source->getBasePtr(0, 0), 640, 0, 80, 640, 320);
|
_vm->_system->copyRectToScreen((byte *)source->getBasePtr(0, 0), 640, 0, 80, 640, 320);
|
||||||
change();
|
change();
|
||||||
|
@ -117,11 +111,11 @@ void GraphicsMan::fadeIn(byte *pal) {
|
||||||
_paletteFull[(i * 4) + 2] = pal[(i * 3) + 2];
|
_paletteFull[(i * 4) + 2] = pal[(i * 3) + 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply a black palette right now
|
|
||||||
applyFading(0);
|
|
||||||
|
|
||||||
// Set the current fading
|
// Set the current fading
|
||||||
_fading = 1;
|
_fading = 1;
|
||||||
|
|
||||||
|
// Apply a black palette right now
|
||||||
|
applyFading(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsMan::fadeOut() {
|
void GraphicsMan::fadeOut() {
|
||||||
|
@ -137,18 +131,30 @@ void GraphicsMan::fadeOut() {
|
||||||
|
|
||||||
void GraphicsMan::applyFading(int step) {
|
void GraphicsMan::applyFading(int step) {
|
||||||
// Calculate the fade factor for the given step
|
// Calculate the fade factor for the given step
|
||||||
int factorR = 256 - (256 - step) * 1;
|
int factorR, factorG, factorB;
|
||||||
int factorGB = 256 - (256 - step) * 2;
|
if (_fading == 1) {
|
||||||
|
// Fading in
|
||||||
if (factorR <= 0) factorR = 0;
|
factorR = (step << 2);
|
||||||
if (factorGB <= 0) factorGB = 0;
|
factorG = (step << 1);
|
||||||
|
factorB = step;
|
||||||
|
if (factorR > 256) factorR = 256;
|
||||||
|
if (factorG > 256) factorG = 256;
|
||||||
|
if (factorB > 256) factorB = 256;
|
||||||
|
} else if (_fading == 2) {
|
||||||
|
// Fading out
|
||||||
|
factorR = 256 - step;
|
||||||
|
factorG = 256 - (step << 1);
|
||||||
|
if (factorR < 0) factorR = 0;
|
||||||
|
if (factorG < 0) factorG = 0;
|
||||||
|
factorB = factorG;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the new palette
|
// Calculate the new palette
|
||||||
byte newpal[256 * 4];
|
byte newpal[256 * 4];
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
newpal[(i * 4) + 0] = (_paletteFull[(i * 4) + 0] * factorR) / 256;
|
newpal[(i * 4) + 0] = (_paletteFull[(i * 4) + 0] * factorR) / 256;
|
||||||
newpal[(i * 4) + 1] = (_paletteFull[(i * 4) + 1] * factorGB) / 256;
|
newpal[(i * 4) + 1] = (_paletteFull[(i * 4) + 1] * factorG) / 256;
|
||||||
newpal[(i * 4) + 2] = (_paletteFull[(i * 4) + 2] * factorGB) / 256;
|
newpal[(i * 4) + 2] = (_paletteFull[(i * 4) + 2] * factorB) / 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the screen palette
|
// Set the screen palette
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue