2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 The ScummVM project
|
|
|
|
*
|
|
|
|
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Palette animation module
|
2004-05-01 23:42:22 +00:00
|
|
|
#include "saga.h"
|
2004-08-01 11:48:53 +00:00
|
|
|
#include "gfx.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
#include "events_mod.h"
|
|
|
|
#include "game_mod.h"
|
|
|
|
|
|
|
|
#include "palanim_mod.h"
|
|
|
|
#include "palanim.h"
|
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
|
|
|
static PALANIM_DATA PAnimData;
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
int PALANIM_Load(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
|
|
|
|
|
|
|
if (PAnimData.loaded) {
|
|
|
|
PALANIM_Free();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resdata == NULL) {
|
|
|
|
return R_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-08-01 23:24:22 +00:00
|
|
|
MemoryReadStream readS(resdata, resdata_len);
|
2004-05-04 03:33:03 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
if (GAME_GetGameType() == R_GAMETYPE_IHNM) {
|
|
|
|
return R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-08-01 23:24:22 +00:00
|
|
|
PAnimData.entry_count = readS.readUint16LE();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(0, "PALANIM_Load(): Loading %d PALANIM entries.", PAnimData.entry_count);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
test_p = calloc(PAnimData.entry_count, sizeof(PALANIM_ENTRY));
|
|
|
|
if (test_p == NULL) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("PALANIM_Load(): Allocation failure");
|
2004-04-12 21:40:49 +00:00
|
|
|
return R_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
PAnimData.entries = (PALANIM_ENTRY *)test_p;
|
|
|
|
|
|
|
|
for (i = 0; i < PAnimData.entry_count; i++) {
|
|
|
|
int color_count;
|
|
|
|
int pal_count;
|
|
|
|
int p, c;
|
|
|
|
|
2004-08-01 23:24:22 +00:00
|
|
|
color_count = readS.readUint16LE();
|
|
|
|
pal_count = readS.readUint16LE();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
PAnimData.entries[i].pal_count = pal_count;
|
|
|
|
PAnimData.entries[i].color_count = color_count;
|
|
|
|
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(2, "PALANIM_Load(): Entry %d: Loading %d palette indices.\n", i, pal_count);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
test_p = calloc(1, sizeof(char) * pal_count);
|
|
|
|
if (test_p == NULL) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("PALANIM_Load(): Allocation failure");
|
2004-04-12 21:40:49 +00:00
|
|
|
return R_MEM;
|
|
|
|
}
|
|
|
|
|
2004-04-30 23:02:23 +00:00
|
|
|
PAnimData.entries[i].pal_index = (byte *)test_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(2, "PALANIM_Load(): Entry %d: Loading %d SAGA_COLOR structures.", i, color_count);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
test_p = calloc(1, sizeof(R_COLOR) * color_count);
|
|
|
|
if (test_p == NULL) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("PALANIM_Load(): Allocation failure");
|
2004-04-12 21:40:49 +00:00
|
|
|
return R_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
PAnimData.entries[i].colors = (R_COLOR *)test_p;
|
|
|
|
|
|
|
|
for (p = 0; p < pal_count; p++) {
|
2004-08-01 23:24:22 +00:00
|
|
|
PAnimData.entries[i].pal_index[p] = readS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (c = 0; c < color_count; c++) {
|
2004-08-01 23:24:22 +00:00
|
|
|
PAnimData.entries[i].colors[c].red = readS.readByte();
|
|
|
|
PAnimData.entries[i].colors[c].green = readS.readByte();
|
|
|
|
PAnimData.entries[i].colors[c].blue = readS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PAnimData.loaded = 1;
|
|
|
|
return R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
int PALANIM_CycleStart() {
|
2004-04-12 21:40:49 +00:00
|
|
|
R_EVENT event;
|
|
|
|
|
|
|
|
if (!PAnimData.loaded) {
|
|
|
|
return R_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.type = R_ONESHOT_EVENT;
|
|
|
|
event.code = R_PALANIM_EVENT;
|
|
|
|
event.op = EVENT_CYCLESTEP;
|
|
|
|
event.time = PALANIM_CYCLETIME;
|
|
|
|
|
|
|
|
EVENT_Queue(&event);
|
|
|
|
|
|
|
|
return R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
int PALANIM_CycleStep(int vectortime) {
|
2004-04-12 21:40:49 +00:00
|
|
|
R_SURFACE *back_buf;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
R_EVENT event;
|
|
|
|
|
|
|
|
if (!PAnimData.loaded) {
|
|
|
|
return R_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-08-01 11:48:53 +00:00
|
|
|
_vm->_gfx->getCurrentPal(pal);
|
|
|
|
back_buf = _vm->_gfx->getBackBuffer();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < PAnimData.entry_count; i++) {
|
|
|
|
cycle = PAnimData.entries[i].cycle;
|
|
|
|
cycle_limit = PAnimData.entries[i].color_count;
|
|
|
|
for (j = 0; j < PAnimData.entries[i].pal_count; j++) {
|
2004-05-01 13:19:15 +00:00
|
|
|
pal_index = (unsigned char)PAnimData.entries[i].pal_index[j];
|
2004-04-12 21:40:49 +00:00
|
|
|
col_index = (cycle + j) % cycle_limit;
|
2004-05-01 13:19:15 +00:00
|
|
|
pal[pal_index].red = (byte) PAnimData.entries[i].colors[col_index].red;
|
|
|
|
pal[pal_index].green = (byte) PAnimData.entries[i].colors[col_index].green;
|
|
|
|
pal[pal_index].blue = (byte) PAnimData.entries[i].colors[col_index].blue;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PAnimData.entries[i].cycle++;
|
|
|
|
|
|
|
|
if (PAnimData.entries[i].cycle == cycle_limit) {
|
|
|
|
PAnimData.entries[i].cycle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-01 11:48:53 +00:00
|
|
|
_vm->_gfx->setPalette(back_buf, pal);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
event.type = R_ONESHOT_EVENT;
|
|
|
|
event.code = R_PALANIM_EVENT;
|
|
|
|
event.op = EVENT_CYCLESTEP;
|
|
|
|
event.time = vectortime + PALANIM_CYCLETIME;
|
|
|
|
|
|
|
|
EVENT_Queue(&event);
|
|
|
|
|
|
|
|
return R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
int PALANIM_Free() {
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 i;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
if (!PAnimData.loaded) {
|
|
|
|
return R_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < PAnimData.entry_count; i++) {
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(2, "PALANIM_Free(): Entry %d: Freeing colors.", i);
|
2004-04-12 21:40:49 +00:00
|
|
|
free(PAnimData.entries[i].colors);
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(2, "PALANIM_Free(): Entry %d: Freeing indices.", i);
|
2004-04-12 21:40:49 +00:00
|
|
|
free(PAnimData.entries[i].pal_index);
|
|
|
|
}
|
|
|
|
|
2004-05-05 13:05:45 +00:00
|
|
|
debug(0, "PALANIM_Free(): Freeing entries.");
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
free(PAnimData.entries);
|
|
|
|
|
|
|
|
PAnimData.loaded = 0;
|
|
|
|
|
|
|
|
return R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|