aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2017-08-20 14:31:47 -0400
committerGitHub2017-08-20 14:31:47 -0400
commita32a29a80e8dfc44c5da8a2f872914710a4009ae (patch)
tree15427ed634e960f0cb2fecf4ae70a2de12577367 /engines
parent4ba87013a9d9d50a2866fd23aaf39e546bff9b7b (diff)
parent312d63c3c951ed3781c4f7a1577b62cb862042b3 (diff)
downloadscummvm-rg350-a32a29a80e8dfc44c5da8a2f872914710a4009ae.tar.gz
scummvm-rg350-a32a29a80e8dfc44c5da8a2f872914710a4009ae.tar.bz2
scummvm-rg350-a32a29a80e8dfc44c5da8a2f872914710a4009ae.zip
Merge pull request #995 from dafioram/star_camera_work
TITANIC: CStarCamera Refactoring and CStarCrosshairs logic fix
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/star_control/base_stars.cpp3
-rw-r--r--engines/titanic/star_control/base_stars.h2
-rw-r--r--engines/titanic/star_control/camera_auto_mover.cpp19
-rw-r--r--engines/titanic/star_control/camera_auto_mover.h6
-rw-r--r--engines/titanic/star_control/dvector.cpp16
-rw-r--r--engines/titanic/star_control/dvector.h11
-rw-r--r--engines/titanic/star_control/fmatrix.cpp15
-rw-r--r--engines/titanic/star_control/fmatrix.h2
-rw-r--r--engines/titanic/star_control/fvector.cpp17
-rw-r--r--engines/titanic/star_control/fvector.h10
-rw-r--r--engines/titanic/star_control/marked_auto_mover.cpp2
-rw-r--r--engines/titanic/star_control/marked_camera_mover.cpp1
-rw-r--r--engines/titanic/star_control/star_camera.cpp129
-rw-r--r--engines/titanic/star_control/star_camera.h34
-rw-r--r--engines/titanic/star_control/star_control.cpp9
-rw-r--r--engines/titanic/star_control/star_crosshairs.cpp21
-rw-r--r--engines/titanic/star_control/star_view.cpp9
-rw-r--r--engines/titanic/star_control/star_view.h7
-rw-r--r--engines/titanic/star_control/unmarked_auto_mover.cpp9
-rw-r--r--engines/titanic/star_control/unmarked_camera_mover.cpp5
20 files changed, 232 insertions, 95 deletions
diff --git a/engines/titanic/star_control/base_stars.cpp b/engines/titanic/star_control/base_stars.cpp
index 94208e7374..c22260ea98 100644
--- a/engines/titanic/star_control/base_stars.cpp
+++ b/engines/titanic/star_control/base_stars.cpp
@@ -23,6 +23,7 @@
#include "titanic/star_control/base_stars.h"
#include "titanic/star_control/star_camera.h"
#include "titanic/star_control/star_ref.h"
+#include "titanic/support/simple_file.h"
#include "titanic/titanic.h"
namespace Titanic {
@@ -560,7 +561,7 @@ int CBaseStars::baseFn2(CSurfaceArea *surfaceArea, CStarCamera *camera) {
/*------------------------------------------------------------------------*/
void CStarVector::apply() {
- _owner->adDAffineRow(_vector);
+ _owner->addLockedStar(_vector);
}
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/base_stars.h b/engines/titanic/star_control/base_stars.h
index e77b20ec08..4333e3231e 100644
--- a/engines/titanic/star_control/base_stars.h
+++ b/engines/titanic/star_control/base_stars.h
@@ -23,7 +23,6 @@
#ifndef TITANIC_BASE_STARS_H
#define TITANIC_BASE_STARS_H
-#include "titanic/support/simple_file.h"
#include "titanic/star_control/frange.h"
#include "titanic/star_control/star_closeup.h"
#include "titanic/star_control/surface_area.h"
@@ -33,6 +32,7 @@ namespace Titanic {
enum StarMode { MODE_STARFIELD = 0, MODE_PHOTO = 1 };
class CStarCamera;
+class SimpleFile;
struct CBaseStarEntry {
byte _red;
diff --git a/engines/titanic/star_control/camera_auto_mover.cpp b/engines/titanic/star_control/camera_auto_mover.cpp
index 45e5a9e03e..bcb94d27c2 100644
--- a/engines/titanic/star_control/camera_auto_mover.cpp
+++ b/engines/titanic/star_control/camera_auto_mover.cpp
@@ -21,8 +21,11 @@
*/
#include "titanic/star_control/camera_auto_mover.h"
+#include "titanic/star_control/fmatrix.h"
+#include "titanic/star_control/error_code.h"
#include "common/textconsole.h"
+
namespace Titanic {
CCameraAutoMover::CCameraAutoMover() : _srcPos(0.0, 1000000.0, 0.0) {
@@ -46,8 +49,12 @@ void CCameraAutoMover::proc2(const FVector &oldPos, const FVector &newPos,
_srcPos = oldPos;
_destPos = newPos;
_posDelta = _destPos - _srcPos;
- _distance = _posDelta.normalize();
-
+ float temp = 0.0;
+ if (!_posDelta.normalize(temp)) { // Do the normalization, put the scale amount in temp,
+ // but if it is unsuccessful, crash
+ assert(temp);
+ }
+ _distance = temp;
_active = false;
_field34 = false;
_transitionPercent = 1.0;
@@ -70,8 +77,12 @@ void CCameraAutoMover::setPath(const FVector &srcV, const FVector &destV, const
_srcPos = srcV;
_destPos = destV;
_posDelta = _destPos - _srcPos;
- _distance = _posDelta.normalize();
-
+ float temp = 0.0;
+ if (!_posDelta.normalize(temp)) { // Do the normalization, put the scale amount in temp,
+ // but if it is unsuccessful, crash
+ assert(temp);
+ }
+ _distance = temp;
_active = false;
_field34 = false;
_field40 = -1;
diff --git a/engines/titanic/star_control/camera_auto_mover.h b/engines/titanic/star_control/camera_auto_mover.h
index 52938284ed..dc9cf6df45 100644
--- a/engines/titanic/star_control/camera_auto_mover.h
+++ b/engines/titanic/star_control/camera_auto_mover.h
@@ -23,13 +23,15 @@
#ifndef TITANIC_CAMERA_AUTO_MOVER_H
#define TITANIC_CAMERA_AUTO_MOVER_H
-#include "titanic/star_control/error_code.h"
-#include "titanic/star_control/fmatrix.h"
#include "titanic/star_control/fvector.h"
#include "titanic/star_control/orientation_changer.h"
+#include "common/array.h"
namespace Titanic {
+class CErrorCode;
+class FMatrix;
+
/**
* Base class for automatic movement of the starview camera
*/
diff --git a/engines/titanic/star_control/dvector.cpp b/engines/titanic/star_control/dvector.cpp
index c7481a2b49..405af4a0d4 100644
--- a/engines/titanic/star_control/dvector.cpp
+++ b/engines/titanic/star_control/dvector.cpp
@@ -26,14 +26,16 @@
namespace Titanic {
-double DVector::normalize() {
- double hyp = sqrt(_x * _x + _y * _y + _z * _z);
- assert(hyp);
+bool DVector::normalize(double & hyp) {
+ hyp = sqrt(_x * _x + _y * _y + _z * _z);
+ if (hyp==0) {
+ return false;
+ }
_x *= 1.0 / hyp;
_y *= 1.0 / hyp;
_z *= 1.0 / hyp;
- return hyp;
+ return true;
}
double DVector::getDistance(const DVector &src) {
@@ -73,7 +75,11 @@ void DVector::rotVectAxisY(double angleDeg) {
DVector DVector::getAnglesAsVect() const {
DVector vector = *this;
DVector dest;
- dest._x = vector.normalize(); // scale that makes this vector have magnitude=1, also does the scaling
+
+ if (!vector.normalize(dest._x)) { // Makes this vector have magnitude=1, put the scale amount in dest._x,
+ // but if it is unsuccessful, crash
+ assert(dest._x);
+ }
dest._y = acos(vector._y); // radian distance/angle that this vector's y component is from the +y axis,
// result is restricted to [0,pi]
dest._z = atan2(vector._x,vector._z); // result is restricted to [-pi,pi]
diff --git a/engines/titanic/star_control/dvector.h b/engines/titanic/star_control/dvector.h
index bff271dd6f..f115abdaae 100644
--- a/engines/titanic/star_control/dvector.h
+++ b/engines/titanic/star_control/dvector.h
@@ -44,7 +44,16 @@ public:
DVector(double x, double y, double z) : _x(x), _y(y), _z(z) {}
DVector(const FVector &v) : _x(v._x), _y(v._y), _z(v._z) {}
- double normalize();
+ /**
+ * Attempts to normalizes the vector so the length from origin equals 1.0
+ * Return value is whether or not it was successful in normalizing
+ * First argument is scale value that normalizes the vector
+ * TODO: split this function into 2. One that calculates the normalization
+ * and another that does the normalization. The 2nd would assert if a
+ * normalization of one was requested. This is cleaner than the current
+ * implementation.
+ */
+ bool normalize(double &);
/**
* Returns the distance between this vector and the passed one
diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp
index cd59c559ca..470569c88d 100644
--- a/engines/titanic/star_control/fmatrix.cpp
+++ b/engines/titanic/star_control/fmatrix.cpp
@@ -22,6 +22,7 @@
#include "titanic/star_control/fmatrix.h"
#include "titanic/star_control/daffine.h"
+#include "titanic/support/simple_file.h"
namespace Titanic {
@@ -39,7 +40,7 @@ void matProd(const FMatrix &a, const FMatrix &m, FMatrix &C) {
C._row3._z = a._row3._x * m._row1._z + a._row3._y * m._row2._z + a._row3._z * m._row3._z;
}
-// member functions
+// Member functions
FMatrix::FMatrix() :
_row1(1.0, 0.0, 0.0), _row2(0.0, 1.0, 0.0), _row3(0.0, 0.0, 1.0) {
@@ -126,10 +127,18 @@ void FMatrix::set(const FVector &v) {
_row2 = _row3.fn1();
_row1 = _row3.crossProduct(_row2);
- _row1.normalize();
+
+ float unused_scale=0.0;
+ if (!_row1.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
_row2 = _row3.crossProduct(_row1);
- _row2.normalize();
+ if (!_row2.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
}
void FMatrix::matRProd(const FMatrix &m) {
diff --git a/engines/titanic/star_control/fmatrix.h b/engines/titanic/star_control/fmatrix.h
index 00054ee7bb..6d118a73a6 100644
--- a/engines/titanic/star_control/fmatrix.h
+++ b/engines/titanic/star_control/fmatrix.h
@@ -23,13 +23,13 @@
#ifndef TITANIC_FMATRIX_H
#define TITANIC_FMATRIX_H
-#include "titanic/support/simple_file.h"
#include "titanic/star_control/fvector.h"
namespace Titanic {
class DAffine;
class DVector;
+class SimpleFile;
/**
* Floating point matrix class.
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp
index a107ad1ed2..75d30748d2 100644
--- a/engines/titanic/star_control/fvector.cpp
+++ b/engines/titanic/star_control/fvector.cpp
@@ -48,20 +48,25 @@ FVector FVector::crossProduct(const FVector &src) const {
);
}
-float FVector::normalize() {
- float hyp = sqrt(_x * _x + _y * _y + _z * _z);
- assert(hyp);
+bool FVector::normalize(float & hyp) {
+ hyp = sqrt(_x * _x + _y * _y + _z * _z);
+ if (hyp==0) {
+ return false;
+ }
_x *= 1.0 / hyp;
_y *= 1.0 / hyp;
_z *= 1.0 / hyp;
- return hyp;
+ return true;
}
FVector FVector::addAndNormalize(const FVector &v) const {
FVector tempV(_x + v._x, _y + v._y, _z + v._z);
- tempV.normalize();
-
+ float unused_scale=0.0;
+ if (!tempV.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
return tempV;
}
diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h
index fa24fe58c1..f93ac60c26 100644
--- a/engines/titanic/star_control/fvector.h
+++ b/engines/titanic/star_control/fvector.h
@@ -59,9 +59,15 @@ public:
FVector crossProduct(const FVector &src) const;
/**
- * Normalizes the vector so the length from origin equals 1.0
+ * Attempts to normalizes the vector so the length from origin equals 1.0
+ * Return value is whether or not it was successful in normalizing
+ * First argument is scale value that normalizes the vector
+ * TODO: split this function into 2. One that calculates the normalization
+ * and another that does the normalization. The 2nd would assert if a
+ * normalization of one was requested. This is cleaner than the current
+ * implementation.
*/
- float normalize();
+ bool normalize(float &);
/**
* Adds the current vector and a passed one together, normalizes them,
diff --git a/engines/titanic/star_control/marked_auto_mover.cpp b/engines/titanic/star_control/marked_auto_mover.cpp
index 828fe03a95..e3ab2b4f20 100644
--- a/engines/titanic/star_control/marked_auto_mover.cpp
+++ b/engines/titanic/star_control/marked_auto_mover.cpp
@@ -21,6 +21,8 @@
*/
#include "titanic/star_control/marked_auto_mover.h"
+#include "titanic/star_control/error_code.h"
+#include "common/array.h"
#include "common/textconsole.h"
namespace Titanic {
diff --git a/engines/titanic/star_control/marked_camera_mover.cpp b/engines/titanic/star_control/marked_camera_mover.cpp
index 2e3fa8f448..61b7c05b60 100644
--- a/engines/titanic/star_control/marked_camera_mover.cpp
+++ b/engines/titanic/star_control/marked_camera_mover.cpp
@@ -21,6 +21,7 @@
*/
#include "titanic/star_control/marked_camera_mover.h"
+#include "common/array.h"
#include "common/textconsole.h"
namespace Titanic {
diff --git a/engines/titanic/star_control/star_camera.cpp b/engines/titanic/star_control/star_camera.cpp
index 9c1c598ede..924ffaf153 100644
--- a/engines/titanic/star_control/star_camera.cpp
+++ b/engines/titanic/star_control/star_camera.cpp
@@ -21,10 +21,14 @@
*/
#include "titanic/star_control/star_camera.h"
-#include "titanic/star_control/unmarked_camera_mover.h"
-#include "titanic/star_control/marked_camera_mover.h"
+#include "titanic/star_control/camera_mover.h"
#include "titanic/star_control/daffine.h"
#include "titanic/star_control/fmatrix.h"
+#include "titanic/star_control/fpoint.h"
+#include "titanic/star_control/marked_camera_mover.h"
+#include "titanic/star_control/unmarked_camera_mover.h"
+#include "titanic/star_control/error_code.h"
+#include "titanic/support/simple_file.h"
#include "titanic/titanic.h"
namespace Titanic {
@@ -33,12 +37,12 @@ FMatrix *CStarCamera::_priorOrientation;
FMatrix *CStarCamera::_newOrientation;
CStarCamera::CStarCamera(const CNavigationInfo *data) :
- _matrixRow(-1), _mover(nullptr), _isMoved(false) {
+ _star_lock_state(ZERO_LOCKED), _mover(nullptr), _isMoved(false) {
setupHandler(data);
}
CStarCamera::CStarCamera(CViewport *src) :
- _matrixRow(-1), _mover(nullptr), _isMoved(false), _viewport(src) {
+ _star_lock_state(ZERO_LOCKED), _mover(nullptr), _isMoved(false), _viewport(src) {
}
void CStarCamera::init() {
@@ -53,6 +57,10 @@ void CStarCamera::deinit() {
_newOrientation = nullptr;
}
+bool CStarCamera::isLocked() {
+ return _mover->isLocked();
+}
+
CStarCamera::~CStarCamera() {
deleteHandler();
}
@@ -226,15 +234,16 @@ void CStarCamera::setViewportAngle(const FPoint &angles) {
if (isLocked())
return;
-
- if (_matrixRow == -1) {
- // No locked markers
+ switch(_star_lock_state) {
+ case ZERO_LOCKED: {
FPose subX(X_AXIS, angles._y);
FPose subY(Y_AXIS, -angles._x); // needs to be negative or looking left will cause the view to go right
FPose sub(subX, subY);
proc22(sub);
- } else if (_matrixRow == 0) {
- // 1 marker is locked in
+ }
+ break;
+
+ case ONE_LOCKED: {
FVector row1 = _matrix._row1;
FPose poseX(X_AXIS, angles._y);
FPose poseY(Y_AXIS, -angles._x); // needs to be negative or looking left will cause the view to go right
@@ -267,16 +276,23 @@ void CStarCamera::setViewportAngle(const FPoint &angles) {
tempV4 -= tempV1;
tempV5 -= tempV1;
tempV6 -= tempV1;
- tempV4.normalize();
- tempV5.normalize();
- tempV6.normalize();
+
+ float unused_scale=0.0;
+ if (!tempV4.normalize(unused_scale) ||
+ !tempV5.normalize(unused_scale) ||
+ !tempV6.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
tempV1 += row1;
m1.set(tempV4, tempV5, tempV6);
_viewport.setOrientation(m1);
_viewport.setPosition(tempV1);
- } else if (_matrixRow == 1) {
- // 2 markers locked in
+ }
+ break;
+
+ case TWO_LOCKED: {
FVector tempV2;
DAffine m1, m2, sub;
DVector mrow1, mrow2, mrow3;
@@ -334,40 +350,52 @@ void CStarCamera::setViewportAngle(const FPoint &angles) {
mrow1 -= tempV3;
mrow2 -= tempV3;
mrow3 -= tempV3;
- mrow1.normalize();
- mrow2.normalize();
- mrow3.normalize();
+
+ double unused_scale=0.0;
+ if (!mrow1.normalize(unused_scale) ||
+ !mrow2.normalize(unused_scale) ||
+ !mrow3.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
+
tempV16 = tempV3;
m3.set(mrow1, mrow2, mrow3);
_viewport.setOrientation(m3);
_viewport.setPosition(tempV16);
- }
+ }
+ break;
+
+ //TODO: should three stars locked do anything in this function? Error?
+ case THREE_LOCKED:
+ break;
+ }
}
-bool CStarCamera::adDAffineRow(const FVector v) {
- if (_matrixRow >= 2)
+bool CStarCamera::addLockedStar(const FVector v) {
+ if (_star_lock_state == THREE_LOCKED)
return false;
CNavigationInfo data;
_mover->copyTo(&data);
deleteHandler();
-
- FVector &row = _matrix[++_matrixRow];
+ FVector &row = _matrix[(int)_star_lock_state];
+ _star_lock_state = StarLockState( (int)_star_lock_state + 1);
row = v;
setupHandler(&data);
return true;
}
-bool CStarCamera::removeMatrixRow() {
- if (_matrixRow == -1)
+bool CStarCamera::removeLockedStar() {
+ if (_star_lock_state == ZERO_LOCKED)
return false;
CNavigationInfo data;
_mover->copyTo(&data);
deleteHandler();
- --_matrixRow;
+ _star_lock_state = StarLockState( (int)_star_lock_state - 1);
setupHandler(&data);
return true;
}
@@ -387,14 +415,14 @@ void CStarCamera::save(SimpleFile *file, int indent) {
bool CStarCamera::setupHandler(const CNavigationInfo *src) {
CCameraMover *mover = nullptr;
- switch (_matrixRow) {
- case -1:
+ switch (_star_lock_state) {
+ case ZERO_LOCKED:
mover = new CUnmarkedCameraMover(src);
break;
- case 0:
- case 1:
- case 2:
+ case ONE_LOCKED:
+ case TWO_LOCKED:
+ case THREE_LOCKED:
mover = new CMarkedCameraMover(src);
break;
@@ -419,7 +447,7 @@ void CStarCamera::deleteHandler() {
}
void CStarCamera::lockMarker1(FVector v1, FVector v2, FVector v3) {
- if (_matrixRow != -1)
+ if (_star_lock_state != ZERO_LOCKED)
return;
FVector tempV;
@@ -442,8 +470,12 @@ void CStarCamera::lockMarker1(FVector v1, FVector v2, FVector v3) {
tempV._x = val9 - _viewport._valArray[2];
tempV._y = val8;
- v3.normalize();
- tempV.normalize();
+ float unused_scale=0.0;
+ if (!v3.normalize(unused_scale) ||
+ !tempV.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
FMatrix matrix = _viewport.getOrientation();
const FVector &pos = _viewport._position;
@@ -454,7 +486,7 @@ void CStarCamera::lockMarker1(FVector v1, FVector v2, FVector v3) {
}
void CStarCamera::lockMarker2(CViewport *viewport, const FVector &v) {
- if (_matrixRow != 0)
+ if (_star_lock_state != ONE_LOCKED)
return;
DAffine m2(X_AXIS, _matrix._row1);
@@ -531,21 +563,30 @@ void CStarCamera::lockMarker2(CViewport *viewport, const FVector &v) {
m4._col2 -= m4._col1;
m4._col4 -= m4._col1;
- m4._col3.normalize();
- m4._col2.normalize();
- m4._col4.normalize();
+ FMatrix m6 = _viewport.getOrientation();
+
+ double unused_scale=0.0;
+ if (!m4._col2.normalize(unused_scale) ||
+ !m4._col3.normalize(unused_scale) ||
+ !m4._col4.normalize(unused_scale) ) { // Do the normalizations, put the scale amount in unused_scale,
+ // but if any of the normalizations are unsuccessful, crash
+ assert(unused_scale);
+ }
+
m5.set(m4._col3, m4._col2, m4._col4);
FVector newPos = m4._col1;
- FMatrix m6 = _viewport.getOrientation();
- _mover->proc8(_viewport._position, newPos, m6, m5);
-
+
+ if (_viewport._position != newPos) {
+ // Only change view if positions are different
+ _mover->proc8(_viewport._position, newPos, m6, m5);
+ }
CStarVector *sv = new CStarVector(this, v);
_mover->setVector(sv);
}
void CStarCamera::lockMarker3(CViewport *viewport, const FVector &v) {
- if (_matrixRow != 1)
+ if (_star_lock_state != TWO_LOCKED)
return;
FMatrix newOr = viewport->getOrientation();
@@ -553,7 +594,11 @@ void CStarCamera::lockMarker3(CViewport *viewport, const FVector &v) {
FVector newPos = viewport->_position;
FVector oldPos = _viewport._position;
- _mover->proc8(oldPos, newPos, oldOr, newOr);
+ if (oldPos != newPos) {
+ // Only change view if positions are different
+ _mover->proc8(oldPos, newPos, oldOr, newOr);
+ }
+
CStarVector *sv = new CStarVector(this, v);
_mover->setVector(sv);
}
diff --git a/engines/titanic/star_control/star_camera.h b/engines/titanic/star_control/star_camera.h
index fa46eb38b1..9de786071e 100644
--- a/engines/titanic/star_control/star_camera.h
+++ b/engines/titanic/star_control/star_camera.h
@@ -23,16 +23,20 @@
#ifndef TITANIC_STAR_CAMERA_H
#define TITANIC_STAR_CAMERA_H
-#include "titanic/support/simple_file.h"
#include "titanic/star_control/fmatrix.h"
-#include "titanic/star_control/fpoint.h"
#include "titanic/star_control/base_stars.h"
#include "titanic/star_control/viewport.h"
-#include "titanic/star_control/camera_mover.h"
-#include "titanic/star_control/error_code.h"
namespace Titanic {
+class CCameraMover;
+class CErrorCode;
+class CNavigationInfo;
+class FPoint;
+class SimpleFile;
+
+enum StarLockState { ZERO_LOCKED=0, ONE_LOCKED=1, TWO_LOCKED=2, THREE_LOCKED=3 };
+
/**
* Implements a reference point from which the starmap can be viewed
*/
@@ -41,7 +45,7 @@ private:
static FMatrix *_priorOrientation;
static FMatrix *_newOrientation;
private:
- int _matrixRow;
+ StarLockState _star_lock_state;
FMatrix _matrix;
CCameraMover *_mover;
CViewport _viewport;
@@ -60,7 +64,7 @@ private:
/**
* Return whether the handler is locked
*/
- bool isLocked() { return _mover->isLocked(); }
+ bool isLocked();
public:
static void init();
static void deinit();
@@ -107,7 +111,7 @@ public:
virtual void increaseForwardSpeed();
/**
- * Decreases movement speed in backward direction
+ * Increases movement speed in backward direction
*/
virtual void increaseBackwardSpeed();
@@ -155,16 +159,24 @@ public:
*/
virtual void setViewportAngle(const FPoint &angles);
- virtual int getMatrixRow() const { return _matrixRow; }
+ /**
+ * How many stars are currently locked onto
+ */
+ virtual StarLockState getStarLockState() const { return _star_lock_state; }
/**
- * Adds the row for a locked in marker
+ * Adds the row for a locked in marker/star
* @remarks This can't be a pass-by-reference, since adding
* the vector for the star destroys the calling star vector
*/
- virtual bool adDAffineRow(const FVector v);
+ virtual bool addLockedStar(const FVector v);
- virtual bool removeMatrixRow();
+ /**
+ * Removes the most recent locked in marker/star
+ * @remarks This can't be a pass-by-reference, since adding
+ * the vector for the star destroys the calling star vector
+ */
+ virtual bool removeLockedStar();
virtual void proc36(double *v1, double *v2, double *v3, double *v4);
/**
diff --git a/engines/titanic/star_control/star_control.cpp b/engines/titanic/star_control/star_control.cpp
index 92cedc9513..743cfd0979 100644
--- a/engines/titanic/star_control/star_control.cpp
+++ b/engines/titanic/star_control/star_control.cpp
@@ -20,17 +20,18 @@
*
*/
-#include "titanic/support/screen_manager.h"
-#include "titanic/pet_control/pet_control.h"
#include "titanic/star_control/star_control.h"
#include "titanic/star_control/daffine.h"
-#include "titanic/star_control/error_code.h"
#include "titanic/star_control/fpose.h"
+#include "titanic/star_control/camera_mover.h"
#include "titanic/star_control/star_camera.h"
-#include "titanic/game_manager.h"
+#include "titanic/star_control/error_code.h"
#include "titanic/core/dont_save_file_item.h"
#include "titanic/core/project_item.h"
#include "titanic/core/view_item.h"
+#include "titanic/pet_control/pet_control.h"
+#include "titanic/support/screen_manager.h"
+#include "titanic/game_manager.h"
namespace Titanic {
diff --git a/engines/titanic/star_control/star_crosshairs.cpp b/engines/titanic/star_control/star_crosshairs.cpp
index 7227a18d03..61d11bf950 100644
--- a/engines/titanic/star_control/star_crosshairs.cpp
+++ b/engines/titanic/star_control/star_crosshairs.cpp
@@ -39,9 +39,15 @@ void CStarCrosshairs::selectStar(int index, CVideoSurface *surface,
// All the stars selected so far have been matched. Only allow
// a selection addition if not all three stars have been found
if (!isSolved()) {
- // Don't allow the most recent match to be re-selected
+ // Don't allow the most recent match or the one before
+ // it to be re-selected (while they are locked/matched)
if (_positions[index] != _entries[_entryIndex]) {
- surface->lock();
+ if (_entryIndex == 1) {//2 stars are matched
+ if (_positions[index] == _entries[_entryIndex-1]) {
+ return;
+ }
+ }
+ surface->lock();
// Draw crosshairs around the selected star
CSurfaceArea surfaceArea(surface);
@@ -63,6 +69,7 @@ void CStarCrosshairs::selectStar(int index, CVideoSurface *surface,
// So we allow the user to reselect it to remove the selection, or shift
// the selection to some other star
if (_positions[index] == _entries[_entryIndex]) {
+ // Player has selected the most recent star
// Remove the crosshairs for the previously selected star
surface->lock();
CSurfaceArea surfaceArea(surface);
@@ -76,6 +83,16 @@ void CStarCrosshairs::selectStar(int index, CVideoSurface *surface,
const CBaseStarEntry *starP = starField->getDataPtr(_positions[index]._index1);
markers->addStar(starP);
} else {
+ // Player has selected some other star other than the most recent
+ // Remove/Add it if it is not one of the other star(s) already matched
+
+ // Check that it is not a previously star and don't remove it if it is
+ for (int i=0;i<_entryIndex;i++) {
+ if (_positions[index] == _entries[i]) {
+ return;
+ }
+ }
+
// Erase the prior selection and draw the new one
surface->lock();
CSurfaceArea surfaceArea(surface);
diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp
index 9b27fa470e..578cc00898 100644
--- a/engines/titanic/star_control/star_view.cpp
+++ b/engines/titanic/star_control/star_view.cpp
@@ -20,13 +20,16 @@
*
*/
-#include "titanic/support/screen_manager.h"
#include "titanic/star_control/star_view.h"
+#include "titanic/star_control/camera_mover.h"
+#include "titanic/star_control/fvector.h"
#include "titanic/star_control/star_control.h"
#include "titanic/star_control/star_field.h"
+#include "titanic/star_control/error_code.h"
+#include "titanic/support/screen_manager.h"
+#include "titanic/support/simple_file.h"
#include "titanic/core/game_object.h"
#include "titanic/messages/pet_messages.h"
-#include "titanic/titanic.h"
namespace Titanic {
@@ -427,7 +430,7 @@ void CStarView::lockStar() {
void CStarView::unlockStar() {
if (_starField && !_showingPhoto) {
- _camera.removeMatrixRow();
+ _camera.removeLockedStar();
_starField->fn8(_photoSurface);
}
}
diff --git a/engines/titanic/star_control/star_view.h b/engines/titanic/star_control/star_view.h
index 204c02336c..b7d50969a6 100644
--- a/engines/titanic/star_control/star_view.h
+++ b/engines/titanic/star_control/star_view.h
@@ -23,18 +23,17 @@
#ifndef TITANIC_STAR_VIEW_H
#define TITANIC_STAR_VIEW_H
-#include "titanic/support/simple_file.h"
-#include "titanic/support/video_surface.h"
#include "titanic/star_control/star_camera.h"
#include "titanic/star_control/viewport.h"
#include "titanic/star_control/surface_fader.h"
-#include "titanic/star_control/error_code.h"
-#include "titanic/star_control/fvector.h"
namespace Titanic {
+class CErrorCode;
class CStarControl;
class CStarField;
+class CVideoSurface;
+class FVector;
class CStarView {
private:
diff --git a/engines/titanic/star_control/unmarked_auto_mover.cpp b/engines/titanic/star_control/unmarked_auto_mover.cpp
index 4f38f68a40..71063fa615 100644
--- a/engines/titanic/star_control/unmarked_auto_mover.cpp
+++ b/engines/titanic/star_control/unmarked_auto_mover.cpp
@@ -21,6 +21,8 @@
*/
#include "titanic/star_control/unmarked_auto_mover.h"
+#include "titanic/star_control/error_code.h"
+#include "common/array.h"
#include "common/textconsole.h"
namespace Titanic {
@@ -96,7 +98,12 @@ int CUnmarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orie
v2 = orientation._row3;
v3 = _destPos - pos;
- v3.normalize();
+
+ float unused_scale=0.0;
+ if (!v3.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
double val = orientation._row3._x * v3._x + orientation._row3._y * v3._y + orientation._row3._z * v3._z;
bool flag = false;
diff --git a/engines/titanic/star_control/unmarked_camera_mover.cpp b/engines/titanic/star_control/unmarked_camera_mover.cpp
index c92ed2bc11..ce42b3949d 100644
--- a/engines/titanic/star_control/unmarked_camera_mover.cpp
+++ b/engines/titanic/star_control/unmarked_camera_mover.cpp
@@ -21,10 +21,11 @@
*/
#include "titanic/star_control/unmarked_camera_mover.h"
-#include "titanic/star_control/daffine.h"
#include "titanic/star_control/dvector.h"
-#include "titanic/titanic.h"
+#include "titanic/star_control/daffine.h"
+#include "titanic/star_control/error_code.h"
#include "common/textconsole.h"
+#include "titanic/titanic.h"
namespace Titanic {