PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/llvolumemgr.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 112 lines | 59 code | 23 blank | 30 comment | 0 complexity | a7651ab9b25827799b5d4a9e44538fed MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvolumemgr.h
  3. * @brief LLVolumeMgr class.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLVOLUMEMGR_H
  27. #define LL_LLVOLUMEMGR_H
  28. #include <map>
  29. #include "llvolume.h"
  30. #include "llpointer.h"
  31. #include "llthread.h"
  32. class LLVolumeParams;
  33. class LLVolumeLODGroup;
  34. class LLVolumeLODGroup
  35. {
  36. LOG_CLASS(LLVolumeLODGroup);
  37. public:
  38. enum
  39. {
  40. NUM_LODS = 4
  41. };
  42. LLVolumeLODGroup(const LLVolumeParams &params);
  43. ~LLVolumeLODGroup();
  44. bool cleanupRefs();
  45. static S32 getDetailFromTan(const F32 tan_angle);
  46. static void getDetailProximity(const F32 tan_angle, F32 &to_lower, F32& to_higher);
  47. static F32 getVolumeScaleFromDetail(const S32 detail);
  48. static S32 getVolumeDetailFromScale(F32 scale);
  49. LLVolume* refLOD(const S32 detail);
  50. BOOL derefLOD(LLVolume *volumep);
  51. S32 getNumRefs() const { return mRefs; }
  52. const LLVolumeParams* getVolumeParams() const { return &mVolumeParams; };
  53. F32 dump();
  54. friend std::ostream& operator<<(std::ostream& s, const LLVolumeLODGroup& volgroup);
  55. protected:
  56. LLVolumeParams mVolumeParams;
  57. S32 mRefs;
  58. S32 mLODRefs[NUM_LODS];
  59. LLPointer<LLVolume> mVolumeLODs[NUM_LODS];
  60. static F32 mDetailThresholds[NUM_LODS];
  61. static F32 mDetailScales[NUM_LODS];
  62. S32 mAccessCount[NUM_LODS];
  63. };
  64. class LLVolumeMgr
  65. {
  66. public:
  67. LLVolumeMgr();
  68. virtual ~LLVolumeMgr();
  69. BOOL cleanup(); // Cleanup all volumes being managed, returns TRUE if no dangling references
  70. virtual LLVolumeLODGroup* getGroup( const LLVolumeParams& volume_params ) const;
  71. // whatever calls getVolume() never owns the LLVolume* and
  72. // cannot keep references for long since it may be deleted
  73. // later. For best results hold it in an LLPointer<LLVolume>.
  74. virtual LLVolume *refVolume(const LLVolumeParams &volume_params, const S32 detail);
  75. virtual void unrefVolume(LLVolume *volumep);
  76. void dump();
  77. // manually call this for mutex magic
  78. void useMutex();
  79. friend std::ostream& operator<<(std::ostream& s, const LLVolumeMgr& volume_mgr);
  80. protected:
  81. void insertGroup(LLVolumeLODGroup* volgroup);
  82. // Overridden in llphysics/abstract/utils/llphysicsvolumemanager.h
  83. virtual LLVolumeLODGroup* createNewGroup(const LLVolumeParams& volume_params);
  84. protected:
  85. typedef std::map<const LLVolumeParams*, LLVolumeLODGroup*, LLVolumeParams::compare> volume_lod_group_map_t;
  86. volume_lod_group_map_t mVolumeLODGroups;
  87. LLMutex* mDataMutex;
  88. };
  89. #endif // LL_LLVOLUMEMGR_H