Panda3D

Loading...
Searching...
No Matches
loader.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 loader.I
10 * @author mike
11 * @date 1997-01-09
12 */
13
14/**
15 *
16 */
17INLINE Loader::Results::
18Results() {
19}
20
21/**
22 *
23 */
24INLINE Loader::Results::
25Results(const Loader::Results &copy) :
26 _files(copy._files)
27{
28}
29
30/**
31 *
32 */
33INLINE void Loader::Results::
34operator = (const Loader::Results &copy) {
35 _files = copy._files;
36}
37
38/**
39 *
40 */
41INLINE Loader::Results::
42~Results() {
43}
44
45/**
46 * Removes all the files from the list.
47 */
48INLINE void Loader::Results::
49 clear() {
50 _files.clear();
51}
52
53/**
54 * Returns the number of files on the result list.
55 */
56INLINE int Loader::Results::
57 get_num_files() const {
58 return _files.size();
59}
60
61/**
62 * Returns the nth file on the result list.
63 */
64INLINE const Filename &Loader::Results::
65 get_file(int n) const {
66 nassertr(n >= 0 && n < (int)_files.size(), _files[0]._path);
67 return _files[n]._path;
68}
69
70/**
71 * Returns the file type of the nth file on the result list.
72 */
73INLINE LoaderFileType *Loader::Results::
74 get_file_type(int n) const {
75 nassertr(n >= 0 && n < (int)_files.size(), nullptr);
76 return _files[n]._type;
77}
78
79/**
80 * Adds a new file to the result list.
81 */
82INLINE void Loader::Results::
83 add_file(const Filename &file, LoaderFileType *type) {
84 ConsiderFile cf;
85 cf._path = file;
86 cf._type = type;
87 _files.push_back(cf);
88}
89
90/**
91 * Specifies the task manager that is used for asynchronous loads. The
92 * default is the global task manager.
93 */
94INLINE void Loader::
95 set_task_manager(AsyncTaskManager *task_manager) {
96 _task_manager = task_manager;
97}
98
99/**
100 * Returns the task manager that is used for asynchronous loads.
101 */
102INLINE AsyncTaskManager *Loader::
103 get_task_manager() const {
104 return _task_manager;
105}
106
107/**
108 * Specifies the task chain that is used for asynchronous loads. The default
109 * is the initial name of the Loader object.
110 */
111INLINE void Loader::
112 set_task_chain(const std::string &task_chain) {
113 _task_chain = task_chain;
114}
115
116/**
117 * Returns the task chain that is used for asynchronous loads.
118 */
119INLINE const std::string &Loader::
120 get_task_chain() const {
121 return _task_chain;
122}
123
124/**
125 * Stop any threads used for asynchronous loads.
126 */
127INLINE void Loader::
128 stop_threads() {
129 PT(AsyncTaskChain) chain = _task_manager->find_task_chain(_task_chain);
130 if (chain != nullptr) {
131 chain->stop_threads();
132 }
133}
134
135/**
136 * Removes a pending asynchronous load request. Returns true if successful,
137 * false otherwise.
138 * @deprecated use task.cancel() to cancel the request instead.
139 */
140INLINE bool Loader::
141 remove(AsyncTask *task) {
142 return _task_manager->remove(task);
143}
144
145/**
146 * Loads the file immediately, waiting for it to complete.
147 *
148 * If search is true, the file is searched for along the model path;
149 * otherwise, only the exact filename is loaded.
150 */
151INLINE PT(PandaNode) Loader::
152load_sync(const Filename &filename, const LoaderOptions &options) const {
153 if (!_file_types_loaded) {
154 load_file_types();
155 }
156 return load_file(filename, options);
157}
158
159/**
160 * Begins an asynchronous load request. To use this call, first call
161 * make_async_request() to create a new ModelLoadRequest object with the
162 * filename you wish to load, and then add that object to the Loader with
163 * load_async. This function will return immediately, and the model will be
164 * loaded in the background.
165 *
166 * To determine when the model has completely loaded, you may poll
167 * request->is_ready() from time to time, or set the done_event on the request
168 * object and listen for that event. When the model is ready, you may
169 * retrieve it via request->get_model().
170 */
171INLINE void Loader::
172load_async(AsyncTask *request) {
173 request->set_task_chain(_task_chain);
174 _task_manager->add(request);
175}
176
177/**
178 * Saves the file immediately, waiting for it to complete.
179 */
180INLINE bool Loader::
181 save_sync(const Filename &filename, const LoaderOptions &options,
182 PandaNode *node) const {
183 if (!_file_types_loaded) {
184 load_file_types();
185 }
186 return save_file(filename, options, node);
187}
188
189/**
190 * Begins an asynchronous save request. To use this call, first call
191 * make_async_save_request() to create a new ModelSaveRequest object with the
192 * filename you wish to load, and then add that object to the Loader with
193 * save_async. This function will return immediately, and the model will be
194 * loaded in the background.
195 *
196 * To determine when the model has completely loaded, you may poll
197 * request->is_ready() from time to time, or set the done_event on the request
198 * object and listen for that event. When the request is ready, you may
199 * retrieve the success or failure via request->get_success().
200 */
201INLINE void Loader::
202 save_async(AsyncTask *request) {
203 request->set_task_chain(_task_chain);
204 _task_manager->add(request);
205}
206
207/**
208 * Returns a pointer to the global Loader. This is the Loader that most code
209 * should use for loading models.
210 */
211INLINE Loader *Loader::
212 get_global_ptr() {
213 if (_global_ptr == nullptr) {
214 make_global_ptr();
215 }
216 return _global_ptr;
217}
AsyncTaskChain
The AsyncTaskChain is a subset of the AsyncTaskManager.
Definition asyncTaskChain.h:50
AsyncTaskManager
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
Definition asyncTaskManager.h:48
AsyncTask
This class represents a concrete task performed by an AsyncManager.
Definition asyncTask.h:32
AsyncTask::set_task_chain
set_task_chain
Specifies the AsyncTaskChain on which this task will be running.
Definition asyncTask.h:114
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
LoaderFileType
This is the base class for a family of scene-graph file types that the Loader supports.
Definition loaderFileType.h:33
LoaderOptions
Specifies parameters that may be passed to the loader.
Definition loaderOptions.h:23
Loader::Results
Definition loader.h:51
Loader::Results::add_file
void add_file(const Filename &file, LoaderFileType *type)
Adds a new file to the result list.
Definition loader.I:83
Loader::Results::get_file
get_file
Returns the nth file on the result list.
Definition loader.h:61
Loader::Results::get_num_files
get_num_files
Returns the number of files on the result list.
Definition loader.h:61
Loader::Results::get_file_type
get_file_type
Returns the file type of the nth file on the result list.
Definition loader.h:63
Loader::Results::clear
void clear()
Removes all the files from the list.
Definition loader.I:49
Loader::get_global_ptr
static Loader * get_global_ptr()
Returns a pointer to the global Loader.
Definition loader.I:212
Loader::save_async
void save_async(AsyncTask *request)
Begins an asynchronous save request.
Definition loader.I:202
Loader::set_task_chain
void set_task_chain(const std::string &task_chain)
Specifies the task chain that is used for asynchronous loads.
Definition loader.I:112
Loader::get_task_manager
AsyncTaskManager * get_task_manager() const
Returns the task manager that is used for asynchronous loads.
Definition loader.I:103
Loader::get_task_chain
const std::string & get_task_chain() const
Returns the task chain that is used for asynchronous loads.
Definition loader.I:120
Loader::save_sync
bool save_sync(const Filename &filename, const LoaderOptions &options, PandaNode *node) const
Saves the file immediately, waiting for it to complete.
Definition loader.I:181
Loader::set_task_manager
void set_task_manager(AsyncTaskManager *task_manager)
Specifies the task manager that is used for asynchronous loads.
Definition loader.I:95
Loader::stop_threads
void stop_threads()
Stop any threads used for asynchronous loads.
Definition loader.I:128
Loader::remove
bool remove(AsyncTask *task)
Removes a pending asynchronous load request.
Definition loader.I:141
PandaNode
A basic node of the scene graph or data graph.
Definition pandaNode.h:65