From ba678eabdc995d22fd9a548bf5ad2925594c334c Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Thu, 9 Jun 2011 22:24:08 +0200 Subject: [PATCH] Add method to reload specific scenery tiles. --- simgear/scene/tgdb/TileCache.cxx | 33 +++++++++++++++++++++++++------- simgear/scene/tgdb/TileCache.hxx | 3 +++ simgear/scene/tgdb/TileEntry.cxx | 14 ++++++++++++++ simgear/scene/tgdb/TileEntry.hxx | 1 + simgear/threads/SGQueue.hxx | 8 ++++++++ 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/simgear/scene/tgdb/TileCache.cxx b/simgear/scene/tgdb/TileCache.cxx index 3032dea1..5028d197 100644 --- a/simgear/scene/tgdb/TileCache.cxx +++ b/simgear/scene/tgdb/TileCache.cxx @@ -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) { diff --git a/simgear/scene/tgdb/TileCache.hxx b/simgear/scene/tgdb/TileCache.hxx index 5fedab9c..5b661964 100644 --- a/simgear/scene/tgdb/TileCache.hxx +++ b/simgear/scene/tgdb/TileCache.hxx @@ -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(); diff --git a/simgear/scene/tgdb/TileEntry.cxx b/simgear/scene/tgdb/TileEntry.cxx index 0e417865..0b16242b 100644 --- a/simgear/scene/tgdb/TileEntry.cxx +++ b/simgear/scene/tgdb/TileEntry.cxx @@ -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 () diff --git a/simgear/scene/tgdb/TileEntry.hxx b/simgear/scene/tgdb/TileEntry.hxx index ffe78947..3edbfd1f 100644 --- a/simgear/scene/tgdb/TileEntry.hxx +++ b/simgear/scene/tgdb/TileEntry.hxx @@ -91,6 +91,7 @@ public: // Constructor TileEntry( const SGBucket& b ); + TileEntry( const TileEntry& t ); // Destructor ~TileEntry(); diff --git a/simgear/threads/SGQueue.hxx b/simgear/threads/SGQueue.hxx index e7311e56..bcdda1d3 100644 --- a/simgear/threads/SGQueue.hxx +++ b/simgear/threads/SGQueue.hxx @@ -283,6 +283,14 @@ public: */ ~SGBlockingDeque() {} + /** + * + */ + virtual void clear() { + OpenThreads::ScopedLock g(mutex); + this->queue.clear(); + } + /** * */ -- 2.39.5