From ec61e15e895b60bfaf699b7b65efe9a36ebb0633 Mon Sep 17 00:00:00 2001 From: timoore Date: Thu, 29 Nov 2007 23:59:47 +0000 Subject: [PATCH] backport of code using ModelRegistry --- src/Scenery/tileentry.cxx | 70 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index e3e4de8bc..1aaa72e81 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -41,7 +41,10 @@ #include #include +#include +#include #include +#include #include #include @@ -51,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +73,7 @@ #include "tilemgr.hxx" SG_USING_STD(string); +using namespace simgear; // FIXME: investigate what huge update flood is clamped away here ... class FGTileUpdateCallback : public osg::NodeCallback { @@ -260,9 +265,13 @@ struct Object { void FGTileEntry::load( const string_list &path_list, bool is_base ) { - osg::Node* new_tile = loadTileByName(tile_bucket.gen_index_str(), - path_list); - terra_range->addChild( new_tile ); + osgDB::ReaderWriter::ReadResult result + = osgDB::Registry::instance()->readNode(tile_bucket.gen_index_str() + + ".stg", 0); + if (result.validNode()) { + osg::Node* new_tile = result.getNode(); + terra_range->addChild( new_tile ); + } terra_transform->addChild( terra_range.get() ); } @@ -503,3 +512,58 @@ FGTileEntry::disconnect_ssg_nodes() exit(-1); } } + +namespace +{ + +class ReaderWriterSTG : public osgDB::ReaderWriter { +public: + virtual const char* className() const; + + virtual bool acceptsExtension(const string& extension) const; + + virtual ReadResult readNode(const string& fileName, + const osgDB::ReaderWriter::Options* options) + const; +}; + +const char* ReaderWriterSTG::className() const +{ + return "STG Database reader"; +} + +bool ReaderWriterSTG::acceptsExtension(const string& extension) const +{ + return (osgDB::equalCaseInsensitive(extension, "gz") + || osgDB::equalCaseInsensitive(extension, "stg")); +} + +osgDB::ReaderWriter::ReadResult +ReaderWriterSTG::readNode(const string& fileName, + const osgDB::ReaderWriter::Options* options) const +{ + string ext = osgDB::getLowerCaseFileExtension(fileName); + if(!acceptsExtension(ext)) + return ReadResult::FILE_NOT_HANDLED; + 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 + = FGTileEntry::loadTileByName(osgDB::getNameLessExtension(stgFileName), + globals->get_fg_scenery()); + if (result) + return result; // Constructor converts to ReadResult + else + return ReadResult::FILE_NOT_HANDLED; +} + +osgDB::RegisterReaderWriterProxy g_readerWriterSTGProxy; +ModelRegistryCallbackProxy g_stgCallbackProxy("stg"); +} // namespace -- 2.39.5