MADS: Refactor MSurface and Screen to not use virtual inheritance

This commit is contained in:
Paul Gilbert 2016-05-26 21:37:52 -04:00
parent ac8adb07c8
commit 78e52365bd
19 changed files with 69 additions and 59 deletions

View File

@ -201,7 +201,7 @@ Common::String DragonsphereScene::formAnimName(char sepChar, int suffixNum) {
/*------------------------------------------------------------------------*/
void SceneInfoDragonsphere::loadCodes(MSurface &depthSurface, int variant) {
void SceneInfoDragonsphere::loadCodes(BaseSurface &depthSurface, int variant) {
Common::String ext = Common::String::format(".WW%d", variant);
Common::String fileName = Resources::formatName(RESPREFIX_RM, _sceneId, ext);
if (!Common::File::exists(fileName))
@ -217,7 +217,7 @@ void SceneInfoDragonsphere::loadCodes(MSurface &depthSurface, int variant) {
f.close();
}
void SceneInfoDragonsphere::loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream) {
void SceneInfoDragonsphere::loadCodes(BaseSurface &depthSurface, Common::SeekableReadStream *stream) {
byte *destP = (byte *)depthSurface.getPixels();
byte *walkMap = new byte[stream->size()];
stream->read(walkMap, stream->size());

View File

@ -647,9 +647,9 @@ public:
class SceneInfoDragonsphere : public SceneInfo {
friend class SceneInfo;
protected:
virtual void loadCodes(MSurface &depthSurface, int variant);
virtual void loadCodes(BaseSurface &depthSurface, int variant);
virtual void loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream);
virtual void loadCodes(BaseSurface &depthSurface, Common::SeekableReadStream *stream);
/**
* Constructor

View File

@ -145,7 +145,7 @@ void Font::setColorMode(SelectionMode mode) {
}
}
int Font::writeString(MSurface *surface, const Common::String &msg, const Common::Point &pt,
int Font::writeString(BaseSurface *surface, const Common::String &msg, const Common::Point &pt,
int spaceWidth, int width) {
int xEnd;
if (width > 0)

View File

@ -86,7 +86,7 @@ public:
int maxWidth() const { return _maxWidth; }
int getWidth(const Common::String &msg, int spaceWidth = -1);
int getHeight() const { return _maxHeight; }
int writeString(MSurface *surface, const Common::String &msg, const Common::Point &pt,
int writeString(BaseSurface *surface, const Common::String &msg, const Common::Point &pt,
int spaceWidth = 0, int width = 0);
};

View File

@ -558,7 +558,7 @@ void TextDisplayList::setDirtyAreas2() {
}
}
void TextDisplayList::draw(MSurface *s) {
void TextDisplayList::draw(BaseSurface *s) {
for (uint idx = 0; idx < size(); ++idx) {
TextDisplay &td = (*this)[idx];
if (td._active && (td._expire >= 0)) {

View File

@ -170,7 +170,7 @@ public:
* Draw any text in the list to the specified surface
* @param surface Surface
*/
void draw(MSurface *s);
void draw(BaseSurface *s);
/**
* Determine dirty areas for active text areas

View File

@ -30,9 +30,9 @@
namespace MADS {
MADSEngine *MSurface::_vm = nullptr;
MADSEngine *BaseSurface::_vm = nullptr;
int MSurface::scaleValue(int value, int scale, int err) {
int BaseSurface::scaleValue(int value, int scale, int err) {
int scaled = 0;
while (value--) {
err -= scale;
@ -44,7 +44,7 @@ int MSurface::scaleValue(int value, int scale, int err) {
return scaled;
}
void MSurface::drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect) {
void BaseSurface::drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect) {
enum {
kStatusSkip,
kStatusScale,
@ -171,7 +171,7 @@ void MSurface::drawSprite(const Common::Point &pt, SpriteInfo &info, const Commo
delete[] scaledLineBuf;
}
void MSurface::scrollX(int xAmount) {
void BaseSurface::scrollX(int xAmount) {
if (xAmount == 0)
return;
@ -203,7 +203,7 @@ void MSurface::scrollX(int xAmount) {
markAllDirty();
}
void MSurface::scrollY(int yAmount) {
void BaseSurface::scrollY(int yAmount) {
if (yAmount == 0)
return;
@ -238,7 +238,7 @@ void MSurface::scrollY(int yAmount) {
delete[] tempData;
}
void MSurface::translate(Common::Array<RGB6> &palette) {
void BaseSurface::translate(Common::Array<RGB6> &palette) {
for (int y = 0; y < this->h; ++y) {
byte *pDest = (byte *)getBasePtr(0, y);
@ -251,7 +251,7 @@ void MSurface::translate(Common::Array<RGB6> &palette) {
markAllDirty();
}
void MSurface::translate(byte map[PALETTE_COUNT]) {
void BaseSurface::translate(byte map[PALETTE_COUNT]) {
for (int y = 0; y < this->h; ++y) {
byte *pDest = (byte *)getBasePtr(0, y);
@ -263,7 +263,7 @@ void MSurface::translate(byte map[PALETTE_COUNT]) {
markAllDirty();
}
MSurface *MSurface::flipHorizontal() const {
BaseSurface *BaseSurface::flipHorizontal() const {
MSurface *dest = new MSurface(this->w, this->h);
for (int y = 0; y < this->h; ++y) {
@ -277,7 +277,7 @@ MSurface *MSurface::flipHorizontal() const {
return dest;
}
void MSurface::copyRectTranslate(MSurface &srcSurface, const byte *paletteMap,
void BaseSurface::copyRectTranslate(BaseSurface &srcSurface, const byte *paletteMap,
const Common::Point &destPos, const Common::Rect &srcRect) {
// Loop through the lines
for (int yCtr = 0; yCtr < srcRect.height(); ++yCtr) {
@ -294,7 +294,7 @@ void MSurface::copyRectTranslate(MSurface &srcSurface, const byte *paletteMap,
destPos.y + srcRect.height()));
}
void MSurface::copyFrom(MSurface &src, const Common::Point &destPos, int depth,
void BaseSurface::copyFrom(BaseSurface &src, const Common::Point &destPos, int depth,
DepthSurface *depthSurface, int scale, bool flipped, int transparentColor) {
int destX = destPos.x, destY = destPos.y;
int frameWidth = src.w;
@ -337,15 +337,13 @@ void MSurface::copyFrom(MSurface &src, const Common::Point &destPos, int depth,
if (destX < 0) {
copyRect.left += -destX;
destX = 0;
}
else if (destX + copyRect.width() > w) {
} else if (destX + copyRect.width() > w) {
copyRect.right -= destX + copyRect.width() - w;
}
if (destY < 0) {
copyRect.top += -destY;
destY = 0;
}
else if (destY + copyRect.height() > h) {
} else if (destY + copyRect.height() > h) {
copyRect.bottom -= destY + copyRect.height() - h;
}

View File

@ -25,7 +25,7 @@
#include "common/scummsys.h"
#include "common/rect.h"
#include "graphics/managed_surface.h"
#include "graphics/screen.h"
#include "mads/palette.h"
namespace MADS {
@ -48,9 +48,11 @@ struct SpriteInfo {
};
/*
* MADS graphics surface
* Base MADS 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 MSurface : virtual public Graphics::ManagedSurface {
class BaseSurface : public Graphics::Screen {
private:
/**
* Helper method for calculating new dimensions when scaling a sprite
@ -72,17 +74,17 @@ public:
/**
* Basic constructor
*/
MSurface() : Graphics::ManagedSurface() {}
BaseSurface() : Graphics::Screen() {}
/**
* Constructor for a surface with fixed dimensions
*/
MSurface(int width, int height) : Graphics::ManagedSurface(width, height) {}
BaseSurface(int width, int height) : Graphics::Screen(width, height) {}
/**
* Destructor
*/
virtual ~MSurface() {}
virtual ~BaseSurface() {}
/**
* Return a rect containing the bounds of the surface
@ -142,13 +144,13 @@ public:
/**
* Create a new surface which is a flipped horizontal copy of the current one
*/
MSurface *flipHorizontal() const;
BaseSurface *flipHorizontal() const;
/**
* Copy an area from one surface to another, translating it using a palette
* map as it's done
*/
void copyRectTranslate(MSurface &srcSurface, const byte *paletteMap,
void copyRectTranslate(BaseSurface &srcSurface, const byte *paletteMap,
const Common::Point &destPos, const Common::Rect &srcRect);
/**
@ -161,10 +163,22 @@ public:
* @param flipped Flag for whether image is to be flipped
* @param transparentColor Transparency palette index
*/
void copyFrom(MSurface &src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
void copyFrom(BaseSurface &src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
int scale, bool flipped, int transparentColor = -1);
};
class MSurface : 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:
MSurface() : BaseSurface() {}
MSurface(int width, int height) : BaseSurface(width, height) {}
};
class DepthSurface : public MSurface {
public:
/**

View File

@ -311,7 +311,7 @@ Common::String NebularScene::formAnimName(char sepChar, int suffixNum) {
/*------------------------------------------------------------------------*/
void SceneInfoNebular::loadCodes(MSurface &depthSurface, int variant) {
void SceneInfoNebular::loadCodes(BaseSurface &depthSurface, int variant) {
File f(Resources::formatName(RESPREFIX_RM, _sceneId, ".DAT"));
MadsPack codesPack(&f);
Common::SeekableReadStream *stream = codesPack.getItemStream(variant + 1);
@ -322,7 +322,7 @@ void SceneInfoNebular::loadCodes(MSurface &depthSurface, int variant) {
f.close();
}
void SceneInfoNebular::loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream) {
void SceneInfoNebular::loadCodes(BaseSurface &depthSurface, Common::SeekableReadStream *stream) {
byte *destP = (byte *)depthSurface.getPixels();
byte *endP = (byte *)depthSurface.getBasePtr(0, depthSurface.h);

View File

@ -1373,9 +1373,9 @@ public:
class SceneInfoNebular : public SceneInfo {
friend class SceneInfo;
protected:
virtual void loadCodes(MSurface &depthSurface, int variant);
virtual void loadCodes(BaseSurface &depthSurface, int variant);
virtual void loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream);
virtual void loadCodes(BaseSurface &depthSurface, Common::SeekableReadStream *stream);
/**
* Constructor

View File

@ -174,7 +174,7 @@ Common::String PhantomScene::formAnimName(char sepChar, int suffixNum) {
/*------------------------------------------------------------------------*/
void SceneInfoPhantom::loadCodes(MSurface &depthSurface, int variant) {
void SceneInfoPhantom::loadCodes(BaseSurface &depthSurface, int variant) {
Common::String ext = Common::String::format(".WW%d", variant);
Common::String fileName = Resources::formatName(RESPREFIX_RM, _sceneId, ext);
if (!Common::File::exists(fileName))
@ -190,7 +190,7 @@ void SceneInfoPhantom::loadCodes(MSurface &depthSurface, int variant) {
f.close();
}
void SceneInfoPhantom::loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream) {
void SceneInfoPhantom::loadCodes(BaseSurface &depthSurface, Common::SeekableReadStream *stream) {
byte *destP = (byte *)depthSurface.getPixels();
byte *walkMap = new byte[stream->size()];
stream->read(walkMap, stream->size());

View File

@ -474,9 +474,9 @@ public:
class SceneInfoPhantom : public SceneInfo {
friend class SceneInfo;
protected:
virtual void loadCodes(MSurface &depthSurface, int variant);
virtual void loadCodes(BaseSurface &depthSurface, int variant);
virtual void loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream);
virtual void loadCodes(BaseSurface &depthSurface, Common::SeekableReadStream *stream);
/**
* Constructor

View File

@ -128,7 +128,7 @@ SceneInfo *SceneInfo::init(MADSEngine *vm) {
}
void SceneInfo::load(int sceneId, int variant, const Common::String &resName,
int flags, DepthSurface &depthSurface, MSurface &bgSurface) {
int flags, DepthSurface &depthSurface, BaseSurface &bgSurface) {
bool sceneFlag = sceneId >= 0;
// Figure out the resource to use
@ -299,7 +299,7 @@ void SceneInfo::load(int sceneId, int variant, const Common::String &resName,
}
}
void SceneInfo::loadPalette(int sceneId, int artFileNum, const Common::String &resName, int flags, MSurface &bgSurface) {
void SceneInfo::loadPalette(int sceneId, int artFileNum, const Common::String &resName, int flags, BaseSurface &bgSurface) {
bool sceneFlag = sceneId >= 0;
Common::String resourceName;
bool isV2 = (_vm->getGameID() != GType_RexNebular);
@ -351,7 +351,7 @@ void SceneInfo::loadPalette(int sceneId, int artFileNum, const Common::String &r
}
}
void SceneInfo::loadMadsV1Background(int sceneId, const Common::String &resName, int flags, MSurface &bgSurface) {
void SceneInfo::loadMadsV1Background(int sceneId, const Common::String &resName, int flags, BaseSurface &bgSurface) {
bool sceneFlag = sceneId >= 0;
Common::String resourceName;
Common::SeekableReadStream *stream;
@ -397,7 +397,7 @@ void SceneInfo::loadMadsV1Background(int sceneId, const Common::String &resName,
artFile.close();
}
void SceneInfo::loadMadsV2Background(int sceneId, const Common::String &resName, int flags, MSurface &bgSurface) {
void SceneInfo::loadMadsV2Background(int sceneId, const Common::String &resName, int flags, BaseSurface &bgSurface) {
Common::String tileMapResourceName = Resources::formatName(RESPREFIX_RM, sceneId, ".MM");
File tileMapFile(tileMapResourceName);
MadsPack tileMapPack(&tileMapFile);

View File

@ -189,36 +189,36 @@ public:
* loads the data
*/
void load(int sceneId, int variant, const Common::String &resName, int flags,
DepthSurface &depthSurface, MSurface &bgSurface);
DepthSurface &depthSurface, BaseSurface &bgSurface);
/**
* Loads the palette for a scene
*/
void loadPalette(int sceneId, int artFileNum, const Common::String &resName, int flags, MSurface &bgSurface);
void loadPalette(int sceneId, int artFileNum, const Common::String &resName, int flags, BaseSurface &bgSurface);
/**
* Loads a V1 game background
*/
void loadMadsV1Background(int sceneId, const Common::String &resName, int flags, MSurface &bgSurface);
void loadMadsV1Background(int sceneId, const Common::String &resName, int flags, BaseSurface &bgSurface);
/**
* Loads a V2 game background
*/
void loadMadsV2Background(int sceneId, const Common::String &resName, int flags, MSurface &bgSurface);
void loadMadsV2Background(int sceneId, const Common::String &resName, int flags, BaseSurface &bgSurface);
/**
* Loads the given surface with depth information of a given scene
* @param depthSurface Depth/walk surface
* @param variant Variant number to load
*/
virtual void loadCodes(MSurface &depthSurface, int variant) = 0;
virtual void loadCodes(BaseSurface &depthSurface, int variant) = 0;
/**
* Loads the given surface with depth information of a given scene
* @param depthSurface Depth/walk surface
* @param stream Stream to load the data from
*/
virtual void loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream) = 0;
virtual void loadCodes(BaseSurface &depthSurface, Common::SeekableReadStream *stream) = 0;
};
} // End of namespace MADS

View File

@ -201,7 +201,7 @@ void DirtyAreas::mergeAreas(int idx1, int idx2) {
da1._textActive = true;
}
void DirtyAreas::copy(MSurface *srcSurface, MSurface *destSurface, const Common::Point &posAdjust) {
void DirtyAreas::copy(BaseSurface *srcSurface, BaseSurface *destSurface, const Common::Point &posAdjust) {
for (uint i = 0; i < size(); ++i) {
const Common::Rect &srcBounds = (*this)[i]._bounds;
@ -555,7 +555,7 @@ void ScreenObjects::synchronize(Common::Serializer &s) {
/*------------------------------------------------------------------------*/
Screen::Screen(): Graphics::Screen(), MSurface() {
Screen::Screen(): BaseSurface() {
// Create the screen surface separately on another surface, since the screen
// surface will be subject to change as the clipping area is altered
_rawSurface.create(MADS_SCREEN_WIDTH, MADS_SCREEN_HEIGHT);

View File

@ -25,7 +25,6 @@
#include "common/scummsys.h"
#include "common/array.h"
#include "graphics/screen.h"
#include "mads/msurface.h"
#include "mads/action.h"
@ -118,7 +117,7 @@ public:
* @param destSurface Dest surface
* @param posAdjust Position adjustment
*/
void copy(MSurface *srcSurface, MSurface *destSurface, const Common::Point &posAdjust);
void copy(BaseSurface *srcSurface, BaseSurface *destSurface, const Common::Point &posAdjust);
/**
* Use the lsit of dirty areas to copy areas of the screen surface to
@ -129,7 +128,6 @@ public:
void reset();
};
class ScreenObject {
public:
bool _active;
@ -208,7 +206,7 @@ public:
void synchronize(Common::Serializer &s);
};
class Screen : virtual public Graphics::Screen, virtual public MSurface {
class Screen : public BaseSurface {
private:
uint16 _random;
MSurface _rawSurface;

View File

@ -337,7 +337,7 @@ void SpriteSlots::drawSprites(MSurface *s) {
s->copyFrom(*sprite, Common::Point(xp, yp), slot._depth, &scene._depthSurface,
-1, flipped, sprite->getTransparencyIndex());
} else {
MSurface *spr = sprite;
BaseSurface *spr = sprite;
if (flipped) {
// Create a flipped copy of the sprite temporarily
spr = sprite->flipHorizontal();

View File

@ -161,7 +161,7 @@ void UISlots::draw(bool updateFlag, bool delFlag) {
MSprite *sprite = asset->getFrame(frameNumber - 1);
if (flipped) {
MSurface *spr = sprite->flipHorizontal();
BaseSurface *spr = sprite->flipHorizontal();
userInterface.mergeFrom(spr, spr->getBounds(), slot._position,
sprite->getTransparencyIndex());
spr->free();
@ -429,7 +429,7 @@ void UserInterface::drawTextElements() {
}
}
void UserInterface::mergeFrom(MSurface *src, const Common::Rect &srcBounds,
void UserInterface::mergeFrom(BaseSurface *src, const Common::Rect &srcBounds,
const Common::Point &destPos, int transparencyIndex) {
// Validation of the rectangle and position
int destX = destPos.x, destY = destPos.y;

View File

@ -238,7 +238,7 @@ public:
* @param destPos Destination position to draw in current surface
* @param transparencyIndex Transparency color
*/
void mergeFrom(MSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos,
void mergeFrom(BaseSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos,
int transparencyIndex = -1);
/**