From de16d367d8fdf31075178ae3cb307ad328c513e2 Mon Sep 17 00:00:00 2001
From: till busch <buti@bux.at>
Date: Fri, 21 Mar 2008 22:42:35 +0100
Subject: [PATCH] modelpaging v0.4.4.1 (incremetal) - flightgear
cleanups, docs
---
 src/AIModel/AIBallistic.cxx   |    2 ++
 src/AIModel/AIBase.cxx        |    2 +-
 src/AIModel/AIManager.cxx     |    2 +-
 src/AIModel/AIManager.hxx     |    2 +-
 src/AIModel/AIModelData.hxx   |    1 +
 src/AIModel/AIMultiplayer.cxx |    1 +
 src/ATC/AIMgr.cxx             |    2 ++
 src/Main/main.cxx             |   14 +++-----------
 src/Model/model_panel.cxx     |    2 ++
 src/Model/modelmgr.cxx        |    3 ++-
 src/Scenery/scenery.cxx       |   22 ++++++++++++++++++++++
 src/Scenery/scenery.hxx       |    5 +++++
 src/Scenery/tilemgr.cxx       |    1 +
 src/Scripting/NasalSys.hxx    |    4 ++--
 14 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx
index a08cc08..0de56a4 100644
--- a/src/AIModel/AIBallistic.cxx
+++ b/src/AIModel/AIBallistic.cxx
@@ -38,6 +38,8 @@
 const double FGAIBallistic::slugs_to_kgs = 14.5939029372;
 const double FGAIBallistic::slugs_to_lbs = 32.1740485564;
 
+using namespace simgear;
+
 FGAIBallistic::FGAIBallistic(object_type ot) :
 FGAIBase(ot),
     _elevation(0),
diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx
index 1debff1..e8d674a 100644
--- a/src/AIModel/AIBase.cxx
+++ b/src/AIModel/AIBase.cxx
@@ -53,6 +53,7 @@
 const double FGAIBase::e = 2.71828183;
 const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
 
+using namespace simgear;
 
 FGAIBase::FGAIBase(object_type ot) :
     props( NULL ),
@@ -197,7 +198,6 @@ void FGAIBase::initModel(osg::Node *node)
         SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
     }
 
-    props->setStringValue("models/path", model_path.c_str());
     props->setStringValue("submodels/path", _path.c_str());
     setDie(false);
 }
diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx
index 9944f46..bc56af3 100644
--- a/src/AIModel/AIManager.cxx
+++ b/src/AIModel/AIManager.cxx
@@ -175,7 +175,7 @@ FGAIManager::update(double dt) {
 }
 
 void
