Browse Source

pgraph: Make ModelPool.load_model() work same as Loader.load_sync()

ModelPool.load_model() did not work like the other pools, didn't resolve relative to the VFS, didn't respect loader options... let's just make these work the same.  We should deprecate one in favor of the other eventually
rdb 1 year ago
parent
commit
3f2b9cd351
2 changed files with 15 additions and 34 deletions
  1. 11 7
      panda/src/pgraph/loader.cxx
  2. 4 27
      panda/src/pgraph/modelPool.cxx

+ 11 - 7
panda/src/pgraph/loader.cxx

@@ -392,13 +392,17 @@ try_load_file(const Filename &pathname, const LoaderOptions &options,
     sgr.premunge(result, RenderState::make_empty());
   }
 
-  if (allow_ram_cache && result->is_of_type(ModelRoot::get_class_type())) {
-    // Store the loaded model in the RAM cache, and make sure we return a
-    // copy so that this node can be modified independently from the RAM
-    // cached version.
-    ModelPool::add_model(pathname, DCAST(ModelRoot, result.p()));
-    if ((options.get_flags() & LoaderOptions::LF_allow_instance) == 0) {
-      result = NodePath(result).copy_to(NodePath()).node();
+  if (result->is_of_type(ModelRoot::get_class_type())) {
+    ((ModelRoot *)result.p())->set_fullpath(pathname);
+
+    if (allow_ram_cache) {
+      // Store the loaded model in the RAM cache, and make sure we return a
+      // copy so that this node can be modified independently from the RAM
+      // cached version.
+      ModelPool::add_model(pathname, DCAST(ModelRoot, result.p()));
+      if ((options.get_flags() & LoaderOptions::LF_allow_instance) == 0) {
+        result = NodePath(result).copy_to(NodePath()).node();
+      }
     }
   }
 

+ 4 - 27
panda/src/pgraph/modelPool.cxx

@@ -118,52 +118,29 @@ ns_get_model(const Filename &filename, bool verify) {
  */
 ModelRoot *ModelPool::
 ns_load_model(const Filename &filename, const LoaderOptions &options) {
-
-  // First check if it has already been loaded and is still current.
+  // First check if it's been cached under the given filename (for backward
+  // compatibility reasons)
   PT(ModelRoot) cached_model = ns_get_model(filename, true);
   if (cached_model != nullptr) {
     return cached_model;
   }
 
-  // Look on disk for the current file.
   LoaderOptions new_options(options);
-  new_options.set_flags((new_options.get_flags() | LoaderOptions::LF_no_ram_cache) &
-                        ~LoaderOptions::LF_search);
+  new_options.set_flags(new_options.get_flags() & ~LoaderOptions::LF_no_ram_cache);
 
   Loader *model_loader = Loader::get_global_ptr();
   PT(PandaNode) panda_node = model_loader->load_sync(filename, new_options);
   PT(ModelRoot) node;
 
-  if (panda_node.is_null()) {
-    // This model was not found.
-
-  } else {
+  if (!panda_node.is_null()) {
     if (panda_node->is_of_type(ModelRoot::get_class_type())) {
       node = DCAST(ModelRoot, panda_node);
-
     } else {
       // We have to construct a ModelRoot node to put it under.
       node = new ModelRoot(filename);
       node->add_child(panda_node);
     }
-    node->set_fullpath(filename);
-  }
-
-  {
-    LightMutexHolder holder(_lock);
-
-    // Look again, in case someone has just loaded the model in another
-    // thread.
-    Models::const_iterator ti;
-    ti = _models.find(filename);
-    if (ti != _models.end() && (*ti).second != cached_model) {
-      // This model was previously loaded.
-      return (*ti).second;
-    }
-
-    _models[filename] = node;
   }
-
   return node;
 }