1
0
Fork 0

Set viewer-[lon|lat]-deg on initial View bind

Previously /sim/current-view/viewer-[lon|lat]-deg were set to
(0,0) when a view was bind() for the first time by the view
manager.  This cause the scenery tile cache to immediately clear
and all scenery to be reloaded.

Now these values are set correctly the first time the view
bind() is called, so the cache behaves correctly.

Also fixed what looks like a possible bug on code read where
the tiles of the current view had a very short expiry time
set.  Seems wrong.
This commit is contained in:
Stuart Buchanan 2020-05-10 14:17:40 +01:00
parent 61ed9efac8
commit f5b469aee0
3 changed files with 29 additions and 25 deletions

View file

@ -131,7 +131,7 @@ long TileCache::get_first_expired_tile() const
{ {
const_tile_map_iterator current = tile_cache.begin(); const_tile_map_iterator current = tile_cache.begin();
const_tile_map_iterator end = tile_cache.end(); const_tile_map_iterator end = tile_cache.end();
for ( ; current != end; ++current ) { for ( ; current != end; ++current ) {
TileEntry *e = current->second; TileEntry *e = current->second;
if (!e->is_current_view() && e->is_expired(current_time)) if (!e->is_current_view() && e->is_expired(current_time))
@ -139,7 +139,7 @@ long TileCache::get_first_expired_tile() const
return current->first; return current->first;
} }
} }
return -1; // no expired tile found return -1; // no expired tile found
} }
@ -215,7 +215,7 @@ void TileCache::request_tile(TileEntry* t,float priority,bool current_view,doubl
if (current_view) if (current_view)
{ {
t->update_time_expired( current_time ); t->update_time_expired( current_time + request_time );
t->set_current_view( true ); t->set_current_view( true );
} }
else else

View file

@ -67,9 +67,9 @@ private:
* to outermost sequence. * to outermost sequence.
*/ */
float _priority; float _priority;
/** Flag indicating if tile belongs to current view. */ /** Flag indicating if tile belongs to current view. */
bool _current_view; bool _current_view;
/** Time when tile expires. */ /** Time when tile expires. */
double _time_expired; double _time_expired;
public: public:
@ -129,7 +129,7 @@ public:
inline bool is_current_view() const { return _current_view; } inline bool is_current_view() const { return _current_view; }
/** /**
* Return true if the tile entry is still needed, otherwise return false * Return false if the tile entry is still needed, otherwise return true
* indicating that the tile is no longer in active use. * indicating that the tile is no longer in active use.
*/ */
inline bool is_expired(double current_time) const { return (_current_view) ? false : (current_time > _time_expired); } inline bool is_expired(double current_time) const { return (_current_view) ? false : (current_time > _time_expired); }
@ -142,4 +142,4 @@ public:
} }
}; };
#endif // _TILEENTRY_HXX #endif // _TILEENTRY_HXX

View file

