#include <modelPool.h>
Static Public Member Functions | |
bool | has_model (const string &filename) |
Returns true if the model has ever been loaded, false otherwise. | |
bool | verify_model (const string &filename) |
Loads the given filename up as a model, if it has not already been loaded, and returns true to indicate success, or false to indicate failure. | |
PandaNode * | load_model (const string &filename) |
Loads the given filename up as a model, if it has not already been loaded, and returns the new model. | |
void | add_model (const string &filename, PandaNode *model) |
Adds the indicated already-loaded model to the pool. | |
void | release_model (const string &filename) |
Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed. | |
void | release_all_models () |
Releases all models in the pool and restores the pool to the empty state. | |
int | garbage_collect () |
Releases only those models in the pool that have a reference count of exactly 1; i.e. | |
void | list_contents (ostream &out) |
Lists the contents of the model pool to the indicated output stream. | |
Private Types | |
typedef pmap< string, PointerTo< PandaNode > > | Models |
Private Member Functions | |
ModelPool () | |
The constructor is not intended to be called directly; there's only supposed to be one ModelPool in the universe and it constructs itself. | |
bool | ns_has_model (const string &filename) |
The nonstatic implementation of has_model(). | |
PandaNode * | ns_load_model (const string &filename) |
The nonstatic implementation of load_model(). | |
void | ns_add_model (const string &filename, PandaNode *model) |
The nonstatic implementation of add_model(). | |
void | ns_release_model (const string &filename) |
The nonstatic implementation of release_model(). | |
void | ns_release_all_models () |
The nonstatic implementation of release_all_models(). | |
int | ns_garbage_collect () |
The nonstatic implementation of garbage_collect(). | |
void | ns_list_contents (ostream &out) |
The nonstatic implementation of list_contents(). | |
Static Private Member Functions | |
ModelPool * | get_ptr () |
Initializes and/or returns the global pointer to the one ModelPool object in the system. | |
Private Attributes | |
Models | _models |
Static Private Attributes | |
ModelPool * | _global_ptr = (ModelPool *)NULL |
It unifies all references to the same filename, so that multiple attempts to load the same model will return the same pointer. Note that the default behavior is thus to make instances: use with caution. Use the copy_subgraph() method on Node (or use NodePath::copy_to) to make modifiable copies of the node.
Unlike TexturePool, this class does not automatically resolve the model filenames before loading, so a relative path and an absolute path to the same model will appear to be different filenames.
This does not presently support asynchronous loading, although it wouldn't be *too* difficult to add.
Definition at line 70 of file modelPool.h.
|
Definition at line 98 of file modelPool.h. |
|
The constructor is not intended to be called directly; there's only supposed to be one ModelPool in the universe and it constructs itself.
Definition at line 184 of file modelPool.I. |
|
Adds the indicated already-loaded model to the pool. The model will always replace any previously-loaded model in the pool that had the same filename. Definition at line 97 of file modelPool.I. References get_ptr(), INLINE, and ns_garbage_collect(). |
|
Releases only those models in the pool that have a reference count of exactly 1; i.e. only those models that are not being used outside of the pool. Returns the number of models released. Definition at line 152 of file modelPool.I. |
|
Initializes and/or returns the global pointer to the one ModelPool object in the system.
Definition at line 184 of file modelPool.cxx. Referenced by add_model(), load_model(), and release_model(). |
|
Returns true if the model has ever been loaded, false otherwise.
Definition at line 34 of file modelPool.I. References INLINE, load_model(), and NULL. |
|
Lists the contents of the model pool to the indicated output stream.
Definition at line 167 of file modelPool.I. |
|
Loads the given filename up as a model, if it has not already been loaded, and returns the new model. If a model with the same filename was previously loaded, returns that one instead. If the model file cannot be found, returns NULL. Definition at line 78 of file modelPool.I. References get_ptr(), INLINE, and ns_release_model(). Referenced by has_model(). |
|
The nonstatic implementation of add_model().
Definition at line 89 of file modelPool.cxx. References _models. |
|
The nonstatic implementation of garbage_collect().
Definition at line 133 of file modelPool.cxx. References _models. Referenced by add_model(). |
|
The nonstatic implementation of has_model().
Definition at line 40 of file modelPool.cxx. |
|
The nonstatic implementation of list_contents().
Definition at line 164 of file modelPool.cxx. Referenced by release_model(). |
|
The nonstatic implementation of load_model().
Definition at line 60 of file modelPool.cxx. References model_loader, and NULL. |
|
The nonstatic implementation of release_all_models().
Definition at line 120 of file modelPool.cxx. |
|
The nonstatic implementation of release_model().
Definition at line 103 of file modelPool.cxx. References _models. Referenced by load_model(). |
|
Releases all models in the pool and restores the pool to the empty state.
Definition at line 133 of file modelPool.I. |
|
Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed. If this function is never called, a reference count will be maintained on every model every loaded, and models will never be freed. Definition at line 118 of file modelPool.I. References get_ptr(), and ns_list_contents(). |
|
Loads the given filename up as a model, if it has not already been loaded, and returns true to indicate success, or false to indicate failure. If this returns true, it is guaranteed that a subsequent call to load_model() with the same model name will return a valid Node pointer. Definition at line 57 of file modelPool.I. |
|
Definition at line 27 of file modelPool.cxx. |
|
Definition at line 99 of file modelPool.h. Referenced by ns_add_model(), ns_garbage_collect(), and ns_release_model(). |