Debian Codegraph @

src/Scenery/tileentry.cxx

raw symbols SCIP
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 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <simgear/compiler.h>
26
27 #include <string>
28 #include <sstream>
29 #include <istream>
30
31 #include <osg/LOD>
32
33 #include <simgear/bucket/newbucket.hxx>
34 #include <simgear/debug/logstream.hxx>
35 #include <simgear/scene/tgdb/SGOceanTile.hxx>
36
37 #include "tileentry.hxx"
38
39 using std::string;
40
41 // Base constructor
42 TileEntry::TileEntry ( const SGBucket& b )
43 : tile_bucket( b ),
44 _node( new osg::LOD ),
45 _priority(-FLT_MAX),
46 _current_view(false),
47 _time_expired(-1.0)
48 {
49 _create_orthophoto();
50
51 // Give a default LOD range so that traversals that traverse
52 // active children (like the groundcache lookup) will work before
53 // tile manager has had a chance to update this node.
54 _node->setRange(0, 0.0, 10000.0);
55 }
56
57 TileEntry::TileEntry( const TileEntry& t )
58 : tile_bucket( t.tile_bucket ),
59 tileFileName(t.tileFileName),
60 _node( new osg::LOD ),
61 _priority(t._priority),
62 _current_view(t._current_view),
63 _time_expired(t._time_expired)
64 {
65 _create_orthophoto();
66
67 _node->setName(tileFileName);
68 // Give a default LOD range so that traversals that traverse
69 // active children (like the groundcache lookup) will work before
70 // tile manager has had a chance to update this node.
71 _node->setRange(0, 0.0, 10000.0);
72 }
73
74 void TileEntry::_create_orthophoto() {
75 bool use_photoscenery = fgGetBool("/sim/rendering/photoscenery/enabled");
76 if (use_photoscenery) {
77 _orthophoto = simgear::Orthophoto::fromBucket(tile_bucket, globals->get_fg_scenery());
78 if (_orthophoto) {
79 simgear::OrthophotoManager::instance()->registerOrthophoto(tile_bucket.gen_index(), _orthophoto);
80 }
81 }
82 }
83
84 // Destructor
85 TileEntry::~TileEntry ()
86 {
87 }
88
89 // Update the ssg transform node for this tile so it can be
90 // properly drawn relative to our (0,0,0) point
91 void TileEntry::prep_ssg_node(float vis) {
92 if (!is_loaded())
93 return;
94 // visibility can change from frame to frame so we update the
95 // range selector cutoff's each time.
96 float bounding_radius = _node->getChild(0)->getBound().radius();
97 _node->setRange( 0, 0, vis + bounding_radius );
98 }
99
100 void
101 TileEntry::addToSceneGraph(osg::Group *terrain_branch)
102 {
103 terrain_branch->addChild( _node.get() );
104
105 SG_LOG( SG_TERRAIN, SG_DEBUG,
106 "connected a tile into scene graph. _node = "
107 << _node.get() );
108 SG_LOG( SG_TERRAIN, SG_DEBUG, "num parents now = "
109 << _node->getNumParents() );
110 }
111
112
113 void
114 TileEntry::removeFromSceneGraph()
115 {
116 if (! is_loaded()) {
117 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a not-fully loaded tile!" );
118 } else {
119 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a fully loaded tile! _node = " << _node.get() );
120 }
121
122 // find the nodes branch parent
123 if ( _node->getNumParents() > 0 ) {
124 // find the first parent (should only be one)
125 osg::Group *parent = _node->getParent( 0 ) ;
126 if( parent ) {
127 parent->removeChild( _node.get() );
128 }
129 }
130 }
131
132 // Constructor - STG Variant
133 STGTileEntry::STGTileEntry ( const SGBucket& b ) : TileEntry(b)
134 {
135 tileFileName = b.gen_index_str() + ".stg";
136 _node->setName(tileFileName);
137 }
138
139 // Destructor - STG Variant
140 STGTileEntry::~STGTileEntry ()
141 {
142 }
143
144 // Constructor - VPB version
145 VPBTileEntry::VPBTileEntry ( const SGBucket& b, osg::ref_ptr<simgear::SGReaderWriterOptions> options ) : TileEntry(b)
146 {
147 tileFileName = "vpb/" + b.gen_vpb_base() + ".osgb";
148 std::string zipFileName = "vpb/" + b.gen_base_path() + ".zip";
149
150 bool found = false;
151 auto filePathList = options->getDatabasePathList();
152 for (auto path : filePathList) {
153 SGPath p(path, tileFileName);
154 if (p.exists()) {
155 found = true;
156 break;
157 }
158
159 SGPath archive(path, zipFileName);
160 if (archive.exists()) {
161 found = true;
162 break;
163 }
164
165 }
166
167 if (found) {
168 // File exists - set it up for loading later
169 _node->setName(tileFileName);
170
171 // Give a default LOD range so that traversals that traverse
172 // active children (like the groundcache lookup) will work before
173 // tile manager has had a chance to update this node.
174 _node->setRange(0, 0.0, 160000.0);
175 } else {
176 // File doesn't exist, so add a 1x1 degree Ocean tile.
177 double lat = floor(b.get_center_lat()) + 0.5;
178 double lon = floor(b.get_center_lon()) + 0.5;
179 SG_LOG( SG_TERRAIN, SG_DEBUG, "Generating Ocean Tile for " << lat << ", " << lon);
180
181 // Standard for WS2.0 is 5 points per bucket (~30km), or 8km spacing.
182 // 1 degree latitude and 1 degree of longitude at the equator is 111km, 15 points
183 // are equivalent resolution.
184 osg::Node* oceanTile = SGOceanTile(lat, lon, 1.0, 1.0, options->getMaterialLib(), 15, 15);
185 _node->addChild(oceanTile, 0, 250000.0);
186 }
187 }
188
189 // Destructor - VPB Variant
190 VPBTileEntry::~VPBTileEntry ()
191 {
192 }
193