[Scummvm-git-logs] scummvm master -> f698d04008c5342f98d58607d6c3259d42965a5f

dreammaster dreammaster at scummvm.org
Wed May 31 03:38:39 CEST 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f698d04008 TITANIC: Fix line drawing of starfield markers


Commit: f698d04008c5342f98d58607d6c3259d42965a5f
    https://github.com/scummvm/scummvm/commit/f698d04008c5342f98d58607d6c3259d42965a5f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-05-30T21:38:28-04:00

Commit Message:
TITANIC: Fix line drawing of starfield markers

Changed paths:
    engines/titanic/star_control/star_markers.cpp
    engines/titanic/star_control/surface_area.cpp
    engines/titanic/star_control/surface_area.h


diff --git a/engines/titanic/star_control/star_markers.cpp b/engines/titanic/star_control/star_markers.cpp
index 5dea6bc..ce8f053 100644
--- a/engines/titanic/star_control/star_markers.cpp
+++ b/engines/titanic/star_control/star_markers.cpp
@@ -54,10 +54,10 @@ void CStarMarkers::draw(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarClo
 
 			xc = center._x + vTemp._x;
 			yc = center._y + vTemp._y;
-			yb = yc + 4.0;
 			xl = xc - 4.0;
-			xr = xc + 4.0;
 			yt = yc - 4.0;
+			xr = xc + 4.0;
+			yb = yc + 4.0;
 			surfaceArea->drawLine(FPoint(xl, yc), FPoint(xc, yb)); // bottom-left
 			surfaceArea->drawLine(FPoint(xc, yb), FPoint(xr, yc)); // bottom-right
 			surfaceArea->drawLine(FPoint(xr, yc), FPoint(xc, yt)); // top-right
diff --git a/engines/titanic/star_control/surface_area.cpp b/engines/titanic/star_control/surface_area.cpp
index be45f6b..647413c 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
diff --git a/engines/titanic/star_control/surface_area.h b/engines/titanic/star_control/surface_area.h
index 2605634..be1689f 100644
--- a/engines/titanic/star_control/surface_area.h
+++ b/engines/titanic/star_control/surface_area.h
@@ -91,13 +91,14 @@ public:
 	/**
 	 * Draws a line on the surface
 	 */
-	double drawLine(const FRect &rect);
+	double drawLine(const FPoint &pt1, const FPoint &pt2);
 
 	/**
-	 * Draws a line on the surface
+	 * Draws a line on the surface from the rect's top-left
+	 * to bottom-right corners
 	 */
-	double drawLine(const FPoint &pt1, const FPoint &pt2) {
-		return drawLine(FRect(pt1._x, pt1._y, pt2._x, pt2._y));
+	double drawLine(const FRect &rect) {
+		return drawLine(FPoint(rect.left, rect.top), FPoint(rect.right, rect.bottom));
 	}
 };
 





More information about the Scummvm-git-logs mailing list