ACCESS: Refactor ASurface and Screen to not use virtual inheritance

This commit is contained in:
Paul Gilbert 2016-05-26 21:21:03 -04:00
parent 741e26cfd2
commit ac8adb07c8
12 changed files with 72 additions and 56 deletions

View File

@ -244,7 +244,7 @@ void AccessEngine::freeCells() {
}
}
void AccessEngine::speakText(ASurface *s, const Common::String &msg) {
void AccessEngine::speakText(BaseSurface *s, const Common::String &msg) {
Common::String lines = msg;
Common::String line;
int curPage = 0;
@ -325,7 +325,7 @@ void AccessEngine::speakText(ASurface *s, const Common::String &msg) {
}
}
void AccessEngine::printText(ASurface *s, const Common::String &msg) {
void AccessEngine::printText(BaseSurface *s, const Common::String &msg) {
Common::String lines = msg;
Common::String line;
int width = 0;

View File

@ -156,8 +156,8 @@ public:
MusicManager *_midi;
VideoPlayer *_video;
ASurface *_destIn;
ASurface *_current;
BaseSurface *_destIn;
BaseSurface *_current;
ASurface _buffer1;
ASurface _buffer2;
ASurface _vidBuf;
@ -280,8 +280,8 @@ public:
/**
* Draw a string on a given surface and update text positioning
*/
void printText(ASurface *s, const Common::String &msg);
void speakText(ASurface *s, const Common::String &msg);
void printText(BaseSurface *s, const Common::String &msg);
void speakText(BaseSurface *s, const Common::String &msg);
/**
* Load a savegame

View File

@ -496,7 +496,7 @@ void AmazonEngine::drawHelp(const Common::String str) {
_files->loadScreen(95, 2);
if (_moreHelp == 1) {
ASurface *oldDest = _destIn;
BaseSurface *oldDest = _destIn;
_destIn = _screen;
int oldClip = _screen->_clipHeight;
_screen->_clipHeight = 200;

View File

@ -107,10 +107,10 @@ void ImageEntryList::addToList(ImageEntry &ie) {
/*------------------------------------------------------------------------*/
int ASurface::_clipWidth;
int ASurface::_clipHeight;
int BaseSurface::_clipWidth;
int BaseSurface::_clipHeight;
ASurface::ASurface(): Graphics::ManagedSurface() {
BaseSurface::BaseSurface(): Graphics::Screen() {
_leftSkip = _rightSkip = 0;
_topSkip = _bottomSkip = 0;
_lastBoundsX = _lastBoundsY = 0;
@ -121,16 +121,16 @@ ASurface::ASurface(): Graphics::ManagedSurface() {
_maxChars = 0;
}
ASurface::~ASurface() {
BaseSurface::~BaseSurface() {
_savedBlock.free();
}
void ASurface::clearBuffer() {
void BaseSurface::clearBuffer() {
byte *pSrc = (byte *)getPixels();
Common::fill(pSrc, pSrc + w * h, 0);
}
void ASurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Point &pt) {
void BaseSurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Point &pt) {
SpriteFrame *frame = sprite->getFrame(frameNum);
Common::Rect r(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h);
@ -144,38 +144,38 @@ void ASurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Poi
}
}
void ASurface::copyBuffer(Graphics::ManagedSurface *src) {
void BaseSurface::copyBuffer(Graphics::ManagedSurface *src) {
blitFrom(*src);
}
void ASurface::plotF(SpriteFrame *frame, const Common::Point &pt) {
void BaseSurface::plotF(SpriteFrame *frame, const Common::Point &pt) {
sPlotF(frame, Common::Rect(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h));
}
void ASurface::plotB(SpriteFrame *frame, const Common::Point &pt) {
void BaseSurface::plotB(SpriteFrame *frame, const Common::Point &pt) {
sPlotB(frame, Common::Rect(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h));
}
void ASurface::sPlotF(SpriteFrame *frame, const Common::Rect &bounds) {
void BaseSurface::sPlotF(SpriteFrame *frame, const Common::Rect &bounds) {
transBlitFrom(*frame, Common::Rect(0, 0, frame->w, frame->h), bounds, TRANSPARENCY, false);
}
void ASurface::sPlotB(SpriteFrame *frame, const Common::Rect &bounds) {
void BaseSurface::sPlotB(SpriteFrame *frame, const Common::Rect &bounds) {
transBlitFrom(*frame, Common::Rect(0, 0, frame->w, frame->h), bounds, TRANSPARENCY, true);
}
void ASurface::copyBlock(ASurface *src, const Common::Rect &bounds) {
void BaseSurface::copyBlock(BaseSurface *src, const Common::Rect &bounds) {
copyRectToSurface(*src, bounds.left, bounds.top, bounds);
}
void ASurface::copyTo(ASurface *dest) {
void BaseSurface::copyTo(BaseSurface *dest) {
if (dest->empty())
dest->create(this->w, this->h);
dest->blitFrom(*this);
}
void ASurface::saveBlock(const Common::Rect &bounds) {
void BaseSurface::saveBlock(const Common::Rect &bounds) {
_savedBounds = bounds;
_savedBounds.clip(Common::Rect(0, 0, this->w, this->h));
@ -185,7 +185,7 @@ void ASurface::saveBlock(const Common::Rect &bounds) {
_savedBlock.copyRectToSurface(*this, 0, 0, _savedBounds);
}
void ASurface::restoreBlock() {
void BaseSurface::restoreBlock() {
if (!_savedBounds.isEmpty()) {
copyRectToSurface(_savedBlock, _savedBounds.left, _savedBounds.top,
Common::Rect(0, 0, _savedBlock.w, _savedBlock.h));
@ -195,26 +195,26 @@ void ASurface::restoreBlock() {
}
}
void ASurface::drawRect() {
void BaseSurface::drawRect() {
Graphics::ManagedSurface::fillRect(Common::Rect(_orgX1, _orgY1, _orgX2, _orgY2), _lColor);
}
void ASurface::drawLine(int x1, int y1, int x2, int y2, int col) {
void BaseSurface::drawLine(int x1, int y1, int x2, int y2, int col) {
Graphics::ManagedSurface::drawLine(x1, y1, x2, y2, col);
}
void ASurface::drawLine() {
void BaseSurface::drawLine() {
Graphics::ManagedSurface::drawLine(_orgX1, _orgY1, _orgX2, _orgY1, _lColor);
}
void ASurface::drawBox() {
void BaseSurface::drawBox() {
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);
}
void ASurface::flipHorizontal(ASurface &dest) {
void BaseSurface::flipHorizontal(BaseSurface &dest) {
dest.create(this->w, this->h);
for (int y = 0; y < h; ++y) {
const byte *pSrc = (const byte *)getBasePtr(this->w - 1, y);
@ -225,27 +225,27 @@ void ASurface::flipHorizontal(ASurface &dest) {
}
}
void ASurface::moveBufferLeft() {
void BaseSurface::moveBufferLeft() {
byte *p = (byte *)getPixels();
Common::copy(p + TILE_WIDTH, p + (w * h), p);
}
void ASurface::moveBufferRight() {
void BaseSurface::moveBufferRight() {
byte *p = (byte *)getPixels();
Common::copy_backward(p, p + (pitch * h) - TILE_WIDTH, p + (pitch * h));
}
void ASurface::moveBufferUp() {
void BaseSurface::moveBufferUp() {
byte *p = (byte *)getPixels();
Common::copy(p + (pitch * TILE_HEIGHT), p + (pitch * h), p);
}
void ASurface::moveBufferDown() {
void BaseSurface::moveBufferDown() {
byte *p = (byte *)getPixels();
Common::copy_backward(p, p + (pitch * (h - TILE_HEIGHT)), p + (pitch * h));
}
bool ASurface::clip(Common::Rect &r) {
bool BaseSurface::clip(Common::Rect &r) {
int skip;
_leftSkip = _rightSkip = 0;
_topSkip = _bottomSkip = 0;

View File

@ -27,7 +27,7 @@
#include "common/array.h"
#include "common/memstream.h"
#include "common/rect.h"
#include "graphics/managed_surface.h"
#include "graphics/screen.h"
#include "access/data.h"
namespace Access {
@ -35,11 +35,16 @@ namespace Access {
class SpriteResource;
class SpriteFrame;
class ASurface : virtual public Graphics::ManagedSurface {
/**
* Base Access surface class. This derivces from Graphics::Screen
* because it has logic we'll need for our own Screen class that
* derives from this one
*/
class BaseSurface : virtual public Graphics::Screen {
private:
Graphics::Surface _savedBlock;
void flipHorizontal(ASurface &dest);
void flipHorizontal(BaseSurface &dest);
protected:
Common::Rect _savedBounds;
public:
@ -57,9 +62,9 @@ public:
public:
static int _clipWidth, _clipHeight;
public:
ASurface();
BaseSurface();
virtual ~ASurface();
virtual ~BaseSurface();
void clearBuffer();
@ -85,7 +90,7 @@ public:
*/
void plotB(SpriteFrame *frame, const Common::Point &pt);
virtual void copyBlock(ASurface *src, const Common::Rect &bounds);
virtual void copyBlock(BaseSurface *src, const Common::Rect &bounds);
virtual void restoreBlock();
@ -99,7 +104,7 @@ public:
virtual void copyBuffer(Graphics::ManagedSurface *src);
void copyTo(ASurface *dest);
void copyTo(BaseSurface *dest);
void saveBlock(const Common::Rect &bounds);
@ -114,6 +119,17 @@ public:
bool clip(Common::Rect &r);
};
class ASurface : public BaseSurface {
protected:
/**
* Override the addDirtyRect from Graphics::Screen, since for standard
* surfaces we don't need dirty rects to be tracked
*/
virtual void addDirtyRect(const Common::Rect &r) {}
public:
ASurface() : BaseSurface() {}
};
class SpriteFrame : public ASurface {
public:
SpriteFrame(AccessEngine *vm, Common::SeekableReadStream *stream, int frameSize);

View File

@ -228,7 +228,7 @@ void BubbleBox::drawBubble(int index) {
void BubbleBox::doBox(int item, int box) {
FontManager &fonts = _vm->_fonts;
ASurface &screen = *_vm->_screen;
Screen &screen = *_vm->_screen;
_startItem = item;
_startBox = box;

View File

@ -139,7 +139,7 @@ bool Font::getLine(Common::String &s, int maxWidth, Common::String &line, int &w
return true;
}
void Font::drawString(ASurface *s, const Common::String &msg, const Common::Point &pt) {
void Font::drawString(BaseSurface *s, const Common::String &msg, const Common::Point &pt) {
Common::Point currPt = pt;
const char *msgP = msg.c_str();
@ -149,7 +149,7 @@ void Font::drawString(ASurface *s, const Common::String &msg, const Common::Poin
}
}
int Font::drawChar(ASurface *s, char c, Common::Point &pt) {
int Font::drawChar(BaseSurface *s, char c, Common::Point &pt) {
Graphics::Surface &ch = _chars[c - ' '];
Graphics::Surface dest = s->getSubArea(Common::Rect(pt.x, pt.y, pt.x + ch.w, pt.y + ch.h));

View File

@ -78,12 +78,12 @@ public:
/**
* Draw a string on a given surface
*/
void drawString(ASurface *s, const Common::String &msg, const Common::Point &pt);
void drawString(BaseSurface *s, const Common::String &msg, const Common::Point &pt);
/**
* Draw a character on a given surface
*/
int drawChar(ASurface *s, char c, Common::Point &pt);
int drawChar(BaseSurface *s, char c, Common::Point &pt);
};

View File

@ -264,22 +264,22 @@ void Screen::copyBlock(ASurface *src, const Common::Rect &bounds) {
void Screen::restoreBlock() {
if (!_savedBounds.isEmpty())
addDirtyRect(_savedBounds);
ASurface::restoreBlock();
BaseSurface::restoreBlock();
}
void Screen::drawRect() {
addDirtyRect(Common::Rect(_orgX1, _orgY1, _orgX2, _orgY2));
ASurface::drawRect();
BaseSurface::drawRect();
}
void Screen::drawBox() {
addDirtyRect(Common::Rect(_orgX1, _orgY1, _orgX2, _orgY2));
ASurface::drawBox();
BaseSurface::drawBox();
}
void Screen::copyBuffer(Graphics::ManagedSurface *src) {
addDirtyRect(Common::Rect(0, 0, src->w, src->h));
ASurface::copyBuffer(src);
BaseSurface::copyBuffer(src);
}
void Screen::setPaletteCycle(int startCycle, int endCycle, int timer) {

View File

@ -45,7 +45,7 @@ struct ScreenSave {
int _screenYOff;
};
class Screen : public virtual ASurface, public virtual Graphics::Screen {
class Screen : public BaseSurface {
private:
AccessEngine *_vm;
byte _tempPalette[PALETTE_SIZE];

View File

@ -48,7 +48,7 @@ VideoPlayer::~VideoPlayer() {
closeVideo();
}
void VideoPlayer::setVideo(ASurface *vidSurface, const Common::Point &pt, int rate) {
void VideoPlayer::setVideo(BaseSurface *vidSurface, const Common::Point &pt, int rate) {
_vidSurface = vidSurface;
vidSurface->_orgX1 = pt.x;
vidSurface->_orgY1 = pt.y;
@ -87,14 +87,14 @@ void VideoPlayer::setVideo(ASurface *vidSurface, const Common::Point &pt, int ra
_videoEnd = false;
}
void VideoPlayer::setVideo(ASurface *vidSurface, const Common::Point &pt, const Common::String filename, int rate) {
void VideoPlayer::setVideo(BaseSurface *vidSurface, const Common::Point &pt, const Common::String filename, int rate) {
// Open up video stream
_videoData = _vm->_files->loadFile(filename);
setVideo(vidSurface, pt, rate);
}
void VideoPlayer::setVideo(ASurface *vidSurface, const Common::Point &pt, const FileIdent &videoFile, int rate) {
void VideoPlayer::setVideo(BaseSurface *vidSurface, const Common::Point &pt, const FileIdent &videoFile, int rate) {
// Open up video stream
_videoData = _vm->_files->loadFile(videoFile);

View File

@ -40,7 +40,7 @@ class VideoPlayer : public Manager {
VideoFlags _flags;
};
private:
ASurface *_vidSurface;
BaseSurface *_vidSurface;
Resource *_videoData;
VideoHeader _header;
byte *_startCoord;
@ -51,7 +51,7 @@ private:
Common::Rect _videoBounds;
void getFrame();
void setVideo(ASurface *vidSurface, const Common::Point &pt, int rate);
void setVideo(BaseSurface *vidSurface, const Common::Point &pt, int rate);
public:
int _videoFrame;
bool _soundFlag;
@ -64,8 +64,8 @@ public:
/**
* Start up a video
*/
void setVideo(ASurface *vidSurface, const Common::Point &pt, const FileIdent &videoFile, int rate);
void setVideo(ASurface *vidSurface, const Common::Point &pt, const Common::String filename, int rate);
void setVideo(BaseSurface *vidSurface, const Common::Point &pt, const FileIdent &videoFile, int rate);
void setVideo(BaseSurface *vidSurface, const Common::Point &pt, const Common::String filename, int rate);
/**
* Decodes a frame of the video