Panda3D
modelPool.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 modelPool.h
10  * @author drose
11  * @date 2002-03-12
12  */
13 
14 #ifndef MODELPOOL_H
15 #define MODELPOOL_H
16 
17 #include "pandabase.h"
18 
19 #include "filename.h"
20 #include "modelRoot.h"
21 #include "pointerTo.h"
22 #include "lightMutex.h"
23 #include "pmap.h"
24 #include "loaderOptions.h"
25 
26 /**
27  * This class unifies all references to the same filename, so that multiple
28  * attempts to load the same model will return the same pointer. Note that
29  * the default behavior is thus to make instances: use with caution. Use the
30  * copy_subgraph() method on Node (or use NodePath::copy_to) to make
31  * modifiable copies of the node.
32  *
33  * Unlike TexturePool, this class does not automatically resolve the model
34  * filenames before loading, so a relative path and an absolute path to the
35  * same model will appear to be different filenames.
36  *
37  * However, see the Loader class, which is now the preferred interface for
38  * loading models. The Loader class can resolve filenames, supports threaded
39  * loading, and can automatically consult the ModelPool, according to the
40  * supplied LoaderOptions.
41  */
42 class EXPCL_PANDA_PGRAPH ModelPool {
43 PUBLISHED:
44  INLINE static bool has_model(const Filename &filename);
45  INLINE static bool verify_model(const Filename &filename);
46  INLINE static ModelRoot *get_model(const Filename &filename, bool verify);
47  BLOCKING INLINE static ModelRoot *load_model(const Filename &filename,
48  const LoaderOptions &options = LoaderOptions());
49 
50  INLINE static void add_model(const Filename &filename, ModelRoot *model);
51  INLINE static void release_model(const Filename &filename);
52 
53  INLINE static void add_model(ModelRoot *model);
54  INLINE static void release_model(ModelRoot *model);
55 
56  INLINE static void release_all_models();
57 
58  INLINE static int garbage_collect();
59 
60  INLINE static void list_contents(std::ostream &out);
61  INLINE static void list_contents();
62  static void write(std::ostream &out);
63 
64 private:
65  INLINE ModelPool();
66 
67  bool ns_has_model(const Filename &filename);
68  ModelRoot *ns_get_model(const Filename &filename, bool verify);
69  ModelRoot *ns_load_model(const Filename &filename,
70  const LoaderOptions &options);
71  void ns_add_model(const Filename &filename, ModelRoot *model);
72  void ns_release_model(const Filename &filename);
73 
74  void ns_add_model(ModelRoot *model);
75  void ns_release_model(ModelRoot *model);
76 
77  void ns_release_all_models();
78  int ns_garbage_collect();
79  void ns_list_contents(std::ostream &out) const;
80 
81  static ModelPool *get_ptr();
82 
83  static ModelPool *_global_ptr;
84 
85  LightMutex _lock;
86  typedef pmap<Filename, PT(ModelRoot) > Models;
87  Models _models;
88 };
89 
90 #include "modelPool.I"
91 
92 #endif
A node of this type is created automatically at the root of each model file that is loaded.
Definition: modelRoot.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:23
This class unifies all references to the same filename, so that multiple attempts to load the same mo...
Definition: modelPool.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.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:39