aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/star_control/surface_area.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2017-05-30 21:38:28 -0400
committerPaul Gilbert2017-05-30 21:38:28 -0400
commitf698d04008c5342f98d58607d6c3259d42965a5f (patch)
treeaf0f54cdbea1fe64c1c45b7689ddbea56089e874 /engines/titanic/star_control/surface_area.cpp
parentd56124e6246eb2224b97802ca9960de2764e5944 (diff)
downloadscummvm-rg350-f698d04008c5342f98d58607d6c3259d42965a5f.tar.gz
scummvm-rg350-f698d04008c5342f98d58607d6c3259d42965a5f.tar.bz2
scummvm-rg350-f698d04008c5342f98d58607d6c3259d42965a5f.zip
TITANIC: Fix line drawing of starfield markers
Diffstat (limited to 'engines/titanic/star_control/surface_area.cpp')
-rw-r--r--engines/titanic/star_control/surface_area.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/engines/titanic/star_control/surface_area.cpp b/engines/titanic/star_control/surface_area.cpp
index be45f6bf75..647413c8fa 100644
--- a/engines/titanic/star_control/surface_area.cpp
+++ b/engines/titanic/star_control/surface_area.cpp
@@ -111,40 +111,39 @@ void CSurfaceArea::pixelToRGB(uint pixel, uint *rgb) {
}
}
-double CSurfaceArea::drawLine(const FRect &rect) {
- if (rect.empty())
- return rect.top;
-
- double xp = rect.left, yp = rect.top;
- FRect r = rect;
-
- // edx=flags1, esi=flags2
- int flags1 = (r.left < _bounds.left ? 1 : 0)
- | (r.left > _bounds.right ? 2 : 0)
- | (r.top < _bounds.top ? 4 : 0)
- | (r.top > _bounds.bottom ? 8 : 0);
- int flags2 = (r.right < _bounds.left ? 1 : 0)
- | (r.right > _bounds.right ? 2 : 0)
- | (r.bottom < _bounds.top ? 4 : 0)
- | (r.bottom > _bounds.bottom ? 8 : 0);
+double CSurfaceArea::drawLine(const FPoint &pt1, const FPoint &pt2) {
+ if (pt1 == pt2)
+ return pt1._y;
+
+ FPoint p1 = pt1, p2 = pt2;
+ double xp = pt1._x, yp = pt1._y;
+
+ int flags1 = (p1._x < _bounds.left ? 1 : 0)
+ | (p1._x > _bounds.right ? 2 : 0)
+ | (p1._y < _bounds.top ? 4 : 0)
+ | (p1._y > _bounds.bottom ? 8 : 0);
+ int flags2 = (p2._x < _bounds.left ? 1 : 0)
+ | (p2._x > _bounds.right ? 2 : 0)
+ | (p2._y < _bounds.top ? 4 : 0)
+ | (p2._y > _bounds.bottom ? 8 : 0);
// Handle any clipping
while (flags1 | flags2) {
if (flags1 & flags2)
- return r.top;
+ return p1._y;
int flags = flags1 ? flags1 : flags2;
if ((flags & 1) || (flags & 2)) {
xp = (flags & 1) ? _bounds.left : _bounds.right;
- yp = (r.bottom - r.top) * (xp - r.left) / (r.right - r.left) + r.top;
+ yp = (p2._y - p1._y) * (xp - p1._x) / (p2._x - p1._x) + p1._y;
} else if ((flags & 4) || (flags & 8)) {
yp = (flags & 4) ? _bounds.top : _bounds.bottom;
- xp = (r.right - r.left) * (yp - r.top) / (r.bottom - r.top) + r.left;
+ xp = (p2._x - p1._x) * (yp - p1._y) / (p2._y - p1._y) + p1._x;
}
if (flags == flags1) {
- r.left = xp;
- r.top = yp;
+ p1._x = xp;
+ p1._y = yp;
flags1 = 0;
if (xp < _bounds.left)
@@ -156,8 +155,8 @@ double CSurfaceArea::drawLine(const FRect &rect) {
if (yp > _bounds.bottom)
flags1 |= 8;
} else {
- r.right = xp;
- r.bottom = yp;
+ p2._x = xp;
+ p2._y = yp;
flags2 = 0;
if (xp < _bounds.left)
@@ -171,9 +170,9 @@ double CSurfaceArea::drawLine(const FRect &rect) {
}
}
- Common::Rect rr((int)(MIN(r.left, r.right) - 0.5), (int)(MIN(r.top, r.bottom) - 0.5),
- (int)(MAX(r.left, r.right) - 0.5), (int)(MAX(r.top, r.bottom) - 0.5));
-
+ Common::Point srcPos((int)(p1._x - 0.5), (int)(p1._y - 0.5));
+ Common::Point destPos((int)(p2._x - 0.5), (int)(p2._y - 0.5));
+
Graphics::Surface s;
s.setPixels(_pixelsPtr);
s.pitch = _pitch;
@@ -185,31 +184,31 @@ double CSurfaceArea::drawLine(const FRect &rect) {
case 0:
s.format = Graphics::PixelFormat::createFormatCLUT8();
if (_mode != SA_SOLID) {
- Graphics::drawLine(rr.left, rr.top, rr.right, rr.bottom, 0, plotPoint<byte>, this);
- return r.top;
+ Graphics::drawLine(srcPos.x, srcPos.y, destPos.x, destPos.y, 0, plotPoint<byte>, this);
+ return p1._y;
}
break;
case 1:
case 2:
s.format = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);
if (_mode != SA_SOLID) {
- Graphics::drawLine(rr.left, rr.top, rr.right, rr.bottom, 0, plotPoint<uint16>, this);
- return r.top;
+ Graphics::drawLine(srcPos.x, srcPos.y, destPos.x, destPos.y, 0, plotPoint<uint16>, this);
+ return p1._y;
}
break;
case 4:
s.format = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
if (_mode != SA_SOLID) {
- Graphics::drawLine(rr.left, rr.top, rr.right, rr.bottom, 0, plotPoint<uint32>, this);
- return r.top;
+ Graphics::drawLine(srcPos.x, srcPos.y, destPos.x, destPos.y, 0, plotPoint<uint32>, this);
+ return p1._y;
}
break;
default:
error("Unknown bpp");
}
- s.drawLine(rr.left, rr.top, rr.right, rr.bottom, _rgb);
- return r.top;
+ s.drawLine(srcPos.x, srcPos.y, destPos.x, destPos.y, _rgb);
+ return p1._y;
}
} // End of namespace Titanic