]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/ReaderWriterSTG.cxx
Win32 fix
[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 #ifdef HAVE_CONFIG_H
23 #  include <simgear_config.h>
24 #endif
25
26 #include <simgear/scene/model/ModelRegistry.hxx>
27
28 #include <osgDB/Registry>
29 #include <osgDB/FileNameUtils>
30
31 #include "TileEntry.hxx"
32 #include "ReaderWriterSTG.hxx"
33
34 using namespace simgear;
35
36 const char* ReaderWriterSTG::className() const
37 {
38     return "STG Database reader";
39 }
40
41 bool ReaderWriterSTG::acceptsExtension(const std::string& extension) const
42 {
43     return (osgDB::equalCaseInsensitive(extension, "gz")
44             || osgDB::equalCaseInsensitive(extension, "stg"));
45 }
46
47 //#define SLOW_PAGER 1
48 #ifdef SLOW_PAGER
49 #include <unistd.h>
50 #endif
51
52 osgDB::ReaderWriter::ReadResult
53 ReaderWriterSTG::readNode(const std::string& fileName,
54                           const osgDB::ReaderWriter::Options* options) const
55 {
56     std::string ext = osgDB::getLowerCaseFileExtension(fileName);
57     if(!acceptsExtension(ext))
58         return ReadResult::FILE_NOT_HANDLED;
59     std::string stgFileName;
60     if (osgDB::equalCaseInsensitive(ext, "gz")) {
61         stgFileName = osgDB::getNameLessExtension(fileName);
62         if (!acceptsExtension(
63                 osgDB::getLowerCaseFileExtension(stgFileName))) {
64             return ReadResult::FILE_NOT_HANDLED;
65         }
66     } else {
67         stgFileName = fileName;
68     }
69     osg::Node* result
70         = TileEntry::loadTileByName(osgDB::getNameLessExtension(stgFileName),
71                                       options);
72     // For debugging race conditions
73 #ifdef SLOW_PAGER
74     sleep(5);
75 #endif
76     if (result)
77         return result;
78     else
79         return ReadResult::FILE_NOT_HANDLED;
80 }
81