2014-08-01 21:32:05 -04: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.
|
2014-12-17 18:27:47 +01:00
|
|
|
*
|
2014-08-01 21:32:05 -04:00
|
|
|
* 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.
|
2014-12-17 18:27:47 +01:00
|
|
|
*
|
2014-08-01 21:32:05 -04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-08-04 21:35:49 -04:00
|
|
|
#include "common/algorithm.h"
|
2014-08-10 16:55:06 -04:00
|
|
|
#include "common/endian.h"
|
|
|
|
#include "common/memstream.h"
|
|
|
|
#include "access/access.h"
|
2014-08-04 21:35:49 -04:00
|
|
|
#include "access/asurface.h"
|
2014-08-01 21:32:05 -04:00
|
|
|
|
|
|
|
namespace Access {
|
|
|
|
|
2015-12-11 21:36:40 -05:00
|
|
|
const int TRANSPARENCY = 0;
|
|
|
|
|
2014-08-27 22:13:43 -04:00
|
|
|
SpriteResource::SpriteResource(AccessEngine *vm, Resource *res) {
|
2014-08-10 16:55:06 -04:00
|
|
|
Common::Array<uint32> offsets;
|
2014-08-27 22:13:43 -04:00
|
|
|
int count = res->_stream->readUint16LE();
|
2014-08-10 16:55:06 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
2014-08-27 22:13:43 -04:00
|
|
|
offsets.push_back(res->_stream->readUint32LE());
|
|
|
|
offsets.push_back(res->_size); // For easier calculations of Noctropolis sizes
|
2014-08-10 16:55:06 -04:00
|
|
|
|
|
|
|
// Build up the frames
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2014-08-27 22:13:43 -04:00
|
|
|
res->_stream->seek(offsets[i]);
|
2014-08-10 16:55:06 -04:00
|
|
|
int frameSize = offsets[i + 1] - offsets[i];
|
|
|
|
|
2014-08-27 22:13:43 -04:00
|
|
|
SpriteFrame *frame = new SpriteFrame(vm, res->_stream, frameSize);
|
2014-08-10 16:55:06 -04:00
|
|
|
_frames.push_back(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteResource::~SpriteResource() {
|
|
|
|
for (uint i = 0; i < _frames.size(); ++i)
|
|
|
|
delete _frames[i];
|
|
|
|
}
|
|
|
|
|
2014-08-27 22:13:43 -04:00
|
|
|
SpriteFrame::SpriteFrame(AccessEngine *vm, Common::SeekableReadStream *stream, int frameSize) {
|
|
|
|
int xSize = stream->readUint16LE();
|
|
|
|
int ySize = stream->readUint16LE();
|
2014-12-29 21:01:38 +01:00
|
|
|
|
|
|
|
if (vm->getGameID() == GType_MartianMemorandum) {
|
|
|
|
int size = stream->readUint16LE();
|
|
|
|
if (size != frameSize)
|
2014-12-29 21:01:38 +01:00
|
|
|
warning("Unexpected file difference: framesize %d - size %d %d - unknown %d", frameSize, xSize, ySize, size);
|
2014-12-29 21:01:38 +01:00
|
|
|
}
|
2014-08-18 20:15:43 -04:00
|
|
|
create(xSize, ySize);
|
2014-12-04 14:17:30 +01:00
|
|
|
|
2014-08-10 16:55:06 -04:00
|
|
|
// Empty surface
|
|
|
|
byte *data = (byte *)getPixels();
|
2015-12-11 21:36:40 -05:00
|
|
|
Common::fill(data, data + w * h, TRANSPARENCY);
|
2014-12-04 14:17:30 +01:00
|
|
|
|
2014-08-10 16:55:06 -04:00
|
|
|
// Decode the data
|
|
|
|
for (int y = 0; y < h; ++y) {
|
2014-08-27 22:13:43 -04:00
|
|
|
int offset = stream->readByte();
|
|
|
|
int len = stream->readByte();
|
2014-08-10 16:55:06 -04:00
|
|
|
assert((offset + len) <= w);
|
|
|
|
|
|
|
|
byte *destP = (byte *)getBasePtr(offset, y);
|
2014-08-27 22:13:43 -04:00
|
|
|
stream->read(destP, len);
|
2014-08-10 16:55:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteFrame::~SpriteFrame() {
|
|
|
|
free();
|
|
|
|
}
|
2014-08-10 11:47:15 -04:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-08-16 15:47:25 -04:00
|
|
|
ImageEntry::ImageEntry() {
|
|
|
|
_frameNumber = 0;
|
|
|
|
_spritesPtr = nullptr;
|
2014-08-19 20:31:23 -04:00
|
|
|
_offsetY = 0;
|
2014-08-16 15:47:25 -04:00
|
|
|
_flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-08-14 22:02:47 -04:00
|
|
|
static bool sortImagesY(const ImageEntry &ie1, const ImageEntry &ie2) {
|
2014-11-10 18:48:16 -05:00
|
|
|
int v = (ie1._position.y + ie1._offsetY) - (ie2._position.y + ie2._offsetY);
|
|
|
|
return (v < 0) || (v == 0 && ie1._position.y <= ie2._position.y);
|
2014-08-14 22:02:47 -04:00
|
|
|
}
|
|
|
|
|
2014-11-10 12:25:13 -05:00
|
|
|
void ImageEntryList::addToList(ImageEntry &ie) {
|
2014-08-14 22:02:47 -04:00
|
|
|
assert(size() < 35);
|
2014-11-10 12:25:13 -05:00
|
|
|
push_back(ie);
|
2014-08-14 22:02:47 -04:00
|
|
|
Common::sort(begin(), end(), sortImagesY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
int BaseSurface::_clipWidth;
|
|
|
|
int BaseSurface::_clipHeight;
|
2014-12-18 21:45:55 -05:00
|
|
|
|
2016-05-27 06:00:48 -04:00
|
|
|
BaseSurface::BaseSurface(): Graphics::Screen(0, 0) {
|
|
|
|
free(); // Free the 0x0 surface allocated by Graphics::Screen
|
2014-08-10 15:50:22 -04:00
|
|
|
_leftSkip = _rightSkip = 0;
|
|
|
|
_topSkip = _bottomSkip = 0;
|
|
|
|
_lastBoundsX = _lastBoundsY = 0;
|
|
|
|
_lastBoundsW = _lastBoundsH = 0;
|
2014-08-17 18:56:05 -04:00
|
|
|
_orgX1 = _orgY1 = 0;
|
|
|
|
_orgX2 = _orgY2 = 0;
|
|
|
|
_lColor = 0;
|
2014-12-19 23:36:53 -05:00
|
|
|
_maxChars = 0;
|
2014-08-10 15:50:22 -04:00
|
|
|
}
|
2014-08-10 11:47:15 -04:00
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
BaseSurface::~BaseSurface() {
|
2014-08-16 20:26:17 -04:00
|
|
|
_savedBlock.free();
|
2014-08-13 22:45:15 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::clearBuffer() {
|
2014-08-04 21:35:49 -04:00
|
|
|
byte *pSrc = (byte *)getPixels();
|
|
|
|
Common::fill(pSrc, pSrc + w * h, 0);
|
2014-08-01 21:32:05 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Point &pt) {
|
2014-08-10 11:47:15 -04:00
|
|
|
SpriteFrame *frame = sprite->getFrame(frameNum);
|
|
|
|
Common::Rect r(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h);
|
|
|
|
|
|
|
|
if (!clip(r)) {
|
|
|
|
_lastBoundsX = r.left;
|
|
|
|
_lastBoundsY = r.top;
|
|
|
|
_lastBoundsW = r.width();
|
|
|
|
_lastBoundsH = r.height();
|
|
|
|
|
2014-08-21 22:15:00 -04:00
|
|
|
plotF(frame, pt);
|
2014-08-10 11:47:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::copyBuffer(Graphics::ManagedSurface *src) {
|
2014-12-19 22:45:00 -05:00
|
|
|
blitFrom(*src);
|
2014-08-23 23:21:17 -04:00
|
|
|
}
|
2014-08-21 22:15:00 -04:00
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::plotF(SpriteFrame *frame, const Common::Point &pt) {
|
2014-08-22 22:15:53 -04:00
|
|
|
sPlotF(frame, Common::Rect(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h));
|
2014-08-21 22:15:00 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::plotB(SpriteFrame *frame, const Common::Point &pt) {
|
2014-08-22 22:15:53 -04:00
|
|
|
sPlotB(frame, Common::Rect(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h));
|
2014-08-11 23:12:53 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::sPlotF(SpriteFrame *frame, const Common::Rect &bounds) {
|
2016-03-10 21:51:06 -05:00
|
|
|
transBlitFrom(*frame, Common::Rect(0, 0, frame->w, frame->h), bounds, TRANSPARENCY, false);
|
2014-08-11 23:12:53 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::sPlotB(SpriteFrame *frame, const Common::Rect &bounds) {
|
2016-03-10 21:51:06 -05:00
|
|
|
transBlitFrom(*frame, Common::Rect(0, 0, frame->w, frame->h), bounds, TRANSPARENCY, true);
|
2014-08-11 23:12:53 -04:00
|
|
|
}
|
2014-08-10 19:19:32 -04:00
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::copyBlock(BaseSurface *src, const Common::Rect &bounds) {
|
2014-08-22 22:55:17 -04:00
|
|
|
copyRectToSurface(*src, bounds.left, bounds.top, bounds);
|
2014-08-12 08:38:12 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::copyTo(BaseSurface *dest) {
|
2015-12-10 20:20:51 -05:00
|
|
|
if (dest->empty())
|
|
|
|
dest->create(this->w, this->h);
|
|
|
|
|
2016-10-09 14:59:58 +02:00
|
|
|
dest->blitFrom(*this);
|
2015-12-10 20:20:51 -05:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::saveBlock(const Common::Rect &bounds) {
|
2014-08-16 20:26:17 -04:00
|
|
|
_savedBounds = bounds;
|
|
|
|
_savedBounds.clip(Common::Rect(0, 0, this->w, this->h));
|
|
|
|
|
|
|
|
_savedBlock.free();
|
|
|
|
_savedBlock.create(bounds.width(), bounds.height(),
|
|
|
|
Graphics::PixelFormat::createFormatCLUT8());
|
|
|
|
_savedBlock.copyRectToSurface(*this, 0, 0, _savedBounds);
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::restoreBlock() {
|
2014-08-16 20:26:17 -04:00
|
|
|
if (!_savedBounds.isEmpty()) {
|
|
|
|
copyRectToSurface(_savedBlock, _savedBounds.left, _savedBounds.top,
|
|
|
|
Common::Rect(0, 0, _savedBlock.w, _savedBlock.h));
|
|
|
|
|
|
|
|
_savedBlock.free();
|
|
|
|
_savedBounds = Common::Rect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::drawRect() {
|
2016-03-10 21:51:06 -05:00
|
|
|
Graphics::ManagedSurface::fillRect(Common::Rect(_orgX1, _orgY1, _orgX2, _orgY2), _lColor);
|
2014-08-17 18:56:05 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::drawLine(int x1, int y1, int x2, int y2, int col) {
|
2016-03-10 21:51:06 -05:00
|
|
|
Graphics::ManagedSurface::drawLine(x1, y1, x2, y2, col);
|
2015-01-13 00:46:45 +01:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::drawLine() {
|
2016-03-10 21:51:06 -05:00
|
|
|
Graphics::ManagedSurface::drawLine(_orgX1, _orgY1, _orgX2, _orgY1, _lColor);
|
2015-01-15 08:23:55 +01:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::drawBox() {
|
2016-03-10 21:51:06 -05:00
|
|
|
Graphics::ManagedSurface::drawLine(_orgX1, _orgY1, _orgX2, _orgY1, _lColor);
|
|
|
|
Graphics::ManagedSurface::drawLine(_orgX1, _orgY2, _orgX2, _orgY2, _lColor);
|
|
|
|
Graphics::ManagedSurface::drawLine(_orgX2, _orgY1, _orgX2, _orgY1, _lColor);
|
|
|
|
Graphics::ManagedSurface::drawLine(_orgX2, _orgY2, _orgX2, _orgY2, _lColor);
|
2015-01-13 00:46:45 +01:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::flipHorizontal(BaseSurface &dest) {
|
2014-08-18 20:15:43 -04:00
|
|
|
dest.create(this->w, this->h);
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
const byte *pSrc = (const byte *)getBasePtr(this->w - 1, y);
|
|
|
|
byte *pDest = (byte *)dest.getBasePtr(0, y);
|
|
|
|
|
|
|
|
for (int x = 0; x < w; ++x, --pSrc, ++pDest)
|
|
|
|
*pDest = *pSrc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::moveBufferLeft() {
|
2014-08-23 17:19:54 -04:00
|
|
|
byte *p = (byte *)getPixels();
|
|
|
|
Common::copy(p + TILE_WIDTH, p + (w * h), p);
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::moveBufferRight() {
|
2014-08-23 17:19:54 -04:00
|
|
|
byte *p = (byte *)getPixels();
|
2014-11-27 16:32:25 -05:00
|
|
|
Common::copy_backward(p, p + (pitch * h) - TILE_WIDTH, p + (pitch * h));
|
2014-08-23 17:19:54 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::moveBufferUp() {
|
2014-08-23 17:19:54 -04:00
|
|
|
byte *p = (byte *)getPixels();
|
2014-11-27 16:32:25 -05:00
|
|
|
Common::copy(p + (pitch * TILE_HEIGHT), p + (pitch * h), p);
|
2014-08-23 17:19:54 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
void BaseSurface::moveBufferDown() {
|
2014-08-23 17:19:54 -04:00
|
|
|
byte *p = (byte *)getPixels();
|
2014-11-27 16:32:25 -05:00
|
|
|
Common::copy_backward(p, p + (pitch * (h - TILE_HEIGHT)), p + (pitch * h));
|
2014-08-23 17:19:54 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 21:21:03 -04:00
|
|
|
bool BaseSurface::clip(Common::Rect &r) {
|
2016-03-10 21:51:06 -05:00
|
|
|
int skip;
|
|
|
|
_leftSkip = _rightSkip = 0;
|
|
|
|
_topSkip = _bottomSkip = 0;
|
|
|
|
|
|
|
|
if (r.left > _clipWidth || r.left < 0) {
|
|
|
|
if (r.left >= 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
skip = -r.left;
|
|
|
|
r.setWidth(r.width() - skip);
|
|
|
|
_leftSkip = skip;
|
|
|
|
r.moveTo(0, r.top);
|
|
|
|
}
|
|
|
|
|
|
|
|
int right = r.right - 1;
|
|
|
|
if (right < 0)
|
|
|
|
return true;
|
|
|
|
else if (right > _clipWidth) {
|
|
|
|
skip = right - _clipWidth;
|
|
|
|
r.setWidth(r.width() - skip);
|
|
|
|
_rightSkip = skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r.top > _clipHeight || r.top < 0) {
|
|
|
|
if (r.top >= 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
skip = -r.top;
|
|
|
|
r.setHeight(r.height() - skip);
|
|
|
|
_topSkip = skip;
|
|
|
|
r.moveTo(r.left, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bottom = r.bottom - 1;
|
|
|
|
if (bottom < 0)
|
|
|
|
return true;
|
|
|
|
else if (bottom > _clipHeight) {
|
|
|
|
skip = bottom - _clipHeight;
|
|
|
|
_bottomSkip = skip;
|
|
|
|
r.setHeight(r.height() - skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-01 21:32:05 -04:00
|
|
|
} // End of namespace Access
|