15 #include "modelPool.h" 17 #include "config_pgraph.h" 18 #include "lightMutexHolder.h" 19 #include "virtualFileSystem.h" 33 get_ptr()->ns_list_contents(out);
42 ns_has_model(
const Filename &filename) {
44 Models::const_iterator ti;
45 ti = _models.find(filename);
46 if (ti != _models.end() && (*ti).second != (
ModelRoot *)NULL) {
60 ns_get_model(
const Filename &filename,
bool verify) {
63 bool got_cached_model =
false;
67 Models::const_iterator ti;
68 ti = _models.find(filename);
69 if (ti != _models.end()) {
71 cached_model = (*ti).second;
72 got_cached_model =
true;
76 if (got_cached_model && verify) {
77 if (pgraph_cat.is_debug()) {
79 <<
"ModelPool found " << cached_model <<
" for " << filename <<
"\n";
82 if (cached_model == NULL) {
85 if (cache_check_timestamps) {
88 if (vfs->
exists(filename)) {
90 got_cached_model =
false;
96 if (cache_check_timestamps && cached_model->get_timestamp() != 0 &&
97 !cached_model->get_fullpath().empty()) {
103 got_cached_model =
false;
105 }
else if (vfile->get_timestamp() > cached_model->get_timestamp()) {
108 got_cached_model =
false;
114 if (got_cached_model) {
115 if (pgraph_cat.is_debug()) {
117 <<
"ModelPool returning " << cached_model <<
" for " << filename <<
"\n";
134 PT(
ModelRoot) cached_model = ns_get_model(filename,
true);
141 new_options.set_flags((new_options.get_flags() | LoaderOptions::LF_no_ram_cache) &
142 ~LoaderOptions::LF_search);
145 PT(
PandaNode) panda_node = model_loader->load_sync(filename, new_options);
148 if (panda_node.is_null()) {
152 if (panda_node->is_of_type(ModelRoot::get_class_type())) {
158 node->add_child(panda_node);
160 node->set_fullpath(filename);
168 Models::const_iterator ti;
169 ti = _models.find(filename);
170 if (ti != _models.end() && (*ti).second != cached_model) {
175 _models[filename] = node;
189 if (pgraph_cat.is_debug()) {
191 <<
"ModelPool storing " << model <<
" for " << filename <<
"\n";
194 _models[filename] = model;
203 ns_release_model(
const Filename &filename) {
206 ti = _models.find(filename);
207 if (ti != _models.end()) {
234 if (ti != _models.end()) {
245 ns_release_all_models() {
256 ns_garbage_collect() {
259 int num_released = 0;
263 for (ti = _models.begin(); ti != _models.end(); ++ti) {
267 if (loader_cat.is_debug()) {
269 <<
"Releasing " << (*ti).first <<
"\n";
273 new_set.insert(new_set.end(), *ti);
277 _models.swap(new_set);
287 ns_list_contents(ostream &out)
const {
290 out <<
"model pool contents:\n";
292 Models::const_iterator ti;
294 for (ti = _models.begin(); ti != _models.end(); ++ti) {
295 if ((*ti).second != NULL) {
297 out << (*ti).first <<
"\n" 298 <<
" (count = " << (*ti).second->get_model_ref_count()
303 out <<
"total number of models: " << num_models <<
" (plus " 304 << _models.size() - num_models <<
" entries for nonexistent files)\n";
A node of this type is created automatically at the root of each model file that is loaded...
static void write(ostream &out)
Lists the contents of the model pool to the indicated output stream.
A basic node of the scene graph or data graph.
const Filename & get_fullpath() const
Returns the full pathname of the model represented by this node, as found on disk.
Specifies parameters that may be passed to the loader.
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
This class unifies all references to the same filename, so that multiple attempts to load the same mo...
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
int get_model_ref_count() const
Returns the number of copies that exist of this particular ModelRoot node.
The abstract base class for a file or directory within the VirtualFileSystem.
static Loader * get_global_ptr()
Returns a pointer to the global Loader.
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists.
The name of a file, such as a texture file or an Egg file.
Similar to MutexHolder, but for a light mutex.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.