Introduced mutex into Terrain node to manage the tile system data structures
This commit is contained in:
parent
49accb1635
commit
3f81a994b7
@ -36,17 +36,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
|||||||
|
|
||||||
virtual void traverse(osg::NodeVisitor& nv);
|
virtual void traverse(osg::NodeVisitor& nv);
|
||||||
|
|
||||||
|
|
||||||
/** Set the TerrainTechnique that is used as the prototype for all Terrain below the Terrain. */
|
|
||||||
void setTerrainTechnique(osgTerrain::TerrainTechnique* TerrainTechnique);
|
|
||||||
|
|
||||||
/** Get the TerrainTechnique*/
|
|
||||||
TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
|
|
||||||
|
|
||||||
/** Get the const TerrainTechnique*/
|
|
||||||
const TerrainTechnique* getTerrainTechnique() const { return _terrainTechnique.get(); }
|
|
||||||
|
|
||||||
|
|
||||||
/** Get the TerrainTile for a given TileID.*/
|
/** Get the TerrainTile for a given TileID.*/
|
||||||
TerrainTile* getTile(const TileID& tileID);
|
TerrainTile* getTile(const TileID& tileID);
|
||||||
|
|
||||||
@ -65,9 +54,7 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
|||||||
typedef std::map< TileID, TerrainTile* > TerrainTileMap;
|
typedef std::map< TileID, TerrainTile* > TerrainTileMap;
|
||||||
typedef std::set< TerrainTile* > TerrainTileSet;
|
typedef std::set< TerrainTile* > TerrainTileSet;
|
||||||
|
|
||||||
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
|
mutable OpenThreads::Mutex _mutex;
|
||||||
|
|
||||||
|
|
||||||
TerrainTileSet _terrainTileSet;
|
TerrainTileSet _terrainTileSet;
|
||||||
TerrainTileMap _terrainTileMap;
|
TerrainTileMap _terrainTileMap;
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
* OpenSceneGraph Public License for more details.
|
* OpenSceneGraph Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OSGTERRAIN_terrainTileTECHNIQUE
|
#ifndef OSGTERRAIN_TERRAINTECHNIQUE
|
||||||
#define OSGTERRAIN_terrainTileTECHNIQUE 1
|
#define OSGTERRAIN_TERRAINTECHNIQUE 1
|
||||||
|
|
||||||
#include <osg/Object>
|
#include <osg/Object>
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <osgTerrain/Terrain>
|
#include <osgTerrain/Terrain>
|
||||||
|
#include <OpenThreads/ScopedLock>
|
||||||
|
|
||||||
using namespace osg;
|
using namespace osg;
|
||||||
using namespace osgTerrain;
|
using namespace osgTerrain;
|
||||||
@ -20,8 +21,16 @@ Terrain::Terrain()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop):
|
||||||
|
osg::Group(ts,copyop)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Terrain::~Terrain()
|
Terrain::~Terrain()
|
||||||
{
|
{
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||||
|
|
||||||
for(TerrainTileSet::iterator itr = _terrainTileSet.begin();
|
for(TerrainTileSet::iterator itr = _terrainTileSet.begin();
|
||||||
itr != _terrainTileSet.end();
|
itr != _terrainTileSet.end();
|
||||||
++itr)
|
++itr)
|
||||||
@ -33,10 +42,6 @@ Terrain::~Terrain()
|
|||||||
_terrainTileMap.clear();
|
_terrainTileMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Terrain::traverse(osg::NodeVisitor& nv)
|
void Terrain::traverse(osg::NodeVisitor& nv)
|
||||||
{
|
{
|
||||||
Group::traverse(nv);
|
Group::traverse(nv);
|
||||||
@ -44,6 +49,8 @@ void Terrain::traverse(osg::NodeVisitor& nv)
|
|||||||
|
|
||||||
TerrainTile* Terrain::getTile(const TileID& tileID)
|
TerrainTile* Terrain::getTile(const TileID& tileID)
|
||||||
{
|
{
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||||
|
|
||||||
TerrainTileMap::iterator itr = _terrainTileMap.find(tileID);
|
TerrainTileMap::iterator itr = _terrainTileMap.find(tileID);
|
||||||
if (itr != _terrainTileMap.end()) return 0;
|
if (itr != _terrainTileMap.end()) return 0;
|
||||||
|
|
||||||
@ -52,16 +59,21 @@ TerrainTile* Terrain::getTile(const TileID& tileID)
|
|||||||
|
|
||||||
const TerrainTile* Terrain::getTile(const TileID& tileID) const
|
const TerrainTile* Terrain::getTile(const TileID& tileID) const
|
||||||
{
|
{
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||||
|
|
||||||
TerrainTileMap::const_iterator itr = _terrainTileMap.find(tileID);
|
TerrainTileMap::const_iterator itr = _terrainTileMap.find(tileID);
|
||||||
if (itr != _terrainTileMap.end()) return 0;
|
if (itr != _terrainTileMap.end()) return 0;
|
||||||
|
|
||||||
return itr->second;
|
return itr->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int s_maxNumTiles = 0;
|
||||||
void Terrain::registerTerrainTile(TerrainTile* tile)
|
void Terrain::registerTerrainTile(TerrainTile* tile)
|
||||||
{
|
{
|
||||||
if (!tile) return;
|
if (!tile) return;
|
||||||
|
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||||
|
|
||||||
if (tile->getTileID().valid())
|
if (tile->getTileID().valid())
|
||||||
{
|
{
|
||||||
_terrainTileMap[tile->getTileID()] = tile;
|
_terrainTileMap[tile->getTileID()] = tile;
|
||||||
@ -69,13 +81,17 @@ void Terrain::registerTerrainTile(TerrainTile* tile)
|
|||||||
|
|
||||||
_terrainTileSet.insert(tile);
|
_terrainTileSet.insert(tile);
|
||||||
|
|
||||||
osg::notify(osg::INFO)<<"Terrain::registerTerrainTile "<<tile<<" total number of tile "<<_terrainTileSet.size()<<std::endl;
|
if (_terrainTileSet.size() > s_maxNumTiles) s_maxNumTiles = _terrainTileSet.size();
|
||||||
|
|
||||||
|
// osg::notify(osg::NOTICE)<<"Terrain::registerTerrainTile "<<tile<<" total number of tile "<<_terrainTileSet.size()<<" max = "<<s_maxNumTiles<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terrain::unregisterTerrainTile(TerrainTile* tile)
|
void Terrain::unregisterTerrainTile(TerrainTile* tile)
|
||||||
{
|
{
|
||||||
if (!tile) return;
|
if (!tile) return;
|
||||||
|
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||||
|
|
||||||
if (tile->getTileID().valid())
|
if (tile->getTileID().valid())
|
||||||
{
|
{
|
||||||
_terrainTileMap.erase(tile->getTileID());
|
_terrainTileMap.erase(tile->getTileID());
|
||||||
@ -83,5 +99,5 @@ void Terrain::unregisterTerrainTile(TerrainTile* tile)
|
|||||||
|
|
||||||
_terrainTileSet.erase(tile);
|
_terrainTileSet.erase(tile);
|
||||||
|
|
||||||
osg::notify(osg::INFO)<<"Terrain::unregisterTerrainTile "<<tile<<" total number of tile "<<_terrainTileSet.size()<<std::endl;
|
// osg::notify(osg::NOTICE)<<"Terrain::unregisterTerrainTile "<<tile<<" total number of tile "<<_terrainTileSet.size()<<" max = "<<s_maxNumTiles<<std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user