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
29class 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 */
42class EXPCL_PANDA_PGRAPH Loader : public TypedReferenceCount, public Namable {
43private:
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:
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
103private:
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
123public:
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
139private:
140 static TypeHandle _type_handle;
141
142 friend class ModelLoadRequest;
143};
144
145#include "loader.I"
146
147#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
This class represents a concrete task performed by an AsyncManager.
Definition asyncTask.h:32
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This is the base class for a family of scene-graph file types that the Loader supports.
Specifies parameters that may be passed to the loader.
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
Definition loader.h:42
A class object that manages a single asynchronous model load request.
A base class for all things which can have a name.
Definition namable.h:26
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...