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