mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-01 06:58:34 +00:00
2dc7cb2cd4
- Cutting down the code-dup - Plucking leaks - Removing dead/unused code - Properly naming "word_2342F"-style variables and functions (removing the warnings alongside) - Fleshing out the "stubby" functions - Moving functions and variables to more appropriate/logical places - Re-ordering functions and variables - Re-structuring functions - Moving the IMD stuff into a new "Imd" class in the new imd.cpp/.h (still to be completely implemented and cleaned up) - Formatting - Getting rid off the classes "Anim", "Pack" and "Timer", along with their files svn-id: r26252
215 lines
5.3 KiB
C++
215 lines
5.3 KiB
C++
/* ScummVM - Scumm Interpreter
|
|
* Copyright (C) 2004 Ivan Dubrov
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* $URL$
|
|
* $Id$
|
|
*
|
|
*/
|
|
|
|
#include "gob/gob.h"
|
|
#include "gob/palanim.h"
|
|
#include "gob/global.h"
|
|
#include "gob/util.h"
|
|
#include "gob/video.h"
|
|
|
|
namespace Gob {
|
|
|
|
PalAnim::PalAnim(GobEngine *vm) : _vm(vm) {
|
|
_fadeValue = 1;
|
|
for (int i = 0; i < 256; i++) {
|
|
_toFadeRed[i] = 0;
|
|
_toFadeGreen[i] = 0;
|
|
_toFadeBlue[i] = 0;
|
|
}
|
|
|
|
_palArray[0] = _vm->_global->_redPalette;
|
|
_palArray[1] = _vm->_global->_greenPalette;
|
|
_palArray[2] = _vm->_global->_bluePalette;
|
|
_fadeArray[0] = _toFadeRed;
|
|
_fadeArray[1] = _toFadeGreen;
|
|
_fadeArray[2] = _toFadeBlue;
|
|
}
|
|
|
|
char PalAnim::fadeColor(int16 from, int16 to) {
|
|
if ((from - _fadeValue) > to)
|
|
return from - _fadeValue;
|
|
else if ((from + _fadeValue) < to)
|
|
return from + _fadeValue;
|
|
else return to;
|
|
}
|
|
|
|
bool PalAnim::fadeStepColor(int color) {
|
|
bool stop = true;
|
|
char colors[3];
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
colors[0] = _palArray[0][i];
|
|
colors[1] = _palArray[1][i];
|
|
colors[2] = _palArray[2][i];
|
|
colors[color] = fadeColor(_palArray[color][i], _fadeArray[color][i]);
|
|
|
|
_vm->_video->setPalElem(i, colors[0], colors[1], colors[2],
|
|
-1, _vm->_global->_videoMode);
|
|
|
|
if (_palArray[color][i] != _fadeArray[color][i])
|
|
stop = false;
|
|
}
|
|
|
|
return stop;
|
|
}
|
|
|
|
bool PalAnim::fadeStep(int16 oper) {
|
|
bool stop = true;
|
|
byte newRed;
|
|
byte newGreen;
|
|
byte newBlue;
|
|
|
|
if (_vm->_global->_colorCount != 256)
|
|
error("fadeStep: Only 256 color mode is supported!");
|
|
|
|
if (oper == 0) {
|
|
if (_vm->_global->_setAllPalette) {
|
|
if (_vm->_global->_inVM != 0)
|
|
error("fade: _vm->_global->_inVM != 0 not supported.");
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
newRed = fadeColor(_vm->_global->_redPalette[i], _toFadeRed[i]);
|
|
newGreen = fadeColor(_vm->_global->_greenPalette[i], _toFadeGreen[i]);
|
|
newBlue = fadeColor(_vm->_global->_bluePalette[i], _toFadeBlue[i]);
|
|
|
|
if ((_vm->_global->_redPalette[i] != newRed) ||
|
|
(_vm->_global->_greenPalette[i] != newGreen) ||
|
|
(_vm->_global->_bluePalette[i] != newBlue)) {
|
|
|
|
_vm->_video->setPalElem(i, newRed, newGreen, newBlue, 0, 0x13);
|
|
|
|
_vm->_global->_redPalette[i] = newRed;
|
|
_vm->_global->_greenPalette[i] = newGreen;
|
|
_vm->_global->_bluePalette[i] = newBlue;
|
|
stop = false;
|
|
}
|
|
}
|
|
} else {
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
_vm->_video->setPalElem(i,
|
|
fadeColor(_vm->_global->_redPalette[i], _toFadeRed[i]),
|
|
fadeColor(_vm->_global->_greenPalette[i], _toFadeGreen[i]),
|
|
fadeColor(_vm->_global->_bluePalette[i], _toFadeBlue[i]),
|
|
-1, _vm->_global->_videoMode);
|
|
|
|
if ((_vm->_global->_redPalette[i] != _toFadeRed[i]) ||
|
|
(_vm->_global->_greenPalette[i] != _toFadeGreen[i]) ||
|
|
(_vm->_global->_bluePalette[i] != _toFadeBlue[i]))
|
|
stop = false;
|
|
}
|
|
}
|
|
} else if ((oper > 0) && (oper < 4))
|
|
stop = fadeStepColor(oper - 1);
|
|
|
|
return stop;
|
|
}
|
|
|
|
void PalAnim::fade(Video::PalDesc *palDesc, int16 fadeV, int16 allColors) {
|
|
bool stop;
|
|
int16 i;
|
|
|
|
if (_vm->_quitRequested)
|
|
return;
|
|
|
|
_fadeValue = (fadeV < 0) ? -fadeV : 2;
|
|
|
|
if (_vm->_global->_colorCount < 256) {
|
|
if (palDesc)
|
|
_vm->_video->setFullPalette(palDesc);
|
|
return;
|
|
}
|
|
|
|
if (!_vm->_global->_setAllPalette) {
|
|
if (!palDesc) {
|
|
for (i = 0; i < 16; i++) {
|
|
_toFadeRed[i] = 0;
|
|
_toFadeGreen[i] = 0;
|
|
_toFadeBlue[i] = 0;
|
|
}
|
|
} else {
|
|
for (i = 0; i < 16; i++) {
|
|
_toFadeRed[i] = palDesc->vgaPal[i].red;
|
|
_toFadeGreen[i] = palDesc->vgaPal[i].green;
|
|
_toFadeBlue[i] = palDesc->vgaPal[i].blue;
|
|
}
|
|
}
|
|
} else {
|
|
if (_vm->_global->_inVM != 0)
|
|
error("fade: _vm->_global->_inVM != 0 is not supported");
|
|
|
|
if (!palDesc) {
|
|
for (i = 0; i < 256; i++) {
|
|
_toFadeRed[i] = 0;
|
|
_toFadeGreen[i] = 0;
|
|
_toFadeBlue[i] = 0;
|
|
}
|
|
} else {
|
|
for (i = 0; i < 256; i++) {
|
|
_toFadeRed[i] = palDesc->vgaPal[i].red;
|
|
_toFadeGreen[i] = palDesc->vgaPal[i].green;
|
|
_toFadeBlue[i] = palDesc->vgaPal[i].blue;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (allColors == 0) {
|
|
do {
|
|
stop = fadeStep(0);
|
|
_vm->_video->waitRetrace(_vm->_global->_videoMode);
|
|
|
|
if (fadeV > 0)
|
|
_vm->_util->delay(fadeV);
|
|
} while (!stop);
|
|
|
|
if (palDesc)
|
|
_vm->_video->setFullPalette(palDesc);
|
|
else
|
|
_vm->_util->clearPalette();
|
|
}
|
|
|
|
if (allColors == 1) {
|
|
do {
|
|
_vm->_video->waitRetrace(_vm->_global->_videoMode);
|
|
stop = fadeStep(1);
|
|
} while (!stop);
|
|
|
|
do {
|
|
_vm->_video->waitRetrace(_vm->_global->_videoMode);
|
|
stop = fadeStep(2);
|
|
} while (!stop);
|
|
|
|
do {
|
|
_vm->_video->waitRetrace(_vm->_global->_videoMode);
|
|
stop = fadeStep(3);
|
|
} while (!stop);
|
|
|
|
if (palDesc)
|
|
_vm->_video->setFullPalette(palDesc);
|
|
else
|
|
_vm->_util->clearPalette();
|
|
}
|
|
}
|
|
|
|
} // End of namespace Gob
|