Panda3D
 All Classes Functions Variables Enumerations
loader.I
00001 // Filename: loader.I
00002 // Created by:  mike (09Jan97)
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: Loader::Results::Constructor
00018 //       Access: Published
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE Loader::Results::
00022 Results() {
00023 }
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: Loader::Results::Copy Constructor
00027 //       Access: Published
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 INLINE Loader::Results::
00031 Results(const Loader::Results &copy) :
00032   _files(copy._files)
00033 {
00034 }
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: Loader::Results::Copy Assignment Operator
00038 //       Access: Published
00039 //  Description:
00040 ////////////////////////////////////////////////////////////////////
00041 INLINE void Loader::Results::
00042 operator = (const Loader::Results &copy) {
00043   _files = copy._files;
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: Loader::Results::Destructor
00048 //       Access: Published
00049 //  Description:
00050 ////////////////////////////////////////////////////////////////////
00051 INLINE Loader::Results::
00052 ~Results() {
00053 }
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //     Function: Loader::Results::clear
00057 //       Access: Published
00058 //  Description: Removes all the files from the list.
00059 ////////////////////////////////////////////////////////////////////
00060 INLINE void Loader::Results::
00061 clear() {
00062   _files.clear();
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: Loader::Results::get_num_files
00067 //       Access: Published
00068 //  Description: Returns the number of files on the result list.
00069 ////////////////////////////////////////////////////////////////////
00070 INLINE int Loader::Results::
00071 get_num_files() const {
00072   return _files.size();
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: Loader::Results::get_file
00077 //       Access: Published
00078 //  Description: Returns the nth file on the result list.
00079 ////////////////////////////////////////////////////////////////////
00080 INLINE const Filename &Loader::Results::
00081 get_file(int n) const {
00082   nassertr(n >= 0 && n < (int)_files.size(), _files[0]._path);
00083   return _files[n]._path;
00084 }
00085 
00086 ////////////////////////////////////////////////////////////////////
00087 //     Function: Loader::Results::get_file_type
00088 //       Access: Published
00089 //  Description: Returns the file type of the nth file on the result
00090 //               list.
00091 ////////////////////////////////////////////////////////////////////
00092 INLINE LoaderFileType *Loader::Results::
00093 get_file_type(int n) const {
00094   nassertr(n >= 0 && n < (int)_files.size(), NULL);
00095   return _files[n]._type;
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: Loader::Results::add_file
00100 //       Access: Published
00101 //  Description: Adds a new file to the result list.
00102 ////////////////////////////////////////////////////////////////////
00103 INLINE void Loader::Results::
00104 add_file(const Filename &file, LoaderFileType *type) {
00105   ConsiderFile cf;
00106   cf._path = file;
00107   cf._type = type;
00108   _files.push_back(cf);
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: Loader::set_task_manager
00113 //       Access: Published
00114 //  Description: Specifies the task manager that is used for
00115 //               asynchronous loads.  The default is the global task
00116 //               manager.
00117 ////////////////////////////////////////////////////////////////////
00118 INLINE void Loader::
00119 set_task_manager(AsyncTaskManager *task_manager) {
00120   _task_manager = task_manager;
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: Loader::get_task_manager
00125 //       Access: Published
00126 //  Description: Returns the task manager that is used for
00127 //               asynchronous loads.
00128 ////////////////////////////////////////////////////////////////////
00129 INLINE AsyncTaskManager *Loader::
00130 get_task_manager() const {
00131   return _task_manager;
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: Loader::set_task_chain
00136 //       Access: Published
00137 //  Description: Specifies the task chain that is used for
00138 //               asynchronous loads.  The default is the initial name
00139 //               of the Loader object.
00140 ////////////////////////////////////////////////////////////////////
00141 INLINE void Loader::
00142 set_task_chain(const string &task_chain) {
00143   _task_chain = task_chain;
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //     Function: Loader::get_task_chain
00148 //       Access: Published
00149 //  Description: Returns the task chain that is used for
00150 //               asynchronous loads.
00151 ////////////////////////////////////////////////////////////////////
00152 INLINE const string &Loader::
00153 get_task_chain() const {
00154   return _task_chain;
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: Loader::stop_threads
00159 //       Access: Published
00160 //  Description: Stop any threads used for asynchronous loads.
00161 ////////////////////////////////////////////////////////////////////
00162 INLINE void Loader::
00163 stop_threads() {
00164   PT(AsyncTaskChain) chain = _task_manager->find_task_chain(_task_chain);
00165   if (chain != (AsyncTaskChain *)NULL) {
00166     chain->stop_threads();
00167   }
00168 }
00169 
00170 ////////////////////////////////////////////////////////////////////
00171 //     Function: Loader::remove
00172 //       Access: Published
00173 //  Description: Removes a pending asynchronous load request.  Returns
00174 //               true if successful, false otherwise.
00175 ////////////////////////////////////////////////////////////////////
00176 INLINE bool Loader::
00177 remove(AsyncTask *task) {
00178   return _task_manager->remove(task);
00179 }
00180 
00181 ////////////////////////////////////////////////////////////////////
00182 //     Function: Loader::load_sync
00183 //       Access: Published
00184 //  Description: Loads the file immediately, waiting for it to
00185 //               complete.
00186 //
00187 //               If search is true, the file is searched for along the
00188 //               model path; otherwise, only the exact filename is
00189 //               loaded.
00190 ////////////////////////////////////////////////////////////////////
00191 INLINE PT(PandaNode) Loader::
00192 load_sync(const Filename &filename, const LoaderOptions &options) const {
00193   if (!_file_types_loaded) {
00194     load_file_types();
00195   }
00196   return load_file(filename, options);
00197 }
00198 
00199 ////////////////////////////////////////////////////////////////////
00200 //     Function: Loader::load_async
00201 //       Access: Published
00202 //  Description: Begins an asynchronous load request.  To use this
00203 //               call, first create a new ModelLoadRequest object with
00204 //               the filename you wish to load, and then add that
00205 //               object to the Loader with load_async.  This function
00206 //               will return immediately, and the model will be loaded
00207 //               in the background.
00208 //
00209 //               To determine when the model has completely loaded,
00210 //               you may poll request->is_ready() from time to time,
00211 //               or set the done_event on the request object and
00212 //               listen for that event.  When the model is ready, you
00213 //               may retrieve it via request->get_model().
00214 ////////////////////////////////////////////////////////////////////
00215 INLINE void Loader::
00216 load_async(AsyncTask *request) {
00217   request->set_task_chain(_task_chain);
00218   _task_manager->add(request);
00219 }
00220 
00221 ////////////////////////////////////////////////////////////////////
00222 //     Function: Loader::get_global_ptr
00223 //       Access: Published
00224 //  Description: Returns a pointer to the global Loader.  This is the
00225 //               Loader that most code should use for loading models.
00226 ////////////////////////////////////////////////////////////////////
00227 INLINE Loader *Loader::
00228 get_global_ptr() {
00229   if (_global_ptr == (Loader *)NULL) {
00230     make_global_ptr();
00231   }
00232   return _global_ptr;
00233 }
 All Classes Functions Variables Enumerations