-FGAIManager::attach(osg::ref_ptr<FGAIBase> model)
+FGAIManager::attach(FGAIBase *model)
 {
     //unsigned idx = mNumAiTypeModels[model->getType()];
     const char* typeString = model->getTypeString();
diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx
index 111ded1..19303fc 100644
--- a/src/AIModel/AIManager.hxx
+++ b/src/AIModel/AIManager.hxx
@@ -66,7 +66,7 @@ public:
     void bind();
     void unbind();
     void update(double dt);
-    void attach(osg::ref_ptr<FGAIBase> model);
+    void attach(FGAIBase *model);
 
     void destroyObject( int ID );
     const FGAIBase *calcCollision(double alt, double lat, double lon, double fuse_range);
diff --git a/src/AIModel/AIModelData.hxx b/src/AIModel/AIModelData.hxx
index 0f9e8f7..6ebabf0 100644
--- a/src/AIModel/AIModelData.hxx
+++ b/src/AIModel/AIModelData.hxx
@@ -1,6 +1,7 @@
 #ifndef __FGAIMODELDATA_HXX
 #define __FGAIMODELDATA_HXX
 
+#include <osg/observer_ptr>
 #include <Scripting/NasalSys.hxx>
 
 class FGAIBase;
diff --git a/src/AIModel/AIMultiplayer.cxx b/src/AIModel/AIMultiplayer.cxx
index b7b0f68..a34a927 100755
--- a/src/AIModel/AIMultiplayer.cxx
+++ b/src/AIModel/AIMultiplayer.cxx
@@ -44,6 +44,7 @@ FGAIMultiplayer::~FGAIMultiplayer() {
 }
 
 bool FGAIMultiplayer::init(bool search_in_AI_path) {
+    props->setStringValue("sim/model/path", model_path.c_str());
     //refuel_node = fgGetNode("systems/refuel/contact", true);
     isTanker = false; // do this until this property is
                       // passed over the net
diff --git a/src/ATC/AIMgr.cxx b/src/ATC/AIMgr.cxx
index fb5ce5a..23d44bb 100644
--- a/src/ATC/AIMgr.cxx
+++ b/src/ATC/AIMgr.cxx
@@ -49,6 +49,8 @@
 SG_USING_STD(list);
 SG_USING_STD(cout);
 
+using namespace simgear;
+
 FGAIMgr::FGAIMgr() {
 	ATC = globals->get_ATC_mgr();
 	initDone = false;
diff --git a/src/Main/main.cxx b/src/Main/main.cxx
index ad3ad39..16866ed 100644
--- a/src/Main/main.cxx
+++ b/src/Main/main.cxx
@@ -55,7 +55,6 @@
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/model/animation.hxx>
 #include <simgear/scene/sky/sky.hxx>
-#include <simgear/scene/model/CheckSceneryVisitor.hxx>
 #include <Time/light.hxx>
 #include <Include/general.hxx>
 #include <Aircraft/replay.hxx>
@@ -138,21 +137,14 @@ void fgUpdateTimeDepCalcs() {
         double lat = fgGetDouble("/sim/presets/latitude-deg");
         // We require just to have 50 meter scenery availabe around
         // the aircraft.
-        double range = 50.0;
-        if (globals->get_tile_mgr()->scenery_available(lat, lon, range)) {
-            double elev;
-            globals->get_scenery()->get_elevation_m(lat, lon, 9000, elev, 0);
-            SGVec3f p = SGVec3f::fromGeod(SGGeod::fromDegM(lon,lat,elev));
-            simgear::CheckSceneryVisitor csnv(p.osg());
-            globals->get_scenery()->get_scene_graph()->accept(csnv);
-            if(csnv.isLoaded()) {
+        double range = 1000.0;
+        if (globals->get_scenery()->scenery_available(lat, lon, range)) {
             SG_LOG(SG_FLIGHT,SG_ALERT, "Finally initializing fdm");
             cur_fdm_state->init();
             if ( cur_fdm_state->get_bound() ) {
                 cur_fdm_state->unbind();
             }
             cur_fdm_state->bind();
-            }
         }
     }
 
@@ -776,7 +768,7 @@ static void fgIdleFunction ( void ) {
         // Initialize the material manager
         ////////////////////////////////////////////////////////////////////
         globals->set_matlib( new SGMaterialLib );
-        SGModelLib::init(globals->get_fg_root());
+        simgear::SGModelLib::init(globals->get_fg_root());
 
 
         ////////////////////////////////////////////////////////////////////
diff --git a/src/Model/model_panel.cxx b/src/Model/model_panel.cxx
index 8ccca9e..ea24a2f 100644
--- a/src/Model/model_panel.cxx
+++ b/src/Model/model_panel.cxx
@@ -21,6 +21,8 @@
 
 SG_USING_STD(vector);
 
+using namespace simgear;
+
 static
 osg::Node* load_panel(SGPropertyNode *n)
 {
diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx
index e8fcd88..a7f543f 100644
--- a/src/Model/modelmgr.cxx
+++ b/src/Model/modelmgr.cxx
@@ -27,10 +27,11 @@
 
 SG_USING_STD(vector);
 
+using namespace simgear;
+
 // OSGFIXME
 // extern SGShadowVolume *shadows;
 
-
 FGModelMgr::FGModelMgr ()
   : _models(fgGetNode("/models", true)),
     _listener(new Listener(this))
diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx
index 3ac04d2..d47c474 100644
--- a/src/Scenery/scenery.cxx
+++ b/src/Scenery/scenery.cxx
@@ -30,6 +30,7 @@
 
 #include <osgUtil/IntersectVisitor>
 
+#include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/scene/tgdb/userdata.hxx>
 #include <simgear/math/sg_geodesy.hxx>
@@ -37,9 +38,11 @@
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
 #include <simgear/scene/util/SGSceneUserData.hxx>
+#include <simgear/scene/model/CheckSceneryVisitor.hxx>
 
 #include <Main/fg_props.hxx>
 
+#include "tilemgr.hxx"
 #include "scenery.hxx"
 
 using namespace flightgear;
@@ -209,6 +212,25 @@ FGScenery::get_cart_ground_intersection(const SGVec3d& pos, const SGVec3d& dir,
   return hits;
 }
 
+bool FGScenery::scenery_available(double lat, double lon, double range_m)
+{
+  if(globals->get_tile_mgr()->scenery_available(lat, lon, range_m))
+  {
+    double elev;
+    get_elevation_m(lat, lon, SG_MAX_ELEVATION_M, elev, 0);
+    SGVec3f p = SGVec3f::fromGeod(SGGeod::fromDegM(lon,lat,elev));
+    simgear::CheckSceneryVisitor csnv(getPagerSingleton(), p.osg(), range_m);
+    // currently the PagedLODs will not be loaded by the DatabasePager
+    // while the splashscreen is there, so CheckSceneryVisitor force-loads
+    // missing objects in the main thread
+    get_scene_graph()->accept(csnv);
+    if(!csnv.isLoaded())
+        return false;
+    return true;
+  }
+  return false;
+}
+
 SceneryPager* FGScenery::getPagerSingleton()
 {
     static osg::ref_ptr<SceneryPager> pager = new SceneryPager;
diff --git a/src/Scenery/scenery.hxx b/src/Scenery/scenery.hxx
index 6b318fd..0a5ea19 100644
--- a/src/Scenery/scenery.hxx
+++ b/src/Scenery/scenery.hxx
@@ -102,6 +102,11 @@ public:
     osg::Group *get_models_branch () const { return models_branch.get(); }
     osg::Group *get_aircraft_branch () const { return aircraft_branch.get(); }
 
+    /// Returns true if scenery is avaliable for the given lat, lon position
+    /// within a range of range_m.
+    /// lat and lon are expected to be in degrees.
+    bool scenery_available(double lat, double lon, double range_m);
+
     // Static because access to the pager is needed before the rest of
     // the scenery is initialized.
     static flightgear::SceneryPager* getPagerSingleton();
diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx
index 83bd9b6..c34701f 100644
--- a/src/Scenery/tilemgr.cxx
+++ b/src/Scenery/tilemgr.cxx
@@ -50,6 +50,7 @@
 
 using std::for_each;
 using flightgear::SceneryPager;
+using simgear::SGModelLib;
 
 #define TEST_LAST_HIT_CACHE
 
diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx
index 04313ea..d1bf0a4 100644
--- a/src/Scripting/NasalSys.hxx
+++ b/src/Scripting/NasalSys.hxx
@@ -4,7 +4,7 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/nasal/nasal.h>
-#include <simgear/scene/model/model.hxx>
+#include <simgear/scene/model/modellib.hxx>
 #include <simgear/xml/easyxml.hxx>
 
 #include <map>
@@ -159,7 +159,7 @@ private:
 };
 
 
-class FGNasalModelData : public SGModelData {
+class FGNasalModelData : public simgear::SGModelData {
 public:
     FGNasalModelData(SGPropertyNode *props = 0) : _props(props), _unload(0) {}
     ~FGNasalModelData();
-- 
1.5.2.5


