Panda3D

Loading...
Searching...
No Matches
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 {
43PUBLISHED:
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
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
LightMutex
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
LoaderOptions
Specifies parameters that may be passed to the loader.
Definition loaderOptions.h:23
ModelPool::garbage_collect
static int garbage_collect()
Releases only those models in the pool that have a reference count of exactly 1; i....
Definition modelPool.I:123
ModelPool::add_model
static void add_model(const Filename &filename, ModelRoot *model)
Adds the indicated already-loaded model to the pool.
Definition modelPool.I:69
ModelPool::get_model
static ModelRoot * get_model(const Filename &filename, bool verify)
Returns the model that has already been previously loaded, or NULL otherwise.
Definition modelPool.I:46
ModelPool::list_contents
static void list_contents(std::ostream &out)
Lists the contents of the model pool to the indicated output stream.
Definition modelPool.I:131
ModelPool::load_model
static ModelRoot * load_model(const Filename &filename, const LoaderOptions &options=LoaderOptions())
Loads the given filename up as a model, if it has not already been loaded, and returns the new model.
Definition modelPool.I:58
ModelPool::has_model
static bool has_model(const Filename &filename)
Returns true if the model has ever been loaded, false otherwise.
Definition modelPool.I:19
ModelPool::release_model
static void release_model(const Filename &filename)
Removes the indicated model from the pool, indicating it will never be loaded again; the model may th...
Definition modelPool.I:82
ModelPool::release_all_models
static void release_all_models()
Releases all models in the pool and restores the pool to the empty state.
Definition modelPool.I:113
ModelPool::write
static void write(std::ostream &out)
Lists the contents of the model pool to the indicated output stream.
Definition modelPool.cxx:28
ModelPool::verify_model
static bool verify_model(const Filename &filename)
Loads the given filename up as a model, if it has not already been loaded, and returns true to indica...
Definition modelPool.I:35
ModelRoot
A node of this type is created automatically at the root of each model file that is loaded.
Definition modelRoot.h:27
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lightMutex.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
loaderOptions.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
modelPool.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
modelRoot.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.