diff --git a/projects/VC7.1/SimGear.vcproj b/projects/VC7.1/SimGear.vcproj
index 5a817b0f..77477a11 100755
--- a/projects/VC7.1/SimGear.vcproj
+++ b/projects/VC7.1/SimGear.vcproj
@@ -893,6 +893,21 @@
+
+
+
+
+
+
+
+
+
+
(refAttr.first.get());
if (!texture)
return;
-
+
texture->setDataVariance(Object::STATIC);
}
@@ -406,7 +406,7 @@ osg::Node* OptimizeModelPolicy::optimize(osg::Node* node,
// STATIC so that textures will be globally shared.
SGTexDataVarianceVisitor dataVarianceVisitor;
node->accept(dataVarianceVisitor);
-
+
SGTexCompressionVisitor texComp;
node->accept(texComp);
return node;
@@ -585,4 +585,4 @@ typedef ModelRegistryCallback g_acRegister("ac");
-}
+}
diff --git a/simgear/scene/model/SGReaderWriterXML.cxx b/simgear/scene/model/SGReaderWriterXML.cxx
index 88f9e645..b952248a 100644
--- a/simgear/scene/model/SGReaderWriterXML.cxx
+++ b/simgear/scene/model/SGReaderWriterXML.cxx
@@ -181,6 +181,7 @@ sgLoad3DModel_internal(const string &path,
throw sg_io_exception("Failed to load 3D model",
sg_location(modelpath.str()));
}
+ model->setName(modelpath.str());
bool needTransform=false;
// Set up the alignment node if needed
diff --git a/simgear/scene/tgdb/Makefile.am b/simgear/scene/tgdb/Makefile.am
index 7c0a7fa3..0600f3d1 100644
--- a/simgear/scene/tgdb/Makefile.am
+++ b/simgear/scene/tgdb/Makefile.am
@@ -9,6 +9,7 @@ include_HEADERS = \
obj.hxx \
pt_lights.hxx \
userdata.hxx \
+ ReaderWriterSTG.hxx \
SGOceanTile.hxx \
SGVasiDrawable.hxx \
SGDirectionalLightBin.hxx \
@@ -19,18 +20,23 @@ include_HEADERS = \
SGTriangleBin.hxx \
SGVertexArrayBin.hxx \
GroundLightManager.hxx \
- ShaderGeometry.hxx
+ ShaderGeometry.hxx \
+ TileCache.hxx \
+ TileEntry.hxx
libsgtgdb_a_SOURCES = \
apt_signs.cxx \
obj.cxx \
pt_lights.cxx \
userdata.cxx \
+ ReaderWriterSTG.cxx \
SGOceanTile.cxx \
SGReaderWriterBTG.cxx \
SGVasiDrawable.cxx \
GroundLightManager.cxx \
ShaderGeometry.cxx \
+ TileCache.cxx \
+ TileEntry.cxx \
TreeBin.cxx
INCLUDES = -I$(top_srcdir)
diff --git a/simgear/scene/tgdb/ReaderWriterSTG.cxx b/simgear/scene/tgdb/ReaderWriterSTG.cxx
new file mode 100644
index 00000000..8344245e
--- /dev/null
+++ b/simgear/scene/tgdb/ReaderWriterSTG.cxx
@@ -0,0 +1,77 @@
+// tileentry.cxx -- routines to handle a scenery tile
+//
+// Written by Curtis Olson, started May 1998.
+//
+// Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program 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 GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#include
+
+#include
+#include
+
+#include "TileEntry.hxx"
+#include "ReaderWriterSTG.hxx"
+
+using namespace simgear;
+
+const char* ReaderWriterSTG::className() const
+{
+ return "STG Database reader";
+}
+
+bool ReaderWriterSTG::acceptsExtension(const std::string& extension) const
+{
+ return (osgDB::equalCaseInsensitive(extension, "gz")
+ || osgDB::equalCaseInsensitive(extension, "stg"));
+}
+
+//#define SLOW_PAGER 1
+#ifdef SLOW_PAGER
+#include
+#endif
+
+osgDB::ReaderWriter::ReadResult
+ReaderWriterSTG::readNode(const std::string& fileName,
+ const osgDB::ReaderWriter::Options* options) const
+{
+ std::string ext = osgDB::getLowerCaseFileExtension(fileName);
+ if(!acceptsExtension(ext))
+ return ReadResult::FILE_NOT_HANDLED;
+ std::string stgFileName;
+ if (osgDB::equalCaseInsensitive(ext, "gz")) {
+ stgFileName = osgDB::getNameLessExtension(fileName);
+ if (!acceptsExtension(
+ osgDB::getLowerCaseFileExtension(stgFileName))) {
+ return ReadResult::FILE_NOT_HANDLED;
+ }
+ } else {
+ stgFileName = fileName;
+ }
+ osg::Node* result
+ = TileEntry::loadTileByName(osgDB::getNameLessExtension(stgFileName),
+ options);
+ // For debugging race conditions
+#ifdef SLOW_PAGER
+ sleep(5);
+#endif
+ if (result)
+ return result;
+ else
+ return ReadResult::FILE_NOT_HANDLED;
+}
+
diff --git a/simgear/scene/tgdb/ReaderWriterSTG.hxx b/simgear/scene/tgdb/ReaderWriterSTG.hxx
new file mode 100644
index 00000000..7f53f65a
--- /dev/null
+++ b/simgear/scene/tgdb/ReaderWriterSTG.hxx
@@ -0,0 +1,41 @@
+// tileentry.hxx -- routines to handle an individual scenery tile
+//
+// Written by Curtis Olson, started May 1998.
+//
+// Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program 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 GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+
+#ifndef _READERWRITERSTG_HXX
+#define _READERWRITERSTG_HXX
+
+#include
+
+namespace simgear {
+
+class ReaderWriterSTG : public osgDB::ReaderWriter {
+public:
+ virtual const char* className() const;
+
+ virtual bool acceptsExtension(const std::string& extension) const;
+
+ virtual ReadResult readNode(const std::string& fileName,
+ const osgDB::ReaderWriter::Options* options)
+ const;
+};
+
+}
+#endif // _READERWRITERSTG_HXX
diff --git a/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx b/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx
index 86174bf2..ed612325 100644
--- a/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx
+++ b/simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx
@@ -15,7 +15,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#ifndef SGREADERWRITERBTGOPTIONS_HXX
-#define SGREADERWRITERBTGOPTIONS_HXX 1
+#define SGREADERWRITERBTGOPTIONS_HXX
#include
#include
@@ -28,7 +28,7 @@ public:
_useRandomObjects(false),
_useRandomVegetation(false)
{}
-
+
SGReaderWriterBTGOptions(const SGReaderWriterBTGOptions& options,
const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osgDB::ReaderWriter::Options(options, copyop),
diff --git a/simgear/scene/tgdb/TileCache.cxx b/simgear/scene/tgdb/TileCache.cxx
new file mode 100644
index 00000000..9004f706
--- /dev/null
+++ b/simgear/scene/tgdb/TileCache.cxx
@@ -0,0 +1,171 @@
+// newcache.cxx -- routines to handle scenery tile caching
+//
+// Written by Curtis Olson, started December 2000.
+//
+// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program 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 GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#include
+#include
+#include
+
+#include "TileEntry.hxx"
+#include "TileCache.hxx"
+
+SG_USING_NAMESPACE(std);
+
+using simgear::TileEntry;
+using simgear::TileCache;
+
+TileCache::TileCache( void ) :
+ max_cache_size(100)
+{
+ tile_cache.clear();
+}
+
+
+TileCache::~TileCache( void ) {
+ clear_cache();
+}
+
+
+// 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];
+ tile->removeFromSceneGraph();
+
+ tile->free_tile();
+ delete tile;
+
+ tile_cache.erase( cache_index );
+}
+
+
+// Initialize the tile cache subsystem
+void TileCache::init( void ) {
+ SG_LOG( SG_TERRAIN, SG_INFO, "Initializing the tile cache." );
+
+ SG_LOG( SG_TERRAIN, SG_INFO, " max cache size = "
+ << max_cache_size );
+ SG_LOG( SG_TERRAIN, SG_INFO, " current cache size = "
+ << tile_cache.size() );
+
+#if 0 // don't clear the cache
+ clear_cache();
+#endif
+
+ SG_LOG( SG_TERRAIN, SG_INFO, " done with init()" );
+}
+
+
+// Search for the specified "bucket" in the cache
+bool TileCache::exists( const SGBucket& b ) const {
+ long tile_index = b.gen_index();
+ const_tile_map_iterator it = tile_cache.find( tile_index );
+
+ return ( it != tile_cache.end() );
+}
+
+
+// Return the index of the oldest tile in the cache, return -1 if
+// nothing available to be removed.
+long TileCache::get_oldest_tile() {
+ // we need to free the furthest entry
+ long min_index = -1;
+ double timestamp = 0.0;
+ double min_time = DBL_MAX;
+
+ tile_map_iterator current = tile_cache.begin();
+ tile_map_iterator end = tile_cache.end();
+
+ for ( ; current != end; ++current ) {
+ long index = current->first;
+ TileEntry *e = current->second;
+ if ( e->is_loaded() ) {
+ timestamp = e->get_timestamp();
+ if ( timestamp < min_time ) {
+ min_time = timestamp;
+ min_index = index;
+ }
+ } else {
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "loaded = " << e->is_loaded()
+ << " time stamp = " << e->get_timestamp() );
+ }
+ }
+
+ SG_LOG( SG_TERRAIN, SG_DEBUG, " index = " << min_index );
+ SG_LOG( SG_TERRAIN, SG_DEBUG, " min_time = " << min_time );
+
+ return min_index;
+}
+
+
+// Clear the inner ring flag for all tiles in the cache so that the
+// external tile scheduler can flag the inner ring correctly.
+void TileCache::clear_inner_ring_flags() {
+ tile_map_iterator current = tile_cache.begin();
+ tile_map_iterator end = tile_cache.end();
+
+ for ( ; current != end; ++current ) {
+ TileEntry *e = current->second;
+ if ( e->is_loaded() ) {
+ e->set_inner_ring( false );
+ }
+ }
+}
+
+// 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 );
+}
+
+
+// Clear all completely loaded tiles (ignores partially loaded tiles)
+void TileCache::clear_cache() {
+ std::vector indexList;
+ tile_map_iterator current = tile_cache.begin();
+ tile_map_iterator end = tile_cache.end();
+
+ for ( ; current != end; ++current ) {
+ long index = current->first;
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "clearing " << index );
+ TileEntry *e = current->second;
+ if ( e->is_loaded() ) {
+ e->tile_bucket.make_bad();
+ // entry_free modifies tile_cache, so store index and call entry_free() later;
+ indexList.push_back( index);
+ }
+ }
+ for (unsigned int it = 0; it < indexList.size(); it++) {
+ entry_free( indexList[ it]);
+ }
+}
+
+/**
+ * Create a new tile and schedule it for loading.
+ */
+bool TileCache::insert_tile( TileEntry *e ) {
+ // register tile in the cache
+ long tile_index = e->get_tile_bucket().gen_index();
+ tile_cache[tile_index] = e;
+
+ return true;
+}
+
diff --git a/simgear/scene/tgdb/TileCache.hxx b/simgear/scene/tgdb/TileCache.hxx
new file mode 100644
index 00000000..6e137d0a
--- /dev/null
+++ b/simgear/scene/tgdb/TileCache.hxx
@@ -0,0 +1,129 @@
+// newcache.hxx -- routines to handle scenery tile caching
+//
+// Written by Curtis Olson, started December 2000.
+//
+// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program 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 GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+
+#ifndef _TILECACHE_HXX
+#define _TILECACHE_HXX
+
+#include