aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2014-02-19 20:22:06 -0500
committerPaul Gilbert2014-02-19 20:22:06 -0500
commit5c565797e5516de97686650be8cc810007111641 (patch)
tree48e74b68d9bb00caf0b7409f6d6c893326e1010b
parent97087e8cd1aee602217c36f1c71d4ca3f74e0e40 (diff)
downloadscummvm-rg350-5c565797e5516de97686650be8cc810007111641.tar.gz
scummvm-rg350-5c565797e5516de97686650be8cc810007111641.tar.bz2
scummvm-rg350-5c565797e5516de97686650be8cc810007111641.zip
MADS: Extra cleanup and commenting for MSurface methods
-rw-r--r--engines/mads/font.cpp11
-rw-r--r--engines/mads/msurface.cpp126
-rw-r--r--engines/mads/msurface.h186
3 files changed, 213 insertions, 110 deletions
diff --git a/engines/mads/font.cpp b/engines/mads/font.cpp
index b7400ed337..9da46c30b1 100644
--- a/engines/mads/font.cpp
+++ b/engines/mads/font.cpp
@@ -79,9 +79,9 @@ int Font::write(MSurface *surface, const Common::String &msg, const Common::Poin
*/
if (width > 0)
- width = MIN(surface->width(), pt.x + width);
+ width = MIN(surface->getWidth(), pt.x + width);
else
- width = surface->width();
+ width = surface->getWidth();
int x = pt.x + 1;
int y = pt.y + 1;
@@ -97,8 +97,8 @@ int Font::write(MSurface *surface, const Common::String &msg, const Common::Poin
return x;
int bottom = y + height - 1;
- if (bottom > surface->height() - 1) {
- height -= MIN(height, bottom - (surface->height() - 1));
+ if (bottom > surface->getHeight() - 1) {
+ height -= MIN(height, bottom - (surface->getHeight() - 1));
}
if (height <= 0)
@@ -142,7 +142,7 @@ int Font::write(MSurface *surface, const Common::String &msg, const Common::Poin
charData++;
}
- destPtr += surface->width() - bpp * 4;
+ destPtr += surface->getWidth() - bpp * 4;
}
@@ -155,7 +155,6 @@ int Font::write(MSurface *surface, const Common::String &msg, const Common::Poin
}
- surface->freeData();
return xPos;
}
diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp
index eca3f76ad9..b3a4510793 100644
--- a/engines/mads/msurface.cpp
+++ b/engines/mads/msurface.cpp
@@ -41,23 +41,23 @@ MSurface *MSurface::init(bool isScreen) {
}
}
-MSurface *MSurface::init(int w, int h) {
+MSurface *MSurface::init(int width, int height) {
if (_vm->getGameID() == GType_RexNebular) {
- return new MSurfaceNebular(w, h);
+ return new MSurfaceNebular(width, height);
} else if (_vm->getGameFeatures() & GF_MADS) {
- return new MSurfaceMADS(w, h);
+ return new MSurfaceMADS(width, height);
} else {
- return new MSurfaceM4(w, h);
+ return new MSurfaceM4(width, height);
}
}
MSurface::MSurface(bool isScreen) {
- create(g_system->getWidth(), g_system->getHeight());
+ setSize(g_system->getWidth(), g_system->getHeight());
_isScreen = isScreen;
}
-MSurface::MSurface(int Width, int Height) {
- create(Width, Height);
+MSurface::MSurface(int width, int height) {
+ setSize(width, height);
_isScreen = false;
}
@@ -137,7 +137,7 @@ int MSurface::scaleValue(int value, int scale, int err) {
return scaled;
}
-void MSurface::drawSprite(int x, int y, SpriteInfo &info, const Common::Rect &clipRect) {
+void MSurface::drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect) {
enum {
kStatusSkip,
@@ -155,11 +155,7 @@ void MSurface::drawSprite(int x, int y, SpriteInfo &info, const Common::Rect &cl
int scaledWidth = scaleValue(info.width, info.scaleX, errX);
int scaledHeight = scaleValue(info.height, info.scaleY, errY);
- /*
- printf("MSurface::drawSprite() info.width = %d; info.scaleX = %d; info.height = %d; info.scaleY = %d; scaledWidth = %d; scaledHeight = %d\n",
- info.width, info.scaleX, info.height, info.scaleY, scaledWidth, scaledHeight); fflush(stdout);
- */
-
+ int x = pt.x, y = pt.y;
int clipX = 0, clipY = 0;
// Clip the sprite's width and height according to the clip rectangle's dimensions
// This clips the sprite to the bottom and right
@@ -176,8 +172,6 @@ void MSurface::drawSprite(int x, int y, SpriteInfo &info, const Common::Rect &cl
scaledHeight = y + scaledHeight;
}
- //printf("MSurface::drawSprite() width = %d; height = %d; scaledWidth = %d; scaledHeight = %d\n", info.width, info.height, scaledWidth, scaledHeight); fflush(stdout);
-
// Check if sprite is inside the screen. If it's not, there's no need to draw it
if (scaledWidth + x <= 0 || scaledHeight + y <= 0) // check left and top (in case x,y are negative)
return;
@@ -206,16 +200,16 @@ void MSurface::drawSprite(int x, int y, SpriteInfo &info, const Common::Rect &cl
// Scale current line
byte *lineDst = scaledLineBuf;
int curErrX = errX;
- int widthVal = scaledWidth;
+ int width = scaledWidth;
byte *tempSrc = src;
int startX = clipX;
- while (widthVal > 0) {
+ while (width > 0) {
byte pixel = *tempSrc++;
curErrX -= info.scaleX;
while (curErrX < 0) {
if (startX == 0) {
*lineDst++ = pixel;
- widthVal--;
+ width--;
} else {
startX++;
}
@@ -276,19 +270,6 @@ void MSurface::drawSprite(int x, int y, SpriteInfo &info, const Common::Rect &cl
}
-// Surface methods
-
-byte *MSurface::getData() {
- return (byte *)Graphics::Surface::getPixels();
-}
-
-byte *MSurface::getBasePtr(int x, int y) {
- return (byte *)Graphics::Surface::getBasePtr(x, y);
-}
-
-void MSurface::freeData() {
-}
-
void MSurface::empty() {
Common::fill(getBasePtr(0, 0), getBasePtr(w, h), _vm->_palette->BLACK);
}
@@ -301,9 +282,10 @@ void MSurface::fillRect(const Common::Rect &r, uint8 color) {
Graphics::Surface::fillRect(r, color);
}
-void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds, int destX, int destY,
- int transparentColor) {
- // Validation of the rectangle and position
+void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds,
+ const Common::Point &destPos, int transparentColor) {
+ // Validation of the rectangle and position
+ int destX = destPos.x, destY = destPos.y;
if ((destX >= w) || (destY >= h))
return;
@@ -327,8 +309,8 @@ void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds, int destX,
// Copy the specified area
byte *data = src->getData();
- byte *srcPtr = data + (src->width() * copyRect.top + copyRect.left);
- byte *destPtr = (byte *)pixels + (destY * width()) + destX;
+ byte *srcPtr = data + (src->getWidth() * copyRect.top + copyRect.left);
+ byte *destPtr = (byte *)pixels + (destY * getWidth()) + destX;
for (int rowCtr = 0; rowCtr < copyRect.height(); ++rowCtr) {
if (transparentColor == -1)
@@ -340,27 +322,21 @@ void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds, int destX,
if (srcPtr[xCtr] != transparentColor) destPtr[xCtr] = srcPtr[xCtr];
}
- srcPtr += src->width();
- destPtr += width();
+ srcPtr += src->getWidth();
+ destPtr += getWidth();
}
-
- src->freeData();
}
-#undef COL_TRANS
-
void MSurface::translate(RGBList *list, bool isTransparent) {
byte *p = getBasePtr(0, 0);
byte *palIndexes = list->palIndexes();
- for (int i = 0; i < width() * height(); ++i, ++p) {
+ for (int i = 0; i < getWidth() * getHeight(); ++i, ++p) {
if (!isTransparent || (*p != 0)) {
assert(*p < list->size());
*p = palIndexes[*p];
}
}
-
- freeData();
}
/*------------------------------------------------------------------------*/
@@ -371,18 +347,18 @@ void MSurfaceMADS::loadCodes(Common::SeekableReadStream *source) {
return;
}
- uint16 widthVal = MADS_SCREEN_WIDTH;
- uint16 heightVal = MADS_SCREEN_HEIGHT - MADS_INTERFACE_HEIGHT;
+ uint16 width = MADS_SCREEN_WIDTH;
+ uint16 height = MADS_SCREEN_HEIGHT - MADS_INTERFACE_HEIGHT;
byte *walkMap = new byte[source->size()];
- create(widthVal, heightVal);
+ setSize(width, height);
source->read(walkMap, source->size());
byte *ptr = (byte *)getBasePtr(0, 0);
- for (int y = 0; y < heightVal; y++) {
- for (int x = 0; x < widthVal; x++) {
- int ofs = x + (y * widthVal);
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int ofs = x + (y * width);
if ((walkMap[ofs / 8] << (ofs % 8)) & 0x80)
*ptr++ = 1; // walkable
else
@@ -444,8 +420,8 @@ void MSurfaceMADS::loadBackground(int roomNumber, RGBList **palData) {
assert(tileCountMap == tileCount);
assert(tileWidth == tileWidthMap);
assert(tileHeight == tileHeightMap);
- assert(screenWidth == _vm->_screen->width());
- assert(screenHeight <= _vm->_screen->height());
+ assert(screenWidth == _vm->_screen->getWidth());
+ assert(screenHeight <= _vm->_screen->getHeight());
// --------------------------------------------------------------------------------
@@ -508,7 +484,7 @@ void MSurfaceMADS::loadBackground(int roomNumber, RGBList **palData) {
TileSetIterator tile = tileSet.begin();
for (i = 0; i < tileIndex; i++)
++tile;
- ((*tile).get())->copyTo(this, x * tileWidth, y * tileHeight);
+ ((*tile).get())->copyTo(this, Common::Point(x * tileWidth, y * tileHeight));
}
}
tileSet.clear();
@@ -537,7 +513,7 @@ void MSurfaceMADS::loadInterface(int index, RGBList **palData) {
// Chunk 1, data
intStream = intFile.getItemStream(1);
- create(MADS_SCREEN_WIDTH, MADS_INTERFACE_HEIGHT);
+ setSize(MADS_SCREEN_WIDTH, MADS_INTERFACE_HEIGHT);
intStream->read(pixels, MADS_SCREEN_WIDTH * MADS_INTERFACE_HEIGHT);
delete intStream;
}
@@ -562,14 +538,14 @@ void MSurfaceNebular::loadBackgroundStream(Common::SeekableReadStream *source, R
int sceneWidth = sourceUnc->readUint16LE();
int sceneHeight = sourceUnc->readUint16LE();
int sceneSize = sceneWidth * sceneHeight;
- if (sceneWidth > this->width()) {
- warning("Background width is %i, too large to fit in screen. Setting it to %i", sceneWidth, this->width());
- sceneWidth = this->width();
+ if (sceneWidth > this->getWidth()) {
+ warning("Background width is %i, too large to fit in screen. Setting it to %i", sceneWidth, getWidth());
+ sceneWidth = this->getWidth();
sceneSize = sceneWidth * sceneHeight;
}
- if (sceneHeight > this->height()) {
- warning("Background height is %i, too large to fit in screen.Setting it to %i", sceneHeight, this->height());
- sceneHeight = this->height();
+ if (sceneHeight > getHeight()) {
+ warning("Background height is %i, too large to fit in screen.Setting it to %i", sceneHeight, getHeight());
+ sceneHeight = getHeight();
sceneSize = sceneWidth * sceneHeight;
}
@@ -590,7 +566,6 @@ void MSurfaceNebular::loadBackgroundStream(Common::SeekableReadStream *source, R
byte *pData = (byte *)pixels;
sourceUnc->read(pData, sceneSize);
- freeData();
delete sourceUnc;
}
@@ -602,11 +577,11 @@ void MSurfaceM4::loadCodes(Common::SeekableReadStream *source) {
return;
}
- uint16 widthVal = source->readUint16LE();
- uint16 heightVal = source->readUint16LE();
+ uint16 width = source->readUint16LE();
+ uint16 height = source->readUint16LE();
- create(widthVal, heightVal);
- source->read(pixels, widthVal * heightVal);
+ setSize(width, height);
+ source->read(pixels, width * height);
}
void MSurfaceM4::loadBackground(int roomNumber, RGBList **palData) {
@@ -627,8 +602,8 @@ void MSurfaceM4::loadBackgroundStream(Common::SeekableReadStream *source) {
source->skip(4);
/*uint32 size =*/ source->readUint32LE();
- uint32 widthVal = source->readUint32LE();
- uint32 heightVal = source->readUint32LE();
+ uint32 width = source->readUint32LE();
+ uint32 height = source->readUint32LE();
uint32 tilesX = source->readUint32LE();
uint32 tilesY = source->readUint32LE();
uint32 tileWidth = source->readUint32LE();
@@ -651,25 +626,26 @@ void MSurfaceM4::loadBackgroundStream(Common::SeekableReadStream *source) {
// resize or create the surface
// Note that the height of the scene in game scenes is smaller than the screen height,
// as the bottom part of the screen is the inventory
- assert(width() == (int)widthVal);
+ assert(getWidth() == (int)width);
- tileBuffer->create(tileWidth, tileHeight);
+ tileBuffer->setSize(tileWidth, tileHeight);
for (curTileY = 0; curTileY < tilesY; curTileY++) {
- clipY = MIN(heightVal, (1 + curTileY) * tileHeight) - (curTileY * tileHeight);
+ clipY = MIN(height, (1 + curTileY) * tileHeight) - (curTileY * tileHeight);
for (curTileX = 0; curTileX < tilesX; curTileX++) {
- clipX = MIN(widthVal, (1 + curTileX) * tileWidth) - (curTileX * tileWidth);
+ clipX = MIN(width, (1 + curTileX) * tileWidth) - (curTileX * tileWidth);
// Read a tile and copy it to the destination surface
source->read(tileBuffer->getData(), tileWidth * tileHeight);
Common::Rect srcBounds(0, 0, clipX, clipY);
- copyFrom(tileBuffer, srcBounds, curTileX * tileWidth, curTileY * tileHeight);
+ copyFrom(tileBuffer, srcBounds,
+ Common::Point(curTileX * tileWidth, curTileY * tileHeight));
}
}
- if (heightVal < (uint)height())
- fillRect(Common::Rect(0, heightVal, width(), height()), blackIndex);
+ if (height < (uint)getHeight())
+ fillRect(Common::Rect(0, height, getWidth(), getHeight()), blackIndex);
delete tileBuffer;
}
diff --git a/engines/mads/msurface.h b/engines/mads/msurface.h
index 21b0cbcd2f..05777d3b8f 100644
--- a/engines/mads/msurface.h
+++ b/engines/mads/msurface.h
@@ -33,6 +33,9 @@ namespace MADS {
class MADSEngine;
class MSprite;
+/**
+ * Basic sprite information
+ */
struct SpriteInfo {
MSprite *sprite;
int hotX, hotY;
@@ -43,6 +46,9 @@ struct SpriteInfo {
RGB8 *palette;
};
+/*
+ * MADS graphics surface
+ */
class MSurface : public Graphics::Surface {
public:
static MADSEngine *_vm;
@@ -61,46 +67,126 @@ public:
/**
* Create a surface
*/
- static MSurface *init(int w, int h);
+ static MSurface *init(int width, int height);
private:
byte _color;
bool _isScreen;
protected:
+ /**
+ * Basic constructor
+ */
MSurface(bool isScreen = false);
- MSurface(int w, int h);
+
+ /**
+ * Constructor for a surface with fixed dimensions
+ */
+ MSurface(int width, int height);
+public:
+ /**
+ * Helper method for calculating new dimensions when scaling a sprite
+ */
+ static int scaleValue(int value, int scale, int err);
public:
virtual ~MSurface() {}
- void create(int w, int h) {
- Graphics::Surface::create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+ /**
+ * Reinitialises a surface to have a given set of dimensions
+ */
+ void setSize(int width, int height) {
+ Graphics::Surface::create(width, height, Graphics::PixelFormat::createFormatCLUT8());
}
+ /**
+ * Sets the color used for drawing on the surface
+ */
void setColor(byte value) { _color = value; }
- byte getColor() { return _color; }
+
+ /**
+ * Returns the currently active color
+ */
+ byte getColor() const { return _color; }
+
+ /**
+ * Draws a vertical line using the currently set color
+ */
void vLine(int x, int y1, int y2);
+
+ /**
+ * Draws a horizontal line using the currently set color
+ */
void hLine(int x1, int x2, int y);
+
+ /**
+ * Draws a vertical line using an Xor on each pixel
+ */
void vLineXor(int x, int y1, int y2);
+
+ /**
+ * Draws a horizontal line using an Xor on each pixel
+ */
void hLineXor(int x1, int x2, int y);
+
+ /**
+ * Draws an arbitrary line on the screen using a specified color
+ */
void line(int x1, int y1, int x2, int y2, byte color);
+
+ /**
+ * Draws a rectangular frame using the currently set color
+ */
void frameRect(int x1, int y1, int x2, int y2);
- void fillRect(int x1, int y1, int x2, int y2);
- static int scaleValue(int value, int scale, int err);
- void drawSprite(int x, int y, SpriteInfo &info, const Common::Rect &clipRect);
-
- // Surface methods
- int width() { return w; }
- int height() { return h; }
- void setSize(int sizeX, int sizeY);
- byte *getData();
- byte *getBasePtr(int x, int y);
- void freeData();
- void empty();
+ /**
+ * Draws a rectangular frame using a specified color
+ */
void frameRect(const Common::Rect &r, uint8 color);
+
+ /**
+ * Draws a filled in box using the currently set color
+ */
+ void fillRect(int x1, int y1, int x2, int y2);
+
+ /**
+ * Draws a filled in box using a specified color
+ */
void fillRect(const Common::Rect &r, uint8 color);
- void copyFrom(MSurface *src, const Common::Rect &srcBounds, int destX, int destY,
- int transparentColor = -1);
+ /**
+ * Draws a sprite
+ * @param pt Position to draw sprite at
+ * @param info General sprite details
+ * @param clipRect Clipping rectangle to constrain sprite drawing within
+ */
+ void drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect);
+
+ /**
+ * Returns the width of the surface
+ */
+ int getWidth() const { return w; }
+
+ /**
+ * Returns the height of the surface
+ */
+ int getHeight() const { return h; }
+
+ /**
+ * Returns a pointer to the surface data
+ */
+ byte *getData() { return (byte *)Graphics::Surface::getPixels(); }
+
+ /**
+ * Returns a pointer to a given position within the surface
+ */
+ byte *getBasePtr(int x, int y) { return (byte *)Graphics::Surface::getBasePtr(x, y); }
+
+ /**
+ * Clears the surface
+ */
+ void empty();
+
+ /**
+ * Updates the surface. If it's the screen surface, copies it to the physical screen.
+ */
void update() {
if (_isScreen) {
g_system->copyRectToScreen((const byte *)pixels, pitch, 0, 0, w, h);
@@ -108,25 +194,67 @@ public:
}
}
- // copyTo methods
+ /**
+ * Copys a sub-section of another surface into the current one.
+ * @param src Source surface
+ * @param srcBounds Area of source surface to copy
+ * @param destPos Destination position to draw in current surface
+ * @param transparentColor Transparency palette index
+ */
+ void copyFrom(MSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos,
+ int transparentColor = -1);
+
+ /**
+ * Copies the surface to a given destination surface
+ */
void copyTo(MSurface *dest, int transparentColor = -1) {
- dest->copyFrom(this, Common::Rect(width(), height()), 0, 0, transparentColor);
+ dest->copyFrom(this, Common::Rect(w, h), Common::Point(), transparentColor);
}
- void copyTo(MSurface *dest, int x, int y, int transparentColor = -1) {
- dest->copyFrom(this, Common::Rect(width(), height()), x, y, transparentColor);
+
+ /**
+ * Copies the surface to a given destination surface
+ */
+ void copyTo(MSurface *dest, const Common::Point &pt, int transparentColor = -1) {
+ dest->copyFrom(this, Common::Rect(w, h), pt, transparentColor);
}
- void copyTo(MSurface *dest, const Common::Rect &srcBounds, int destX, int destY,
+
+ /**
+ * Copies the surface to a given destination surface
+ */
+ void copyTo(MSurface *dest, const Common::Rect &srcBounds, const Common::Point &destPos,
int transparentColor = -1) {
- dest->copyFrom(this, srcBounds, destX, destY, transparentColor);
+ dest->copyFrom(this, srcBounds, destPos, transparentColor);
}
+ /**
+ * Translates the data of a surface using a specified RGBList translation matrix.
+ */
void translate(RGBList *list, bool isTransparent = false);
// Base virtual methods
+ /**
+ * Loads a background by scene name
+ */
virtual void loadBackground(const Common::String &sceneName) {}
+
+ /**
+ * Load background by room number
+ */
virtual void loadBackground(int roomNumber, RGBList **palData) = 0;
+
+ /**
+ * Load background from a passed stream
+ */
virtual void loadBackground(Common::SeekableReadStream *source, RGBList **palData) {}
+
+ /**
+ * Load scene codes from a passed stream
+ */
virtual void loadCodes(Common::SeekableReadStream *source) = 0;
+
+ /**
+ * Load a given user interface by index
+ */
virtual void loadInterface(int index, RGBList **palData) {}
};
@@ -134,7 +262,7 @@ class MSurfaceMADS: public MSurface {
friend class MSurface;
protected:
MSurfaceMADS(bool isScreen = false): MSurface(isScreen) {}
- MSurfaceMADS(int w, int h): MSurface(w, h) {}
+ MSurfaceMADS(int width, int height): MSurface(width, height) {}
public:
virtual void loadCodes(Common::SeekableReadStream *source);
virtual void loadBackground(const Common::String &sceneName) {}
@@ -146,7 +274,7 @@ class MSurfaceNebular: public MSurfaceMADS {
friend class MSurface;
protected:
MSurfaceNebular(bool isScreen = false): MSurfaceMADS(isScreen) {}
- MSurfaceNebular(int w, int h): MSurfaceMADS(w, h) {}
+ MSurfaceNebular(int width, int height): MSurfaceMADS(width, height) {}
private:
void loadBackgroundStream(Common::SeekableReadStream *source, RGBList **palData);
public:
@@ -157,7 +285,7 @@ class MSurfaceM4: public MSurface {
friend class MSurface;
protected:
MSurfaceM4(bool isScreen = false): MSurface(isScreen) {}
- MSurfaceM4(int widthVal, int heightVal): MSurface(widthVal, heightVal) {}
+ MSurfaceM4(int width, int height): MSurface(width, height) {}
void loadBackgroundStream(Common::SeekableReadStream *source);
public:
@@ -169,7 +297,7 @@ class MSurfaceRiddle: public MSurfaceM4 {
friend class MSurface;
protected:
MSurfaceRiddle(bool isScreen = false): MSurfaceM4(isScreen) {}
- MSurfaceRiddle(int widthVal, int heightVal): MSurfaceM4(widthVal, heightVal) {}
+ MSurfaceRiddle(int width, int height): MSurfaceM4(width, height) {}
public:
virtual void loadBackground(const Common::String &sceneName);
};