Panda3D

modelPool.h

00001 // Filename: modelPool.h
00002 // Created by:  drose (12Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef MODELPOOL_H
00016 #define MODELPOOL_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "filename.h"
00021 #include "modelRoot.h"
00022 #include "pointerTo.h"
00023 #include "lightMutex.h"
00024 #include "pmap.h"
00025 #include "loaderOptions.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : ModelPool
00029 // Description : This class unifies all references to the same
00030 //               filename, so that multiple attempts to load the same
00031 //               model will return the same pointer.  Note that the
00032 //               default behavior is thus to make instances: use with
00033 //               caution.  Use the copy_subgraph() method on Node (or
00034 //               use NodePath::copy_to) to make modifiable copies of
00035 //               the node.
00036 //
00037 //               Unlike TexturePool, this class does not automatically
00038 //               resolve the model filenames before loading, so a
00039 //               relative path and an absolute path to the same model
00040 //               will appear to be different filenames.
00041 //
00042 //               However, see the Loader class, which is now the
00043 //               preferred interface for loading models.  The Loader
00044 //               class can resolve filenames, supports threaded
00045 //               loading, and can automatically consult the ModelPool,
00046 //               according to the supplied LoaderOptions.
00047 ////////////////////////////////////////////////////////////////////
00048 class EXPCL_PANDA_PGRAPH ModelPool {
00049 PUBLISHED:
00050   INLINE static bool has_model(const Filename &filename);
00051   INLINE static bool verify_model(const Filename &filename);
00052   INLINE static ModelRoot *load_model(const Filename &filename,
00053                                       const LoaderOptions &options = LoaderOptions());
00054 
00055   INLINE static void add_model(const Filename &filename, ModelRoot *model);
00056   INLINE static void release_model(const Filename &filename);
00057 
00058   INLINE static void add_model(ModelRoot *model);
00059   INLINE static void release_model(ModelRoot *model);
00060 
00061   INLINE static void release_all_models();
00062 
00063   INLINE static int garbage_collect();
00064 
00065   INLINE static void list_contents(ostream &out);
00066   INLINE static void list_contents();
00067   static void write(ostream &out);
00068 
00069 private:
00070   INLINE ModelPool();
00071 
00072   bool ns_has_model(const Filename &filename);
00073   ModelRoot *ns_load_model(const Filename &filename,
00074                            const LoaderOptions &options);
00075   void ns_add_model(const Filename &filename, ModelRoot *model);
00076   void ns_release_model(const Filename &filename);
00077 
00078   void ns_add_model(ModelRoot *model);
00079   void ns_release_model(ModelRoot *model);
00080 
00081   void ns_release_all_models();
00082   int ns_garbage_collect();
00083   void ns_list_contents(ostream &out) const;
00084 
00085   static ModelPool *get_ptr();
00086 
00087   static ModelPool *_global_ptr;
00088 
00089   LightMutex _lock;
00090   typedef pmap<Filename,  PT(ModelRoot) > Models;
00091   Models _models;
00092 };
00093 
00094 #include "modelPool.I"
00095 
00096 #endif
00097 
00098 
 All Classes Functions Variables Enumerations