Panda3D
modelPool.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file modelPool.I
10  * @author drose
11  * @date 2002-03-12
12  */
13 
14 /**
15  * Returns true if the model has ever been loaded, false otherwise. Note that
16  * this does not guarantee that the model is still up-to-date.
17  */
18 INLINE bool ModelPool::
19 has_model(const Filename &filename) {
20  return get_ptr()->ns_has_model(filename);
21 }
22 
23 /**
24  * Loads the given filename up as a model, if it has not already been loaded,
25  * and returns true to indicate success, or false to indicate failure. If
26  * this returns true, it is probable that a subsequent call to load_model()
27  * with the same model name will return a valid PandaNode.
28  *
29  * However, even if this returns true, it is still possible for a subsequent
30  * call to load_model() to fail. This can happen if cache-check-timestamps is
31  * true, and the on-disk file is subsequently modified to replace it with an
32  * invalid model.
33  */
34 INLINE bool ModelPool::
35 verify_model(const Filename &filename) {
36  return load_model(filename) != nullptr;
37 }
38 
39 /**
40  * Returns the model that has already been previously loaded, or NULL
41  * otherwise. If verify is true, it will check if the file is still up-to-
42  * date (and hasn't been modified in the meantime), and if not, will still
43  * return NULL.
44  */
45 INLINE ModelRoot *ModelPool::
46 get_model(const Filename &filename, bool verify) {
47  return get_ptr()->ns_get_model(filename, verify);
48 }
49 
50 /**
51  * Loads the given filename up as a model, if it has not already been loaded,
52  * and returns the new model. If a model with the same filename was
53  * previously loaded, returns that one instead (unless cache-check-timestamps
54  * is true and the file has recently changed). If the model file cannot be
55  * found, or cannot be loaded for some reason, returns NULL.
56  */
57 INLINE ModelRoot *ModelPool::
58 load_model(const Filename &filename, const LoaderOptions &options) {
59  return get_ptr()->ns_load_model(filename, options);
60 }
61 
62 /**
63  * Adds the indicated already-loaded model to the pool. The model will
64  * replace any previously-loaded model in the pool that had the same filename.
65  *
66  * This two-parameter version of this method is deprecated; use the one-
67  * parameter add_model(model) instead.
68  */
69 INLINE void ModelPool::
70 add_model(const Filename &filename, ModelRoot *model) {
71  get_ptr()->ns_add_model(filename, model);
72 }
73 
74 /**
75  * Removes the indicated model from the pool, indicating it will never be
76  * loaded again; the model may then be freed. If this function is never
77  * called, a reference count will be maintained on every model every loaded,
78  * and models will never be freed.
79  *
80  * This version of this method is deprecated; use release_model(model)
81  * instead.
82  */
83 INLINE void ModelPool::
84 release_model(const Filename &filename) {
85  get_ptr()->ns_release_model(filename);
86 }
87 
88 /**
89  * Adds the indicated already-loaded model to the pool. The model will
90  * replace any previously-loaded model in the pool that had the same filename.
91  */
92 INLINE void ModelPool::
94  get_ptr()->ns_add_model(model);
95 }
96 
97 /**
98  * Removes the indicated model from the pool, indicating it will never be
99  * loaded again; the model may then be freed. If this function (and
100  * garbage_collect()) is never called, a reference count will be maintained on
101  * every model every loaded, and models will never be freed.
102  *
103  * The model's get_fullpath() value should not have been changed during its
104  * lifetime, or this function may fail to locate it in the pool.
105  */
106 INLINE void ModelPool::
108  get_ptr()->ns_release_model(model);
109 }
110 
111 /**
112  * Releases all models in the pool and restores the pool to the empty state.
113  */
114 INLINE void ModelPool::
116  get_ptr()->ns_release_all_models();
117 }
118 
119 /**
120  * Releases only those models in the pool that have a reference count of
121  * exactly 1; i.e. only those models that are not being used outside of the
122  * pool. Returns the number of models released.
123  */
124 INLINE int ModelPool::
126  return get_ptr()->ns_garbage_collect();
127 }
128 
129 /**
130  * Lists the contents of the model pool to the indicated output stream.
131  */
132 INLINE void ModelPool::
133 list_contents(std::ostream &out) {
134  get_ptr()->ns_list_contents(out);
135 }
136 
137 /**
138  * Lists the contents of the model pool to cout.
139  */
140 INLINE void ModelPool::
142  get_ptr()->ns_list_contents(std::cout);
143 }
144 
145 /**
146  * The constructor is not intended to be called directly; there's only
147  * supposed to be one ModelPool in the universe and it constructs itself.
148  */
149 INLINE ModelPool::
150 ModelPool() {
151 }
A node of this type is created automatically at the root of each model file that is loaded.
Definition: modelRoot.h:27
static void add_model(const Filename &filename, ModelRoot *model)
Adds the indicated already-loaded model to the pool.
Definition: modelPool.I:70
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:23
static void list_contents()
Lists the contents of the model pool to cout.
Definition: modelPool.I:141
static ModelRoot * load_model(const Filename &filename, const LoaderOptions &options=LoaderOptions())
Loads the given filename up as a model, if it has not already been loaded, and returns the new model.
Definition: modelPool.I:58
static int garbage_collect()
Releases only those models in the pool that have a reference count of exactly 1; i....
Definition: modelPool.I:125
static bool verify_model(const Filename &filename)
Loads the given filename up as a model, if it has not already been loaded, and returns true to indica...
Definition: modelPool.I:35
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
static void release_all_models()
Releases all models in the pool and restores the pool to the empty state.
Definition: modelPool.I:115
static void release_model(const Filename &filename)
Removes the indicated model from the pool, indicating it will never be loaded again; the model may th...
Definition: modelPool.I:84
static ModelRoot * get_model(const Filename &filename, bool verify)
Returns the model that has already been previously loaded, or NULL otherwise.
Definition: modelPool.I:46
static bool has_model(const Filename &filename)
Returns true if the model has ever been loaded, false otherwise.
Definition: modelPool.I:19