Panda3D

Loading...
Searching...
No Matches
loader.h
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.h
10 * @author mike
11 * @date 1997-01-09
12 */
13
14#ifndef LOADER_H
15#define LOADER_H
16
17#include "pandabase.h"
18
19#include "namable.h"
20#include "loaderOptions.h"
21#include "pnotify.h"
22#include "pandaNode.h"
23#include "filename.h"
24#include "dSearchPath.h"
25#include "pvector.h"
26#include "asyncTaskManager.h"
27#include "asyncTask.h"
28
29 class LoaderFileType;
30
31/**
32 * A convenient class for loading models from disk, in bam or egg format (or
33 * any of a number of other formats implemented by a LoaderFileType, such as
34 * ptloader).
35 *
36 * This class supports synchronous as well as asynchronous loading. In
37 * asynchronous loading, the model is loaded in the background by a thread,
38 * and an event will be generated when the model is available. If threading
39 * is not available, the asynchronous loading interface may be used, but it
40 * loads synchronously.
41 */
42 class EXPCL_PANDA_PGRAPH Loader : public TypedReferenceCount, public Namable {
43 private:
44 class ConsiderFile {
45 public:
46 Filename _path;
47 LoaderFileType *_type;
48 };
49
50PUBLISHED:
51 class EXPCL_PANDA_PGRAPH Results {
52 PUBLISHED:
53 INLINE Results();
54 INLINE Results(const Results &copy);
55 INLINE void operator = (const Results &copy);
56 INLINE ~Results();
57
58 INLINE void clear();
59 INLINE int get_num_files() const;
60 INLINE const Filename &get_file(int n) const;
61 MAKE_SEQ(get_files, get_num_files, get_file);
62 INLINE LoaderFileType *get_file_type(int n) const;
63 MAKE_SEQ(get_file_types, get_num_files, get_file_type);
64
65 public:
66 INLINE void add_file(const Filename &file, LoaderFileType *type);
67
68 private:
69 typedef pvector<ConsiderFile> Files;
70 Files _files;
71 };
72
73 explicit Loader(const std::string &name = "loader");
74
75 INLINE void set_task_manager(AsyncTaskManager *task_manager);
76 INLINE AsyncTaskManager *get_task_manager() const;
77 INLINE void set_task_chain(const std::string &task_chain);
78 INLINE const std::string &get_task_chain() const;
79
80 BLOCKING INLINE void stop_threads();
81 INLINE bool remove(AsyncTask *task);
82
83 BLOCKING INLINE PT(PandaNode) load_sync(const Filename &filename,
84 const LoaderOptions &options = LoaderOptions()) const;
85
86 PT(AsyncTask) make_async_request(const Filename &filename,
87 const LoaderOptions &options = LoaderOptions());
88 INLINE void load_async(AsyncTask *request);
89
90 INLINE bool save_sync(const Filename &filename, const LoaderOptions &options,
91 PandaNode *node) const;
92 PT(AsyncTask) make_async_save_request(const Filename &filename,
93 const LoaderOptions &options,
94 PandaNode *node);
95 INLINE void save_async(AsyncTask *request);
96
97 BLOCKING PT(PandaNode) load_bam_stream(std::istream &in);
98
99 virtual void output(std::ostream &out) const;
100
101 INLINE static Loader *get_global_ptr();
102
103 private:
104 PT(PandaNode) load_file(const Filename &filename, const LoaderOptions &options) const;
105 PT(PandaNode) try_load_file(const Filename &pathname, const LoaderOptions &options,
106 LoaderFileType *requested_type) const;
107
108 bool save_file(const Filename &filename, const LoaderOptions &options,
109 PandaNode *node) const;
110 bool try_save_file(const Filename &filename, const LoaderOptions &options,
111 PandaNode *node, LoaderFileType *requested_type) const;
112
113 static void make_global_ptr();
114
115 PT(AsyncTaskManager) _task_manager;
116 std::string _task_chain;
117
118 static void load_file_types();
119 static bool _file_types_loaded;
120
121 static PT(Loader) _global_ptr;
122
123 public:
124 static TypeHandle get_class_type() {
125 return _type_handle;
126 }
127 static void init_type() {
128 TypedReferenceCount::init_type();
129 Namable::init_type();
130 register_type(_type_handle, "Loader",
131 TypedReferenceCount::get_class_type(),
132 Namable::get_class_type());
133 }
134 virtual TypeHandle get_type() const {
135 return get_class_type();
136 }
137 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
138
139 private:
140 static TypeHandle _type_handle;
141
142 friend class ModelLoadRequest;
143};
144
145#include "loader.I"
146
147#endif
asyncTaskManager.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
asyncTask.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
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::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::make_async_save_request
PointerTo< AsyncTask > make_async_save_request(const Filename &filename, const LoaderOptions &options, PandaNode *node)
Returns a new AsyncTask object suitable for adding to save_async() to start an asynchronous model sav...
Definition loader.cxx:90
Loader::make_async_request
PointerTo< AsyncTask > make_async_request(const Filename &filename, const LoaderOptions &options=LoaderOptions())
Returns a new AsyncTask object suitable for adding to load_async() to start an asynchronous model loa...
Definition loader.cxx:80
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::load_bam_stream
PointerTo< PandaNode > load_bam_stream(std::istream &in)
Attempts to read a bam file from the indicated stream and return the scene graph defined there.
Definition loader.cxx:101
Loader::remove
bool remove(AsyncTask *task)
Removes a pending asynchronous load request.
Definition loader.I:141
Namable::output
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
PandaNode
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
dSearchPath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
loaderOptions.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
loader.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
namable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandaNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22