]> git.mxchange.org Git - flightgear.git/commitdiff
Clean up view-number property handling
authorJames Turner <zakalawe@mac.com>
Thu, 21 Jan 2016 02:26:51 +0000 (21:26 -0500)
committerJames Turner <zakalawe@mac.com>
Wed, 17 Feb 2016 21:25:39 +0000 (21:25 +0000)
src/Viewer/viewmgr.cxx
src/Viewer/viewmgr.hxx

index ffe87bb0e066d6ab5b8e4bf11f842d3722367287..503db730c8441077f1562a5bd70cdd120439b245 100644 (file)
@@ -42,7 +42,6 @@ FGViewMgr::FGViewMgr( void ) :
   axis_long(0),
   axis_lat(0),
   inited(false),
-  view_number(fgGetNode("/sim/current-view/view-number", true)),
   config_list(fgGetNode("/sim", true)->getChildren("view")),
   current(0)
 {
@@ -123,6 +122,8 @@ FGViewMgr::bind()
     target_x_offs  = fgGetNode("/sim/current-view/target-x-offset-m", true);
     target_y_offs  = fgGetNode("/sim/current-view/target-y-offset-m", true);
     target_z_offs  = fgGetNode("/sim/current-view/target-z-offset-m", true);
+
+
 }
 
 void
@@ -131,13 +132,13 @@ FGViewMgr::do_bind()
   // these are bound to the current view properties
   _tiedProperties.setRoot(fgGetNode("/sim/current-view", true));
 
-  _tiedProperties.Tie("view-number", this,
-                      &FGViewMgr::getView, &FGViewMgr::setView);
-  SGPropertyNode* view_number =
-    _tiedProperties.getRoot()->getNode("view-number");
-  view_number->setAttribute(SGPropertyNode::ARCHIVE, false);
-  // Keep view on reset/reinit
-  view_number->setAttribute(SGPropertyNode::PRESERVE, true);
+
+    _tiedProperties.Tie("view-number", this,
+                        &FGViewMgr::getView, &FGViewMgr::setView);
+    _viewNumberProp = _tiedProperties.getRoot()->getNode("view-number");
+    _viewNumberProp->setAttribute(SGPropertyNode::ARCHIVE, false);
+    _viewNumberProp->setAttribute(SGPropertyNode::PRESERVE, true);
+
 
   _tiedProperties.Tie("axes/long", this,
                       (double_getter)0, &FGViewMgr::setViewAxisLong);
@@ -169,8 +170,9 @@ FGViewMgr::unbind ()
     }
 
   _tiedProperties.Untie();
+    _viewNumberProp.clear();
+    
     config_list.clear();
-    view_number.clear();
     target_x_offs.clear();
     target_y_offs.clear();
     target_z_offs.clear();
@@ -258,7 +260,7 @@ flightgear::View*
 FGViewMgr::next_view()
 {
     setView((current+1 < (int)views.size()) ? (current + 1) : 0);
-    view_number->fireValueChanged();
+    _viewNumberProp->fireValueChanged();
     return views[current];
 }
 
@@ -266,7 +268,7 @@ flightgear::View*
 FGViewMgr::prev_view()
 {
     setView((0 < current) ? (current - 1) : (views.size() - 1));
-    view_number->fireValueChanged();
+    _viewNumberProp->fireValueChanged();
     return views[current];
 }
 
@@ -397,15 +399,18 @@ FGViewMgr::setViewTargetZOffset_m (double z)
   }
 }
 
-int
-FGViewMgr::getView () const
+int FGViewMgr::getView () const
 {
-  return ( current );
+  return current;
 }
 
 void
 FGViewMgr::setView (int newview)
 {
+    if (newview == current) {
+        return;
+    }
+
   // negative numbers -> set view with node index -newview
   if (newview < 0) {
     for (int i = 0; i < (int)config_list.size(); i++) {
index d17648d629d4c62939ff66f27db9b7950e8be027..f13ffeee867453ebbe64e4f68515cf849b554131 100644 (file)
@@ -117,8 +117,8 @@ private:
     double getViewElev_ft() const;
 
     bool inited;
-    SGPropertyNode_ptr view_number;
     std::vector<SGPropertyNode_ptr> config_list;
+    SGPropertyNode_ptr _viewNumberProp;
     typedef std::vector<flightgear::ViewPtr> viewer_list;
     viewer_list views;
     SGVec3d abs_viewer_position;