Removed TileSystem class, and added support for TerrainTile's automatically

registering and unregistering themseles with the enclosing Terrain node.
This commit is contained in:
Robert Osfield
2008-03-27 13:21:36 +00:00
parent 31bc0dd9e3
commit 2567b810cf
10 changed files with 147 additions and 145 deletions

View File

@@ -46,13 +46,32 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
/** Get the const TerrainTechnique*/
const TerrainTechnique* getTerrainTechnique() const { return _terrainTechnique.get(); }
/** Get the TerrainTile for a given TileID.*/
TerrainTile* getTile(const TileID& tileID);
/** Get the const TerrainTile for a given TileID.*/
const TerrainTile* getTile(const TileID& tileID) const;
protected:
virtual ~Terrain();
friend class TerrainTile;
void registerTerrainTile(TerrainTile* tile);
void unregisterTerrainTile(TerrainTile* tile);
typedef std::map< TileID, TerrainTile* > TerrainTileMap;
typedef std::set< TerrainTile* > TerrainTileSet;
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
TerrainTileSet _terrainTileSet;
TerrainTileMap _terrainTileMap;
};

View File

@@ -39,6 +39,16 @@ class TileID
x(in_x),
y(in_y) {}
bool operator == (const TileID& rhs) const
{
return (layer==rhs.layer) && (x==rhs.x) && (y==rhs.y);
}
bool operator != (const TileID& rhs) const
{
return (layer!=rhs.layer) || (x!=rhs.x) || (y!=rhs.y);
}
bool operator < (const TileID& rhs) const
{
if (layer<rhs.layer) return true;
@@ -47,6 +57,8 @@ class TileID
if (x>rhs.x) return false;
return y<rhs.y;
}
bool valid() const { return layer>=0; }
int layer;
int x;
@@ -74,7 +86,7 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
/** Set the Terrain that this Terrain tile is a member of.*/
void setTerrain(Terrain* ts) { _terrain = ts; }
void setTerrain(Terrain* ts);
/** Get the Terrain that this Terrain tile is a member of.*/
Terrain* getTerrain() { return _terrain; }
@@ -83,11 +95,14 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
const Terrain* getTerrain() const { return _terrain; }
void setTileID(const TileID& tileID) { _tileID = tileID; }
/** Set the TileID (layer, x,y) of the TerrainTile.
* The TileID is used so it can be located by its neighbours
* via the enclosing Terrain node that manages a map of TileID to TerraiTiles.*/
void setTileID(const TileID& tileID);
/** Get the TileID (layer, x,y) of the TerrainTile.*/
const TileID& getTileID() const { return _tileID; }
/** Set the TerrainTechnique*/
void setTerrainTechnique(TerrainTechnique* TerrainTechnique);
@@ -155,6 +170,7 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
typedef std::vector< osg::ref_ptr<Layer> > Layers;
friend class Terrain;
Terrain* _terrain;

View File

@@ -1,46 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGTERRAIN_TILESYSTEM
#define OSGTERRAIN_TILESYSTEM 1
#include <osgTerrain/TerrainTile>
#include <osg/Object>
#include <osg/observer_ptr>
namespace osgTerrain {
/** TileSystem provides the mechanism for computing the position in space of tiles.*/
class OSGTERRAIN_EXPORT TileSystem : public osg::Object
{
public:
TileSystem();
TileSystem(const TileSystem&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgTerrain, TileSystem);
protected:
virtual ~TileSystem();
typedef std::map< TileID, osg::observer_ptr<TerrainTile> > TileMap;
TileMap _tileMap;
};
}
#endif