TWINE: brick parser

This commit is contained in:
Martin Gerhardy 2020-12-23 23:31:01 +01:00
parent 728617c397
commit afa1eb4fa8
3 changed files with 119 additions and 0 deletions

View File

@ -16,6 +16,7 @@ MODULE_OBJS := \
parser/anim.o \
parser/body.o \
parser/entity.o \
parser/brick.o \
parser/parser.o \
parser/sprite.o \
\

View File

@ -0,0 +1,60 @@
/* 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 "twine/parser/brick.h"
#include "common/debug.h"
#include "common/memstream.h"
namespace TwinE {
bool BrickData::loadFromStream(Common::SeekableReadStream &stream) {
int width = stream.readByte();
int height = stream.readByte();
_offsetX = stream.readByte();
_offsetY = stream.readByte();
const int maxY = _offsetY + height;
const Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8();
_surface.create(width, height, format);
for (int y = _offsetY; y < maxY; ++y) {
const uint8 numRuns = stream.readByte();
int x = _offsetX;
for (uint8 run = 0; run < numRuns; ++run) {
const uint8 runSpec = stream.readByte();
const uint8 runLength = bits(runSpec, 0, 6) + 1;
const uint8 type = bits(runSpec, 6, 2);
if (type == 2) {
uint8 *start = (uint8 *)_surface.getBasePtr(x, y);
uint8 *end = (uint8 *)_surface.getBasePtr(x + runLength, y);
Common::fill(start, end, stream.readByte());
} else if (type == 1 || type == 3) {
uint8 *start = (uint8 *)_surface.getBasePtr(x, y);
for (uint8 i = 0; i < runLength; ++i) {
*start++ = stream.readByte();
}
}
x += runLength;
}
}
return !stream.err();
}
} // namespace TwinE

View File

@ -0,0 +1,58 @@
/* 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.
*
*/
#ifndef TWINE_BRICK_H
#define TWINE_BRICK_H
#include "common/memstream.h"
#include "common/stream.h"
#include "graphics/managed_surface.h"
#include "twine/parser/parser.h"
#include "twine/shared.h"
namespace TwinE {
class BrickData : public Parser {
private:
Graphics::ManagedSurface _surface;
int _offsetX = 0;
int _offsetY = 0;
public:
bool loadFromStream(Common::SeekableReadStream &stream) override;
inline const Graphics::ManagedSurface &surface() const {
return _surface;
}
inline int offsetX() const {
return _offsetX;
}
inline int offsetY() const {
return _offsetY;
}
};
} // End of namespace TwinE
#endif