Skip to content

Commit

Permalink
MADS: Merge copyFromScaled into the existing copyFrom method
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 31, 2014
1 parent 13cc433 commit 7d24e14
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 71 deletions.
88 changes: 34 additions & 54 deletions engines/mads/msurface.cpp
Expand Up @@ -259,24 +259,52 @@ void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds,

void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
DepthSurface *depthSurface, int scale, int transparentColor) {

int destX = destPos.x, destY = destPos.y;
if (scale == 100) {
int frameWidth = src->getWidth();
int frameHeight = src->getHeight();

int highestDim = MAX(frameWidth, frameHeight);
bool lineDist[MADS_SCREEN_WIDTH];
int distIndex = 0;
int distXCount = 0, distYCount = 0;

if (scale != -1) {
int distCtr = 0;
do {
distCtr += scale;
if (distCtr < 100) {
lineDist[distIndex] = false;
} else {
lineDist[distIndex] = true;
distCtr -= 100;

if (distIndex < frameWidth)
++distXCount;

if (distIndex < frameHeight)
++distYCount;
}
} while (++distIndex < highestDim);

destX -= distXCount / 2;
destY -= distYCount - 1;
}

// Special case for quicker drawing of non-scaled images
if (scale == 100 || scale == -1) {
// Copy the specified area
Common::Rect copyRect(0, 0, src->getWidth(), src->getHeight());

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;
}

Expand Down Expand Up @@ -310,33 +338,6 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
int destRight = this->getWidth() - 1;
int destBottom = this->getHeight() - 1;
bool normalFrame = true;
int frameWidth = src->getWidth();
int frameHeight = src->getHeight();

int highestDim = MAX(frameWidth, frameHeight);
bool lineDist[MADS_SCREEN_WIDTH];
int distIndex = 0;
int distXCount = 0, distYCount = 0;

int distCtr = 0;
do {
distCtr += scale;
if (distCtr < 100) {
lineDist[distIndex] = false;
} else {
lineDist[distIndex] = true;
distCtr -= 100;

if (distIndex < frameWidth)
++distXCount;

if (distIndex < frameHeight)
++distYCount;
}
} while (++distIndex < highestDim);

destX -= distXCount / 2;
destY -= distYCount - 1;

// Check x bounding area
int spriteLeft = 0;
Expand Down Expand Up @@ -419,27 +420,6 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
}
}

void MSurface::copyFromScaled(MSurface *src, const Common::Point &destPos, int depth,
DepthSurface *depthSurface, int scale, int transparentColor) {
int distXCount = 0, distYCount = 0;
int highestDim = MAX(src->w, src->h);
int accum = 0;

for (int idx = 0; idx < highestDim; ++idx) {
accum += scale;
if (accum >= 100) {
accum -= 100;
if (idx < src->w)
++distXCount;
if (idx < src->h)
++distYCount;
}
}

Common::Point newPos(destPos.x - distXCount / 2, destPos.y - distYCount);
copyFrom(src, src->getBounds(), newPos, transparentColor);
}

void MSurface::scrollX(int xAmount) {
if (xAmount == 0)
return;
Expand Down
14 changes: 0 additions & 14 deletions engines/mads/msurface.h
Expand Up @@ -167,20 +167,6 @@ class MSurface : public Graphics::Surface {
void copyFrom(MSurface *src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
int scale, int transparentColor = -1);

/**
* Copys a sub-section of another surface into the current one, taking into
* account variation in the destination copy position based on item size
* and scaling.
* @param src Source surface
* @param destPos Destination position to draw in current surface
* @param depth Depth of sprite
* @param depthSurface Depth surface to use with sprite depth
* @param scale Scale for image
* @param transparentColor Transparency palette index
*/
void copyFromScaled(MSurface *src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
int scale, int transparentColor = -1);

/**
* Copies the surface to a given destination surface
*/
Expand Down
2 changes: 1 addition & 1 deletion engines/mads/scene_data.cpp
Expand Up @@ -265,7 +265,7 @@ void SceneInfo::load(int sceneId, int variant, const Common::String &resName,
assert(asset && _depthStyle != 2);

MSprite *spr = asset->getFrame(asset->getCount() - 1);
bgSurface.copyFromScaled(spr, si._position, si._depth, &depthSurface,
bgSurface.copyFrom(spr, si._position, si._depth, &depthSurface,
si._scale, spr->getTransparencyIndex());
}

Expand Down
4 changes: 2 additions & 2 deletions engines/mads/sprites.cpp
Expand Up @@ -324,7 +324,7 @@ void SpriteSlots::drawSprites(MSurface *s) {
}

if ((slot._scale < 100) && (slot._scale != -1)) {
// Minimalized drawing
// Scaled drawing
s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface,
slot._scale, sprite->getTransparencyIndex());
} else {
Expand All @@ -341,7 +341,7 @@ void SpriteSlots::drawSprites(MSurface *s) {
if (slot._depth > 1) {
// Draw the frame with depth processing
s->copyFrom(spr, Common::Point(xp, yp), slot._depth, &scene._depthSurface,
100, sprite->getTransparencyIndex());
-1, sprite->getTransparencyIndex());
} else {
// No depth, so simply draw the image
spr->copyTo(s, Common::Point(xp, yp), sprite->getTransparencyIndex());
Expand Down

0 comments on commit 7d24e14

Please sign in to comment.