Add method to reload specific scenery tiles.

This commit is contained in:
ThorstenB 2011-06-09 22:24:08 +02:00
parent 9442d3d0f3
commit ba678eabdc
5 changed files with 52 additions and 7 deletions

View File

@ -47,12 +47,11 @@ TileCache::~TileCache( void ) {
// Free a tile cache entry
void TileCache::entry_free( long cache_index ) {
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING CACHE ENTRY = " << cache_index );
TileEntry *tile = tile_cache[cache_index];
void TileCache::entry_free( long tile_index ) {
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING CACHE ENTRY = " << tile_index );
TileEntry *tile = tile_cache[tile_index];
tile->removeFromSceneGraph();
tile_cache.erase( cache_index );
tile_cache.erase( tile_index );
delete tile;
}
@ -144,8 +143,8 @@ void TileCache::clear_current_view()
// Clear a cache entry, note that the cache only holds pointers
// and this does not free the object which is pointed to.
void TileCache::clear_entry( long cache_index ) {
tile_cache.erase( cache_index );
void TileCache::clear_entry( long tile_index ) {
tile_cache.erase( tile_index );
}
@ -182,6 +181,26 @@ bool TileCache::insert_tile( TileEntry *e ) {
return true;
}
/**
* Reloads a tile when it's already in memory.
*/
void TileCache::refresh_tile(long tile_index)
{
const_tile_map_iterator it = tile_cache.find( tile_index );
if ( it == tile_cache.end() )
return;
SG_LOG( SG_TERRAIN, SG_DEBUG, "REFRESHING CACHE ENTRY = " << tile_index );
TileEntry* e = NULL;
if (!it->second->is_expired(current_time))
e = new TileEntry(it->second);
entry_free(tile_index);
if (e)
tile_cache[tile_index] = e;
}
// update tile's priority and expiry time according to current request
void TileCache::request_tile(TileEntry* t,float priority,bool current_view,double request_time)
{

View File

@ -83,6 +83,9 @@ public:
// and this does not free the object which is pointed to.
void clear_entry( long cache_entry );
// Refresh/reload a tile when it's already in memory.
void refresh_tile(long tile_index);
// Clear all completely loaded tiles (ignores partially loaded tiles)
void clear_cache();

View File

@ -82,6 +82,20 @@ TileEntry::TileEntry ( const SGBucket& b )
_node->setRange(0, 0.0, 10000.0);
}
TileEntry::TileEntry( const TileEntry& t )
: tile_bucket( t.tile_bucket ),
tileFileName(t.tileFileName),
_node( new osg::LOD ),
_priority(t._priority),
_current_view(t._current_view),
_time_expired(t._time_expired)
{
_node->setName(tileFileName);
// Give a default LOD range so that traversals that traverse
// active children (like the groundcache lookup) will work before
// tile manager has had a chance to update this node.
_node->setRange(0, 0.0, 10000.0);
}
// Destructor
TileEntry::~TileEntry ()

View File

@ -91,6 +91,7 @@ public:
// Constructor
TileEntry( const SGBucket& b );
TileEntry( const TileEntry& t );
// Destructor
~TileEntry();

View File

@ -283,6 +283,14 @@ public:
*/
~SGBlockingDeque() {}
/**
*
*/
virtual void clear() {
OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
this->queue.clear();
}
/**
*
*/