Panda3D
|
00001 // Filename: modelPool.I 00002 // Created by: drose (12Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: ModelPool::has_model 00018 // Access: Public, Static 00019 // Description: Returns true if the model has ever been loaded, 00020 // false otherwise. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE bool ModelPool:: 00023 has_model(const Filename &filename) { 00024 return get_ptr()->ns_has_model(filename); 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: ModelPool::verify_model 00029 // Access: Public, Static 00030 // Description: Loads the given filename up as a model, if it has 00031 // not already been loaded, and returns true to indicate 00032 // success, or false to indicate failure. If this 00033 // returns true, it is guaranteed that a subsequent call 00034 // to load_model() with the same model name will 00035 // return a valid Node pointer. 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE bool ModelPool:: 00038 verify_model(const Filename &filename) { 00039 return load_model(filename) != (ModelRoot *)NULL; 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: ModelPool::load_model 00044 // Access: Public, Static 00045 // Description: Loads the given filename up as a model, if it has 00046 // not already been loaded, and returns the new model. 00047 // If a model with the same filename was previously 00048 // loaded, returns that one instead. If the model 00049 // file cannot be found, returns NULL. 00050 //////////////////////////////////////////////////////////////////// 00051 INLINE ModelRoot *ModelPool:: 00052 load_model(const Filename &filename, const LoaderOptions &options) { 00053 return get_ptr()->ns_load_model(filename, options); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: ModelPool::add_model 00058 // Access: Public, Static 00059 // Description: Adds the indicated already-loaded model to the 00060 // pool. The model will always replace any 00061 // previously-loaded model in the pool that had the 00062 // same filename. 00063 // 00064 // This two-parameter version of this method is 00065 // deprecated; use the one-parameter add_model(model) 00066 // instead. 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE void ModelPool:: 00069 add_model(const Filename &filename, ModelRoot *model) { 00070 get_ptr()->ns_add_model(filename, model); 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: ModelPool::release_model 00075 // Access: Public, Static 00076 // Description: Removes the indicated model from the pool, 00077 // indicating it will never be loaded again; the model 00078 // may then be freed. If this function is never called, 00079 // a reference count will be maintained on every model 00080 // every loaded, and models will never be freed. 00081 // 00082 // This version of this method is deprecated; use 00083 // release_model(model) instead. 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE void ModelPool:: 00086 release_model(const Filename &filename) { 00087 get_ptr()->ns_release_model(filename); 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: ModelPool::add_model 00092 // Access: Public, Static 00093 // Description: Adds the indicated already-loaded model to the 00094 // pool. The model will always replace any 00095 // previously-loaded model in the pool that had the 00096 // same filename. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE void ModelPool:: 00099 add_model(ModelRoot *model) { 00100 get_ptr()->ns_add_model(model); 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: ModelPool::release_model 00105 // Access: Public, Static 00106 // Description: Removes the indicated model from the pool, 00107 // indicating it will never be loaded again; the model 00108 // may then be freed. If this function is never called, 00109 // a reference count will be maintained on every model 00110 // every loaded, and models will never be freed. 00111 // 00112 // The model's get_fullpath() value should not have been 00113 // changed during its lifetime, or this function may 00114 // fail to locate it in the pool. 00115 //////////////////////////////////////////////////////////////////// 00116 INLINE void ModelPool:: 00117 release_model(ModelRoot *model) { 00118 get_ptr()->ns_release_model(model); 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: ModelPool::release_all_models 00123 // Access: Public, Static 00124 // Description: Releases all models in the pool and restores the 00125 // pool to the empty state. 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE void ModelPool:: 00128 release_all_models() { 00129 get_ptr()->ns_release_all_models(); 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: ModelPool::garbage_collect 00134 // Access: Public, Static 00135 // Description: Releases only those models in the pool that have a 00136 // reference count of exactly 1; i.e. only those 00137 // models that are not being used outside of the pool. 00138 // Returns the number of models released. 00139 //////////////////////////////////////////////////////////////////// 00140 INLINE int ModelPool:: 00141 garbage_collect() { 00142 return get_ptr()->ns_garbage_collect(); 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: ModelPool::list_contents 00147 // Access: Public, Static 00148 // Description: Lists the contents of the model pool to the 00149 // indicated output stream. 00150 //////////////////////////////////////////////////////////////////// 00151 INLINE void ModelPool:: 00152 list_contents(ostream &out) { 00153 get_ptr()->ns_list_contents(out); 00154 } 00155 00156 //////////////////////////////////////////////////////////////////// 00157 // Function: ModelPool::list_contents 00158 // Access: Public, Static 00159 // Description: Lists the contents of the model pool to cout. 00160 //////////////////////////////////////////////////////////////////// 00161 INLINE void ModelPool:: 00162 list_contents() { 00163 get_ptr()->ns_list_contents(cout); 00164 } 00165 00166 //////////////////////////////////////////////////////////////////// 00167 // Function: ModelPool::Constructor 00168 // Access: Private 00169 // Description: The constructor is not intended to be called 00170 // directly; there's only supposed to be one ModelPool 00171 // in the universe and it constructs itself. 00172 //////////////////////////////////////////////////////////////////// 00173 INLINE ModelPool:: 00174 ModelPool() { 00175 }