2013-05-20 02:45:54 +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 "voyeur/files.h"
|
2013-05-26 00:51:53 +00:00
|
|
|
#include "voyeur/graphics.h"
|
|
|
|
#include "voyeur/voyeur.h"
|
2013-12-10 14:19:54 +00:00
|
|
|
#include "voyeur/staticres.h"
|
2013-05-20 02:45:54 +00:00
|
|
|
|
|
|
|
namespace Voyeur {
|
|
|
|
|
|
|
|
#define BOLT_GROUP_SIZE 16
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
BoltFilesState::BoltFilesState() {
|
|
|
|
_curLibPtr = NULL;
|
|
|
|
_curGroupPtr = NULL;
|
|
|
|
_curMemberPtr = NULL;
|
|
|
|
_curMemInfoPtr = NULL;
|
|
|
|
_fromGroupFlag = 0;
|
|
|
|
_xorMask = 0;
|
|
|
|
_encrypt = false;
|
2013-05-20 02:45:54 +00:00
|
|
|
_curFilePosition = 0;
|
2013-05-25 19:36:57 +00:00
|
|
|
_bufferEnd = 0;
|
|
|
|
_bufferBegin = 0;
|
|
|
|
_bytesLeft = 0;
|
|
|
|
_bufSize = 0;
|
|
|
|
_bufStart = NULL;
|
|
|
|
_bufPos = NULL;
|
2013-05-22 04:00:47 +00:00
|
|
|
_historyIndex = 0;
|
2013-05-25 19:36:57 +00:00
|
|
|
_runLength = 0;
|
|
|
|
_decompState = 0;
|
|
|
|
_runType = 0;
|
|
|
|
_runValue = 0;
|
|
|
|
_runOffset = 0;
|
|
|
|
Common::fill(&_historyBuffer[0], &_historyBuffer[0x200], 0);
|
2013-05-26 00:51:53 +00:00
|
|
|
_curFd = NULL;
|
|
|
|
_boltPageFrame = NULL;
|
2013-05-22 02:07:17 +00:00
|
|
|
}
|
|
|
|
|
2013-06-08 00:15:26 +00:00
|
|
|
#define NEXT_BYTE if (--_bytesLeft < 0) nextBlock()
|
2013-05-22 02:07:17 +00:00
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
byte *BoltFilesState::decompress(byte *buf, int size, int mode) {
|
2013-06-07 03:48:46 +00:00
|
|
|
if (!buf) {
|
2013-05-22 02:07:17 +00:00
|
|
|
buf = new byte[size];
|
2013-06-07 03:48:46 +00:00
|
|
|
Common::fill(buf, buf + size, 0);
|
|
|
|
}
|
2013-05-22 02:07:17 +00:00
|
|
|
byte *bufP = buf;
|
|
|
|
|
|
|
|
if (mode & 8) {
|
|
|
|
_decompState = 1;
|
|
|
|
_runType = 0;
|
|
|
|
_runLength = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (size > 0) {
|
|
|
|
if (!_decompState) {
|
|
|
|
NEXT_BYTE;
|
|
|
|
byte nextByte = *_bufPos++;
|
|
|
|
|
|
|
|
switch (nextByte & 0xC0) {
|
|
|
|
case 0:
|
|
|
|
_runType = 0;
|
|
|
|
_runLength = 30 - (nextByte & 0x1f) + 1;
|
|
|
|
break;
|
|
|
|
case 0x40:
|
|
|
|
_runType = 1;
|
|
|
|
_runLength = 35 - (nextByte & 0x1f);
|
|
|
|
NEXT_BYTE;
|
|
|
|
_runOffset = *_bufPos++ + ((nextByte & 0x20) << 3);
|
|
|
|
break;
|
|
|
|
case 0x80:
|
|
|
|
_runType = 1;
|
|
|
|
_runLength = (nextByte & 0x20) ? ((32 - (nextByte & 0x1f)) << 2) + 2 :
|
|
|
|
(32 - (nextByte & 0x1f)) << 2;
|
|
|
|
NEXT_BYTE;
|
|
|
|
_runOffset = *_bufPos++ << 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_runType = 2;
|
|
|
|
|
|
|
|
if (nextByte & 0x20) {
|
|
|
|
_runLength = 0;
|
|
|
|
} else {
|
|
|
|
NEXT_BYTE;
|
|
|
|
_runLength = ((32 - (nextByte & 0x1f)) + (*_bufPos++ << 5)) << 2;
|
|
|
|
NEXT_BYTE;
|
|
|
|
_bufPos++;
|
|
|
|
NEXT_BYTE;
|
|
|
|
_runValue = *_bufPos++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_runOffset = _historyIndex - _runOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
int runOffset = _runOffset & 0x1ff;
|
|
|
|
int len;
|
|
|
|
if (_runLength <= size) {
|
|
|
|
len = _runLength;
|
|
|
|
_decompState = 0;
|
|
|
|
} else {
|
|
|
|
_decompState = 1;
|
2013-06-07 03:48:46 +00:00
|
|
|
len = size;
|
|
|
|
_runLength -= size;
|
2013-05-22 02:07:17 +00:00
|
|
|
if (_runType == 1)
|
|
|
|
_runOffset += len;
|
|
|
|
}
|
|
|
|
|
2013-05-22 04:00:47 +00:00
|
|
|
// Reduce the remaining size
|
|
|
|
size -= len;
|
|
|
|
|
2013-05-22 02:07:17 +00:00
|
|
|
// Handle the run lengths
|
|
|
|
switch (_runType) {
|
|
|
|
case 0:
|
|
|
|
while (len-- > 0) {
|
|
|
|
NEXT_BYTE;
|
2013-05-26 00:51:53 +00:00
|
|
|
byte v = *_bufPos++;
|
|
|
|
_historyBuffer[_historyIndex] = v;
|
|
|
|
*bufP++ = v;
|
2013-05-22 02:07:17 +00:00
|
|
|
_historyIndex = (_historyIndex + 1) & 0x1ff;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
while (len-- > 0) {
|
|
|
|
_historyBuffer[_historyIndex] = _historyBuffer[runOffset];
|
|
|
|
*bufP++ = _historyBuffer[runOffset];
|
|
|
|
_historyIndex = (_historyIndex + 1) & 0x1ff;
|
2013-05-26 00:51:53 +00:00
|
|
|
runOffset = (runOffset + 1) & 0x1ff;
|
2013-05-22 02:07:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
while (len-- > 0) {
|
|
|
|
_historyBuffer[_historyIndex] = _runValue;
|
2013-05-22 04:00:47 +00:00
|
|
|
*bufP++ = _runValue;
|
2013-05-22 02:07:17 +00:00
|
|
|
_historyIndex = (_historyIndex + 1) & 0x1ff;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
#undef NEXT_BYTE
|
|
|
|
|
|
|
|
void BoltFilesState::nextBlock() {
|
2013-12-15 22:51:47 +00:00
|
|
|
if (&_curLibPtr->_file != _curFd || _curFilePosition != _bufferEnd)
|
|
|
|
_curLibPtr->_file.seek(_bufferEnd);
|
2013-05-22 02:07:17 +00:00
|
|
|
|
2013-12-15 22:51:47 +00:00
|
|
|
_curFd = &_curLibPtr->_file;
|
2013-05-22 03:15:43 +00:00
|
|
|
_bufferBegin = _bufferEnd;
|
2013-05-26 00:51:53 +00:00
|
|
|
int bytesRead = _curFd->read(_bufStart, _bufSize);
|
2013-05-22 02:07:17 +00:00
|
|
|
|
|
|
|
_bufferEnd = _curFilePosition = _bufferBegin + bytesRead;
|
2013-05-22 03:15:43 +00:00
|
|
|
_bytesLeft = bytesRead - 1;
|
2013-05-22 02:07:17 +00:00
|
|
|
_bufPos = _bufStart;
|
|
|
|
}
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
FilesManager::FilesManager() {
|
|
|
|
_decompressSize = 0x7000;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FilesManager::openBoltLib(const Common::String &filename, BoltFile *&boltFile) {
|
|
|
|
if (boltFile != NULL) {
|
|
|
|
_boltFilesState._curLibPtr = boltFile;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the bolt file interface object and load the index
|
2013-12-08 01:44:28 +00:00
|
|
|
if (filename == "bvoy.blt")
|
|
|
|
boltFile = _boltFilesState._curLibPtr = new BVoyBoltFile(_boltFilesState);
|
|
|
|
else if (filename == "stampblt.blt")
|
|
|
|
boltFile = _boltFilesState._curLibPtr = new StampBoltFile(_boltFilesState);
|
|
|
|
else
|
|
|
|
error("Unknown bolt file specified");
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-11 01:29:12 +00:00
|
|
|
byte *FilesManager::fload(const Common::String &filename, int *size) {
|
|
|
|
Common::File f;
|
|
|
|
int filesize;
|
|
|
|
byte *data = NULL;
|
|
|
|
|
|
|
|
if (f.open(filename)) {
|
|
|
|
// Read in the file
|
|
|
|
filesize = f.size();
|
|
|
|
data = new byte[filesize];
|
|
|
|
f.read(data, filesize);
|
|
|
|
} else {
|
|
|
|
filesize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
*size = filesize;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
BoltFile::BoltFile(const Common::String &filename, BoltFilesState &state): _state(state) {
|
|
|
|
if (!_file.open(filename))
|
|
|
|
error("Could not open %s", filename.c_str());
|
2013-05-25 19:36:57 +00:00
|
|
|
_state._curFilePosition = 0;
|
|
|
|
|
|
|
|
// Read in the file header
|
|
|
|
byte header[16];
|
2013-05-26 00:51:53 +00:00
|
|
|
_file.read(&header[0], 16);
|
2013-05-25 19:36:57 +00:00
|
|
|
|
|
|
|
if (strncmp((const char *)&header[0], "BOLT", 4) != 0)
|
|
|
|
error("Tried to load non-bolt file");
|
|
|
|
|
|
|
|
int totalGroups = header[11] ? header[11] : 0x100;
|
|
|
|
for (int i = 0; i < totalGroups; ++i)
|
2013-12-15 22:51:47 +00:00
|
|
|
_groups.push_back(BoltGroup(&_file));
|
2013-05-25 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BoltFile::~BoltFile() {
|
2013-12-08 23:23:40 +00:00
|
|
|
_file.close();
|
|
|
|
if (_state._curFd == &_file)
|
|
|
|
_state._curFd = NULL;
|
2013-12-15 22:51:47 +00:00
|
|
|
if (_state._curLibPtr == this)
|
|
|
|
_state._curLibPtr = NULL;
|
2013-05-25 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-15 20:08:25 +00:00
|
|
|
BoltGroup *BoltFile::getBoltGroup(uint16 id, bool process) {
|
2013-05-25 19:36:57 +00:00
|
|
|
++_state._fromGroupFlag;
|
|
|
|
_state._curLibPtr = this;
|
|
|
|
_state._curGroupPtr = &_groups[(id >> 8) & 0xff];
|
|
|
|
|
|
|
|
if (!_state._curGroupPtr->_loaded) {
|
|
|
|
// Load the group index
|
|
|
|
_state._curGroupPtr->load();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_state._curGroupPtr->_callInitGro)
|
|
|
|
initGro();
|
|
|
|
|
2013-12-15 20:08:25 +00:00
|
|
|
if (process) {
|
|
|
|
// Pre-process the resources
|
2013-05-25 19:36:57 +00:00
|
|
|
id &= 0xff00;
|
|
|
|
for (int idx = 0; idx < _state._curGroupPtr->_count; ++idx, ++id) {
|
|
|
|
byte *member = getBoltMember(id);
|
|
|
|
assert(member);
|
|
|
|
}
|
|
|
|
} else if (!_state._curGroupPtr->_processed) {
|
|
|
|
_state._curGroupPtr->_processed = true;
|
|
|
|
_state._curGroupPtr->load();
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveAll();
|
|
|
|
--_state._fromGroupFlag;
|
2013-12-11 05:11:02 +00:00
|
|
|
|
|
|
|
return _state._curGroupPtr;
|
2013-05-25 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-15 20:08:25 +00:00
|
|
|
void BoltFile::freeBoltGroup(uint16 id, bool freeEntries) {
|
|
|
|
// TODO: I currently ignore freeEntries flag, in favour of always
|
|
|
|
// freeing. Need to check whether this can really ever be false.
|
2013-06-08 19:49:44 +00:00
|
|
|
_state._curLibPtr = this;
|
|
|
|
_state._curGroupPtr = &_groups[(id >> 8) & 0xff];
|
|
|
|
|
|
|
|
// Unload the group
|
|
|
|
_state._curGroupPtr->unload();
|
2013-06-06 01:28:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 21:51:50 +00:00
|
|
|
void BoltFile::freeBoltMember(uint32 id) {
|
2014-01-05 21:47:03 +00:00
|
|
|
// TODO: Determine whether this is needed, given all group entries are automatically loaded
|
|
|
|
// warning("TODO: BoltFile::freeBoltMember");
|
2013-12-08 21:51:50 +00:00
|
|
|
}
|
|
|
|
|
2013-06-15 15:39:28 +00:00
|
|
|
BoltEntry &BoltFile::getBoltEntryFromLong(uint32 id) {
|
2013-05-29 03:57:16 +00:00
|
|
|
BoltGroup &group = _groups[id >> 24];
|
|
|
|
assert(group._loaded);
|
2013-05-29 02:39:32 +00:00
|
|
|
|
2013-05-29 03:57:16 +00:00
|
|
|
BoltEntry &entry = group._entries[(id >> 16) & 0xff];
|
2013-05-29 02:39:32 +00:00
|
|
|
assert(!entry.hasResource() || (id & 0xffff) == 0);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2013-06-15 15:39:28 +00:00
|
|
|
BoltEntry &BoltFile::boltEntry(uint16 id) {
|
|
|
|
BoltGroup &group = _groups[id >> 8];
|
|
|
|
assert(group._loaded);
|
|
|
|
|
|
|
|
BoltEntry &entry = group._entries[id & 0xff];
|
|
|
|
assert(entry.hasResource());
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:13:52 +00:00
|
|
|
PictureResource *BoltFile::getPictureResource(uint32 id) {
|
2013-05-29 03:57:16 +00:00
|
|
|
if ((int32)id == -1)
|
|
|
|
return NULL;
|
|
|
|
|
2013-06-13 02:43:54 +00:00
|
|
|
if (id & 0xffff)
|
|
|
|
id <<= 16;
|
2013-06-15 15:39:28 +00:00
|
|
|
return getBoltEntryFromLong(id)._picResource;
|
2013-05-29 03:57:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 01:28:51 +00:00
|
|
|
CMapResource *BoltFile::getCMapResource(uint32 id) {
|
|
|
|
if ((int32)id == -1)
|
|
|
|
return NULL;
|
|
|
|
|
2013-06-15 15:39:28 +00:00
|
|
|
if (id & 0xffff)
|
|
|
|
id <<= 16;
|
|
|
|
return getBoltEntryFromLong(id)._cMapResource;
|
2013-06-06 01:28:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
byte *BoltFile::memberAddr(uint32 id) {
|
|
|
|
BoltGroup &group = _groups[id >> 8];
|
|
|
|
if (!group._loaded)
|
|
|
|
return NULL;
|
|
|
|
|
2013-05-29 02:39:32 +00:00
|
|
|
// If an entry already has a processed representation, we shouldn't
|
|
|
|
// still be accessing the raw data
|
|
|
|
BoltEntry &entry = group._entries[id & 0xff];
|
|
|
|
assert(!entry.hasResource());
|
|
|
|
|
|
|
|
return entry._data;
|
2013-05-25 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 03:30:48 +00:00
|
|
|
byte *BoltFile::memberAddrOffset(uint32 id) {
|
2013-05-29 03:57:16 +00:00
|
|
|
BoltGroup &group = _groups[id >> 24];
|
2013-05-26 03:30:48 +00:00
|
|
|
if (!group._loaded)
|
|
|
|
return NULL;
|
|
|
|
|
2013-05-29 02:39:32 +00:00
|
|
|
// If an entry already has a processed representation, we shouldn't
|
|
|
|
// still be accessing the raw data
|
|
|
|
BoltEntry &entry = group._entries[(id >> 16) & 0xff];
|
|
|
|
assert(!entry.hasResource());
|
|
|
|
|
|
|
|
return entry._data + (id & 0xffff);
|
2013-05-26 03:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves an Id to an offset within a loaded resource
|
|
|
|
*/
|
|
|
|
void BoltFile::resolveIt(uint32 id, byte **p) {
|
|
|
|
if ((int32)id == -1) {
|
|
|
|
*p = NULL;
|
|
|
|
} else {
|
|
|
|
byte *ptr = memberAddrOffset(id);
|
|
|
|
if (ptr) {
|
|
|
|
*p = ptr;
|
|
|
|
} else {
|
|
|
|
*p = NULL;
|
|
|
|
assert(_state._resolves.size() < 1000);
|
|
|
|
_state._resolves.push_back(ResolveEntry(id, p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
void BoltFile::resolveFunction(uint32 id, GraphicMethodPtr *fn) {
|
2013-05-26 03:30:48 +00:00
|
|
|
if ((int32)id == -1) {
|
|
|
|
*fn = NULL;
|
|
|
|
} else {
|
|
|
|
error("Function fnTermGro array not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve any data references to within resources that weren't
|
|
|
|
* previously loaded, but are now
|
|
|
|
*/
|
|
|
|
void BoltFile::resolveAll() {
|
|
|
|
for (uint idx = 0; idx < _state._resolves.size(); ++idx)
|
|
|
|
*_state._resolves[idx]._p = memberAddrOffset(_state._resolves[idx]._id);
|
2013-12-15 16:15:58 +00:00
|
|
|
|
|
|
|
_state._resolves.clear();
|
2013-05-26 03:30:48 +00:00
|
|
|
}
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
byte *BoltFile::getBoltMember(uint32 id) {
|
|
|
|
_state._curLibPtr = this;
|
|
|
|
|
|
|
|
// Get the group, and load it's entry list if not already loaded
|
|
|
|
_state._curGroupPtr = &_groups[(id >> 8) & 0xff];
|
|
|
|
if (!_state._curGroupPtr->_loaded)
|
|
|
|
_state._curGroupPtr->load();
|
|
|
|
|
|
|
|
// Get the entry
|
|
|
|
_state._curMemberPtr = &_state._curGroupPtr->_entries[id & 0xff];
|
|
|
|
if (_state._curMemberPtr->_field1)
|
|
|
|
initMem(_state._curMemberPtr->_field1);
|
|
|
|
|
|
|
|
// Return the data for the entry if it's already been loaded
|
|
|
|
if (_state._curMemberPtr->_data)
|
|
|
|
return _state._curMemberPtr->_data;
|
|
|
|
|
|
|
|
_state._xorMask = _state._curMemberPtr->_xorMask;
|
|
|
|
_state._encrypt = (_state._curMemberPtr->_mode & 0x10) != 0;
|
|
|
|
|
|
|
|
if (_state._curGroupPtr->_processed) {
|
|
|
|
// TODO: Figure out weird access type. Uncompressed read perhaps?
|
|
|
|
//int fileDiff = _state._curGroupPtr->_fileOffset - _state._curMemberPtr->_fileOffset;
|
2013-12-08 01:44:28 +00:00
|
|
|
error("TODO: processed bolt flag");
|
2013-05-25 19:36:57 +00:00
|
|
|
} else {
|
|
|
|
_state._bufStart = _state._decompressBuf;
|
|
|
|
_state._bufSize = DECOMPRESS_SIZE;
|
|
|
|
|
2013-05-26 00:51:53 +00:00
|
|
|
if ((_state._curFd != &_file) || (_state._curMemberPtr->_fileOffset < _state._bufferBegin)
|
|
|
|
|| (_state._curMemberPtr->_fileOffset >= _state._bufferEnd)) {
|
2013-05-25 19:36:57 +00:00
|
|
|
_state._bytesLeft = 0;
|
|
|
|
_state._bufPos = _state._bufStart;
|
|
|
|
_state._bufferBegin = -1;
|
|
|
|
_state._bufferEnd = _state._curMemberPtr->_fileOffset;
|
|
|
|
} else {
|
2013-05-26 00:51:53 +00:00
|
|
|
_state._bufPos = _state._curMemberPtr->_fileOffset - _state._bufferBegin + _state._bufStart;
|
|
|
|
_state._bytesLeft = _state._bufSize - (_state._bufPos - _state._bufStart);
|
2013-05-25 19:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_state._decompState = 0;
|
|
|
|
_state._historyIndex = 0;
|
|
|
|
|
|
|
|
// Initialise the resource
|
|
|
|
assert(_state._curMemberPtr->_initMethod < 25);
|
2013-12-08 01:44:28 +00:00
|
|
|
initResource(_state._curMemberPtr->_initMethod);
|
2013-05-25 19:36:57 +00:00
|
|
|
|
|
|
|
return _state._curMemberPtr->_data;
|
|
|
|
}
|
|
|
|
|
2013-05-25 13:58:03 +00:00
|
|
|
void BoltFile::initDefault() {
|
2013-05-25 19:36:57 +00:00
|
|
|
_state._curMemberPtr->_data = _state.decompress(0, _state._curMemberPtr->_size,
|
|
|
|
_state._curMemberPtr->_mode);
|
2013-05-25 13:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
2013-05-25 13:58:03 +00:00
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
BVoyBoltFile::BVoyBoltFile(BoltFilesState &state): BoltFile("bvoy.blt", state) {
|
2013-05-25 13:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
void BVoyBoltFile::initResource(int resType) {
|
|
|
|
switch (resType) {
|
2013-12-25 05:40:46 +00:00
|
|
|
case 2:
|
2014-01-01 02:08:00 +00:00
|
|
|
// Also used for point list, and ending credits credit data
|
2013-12-25 05:40:46 +00:00
|
|
|
sInitRect();
|
|
|
|
break;
|
2013-12-08 01:44:28 +00:00
|
|
|
case 8:
|
|
|
|
sInitPic();
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
vInitCMap();
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
vInitCycl();
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
initViewPort();
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
initViewPortList();
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
initFont();
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
initFontInfo();
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
initSoundMap();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
initDefault();
|
|
|
|
break;
|
|
|
|
}
|
2013-05-25 13:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
void BVoyBoltFile::initViewPort() {
|
2013-05-26 03:30:48 +00:00
|
|
|
initDefault();
|
2013-06-17 01:20:42 +00:00
|
|
|
|
|
|
|
ViewPortResource *viewPort;
|
|
|
|
byte *src = _state._curMemberPtr->_data;
|
|
|
|
_state._curMemberPtr->_viewPortResource = viewPort = new ViewPortResource(_state, src);
|
|
|
|
|
|
|
|
// This is done post-constructor, since viewports can be self referential, so
|
|
|
|
// we ned the _viewPortResource field to have been set before resolving the pointer
|
|
|
|
viewPort->_parent = getBoltEntryFromLong(READ_LE_UINT32(src + 2))._viewPortResource;
|
2013-05-25 13:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
void BVoyBoltFile::initViewPortList() {
|
2013-05-27 02:18:54 +00:00
|
|
|
initDefault();
|
2013-06-01 01:03:16 +00:00
|
|
|
|
|
|
|
ViewPortListResource *res;
|
|
|
|
_state._curMemberPtr->_viewPortListResource = res = new ViewPortListResource(
|
2013-05-27 02:18:54 +00:00
|
|
|
_state, _state._curMemberPtr->_data);
|
2013-06-01 01:03:16 +00:00
|
|
|
|
2013-06-06 01:28:51 +00:00
|
|
|
_state._vm->_graphicsManager._viewPortListPtr = res;
|
2013-06-01 01:03:16 +00:00
|
|
|
_state._vm->_graphicsManager._vPort = &res->_entries[0];
|
2013-05-25 13:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
void BVoyBoltFile::initFontInfo() {
|
2013-05-28 03:01:15 +00:00
|
|
|
initDefault();
|
2013-06-15 15:39:28 +00:00
|
|
|
_state._curMemberPtr->_fontInfoResource = new FontInfoResource(
|
2013-05-28 03:01:15 +00:00
|
|
|
_state, _state._curMemberPtr->_data);
|
2013-05-25 13:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
void BVoyBoltFile::initFont() {
|
2013-06-15 15:39:28 +00:00
|
|
|
initDefault();
|
|
|
|
_state._curMemberPtr->_fontResource = new FontResource(_state, _state._curMemberPtr->_data);
|
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
void BVoyBoltFile::initSoundMap() {
|
|
|
|
initDefault();
|
|
|
|
}
|
|
|
|
|
2013-12-25 05:40:46 +00:00
|
|
|
void BVoyBoltFile::sInitRect() {
|
2013-12-25 06:07:05 +00:00
|
|
|
_state._curMemberPtr->_data = _state.decompress(NULL, _state._curMemberPtr->_size,
|
|
|
|
_state._curMemberPtr->_mode);
|
2013-12-28 02:30:51 +00:00
|
|
|
|
|
|
|
if ((_state._curMemberPtr->_size % 8) == 0 || (_state._curMemberPtr->_size % 8) == 2)
|
2013-12-25 06:07:05 +00:00
|
|
|
_state._curMemberPtr->_rectResource = new RectResource(_state._curMemberPtr->_data,
|
|
|
|
_state._curMemberPtr->_size);
|
2013-12-25 05:40:46 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 01:44:28 +00:00
|
|
|
void BVoyBoltFile::sInitPic() {
|
|
|
|
// Read in the header data
|
|
|
|
_state._curMemberPtr->_data = _state.decompress(NULL, 24, _state._curMemberPtr->_mode);
|
|
|
|
_state._curMemberPtr->_picResource = new PictureResource(_state,
|
|
|
|
_state._curMemberPtr->_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BVoyBoltFile::vInitCMap() {
|
|
|
|
initDefault();
|
|
|
|
_state._curMemberPtr->_cMapResource = new CMapResource(
|
|
|
|
_state, _state._curMemberPtr->_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BVoyBoltFile::vInitCycl() {
|
2013-05-28 03:01:15 +00:00
|
|
|
initDefault();
|
2013-12-29 23:25:46 +00:00
|
|
|
_state._curMemberPtr->_vInitCycleResource = new VInitCycleResource(
|
2013-12-08 01:44:28 +00:00
|
|
|
_state, _state._curMemberPtr->_data);
|
2013-12-30 09:28:29 +00:00
|
|
|
_state._curMemberPtr->_vInitCycleResource->vStopCycle();
|
2013-12-08 01:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
StampBoltFile::StampBoltFile(BoltFilesState &state): BoltFile("stampblt.blt", state) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void StampBoltFile::initResource(int resType) {
|
|
|
|
switch (resType) {
|
2013-12-08 21:51:50 +00:00
|
|
|
case 0:
|
|
|
|
initThread();
|
|
|
|
break;
|
2013-12-08 15:40:26 +00:00
|
|
|
case 6:
|
|
|
|
initPtr();
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
initControl();
|
|
|
|
break;
|
2013-12-08 01:44:28 +00:00
|
|
|
default:
|
|
|
|
initDefault();
|
|
|
|
break;
|
|
|
|
}
|
2013-05-25 13:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 21:51:50 +00:00
|
|
|
void StampBoltFile::initThread() {
|
|
|
|
initDefault();
|
|
|
|
|
|
|
|
_state._curMemberPtr->_threadResource = new ThreadResource(_state,
|
|
|
|
_state._curMemberPtr->_data);
|
|
|
|
}
|
|
|
|
|
2013-12-08 15:40:26 +00:00
|
|
|
void StampBoltFile::initPtr() {
|
|
|
|
initDefault();
|
|
|
|
|
|
|
|
_state._curMemberPtr->_ptrResource = new PtrResource(_state,
|
|
|
|
_state._curMemberPtr->_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StampBoltFile::initControl() {
|
|
|
|
initDefault();
|
|
|
|
|
|
|
|
ControlResource *res;
|
|
|
|
_state._curMemberPtr->_controlResource = res = new ControlResource(_state,
|
|
|
|
_state._curMemberPtr->_data);
|
|
|
|
|
2013-12-08 19:44:48 +00:00
|
|
|
_state._vm->_controlGroupPtr = _state._curGroupPtr;
|
2013-12-08 15:40:26 +00:00
|
|
|
_state._vm->_controlPtr = res;
|
|
|
|
}
|
|
|
|
|
2013-05-20 02:45:54 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
BoltGroup::BoltGroup(Common::SeekableReadStream *f): _file(f) {
|
|
|
|
byte buffer[BOLT_GROUP_SIZE];
|
|
|
|
|
2013-05-22 02:07:17 +00:00
|
|
|
_loaded = false;
|
2013-05-20 02:45:54 +00:00
|
|
|
|
|
|
|
_file->read(&buffer[0], BOLT_GROUP_SIZE);
|
2013-05-22 02:07:17 +00:00
|
|
|
_processed = buffer[0] != 0;
|
2013-05-20 02:45:54 +00:00
|
|
|
_callInitGro = buffer[1] != 0;
|
2013-06-06 01:28:51 +00:00
|
|
|
_termGroIndex = buffer[2];
|
2013-05-21 01:18:40 +00:00
|
|
|
_count = buffer[3] ? buffer[3] : 256; // TODO: Added this in. Check it's okay
|
2013-05-20 02:45:54 +00:00
|
|
|
_fileOffset = READ_LE_UINT32(&buffer[8]);
|
|
|
|
}
|
|
|
|
|
2013-06-08 19:49:44 +00:00
|
|
|
BoltGroup::~BoltGroup() {
|
|
|
|
}
|
|
|
|
|
2013-05-20 02:45:54 +00:00
|
|
|
void BoltGroup::load() {
|
|
|
|
_file->seek(_fileOffset);
|
|
|
|
|
|
|
|
// Read the entries
|
2013-05-21 03:19:12 +00:00
|
|
|
for (int i = 0; i < _count; ++i)
|
2013-05-20 02:45:54 +00:00
|
|
|
_entries.push_back(BoltEntry(_file));
|
2013-05-21 01:18:40 +00:00
|
|
|
|
|
|
|
_loaded = true;
|
2013-05-20 02:45:54 +00:00
|
|
|
}
|
|
|
|
|
2013-06-08 19:49:44 +00:00
|
|
|
void BoltGroup::unload() {
|
|
|
|
if (!_loaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_entries.clear();
|
|
|
|
_loaded = false;
|
|
|
|
}
|
|
|
|
|
2013-05-20 02:45:54 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
BoltEntry::BoltEntry(Common::SeekableReadStream *f): _file(f) {
|
2013-12-25 05:40:46 +00:00
|
|
|
_data = nullptr;
|
|
|
|
_rectResource = nullptr;
|
|
|
|
_picResource = nullptr;
|
|
|
|
_viewPortResource = nullptr;
|
|
|
|
_viewPortListResource = nullptr;
|
|
|
|
_fontResource = nullptr;
|
|
|
|
_fontInfoResource = nullptr;
|
|
|
|
_cMapResource = nullptr;
|
2013-12-29 23:25:46 +00:00
|
|
|
_vInitCycleResource = nullptr;
|
2013-12-25 05:40:46 +00:00
|
|
|
_ptrResource = nullptr;
|
|
|
|
_controlResource = nullptr;
|
2013-12-29 23:25:46 +00:00
|
|
|
_vInitCycleResource = nullptr;
|
2013-12-25 05:40:46 +00:00
|
|
|
_threadResource = nullptr;
|
2013-05-21 01:18:40 +00:00
|
|
|
|
|
|
|
byte buffer[16];
|
|
|
|
_file->read(&buffer[0], 16);
|
|
|
|
_mode = buffer[0];
|
|
|
|
_field1 = buffer[1];
|
2013-05-25 13:58:03 +00:00
|
|
|
_initMethod = buffer[3];
|
2013-05-21 01:18:40 +00:00
|
|
|
_xorMask = buffer[4] & 0xff; // TODO: Is this right??
|
|
|
|
_size = READ_LE_UINT32(&buffer[4]);
|
|
|
|
_fileOffset = READ_LE_UINT32(&buffer[8]);
|
2013-05-20 02:45:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 01:18:40 +00:00
|
|
|
BoltEntry::~BoltEntry() {
|
|
|
|
delete[] _data;
|
2013-12-25 05:40:46 +00:00
|
|
|
delete _rectResource;
|
2013-05-25 19:36:57 +00:00
|
|
|
delete _picResource;
|
2013-05-26 03:30:48 +00:00
|
|
|
delete _viewPortResource;
|
2013-05-27 02:18:54 +00:00
|
|
|
delete _viewPortListResource;
|
2013-05-28 03:01:15 +00:00
|
|
|
delete _fontResource;
|
2013-06-15 15:39:28 +00:00
|
|
|
delete _fontInfoResource;
|
2013-05-28 03:01:15 +00:00
|
|
|
delete _cMapResource;
|
2013-12-29 23:25:46 +00:00
|
|
|
delete _vInitCycleResource;
|
2013-12-08 15:40:26 +00:00
|
|
|
delete _ptrResource;
|
|
|
|
delete _controlResource;
|
2013-05-21 01:18:40 +00:00
|
|
|
}
|
2013-05-20 02:45:54 +00:00
|
|
|
|
2013-05-21 01:18:40 +00:00
|
|
|
void BoltEntry::load() {
|
2013-05-25 19:36:57 +00:00
|
|
|
// TODO: Currently, all entry loading and decompression is done in BoltFile::memberAddr.
|
|
|
|
// Ideally, a lot of the code should be moved here
|
|
|
|
}
|
|
|
|
|
2013-05-29 02:39:32 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given bolt entry has an attached resource
|
|
|
|
*/
|
|
|
|
bool BoltEntry::hasResource() const {
|
2013-12-25 05:40:46 +00:00
|
|
|
return _rectResource || _picResource || _viewPortResource || _viewPortListResource
|
2013-12-08 15:40:26 +00:00
|
|
|
|| _fontResource || _fontInfoResource || _cMapResource
|
2013-12-29 23:25:46 +00:00
|
|
|
|| _vInitCycleResource
|
2013-12-25 05:40:46 +00:00
|
|
|
|| _ptrResource || _controlResource || _threadResource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-12-25 06:07:05 +00:00
|
|
|
RectResource::RectResource(const byte *src, int size) {
|
2013-12-28 22:54:40 +00:00
|
|
|
int count;
|
|
|
|
if ((size % 8) == 2) {
|
2013-12-25 06:07:05 +00:00
|
|
|
count = READ_LE_UINT16(src);
|
|
|
|
src += 2;
|
2013-12-28 22:54:40 +00:00
|
|
|
} else {
|
|
|
|
count = size / 8;
|
2013-12-25 06:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i, src += 8) {
|
|
|
|
_entries.push_back(Common::Rect(READ_LE_UINT16(src), READ_LE_UINT16(src + 2),
|
|
|
|
READ_LE_UINT16(src + 4), READ_LE_UINT16(src + 6)));
|
|
|
|
}
|
|
|
|
|
|
|
|
left = _entries[0].left;
|
|
|
|
top = _entries[0].top;
|
|
|
|
right = _entries[0].right;
|
|
|
|
bottom = _entries[0].bottom;
|
2013-12-25 05:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RectResource::RectResource(int x1, int y1, int x2, int y2) {
|
|
|
|
left = x1;
|
|
|
|
top = y1;
|
|
|
|
right = x2;
|
|
|
|
bottom = y2;
|
2013-05-29 02:39:32 +00:00
|
|
|
}
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-01-18 13:09:38 +00:00
|
|
|
DisplayResource::DisplayResource() {
|
|
|
|
_vm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayResource::DisplayResource(VoyeurEngine *vm) {
|
|
|
|
_vm = vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayResource::sFillBox(int width, int height) {
|
|
|
|
assert(_vm);
|
|
|
|
bool saveBack = _vm->_graphicsManager._saveBack;
|
|
|
|
_vm->_graphicsManager._saveBack = false;
|
|
|
|
|
|
|
|
PictureResource pr;
|
|
|
|
pr._flags = 1;
|
|
|
|
pr._select = 0xff;
|
|
|
|
pr._pick = 0;
|
|
|
|
pr._onOff = _vm->_graphicsManager._drawPtr->_penColor;
|
|
|
|
pr._bounds = Common::Rect(0, 0, width, height);
|
|
|
|
|
|
|
|
_vm->_graphicsManager.sDrawPic(&pr, this, _vm->_graphicsManager._drawPtr->_pos);
|
|
|
|
_vm->_graphicsManager._saveBack = saveBack;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
PictureResource::PictureResource(BoltFilesState &state, const byte *src):
|
|
|
|
DisplayResource(state._vm) {
|
2013-05-25 19:36:57 +00:00
|
|
|
_flags = READ_LE_UINT16(src);
|
|
|
|
_select = src[2];
|
|
|
|
_pick = src[3];
|
|
|
|
_onOff = src[4];
|
|
|
|
_depth = src[5];
|
2013-05-30 03:21:07 +00:00
|
|
|
|
|
|
|
int xs = READ_LE_UINT16(&src[6]);
|
|
|
|
int ys = READ_LE_UINT16(&src[8]);
|
|
|
|
_bounds = Common::Rect(xs, ys, xs + READ_LE_UINT16(&src[10]),
|
|
|
|
ys + READ_LE_UINT16(&src[12]));
|
2013-05-25 19:36:57 +00:00
|
|
|
_maskData = READ_LE_UINT32(&src[14]);
|
2013-06-08 21:51:41 +00:00
|
|
|
_planeSize = READ_LE_UINT16(&src[22]);
|
2013-05-25 19:36:57 +00:00
|
|
|
|
|
|
|
_imgData = NULL;
|
2014-01-16 14:25:31 +00:00
|
|
|
_freeImgData = DisposeAfterUse::YES;
|
2013-05-26 00:51:53 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
int nbytes = _bounds.width() * _bounds.height();
|
2013-12-15 20:08:25 +00:00
|
|
|
if (_flags & PICFLAG_20) {
|
2014-01-15 04:19:24 +00:00
|
|
|
if (_flags & (PICFLAG_VFLIP | PICFLAG_HFLIP)) {
|
|
|
|
// Get the raw data for the picture from another resource
|
|
|
|
uint32 id = READ_LE_UINT32(&src[18]);
|
|
|
|
const byte *srcData = state._curLibPtr->boltEntry(id)._data;
|
|
|
|
_imgData = new byte[nbytes];
|
|
|
|
|
|
|
|
// Flip the image data either horizontally or vertically
|
|
|
|
if (_flags & PICFLAG_HFLIP)
|
|
|
|
flipHorizontal(srcData);
|
|
|
|
else
|
|
|
|
flipVertical(srcData);
|
2013-12-15 20:08:25 +00:00
|
|
|
} else {
|
2014-01-16 14:25:31 +00:00
|
|
|
uint32 id = READ_LE_UINT32(&src[18]) >> 16;
|
|
|
|
byte *imgData = state._curLibPtr->boltEntry(id)._picResource->_imgData;
|
|
|
|
_freeImgData = DisposeAfterUse::NO;
|
|
|
|
|
|
|
|
if (_flags & PICFLAG_PIC_OFFSET) {
|
|
|
|
_imgData = imgData + (READ_LE_UINT32(&src[18]) & 0xffff);
|
|
|
|
} else {
|
|
|
|
warning("TODO: Double-check if this is correct");
|
|
|
|
_imgData = imgData + (READ_LE_UINT32(&src[18]) & 0xffff);
|
|
|
|
}
|
2013-12-15 20:08:25 +00:00
|
|
|
}
|
2014-01-16 14:25:31 +00:00
|
|
|
} else if (_flags & PICFLAG_PIC_OFFSET) {
|
2013-05-26 00:51:53 +00:00
|
|
|
int mode = 0;
|
2013-05-30 03:21:07 +00:00
|
|
|
if (_bounds.width() == 320) {
|
2013-05-26 00:51:53 +00:00
|
|
|
mode = 147;
|
|
|
|
state._sImageShift = 2;
|
|
|
|
state._SVGAReset = false;
|
|
|
|
} else {
|
|
|
|
state._SVGAReset = true;
|
2013-05-30 03:21:07 +00:00
|
|
|
if (_bounds.width() == 640) {
|
|
|
|
if (_bounds.height() == 400) {
|
2013-05-26 00:51:53 +00:00
|
|
|
mode = 220;
|
|
|
|
state._sImageShift = 3;
|
|
|
|
} else {
|
|
|
|
mode = 221;
|
|
|
|
state._sImageShift = 3;
|
|
|
|
}
|
2013-05-30 03:21:07 +00:00
|
|
|
} else if (_bounds.width() == 800) {
|
2013-05-26 00:51:53 +00:00
|
|
|
mode = 222;
|
|
|
|
state._sImageShift = 3;
|
2013-05-30 03:21:07 +00:00
|
|
|
} else if (_bounds.width() == 1024) {
|
2013-05-26 00:51:53 +00:00
|
|
|
mode = 226;
|
|
|
|
state._sImageShift = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != state._vm->_graphicsManager._SVGAMode) {
|
|
|
|
state._vm->_graphicsManager._SVGAMode = mode;
|
2013-06-06 01:28:51 +00:00
|
|
|
state._vm->_graphicsManager.clearPalette();
|
2013-05-26 00:51:53 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 14:25:31 +00:00
|
|
|
int screenOffset = READ_LE_UINT32(&src[18]) & 0xffff;
|
|
|
|
assert(screenOffset == 0);
|
|
|
|
|
|
|
|
if (_flags & PICFLAG_CLEAR_SCREEN) {
|
|
|
|
// Clear screen picture. That's right. This game actually has a picture
|
|
|
|
// resource flag to clear the screen! Bizarre.
|
|
|
|
Graphics::Surface &s = state._vm->_graphicsManager._screenSurface;
|
|
|
|
s.fillRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), 0);
|
2013-05-26 00:51:53 +00:00
|
|
|
} else {
|
2014-01-16 14:25:31 +00:00
|
|
|
// Direct sceren loading picture. In this case, the raw data of the resource
|
|
|
|
// is directly decompressed into the screen surface. Again, bizarre.
|
|
|
|
byte *pDest = (byte *)state._vm->_graphicsManager._screenSurface.getPixels();
|
|
|
|
state.decompress(pDest, SCREEN_WIDTH * SCREEN_HEIGHT, state._curMemberPtr->_mode);
|
2013-05-26 00:51:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-01-16 14:25:31 +00:00
|
|
|
if (_flags & PICFLAG_CLEAR_SCREEN00) {
|
|
|
|
if (!(_flags & PICFLAG_CLEAR_SCREEN))
|
2013-05-26 00:51:53 +00:00
|
|
|
nbytes = state._curMemberPtr->_size - 24;
|
|
|
|
|
|
|
|
int mask = (nbytes + 0x3FFF) >> 14;
|
|
|
|
_imgData = NULL;
|
|
|
|
|
|
|
|
if (state._boltPageFrame == 0)
|
|
|
|
state.EMSGetFrameAddr(&state._boltPageFrame);
|
|
|
|
if (state._boltPageFrame != 0) {
|
|
|
|
if (!state.EMSAllocatePages(&_planeSize)) {
|
|
|
|
_maskData = mask;
|
|
|
|
|
|
|
|
for (int idx = 0; idx < mask; ++idx)
|
|
|
|
state.EMSMapPageHandle(_planeSize, idx, idx);
|
|
|
|
|
|
|
|
state.decompress(state._boltPageFrame, nbytes, state._curMemberPtr->_mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-16 14:25:31 +00:00
|
|
|
if (_flags & PICFLAG_CLEAR_SCREEN) {
|
2013-05-26 00:51:53 +00:00
|
|
|
_imgData = new byte[nbytes];
|
2013-06-07 03:48:46 +00:00
|
|
|
Common::fill(_imgData, _imgData + nbytes, 0);
|
2013-05-26 00:51:53 +00:00
|
|
|
} else {
|
|
|
|
_imgData = state.decompress(NULL, nbytes, state._curMemberPtr->_mode);
|
|
|
|
}
|
|
|
|
}
|
2013-05-25 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-28 22:54:40 +00:00
|
|
|
PictureResource::PictureResource(Graphics::Surface *surface) {
|
|
|
|
_flags = 0;
|
|
|
|
_select = 0;
|
|
|
|
_pick = 0;
|
|
|
|
_onOff = 0;
|
|
|
|
_depth = 0;
|
|
|
|
_maskData = 0;
|
|
|
|
_planeSize = 0;
|
|
|
|
|
|
|
|
_bounds = Common::Rect(0, 0, surface->w, surface->h);
|
|
|
|
_imgData = (byte *)surface->getPixels();
|
2014-01-16 14:25:31 +00:00
|
|
|
_freeImgData = DisposeAfterUse::NO;
|
2013-12-28 22:54:40 +00:00
|
|
|
}
|
|
|
|
|
2013-06-08 21:51:41 +00:00
|
|
|
PictureResource::PictureResource() {
|
2013-06-21 04:18:19 +00:00
|
|
|
_flags = 0;
|
2013-06-08 21:51:41 +00:00
|
|
|
_select = 0;
|
|
|
|
_pick = 0;
|
|
|
|
_onOff = 0;
|
|
|
|
_depth = 0;
|
|
|
|
_maskData = 0;
|
|
|
|
_planeSize = 0;
|
|
|
|
|
|
|
|
_imgData = NULL;
|
2014-01-16 14:25:31 +00:00
|
|
|
_freeImgData = DisposeAfterUse::NO;
|
2013-06-08 21:51:41 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 13:03:03 +00:00
|
|
|
PictureResource::PictureResource(int flags, int select, int pick, int onOff,
|
|
|
|
int depth, const Common::Rect &bounds, int maskData, byte *imgData,
|
|
|
|
int planeSize) {
|
|
|
|
_flags = flags;
|
|
|
|
_select = select;
|
|
|
|
_pick = pick;
|
|
|
|
_onOff = onOff;
|
|
|
|
_depth = depth;
|
|
|
|
_bounds = bounds;
|
|
|
|
_maskData = maskData;
|
|
|
|
_imgData = imgData;
|
|
|
|
_planeSize = planeSize;
|
|
|
|
}
|
|
|
|
|
2013-05-25 19:36:57 +00:00
|
|
|
PictureResource::~PictureResource() {
|
2014-01-16 14:25:31 +00:00
|
|
|
if (_freeImgData == DisposeAfterUse::YES)
|
|
|
|
delete[] _imgData;
|
2013-05-20 02:45:54 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 04:19:24 +00:00
|
|
|
void PictureResource::flipHorizontal(const byte *data) {
|
|
|
|
const byte *srcP = data + 18;
|
|
|
|
byte *destP = _imgData + _bounds.width() - 1;
|
|
|
|
|
|
|
|
for (int y = 0; y < _bounds.height(); ++y) {
|
|
|
|
for (int x = 0; x < _bounds.width(); ++x, ++srcP, --destP)
|
|
|
|
*destP = *srcP;
|
|
|
|
|
|
|
|
srcP += _bounds.width();
|
|
|
|
destP += _bounds.width();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureResource::flipVertical(const byte *data) {
|
|
|
|
const byte *srcP = data + 18;
|
|
|
|
byte *destP = _imgData + _bounds.width() * (_bounds.height() - 1);
|
|
|
|
|
|
|
|
for (int y = 0; y < _bounds.height(); ++y) {
|
|
|
|
Common::copy(srcP, srcP + _bounds.width(), destP);
|
|
|
|
srcP += _bounds.width();
|
|
|
|
destP -= _bounds.width();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-26 03:30:48 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-05-29 02:39:32 +00:00
|
|
|
ViewPortResource::ViewPortResource(BoltFilesState &state, const byte *src):
|
2014-01-18 13:09:38 +00:00
|
|
|
_fontChar(0, 0xff, 0xff, 0, 0, Common::Rect(), 0, NULL, 0),
|
|
|
|
_state(state), DisplayResource(state._vm) {
|
2013-05-30 12:31:06 +00:00
|
|
|
_flags = READ_LE_UINT16(src);
|
2013-06-17 01:20:42 +00:00
|
|
|
_parent = NULL;
|
2013-06-01 01:31:33 +00:00
|
|
|
_pageCount = READ_LE_UINT16(src + 6);
|
|
|
|
_pageIndex = READ_LE_UINT16(src + 8);
|
|
|
|
_lastPage = READ_LE_UINT16(src + 10);
|
|
|
|
|
|
|
|
int xs = READ_LE_UINT16(src + 12);
|
|
|
|
int ys = READ_LE_UINT16(src + 14);
|
|
|
|
_bounds = Common::Rect(xs, ys, xs + READ_LE_UINT16(src + 16),
|
|
|
|
ys + READ_LE_UINT16(src + 18));
|
2013-05-29 02:39:32 +00:00
|
|
|
_field18 = READ_LE_UINT16(src + 0x18);
|
|
|
|
|
2013-06-13 02:13:52 +00:00
|
|
|
_currentPic = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x20));
|
|
|
|
_activePage = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x24));
|
|
|
|
_pages[0] = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x28));
|
|
|
|
_pages[1] = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x2C));
|
2013-05-29 03:57:16 +00:00
|
|
|
|
2013-05-26 03:30:48 +00:00
|
|
|
state._curLibPtr->resolveIt(READ_LE_UINT32(src + 0x30), &_field30);
|
2013-05-29 02:39:32 +00:00
|
|
|
|
2013-06-01 16:35:50 +00:00
|
|
|
// Get the rect list
|
2013-06-02 00:07:20 +00:00
|
|
|
for (int listIndex = 0; listIndex < 3; ++listIndex) {
|
|
|
|
_rectListCount[listIndex] = (int16)READ_LE_UINT16(src + 0x40 + 2 * listIndex);
|
2013-12-14 16:07:01 +00:00
|
|
|
int id = (int)READ_LE_UINT32(src + 0x34 + listIndex * 4);
|
2013-06-01 16:35:50 +00:00
|
|
|
|
2013-06-02 00:07:20 +00:00
|
|
|
if (id == -1) {
|
|
|
|
_rectListPtr[listIndex] = NULL;
|
|
|
|
} else {
|
|
|
|
_rectListPtr[listIndex] = new Common::Array<Common::Rect>();
|
|
|
|
|
|
|
|
if (_rectListCount[listIndex] > 0) {
|
|
|
|
int16 *rectList = (int16 *)state._curLibPtr->memberAddrOffset(id);
|
|
|
|
for (int i = 0; i < _rectListCount[listIndex]; ++i) {
|
2013-12-14 16:07:01 +00:00
|
|
|
xs = FROM_LE_16(rectList[0]);
|
|
|
|
ys = FROM_LE_16(rectList[1]);
|
2013-06-02 00:07:20 +00:00
|
|
|
_rectListPtr[i]->push_back(Common::Rect(xs, ys, xs + FROM_LE_16(rectList[2]),
|
|
|
|
ys + FROM_LE_16(rectList[3])));
|
|
|
|
}
|
|
|
|
}
|
2013-06-01 16:35:50 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-01 02:13:28 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
xs = READ_LE_UINT16(src + 0x46);
|
|
|
|
ys = READ_LE_UINT16(src + 0x48);
|
|
|
|
_clipRect = Common::Rect(xs, ys, xs + READ_LE_UINT16(src + 0x4A),
|
|
|
|
ys + READ_LE_UINT16(src + 0x4C));
|
2013-05-29 02:39:32 +00:00
|
|
|
|
2013-05-26 03:30:48 +00:00
|
|
|
state._curLibPtr->resolveIt(READ_LE_UINT32(src + 0x7A), &_field7A);
|
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x7E), (GraphicMethodPtr *)&_fn1);
|
|
|
|
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x82), (GraphicMethodPtr *)&_setupFn);
|
|
|
|
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x86), (GraphicMethodPtr *)&_addFn);
|
|
|
|
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x8A), (GraphicMethodPtr *)&_restoreFn);
|
2013-05-26 03:30:48 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
if (!_restoreFn && _addFn)
|
|
|
|
_addFn = &GraphicsManager::addRectNoSaveBack;
|
2013-05-26 03:30:48 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 16:35:50 +00:00
|
|
|
ViewPortResource::~ViewPortResource() {
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
delete _rectListPtr[i];
|
|
|
|
}
|
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
void ViewPortResource::setupViewPort(PictureResource *page, Common::Rect *clipRect,
|
|
|
|
ViewPortSetupPtr setupFn, ViewPortAddPtr addFn, ViewPortRestorePtr restoreFn) {
|
2013-06-01 01:31:33 +00:00
|
|
|
PictureResource *pic = _currentPic;
|
2013-05-30 12:31:06 +00:00
|
|
|
Common::Rect r = _bounds;
|
|
|
|
r.translate(pic->_bounds.left, pic->_bounds.top);
|
2013-05-30 03:21:07 +00:00
|
|
|
int xDiff, yDiff;
|
|
|
|
|
|
|
|
if (page) {
|
|
|
|
// Clip based on the passed picture resource
|
|
|
|
xDiff = page->_bounds.left - r.left;
|
|
|
|
yDiff = page->_bounds.top - r.top;
|
|
|
|
|
|
|
|
if (xDiff > 0) {
|
2013-05-30 12:31:06 +00:00
|
|
|
int width = r.width();
|
2013-05-30 03:21:07 +00:00
|
|
|
r.left = page->_bounds.left;
|
2013-05-30 12:31:06 +00:00
|
|
|
r.setWidth(xDiff <= width ? width - xDiff : 0);
|
2013-05-30 03:21:07 +00:00
|
|
|
}
|
|
|
|
if (yDiff > 0) {
|
2013-05-30 12:31:06 +00:00
|
|
|
int height = r.height();
|
2013-05-30 03:21:07 +00:00
|
|
|
r.top = page->_bounds.top;
|
2013-05-30 12:31:06 +00:00
|
|
|
r.setHeight(yDiff <= height ? height - yDiff : 0);
|
2013-05-30 03:21:07 +00:00
|
|
|
}
|
2013-05-29 02:39:32 +00:00
|
|
|
|
2013-05-30 12:31:06 +00:00
|
|
|
xDiff = r.right - page->_bounds.right;
|
|
|
|
yDiff = r.bottom - page->_bounds.bottom;
|
2013-05-29 02:39:32 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
if (xDiff > 0)
|
|
|
|
r.setWidth(xDiff <= r.width() ? r.width() - xDiff : 0);
|
|
|
|
if (yDiff > 0)
|
|
|
|
r.setHeight(yDiff <= r.height() ? r.height() - yDiff : 0);
|
|
|
|
}
|
2013-05-29 02:39:32 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
if (clipRect) {
|
|
|
|
// Clip based on the passed clip rectangles
|
|
|
|
xDiff = clipRect->left - r.left;
|
|
|
|
yDiff = clipRect->top - r.top;
|
|
|
|
|
|
|
|
if (xDiff > 0) {
|
2013-05-30 12:31:06 +00:00
|
|
|
int width = r.width();
|
2013-05-30 03:21:07 +00:00
|
|
|
r.left = clipRect->left;
|
2013-05-30 12:31:06 +00:00
|
|
|
r.setWidth(xDiff <= width ? width - xDiff : 0);
|
2013-05-30 03:21:07 +00:00
|
|
|
}
|
|
|
|
if (yDiff > 0) {
|
2013-05-30 12:31:06 +00:00
|
|
|
int height = r.height();
|
2013-05-30 03:21:07 +00:00
|
|
|
r.top = clipRect->top;
|
2013-05-30 12:31:06 +00:00
|
|
|
r.setHeight(yDiff <= height ? height - yDiff : 0);
|
2013-05-30 03:21:07 +00:00
|
|
|
}
|
2013-05-30 12:31:06 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
xDiff = r.right - clipRect->right;
|
2013-12-23 22:50:42 +00:00
|
|
|
yDiff = r.bottom - clipRect->bottom;
|
2013-05-30 03:21:07 +00:00
|
|
|
|
|
|
|
if (xDiff > 0)
|
|
|
|
r.setWidth(xDiff <= r.width() ? r.width() - xDiff : 0);
|
|
|
|
if (yDiff > 0)
|
|
|
|
r.setHeight(yDiff <= r.height() ? r.height() - yDiff : 0);
|
|
|
|
}
|
2013-12-28 22:54:40 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
_activePage = page;
|
|
|
|
_field18 = 0;
|
2013-05-31 22:40:04 +00:00
|
|
|
_clipRect = r;
|
2013-05-30 03:21:07 +00:00
|
|
|
_setupFn = setupFn;
|
|
|
|
_addFn = addFn;
|
|
|
|
_restoreFn = restoreFn;
|
2013-05-29 02:39:32 +00:00
|
|
|
|
2013-05-30 03:21:07 +00:00
|
|
|
if (setupFn)
|
|
|
|
(_state._vm->_graphicsManager.*setupFn)(this);
|
2013-05-29 02:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPortResource::setupViewPort() {
|
2013-05-30 03:21:07 +00:00
|
|
|
setupViewPort(_state._vm->_graphicsManager._backgroundPage, NULL,
|
|
|
|
&GraphicsManager::setupMCGASaveRect, &GraphicsManager::addRectOptSaveRect,
|
|
|
|
&GraphicsManager::restoreMCGASaveRect);
|
2013-05-29 02:39:32 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 14:25:40 +00:00
|
|
|
void ViewPortResource::setupViewPort(PictureResource *pic, Common::Rect *clipRect) {
|
|
|
|
setupViewPort(pic, clipRect,
|
2013-12-11 05:11:02 +00:00
|
|
|
&GraphicsManager::setupMCGASaveRect, &GraphicsManager::addRectOptSaveRect,
|
|
|
|
&GraphicsManager::restoreMCGASaveRect);
|
|
|
|
}
|
|
|
|
|
2013-06-15 02:01:59 +00:00
|
|
|
int ViewPortResource::drawText(const Common::String &msg) {
|
|
|
|
GraphicsManager &gfxManager = _state._vm->_graphicsManager;
|
2013-06-15 15:39:28 +00:00
|
|
|
assert(gfxManager._fontPtr);
|
|
|
|
assert(gfxManager._fontPtr->_curFont);
|
|
|
|
FontInfoResource &fontInfo = *gfxManager._fontPtr;
|
2013-06-15 02:01:59 +00:00
|
|
|
FontResource &fontData = *fontInfo._curFont;
|
|
|
|
int xShadows[9] = { 0, 1, 1, 1, 0, -1, -1, -1, 0 };
|
|
|
|
int yShadows[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
|
|
|
|
|
|
|
|
Common::Rect *clipPtr = gfxManager._clipPtr;
|
2013-06-19 04:16:51 +00:00
|
|
|
if (!(fontInfo._picFlags & DISPFLAG_1))
|
2013-06-15 02:01:59 +00:00
|
|
|
gfxManager._clipPtr = NULL;
|
|
|
|
|
|
|
|
int minChar = fontData._minChar;
|
|
|
|
int padding = fontData._padding;
|
|
|
|
int fontHeight = fontData._fontHeight;
|
|
|
|
int totalChars = fontData._maxChar - fontData._minChar;
|
|
|
|
int msgWidth = 0;
|
|
|
|
int xp = 0, yp = 0;
|
|
|
|
|
2013-06-19 04:16:51 +00:00
|
|
|
Common::Point pos = Common::Point(fontInfo._pos.x, fontInfo._pos.y + fontData._topPadding);
|
2013-06-15 02:01:59 +00:00
|
|
|
|
2013-06-19 04:16:51 +00:00
|
|
|
_fontChar._flags = fontInfo._picFlags | DISPFLAG_2;
|
2013-06-15 02:01:59 +00:00
|
|
|
_fontChar._select = fontInfo._picSelect;
|
|
|
|
_fontChar._bounds.setHeight(fontHeight);
|
|
|
|
|
2013-06-19 04:16:51 +00:00
|
|
|
if (gfxManager._drawTextPermFlag || (fontInfo._fontFlags & DISPFLAG_1) || fontInfo._justify ||
|
|
|
|
(gfxManager._saveBack && fontInfo._fontSaveBack && (_flags & DISPFLAG_VIEWPORT))) {
|
2013-06-15 02:01:59 +00:00
|
|
|
msgWidth = textWidth(msg);
|
|
|
|
yp = pos.y;
|
|
|
|
xp = pos.x;
|
|
|
|
|
|
|
|
switch (fontInfo._justify) {
|
|
|
|
case 1:
|
|
|
|
xp = pos.x + (fontInfo._justifyWidth / 2) - (msgWidth / 2);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
xp = pos.x + fontInfo._justifyWidth - msgWidth;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(fontInfo._fontFlags & 3)) {
|
|
|
|
_fontRect.left = xp;
|
|
|
|
_fontRect.top = yp;
|
|
|
|
_fontRect.setWidth(msgWidth);
|
|
|
|
_fontRect.setHeight(fontHeight);
|
|
|
|
} else {
|
|
|
|
_fontRect.left = pos.x;
|
|
|
|
_fontRect.top = pos.y;
|
|
|
|
_fontRect.setWidth(fontInfo._justifyWidth);
|
|
|
|
_fontRect.setHeight(fontInfo._justifyHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.x = xp;
|
|
|
|
pos.y = yp;
|
|
|
|
|
|
|
|
if (fontInfo._fontFlags & 4) {
|
|
|
|
if (fontInfo._shadow.x <= 0) {
|
|
|
|
_fontRect.left += fontInfo._shadow.x;
|
|
|
|
_fontRect.right -= fontInfo._shadow.x * 2;
|
|
|
|
} else {
|
|
|
|
_fontRect.right += fontInfo._shadow.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fontInfo._shadow.y <= 0) {
|
|
|
|
_fontRect.top += fontInfo._shadow.y;
|
|
|
|
_fontRect.bottom -= fontInfo._shadow.y * 2;
|
|
|
|
} else {
|
|
|
|
_fontRect.bottom += fontInfo._shadow.y;
|
|
|
|
}
|
|
|
|
} else if (fontInfo._fontFlags & 8) {
|
|
|
|
if (fontInfo._shadow.x <= 0) {
|
|
|
|
_fontRect.left += fontInfo._shadow.x;
|
|
|
|
_fontRect.right -= fontInfo._shadow.x * 3;
|
|
|
|
} else {
|
|
|
|
_fontRect.right += fontInfo._shadow.x * 3;
|
|
|
|
_fontRect.left -= fontInfo._shadow.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fontInfo._shadow.y <= 0) {
|
|
|
|
_fontRect.top += fontInfo._shadow.y;
|
|
|
|
_fontRect.bottom -= fontInfo._shadow.y * 3;
|
|
|
|
} else {
|
|
|
|
_fontRect.bottom += fontInfo._shadow.y * 3;
|
|
|
|
_fontRect.top -= fontInfo._shadow.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 03:02:40 +00:00
|
|
|
if (gfxManager._saveBack && fontInfo._fontSaveBack && (_flags & DISPFLAG_VIEWPORT)) {
|
2013-06-15 02:01:59 +00:00
|
|
|
addSaveRect(_pageIndex, _fontRect);
|
|
|
|
}
|
|
|
|
|
2013-06-19 04:16:51 +00:00
|
|
|
if (fontInfo._fontFlags & DISPFLAG_1) {
|
2013-06-15 02:01:59 +00:00
|
|
|
gfxManager._drawPtr->_pos = Common::Point(_fontRect.left, _fontRect.top);
|
|
|
|
gfxManager._drawPtr->_penColor = fontInfo._backColor;
|
2013-12-19 14:25:40 +00:00
|
|
|
sFillBox(_fontRect.width(), _fontRect.height());
|
2013-06-15 02:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool saveBack = gfxManager._saveBack;
|
|
|
|
gfxManager._saveBack = false;
|
|
|
|
|
|
|
|
int count = 0;
|
2013-06-19 04:16:51 +00:00
|
|
|
if (fontInfo._fontFlags & DISPFLAG_4)
|
2013-06-15 02:01:59 +00:00
|
|
|
count = 1;
|
2013-06-19 04:16:51 +00:00
|
|
|
else if (fontInfo._fontFlags & DISPFLAG_8)
|
2013-06-15 02:01:59 +00:00
|
|
|
count = 8;
|
|
|
|
|
2013-06-16 13:03:03 +00:00
|
|
|
for (int i = count; i >= 0; --i) {
|
2013-06-15 02:01:59 +00:00
|
|
|
xp = pos.x;
|
|
|
|
yp = pos.y;
|
|
|
|
|
|
|
|
switch (xShadows[i]) {
|
|
|
|
case -1:
|
|
|
|
xp -= fontInfo._shadow.x;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
xp += fontInfo._shadow.x;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (yShadows[i]) {
|
|
|
|
case -1:
|
|
|
|
yp -= fontInfo._shadow.y;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
yp += fontInfo._shadow.y;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-16 13:03:03 +00:00
|
|
|
if (i != 0) {
|
2013-06-15 02:01:59 +00:00
|
|
|
_fontChar._pick = 0;
|
|
|
|
_fontChar._onOff = fontInfo._shadowColor;
|
|
|
|
} else if (fontData.field2 == 1 || (fontInfo._fontFlags & 0x10)) {
|
|
|
|
_fontChar._pick = 0;
|
|
|
|
_fontChar._onOff = fontInfo._foreColor;
|
|
|
|
} else {
|
|
|
|
_fontChar._pick = fontInfo._picPick;
|
|
|
|
_fontChar._onOff = fontInfo._picOnOff;
|
|
|
|
_fontChar._depth = fontData.field2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop to draw each character in turn
|
|
|
|
msgWidth = -padding;
|
|
|
|
const char *msgP = msg.c_str();
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
while ((ch = *msgP++) != '\0') {
|
|
|
|
int charValue = (int)ch - minChar;
|
2013-06-16 13:03:03 +00:00
|
|
|
if (charValue < 0 || charValue >= totalChars || fontData._charWidth[charValue] == 0)
|
2013-06-15 02:01:59 +00:00
|
|
|
charValue = fontData._maxChar - minChar;
|
|
|
|
|
|
|
|
int charWidth = fontData._charWidth[charValue];
|
|
|
|
_fontChar._bounds.setWidth(charWidth);
|
|
|
|
|
2013-12-04 03:17:04 +00:00
|
|
|
uint16 offset = READ_LE_UINT16(fontData._charOffsets + charValue * 2);
|
|
|
|
_fontChar._imgData = fontData._charImages + offset * 2;
|
2013-06-15 02:01:59 +00:00
|
|
|
|
|
|
|
gfxManager.sDrawPic(&_fontChar, this, Common::Point(xp, yp));
|
|
|
|
|
2013-06-18 03:06:00 +00:00
|
|
|
_fontChar._imgData = NULL;
|
2013-06-15 02:01:59 +00:00
|
|
|
xp += charWidth + padding;
|
|
|
|
msgWidth += charWidth + padding;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msgWidth = MAX(msgWidth, 0);
|
|
|
|
if (fontInfo._justify == ALIGN_LEFT)
|
|
|
|
fontInfo._pos.x = xp;
|
|
|
|
|
|
|
|
gfxManager._saveBack = saveBack;
|
|
|
|
gfxManager._clipPtr = clipPtr;
|
|
|
|
|
|
|
|
return msgWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ViewPortResource::textWidth(const Common::String &msg) {
|
|
|
|
if (msg.size() == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const char *msgP = msg.c_str();
|
|
|
|
FontResource &fontData = *_state._vm->_graphicsManager._fontPtr->_curFont;
|
|
|
|
int minChar = fontData._minChar;
|
|
|
|
int maxChar = fontData._maxChar;
|
|
|
|
int padding = fontData._padding;
|
|
|
|
int totalWidth = -padding;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
// Loop through the characters
|
|
|
|
while ((ch = *msgP++) != '\0') {
|
|
|
|
int charValue = (int)ch;
|
|
|
|
if (charValue < minChar || charValue > maxChar)
|
|
|
|
charValue = maxChar;
|
|
|
|
|
|
|
|
if (!fontData._charWidth[charValue - minChar])
|
|
|
|
charValue = maxChar;
|
|
|
|
|
|
|
|
totalWidth += fontData._charWidth[charValue - minChar] + padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totalWidth < 0)
|
|
|
|
totalWidth = 0;
|
|
|
|
return totalWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPortResource::addSaveRect(int pageIndex, const Common::Rect &r) {
|
2013-06-13 02:13:52 +00:00
|
|
|
// TODO
|
2014-01-18 13:09:38 +00:00
|
|
|
error("TODO: addSaveRect");
|
2013-06-23 18:55:27 +00:00
|
|
|
}
|
2013-06-15 02:01:59 +00:00
|
|
|
|
2013-06-23 18:55:27 +00:00
|
|
|
void ViewPortResource::fillPic(byte onOff) {
|
|
|
|
_state._vm->_graphicsManager.fillPic(this, onOff);
|
2013-06-15 02:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 03:01:16 +00:00
|
|
|
void ViewPortResource::drawIfaceTime() {
|
|
|
|
// Hour display
|
|
|
|
_state._vm->_graphicsManager.drawANumber(*_state._vm->_graphicsManager._vPort,
|
|
|
|
(_state._vm->_gameHour / 10) == 0 ? 10 : _state._vm->_gameHour / 10,
|
|
|
|
Common::Point(161, 25));
|
|
|
|
_state._vm->_graphicsManager.drawANumber(*_state._vm->_graphicsManager._vPort,
|
|
|
|
_state._vm->_gameHour % 10, Common::Point(172, 25));
|
|
|
|
|
|
|
|
// Minute display
|
|
|
|
_state._vm->_graphicsManager.drawANumber(*_state._vm->_graphicsManager._vPort,
|
|
|
|
_state._vm->_gameMinute / 10, Common::Point(190, 25));
|
|
|
|
_state._vm->_graphicsManager.drawANumber(*_state._vm->_graphicsManager._vPort,
|
|
|
|
_state._vm->_gameMinute % 10, Common::Point(201, 25));
|
|
|
|
|
|
|
|
// AM/PM indicator
|
|
|
|
PictureResource *pic = _state._vm->_bVoy->boltEntry(_state._vm->_voy._isAM ? 272 : 273)._picResource;
|
|
|
|
_state._vm->_graphicsManager.sDrawPic(pic, *_state._vm->_graphicsManager._vPort,
|
|
|
|
Common::Point(215, 27));
|
|
|
|
}
|
|
|
|
|
2013-05-27 02:18:54 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
ViewPortListResource::ViewPortListResource(BoltFilesState &state, const byte *src) {
|
2013-05-28 03:01:15 +00:00
|
|
|
uint count = READ_LE_UINT16(src);
|
2013-06-11 01:46:19 +00:00
|
|
|
_palIndex = READ_LE_UINT16(src + 2);
|
2013-05-28 03:01:15 +00:00
|
|
|
|
2013-06-08 02:07:57 +00:00
|
|
|
// Load palette map
|
|
|
|
byte *palData = state._curLibPtr->memberAddr(READ_LE_UINT32(src + 4));
|
|
|
|
for (uint i = 0; i < 256; ++i, palData += 16)
|
|
|
|
_palette.push_back(ViewPortPalEntry(palData));
|
2013-05-27 02:18:54 +00:00
|
|
|
|
2013-06-08 02:07:57 +00:00
|
|
|
// Load view port pointer list
|
2013-12-14 16:07:01 +00:00
|
|
|
const uint32 *idP = (const uint32 *)&src[8];
|
2013-05-27 02:18:54 +00:00
|
|
|
for (uint i = 0; i < count; ++i, ++idP) {
|
|
|
|
uint32 id = READ_LE_UINT32(idP);
|
2013-06-15 15:39:28 +00:00
|
|
|
BoltEntry &entry = state._curLibPtr->getBoltEntryFromLong(id);
|
2013-05-29 02:39:32 +00:00
|
|
|
|
|
|
|
assert(entry._viewPortResource);
|
|
|
|
_entries.push_back(entry._viewPortResource);
|
2013-05-27 02:18:54 +00:00
|
|
|
}
|
2013-06-08 02:07:57 +00:00
|
|
|
}
|
2013-06-06 01:28:51 +00:00
|
|
|
|
2013-06-08 02:07:57 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
ViewPortPalEntry::ViewPortPalEntry(const byte *src) {
|
2013-12-14 16:07:01 +00:00
|
|
|
const uint16 *v = (const uint16 *)src;
|
2013-06-08 02:07:57 +00:00
|
|
|
_rEntry = READ_LE_UINT16(v++);
|
|
|
|
_gEntry = READ_LE_UINT16(v++);
|
|
|
|
_bEntry = READ_LE_UINT16(v++);
|
2013-06-08 14:31:37 +00:00
|
|
|
_rChange = READ_LE_UINT16(v++);
|
|
|
|
_gChange = READ_LE_UINT16(v++);
|
|
|
|
_bChange = READ_LE_UINT16(v++);
|
|
|
|
_palIndex = READ_LE_UINT16(v++);
|
2013-05-27 02:18:54 +00:00
|
|
|
}
|
|
|
|
|
2013-06-08 02:07:57 +00:00
|
|
|
|
2013-05-28 03:01:15 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-06-15 02:01:59 +00:00
|
|
|
FontResource::FontResource(BoltFilesState &state, byte *src) {
|
|
|
|
_minChar = src[0];
|
|
|
|
_maxChar = src[1];
|
|
|
|
field2 = src[2];
|
|
|
|
_padding = src[3];
|
|
|
|
_fontHeight = src[5];
|
2013-06-19 04:16:51 +00:00
|
|
|
_topPadding = (int8)src[6];
|
2013-06-15 02:01:59 +00:00
|
|
|
|
|
|
|
int totalChars = _maxChar - _minChar + 1;
|
|
|
|
_charWidth = new int[totalChars];
|
|
|
|
for (int i = 0; i < totalChars; ++i)
|
|
|
|
_charWidth[i] = READ_LE_UINT16(src + 8 + 2 * i);
|
|
|
|
|
2013-12-04 03:17:04 +00:00
|
|
|
_charOffsets = src + 8 + totalChars * 2;
|
|
|
|
_charImages = _charOffsets + totalChars * 2;
|
2013-06-15 02:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FontResource::~FontResource() {
|
|
|
|
delete[] _charWidth;
|
2013-05-28 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-06-15 15:39:28 +00:00
|
|
|
FontInfoResource::FontInfoResource(BoltFilesState &state, const byte *src) {
|
|
|
|
_curFont = NULL;
|
|
|
|
_picFlags = src[4];
|
|
|
|
_picSelect = src[5];
|
|
|
|
_picPick = src[6];
|
|
|
|
_picOnOff = src[7];
|
|
|
|
_fontFlags = src[8];
|
|
|
|
_justify = (FontJustify)src[9];
|
|
|
|
_fontSaveBack = READ_LE_UINT16(src + 10);
|
|
|
|
_pos.x = (int16)READ_LE_UINT16(src + 12);
|
|
|
|
_pos.y = (int16)READ_LE_UINT16(src + 14);
|
|
|
|
_justifyWidth = READ_LE_UINT16(src + 16);
|
|
|
|
_justifyHeight = READ_LE_UINT16(src + 18);
|
|
|
|
_shadow.x = READ_LE_UINT16(src + 20);
|
|
|
|
_shadow.y = READ_LE_UINT16(src + 22);
|
|
|
|
_foreColor = READ_LE_UINT16(src + 24);
|
|
|
|
_backColor = READ_LE_UINT16(src + 26);
|
|
|
|
_shadowColor = READ_LE_UINT16(src + 28);
|
|
|
|
}
|
|
|
|
|
|
|
|
FontInfoResource::FontInfoResource() {
|
|
|
|
_curFont = NULL;
|
|
|
|
_picFlags = 3;
|
|
|
|
_picSelect = 0xff;
|
|
|
|
_picPick = 0xff;
|
|
|
|
_picOnOff = 0;
|
|
|
|
_fontFlags = 0;
|
|
|
|
_justify = ALIGN_LEFT;
|
|
|
|
_fontSaveBack = 0;
|
|
|
|
_justifyWidth = 1;
|
|
|
|
_justifyHeight = 1;
|
|
|
|
_shadow = Common::Point(1, 1);
|
|
|
|
_foreColor = 1;
|
|
|
|
_backColor = 0;
|
|
|
|
_shadowColor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontInfoResource::FontInfoResource(byte picFlags, byte picSelect, byte picPick, byte picOnOff,
|
|
|
|
byte fontFlags, FontJustify justify, int fontSaveBack, const Common::Point &pos,
|
|
|
|
int justifyWidth, int justifyHeight, const Common::Point &shadow, int foreColor,
|
|
|
|
int backColor, int shadowColor) {
|
|
|
|
_curFont = NULL;
|
|
|
|
_picFlags = picFlags;
|
|
|
|
_picSelect = picSelect;
|
|
|
|
_picPick = picPick;
|
|
|
|
_picOnOff = picOnOff;
|
|
|
|
_fontFlags = fontFlags;
|
|
|
|
_justify = justify;
|
|
|
|
_fontSaveBack = fontSaveBack;
|
|
|
|
_pos = pos;
|
|
|
|
_justifyWidth = justifyWidth;
|
|
|
|
_justifyHeight = justifyHeight;
|
|
|
|
_shadow = shadow;
|
|
|
|
_foreColor = foreColor;
|
|
|
|
_backColor = backColor;
|
|
|
|
_shadowColor = shadowColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-06-06 01:28:51 +00:00
|
|
|
CMapResource::CMapResource(BoltFilesState &state, const byte *src): _vm(state._vm) {
|
2013-06-06 02:10:13 +00:00
|
|
|
_steps = src[0];
|
|
|
|
_fadeStatus = src[1];
|
2013-05-28 03:01:15 +00:00
|
|
|
_start = READ_LE_UINT16(src + 2);
|
|
|
|
_end = READ_LE_UINT16(src + 4);
|
|
|
|
|
2013-06-18 02:59:26 +00:00
|
|
|
int count = _end - _start + 1;
|
2013-06-06 01:28:51 +00:00
|
|
|
_entries = new byte[count * 3];
|
|
|
|
Common::copy(src + 6, src + 6 + 3 * count, _entries);
|
2013-06-11 01:46:19 +00:00
|
|
|
|
|
|
|
int palIndex = state._vm->_graphicsManager._viewPortListPtr->_palIndex;
|
|
|
|
if (_end > palIndex)
|
|
|
|
_end = palIndex;
|
|
|
|
if (_start > palIndex)
|
|
|
|
_start = palIndex;
|
2013-05-28 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMapResource::~CMapResource() {
|
2013-06-06 01:28:51 +00:00
|
|
|
delete[] _entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapResource::startFade() {
|
|
|
|
_vm->_eventsManager.startFade(this);
|
2013-05-28 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-12-30 05:52:50 +00:00
|
|
|
VInitCycleResource::VInitCycleResource(BoltFilesState &state, const byte *src):
|
|
|
|
_state(state) {
|
|
|
|
// Set up arrays
|
2013-05-28 03:01:15 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2013-12-30 11:00:15 +00:00
|
|
|
_type[i] = READ_LE_UINT16(src + i * 2);
|
2013-05-28 03:01:15 +00:00
|
|
|
state._curLibPtr->resolveIt(READ_LE_UINT32(src + 8 + i * 4), &_ptr[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-30 05:52:50 +00:00
|
|
|
void VInitCycleResource::vStartCycle(int flags) {
|
|
|
|
EventsManager &evt = _state._vm->_eventsManager;
|
|
|
|
evt._cycleIntNode._flags |= 1;
|
|
|
|
evt._cyclePtr = this;
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
evt._cycleNext[i] = _ptr[i];
|
|
|
|
evt._cycleTime[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt._cycleStatus = flags | 1;
|
|
|
|
evt._cycleIntNode._flags &= ~1;
|
2013-12-29 23:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VInitCycleResource::vStopCycle() {
|
2013-12-30 05:52:50 +00:00
|
|
|
EventsManager &evt = _state._vm->_eventsManager;
|
|
|
|
evt._cycleIntNode._flags |= 1;
|
|
|
|
evt._cycleStatus &= ~1;
|
2013-12-29 23:25:46 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 15:40:26 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
2013-12-08 21:51:50 +00:00
|
|
|
|
2013-12-08 15:40:26 +00:00
|
|
|
PtrResource::PtrResource(BoltFilesState &state, const byte *src) {
|
|
|
|
// Load pointer list
|
2013-12-14 16:07:01 +00:00
|
|
|
const uint32 *idP = (const uint32 *)&src[0];
|
2013-12-08 15:40:26 +00:00
|
|
|
int size = state._curMemberPtr->_size;
|
|
|
|
|
|
|
|
for (int i = 0; i < size / 4; ++i, ++idP) {
|
|
|
|
uint32 id = READ_LE_UINT32(idP);
|
|
|
|
BoltEntry &entry = state._curLibPtr->getBoltEntryFromLong(id);
|
|
|
|
|
|
|
|
_entries.push_back(&entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
ControlResource::ControlResource(BoltFilesState &state, const byte *src) {
|
|
|
|
// Get pointer
|
|
|
|
uint32 ptrId = READ_LE_UINT32(&src[0x32]);
|
2013-12-12 03:36:40 +00:00
|
|
|
state._curLibPtr->resolveIt(ptrId, &_ptr);
|
2013-12-08 15:40:26 +00:00
|
|
|
|
2013-12-08 23:23:40 +00:00
|
|
|
for (int i = 0; i < 8; ++i)
|
2013-12-08 21:51:50 +00:00
|
|
|
_memberIds[i] = READ_LE_UINT16(src + i * 2);
|
|
|
|
|
2013-12-08 15:40:26 +00:00
|
|
|
// Load pointer list
|
2013-12-14 16:07:01 +00:00
|
|
|
const uint32 *idP = (const uint32 *)&src[0x10];
|
2013-12-08 15:40:26 +00:00
|
|
|
int count = READ_LE_UINT16(&src[0x36]);
|
|
|
|
|
2013-12-14 03:10:39 +00:00
|
|
|
Common::fill(&_entries[0], &_entries[8], (byte *)nullptr);
|
2013-12-08 15:40:26 +00:00
|
|
|
for (int i = 0; i < count; ++i, ++idP) {
|
|
|
|
uint32 id = READ_LE_UINT32(idP);
|
2013-12-08 23:23:40 +00:00
|
|
|
state._curLibPtr->resolveIt(id, &_entries[i]);
|
2013-12-08 15:40:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-25 05:05:01 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2013-05-20 02:45:54 +00:00
|
|
|
} // End of namespace Voyeur
|