From 3f81a994b7efea492c5d9cfe7e57b0b6b79f3973 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 28 Mar 2008 15:31:46 +0000 Subject: [PATCH] Introduced mutex into Terrain node to manage the tile system data structures --- include/osgTerrain/Terrain | 19 +++---------------- include/osgTerrain/TerrainTechnique | 4 ++-- src/osgTerrain/Terrain.cpp | 28 ++++++++++++++++++++++------ 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/osgTerrain/Terrain b/include/osgTerrain/Terrain index 7a5553f66..e30888d21 100644 --- a/include/osgTerrain/Terrain +++ b/include/osgTerrain/Terrain @@ -36,17 +36,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group 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.*/ TerrainTile* getTile(const TileID& tileID); @@ -65,11 +54,9 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group typedef std::map< TileID, TerrainTile* > TerrainTileMap; typedef std::set< TerrainTile* > TerrainTileSet; - osg::ref_ptr _terrainTechnique; - - - TerrainTileSet _terrainTileSet; - TerrainTileMap _terrainTileMap; + mutable OpenThreads::Mutex _mutex; + TerrainTileSet _terrainTileSet; + TerrainTileMap _terrainTileMap; diff --git a/include/osgTerrain/TerrainTechnique b/include/osgTerrain/TerrainTechnique index 239443934..d5dbe5d13 100644 --- a/include/osgTerrain/TerrainTechnique +++ b/include/osgTerrain/TerrainTechnique @@ -11,8 +11,8 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSGTERRAIN_terrainTileTECHNIQUE -#define OSGTERRAIN_terrainTileTECHNIQUE 1 +#ifndef OSGTERRAIN_TERRAINTECHNIQUE +#define OSGTERRAIN_TERRAINTECHNIQUE 1 #include diff --git a/src/osgTerrain/Terrain.cpp b/src/osgTerrain/Terrain.cpp index 16816fe04..3e248d4e7 100644 --- a/src/osgTerrain/Terrain.cpp +++ b/src/osgTerrain/Terrain.cpp @@ -12,6 +12,7 @@ */ #include +#include using namespace osg; using namespace osgTerrain; @@ -20,8 +21,16 @@ Terrain::Terrain() { } +Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop): + osg::Group(ts,copyop) +{ +} + + Terrain::~Terrain() { + OpenThreads::ScopedLock lock(_mutex); + for(TerrainTileSet::iterator itr = _terrainTileSet.begin(); itr != _terrainTileSet.end(); ++itr) @@ -33,10 +42,6 @@ Terrain::~Terrain() _terrainTileMap.clear(); } -Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop) -{ -} - void Terrain::traverse(osg::NodeVisitor& nv) { Group::traverse(nv); @@ -44,6 +49,8 @@ void Terrain::traverse(osg::NodeVisitor& nv) TerrainTile* Terrain::getTile(const TileID& tileID) { + OpenThreads::ScopedLock lock(_mutex); + TerrainTileMap::iterator itr = _terrainTileMap.find(tileID); if (itr != _terrainTileMap.end()) return 0; @@ -52,15 +59,20 @@ TerrainTile* Terrain::getTile(const TileID& tileID) const TerrainTile* Terrain::getTile(const TileID& tileID) const { + OpenThreads::ScopedLock lock(_mutex); + TerrainTileMap::const_iterator itr = _terrainTileMap.find(tileID); if (itr != _terrainTileMap.end()) return 0; return itr->second; } +static unsigned int s_maxNumTiles = 0; void Terrain::registerTerrainTile(TerrainTile* tile) { if (!tile) return; + + OpenThreads::ScopedLock lock(_mutex); if (tile->getTileID().valid()) { @@ -69,13 +81,17 @@ void Terrain::registerTerrainTile(TerrainTile* tile) _terrainTileSet.insert(tile); - osg::notify(osg::INFO)<<"Terrain::registerTerrainTile "< s_maxNumTiles) s_maxNumTiles = _terrainTileSet.size(); + + // osg::notify(osg::NOTICE)<<"Terrain::registerTerrainTile "<