Skip to content

Commit

Permalink
ACCESS: Simplified surface creation, added drawing for scaled flipped…
Browse files Browse the repository at this point in the history
… images
  • Loading branch information
dreammaster committed Aug 19, 2014
1 parent b6dc7a1 commit ad0be89
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
6 changes: 3 additions & 3 deletions engines/access/access.cpp
Expand Up @@ -153,8 +153,8 @@ void AccessEngine::initialize() {
_screen = new Screen(this);
_sound = new SoundManager(this, _mixer);

_buffer1.create(g_system->getWidth() + TILE_WIDTH, g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8());
_buffer2.create(g_system->getWidth(), g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8());
_buffer1.create(g_system->getWidth() + TILE_WIDTH, g_system->getHeight());
_buffer2.create(g_system->getWidth(), g_system->getHeight());
}

Common::Error AccessEngine::run() {
Expand Down Expand Up @@ -272,7 +272,7 @@ void AccessEngine::plotList1() {
bounds.setWidth(bounds.width() / _scale);

if (ie._flags & 2) {
_buffer2.sPlotB(frame, Common::Point(bounds.left, bounds.top));
_buffer2.sPlotB(frame, destBounds);
} else {
_buffer2.sPlotF(frame, destBounds);
}
Expand Down
24 changes: 21 additions & 3 deletions engines/access/asurface.cpp
Expand Up @@ -59,7 +59,7 @@ SpriteResource::~SpriteResource() {
SpriteFrame::SpriteFrame(AccessEngine *vm, Common::MemoryReadStream &stream, int frameSize) {
int xSize = stream.readUint16LE();
int ySize = stream.readUint16LE();
create(xSize, ySize, Graphics::PixelFormat::createFormatCLUT8());
create(xSize, ySize);

// Empty surface
byte *data = (byte *)getPixels();
Expand Down Expand Up @@ -138,6 +138,10 @@ ASurface::~ASurface() {
_savedBlock.free();
}

void ASurface::create(uint16 width, uint16 height) {
Graphics::Surface::create(width, height, Graphics::PixelFormat::createFormatCLUT8());
}

void ASurface::clearBuffer() {
byte *pSrc = (byte *)getPixels();
Common::fill(pSrc, pSrc + w * h, 0);
Expand Down Expand Up @@ -301,8 +305,10 @@ void ASurface::copyTo(ASurface *dest, const Common::Rect &bounds) {
}
}

void ASurface::sPlotB(SpriteFrame *frame, const Common::Point &pt) {
frame->copyTo(this, pt);
void ASurface::sPlotB(SpriteFrame *frame, const Common::Rect &bounds) {
ASurface flippedFrame;
frame->flipHorizontal(flippedFrame);
flippedFrame.copyTo(this, bounds);
}

void ASurface::sPlotF(SpriteFrame *frame, const Common::Rect &bounds) {
Expand Down Expand Up @@ -341,4 +347,16 @@ void ASurface::drawRect() {
Graphics::Surface::fillRect(Common::Rect(_orgX1, _orgY1, _orgX2, _orgY2), _lColor);
}

void ASurface::flipHorizontal(ASurface &dest) {
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;
}
}


} // End of namespace Access
14 changes: 12 additions & 2 deletions engines/access/asurface.h
Expand Up @@ -39,6 +39,8 @@ class ASurface : public Graphics::Surface {
private:
Graphics::Surface _savedBlock;
Common::Rect _savedBounds;

void flipHorizontal(ASurface &dest);
public:
static int _leftSkip, _rightSkip;
static int _topSkip, _bottomSkip;
Expand All @@ -56,6 +58,8 @@ class ASurface : public Graphics::Surface {
public:
virtual ~ASurface();

void create(uint16 width, uint16 height);

void clearBuffer();

void copyBuffer(Graphics::Surface *src) { copyFrom(*src); }
Expand All @@ -64,10 +68,16 @@ class ASurface : public Graphics::Surface {

void plotImage(SpriteResource *sprite, int frameNum, const Common::Point &pt);

void sPlotB(SpriteFrame *frame, const Common::Point &pt);

/**
* Scaled draw frame
*/
void sPlotF(SpriteFrame *frame, const Common::Rect &bounds);

/**
* Scaled flipped horizontal draw frame
*/
void sPlotB(SpriteFrame *frame, const Common::Rect &bounds);

void plotB(SpriteFrame *frame, const Common::Point &pt);

void copyBlock(ASurface *src, const Common::Rect &bounds);
Expand Down
2 changes: 1 addition & 1 deletion engines/access/screen.cpp
Expand Up @@ -35,7 +35,7 @@ namespace Access {
#define VGA_COLOR_TRANS(x) ((x) * 255 / 63)

Screen::Screen(AccessEngine *vm) : _vm(vm) {
create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
create(320, 200);
Common::fill(&_tempPalette[0], &_tempPalette[PALETTE_SIZE], 0);
Common::fill(&_manPal[0], &_manPal[0x60], 0);
Common::fill(&_scaleTable1[0], &_scaleTable1[256], 0);
Expand Down

0 comments on commit ad0be89

Please sign in to comment.