2014-02-25 14:21:19 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2014-02-26 00:52:35 +00:00
|
|
|
#include "mads/scene_data.h"
|
2014-02-25 14:21:19 +00:00
|
|
|
#include "mads/mads.h"
|
2014-03-01 01:37:42 +00:00
|
|
|
#include "mads/compression.h"
|
2014-03-14 02:25:16 +00:00
|
|
|
#include "mads/screen.h"
|
2014-02-26 04:10:51 +00:00
|
|
|
#include "mads/resources.h"
|
2014-04-27 18:14:26 +00:00
|
|
|
#include "mads/dragonsphere/dragonsphere_scenes.h"
|
2014-02-25 14:21:19 +00:00
|
|
|
#include "mads/nebular/nebular_scenes.h"
|
2014-04-27 18:14:26 +00:00
|
|
|
#include "mads/phantom/phantom_scenes.h"
|
2014-02-25 14:21:19 +00:00
|
|
|
|
|
|
|
namespace MADS {
|
|
|
|
|
|
|
|
KernelMessage::KernelMessage() {
|
|
|
|
_flags = 0;
|
2014-03-04 04:40:23 +00:00
|
|
|
_sequenceIndex = 0;
|
|
|
|
_color1 = 0;
|
|
|
|
_color2 = 0;
|
2014-02-25 14:21:19 +00:00
|
|
|
_msgOffset = 0;
|
|
|
|
_numTicks = 0;
|
|
|
|
_frameTimer2 = 0;
|
|
|
|
_frameTimer = 0;
|
|
|
|
_timeout = 0;
|
2014-03-28 02:38:28 +00:00
|
|
|
_trigger = 0;
|
2014-04-16 03:51:41 +00:00
|
|
|
_abortMode = SEQUENCE_TRIGGER_PARSER;
|
2014-03-29 21:47:21 +00:00
|
|
|
_actionDetails._verbId = VERB_NONE;
|
2014-03-04 04:40:23 +00:00
|
|
|
_actionDetails._objectNameId = 0;
|
|
|
|
_actionDetails._indirectObjectId = 0;
|
2014-05-28 05:18:14 +00:00
|
|
|
_textDisplayIndex = 0;
|
2014-02-25 14:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
void ARTHeader::load(Common::SeekableReadStream *f, bool isV2) {
|
|
|
|
if (!isV2) {
|
|
|
|
// Read in dimensions of image
|
|
|
|
_width = f->readUint16LE();
|
|
|
|
_height = f->readUint16LE();
|
|
|
|
}
|
2014-02-26 04:10:51 +00:00
|
|
|
|
2014-03-01 01:37:42 +00:00
|
|
|
// Read in palette information
|
|
|
|
int palCount = f->readUint16LE();
|
|
|
|
for (int i = 0; i < palCount; ++i) {
|
2014-02-26 04:10:51 +00:00
|
|
|
RGB6 rgb;
|
2014-03-01 01:37:42 +00:00
|
|
|
rgb.load(f);
|
2014-02-26 04:10:51 +00:00
|
|
|
_palette.push_back(rgb);
|
|
|
|
}
|
2014-03-01 01:37:42 +00:00
|
|
|
f->skip(6 * (256 - palCount));
|
2014-02-26 04:10:51 +00:00
|
|
|
|
2014-04-20 02:49:14 +00:00
|
|
|
// Read palette animations
|
|
|
|
int cycleCount = f->readUint16LE();
|
|
|
|
for (int i = 0; i < cycleCount; ++i) {
|
|
|
|
PaletteCycle cycle;
|
|
|
|
cycle._colorCount = f->readByte();
|
|
|
|
cycle._firstListColor = f->readByte();
|
|
|
|
cycle._firstColorIndex = f->readByte();
|
|
|
|
cycle._ticks = f->readByte();
|
|
|
|
|
|
|
|
_paletteCycles.push_back(cycle);
|
2014-02-26 04:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-03-02 01:19:02 +00:00
|
|
|
void SceneInfo::SpriteInfo::load(Common::SeekableReadStream *f) {
|
|
|
|
f->skip(3);
|
|
|
|
_spriteSetIndex = f->readByte();
|
2015-01-17 21:46:57 +00:00
|
|
|
_frameNumber = f->readSByte();
|
|
|
|
f->skip(1);
|
2014-03-02 01:19:02 +00:00
|
|
|
_position.x = f->readSint16LE();
|
|
|
|
_position.y = f->readSint16LE();
|
|
|
|
_depth = f->readByte();
|
|
|
|
_scale = f->readByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-05-28 19:24:14 +00:00
|
|
|
SceneInfo::SceneInfo(MADSEngine *vm) : _vm(vm) {
|
|
|
|
_sceneId = 0;
|
|
|
|
_artFileNum = 0;
|
|
|
|
_depthStyle = 0;
|
|
|
|
_width = 0;
|
|
|
|
_height = 0;
|
|
|
|
_yBandsEnd = 0;
|
|
|
|
_yBandsStart = 0;
|
|
|
|
_maxScale = 0;
|
|
|
|
_minScale = 0;
|
|
|
|
_field4A = 0;
|
|
|
|
_usageIndex = 0;
|
2015-11-07 16:17:45 +00:00
|
|
|
for (int i = 0; i < DEPTH_BANDS_SIZE; ++i)
|
2014-05-28 19:24:14 +00:00
|
|
|
_depthList[i] = 0;
|
|
|
|
}
|
|
|
|
|
2014-03-02 03:53:08 +00:00
|
|
|
SceneInfo *SceneInfo::init(MADSEngine *vm) {
|
2014-04-27 18:14:26 +00:00
|
|
|
switch (vm->getGameID()) {
|
|
|
|
case GType_RexNebular:
|
2014-03-07 03:31:41 +00:00
|
|
|
return new Nebular::SceneInfoNebular(vm);
|
2014-04-27 18:14:26 +00:00
|
|
|
case GType_Dragonsphere:
|
|
|
|
return new Dragonsphere::SceneInfoDragonsphere(vm);
|
|
|
|
case GType_Phantom:
|
|
|
|
return new Phantom::SceneInfoPhantom(vm);
|
|
|
|
default:
|
|
|
|
error("SceneInfo: Unknown game");
|
2014-03-02 03:53:08 +00:00
|
|
|
}
|
2014-04-27 18:14:26 +00:00
|
|
|
|
|
|
|
return nullptr;
|
2014-02-26 04:10:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-06 02:41:25 +00:00
|
|
|
void SceneInfo::load(int sceneId, int variant, const Common::String &resName,
|
2014-05-25 17:23:05 +00:00
|
|
|
int flags, DepthSurface &depthSurface, MSurface &bgSurface) {
|
2014-02-26 04:10:51 +00:00
|
|
|
bool sceneFlag = sceneId >= 0;
|
2014-05-08 08:43:23 +00:00
|
|
|
|
2014-02-26 04:10:51 +00:00
|
|
|
// Figure out the resource to use
|
|
|
|
Common::String resourceName;
|
|
|
|
if (sceneFlag) {
|
|
|
|
resourceName = Resources::formatName(RESPREFIX_RM, sceneId, ".DAT");
|
|
|
|
} else {
|
|
|
|
resourceName = "*" + Resources::formatResource(resName, resName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the scene info resource for access
|
2014-03-02 01:19:02 +00:00
|
|
|
File infoFile(resourceName);
|
|
|
|
MadsPack infoPack(&infoFile);
|
2014-02-26 04:10:51 +00:00
|
|
|
|
|
|
|
// Read in basic data
|
2014-03-02 01:19:02 +00:00
|
|
|
Common::SeekableReadStream *infoStream = infoPack.getItemStream(0);
|
2015-11-07 16:17:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
byte *data = new byte[infoStream->size()];
|
|
|
|
infoStream->read(data, infoStream->size());
|
|
|
|
Common::hexdump(data, infoStream->size());
|
|
|
|
infoStream->seek(0);
|
|
|
|
delete[] data;
|
|
|
|
*/
|
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
if (_vm->getGameID() == GType_RexNebular) {
|
|
|
|
_sceneId = infoStream->readUint16LE();
|
|
|
|
} else {
|
|
|
|
infoStream->skip(6); // actual scene ID (string)
|
|
|
|
_sceneId = sceneId;
|
|
|
|
}
|
2014-05-08 08:43:23 +00:00
|
|
|
|
2014-07-22 23:46:58 +00:00
|
|
|
int nodeCount = 20;
|
|
|
|
|
|
|
|
if (_vm->getGameID() == GType_RexNebular) {
|
|
|
|
_artFileNum = infoStream->readUint16LE();
|
|
|
|
_depthStyle = infoStream->readUint16LE();
|
|
|
|
_width = infoStream->readUint16LE();
|
|
|
|
_height = infoStream->readUint16LE();
|
|
|
|
|
|
|
|
infoStream->skip(24);
|
|
|
|
} else {
|
|
|
|
_artFileNum = sceneId;
|
|
|
|
_depthStyle = 0;
|
2014-04-27 18:14:26 +00:00
|
|
|
_width = 320;
|
|
|
|
_height = 156;
|
2014-03-02 15:49:20 +00:00
|
|
|
|
2015-11-07 16:17:45 +00:00
|
|
|
infoStream->skip(98);
|
|
|
|
}
|
2015-11-06 20:26:32 +00:00
|
|
|
|
2015-11-07 16:17:45 +00:00
|
|
|
nodeCount = infoStream->readUint16LE();
|
|
|
|
_yBandsEnd = infoStream->readUint16LE();
|
|
|
|
_yBandsStart = infoStream->readUint16LE();
|
|
|
|
_maxScale = infoStream->readUint16LE();
|
|
|
|
_minScale = infoStream->readUint16LE();
|
|
|
|
for (int i = 0; i < DEPTH_BANDS_SIZE; ++i)
|
|
|
|
_depthList[i] = infoStream->readUint16LE();
|
|
|
|
_field4A = infoStream->readUint16LE();
|
|
|
|
|
|
|
|
// HACK for V2 games
|
|
|
|
if (_vm->getGameID() != GType_RexNebular) {
|
|
|
|
_minScale = _maxScale = 100;
|
|
|
|
memset(_depthList, 0, DEPTH_BANDS_SIZE * sizeof(int));
|
2014-07-22 23:46:58 +00:00
|
|
|
}
|
2014-02-26 04:10:51 +00:00
|
|
|
|
2014-07-22 23:46:58 +00:00
|
|
|
// Load the scene's walk nodes
|
2014-02-26 04:10:51 +00:00
|
|
|
for (int i = 0; i < 20; ++i) {
|
2014-03-29 21:12:12 +00:00
|
|
|
WalkNode node;
|
2014-03-02 15:49:20 +00:00
|
|
|
node.load(infoStream);
|
2014-05-08 08:43:23 +00:00
|
|
|
|
2015-11-07 16:17:45 +00:00
|
|
|
if (i < nodeCount) {
|
2014-03-02 15:49:20 +00:00
|
|
|
_nodes.push_back(node);
|
2015-11-07 16:17:45 +00:00
|
|
|
//debug("Node %d: %d,%d", i, node._walkPos.x, node._walkPos.y);
|
|
|
|
}
|
2014-02-26 04:10:51 +00:00
|
|
|
}
|
|
|
|
|
2014-03-02 01:19:02 +00:00
|
|
|
Common::StringArray setNames;
|
|
|
|
Common::Array<SpriteInfo> spriteInfo;
|
2015-11-07 16:17:45 +00:00
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
if (_vm->getGameID() == GType_RexNebular) {
|
2015-11-07 16:17:45 +00:00
|
|
|
int spriteSetsCount = infoStream->readUint16LE();
|
|
|
|
int spriteInfoCount = infoStream->readUint16LE();
|
|
|
|
|
|
|
|
// Load in sprite sets
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
char name[64];
|
|
|
|
infoStream->read(name, 64);
|
|
|
|
|
|
|
|
if (i < spriteSetsCount)
|
|
|
|
setNames.push_back(Common::String(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load in sprite draw information
|
2014-04-27 18:14:26 +00:00
|
|
|
for (int i = 0; i < 50; ++i) {
|
|
|
|
SpriteInfo info;
|
|
|
|
info.load(infoStream);
|
|
|
|
|
|
|
|
if (i < spriteInfoCount)
|
|
|
|
spriteInfo.push_back(info);
|
|
|
|
}
|
2015-11-07 16:17:45 +00:00
|
|
|
} else {
|
|
|
|
uint16 shadowColors = infoStream->readUint16LE();
|
|
|
|
uint16 shadowR = infoStream->readUint16LE();
|
|
|
|
uint16 shadowG = infoStream->readUint16LE();
|
|
|
|
uint16 shadowB = infoStream->readUint16LE();
|
|
|
|
debug("Shadow colors: %d (%d, %d, %d)", shadowColors, shadowR, shadowG, shadowB);
|
2014-03-02 01:19:02 +00:00
|
|
|
}
|
|
|
|
delete infoStream;
|
|
|
|
|
2014-02-26 04:10:51 +00:00
|
|
|
int width = _width;
|
|
|
|
int height = _height;
|
|
|
|
|
2014-10-11 20:27:25 +00:00
|
|
|
if (!bgSurface.getPixels() || (bgSurface.w != width) || (bgSurface.h != height)) {
|
2014-02-26 04:10:51 +00:00
|
|
|
bgSurface.setSize(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_depthStyle == 2)
|
|
|
|
width >>= 2;
|
|
|
|
if (!depthSurface.getPixels()) {
|
|
|
|
depthSurface.setSize(width, height);
|
|
|
|
}
|
|
|
|
|
2014-07-22 23:46:58 +00:00
|
|
|
loadCodes(depthSurface, variant);
|
2014-07-25 01:09:34 +00:00
|
|
|
depthSurface._depthStyle = _depthStyle;
|
2014-03-13 03:45:57 +00:00
|
|
|
infoFile.close();
|
2014-02-26 04:10:51 +00:00
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
if (_vm->getGameID() == GType_RexNebular) {
|
2014-10-10 22:11:48 +00:00
|
|
|
loadMadsV1Background(_artFileNum, resName, flags, bgSurface);
|
2014-09-06 21:55:01 +00:00
|
|
|
loadPalette(_sceneId, _artFileNum, resName, flags, bgSurface);
|
2014-04-27 18:14:26 +00:00
|
|
|
} else {
|
2014-09-06 21:55:01 +00:00
|
|
|
loadMadsV2Background(_sceneId, resName, flags, bgSurface);
|
|
|
|
loadPalette(_sceneId, _sceneId, resName, flags, bgSurface);
|
2014-04-27 18:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Array<SpriteAsset *> spriteSets;
|
|
|
|
Common::Array<int> usageList;
|
|
|
|
|
2014-05-06 01:38:24 +00:00
|
|
|
// TODO: The following isn't quite right for V2 games
|
|
|
|
if (_vm->getGameID() == GType_RexNebular) {
|
|
|
|
for (uint i = 0; i < setNames.size(); ++i) {
|
|
|
|
Common::String setResName;
|
|
|
|
if (sceneFlag || resName.hasPrefix("*"))
|
|
|
|
setResName += "*";
|
|
|
|
setResName += setNames[i];
|
|
|
|
|
|
|
|
SpriteAsset *sprites = new SpriteAsset(_vm, setResName, flags);
|
|
|
|
spriteSets.push_back(sprites);
|
2014-05-08 08:43:23 +00:00
|
|
|
usageList.push_back(sprites->_usageIndex);
|
2014-05-06 01:38:24 +00:00
|
|
|
}
|
2014-04-27 18:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_palette->_paletteUsage.updateUsage(usageList, _usageIndex);
|
|
|
|
|
|
|
|
for (uint i = 0; i < spriteInfo.size(); ++i) {
|
|
|
|
SpriteInfo &si = spriteInfo[i];
|
|
|
|
SpriteAsset *asset = spriteSets[si._spriteSetIndex];
|
|
|
|
assert(asset && _depthStyle != 2);
|
|
|
|
|
2015-01-17 21:46:57 +00:00
|
|
|
MSprite *spr = asset->getFrame(si._frameNumber);
|
2014-10-28 14:19:26 +00:00
|
|
|
bgSurface.copyFrom(spr, si._position, si._depth, &depthSurface,
|
2015-01-17 22:29:08 +00:00
|
|
|
si._scale, false, spr->getTransparencyIndex());
|
2014-04-27 18:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Free the sprite sets
|
|
|
|
for (int i = (int)spriteSets.size() - 1; i >= 0; --i) {
|
2014-05-30 01:35:59 +00:00
|
|
|
_vm->_palette->_paletteUsage.resetPalFlags(spriteSets[i]->_usageIndex);
|
2014-04-27 18:14:26 +00:00
|
|
|
delete spriteSets[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneInfo::loadPalette(int sceneId, int artFileNum, const Common::String &resName, int flags, MSurface &bgSurface) {
|
|
|
|
bool sceneFlag = sceneId >= 0;
|
|
|
|
Common::String resourceName;
|
|
|
|
bool isV2 = (_vm->getGameID() != GType_RexNebular);
|
|
|
|
Common::String extension = !isV2 ? ".ART" : ".TT";
|
|
|
|
int paletteStream = !isV2 ? 0 : 2;
|
|
|
|
|
2014-02-26 04:10:51 +00:00
|
|
|
// Get the ART resource
|
|
|
|
if (sceneFlag) {
|
2014-04-27 18:14:26 +00:00
|
|
|
resourceName = Resources::formatName(RESPREFIX_RM, artFileNum, extension);
|
2014-02-26 04:10:51 +00:00
|
|
|
} else {
|
|
|
|
resourceName = "*" + Resources::formatResource(resName, resName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load in the ART header and palette
|
|
|
|
File artFile(resourceName);
|
2014-03-01 01:37:42 +00:00
|
|
|
MadsPack artResource(&artFile);
|
2014-04-27 18:14:26 +00:00
|
|
|
Common::SeekableReadStream *stream = artResource.getItemStream(paletteStream);
|
2014-03-01 01:37:42 +00:00
|
|
|
|
2014-02-26 04:10:51 +00:00
|
|
|
ARTHeader artHeader;
|
2014-04-27 18:14:26 +00:00
|
|
|
artHeader.load(stream, isV2);
|
2014-03-02 01:19:02 +00:00
|
|
|
delete stream;
|
2014-02-26 04:10:51 +00:00
|
|
|
|
2014-04-20 02:49:14 +00:00
|
|
|
// Copy out the palette animation data
|
2014-10-13 13:03:50 +00:00
|
|
|
_paletteCycles.clear();
|
2014-04-20 02:49:14 +00:00
|
|
|
for (uint i = 0; i < artHeader._paletteCycles.size(); ++i)
|
|
|
|
_paletteCycles.push_back(artHeader._paletteCycles[i]);
|
2014-03-01 01:37:42 +00:00
|
|
|
|
2014-02-26 04:10:51 +00:00
|
|
|
if (!(flags & 1)) {
|
2014-03-01 01:37:42 +00:00
|
|
|
if (!_vm->_palette->_paletteUsage.empty()) {
|
|
|
|
_vm->_palette->_paletteUsage.getKeyEntries(artHeader._palette);
|
|
|
|
_vm->_palette->_paletteUsage.prioritize(artHeader._palette);
|
|
|
|
}
|
|
|
|
|
2014-05-08 08:43:23 +00:00
|
|
|
_usageIndex = _vm->_palette->_paletteUsage.process(artHeader._palette,
|
2014-03-11 02:08:55 +00:00
|
|
|
(flags & 0xF800) | 0x8000);
|
2014-03-10 05:00:11 +00:00
|
|
|
if (_usageIndex > 0) {
|
2014-03-01 01:37:42 +00:00
|
|
|
_vm->_palette->_paletteUsage.transform(artHeader._palette);
|
|
|
|
|
2014-04-20 02:49:14 +00:00
|
|
|
for (uint i = 0; i < _paletteCycles.size(); ++i) {
|
|
|
|
byte listColor = _paletteCycles[i]._firstListColor;
|
|
|
|
_paletteCycles[i]._firstColorIndex = artHeader._palette[listColor]._palIndex;
|
2014-03-01 01:37:42 +00:00
|
|
|
}
|
2014-02-26 04:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-01 01:37:42 +00:00
|
|
|
|
2014-03-15 18:08:43 +00:00
|
|
|
if (!(flags & 1)) {
|
|
|
|
// Translate the background to use the correct palette indexes
|
|
|
|
bgSurface.translate(artHeader._palette);
|
|
|
|
}
|
2014-04-27 18:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneInfo::loadMadsV1Background(int sceneId, const Common::String &resName, int flags, MSurface &bgSurface) {
|
|
|
|
bool sceneFlag = sceneId >= 0;
|
|
|
|
Common::String resourceName;
|
|
|
|
Common::SeekableReadStream *stream;
|
|
|
|
|
|
|
|
// Get the ART resource
|
|
|
|
if (sceneFlag) {
|
2014-09-06 20:39:49 +00:00
|
|
|
resourceName = Resources::formatName(RESPREFIX_RM, sceneId, ".ART");
|
2014-04-27 18:14:26 +00:00
|
|
|
} else {
|
|
|
|
resourceName = "*" + Resources::formatResource(resName, resName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load in the ART data
|
|
|
|
File artFile(resourceName);
|
|
|
|
MadsPack artResource(&artFile);
|
|
|
|
|
2014-10-11 20:27:25 +00:00
|
|
|
// Read inhh the background surface data
|
|
|
|
assert(_width && _height == bgSurface.h);
|
2014-04-27 18:14:26 +00:00
|
|
|
stream = artResource.getItemStream(1);
|
|
|
|
stream->read(bgSurface.getPixels(), bgSurface.w * bgSurface.h);
|
2014-09-06 20:39:49 +00:00
|
|
|
delete stream;
|
|
|
|
|
|
|
|
if (flags & SCENEFLAG_TRANSLATE) {
|
|
|
|
// Load in the palette and translate it
|
|
|
|
Common::SeekableReadStream *palStream = artResource.getItemStream(0);
|
|
|
|
Common::Array<RGB6> palette;
|
|
|
|
|
2014-10-11 20:27:25 +00:00
|
|
|
_width = palStream->readUint16LE();
|
|
|
|
_height = palStream->readUint16LE();
|
|
|
|
|
2014-09-06 20:39:49 +00:00
|
|
|
int numColors = palStream->readUint16LE();
|
|
|
|
assert(numColors <= 252);
|
|
|
|
palette.resize(numColors);
|
|
|
|
for (int i = 0; i < numColors; ++i)
|
|
|
|
palette[i].load(palStream);
|
|
|
|
delete palStream;
|
|
|
|
|
|
|
|
// Translate the surface
|
|
|
|
_vm->_palette->_paletteUsage.process(palette, 0);
|
|
|
|
bgSurface.translate(palette);
|
|
|
|
}
|
2014-03-15 18:08:43 +00:00
|
|
|
|
2014-03-02 03:53:08 +00:00
|
|
|
// Close the ART file
|
|
|
|
artFile.close();
|
2014-04-27 18:14:26 +00:00
|
|
|
}
|
2014-03-02 03:53:08 +00:00
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
void SceneInfo::loadMadsV2Background(int sceneId, const Common::String &resName, int flags, MSurface &bgSurface) {
|
|
|
|
Common::String tileMapResourceName = Resources::formatName(RESPREFIX_RM, sceneId, ".MM");
|
|
|
|
File tileMapFile(tileMapResourceName);
|
|
|
|
MadsPack tileMapPack(&tileMapFile);
|
|
|
|
Common::SeekableReadStream *mapStream = tileMapPack.getItemStream(0);
|
|
|
|
|
|
|
|
// Get the details of the tiles and map
|
|
|
|
mapStream->readUint32LE();
|
|
|
|
int tileCountX = mapStream->readUint16LE();
|
|
|
|
int tileCountY = mapStream->readUint16LE();
|
|
|
|
int tileWidthMap = mapStream->readUint16LE();
|
|
|
|
int tileHeightMap = mapStream->readUint16LE();
|
|
|
|
int screenWidth = mapStream->readUint16LE();
|
|
|
|
int screenHeight = mapStream->readUint16LE();
|
|
|
|
int tileCountMap = tileCountX * tileCountY;
|
|
|
|
delete mapStream;
|
|
|
|
|
|
|
|
// Obtain tile map information
|
|
|
|
typedef Common::List<Common::SharedPtr<MSurface> > TileSetList;
|
|
|
|
typedef TileSetList::iterator TileSetIterator;
|
|
|
|
TileSetList tileSet;
|
|
|
|
uint16 *tileMap = new uint16[tileCountMap];
|
|
|
|
mapStream = tileMapPack.getItemStream(1);
|
|
|
|
for (int i = 0; i < tileCountMap; ++i)
|
|
|
|
tileMap[i] = mapStream->readUint16LE();
|
|
|
|
delete mapStream;
|
|
|
|
tileMapFile.close();
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Tile data, which needs to be kept compressed, as the tile map offsets refer to
|
|
|
|
// the compressed data. Each tile is then uncompressed separately
|
|
|
|
Common::String tileDataResourceName = Resources::formatName(RESPREFIX_RM, sceneId, ".TT");
|
|
|
|
File tileDataFile(tileDataResourceName);
|
|
|
|
MadsPack tileDataPack(&tileDataFile);
|
|
|
|
Common::SeekableReadStream *tileDataUncomp = tileDataPack.getItemStream(0);
|
|
|
|
|
|
|
|
// Validate that the data matches between the tiles and tile map file and is valid
|
|
|
|
int tileCount = tileDataUncomp->readUint16LE();
|
|
|
|
int tileWidth = tileDataUncomp->readUint16LE();
|
|
|
|
int tileHeight = tileDataUncomp->readUint16LE();
|
|
|
|
delete tileDataUncomp;
|
|
|
|
assert(tileCountMap == tileCount);
|
|
|
|
assert(tileWidth == tileWidthMap);
|
|
|
|
assert(tileHeight == tileHeightMap);
|
|
|
|
assert(screenWidth == _width);
|
|
|
|
assert(screenHeight <= _height);
|
|
|
|
|
2015-10-21 23:14:41 +00:00
|
|
|
// Resize the background surface to hold all of the tiles
|
|
|
|
uint16 newWidth = bgSurface.w;
|
|
|
|
uint16 newHeight = bgSurface.h;
|
|
|
|
|
|
|
|
if (tileWidth < screenWidth && bgSurface.w != tileCount * tileWidth)
|
|
|
|
newWidth = tileCount * tileWidth;
|
|
|
|
if (tileHeight < screenHeight && bgSurface.h != tileCount * tileHeight)
|
|
|
|
newHeight = tileCount * tileHeight;
|
|
|
|
|
|
|
|
if (bgSurface.w != newWidth || bgSurface.h != newHeight)
|
|
|
|
bgSurface.setSize(newWidth, newHeight);
|
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
// --------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Get tile data
|
|
|
|
|
|
|
|
tileDataUncomp = tileDataPack.getItemStream(1);
|
|
|
|
FabDecompressor fab;
|
|
|
|
uint32 compressedTileDataSize = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < tileCount; i++) {
|
|
|
|
tileDataUncomp->seek(i * 4, SEEK_SET);
|
|
|
|
uint32 tileOfs = tileDataUncomp->readUint32LE();
|
|
|
|
MSurface* newTile = new MSurface(tileWidth, tileHeight);
|
|
|
|
|
|
|
|
if (i == tileCount - 1)
|
|
|
|
compressedTileDataSize = tileDataFile.size() - tileOfs;
|
|
|
|
else
|
|
|
|
compressedTileDataSize = tileDataUncomp->readUint32LE() - tileOfs;
|
|
|
|
|
|
|
|
//debugCN(kDebugGraphics, "Tile: %i, compressed size: %i\n", i, compressedTileDataSize);
|
|
|
|
|
|
|
|
newTile->empty();
|
|
|
|
|
|
|
|
byte *compressedTileData = new byte[compressedTileDataSize];
|
|
|
|
|
|
|
|
tileDataFile.seek(tileDataPack.getDataOffset() + tileOfs, SEEK_SET);
|
|
|
|
tileDataFile.read(compressedTileData, compressedTileDataSize);
|
|
|
|
|
|
|
|
fab.decompress(compressedTileData, compressedTileDataSize, (byte*)newTile->getPixels(), tileWidth * tileHeight);
|
|
|
|
tileSet.push_back(TileSetList::value_type(newTile));
|
|
|
|
delete[] compressedTileData;
|
2014-03-01 01:37:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
delete tileDataUncomp;
|
2014-03-02 01:19:02 +00:00
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
// --------------------------------------------------------------------------------
|
2014-03-01 01:37:42 +00:00
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
// Loop through the mapping data to place the tiles on the screen
|
2014-03-01 01:37:42 +00:00
|
|
|
|
2014-04-27 18:14:26 +00:00
|
|
|
uint16 *tIndex = &tileMap[0];
|
|
|
|
for (int y = 0; y < tileCountY; y++) {
|
|
|
|
for (int x = 0; x < tileCountX; x++) {
|
|
|
|
int tileIndex = *tIndex++;
|
|
|
|
assert(tileIndex < tileCount);
|
|
|
|
TileSetIterator tile = tileSet.begin();
|
|
|
|
for (int i = 0; i < tileIndex; i++)
|
|
|
|
++tile;
|
|
|
|
((*tile).get())->copyTo(&bgSurface, Common::Point(x * tileWidth, y * tileHeight));
|
2015-04-09 11:08:48 +00:00
|
|
|
((*tile).get())->free();
|
2014-04-27 18:14:26 +00:00
|
|
|
}
|
2014-03-02 01:19:02 +00:00
|
|
|
}
|
2014-04-27 18:14:26 +00:00
|
|
|
tileSet.clear();
|
|
|
|
tileDataFile.close();
|
2015-11-24 18:10:11 +00:00
|
|
|
|
|
|
|
delete[] tileMap;
|
2014-02-26 04:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-03-06 02:36:02 +00:00
|
|
|
SceneLogic::SceneLogic(MADSEngine *vm) : _vm(vm) {
|
|
|
|
_scene = &_vm->_game->_scene;
|
|
|
|
}
|
|
|
|
|
2014-02-25 14:21:19 +00:00
|
|
|
} // End of namespace MADS
|