2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-12 21:40:49 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Palette animation module
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
|
|
|
#include "saga/gfx.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:00:30 +00:00
|
|
|
#include "saga/events.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/palanim.h"
|
2008-02-23 13:36:40 +00:00
|
|
|
#include "saga/interface.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
PalAnim::PalAnim(SagaEngine *vm) : _vm(vm) {
|
|
|
|
}
|
|
|
|
|
2010-10-24 22:17:44 +00:00
|
|
|
void PalAnim::loadPalAnim(const ByteArray &resourceData) {
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
clear();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-24 22:17:44 +00:00
|
|
|
if (resourceData.empty()) {
|
2010-10-22 23:13:17 +00:00
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-24 22:17:44 +00:00
|
|
|
ByteArrayReadStreamEndian readS(resourceData, _vm->isBigEndian());
|
2004-05-04 03:33:03 +00:00
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM) {
|
2010-10-22 23:13:17 +00:00
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
_entries.resize(readS.readUint16());
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
debug(3, "PalAnim::loadPalAnim(): Loading %d PALANIM entries.", _entries.size());
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
for (Common::Array<PalanimEntry>::iterator i = _entries.begin(); i != _entries.end(); ++i) {
|
|
|
|
|
|
|
|
i->cycle = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
i->colors.resize(readS.readUint16());
|
|
|
|
debug(2, "PalAnim::loadPalAnim(): Loading %d SAGA_COLOR structures.", i->colors.size());
|
2009-03-24 05:35:48 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
i->palIndex.resize(readS.readUint16());
|
|
|
|
debug(2, "PalAnim::loadPalAnim(): Loading %d palette indices.\n", i->palIndex.size());
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
for (uint j = 0; j < i->palIndex.size(); j++) {
|
|
|
|
i->palIndex[j] = readS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
for (Common::Array<Color>::iterator j = i->colors.begin(); j != i->colors.end(); ++j) {
|
|
|
|
j->red = readS.readByte();
|
|
|
|
j->green = readS.readByte();
|
|
|
|
j->blue = readS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
void PalAnim::cycleStart() {
|
2005-08-10 14:11:22 +00:00
|
|
|
Event event;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
if (_entries.empty()) {
|
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-08-10 15:31:15 +00:00
|
|
|
event.type = kEvTOneshot;
|
|
|
|
event.code = kPalAnimEvent;
|
|
|
|
event.op = kEventCycleStep;
|
2004-04-12 21:40:49 +00:00
|
|
|
event.time = PALANIM_CYCLETIME;
|
2010-10-23 23:07:10 +00:00
|
|
|
_vm->_events->queue(event);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
void PalAnim::cycleStep(int vectortime) {
|
2005-07-09 16:23:45 +00:00
|
|
|
static PalEntry pal[256];
|
2010-10-22 23:13:17 +00:00
|
|
|
uint16 palIndex;
|
|
|
|
uint16 colIndex;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
uint16 j;
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 cycle;
|
2010-10-22 23:13:17 +00:00
|
|
|
uint16 cycleLimit;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-10 14:11:22 +00:00
|
|
|
Event event;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
if (_entries.empty()) {
|
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-01 11:48:53 +00:00
|
|
|
_vm->_gfx->getCurrentPal(pal);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
for (Common::Array<PalanimEntry>::iterator i = _entries.begin(); i != _entries.end(); ++i) {
|
|
|
|
cycle = i->cycle;
|
|
|
|
cycleLimit = i->colors.size();
|
|
|
|
for (j = 0; j < i->palIndex.size(); j++) {
|
|
|
|
palIndex = i->palIndex[j];
|
|
|
|
colIndex = (cycle + j) % cycleLimit;
|
|
|
|
pal[palIndex].red = (byte) i->colors[colIndex].red;
|
|
|
|
pal[palIndex].green = (byte) i->colors[colIndex].green;
|
|
|
|
pal[palIndex].blue = (byte) i->colors[colIndex].blue;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
i->cycle++;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
if (i->cycle == cycleLimit) {
|
|
|
|
i->cycle = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-23 13:36:40 +00:00
|
|
|
// Don't cycle the palette when the map is open
|
|
|
|
// Fixes bug #1900258 - "ITE: Glitch when looking at the map while at the docks"
|
|
|
|
if (_vm->_interface->getMode() != kPanelMap)
|
|
|
|
_vm->_gfx->setPalette(pal);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-10 15:31:15 +00:00
|
|
|
event.type = kEvTOneshot;
|
|
|
|
event.code = kPalAnimEvent;
|
|
|
|
event.op = kEventCycleStep;
|
2004-04-12 21:40:49 +00:00
|
|
|
event.time = vectortime + PALANIM_CYCLETIME;
|
2010-10-23 23:07:10 +00:00
|
|
|
_vm->_events->queue(event);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-22 23:13:17 +00:00
|
|
|
void PalAnim::clear() {
|
|
|
|
debug(3, "PalAnim::clear()");
|
|
|
|
|
|
|
|
_entries.clear();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|