1 // tileentry.cxx -- routines to handle a scenery tile
3 // Written by Curtis Olson, started May 1998.
5 // Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
25 #include <simgear/compiler.h>
33 #include <simgear/bucket/newbucket.hxx>
34 #include <simgear/debug/logstream.hxx>
36 #include "tileentry.hxx"
41 TileEntry::TileEntry ( const SGBucket& b )
43 tileFileName(b.gen_index_str()),
44 _node( new osg::LOD ),
49 tileFileName += ".stg";
50 _node->setName(tileFileName);
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);
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)
65 _node->setName(tileFileName);
66 // Give a default LOD range so that traversals that traverse
67 // active children (like the groundcache lookup) will work before
68 // tile manager has had a chance to update this node.
69 _node->setRange(0, 0.0, 10000.0);
73 TileEntry::~TileEntry ()
77 // Update the ssg transform node for this tile so it can be
78 // properly drawn relative to our (0,0,0) point
79 void TileEntry::prep_ssg_node(float vis) {
82 // visibility can change from frame to frame so we update the
83 // range selector cutoff's each time.
84 float bounding_radius = _node->getChild(0)->getBound().radius();
85 _node->setRange( 0, 0, vis + bounding_radius );
89 TileEntry::addToSceneGraph(osg::Group *terrain_branch)
91 terrain_branch->addChild( _node.get() );
93 SG_LOG( SG_TERRAIN, SG_DEBUG,
94 "connected a tile into scene graph. _node = "
96 SG_LOG( SG_TERRAIN, SG_DEBUG, "num parents now = "
97 << _node->getNumParents() );
102 TileEntry::removeFromSceneGraph()
104 SG_LOG( SG_TERRAIN, SG_DEBUG, "disconnecting TileEntry nodes" );
107 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a not-fully loaded tile!" );
109 SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a fully loaded tile! _node = " << _node.get() );
112 // find the nodes branch parent
113 if ( _node->getNumParents() > 0 ) {
114 // find the first parent (should only be one)
115 osg::Group *parent = _node->getParent( 0 ) ;
117 parent->removeChild( _node.get() );
125 osg::Group *parent = NULL;
126 // find the nodes branch parent
127 if ( _node->getNumParents() > 0 ) {
128 // find the first parent (should only be one)
129 parent = _node->getParent( 0 ) ;
131 parent->removeChild( _node.get() );
134 _node = new osg::LOD;
136 parent->addChild(_node.get());