PageRenderTime 41ms CodeModel.GetById 17ms app.highlight 17ms RepoModel.GetById 2ms 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
  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
 27#ifndef LL_LLVOLUMEMGR_H
 28#define LL_LLVOLUMEMGR_H
 29
 30#include <map>
 31
 32#include "llvolume.h"
 33#include "llpointer.h"
 34#include "llthread.h"
 35
 36class LLVolumeParams;
 37class LLVolumeLODGroup;
 38
 39class LLVolumeLODGroup
 40{
 41	LOG_CLASS(LLVolumeLODGroup);
 42	
 43public:
 44	enum
 45	{
 46		NUM_LODS = 4
 47	};
 48
 49	LLVolumeLODGroup(const LLVolumeParams &params);
 50	~LLVolumeLODGroup();
 51	bool cleanupRefs();
 52
 53	static S32 getDetailFromTan(const F32 tan_angle);
 54	static void getDetailProximity(const F32 tan_angle, F32 &to_lower, F32& to_higher);
 55	static F32 getVolumeScaleFromDetail(const S32 detail);
 56	static S32 getVolumeDetailFromScale(F32 scale);
 57
 58	LLVolume* refLOD(const S32 detail);
 59	BOOL derefLOD(LLVolume *volumep);
 60	S32 getNumRefs() const { return mRefs; }
 61	
 62	const LLVolumeParams* getVolumeParams() const { return &mVolumeParams; };
 63
 64	F32	dump();
 65	friend std::ostream& operator<<(std::ostream& s, const LLVolumeLODGroup& volgroup);
 66
 67protected:
 68	LLVolumeParams mVolumeParams;
 69
 70	S32 mRefs;
 71	S32 mLODRefs[NUM_LODS];
 72	LLPointer<LLVolume> mVolumeLODs[NUM_LODS];
 73	static F32 mDetailThresholds[NUM_LODS];
 74	static F32 mDetailScales[NUM_LODS];
 75	S32		mAccessCount[NUM_LODS];
 76};
 77
 78class LLVolumeMgr
 79{
 80public:
 81	LLVolumeMgr();
 82	virtual ~LLVolumeMgr();
 83	BOOL cleanup();			// Cleanup all volumes being managed, returns TRUE if no dangling references
 84
 85	virtual LLVolumeLODGroup* getGroup( const LLVolumeParams& volume_params ) const;
 86
 87	// whatever calls getVolume() never owns the LLVolume* and
 88	// cannot keep references for long since it may be deleted
 89	// later.  For best results hold it in an LLPointer<LLVolume>.
 90	virtual LLVolume *refVolume(const LLVolumeParams &volume_params, const S32 detail);
 91	virtual void unrefVolume(LLVolume *volumep);
 92
 93	void dump();
 94
 95	// manually call this for mutex magic
 96	void useMutex();
 97
 98	friend std::ostream& operator<<(std::ostream& s, const LLVolumeMgr& volume_mgr);
 99
100protected:
101	void insertGroup(LLVolumeLODGroup* volgroup);
102	// Overridden in llphysics/abstract/utils/llphysicsvolumemanager.h
103	virtual LLVolumeLODGroup* createNewGroup(const LLVolumeParams& volume_params);
104
105protected:
106	typedef std::map<const LLVolumeParams*, LLVolumeLODGroup*, LLVolumeParams::compare> volume_lod_group_map_t;
107	volume_lod_group_map_t mVolumeLODGroups;
108
109	LLMutex* mDataMutex;
110};
111
112#endif // LL_LLVOLUMEMGR_H