mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-14 07:48:58 +00:00
TITANIC: Cleanup of CStarView
This commit is contained in:
parent
e580ff30a9
commit
75739abe01
@ -69,12 +69,14 @@ public:
|
||||
* 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(float &);
|
||||
bool normalize(float &hyp);
|
||||
|
||||
void normalize() {
|
||||
float hyp;
|
||||
bool result = normalize(hyp);
|
||||
assert(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the current vector and a passed one together, normalizes them,
|
||||
|
@ -219,7 +219,6 @@ StarColor CStarCamera::getStarColor() const {
|
||||
return _viewport._starColor;
|
||||
}
|
||||
|
||||
// Similar to CViewport::fn17/fn18
|
||||
FVector CStarCamera::getRelativePos(int index, const FVector &src) {
|
||||
FVector dest;
|
||||
|
||||
|
@ -69,7 +69,7 @@ void CStarControl::load(SimpleFile *file) {
|
||||
error("There's no screen manager during loading");
|
||||
|
||||
_view.setup(screenManager, &_starField, this);
|
||||
_view.reset();
|
||||
_view.takeCurrentHomePhoto();
|
||||
|
||||
_enabled = true;
|
||||
}
|
||||
@ -168,7 +168,7 @@ void CStarControl::doAction(StarControlAction action) {
|
||||
if (view) {
|
||||
detach();
|
||||
addUnder(view);
|
||||
_view.fn2();
|
||||
_view.resetView();
|
||||
_view.triggerFade(true);
|
||||
_visible = true;
|
||||
}
|
||||
@ -235,7 +235,7 @@ void CStarControl::doAction(StarControlAction action) {
|
||||
break;
|
||||
|
||||
case STAR_SET_REFERENCE: {
|
||||
_view.setHasReference();
|
||||
_view.takeCurrentHomePhoto();
|
||||
CPetControl *pet = getPetControl();
|
||||
if (pet)
|
||||
pet->starsSetReference();
|
||||
|
@ -149,7 +149,7 @@ bool CStarCrosshairs::fn1(CStarField *starField, CSurfaceArea *surfaceArea, CSta
|
||||
}
|
||||
}
|
||||
|
||||
void CStarCrosshairs::fn2(CVideoSurface *surface, CStarField *starField, CStarMarkers *markers) {
|
||||
void CStarCrosshairs::decMatches(CVideoSurface *surface, CStarField *starField, CStarMarkers *markers) {
|
||||
if (_matchIndex <= -1) {
|
||||
if (_entryIndex > -1) {
|
||||
drawEntry(_entryIndex, surface, starField, markers);
|
||||
|
@ -79,13 +79,17 @@ public:
|
||||
void draw(CSurfaceArea *surfaceArea);
|
||||
|
||||
bool fn1(CStarField *starField, CSurfaceArea *surfaceArea, CStarCamera *camera);
|
||||
void fn2(CVideoSurface *surface, CStarField *starField, CStarMarkers *markers);
|
||||
|
||||
/**
|
||||
* Increments the index for the number of matches
|
||||
* Increments the number of matches
|
||||
*/
|
||||
void incMatches();
|
||||
|
||||
/**
|
||||
* Decrements the number of matches
|
||||
*/
|
||||
void decMatches(CVideoSurface *surface, CStarField *starField, CStarMarkers *markers);
|
||||
|
||||
/**
|
||||
* Draw the crosshairs for a given star
|
||||
*/
|
||||
|
@ -178,20 +178,20 @@ void CStarField::drawBox(CSurfaceArea *surfaceArea) {
|
||||
}
|
||||
|
||||
void CStarField::fn4(CSurfaceArea *surfaceArea, CStarCamera *camera) {
|
||||
FVector v1, v2, v3;
|
||||
FVector screenCoord, worldCoord, photoPos;
|
||||
_closeToMarker = false;
|
||||
|
||||
if (_mode == MODE_STARFIELD) {
|
||||
if (fn5(surfaceArea, camera, v1, v2, v3) > -1.0) {
|
||||
if (lockDistance(surfaceArea, camera, screenCoord, worldCoord, photoPos) > -1.0) {
|
||||
surfaceArea->_pixel = 0xA0A0;
|
||||
surfaceArea->setColorFromPixel();
|
||||
surfaceArea->drawLine(FRect(v1._x, v1._y, v3._x, v3._y));
|
||||
surfaceArea->drawLine(FRect(screenCoord._x, screenCoord._y, photoPos._x, photoPos._y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double CStarField::fn5(CSurfaceArea *surfaceArea, CStarCamera *camera,
|
||||
FVector &v1, FVector &v2, FVector &v3) {
|
||||
double CStarField::lockDistance(CSurfaceArea *surfaceArea, CStarCamera *camera,
|
||||
FVector &screenCoord, FVector &worldCoord, FVector &photoPos) {
|
||||
if (_crosshairs.isEmpty())
|
||||
// No crosshairs selection yet
|
||||
return -1.0;
|
||||
@ -200,24 +200,24 @@ double CStarField::fn5(CSurfaceArea *surfaceArea, CStarCamera *camera,
|
||||
return -1.0;
|
||||
|
||||
const CBaseStarEntry *dataP = _markers.getDataPtr(_crosshairs._entryIndex);
|
||||
v2 = dataP->_position;
|
||||
FVector tv = camera->getRelativePosNoCentering(2, v2); // First argument is not getting used in CViewport::fn16
|
||||
worldCoord = dataP->_position;
|
||||
FVector tv = camera->getRelativePosNoCentering(2, worldCoord); // First argument is not getting used in CViewport::fn16
|
||||
|
||||
if (camera->getThreshold() >= tv._z)
|
||||
return -1.0;
|
||||
|
||||
tv = camera->getRelativePos(2, tv);
|
||||
|
||||
v1 = FVector(tv._x + surfaceArea->_centroid._x,
|
||||
screenCoord = FVector(tv._x + surfaceArea->_centroid._x,
|
||||
tv._y + surfaceArea->_centroid._y, tv._z);
|
||||
FPoint pt = _crosshairs.getPosition();
|
||||
v3 = FVector(pt._x, pt._y, 1.0);
|
||||
photoPos = FVector(pt._x, pt._y, 1.0);
|
||||
|
||||
double incr = (v1._x - pt._x) * (v1._x - pt._x);
|
||||
double incr = (screenCoord._x - pt._x) * (screenCoord._x - pt._x);
|
||||
if (incr > 3600.0)
|
||||
return -1.0;
|
||||
|
||||
incr += (v1._y - pt._y) * (v1._y - pt._y);
|
||||
incr += (screenCoord._y - pt._y) * (screenCoord._y - pt._y);
|
||||
if (incr > 3600.0)
|
||||
return -1.0;
|
||||
|
||||
@ -230,13 +230,13 @@ void CStarField::fn6(CVideoSurface *surface, CStarCamera *camera) {
|
||||
_crosshairs.fn1(this, &surfaceArea, camera);
|
||||
}
|
||||
|
||||
void CStarField::incMatches() {
|
||||
void CStarField::incLockLevel() {
|
||||
_crosshairs.incMatches();
|
||||
setSolved();
|
||||
}
|
||||
|
||||
void CStarField::fn8(CVideoSurface *surface) {
|
||||
_crosshairs.fn2(surface, this, &_markers);
|
||||
void CStarField::decLockLevel(CVideoSurface *surface) {
|
||||
_crosshairs.decMatches(surface, this, &_markers);
|
||||
setSolved();
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@
|
||||
|
||||
namespace Titanic {
|
||||
|
||||
#define STAR_SCALE 1024.0F
|
||||
|
||||
class CStarField : public CStarFieldBase {
|
||||
private:
|
||||
CStarMarkers _markers;
|
||||
@ -141,18 +143,26 @@ public:
|
||||
}
|
||||
|
||||
void fn1(CErrorCode *errorCode);
|
||||
double fn5(CSurfaceArea *surfaceArea, CStarCamera *camera,
|
||||
FVector &v1, FVector &v2, FVector &v3);
|
||||
|
||||
/**
|
||||
* Gets the lock distance to a star
|
||||
*/
|
||||
double lockDistance(CSurfaceArea *surfaceArea, CStarCamera *camera,
|
||||
FVector &screenCoord, FVector &worldCoord, FVector &photoPos);
|
||||
|
||||
void fn6(CVideoSurface *surface, CStarCamera *camera);
|
||||
|
||||
/**
|
||||
* Increments the number of matched markers
|
||||
*/
|
||||
void incMatches();
|
||||
void incLockLevel();
|
||||
|
||||
void fn8(CVideoSurface *surface);
|
||||
/**
|
||||
* Decrements the number of matched markers
|
||||
*/
|
||||
void decLockLevel(CVideoSurface *surface);
|
||||
|
||||
void fn9() { _starCloseup.fn1(); }
|
||||
void ToggleSolarRendering() { _starCloseup.fn1(); }
|
||||
|
||||
/**
|
||||
* Called when the starfield is clicked
|
||||
|
@ -31,11 +31,12 @@
|
||||
#include "titanic/core/game_object.h"
|
||||
#include "titanic/messages/pet_messages.h"
|
||||
#include "titanic/pet_control/pet_control.h"
|
||||
#include "titanic/titanic.h"
|
||||
|
||||
namespace Titanic {
|
||||
|
||||
CStarView::CStarView() : _camera((const CNavigationInfo *)nullptr), _owner(nullptr),
|
||||
_starField(nullptr), _videoSurface(nullptr), _hasReference(0),
|
||||
_starField(nullptr), _videoSurface(nullptr), _lensValid(0),
|
||||
_photoSurface(nullptr), _homePhotoMask(nullptr),
|
||||
_stereoPair(false), _showingPhoto(false) {
|
||||
CNavigationInfo data = { 0, 0, 100000.0, 0, 20.0, 1.0, 1.0, 1.0 };
|
||||
@ -52,8 +53,8 @@ void CStarView::load(SimpleFile *file, int param) {
|
||||
if (!param) {
|
||||
_camera.load(file, param);
|
||||
|
||||
_hasReference = file->readNumber();
|
||||
if (_hasReference)
|
||||
_lensValid = file->readNumber();
|
||||
if (_lensValid)
|
||||
_photoViewport.load(file, 0);
|
||||
|
||||
_stereoPair = file->readNumber();
|
||||
@ -64,8 +65,8 @@ void CStarView::load(SimpleFile *file, int param) {
|
||||
void CStarView::save(SimpleFile *file, int indent) {
|
||||
_camera.save(file, indent);
|
||||
|
||||
file->writeNumberLine(_hasReference, indent);
|
||||
if (_hasReference)
|
||||
file->writeNumberLine(_lensValid, indent);
|
||||
if (_lensValid)
|
||||
_photoViewport.save(file, indent);
|
||||
|
||||
file->writeNumberLine(_stereoPair, indent);
|
||||
@ -77,10 +78,10 @@ void CStarView::setup(CScreenManager *screenManager, CStarField *starField, CSta
|
||||
_owner = starControl;
|
||||
}
|
||||
|
||||
void CStarView::reset() {
|
||||
if (_hasReference) {
|
||||
void CStarView::takeCurrentHomePhoto() {
|
||||
if (_lensValid) {
|
||||
CStarCamera camera(&_photoViewport);
|
||||
fn18(&camera);
|
||||
takeHomePhotoHelper(&camera);
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,7 +279,7 @@ bool CStarView::updateCamera() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void CStarView::fn2() {
|
||||
void CStarView::resetView() {
|
||||
if (!_videoSurface) {
|
||||
CScreenManager *scrManager = CScreenManager::setCurrent();
|
||||
if (scrManager)
|
||||
@ -286,7 +287,7 @@ void CStarView::fn2() {
|
||||
|
||||
if (_videoSurface) {
|
||||
stereoPairOn();
|
||||
fn19(244);
|
||||
viewRequiredStar(244);
|
||||
draw(scrManager);
|
||||
}
|
||||
}
|
||||
@ -327,7 +328,7 @@ void CStarView::viewRandomStar() {
|
||||
}
|
||||
}
|
||||
|
||||
void CStarView::fn19(int index) {
|
||||
void CStarView::viewRequiredStar(int index) {
|
||||
const CBaseStarEntry *star = _starField->getStar(index);
|
||||
if (star) {
|
||||
FVector pos, orientation;
|
||||
@ -364,7 +365,7 @@ void CStarView::toggleHomePhoto() {
|
||||
|
||||
void CStarView::toggleSolarRendering() {
|
||||
if (_starField)
|
||||
_starField->fn9();
|
||||
_starField->ToggleSolarRendering();
|
||||
}
|
||||
|
||||
void CStarView::TogglePosFrame() {
|
||||
@ -384,7 +385,7 @@ void CStarView::stereoPairOff() {
|
||||
_camera.setFields(MODE_STARFIELD, 0.0);
|
||||
}
|
||||
|
||||
void CStarView::setHasReference() {
|
||||
void CStarView::takeHomePhoto() {
|
||||
FVector pos, orientation;
|
||||
getRandomPhotoViewpoint(pos, orientation);
|
||||
|
||||
@ -393,42 +394,44 @@ void CStarView::setHasReference() {
|
||||
_stereoPair = false;
|
||||
_photoViewport.changeStarColorPixel(MODE_PHOTO, 0.0);
|
||||
_photoViewport.changeStarColorPixel(MODE_STARFIELD, 0.0);
|
||||
_hasReference = true;
|
||||
reset();
|
||||
|
||||
_lensValid = true;
|
||||
takeCurrentHomePhoto();
|
||||
_stereoPair = true;
|
||||
}
|
||||
|
||||
void CStarView::lockStar() {
|
||||
if (_starField && !_showingPhoto) {
|
||||
CSurfaceArea surfaceArea(_videoSurface);
|
||||
FVector v1, v2, v3;
|
||||
double val = _starField->fn5(&surfaceArea, &_camera, v1, v2, v3);
|
||||
FVector screenCoord, worldCoord, photoPos;
|
||||
double dist = _starField->lockDistance(&surfaceArea, &_camera,
|
||||
screenCoord, worldCoord, photoPos);
|
||||
bool lockSuccess = false;
|
||||
|
||||
if (val > -1.0) {
|
||||
v1 -= surfaceArea._centroid;
|
||||
v3 -= surfaceArea._centroid;
|
||||
if (dist > -1.0) {
|
||||
screenCoord -= surfaceArea._centroid;
|
||||
photoPos -= surfaceArea._centroid;
|
||||
|
||||
switch (_starField->getMatchedIndex()) {
|
||||
case -1:
|
||||
// First star match
|
||||
lockSuccess = _camera.lockMarker1(v1, v2, v3);
|
||||
lockSuccess = _camera.lockMarker1(screenCoord, worldCoord, photoPos);
|
||||
assert(lockSuccess); // lockMarker1 should always succeed
|
||||
_starField->incMatches();
|
||||
_starField->incLockLevel();
|
||||
break;
|
||||
|
||||
case 0:
|
||||
// Second star match
|
||||
lockSuccess = _camera.lockMarker2(&_photoViewport, v2);
|
||||
lockSuccess = _camera.lockMarker2(&_photoViewport, worldCoord);
|
||||
if (lockSuccess) // lockMarker2 may have issues
|
||||
_starField->incMatches();
|
||||
_starField->incLockLevel();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
// Third star match
|
||||
lockSuccess = _camera.lockMarker3(&_photoViewport, v2);
|
||||
lockSuccess = _camera.lockMarker3(&_photoViewport, worldCoord);
|
||||
assert(lockSuccess); // lockMarker3 should always succeed
|
||||
_starField->incMatches();
|
||||
_starField->incLockLevel();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -441,11 +444,11 @@ void CStarView::lockStar() {
|
||||
void CStarView::unlockStar() {
|
||||
if (_starField && !_showingPhoto && _camera.isNotInLockingProcess()) {
|
||||
_camera.removeLockedStar();
|
||||
_starField->fn8(_photoSurface);
|
||||
_starField->decLockLevel(_photoSurface);
|
||||
}
|
||||
}
|
||||
|
||||
void CStarView::fn18(CStarCamera *camera) {
|
||||
void CStarView::takeHomePhotoHelper(CStarCamera *camera) {
|
||||
if (_starField) {
|
||||
if (!_photoSurface) {
|
||||
CScreenManager *scrManager = CScreenManager::setCurrent();
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
CStarField *_starField;
|
||||
CVideoSurface *_videoSurface;
|
||||
CStarCamera _camera;
|
||||
bool _hasReference;
|
||||
bool _lensValid;
|
||||
CViewport _photoViewport;
|
||||
CSurfaceFader _fader;
|
||||
CVideoSurface *_photoSurface;
|
||||
@ -51,8 +51,15 @@ private:
|
||||
bool _stereoPair;
|
||||
bool _showingPhoto;
|
||||
private:
|
||||
void fn18(CStarCamera *camera);
|
||||
void fn19(int v);
|
||||
/**
|
||||
* Take a photograph of a view specified by the camera
|
||||
*/
|
||||
void takeHomePhotoHelper(CStarCamera *camera);
|
||||
|
||||
/**
|
||||
* View a specified star
|
||||
*/
|
||||
void viewRequiredStar(int index);
|
||||
|
||||
/**
|
||||
* Gets a random position and orientation
|
||||
@ -88,7 +95,10 @@ public:
|
||||
*/
|
||||
void setup(CScreenManager *screenManager, CStarField *starField, CStarControl *starControl);
|
||||
|
||||
void reset();
|
||||
/**
|
||||
* Take a photograph of a view specified by the current home photo lens
|
||||
*/
|
||||
void takeCurrentHomePhoto();
|
||||
|
||||
/**
|
||||
* Allows the item to draw itself
|
||||
@ -125,7 +135,11 @@ public:
|
||||
*/
|
||||
void starDestinationSet();
|
||||
|
||||
void fn2();
|
||||
/**
|
||||
* Reset the starfield view
|
||||
*/
|
||||
void resetView();
|
||||
|
||||
void triggerFade(bool fadeIn);
|
||||
|
||||
/**
|
||||
@ -189,9 +203,10 @@ public:
|
||||
void stereoPairOff();
|
||||
|
||||
/**
|
||||
* Called when the photograph is used on the navigation computer
|
||||
* Called when the photograph is used on the navigation computer,
|
||||
* takes a photograph of the current view, writing it to the home photo surface
|
||||
*/
|
||||
void setHasReference();
|
||||
void takeHomePhoto();
|
||||
|
||||
/**
|
||||
* Handles locking in a star
|
||||
@ -206,4 +221,4 @@ public:
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
||||
#endif /* TITANIC_STAR_RENDERER_H */
|
||||
#endif /* TITANIC_STAR_VIEW_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user