From b64a5bc3d22c47f917abd55fb7bcc6c3d7534f61 Mon Sep 17 00:00:00 2001 From: David Fioramonti Date: Tue, 29 Aug 2017 04:33:43 -0700 Subject: TITANIC: AutoMover and related refactoring --- engines/titanic/star_control/camera_auto_mover.cpp | 13 ++++++++----- engines/titanic/star_control/camera_auto_mover.h | 16 ++++++++++++---- engines/titanic/star_control/marked_auto_mover.cpp | 16 ++++++++-------- engines/titanic/star_control/marked_auto_mover.h | 8 ++++++-- engines/titanic/star_control/marked_camera_mover.cpp | 8 ++++---- engines/titanic/star_control/unmarked_auto_mover.cpp | 20 ++++++++++---------- engines/titanic/star_control/unmarked_auto_mover.h | 4 ++-- .../titanic/star_control/unmarked_camera_mover.cpp | 8 ++++---- 8 files changed, 54 insertions(+), 39 deletions(-) diff --git a/engines/titanic/star_control/camera_auto_mover.cpp b/engines/titanic/star_control/camera_auto_mover.cpp index 201cd9440a..9fe5e15e7e 100644 --- a/engines/titanic/star_control/camera_auto_mover.cpp +++ b/engines/titanic/star_control/camera_auto_mover.cpp @@ -41,7 +41,8 @@ CCameraAutoMover::CCameraAutoMover() : _srcPos(0.0, 1000000.0, 0.0) { _transitionPercentInc = 0.0; } -void CCameraAutoMover::proc2(const FVector &oldPos, const FVector &newPos, +// TODO: same as setPath also orientations are not used +void CCameraAutoMover::setPath2(const FVector &oldPos, const FVector &newPos, const FMatrix &oldOrientation, const FMatrix &newOrientation) { _srcPos = oldPos; _destPos = newPos; @@ -59,7 +60,8 @@ void CCameraAutoMover::proc2(const FVector &oldPos, const FVector &newPos, _field4C = 0; } -void CCameraAutoMover::proc3(const FMatrix &srcOrient, const FMatrix &destOrient) { +// TODO: same as proc2 also orientations are not used +void CCameraAutoMover::setOrientations(const FMatrix &srcOrient, const FMatrix &destOrient) { _srcPos.clear(); _destPos.clear(); _transitionPercent = 1.0; @@ -68,6 +70,7 @@ void CCameraAutoMover::proc3(const FMatrix &srcOrient, const FMatrix &destOrient _field34 = false; } +// TODO: same as setPath2 also orientations are not used void CCameraAutoMover::setPath(const FVector &srcV, const FVector &destV, const FMatrix &orientation) { _srcPos = srcV; _destPos = destV; @@ -93,8 +96,8 @@ void CCameraAutoMover::setPath(const FVector &srcV, const FVector &destV, const void CCameraAutoMover::calcSpeeds(int val1, int val2, float distance) { // Usually val1 and val2 are small where as distance can be large _field44 = val1; - _field4C = val1 + 2 * nMoverTransitions; // For _nMoverTransitions = 32 this second value was 64, - // should it always be x2 _nMoverTransitions? + _field4C = val1 + 2 * (nMoverTransitions - 1); // For _nMoverTransitions = 32 this second value was 62, + // should it always be x2 (_nMoverTransitions - 1)? _field38 = distance / (double)(val1 + val2 * 2); _field40 = nMoverTransitions-1; _field48 = nMoverTransitions-1; @@ -113,4 +116,4 @@ void CCameraAutoMover::calcSpeeds(int val1, int val2, float distance) { } } -} // End of namespace Titanic +} // End of namespace Titanic \ No newline at end of file diff --git a/engines/titanic/star_control/camera_auto_mover.h b/engines/titanic/star_control/camera_auto_mover.h index 210bd74091..25384632fa 100644 --- a/engines/titanic/star_control/camera_auto_mover.h +++ b/engines/titanic/star_control/camera_auto_mover.h @@ -32,7 +32,7 @@ namespace Titanic { class CErrorCode; class FMatrix; const int nMoverTransitions = 32; // The number of vector transitions when doing a mover change is fixed - +enum MoverState {NOT_ACTIVE=0,MOVING=1,DONE_MOVING=2}; /** * Base class for automatic movement of the starview camera */ @@ -59,11 +59,19 @@ public: CCameraAutoMover(); virtual ~CCameraAutoMover() {} - virtual void proc2(const FVector &oldPos, const FVector &newPos, + virtual void setPath2(const FVector &oldPos, const FVector &newPos, const FMatrix &oldOrientation, const FMatrix &newOrientation); - virtual void proc3(const FMatrix &srcOrient, const FMatrix &destOrient); + + /** + * Clear src and dest orientation and set some default values for other fields + */ + virtual void setOrientations(const FMatrix &srcOrient, const FMatrix &destOrient); virtual void setPath(const FVector &srcV, const FVector &destV, const FMatrix &orientation); - virtual int proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { return 2; } + + /** + * Applys speeds to the mover. More than one application is usually done for several transitions + */ + virtual MoverState move(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { return DONE_MOVING; } /** * Given a distance to cover, determines a bunch of speeds for a gradual transition * from one position to another (the mover). The speeds go from fast to slow diff --git a/engines/titanic/star_control/marked_auto_mover.cpp b/engines/titanic/star_control/marked_auto_mover.cpp index a154bfddf2..0787c48de3 100644 --- a/engines/titanic/star_control/marked_auto_mover.cpp +++ b/engines/titanic/star_control/marked_auto_mover.cpp @@ -26,9 +26,9 @@ namespace Titanic { -void CMarkedAutoMover::proc2(const FVector &oldPos, const FVector &newPos, +void CMarkedAutoMover::setPath2(const FVector &oldPos, const FVector &newPos, const FMatrix &oldOrientation, const FMatrix &newOrientation) { - CCameraAutoMover::proc2(oldPos, newPos, oldOrientation, newOrientation); + CCameraAutoMover::setPath2(oldPos, newPos, oldOrientation, newOrientation); double distance = _distance; _active = true; @@ -49,9 +49,9 @@ void CMarkedAutoMover::proc2(const FVector &oldPos, const FVector &newPos, } -int CMarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { +MoverState CMarkedAutoMover::move(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { if (!_active) - return 0; + return NOT_ACTIVE; _transitionPercent += _transitionPercentInc; orientation = _orientationChanger.getOrientation(_transitionPercent); @@ -64,14 +64,14 @@ int CMarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orient --_field40; errorCode.set(); - return 1; + return MOVING; } else if (_field44 > 0) { pos += _posDelta * _field38; getVectorOnPath(pos); --_field44; errorCode.set(); - return 1; + return MOVING; } else if (_field48 >= 0) { double speedVal = _speeds[nMoverTransitions - 1 - _field48]; pos += _posDelta * speedVal; @@ -79,10 +79,10 @@ int CMarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orient --_field48; errorCode.set(); - return 1; + return MOVING; } else { _active = false; - return 2; + return DONE_MOVING; } } diff --git a/engines/titanic/star_control/marked_auto_mover.h b/engines/titanic/star_control/marked_auto_mover.h index 5127496241..856df99c03 100644 --- a/engines/titanic/star_control/marked_auto_mover.h +++ b/engines/titanic/star_control/marked_auto_mover.h @@ -41,9 +41,13 @@ private: public: virtual ~CMarkedAutoMover() {} - virtual void proc2(const FVector &oldPos, const FVector &newPos, + virtual void setPath2(const FVector &oldPos, const FVector &newPos, const FMatrix &oldOrientation, const FMatrix &newOrientation); - virtual int proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orientation); + + /** + * Applys speeds to the mover. More than one application is usually done for several transitions + */ + virtual MoverState move(CErrorCode &errorCode, FVector &pos, FMatrix &orientation); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/marked_camera_mover.cpp b/engines/titanic/star_control/marked_camera_mover.cpp index 66549c5859..ff9c055abb 100644 --- a/engines/titanic/star_control/marked_camera_mover.cpp +++ b/engines/titanic/star_control/marked_camera_mover.cpp @@ -38,17 +38,17 @@ void CMarkedCameraMover::transitionBetweenPosOrients(const FVector &oldPos, cons if (isLocked()) decLockCount(); - _autoMover.proc2(oldPos, newPos, oldOrientation, newOrientation); + _autoMover.setPath2(oldPos, newPos, oldOrientation, newOrientation); incLockCount(); } void CMarkedCameraMover::updatePosition(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { if (_autoMover.isActive()) { decLockCount(); - int val = _autoMover.proc5(errorCode, pos, orientation); - if (val == 1) + MoverState moveState = _autoMover.move(errorCode, pos, orientation); + if (moveState == MOVING) incLockCount(); - if (val == 2) { + if (moveState == DONE_MOVING) { stop(); if (_starVector) _starVector->apply(); diff --git a/engines/titanic/star_control/unmarked_auto_mover.cpp b/engines/titanic/star_control/unmarked_auto_mover.cpp index 1a5d886796..c84fbbab00 100644 --- a/engines/titanic/star_control/unmarked_auto_mover.cpp +++ b/engines/titanic/star_control/unmarked_auto_mover.cpp @@ -27,8 +27,8 @@ namespace Titanic { -void CUnmarkedAutoMover::proc3(const FMatrix &srcOrient, const FMatrix &destOrient) { - CCameraAutoMover::proc3(srcOrient, destOrient); +void CUnmarkedAutoMover::setOrientations(const FMatrix &srcOrient, const FMatrix &destOrient) { + CCameraAutoMover::setOrientations(srcOrient, destOrient); _orientationChanger.load(srcOrient, destOrient); _transitionPercentInc = 0.1; _transitionPercent = 0.0; @@ -75,11 +75,11 @@ void CUnmarkedAutoMover::setPath(const FVector &srcV, const FVector &destV, cons } } -int CUnmarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { +MoverState CUnmarkedAutoMover::move(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { FVector v1, v2, v3, v4; if (!_active) - return 0; + return NOT_ACTIVE; // Firstly we have to do a transition of the camera orientation from // it's current position to one where the destination star is centered @@ -87,13 +87,13 @@ int CUnmarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orie _transitionPercent += _transitionPercentInc; orientation = _orientationChanger.getOrientation(_transitionPercent); errorCode.set(); - return 1; + return MOVING; } // From here on, we handle the movement to the given destination if (!_field34) { _active = false; - return 2; + return DONE_MOVING; } v2 = orientation._row3; @@ -133,7 +133,7 @@ int CUnmarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orie --_field40; errorCode.set(); - return 1; + return MOVING; } if (_field44 > 0) { @@ -145,7 +145,7 @@ int CUnmarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orie --_field44; errorCode.set(); - return 1; + return MOVING; } if (_field48 >= 0) { @@ -159,11 +159,11 @@ int CUnmarkedAutoMover::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orie --_field48; errorCode.set(); - return 1; + return MOVING; } _active = false; - return 2; + return DONE_MOVING; } } // End of namespace Titanic diff --git a/engines/titanic/star_control/unmarked_auto_mover.h b/engines/titanic/star_control/unmarked_auto_mover.h index fa1aa95140..b7fb4e3c66 100644 --- a/engines/titanic/star_control/unmarked_auto_mover.h +++ b/engines/titanic/star_control/unmarked_auto_mover.h @@ -34,14 +34,14 @@ class CUnmarkedAutoMover : public CCameraAutoMover { public: virtual ~CUnmarkedAutoMover() {} - virtual void proc3(const FMatrix &srcOrient, const FMatrix &destOrient); + virtual void setOrientations(const FMatrix &srcOrient, const FMatrix &destOrient); /** * Sets the path to animate movement between */ virtual void setPath(const FVector &srcV, const FVector &destV, const FMatrix &orientation); - virtual int proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orientation); + virtual MoverState move(CErrorCode &errorCode, FVector &pos, FMatrix &orientation); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/unmarked_camera_mover.cpp b/engines/titanic/star_control/unmarked_camera_mover.cpp index aa896710f2..c1459ec372 100644 --- a/engines/titanic/star_control/unmarked_camera_mover.cpp +++ b/engines/titanic/star_control/unmarked_camera_mover.cpp @@ -55,17 +55,17 @@ void CUnmarkedCameraMover::transitionBetweenOrientations(const FVector &v1, cons DAffine matrix1 = vector2.getFrameTransform(vector1); DAffine matrix2 = matrix1.compose(m); - _autoMover.proc3(m, matrix2); + _autoMover.setOrientations(m, matrix2); incLockCount(); } void CUnmarkedCameraMover::updatePosition(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { if (_autoMover.isActive()) { decLockCount(); - int val = _autoMover.proc5(errorCode, pos, orientation); - if (val == 1) + MoverState moverState = _autoMover.move(errorCode, pos, orientation); + if (moverState == MOVING) incLockCount(); - if (val == 2) { + if (moverState == DONE_MOVING) { stop(); if (_starVector) _starVector->apply(); -- cgit v1.2.3