[Scummvm-git-logs] scummvm master -> 93a4c29b112929f26bb0045f2da210afdd58ac4a

dreammaster dreammaster at scummvm.org
Thu Apr 6 03:10:30 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:
93a4c29b11 TITANIC: Change many doubles to floats to match original's precision


Commit: 93a4c29b112929f26bb0045f2da210afdd58ac4a
    https://github.com/scummvm/scummvm/commit/93a4c29b112929f26bb0045f2da210afdd58ac4a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-04-05T21:08:51-04:00

Commit Message:
TITANIC: Change many doubles to floats to match original's precision

Many of the Star Control classes in the original explicitly used floats
rather than doubles. I'm switching to using them where applicable for
now, since the resulting figures will more closely match the original,
and it will be easier to spot errors in the various formulas

Changed paths:
    engines/titanic/star_control/fmatrix.cpp
    engines/titanic/star_control/fpoint.cpp
    engines/titanic/star_control/fpoint.h
    engines/titanic/star_control/fvector.cpp
    engines/titanic/star_control/fvector.h
    engines/titanic/star_control/star_control_sub6.cpp
    engines/titanic/star_control/star_control_sub6.h
    engines/titanic/star_control/star_view.cpp


diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp
index 5885658..11d9653 100644
--- a/engines/titanic/star_control/fmatrix.cpp
+++ b/engines/titanic/star_control/fmatrix.cpp
@@ -105,15 +105,15 @@ void FMatrix::fn1(const FVector &v) {
 }
 
 void FMatrix::fn2(const FMatrix &m) {
-	double x1 = _row1._y * m._row2._x + _row1._z * m._row3._x + _row1._x * m._row1._x;
-	double y1 = _row1._x * m._row1._y + m._row2._y * _row1._y + m._row3._y * _row1._z;
-	double z1 = _row1._x * m._row1._z + _row1._y * m._row2._z + _row1._z * m._row3._z;
-	double x2 = m._row1._x * _row2._x + m._row3._x * _row2._z + m._row2._x * _row2._y;
-	double y2 = m._row3._y * _row2._z + m._row1._y * _row2._x + m._row2._y * _row2._y;
-	double z2 = _row2._z * m._row3._z + _row2._x * m._row1._z + _row2._y * m._row2._z;
-	double x3 = m._row1._x * _row3._x + _row3._z * m._row3._x + _row3._y * m._row2._x;
-	double y3 = _row3._y * m._row2._y + _row3._z * m._row3._y + _row3._x * m._row1._y;
-	double z3 = _row3._x * m._row1._z + _row3._y * m._row2._z + _row3._z * m._row3._z;
+	float x1 = _row1._y * m._row2._x + _row1._z * m._row3._x + _row1._x * m._row1._x;
+	float y1 = _row1._x * m._row1._y + m._row2._y * _row1._y + m._row3._y * _row1._z;
+	float z1 = _row1._x * m._row1._z + _row1._y * m._row2._z + _row1._z * m._row3._z;
+	float x2 = m._row1._x * _row2._x + m._row3._x * _row2._z + m._row2._x * _row2._y;
+	float y2 = m._row3._y * _row2._z + m._row1._y * _row2._x + m._row2._y * _row2._y;
+	float z2 = _row2._z * m._row3._z + _row2._x * m._row1._z + _row2._y * m._row2._z;
+	float x3 = m._row1._x * _row3._x + _row3._z * m._row3._x + _row3._y * m._row2._x;
+	float y3 = _row3._y * m._row2._y + _row3._z * m._row3._y + _row3._x * m._row1._y;
+	float z3 = _row3._x * m._row1._z + _row3._y * m._row2._z + _row3._z * m._row3._z;
 
 	_row1 = FVector(x1, y1, z1);
 	_row2 = FVector(x2, y2, z2);
@@ -121,15 +121,15 @@ void FMatrix::fn2(const FMatrix &m) {
 }
 
 void FMatrix::fn3(const FMatrix &m) {
-	double x1 = _row2._x * m._row1._y + m._row1._z * _row3._x + _row1._x * m._row1._x;
-	double y1 = m._row1._x * _row1._y + _row3._y * m._row1._z + _row2._y * m._row1._y;
-	double z1 = m._row1._x * _row1._z + m._row1._y * _row2._z + m._row1._z * _row3._z;
-	double x2 = _row1._x * m._row2._x + _row2._x * m._row2._y + _row3._x * m._row2._z;
-	double y2 = _row3._y * m._row2._z + _row1._y * m._row2._x + _row2._y * m._row2._y;
-	double z2 = m._row2._z * _row3._z + m._row2._x * _row1._z + m._row2._y * _row2._z;
-	double x3 = _row1._x * m._row3._x + m._row3._z * _row3._x + m._row3._y * _row2._x;
-	double y3 = m._row3._y * _row2._y + m._row3._z * _row3._y + m._row3._x * _row1._y;
-	double z3 = m._row3._x * _row1._z + m._row3._y * _row2._z + m._row3._z * _row3._z;
+	float x1 = _row2._x * m._row1._y + m._row1._z * _row3._x + _row1._x * m._row1._x;
+	float y1 = m._row1._x * _row1._y + _row3._y * m._row1._z + _row2._y * m._row1._y;
+	float z1 = m._row1._x * _row1._z + m._row1._y * _row2._z + m._row1._z * _row3._z;
+	float x2 = _row1._x * m._row2._x + _row2._x * m._row2._y + _row3._x * m._row2._z;
+	float y2 = _row3._y * m._row2._z + _row1._y * m._row2._x + _row2._y * m._row2._y;
+	float z2 = m._row2._z * _row3._z + m._row2._x * _row1._z + m._row2._y * _row2._z;
+	float x3 = _row1._x * m._row3._x + m._row3._z * _row3._x + m._row3._y * _row2._x;
+	float y3 = m._row3._y * _row2._y + m._row3._z * _row3._y + m._row3._x * _row1._y;
+	float z3 = m._row3._x * _row1._z + m._row3._y * _row2._z + m._row3._z * _row3._z;
 
 	_row1 = FVector(x1, y1, z1);
 	_row2 = FVector(x2, y2, z2);
diff --git a/engines/titanic/star_control/fpoint.cpp b/engines/titanic/star_control/fpoint.cpp
index a7c7641..e70cd64 100644
--- a/engines/titanic/star_control/fpoint.cpp
+++ b/engines/titanic/star_control/fpoint.cpp
@@ -25,11 +25,11 @@
 
 namespace Titanic {
 
-double FPoint::normalize() {
-	double hyp = sqrt(_x * _x + _y * _y);
+float FPoint::normalize() {
+	float hyp = sqrt(_x * _x + _y * _y);
 	assert(hyp != 0.0);
 
-	double fraction = 1.0 / hyp;
+	float fraction = 1.0 / hyp;
 	_x *= fraction;
 	_y *= fraction;
 	return hyp;
diff --git a/engines/titanic/star_control/fpoint.h b/engines/titanic/star_control/fpoint.h
index d967351..d65da1a 100644
--- a/engines/titanic/star_control/fpoint.h
+++ b/engines/titanic/star_control/fpoint.h
@@ -32,10 +32,10 @@ namespace Titanic {
  */
 class FPoint {
 public:
-	double _x, _y;
+	float _x, _y;
 public:
 	FPoint() : _x(0), _y(0) {}
-	FPoint(double x, double y) : _x(x), _y(y) {}
+	FPoint(float x, float y) : _x(x), _y(y) {}
 	FPoint(const Common::Point &pt) : _x(pt.x), _y(pt.y) {}
 
 	bool operator==(const FPoint &p) const { return _x == p._x && _y == p._y; }
@@ -57,7 +57,7 @@ public:
 	 * Normalises the X and Y coordinates as fractions relative to the
 	 * value of the hypotenuse formed by a triangle from the origin (0,0)
 	 */
-	double normalize();
+	float normalize();
 };
 
 } // End of namespace Titanic
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp
index eec16d1..1e509b5 100644
--- a/engines/titanic/star_control/fvector.cpp
+++ b/engines/titanic/star_control/fvector.cpp
@@ -48,8 +48,8 @@ FVector FVector::crossProduct(const FVector &src) const {
 	);
 }
 
-double FVector::normalize() {
-	double hyp = sqrt(_x * _x + _y * _y + _z * _z);
+float FVector::normalize() {
+	float hyp = sqrt(_x * _x + _y * _y + _z * _z);
 	assert(hyp);
 
 	_x *= 1.0 / hyp;
@@ -66,10 +66,10 @@ const FVector *FVector::addAndNormalize(FVector &dest, const FVector &v1, const
 	return &dest;
 }
 
-double FVector::getDistance(const FVector &src) const {
-	double xd = src._x - _x;
-	double yd = src._y - _y;
-	double zd = src._z - _z;
+float FVector::getDistance(const FVector &src) const {
+	float xd = src._x - _x;
+	float yd = src._y - _y;
+	float zd = src._z - _z;
 
 	return sqrt(xd * xd + yd * yd + zd * zd);
 }
diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h
index dd8a25e..22ce5e8 100644
--- a/engines/titanic/star_control/fvector.h
+++ b/engines/titanic/star_control/fvector.h
@@ -38,10 +38,10 @@ class DVector;
  */
 class FVector {
 public:
-	double _x, _y, _z;
+	float _x, _y, _z;
 public:
 	FVector() : _x(0), _y(0), _z(0) {}
-	FVector(double x, double y, double z) : _x(x), _y(y), _z(z) {}
+	FVector(float x, float y, float z) : _x(x), _y(y), _z(z) {}
 	FVector(const DVector &src);
 
 	/**
@@ -61,7 +61,7 @@ public:
 	/**
 	 * Normalizes the vector so the length from origin equals 1.0
 	 */
-	double normalize();
+	float normalize();
 
 	/**
 	 * Adds two vectors together and then normalizes the result
@@ -71,7 +71,7 @@ public:
 	/**
 	 * Returns the distance between a specified point and this one
 	 */
-	double getDistance(const FVector &src) const;
+	float getDistance(const FVector &src) const;
 
 	FVector fn5(const CStarControlSub6 *sub6) const;
 
@@ -97,7 +97,7 @@ public:
 		return FVector(_x - delta._x, _y - delta._y, _z - delta._z);
 	}
 
-	const FVector operator*(double right) const {
+	const FVector operator*(float right) const {
 		return FVector(_x * right, _y * right, _z * right);
 	}
 
diff --git a/engines/titanic/star_control/star_control_sub6.cpp b/engines/titanic/star_control/star_control_sub6.cpp
index 7d9cee4..5bedb6f 100644
--- a/engines/titanic/star_control/star_control_sub6.cpp
+++ b/engines/titanic/star_control/star_control_sub6.cpp
@@ -28,7 +28,7 @@ CStarControlSub6::CStarControlSub6() {
 	clear();
 }
 
-CStarControlSub6::CStarControlSub6(Axis axis, double amount) {
+CStarControlSub6::CStarControlSub6(Axis axis, float amount) {
 	setRotationMatrix(axis, amount);
 }
 
@@ -83,10 +83,10 @@ void CStarControlSub6::identity() {
 	_vector.clear();
 }
 
-void CStarControlSub6::setRotationMatrix(Axis axis, double amount) {
-	const double ROTATION = 2 * M_PI / 360.0;
-	double sinVal = sin(amount * ROTATION);
-	double cosVal = cos(amount * ROTATION);
+void CStarControlSub6::setRotationMatrix(Axis axis, float amount) {
+	const float ROTATION = 2 * M_PI / 360.0;
+	float sinVal = sin(amount * ROTATION);
+	float cosVal = cos(amount * ROTATION);
 
 	switch (axis) {
 	case X_AXIS:
@@ -146,8 +146,8 @@ void CStarControlSub6::copyFrom(const FMatrix &src) {
 }
 
 CStarControlSub6 CStarControlSub6::fn4() const {
-	double v2, v3, v6, v7, v8, v9, v10, v11;
-	double v12, v13, v14, v15, v16, v17, v18;
+	float v2, v3, v6, v7, v8, v9, v10, v11;
+	float v12, v13, v14, v15, v16, v17, v18;
 	CStarControlSub6 result;
 
 	v16 = _row3._z * _row2._y;
diff --git a/engines/titanic/star_control/star_control_sub6.h b/engines/titanic/star_control/star_control_sub6.h
index 6ac22a7..3ded69b 100644
--- a/engines/titanic/star_control/star_control_sub6.h
+++ b/engines/titanic/star_control/star_control_sub6.h
@@ -32,7 +32,7 @@ public:
 	FVector _vector;
 public:
 	CStarControlSub6();
-	CStarControlSub6(Axis axis, double amount);
+	CStarControlSub6(Axis axis, float amount);
 	CStarControlSub6(const CStarControlSub6 *src);
 	CStarControlSub6(const CStarControlSub6 *s1, const CStarControlSub6 *s2);
 
@@ -44,7 +44,7 @@ public:
 	/**
 	 * Sets a rotation matrix for the given axis for the given amount
 	 */
-	void setRotationMatrix(Axis axis, double val);
+	void setRotationMatrix(Axis axis, float val);
 
 	void copyFrom(const CStarControlSub6 *src);
 
diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp
index d3693d5..d529012 100644
--- a/engines/titanic/star_control/star_view.cpp
+++ b/engines/titanic/star_control/star_view.cpp
@@ -126,10 +126,10 @@ bool CStarView::MouseMoveMsg(int unused, const Point &pt) {
 		FPoint centerPt(300.0, 170.0);
 
 		if (fpt != centerPt) {
-			double threshold = MIN(centerPt._x, centerPt._y) * 0.5;
+			float threshold = MIN(centerPt._x, centerPt._y) * 0.5;
 			FPoint tempPt = fpt - centerPt;
 
-			double distance = tempPt.normalize();
+			float distance = tempPt.normalize();
 			if (distance >= threshold) {
 				distance -= threshold;
 





More information about the Scummvm-git-logs mailing list