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 <simgear/compiler.h>
26 #ifdef FG_MATH_EXCEPTION_CLASH
30 #include STL_FUNCTIONAL
31 #include STL_ALGORITHM
33 #include <simgear/bucket/newbucket.hxx>
34 #include <simgear/debug/logstream.hxx>
36 #include "tileentry.hxx"
38 FG_USING_STD(for_each);
39 FG_USING_STD(mem_fun_ref);
43 FGTileEntry::FGTileEntry ( void )
53 FGTileEntry::~FGTileEntry ( void ) {
54 // cout << "nodes = " << nodes.size() << endl;;
59 // recurse an ssg tree and call removeKid() on every node from the
60 // bottom up. Leaves the original branch in existance, but empty so
61 // it can be removed by the calling routine.
62 static void my_remove_branch( ssgBranch * branch ) {
63 for ( ssgEntity *k = branch->getKid( 0 );
65 k = branch->getNextKid() )
67 if ( k -> isAKindOf ( ssgTypeBranch() ) ) {
68 my_remove_branch( (ssgBranch *)k );
69 branch -> removeKid ( k );
70 } else if ( k -> isAKindOf ( ssgTypeLeaf() ) ) {
71 branch -> removeKid ( k ) ;
77 // Step through the fragment list, deleting the display list, then the
78 // fragment, until the list is empty. Also delete the arrays used by
79 // ssg as well as the whole ssg branch
80 void FGTileEntry::free_tile() {
82 FG_LOG( FG_TERRAIN, FG_DEBUG,
83 "FREEING TILE = (" << tile_bucket << ")" );
88 // delete fragment list and node list
89 FG_LOG( FG_TERRAIN, FG_DEBUG,
90 " deleting " << fragment_list.size() << " fragments" );
91 fragment_list.clear();
92 FG_LOG( FG_TERRAIN, FG_DEBUG,
93 " deleting " << nodes.size() << " nodes" );
96 // delete the ssg structures
97 FG_LOG( FG_TERRAIN, FG_DEBUG,
98 " deleting (leaf data) vertex, normal, and "
99 << " texture coordinate arrays" );
101 for ( i = 0; i < (int)vec3_ptrs.size(); ++i ) {
103 delete [] vec3_ptrs[i];
110 for ( i = 0; i < (int)vec2_ptrs.size(); ++i ) {
112 delete [] vec2_ptrs[i];
119 for ( i = 0; i < (int)index_ptrs.size(); ++i ) {
120 delete index_ptrs[i];
124 // delete the ssg branch
126 int pcount = select_ptr->getNumParents();
128 // find the first parent (should only be one)
129 ssgBranch *parent = select_ptr->getParent( 0 ) ;
131 // my_remove_branch( select_ptr );
132 parent->removeKid( select_ptr );
135 FG_LOG( FG_TERRAIN, FG_ALERT,
136 "parent pointer is NULL! Dying" );
140 FG_LOG( FG_TERRAIN, FG_ALERT,
141 "Parent count is zero for an ssg tile! Dying" );
147 // when a tile is still in the cache, but not in the immediate draw
148 // list, it can still remain in the scene graph, but we use a range
149 // selector to disable it from ever being drawn.
151 FGTileEntry::ssg_disable() {
152 // cout << "TILE STATE = " << state << endl;
153 if ( state == Scheduled_for_use ) {
154 state = Scheduled_for_cache;
155 } else if ( state == Scheduled_for_cache ) {
157 } else if ( (state == Loaded) || (state == Cached) ) {
159 // cout << "DISABLING SSG NODE" << endl;
160 select_ptr->select(0);
162 FG_LOG( FG_TERRAIN, FG_ALERT,
163 "Trying to disable an unused tile! Dying" );
166 // cout << "TILE STATE = " << state << endl;