Panda3D
Loading...
Searching...
No Matches
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 */
18INLINE bool ModelPool::
19has_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 */
34INLINE bool ModelPool::
35verify_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 */
46get_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 */
58load_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 * @deprecated Use the one-parameter add_model(model) instead.
67 */
68INLINE void ModelPool::
69add_model(const Filename &filename, ModelRoot *model) {
70 get_ptr()->ns_add_model(filename, model);
71}
72
73/**
74 * Removes the indicated model from the pool, indicating it will never be
75 * loaded again; the model may then be freed. If this function is never
76 * called, a reference count will be maintained on every model every loaded,
77 * and models will never be freed.
78 *
79 * @deprecated Use release_model(model) instead.
80 */
81INLINE void ModelPool::
82release_model(const Filename &filename) {
83 get_ptr()->ns_release_model(filename);
84}
85
86/**
87 * Adds the indicated already-loaded model to the pool. The model will
88 * replace any previously-loaded model in the pool that had the same filename.
89 */
90INLINE void ModelPool::
91add_model(ModelRoot *model) {
92 get_ptr()->ns_add_model(model);
93}
94
95/**
96 * Removes the indicated model from the pool, indicating it will never be
97 * loaded again; the model may then be freed. If this function (and
98 * garbage_collect()) is never called, a reference count will be maintained on
99 * every model every loaded, and models will never be freed.
100 *
101 * The model's get_fullpath() value should not have been changed during its
102 * lifetime, or this function may fail to locate it in the pool.
103 */
104INLINE void ModelPool::
105release_model(ModelRoot *model) {
106 get_ptr()->ns_release_model(model);
107}
108
109/**
110 * Releases all models in the pool and restores the pool to the empty state.
111 */
112INLINE void ModelPool::
114 get_ptr()->ns_release_all_models();
115}
116
117/**
118 * Releases only those models in the pool that have a reference count of
119 * exactly 1; i.e. only those models that are not being used outside of the
120 * pool. Returns the number of models released.
121 */
122INLINE int ModelPool::
124 return get_ptr()->ns_garbage_collect();
125}
126
127/**
128 * Lists the contents of the model pool to the indicated output stream.
129 */
130INLINE void ModelPool::
131list_contents(std::ostream &out) {
132 get_ptr()->ns_list_contents(out);
133}
134
135/**
136 * Lists the contents of the model pool to cout.
137 */
138INLINE void ModelPool::
140 get_ptr()->ns_list_contents(std::cout);
141}
142
143/**
144 * The constructor is not intended to be called directly; there's only
145 * supposed to be one ModelPool in the universe and it constructs itself.
146 */
147INLINE ModelPool::
148ModelPool() {
149}
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
Specifies parameters that may be passed to the loader.
static int garbage_collect()
Releases only those models in the pool that have a reference count of exactly 1; i....
Definition modelPool.I:123
static void add_model(const Filename &filename, ModelRoot *model)
Adds the indicated already-loaded model to the pool.
Definition modelPool.I:69
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 void list_contents()
Lists the contents of the model pool to cout.
Definition modelPool.I:139
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 bool has_model(const Filename &filename)
Returns true if the model has ever been loaded, false otherwise.
Definition modelPool.I:19
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:82
static void release_all_models()
Releases all models in the pool and restores the pool to the empty state.
Definition modelPool.I:113
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
A node of this type is created automatically at the root of each model file that is loaded.
Definition modelRoot.h:27