]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/modellib.cxx
- better error message when submodel loading failed
[simgear.git] / simgear / scene / model / modellib.cxx
index 49073d63908baf5de7fac98d267e2b0155653f05..bd28d43d23eed91899a3bf90b8e388f587f46188 100644 (file)
@@ -1,5 +1,9 @@
 // modellib.cxx - implement an SSG model library.
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include <simgear/compiler.h>
 #include <simgear/props/props.hxx>
 
@@ -21,11 +25,6 @@ SGModelLib::SGModelLib ()
 
 SGModelLib::~SGModelLib ()
 {
-    map<string, ssgBase *>::iterator it = _table.begin();
-    while (it != _table.end()) {
-        it->second->deRef();
-        _table.erase(it);
-    }
 }
 
 void
@@ -49,16 +48,16 @@ SGModelLib::flush1()
 
     return;
 
-    map<string, ssgBase *>::iterator it = _table.begin();
+    map<string, ssgSharedPtr<ssgEntity> >::iterator it = _table.begin();
     while (it != _table.end()) {
-        ssgBase *item = it->second;
                                 // If there is only one reference, it's
                                 // ours; no one else is using the item.
-        if (item->getRef() == 1) {
-            item->deRef();
+        if (!it->second.isShared()) {
+            string key = it->first;
             _table.erase(it);
-        }
-        it++;
+            it = _table.upper_bound(key);
+        } else
+            it++;
     }
 }
 
@@ -82,7 +81,9 @@ ssgEntity *
 SGModelLib::load_model( const string &fg_root,
                            const string &path,
                            SGPropertyNode *prop_root,
-                           double sim_time_sec )
+                           double sim_time_sec,
+                           bool cache_object,
+                           SGModelData *data )
 {
     ssgBranch *personality_branch = new SGPersonalityBranch;
     personality_branch->setTravCallback(SSG_CALLBACK_PRETRAV, personality_pretrav_callback);
@@ -90,15 +91,16 @@ SGModelLib::load_model( const string &fg_root,
 
                                 // FIXME: normalize path to
                                 // avoid duplicates.
-    map<string, ssgBase *>::iterator it = _table.find(path);
-    if (it == _table.end()) {
-        ssgEntity *model = sgLoad3DModel( fg_root, path, prop_root,
-                                          sim_time_sec );
-        model->ref();
-        _table[path] = model;      // add one reference to keep it around
+    map<string, ssgSharedPtr<ssgEntity> >::iterator it = _table.find(path);
+    if (!cache_object || it == _table.end()) {
+        ssgSharedPtr<ssgEntity> model = sgLoad3DModel(fg_root, path, prop_root,
+                                                      sim_time_sec, 0, data );
+        if (cache_object)
+            _table[path] = model;      // add one reference to keep it around
+
         personality_branch->addKid( model );
     } else {
-        personality_branch->addKid( (ssgEntity *)it->second );
+        personality_branch->addKid( it->second );
     }
     return personality_branch;
 }