1 // tile.cxx -- routines to handle a scenery tile
3 // Written by Curtis Olson, started May 1998.
5 // Copyright (C) 1998, 1999 Curtis L. Olson - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <Include/compiler.h>
26 #ifdef FG_MATH_EXCEPTION_CLASH
30 #include STL_FUNCTIONAL
31 #include STL_ALGORITHM
33 #include <Debug/logstream.hxx>
34 #include <Bucket/newbucket.hxx>
36 #include "tileentry.hxx"
38 FG_USING_STD(for_each);
39 FG_USING_STD(mem_fun_ref);
43 FGTileEntry::FGTileEntry ( void )
55 FGTileEntry::~FGTileEntry ( void ) {
56 // cout << "nodes = " << nodes.size() << endl;;
61 // Step through the fragment list, deleting the display list, then the
62 // fragment, until the list is empty. Also delete the arrays used by
63 // ssg as well as the whole ssg branch
65 FGTileEntry::free_tile()
67 FG_LOG( FG_TERRAIN, FG_INFO,
68 "FREEING TILE = (" << tile_bucket << ")" );
73 // delete fragment list
74 FG_LOG( FG_TERRAIN, FG_INFO,
75 " deleting " << fragment_list.size() << " fragments" );
76 for_each( begin(), end(),
77 mem_fun_ref( &fgFRAGMENT::deleteDisplayList ));
78 fragment_list.erase( begin(), end() );
80 // delete the ssg used structures
81 FG_LOG( FG_TERRAIN, FG_INFO,
82 " deleting vertex, normal, and texture coordinate arrays" );
83 FG_LOG( FG_TERRAIN, FG_INFO,
84 " deleting vertex array" );
85 if ( vtlist != NULL ) {
88 FG_LOG( FG_TERRAIN, FG_INFO,
89 " deleting normal array" );
90 if ( vnlist != NULL ) {
93 FG_LOG( FG_TERRAIN, FG_INFO,
94 " deleting texture coordinate array" );
95 if ( tclist != NULL ) {
99 // delete the ssg branch
101 // make sure we have a sane number of parents
102 int pcount = select_ptr->getNumParents();
104 // find the first parent (should only be one)
105 ssgBranch *parent = select_ptr->getParent( 0 ) ;
106 // find the number of kids this parent has
107 int kcount = parent->getNumKids();
108 // find the kid that matches our original select_ptr
109 bool found_kid = false;
110 for ( int i = 0; i < kcount; ++i ) {
111 ssgEntity *kid = parent->getKid( i );
112 if ( kid == select_ptr ) {
113 FG_LOG( FG_TERRAIN, FG_INFO,
114 "Found a kid to delete " << kid);
119 FG_LOG( FG_TERRAIN, FG_ALERT,
120 "Couldn't find the kid to delete! Dying" );
124 FG_LOG( FG_TERRAIN, FG_ALERT,
125 "Parent count is zero for an ssg tile! Dying" );
131 // when a tile is still in the cache, but not in the immediate draw l
132 // ist, it can still remain in the scene graph, but we use a range
133 // selector to disable it from ever being drawn.
135 FGTileEntry::ssg_disable() {
136 cout << "TILE STATE = " << state << endl;
137 if ( state == Scheduled_for_use ) {
138 state = Scheduled_for_cache;
139 } else if ( (state == Loaded) || (state == Cached) ) {
141 cout << "DISABLING SSG NODE" << endl;
142 select_ptr->select(0);
145 // set a really tiny range
146 // cout << "SETTING TINY RANGE" << endl;
149 ranges[1] = 0.00001f;
150 range_ptr->setRanges( ranges, 2 );
152 // transform to a long way away
153 // cout << "MOVING FAR AWAY" << endl;
155 sgSetCoord( &sgcoord, 999999.0, 999999.0, 999999.0, 0.0, 0.0, 0.0 );
156 transform_ptr->setTransform( &sgcoord );
159 FG_LOG( FG_TERRAIN, FG_ALERT,
160 "Trying to disable an unused tile! Dying" );
163 cout << "TILE STATE = " << state << endl;