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) {
|
|
|
|
_loaded = false;
|
|
|
|
_entryCount = 0;
|
|
|
|
_entries = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PalAnim::~PalAnim(void) {
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
int PalAnim::loadPalAnim(const byte *resdata, size_t resdata_len) {
|
2004-04-12 21:40:49 +00:00
|
|
|
void *test_p;
|
|
|
|
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 i;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
if (_loaded) {
|
|
|
|
freePalAnim();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resdata == NULL) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
MemoryReadStreamEndian readS(resdata, resdata_len, _vm->isBigEndian());
|
2004-05-04 03:33:03 +00:00
|
|
|
|
2005-01-11 21:10:36 +00:00
|
|
|
if (_vm->getGameType() == GType_IHNM) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
_entryCount = readS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-05 16:58:36 +00:00
|
|
|
debug(3, "PalAnim::loadPalAnim(): Loading %d PALANIM entries.", _entryCount);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-05-26 11:10:46 +00:00
|
|
|
test_p = malloc(_entryCount * sizeof(PalanimEntry));
|
2005-08-10 15:01:23 +00:00
|
|
|
_entries = (PalanimEntry *)test_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
for (i = 0; i < _entryCount; i++) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int color_count;
|
|
|
|
int pal_count;
|
|
|
|
int p, c;
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
color_count = readS.readUint16();
|
|
|
|
pal_count = readS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
_entries[i].pal_count = pal_count;
|
|
|
|
_entries[i].color_count = color_count;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
debug(2, "PalAnim::loadPalAnim(): Entry %d: Loading %d palette indices.\n", i, pal_count);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-05-26 11:10:46 +00:00
|
|
|
test_p = malloc(sizeof(char) * pal_count);
|
2004-08-10 19:20:33 +00:00
|
|
|
_entries[i].pal_index = (byte *)test_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
debug(2, "PalAnim::loadPalAnim(): Entry %d: Loading %d SAGA_COLOR structures.", i, color_count);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-05-26 11:10:46 +00:00
|
|
|
test_p = malloc(sizeof(Color) * color_count);
|
2005-07-09 16:23:45 +00:00
|
|
|
_entries[i].colors = (Color *)test_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
for (p = 0; p < pal_count; p++) {
|
2004-08-10 19:20:33 +00:00
|
|
|
_entries[i].pal_index[p] = readS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (c = 0; c < color_count; c++) {
|
2004-08-10 19:20:33 +00:00
|
|
|
_entries[i].colors[c].red = readS.readByte();
|
|
|
|
_entries[i].colors[c].green = readS.readByte();
|
|
|
|
_entries[i].colors[c].blue = readS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
_loaded = true;
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
int PalAnim::cycleStart() {
|
2005-08-10 14:11:22 +00:00
|
|
|
Event event;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
if (!_loaded) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
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;
|
2004-08-10 19:00:30 +00:00
|
|
|
_vm->_events->queue(&event);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
int PalAnim::cycleStep(int vectortime) {
|
2005-07-09 16:23:45 +00:00
|
|
|
static PalEntry pal[256];
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 pal_index;
|
|
|
|
uint16 col_index;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 i, j;
|
|
|
|
uint16 cycle;
|
|
|
|
uint16 cycle_limit;
|
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
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
if (!_loaded) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
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
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
for (i = 0; i < _entryCount; i++) {
|
|
|
|
cycle = _entries[i].cycle;
|
|
|
|
cycle_limit = _entries[i].color_count;
|
|
|
|
for (j = 0; j < _entries[i].pal_count; j++) {
|
|
|
|
pal_index = (unsigned char)_entries[i].pal_index[j];
|
2004-04-12 21:40:49 +00:00
|
|
|
col_index = (cycle + j) % cycle_limit;
|
2004-08-10 19:20:33 +00:00
|
|
|
pal[pal_index].red = (byte) _entries[i].colors[col_index].red;
|
|
|
|
pal[pal_index].green = (byte) _entries[i].colors[col_index].green;
|
|
|
|
pal[pal_index].blue = (byte) _entries[i].colors[col_index].blue;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
_entries[i].cycle++;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
if (_entries[i].cycle == cycle_limit) {
|
|
|
|
_entries[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;
|
2004-08-10 19:00:30 +00:00
|
|
|
_vm->_events->queue(&event);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
int PalAnim::freePalAnim() {
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 i;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
if (!_loaded) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
for (i = 0; i < _entryCount; i++) {
|
|
|
|
debug(2, "PalAnim::freePalAnim(): Entry %d: Freeing colors.", i);
|
|
|
|
free(_entries[i].colors);
|
|
|
|
debug(2, "PalAnim::freePalAnim(): Entry %d: Freeing indices.", i);
|
|
|
|
free(_entries[i].pal_index);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-05 16:58:36 +00:00
|
|
|
debug(3, "PalAnim::freePalAnim(): Freeing entries.");
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
free(_entries);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-10 19:20:33 +00:00
|
|
|
_loaded = false;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|