Panda3D
 All Classes Functions Variables Enumerations
loader.h
1 // Filename: loader.h
2 // Created by: mike (09Jan97)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef LOADER_H
16 #define LOADER_H
17 
18 #include "pandabase.h"
19 
20 #include "namable.h"
21 #include "loaderOptions.h"
22 #include "pnotify.h"
23 #include "pandaNode.h"
24 #include "filename.h"
25 #include "dSearchPath.h"
26 #include "pvector.h"
27 #include "asyncTaskManager.h"
28 #include "asyncTask.h"
29 
30 class LoaderFileType;
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : Loader
34 // Description : A convenient class for loading models from disk, in
35 // bam or egg format (or any of a number of other
36 // formats implemented by a LoaderFileType, such as
37 // ptloader).
38 //
39 // This class supports synchronous as well as
40 // asynchronous loading. In asynchronous loading, the
41 // model is loaded in the background by a thread, and an
42 // event will be generated when the model is available.
43 // If threading is not available, the asynchronous
44 // loading interface may be used, but it loads
45 // synchronously.
46 ////////////////////////////////////////////////////////////////////
47 class EXPCL_PANDA_PGRAPH Loader : public TypedReferenceCount, public Namable {
48 private:
49  class ConsiderFile {
50  public:
51  Filename _path;
52  LoaderFileType *_type;
53  };
54 
55 PUBLISHED:
56  class EXPCL_PANDA_PGRAPH Results {
57  PUBLISHED:
58  INLINE Results();
59  INLINE Results(const Results &copy);
60  INLINE void operator = (const Results &copy);
61  INLINE ~Results();
62 
63  INLINE void clear();
64  INLINE int get_num_files() const;
65  INLINE const Filename &get_file(int n) const;
66  MAKE_SEQ(get_files, get_num_files, get_file);
67  INLINE LoaderFileType *get_file_type(int n) const;
68  MAKE_SEQ(get_file_types, get_num_files, get_file_type);
69 
70  public:
71  INLINE void add_file(const Filename &file, LoaderFileType *type);
72 
73  private:
75  Files _files;
76  };
77 
78  Loader(const string &name = "loader");
79 
80  INLINE void set_task_manager(AsyncTaskManager *task_manager);
81  INLINE AsyncTaskManager *get_task_manager() const;
82  INLINE void set_task_chain(const string &task_chain);
83  INLINE const string &get_task_chain() const;
84 
85  BLOCKING INLINE void stop_threads();
86  INLINE bool remove(AsyncTask *task);
87 
88  BLOCKING INLINE PT(PandaNode) load_sync(const Filename &filename,
89  const LoaderOptions &options = LoaderOptions()) const;
90 
91  PT(AsyncTask) make_async_request(const Filename &filename,
92  const LoaderOptions &options = LoaderOptions());
93  INLINE void load_async(AsyncTask *request);
94 
95  INLINE bool save_sync(const Filename &filename, const LoaderOptions &options,
96  PandaNode *node) const;
97  PT(AsyncTask) make_async_save_request(const Filename &filename,
98  const LoaderOptions &options,
99  PandaNode *node);
100  INLINE void save_async(AsyncTask *request);
101 
102  BLOCKING PT(PandaNode) load_bam_stream(istream &in);
103 
104  virtual void output(ostream &out) const;
105 
106  INLINE static Loader *get_global_ptr();
107 
108 private:
109  PT(PandaNode) load_file(const Filename &filename, const LoaderOptions &options) const;
110  PT(PandaNode) try_load_file(const Filename &pathname, const LoaderOptions &options,
111  LoaderFileType *requested_type) const;
112 
113  bool save_file(const Filename &filename, const LoaderOptions &options,
114  PandaNode *node) const;
115  bool try_save_file(const Filename &filename, const LoaderOptions &options,
116  PandaNode *node, LoaderFileType *requested_type) const;
117 
118  static void make_global_ptr();
119 
120  PT(AsyncTaskManager) _task_manager;
121  string _task_chain;
122 
123  static void load_file_types();
124  static bool _file_types_loaded;
125 
126  static PT(Loader) _global_ptr;
127 
128 public:
129  static TypeHandle get_class_type() {
130  return _type_handle;
131  }
132  static void init_type() {
133  TypedReferenceCount::init_type();
134  Namable::init_type();
135  register_type(_type_handle, "Loader",
136  TypedReferenceCount::get_class_type(),
137  Namable::get_class_type());
138  }
139  virtual TypeHandle get_type() const {
140  return get_class_type();
141  }
142  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
143 
144 private:
145  static TypeHandle _type_handle;
146 
147  friend class ModelLoadRequest;
148 };
149 
150 #include "loader.I"
151 
152 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:26
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
Definition: loader.h:47
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A base class for all things which can have a name.
Definition: namable.h:29
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This class represents a concrete task performed by an AsyncManager.
Definition: asyncTask.h:43
This is the base class for a family of scene-graph file types that the Loader supports.
A class object that manages a single asynchronous model load request.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85