@ -87,7 +87,7 @@ View::View( ViewType Type, bool from_model, int from_model_index,
_internal = internal; _internal = internal;
_lookat_agl = lookat_agl; _lookat_agl = lookat_agl;
_view_index = view_index; _view_index = view_index;
_dampFactor = SGVec3d::zeros(); _dampFactor = SGVec3d::zeros();
_dampOutput = SGVec3d::zeros(); _dampOutput = SGVec3d::zeros();
_dampTarget = SGVec3d::zeros(); _dampTarget = SGVec3d::zeros();
@ -122,7 +122,7 @@ View::View( ViewType Type, bool from_model, int from_model_index,
} }
_configFOV_deg = _fov_deg; _configFOV_deg = _fov_deg;
_fov_user_deg = _fov_deg; _fov_user_deg = _fov_deg;
_aspect_ratio_multiplier = aspect_ratio_multiplier; _aspect_ratio_multiplier = aspect_ratio_multiplier;
@ -145,7 +145,7 @@ View* View::createFromProperties(SGPropertyNode_ptr config, int view_index)
// find out if this is an internal view (e.g. in cockpit, low near plane) // find out if this is an internal view (e.g. in cockpit, low near plane)
// FIXME : should be a child of config // FIXME : should be a child of config
bool internal = config->getParent()->getBoolValue("internal", false); bool internal = config->getParent()->getBoolValue("internal", false);
std::string root = config->getPath(); std::string root = config->getPath();
// Will typically be /sim/view[]/config. // Will typically be /sim/view[]/config.
@ -229,6 +229,10 @@ View::init ()
void void
View::bind () View::bind ()
{ {
// Perform an immediate recalculation to ensure that the data for the
// viewer position is correct.
recalc();
_tiedProperties.setRoot(fgGetNode("/sim/current-view", true)); _tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
_tiedProperties.Tie("heading-offset-deg", this, _tiedProperties.Tie("heading-offset-deg", this,
&View::getHeadingOffset_deg, &View::getHeadingOffset_deg,
@ -668,7 +672,7 @@ static void getAircraftPositionOrientation(
ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/position/latitude-deg)"), ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/position/latitude-deg)"),
ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/position/altitude-ft)") ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/position/altitude-ft)")
); );
head = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/orientation/true-heading-deg)"); head = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/orientation/true-heading-deg)");
pitch = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/orientation/pitch-deg)"); pitch = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/orientation/pitch-deg)");
roll = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/orientation/roll-deg)"); roll = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/orientation/roll-deg)");
@ -688,7 +692,7 @@ root:
/ai/models/multiplayer[]. /ai/models/multiplayer[].
view_index: view_index:
The view number. We will look in .../sim/view[view_index]. The view number. We will look in .../sim/view[view_index].
infix: infix:
We look at .../view[view_index]/config/<infix>x-offset-m etc. Views appear We look at .../view[view_index]/config/<infix>x-offset-m etc. Views appear
to use 'z-offset-m' to define the location of pilot's eyes in cockpit to use 'z-offset-m' to define the location of pilot's eyes in cockpit
view, but 'target-z-offset' when defining viewpoint of other views such as view, but 'target-z-offset' when defining viewpoint of other views such as
@ -745,7 +749,7 @@ static void getViewOffsets(
offset_m += offset; offset_m += offset;
} }
} }
// recalculate for LookFrom view type... // recalculate for LookFrom view type...
// E.g. Cockpit View and Tower View Look From. // E.g. Cockpit View and Tower View Look From.
void void
@ -754,7 +758,7 @@ View::recalcLookFrom ()
double head; double head;
double pitch; double pitch;
double roll; double roll;
if (_from_model ) { if (_from_model ) {
/* Look up aircraft position; this works for user's aircaft or multiplayer /* Look up aircraft position; this works for user's aircaft or multiplayer
aircraft. */ aircraft. */
@ -762,11 +766,11 @@ View::recalcLookFrom ()
} }
else { else {
/* Tower View Look From. /* Tower View Look From.
<_config> will be /sim/view[4]/config, so <_config>/eye-lon-deg-path <_config> will be /sim/view[4]/config, so <_config>/eye-lon-deg-path
will be /sim/view[4]/config/eye-lon-deg-path which will contain will be /sim/view[4]/config/eye-lon-deg-path which will contain
/sim/tower/longitude-deg (see fgdata:defaults.xml). /sim/tower/longitude-deg (see fgdata:defaults.xml).
[Might be nice to make a 'TowerView Look From Multiplayer' that uses the [Might be nice to make a 'TowerView Look From Multiplayer' that uses the
tower that is nearest to a particular multiplayer aircraft. We'd end up tower that is nearest to a particular multiplayer aircraft. We'd end up
looking at /ai/models/multiplayer[]/sim/tower/longitude-deg, so we'd need looking at /ai/models/multiplayer[]/sim/tower/longitude-deg, so we'd need
@ -781,12 +785,12 @@ View::recalcLookFrom ()
pitch = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-pitch-deg-path))"); pitch = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-pitch-deg-path))");
roll = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-roll-deg-path))"); roll = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-roll-deg-path))");
} }
/* Find the offset of the view position relative to the aircraft model's /* Find the offset of the view position relative to the aircraft model's
origin. */ origin. */
SGVec3d offset_m; SGVec3d offset_m;
getViewOffsets(false /*target_infix*/, &_adjust_offset_m, offset_m); getViewOffsets(false /*target_infix*/, &_adjust_offset_m, offset_m);
set_fov(_fov_user_deg); set_fov(_fov_user_deg);
// The rotation rotating from the earth centerd frame to // The rotation rotating from the earth centerd frame to
@ -811,7 +815,7 @@ View::recalcLookFrom ()
// This is rotates the x-forward, y-right, z-down coordinate system the where // This is rotates the x-forward, y-right, z-down coordinate system the where
// simulation runs into the OpenGL camera system with x-right, y-up, z-back. // simulation runs into the OpenGL camera system with x-right, y-up, z-back.
SGQuatd q(-0.5, -0.5, 0.5, 0.5); SGQuatd q(-0.5, -0.5, 0.5, 0.5);
_absolute_view_pos = position + (ec2body*q).backTransform(offset_m); _absolute_view_pos = position + (ec2body*q).backTransform(offset_m);
mViewOrientation = ec2body*mViewOffsetOr*q; mViewOrientation = ec2body*mViewOffsetOr*q;
} }
@ -906,7 +910,7 @@ void View::handleAGL()
_lookat_agl_damping.reset(relative_height_ground_); _lookat_agl_damping.reset(relative_height_ground_);
relative_height_ground = relative_height_ground_; relative_height_ground = relative_height_ground_;
} }
/* Apply scaling from user field of view setting, altering only /* Apply scaling from user field of view setting, altering only
relative_height_ground so that the aircraft is always in view. */ relative_height_ground so that the aircraft is always in view. */
{ {
@ -973,14 +977,14 @@ View::recalcLookAt ()
_target_roll_deg _target_roll_deg
); );
} }
double eye_heading = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-heading-deg-path))"); double eye_heading = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-heading-deg-path))");
double eye_roll = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-roll-deg-path))"); double eye_roll = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-roll-deg-path))");
double eye_pitch = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-pitch-deg-path))"); double eye_pitch = ViewPropertyEvaluator::getDoubleValue("((/sim/view[(/sim/current-view/view-number-raw)]/config/root)/(/sim/view[(/sim/current-view/view-number-raw)]/config/eye-pitch-deg-path))");
setDampTarget(eye_roll, eye_pitch, eye_heading); setDampTarget(eye_roll, eye_pitch, eye_heading);
getDampOutput(eye_roll, eye_pitch, eye_heading); getDampOutput(eye_roll, eye_pitch, eye_heading);
SGQuatd geodTargetOr = SGQuatd::fromYawPitchRollDeg(_target_heading_deg, SGQuatd geodTargetOr = SGQuatd::fromYawPitchRollDeg(_target_heading_deg,
_target_pitch_deg, _target_pitch_deg,
_target_roll_deg); _target_roll_deg);
@ -993,7 +997,7 @@ View::recalcLookAt ()
target_pos_off.x(), target_pos_off.x(),
-target_pos_off.y() -target_pos_off.y()
); );
target_pos_off = (geodTargetHlOr*geodTargetOr).backTransform(target_pos_off); target_pos_off = (geodTargetHlOr*geodTargetOr).backTransform(target_pos_off);
SGVec3d targetCart = SGVec3d::fromGeod(_target); SGVec3d targetCart = SGVec3d::fromGeod(_target);
SGVec3d targetCart2 = targetCart + target_pos_off; SGVec3d targetCart2 = targetCart + target_pos_off;
@ -1048,7 +1052,7 @@ View::recalcLookAt ()
else { else {
set_fov(_fov_user_deg); set_fov(_fov_user_deg);
} }
SGQuatd geodEyeOr = SGQuatd::fromYawPitchRollDeg(eye_heading, eye_pitch, eye_roll); SGQuatd geodEyeOr = SGQuatd::fromYawPitchRollDeg(eye_heading, eye_pitch, eye_roll);
SGQuatd geodEyeHlOr = SGQuatd::fromLonLat(_position); SGQuatd geodEyeHlOr = SGQuatd::fromLonLat(_position);