aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2017-04-02 10:06:42 -0400
committerPaul Gilbert2017-04-02 10:06:42 -0400
commit2889f6c463bd121664169c3b5209ddacf9ee8d82 (patch)
treeefc4b3c9cd78f4d16f9aa17eeffd64b96e964102
parent5929d647e420c14dc22ffa223a5cee5ebcee1395 (diff)
downloadscummvm-rg350-2889f6c463bd121664169c3b5209ddacf9ee8d82.tar.gz
scummvm-rg350-2889f6c463bd121664169c3b5209ddacf9ee8d82.tar.bz2
scummvm-rg350-2889f6c463bd121664169c3b5209ddacf9ee8d82.zip
TITANIC: Cleanup and minor fixes in star drawing code
-rw-r--r--engines/titanic/star_control/base_star.cpp85
-rw-r--r--engines/titanic/star_control/star_control_sub13.cpp2
-rw-r--r--engines/titanic/star_control/star_control_sub5.cpp14
-rw-r--r--engines/titanic/star_control/star_control_sub5.h3
-rw-r--r--engines/titanic/star_control/star_control_sub6.cpp47
-rw-r--r--engines/titanic/star_control/star_control_sub6.h2
6 files changed, 78 insertions, 75 deletions
diff --git a/engines/titanic/star_control/base_star.cpp b/engines/titanic/star_control/base_star.cpp
index 738ad5ab86..fd99c2012b 100644
--- a/engines/titanic/star_control/base_star.cpp
+++ b/engines/titanic/star_control/base_star.cpp
@@ -170,31 +170,31 @@ void CBaseStar::draw1(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStar
int height1 = surfaceArea->_height - 1;
double *v1Ptr = &_value1, *v2Ptr = &_value2;
FVector vector;
- double total;
+ double tempZ;
for (uint idx = 0; idx < _data.size(); ++idx) {
CBaseStarEntry &entry = _data[idx];
vector = entry._position;
- total = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ tempZ = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ vector._z * sub6._row3._z + sub6._vector._z;
- if (total <= minVal)
+ if (tempZ <= minVal)
continue;
- double temp1 = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + vector._y;
- double temp2 = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + vector._x;
- double total2 = temp1 * temp1 + temp2 * temp2 + total * total;
+ double tempY = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + sub6._vector._y;
+ double tempX = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + sub6._vector._x;
+ double total2 = tempY * tempY + tempX * tempX + tempZ * tempZ;
if (total2 < 1.0e12) {
- sub5->proc2(&sub6, &vector, centroid._x, centroid._y, total2,
+ sub5->proc2(&sub6, vector, centroid._x, centroid._y, total2,
surfaceArea, sub12);
continue;
}
- if (total <= threshold || total2 >= MAX_VAL)
+ if (tempZ <= threshold || total2 >= MAX_VAL)
continue;
- int xStart = (int)(*v1Ptr * temp2 / total + centroid._x);
- int yStart = (int)(*v2Ptr * temp1 / total + centroid._y);
+ int xStart = (int)(*v1Ptr * tempX / tempZ + centroid._x);
+ int yStart = (int)(*v2Ptr * tempY / tempZ + centroid._y);
if (xStart < 0 || xStart >= width1 || yStart < 0 || yStart >= height1)
continue;
@@ -256,31 +256,31 @@ void CBaseStar::draw2(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStar
int height1 = surfaceArea->_height - 1;
double *v1Ptr = &_value1, *v2Ptr = &_value2;
FVector vector;
- double total;
+ double tempZ;
for (uint idx = 0; idx < _data.size(); ++idx) {
CBaseStarEntry &entry = _data[idx];
vector = entry._position;
- total = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ tempZ = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ vector._z * sub6._row3._z + sub6._vector._z;
- if (total <= minVal)
+ if (tempZ <= minVal)
continue;
- double temp1 = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + vector._y;
- double temp2 = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + vector._x;
- double total2 = temp1 * temp1 + temp2 * temp2 + total * total;
+ double tempY = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + vector._y;
+ double tempX = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + vector._x;
+ double total2 = tempY * tempY + tempX * tempX + tempZ * tempZ;
if (total2 < 1.0e12) {
- sub5->proc2(&sub6, &vector, centroid._x, centroid._y, total2,
+ sub5->proc2(&sub6, vector, centroid._x, centroid._y, total2,
surfaceArea, sub12);
continue;
}
- if (total <= threshold || total2 >= MAX_VAL)
+ if (tempZ <= threshold || total2 >= MAX_VAL)
continue;
- int xStart = (int)(*v1Ptr * temp2 / total + centroid._x);
- int yStart = (int)(*v2Ptr * temp1 / total + centroid._y);
+ int xStart = (int)(*v1Ptr * tempX / tempZ + centroid._x);
+ int yStart = (int)(*v2Ptr * tempY / tempZ + centroid._y);
if (xStart < 0 || xStart >= width1 || yStart < 0 || yStart >= height1)
continue;
@@ -343,31 +343,31 @@ void CBaseStar::draw3(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStar
int height1 = surfaceArea->_height - 1;
double *v1Ptr = &_value1, *v2Ptr = &_value2, *v3Ptr = &_value3;
FVector vector;
- double total;
+ double tempZ;
for (uint idx = 0; idx < _data.size(); ++idx) {
CBaseStarEntry &entry = _data[idx];
vector = entry._position;
- total = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ tempZ = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ vector._z * sub6._row3._z + sub6._vector._z;
- if (total <= minVal)
+ if (tempZ <= minVal)
continue;
- double temp1 = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + vector._y;
- double temp2 = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + vector._x;
- double total2 = temp1 * temp1 + temp2 * temp2 + total * total;
+ double tempY = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + sub6._vector._y;
+ double tempX = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + sub6._vector._x;
+ double total2 = tempY * tempY + tempX * tempX + tempZ * tempZ;
if (total2 < 1.0e12) {
- sub5->proc2(&sub6, &vector, centroid._x, centroid._y, total2,
+ sub5->proc2(&sub6, vector, centroid._x, centroid._y, total2,
surfaceArea, sub12);
continue;
}
- if (total <= threshold || total2 >= MAX_VAL)
+ if (tempZ <= threshold || total2 >= MAX_VAL)
continue;
- int xStart = (int)((temp2 + *v3Ptr) * *v1Ptr / total + centroid._x);
- int yStart = (int)(temp1 * *v2Ptr / total + centroid._y);
+ int xStart = (int)((tempX + *v3Ptr) * *v1Ptr / tempZ + centroid._x);
+ int yStart = (int)(tempY * *v2Ptr / tempZ + centroid._y);
if (xStart < 0 || xStart >= width1 || yStart < 0 || yStart >= height1)
continue;
@@ -413,32 +413,31 @@ void CBaseStar::draw4(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStar
int width1 = surfaceArea->_width - 1;
int height1 = surfaceArea->_height - 1;
double *v1Ptr = &_value1, *v2Ptr = &_value2, *v3Ptr = &_value3;
- FVector vector;
- double total;
+ double tempZ;
for (uint idx = 0; idx < _data.size(); ++idx) {
- CBaseStarEntry &entry = _data[idx];
- vector = entry._position;
- total = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ const CBaseStarEntry &entry = _data[idx];
+ const FVector &vector = entry._position;
+ tempZ = vector._x * sub6._row1._z + vector._y * sub6._row2._z
+ vector._z * sub6._row3._z + sub6._vector._z;
- if (total <= minVal)
+ if (tempZ <= minVal)
continue;
- double temp1 = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + vector._y;
- double temp2 = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + vector._x;
- double total2 = temp1 * temp1 + temp2 * temp2 + total * total;
+ double tempY = vector._x * sub6._row1._y + vector._y * sub6._row2._y + vector._z * sub6._row3._y + sub6._vector._y;
+ double tempX = vector._x * sub6._row1._x + vector._y * sub6._row2._x + vector._z * sub6._row3._x + sub6._vector._x;
+ double total2 = tempY * tempY + tempX * tempX + tempZ * tempZ;
if (total2 < 1.0e12) {
- sub5->proc2(&sub6, &vector, centroid._x, centroid._y, total2,
+ sub5->proc2(&sub6, vector, centroid._x, centroid._y, total2,
surfaceArea, sub12);
continue;
}
- if (total <= threshold || total2 >= MAX_VAL)
+ if (tempZ <= threshold || total2 >= MAX_VAL)
continue;
- int xStart = (int)((temp2 + *v3Ptr) * *v1Ptr / total + centroid._x);
- int yStart = (int)(temp1 * *v2Ptr / total + centroid._y);
+ int xStart = (int)((tempX + *v3Ptr) * *v1Ptr / tempZ + centroid._x);
+ int yStart = (int)(tempY * *v2Ptr / tempZ + centroid._y);
if (xStart < 0 || xStart >= width1 || yStart < 0 || yStart >= height1)
continue;
diff --git a/engines/titanic/star_control/star_control_sub13.cpp b/engines/titanic/star_control/star_control_sub13.cpp
index 6475c75589..d96a29075b 100644
--- a/engines/titanic/star_control/star_control_sub13.cpp
+++ b/engines/titanic/star_control/star_control_sub13.cpp
@@ -246,7 +246,7 @@ void CStarControlSub13::reset() {
_sub2.copyFrom(_matrix);
_sub2._vector = _position;
- _sub2.fn4(&_sub1);
+ _sub1 = _sub2.fn4();
_center = FPoint((double)_width * 0.5, (double)_height * 0.5);
_centerVector._x = MIN(_center._x, _center._y);
diff --git a/engines/titanic/star_control/star_control_sub5.cpp b/engines/titanic/star_control/star_control_sub5.cpp
index e4a9739f3a..328a992ea5 100644
--- a/engines/titanic/star_control/star_control_sub5.cpp
+++ b/engines/titanic/star_control/star_control_sub5.cpp
@@ -189,7 +189,7 @@ bool CStarControlSub5::setup2(int val1, int val2) {
return false;
}
-void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1, double v2, double v3,
+void CStarControlSub5::proc2(CStarControlSub6 *sub6, const FVector &vector, double v1, double v2, double v3,
CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) {
const int VALUES[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4 };
double val1 = sub12->proc25();
@@ -207,8 +207,8 @@ void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1,
if (v3 >= 6.0e9) {
int count, start;
- if (vector->_x != 0.0 && (vector->_y != 0.0 || vector->_z != 0.0)) {
- // WORKAROUND: Ignoring non-sensical randSeed((int)vector->_x);
+ if (vector._x != 0.0 && (vector._y != 0.0 || vector._z != 0.0)) {
+ // WORKAROUND: Ignoring non-sensical randSeed((int)vector._x);
count = VALUES[g_vm->getRandomNumber(15)];
start = 5 * g_vm->getRandomNumber(255);
} else {
@@ -249,9 +249,9 @@ void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1,
_sub1._row3._z = f14;
f22 = (double)entryP->_field0;
- _sub1._vector._x = f22 * f10 + vector->_x;
- _sub1._vector._y = f9 * f22 + vector->_y;
- _sub1._vector._z = f22 * f12 + vector->_z;
+ _sub1._vector._x = f22 * f10 + vector._x;
+ _sub1._vector._y = f9 * f22 + vector._y;
+ _sub1._vector._z = f22 * f12 + vector._z;
_sub2._row1._x = sub6->_row1._x * f13 + f16 * sub6->_row3._x + f15 * sub6->_row2._x;
_sub2._row1._y = f15 * sub6->_row2._y + f16 * sub6->_row3._y + f13 * sub6->_row1._y;
_sub2._row1._z = f16 * sub6->_row3._z + f13 * sub6->_row1._z + f15 * sub6->_row2._z;
@@ -405,7 +405,7 @@ void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1,
for (uint ctr = 0; ctr < entry._data2.size(); ++ctr) {
GridEntry &gridEntry = _grid[ctr];
const FVector &d2v = entry._data2[ctr];
- FVector newV = d2v + *vector;
+ FVector newV = d2v + vector;
f41 = sub6->_row1._x;
f42 = sub6->_row3._x;
diff --git a/engines/titanic/star_control/star_control_sub5.h b/engines/titanic/star_control/star_control_sub5.h
index b5e5bb1b6a..dc25ddc62b 100644
--- a/engines/titanic/star_control/star_control_sub5.h
+++ b/engines/titanic/star_control/star_control_sub5.h
@@ -24,6 +24,7 @@
#define TITANIC_STAR_CONTROL_SUB5_H
#include "common/array.h"
+#include "titanic/star_control/fvector.h"
#include "titanic/star_control/star_control_sub6.h"
#include "titanic/star_control/error_code.h"
#include "titanic/star_control/surface_area.h"
@@ -115,7 +116,7 @@ public:
virtual ~CStarControlSub5() {}
virtual bool setup();
- virtual void proc2(CStarControlSub6 *sub6, FVector *vector, double v1, double v2, double v3,
+ virtual void proc2(CStarControlSub6 *sub6, const FVector &vector, double v1, double v2, double v3,
CSurfaceArea *surfaceArea, CStarControlSub12 *sub12);
virtual void proc3(CErrorCode *errorCode);
diff --git a/engines/titanic/star_control/star_control_sub6.cpp b/engines/titanic/star_control/star_control_sub6.cpp
index 9d22f4610d..db9c4e59ab 100644
--- a/engines/titanic/star_control/star_control_sub6.cpp
+++ b/engines/titanic/star_control/star_control_sub6.cpp
@@ -145,10 +145,11 @@ void CStarControlSub6::copyFrom(const FMatrix &src) {
_row3 = src._row3;
}
-void CStarControlSub6::fn4(CStarControlSub6 *sub6) {
+CStarControlSub6 CStarControlSub6::fn4() const {
double v2, v3, v6, v7, v8, v9, v10, v11;
double v12, v13, v14, v15, v16, v17, v18;
-
+ CStarControlSub6 result;
+
v16 = _row3._z * _row2._y;
v2 = _row1._x * v16;
v3 = 0.0;
@@ -185,27 +186,29 @@ void CStarControlSub6::fn4(CStarControlSub6 *sub6) {
v8 = 1.0 / v18;
v18 = v8;
- sub6->_row1._x = (v16 - v17) * v8;
- sub6->_row2._x = -(_row2._x * _row3._z - _row3._x * _row2._z) * v8;
- sub6->_row3._x = (_row3._y * _row2._x - _row3._x * _row2._y) * v8;
- sub6->_row1._y = -(_row1._y * _row3._z - _row3._y * _row1._z) * v8;
- sub6->_row2._y = (_row1._x * _row3._z - _row3._x * _row1._z) * v8;
- sub6->_row3._y = -(_row1._x * _row3._y - _row3._x * _row1._y) * v8;
- sub6->_row1._z = (_row1._y * _row2._z - _row1._z * _row2._y) * v8;
- sub6->_row2._z = -(_row1._x * _row2._z - _row1._z * _row2._x) * v8;
- v9 = sub6->_row1._x;
- v10 = sub6->_row2._y;
- v11 = sub6->_row3._y;
- v12 = sub6->_row1._z;
- v13 = sub6->_row2._z;
- sub6->_row3._z = (_row1._x * _row2._y - _row1._y * _row2._x) * v18;
+ result._row1._x = (v16 - v17) * v8;
+ result._row2._x = -(_row2._x * _row3._z - _row3._x * _row2._z) * v8;
+ result._row3._x = (_row3._y * _row2._x - _row3._x * _row2._y) * v8;
+ result._row1._y = -(_row1._y * _row3._z - _row3._y * _row1._z) * v8;
+ result._row2._y = (_row1._x * _row3._z - _row3._x * _row1._z) * v8;
+ result._row3._y = -(_row1._x * _row3._y - _row3._x * _row1._y) * v8;
+ result._row1._z = (_row1._y * _row2._z - _row1._z * _row2._y) * v8;
+ result._row2._z = -(_row1._x * _row2._z - _row1._z * _row2._x) * v8;
+ v9 = result._row1._x;
+ v10 = result._row2._y;
+ v11 = result._row3._y;
+ v12 = result._row1._z;
+ v13 = result._row2._z;
+ result._row3._z = (_row1._x * _row2._y - _row1._y * _row2._x) * v18;
v14 = v9;
- v15 = sub6->_row3._z;
- sub6->_vector._x = -(v14 * _vector._x
- + _vector._y * sub6->_row2._x
- + _vector._z * sub6->_row3._x);
- sub6->_vector._y = -(_vector._x * sub6->_row1._y + v10 * _vector._y + v11 * _vector._z);
- sub6->_vector._z = -(v12 * _vector._x + v13 * _vector._y + v15 * _vector._z);
+ v15 = result._row3._z;
+ result._vector._x = -(v14 * _vector._x
+ + _vector._y * result._row2._x
+ + _vector._z * result._row3._x);
+ result._vector._y = -(_vector._x * result._row1._y + v10 * _vector._y + v11 * _vector._z);
+ result._vector._z = -(v12 * _vector._x + v13 * _vector._y + v15 * _vector._z);
+
+ return result;
}
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_control_sub6.h b/engines/titanic/star_control/star_control_sub6.h
index f0f14b6ccc..6ac22a79df 100644
--- a/engines/titanic/star_control/star_control_sub6.h
+++ b/engines/titanic/star_control/star_control_sub6.h
@@ -53,7 +53,7 @@ public:
*/
void copyFrom(const FMatrix &src);
- void fn4(CStarControlSub6 *sub6);
+ CStarControlSub6 fn4() const;
};
} // End of namespace Titanic