]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/ReaderWriterSTG.cxx
8344245ecb7912ddabeff72b735b7a56d9a1dad9
[simgear.git] / simgear / scene / tgdb / ReaderWriterSTG.cxx
1 // tileentry.cxx -- routines to handle a scenery tile
2 //
3 // Written by Curtis Olson, started May 1998.
4 //
5 // Copyright (C) 1998 - 2001  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21
22 #include <simgear/scene/model/ModelRegistry.hxx>
23
24 #include <osgDB/Registry>
25 #include <osgDB/FileNameUtils>
26
27 #include "TileEntry.hxx"
28 #include "ReaderWriterSTG.hxx"
29
30 using namespace simgear;
31
32 const char* ReaderWriterSTG::className() const
33 {
34     return "STG Database reader";
35 }
36
37 bool ReaderWriterSTG::acceptsExtension(const std::string& extension) const
38 {
39     return (osgDB::equalCaseInsensitive(extension, "gz")
40             || osgDB::equalCaseInsensitive(extension, "stg"));
41 }
42
43 //#define SLOW_PAGER 1
44 #ifdef SLOW_PAGER
45 #include <unistd.h>
46 #endif
47
48 osgDB::ReaderWriter::ReadResult
49 ReaderWriterSTG::readNode(const std::string& fileName,
50                           const osgDB::ReaderWriter::Options* options) const
51 {
52     std::string ext = osgDB::getLowerCaseFileExtension(fileName);
53     if(!acceptsExtension(ext))
54         return ReadResult::FILE_NOT_HANDLED;
55     std::string stgFileName;
56     if (osgDB::equalCaseInsensitive(ext, "gz")) {
57         stgFileName = osgDB::getNameLessExtension(fileName);
58         if (!acceptsExtension(
59                 osgDB::getLowerCaseFileExtension(stgFileName))) {
60             return ReadResult::FILE_NOT_HANDLED;
61         }
62     } else {
63         stgFileName = fileName;
64     }
65     osg::Node* result
66         = TileEntry::loadTileByName(osgDB::getNameLessExtension(stgFileName),
67                                       options);
68     // For debugging race conditions
69 #ifdef SLOW_PAGER
70     sleep(5);
71 #endif
72     if (result)
73         return result;
74     else
75         return ReadResult::FILE_NOT_HANDLED;
76 }
77