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