modelPool.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Filename: modelPool.h
  2. // Created by: drose (12Mar02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef MODELPOOL_H
  19. #define MODELPOOL_H
  20. #include "pandabase.h"
  21. #include "filename.h"
  22. #include "pandaNode.h"
  23. #include "pointerTo.h"
  24. #include "pmap.h"
  25. ////////////////////////////////////////////////////////////////////
  26. // Class : ModelPool
  27. // Description : This is the preferred interface for loading models.
  28. // It unifies all references to the same filename, so
  29. // that multiple attempts to load the same model will
  30. // return the same pointer. Note that the default
  31. // behavior is thus to make instances: use with caution.
  32. // Use the copy_subgraph() method on Node (or use
  33. // NodePath::copy_to) to make modifiable copies of the
  34. // node.
  35. //
  36. // Unlike TexturePool, this class does not automatically
  37. // resolve the model filenames before loading, so a
  38. // relative path and an absolute path to the same model
  39. // will appear to be different filenames.
  40. //
  41. // This does not presently support asynchronous loading,
  42. // although it wouldn't be *too* difficult to add.
  43. ////////////////////////////////////////////////////////////////////
  44. class EXPCL_PANDA ModelPool {
  45. PUBLISHED:
  46. INLINE static bool has_model(const string &filename);
  47. INLINE static bool verify_model(const string &filename);
  48. INLINE static PandaNode *load_model(const string &filename);
  49. INLINE static void add_model(const string &filename, PandaNode *model);
  50. INLINE static void release_model(const string &filename);
  51. INLINE static void release_all_models();
  52. INLINE static int garbage_collect();
  53. INLINE static void list_contents(ostream &out);
  54. private:
  55. INLINE ModelPool();
  56. bool ns_has_model(const string &filename);
  57. PandaNode *ns_load_model(const string &filename);
  58. void ns_add_model(const string &filename, PandaNode *model);
  59. void ns_release_model(const string &filename);
  60. void ns_release_all_models();
  61. int ns_garbage_collect();
  62. void ns_list_contents(ostream &out);
  63. static ModelPool *get_ptr();
  64. static ModelPool *_global_ptr;
  65. typedef pmap<string, PT(PandaNode) > Models;
  66. Models _models;
  67. };
  68. #include "modelPool.I"
  69. #endif