Moved TileMapper code out into its own file and made it a signleton
This commit is contained in:
parent
7a5053f81f
commit
503568a303
@ -98,11 +98,35 @@ SOURCE=..\..\..\src\osgPlugins\txp\ReaderWriterTXP.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TerrapageNode.cpp
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPArchive.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\IO_TerrapageNode.cpp
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPIO.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPNode.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPPageManager.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPParser.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPSeamLOD.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPTileNode.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TileMap.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@ -192,18 +216,6 @@ SOURCE=..\..\..\src\osgPlugins\txp\trpage_warchive.cpp
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\trpage_writebuf.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TrPageArchive.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TrPageParser.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TrPagePageManager.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
@ -214,7 +226,35 @@ SOURCE=..\..\..\src\osgPlugins\txp\ReaderWriterTXP.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TerrapageNode.h
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPArchive.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPIO.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPNode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPPageManager.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPParser.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPSeamLOD.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TXPTileNode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TileMap.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@ -222,10 +262,6 @@ SOURCE=..\..\..\src\osgPlugins\txp\trdll.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\trPagePageManager.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\trpage_compat.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -272,18 +308,6 @@ SOURCE=..\..\..\src\osgPlugins\txp\trpage_util.h
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\trpage_write.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TrPageArchive.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\TrPageParser.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\txp\WaitBlock.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
|
@ -10,6 +10,7 @@ CXXFILES =\
|
||||
TXPTileNode.cpp\
|
||||
TXPParser.cpp\
|
||||
TXPSeamLOD.cpp\
|
||||
TileMapper.cpp\
|
||||
trpage_basic.cpp\
|
||||
trpage_compat.cpp\
|
||||
trpage_geom.cpp\
|
||||
|
@ -563,36 +563,3 @@ osg::Group* TXPArchive::getTileContent(int x, int y, int lod)
|
||||
osg::Group *tileGroup = _parser->parseScene(buf,_gstates,_models);
|
||||
return tileGroup;
|
||||
}
|
||||
|
||||
osg::PagedLOD* TXPArchive::getPagedLOD(int x, int y, int lod)
|
||||
{
|
||||
TileMap::iterator itr = _tileMap.find(TileTriple(x,y,lod));
|
||||
if (itr!=_tileMap.end()) return itr->second.get();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void TXPArchive::insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod)
|
||||
{
|
||||
_tileMap[TileTriple(x,y,lod)]=pagedLod;
|
||||
}
|
||||
|
||||
void TXPArchive::removePagedLOD(int x, int y, int lod)
|
||||
{
|
||||
TileMap::iterator itr = _tileMap.find(TileTriple(x,y,lod));
|
||||
if (itr!=_tileMap.end()) return _tileMap.erase(itr);
|
||||
}
|
||||
|
||||
void TXPArchive::prunePagedLOD()
|
||||
{
|
||||
for(TileMap::iterator itr = _tileMap.begin();
|
||||
itr!=_tileMap.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->second.valid() && itr->second->referenceCount()==1)
|
||||
{
|
||||
TileMap::iterator eitr = itr;
|
||||
--itr;
|
||||
_tileMap.erase(eitr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,14 +79,6 @@ namespace txp
|
||||
|
||||
osg::Group* getTileContent(int x, int y, int lod);
|
||||
|
||||
|
||||
osg::PagedLOD* getPagedLOD(int x, int y, int lod);
|
||||
|
||||
void insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod);
|
||||
|
||||
void removePagedLOD(int x, int y, int lod);
|
||||
|
||||
void prunePagedLOD();
|
||||
|
||||
protected:
|
||||
|
||||
@ -119,29 +111,6 @@ namespace txp
|
||||
// Light attributes vector
|
||||
std::vector<DefferedLightAttribute> _lights;
|
||||
|
||||
|
||||
struct TileTriple
|
||||
{
|
||||
TileTriple(int ax, int ay, int alod):
|
||||
x(ax),y(ay),lod(alod) {}
|
||||
|
||||
int x,y,lod;
|
||||
|
||||
bool operator < (const TileTriple& rhs) const
|
||||
{
|
||||
if (x<rhs.x) return true;
|
||||
if (x>rhs.x) return false;
|
||||
if (y<rhs.y) return true;
|
||||
if (y>rhs.y) return false;
|
||||
if (lod<rhs.lod) return true;
|
||||
if (lod>rhs.lod) return false;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map< TileTriple, osg::ref_ptr<osg::PagedLOD> > TileMap;
|
||||
TileMap _tileMap;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "TileMapper.h"
|
||||
#include "TXPNode.h"
|
||||
using namespace txp;
|
||||
|
||||
@ -193,7 +194,7 @@ osg::Node* TXPNode::addPagedLODTile(int x, int y, int lod)
|
||||
|
||||
_nodesToAdd.push_back(pagedLOD);
|
||||
|
||||
_archive->insertPagedLOD(x,y,lod,pagedLOD);
|
||||
TileMapper::instance()->insertPagedLOD(x,y,lod,pagedLOD);
|
||||
|
||||
return pagedLOD;
|
||||
}
|
||||
@ -219,7 +220,7 @@ void TXPNode::updateSceneGraph()
|
||||
|
||||
}
|
||||
|
||||
_archive->prunePagedLOD();
|
||||
TileMapper::instance()->prunePagedLOD();
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "TXPSeamLOD.h"
|
||||
#include "TXPArchive.h"
|
||||
#include "TXPTileNode.h"
|
||||
#include "TileMapper.h"
|
||||
|
||||
using namespace txp;
|
||||
|
||||
@ -52,7 +53,7 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv)
|
||||
if (distance<_mid)
|
||||
{
|
||||
// cap the lod's that can be used to what is available in the adjacent PagedLOD.
|
||||
osg::PagedLOD* pagedLOD = _archive->getPagedLOD(_neighbourTileX,_neighbourTileY, _neighbourTileLOD);
|
||||
osg::PagedLOD* pagedLOD = TileMapper::instance()->getPagedLOD(_neighbourTileX,_neighbourTileY, _neighbourTileLOD);
|
||||
if (pagedLOD && pagedLOD->getNumChildren()>1) getChild(1)->accept(nv);
|
||||
else getChild(0)->accept(nv);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <osg/PagedLOD>
|
||||
|
||||
#include "TileMapper.h"
|
||||
#include "TXPTileNode.h"
|
||||
#include "TXPArchive.h"
|
||||
#include "TXPSeamLOD.h"
|
||||
@ -198,7 +199,7 @@ bool TXPTileNode::loadTile(int x, int y, int lod)
|
||||
pagedLOD->setRadius(info.radius);
|
||||
pagedLOD->setNumChildrenThatCannotBeExpired(1);
|
||||
|
||||
_archive->insertPagedLOD(x,y,lod,pagedLOD);
|
||||
TileMapper::instance()->insertPagedLOD(x,y,lod,pagedLOD);
|
||||
|
||||
addChild(pagedLOD);
|
||||
}
|
||||
|
48
src/osgPlugins/txp/TileMapper.cpp
Normal file
48
src/osgPlugins/txp/TileMapper.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "TileMapper.h"
|
||||
#include <OpenThreads/ScopedLock>
|
||||
|
||||
using namespace txp;
|
||||
|
||||
TileMapper* TileMapper::instance()
|
||||
{
|
||||
static osg::ref_ptr<TileMapper> s_tilemapper = new TileMapper;
|
||||
return s_tilemapper.get();
|
||||
}
|
||||
|
||||
osg::PagedLOD* TileMapper::getPagedLOD(int x, int y, int lod)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
TileMap::iterator itr = _tileMap.find(TileTriple(x,y,lod));
|
||||
if (itr!=_tileMap.end()) return itr->second.get();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void TileMapper::insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_tileMap[TileTriple(x,y,lod)]=pagedLod;
|
||||
}
|
||||
|
||||
void TileMapper::removePagedLOD(int x, int y, int lod)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
TileMap::iterator itr = _tileMap.find(TileTriple(x,y,lod));
|
||||
if (itr!=_tileMap.end()) return _tileMap.erase(itr);
|
||||
}
|
||||
|
||||
void TileMapper::prunePagedLOD()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
for(TileMap::iterator itr = _tileMap.begin();
|
||||
itr!=_tileMap.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->second.valid() && itr->second->referenceCount()==1)
|
||||
{
|
||||
TileMap::iterator eitr = itr;
|
||||
--itr;
|
||||
_tileMap.erase(eitr);
|
||||
}
|
||||
}
|
||||
//std::cout<<"_tileMap.size()="<<_tileMap.size()<<std::endl;
|
||||
}
|
64
src/osgPlugins/txp/TileMapper.h
Normal file
64
src/osgPlugins/txp/TileMapper.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef __TILEMAPPER_H_
|
||||
#define __TILEMAPPER_H_
|
||||
|
||||
#include "trpage_sys.h"
|
||||
#include "trpage_read.h"
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osg/PagedLOD>
|
||||
|
||||
#include <OpenThreads/Mutex>
|
||||
|
||||
namespace txp
|
||||
{
|
||||
class TileMapper : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
static TileMapper* instance();
|
||||
|
||||
osg::PagedLOD* getPagedLOD(int x, int y, int lod);
|
||||
|
||||
void insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod);
|
||||
|
||||
void removePagedLOD(int x, int y, int lod);
|
||||
|
||||
void prunePagedLOD();
|
||||
|
||||
protected:
|
||||
|
||||
// Constructor
|
||||
TileMapper() {}
|
||||
|
||||
// Destructor
|
||||
virtual ~TileMapper() {}
|
||||
|
||||
struct TileTriple
|
||||
{
|
||||
TileTriple(int ax, int ay, int alod):
|
||||
x(ax),y(ay),lod(alod) {}
|
||||
|
||||
int x,y,lod;
|
||||
|
||||
bool operator < (const TileTriple& rhs) const
|
||||
{
|
||||
if (x<rhs.x) return true;
|
||||
if (x>rhs.x) return false;
|
||||
if (y<rhs.y) return true;
|
||||
if (y>rhs.y) return false;
|
||||
if (lod<rhs.lod) return true;
|
||||
if (lod>rhs.lod) return false;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map< TileTriple, osg::ref_ptr<osg::PagedLOD> > TileMap;
|
||||
|
||||
OpenThreads::Mutex _mutex;
|
||||
TileMap _tileMap;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // __TXPARCHIVE_H_
|
Loading…
Reference in New Issue
Block a user