// $Id$
-#include <Include/compiler.h>
+#include <simgear/compiler.h>
#ifdef FG_MATH_EXCEPTION_CLASH
# include <math.h>
#include STL_FUNCTIONAL
#include STL_ALGORITHM
-#include <Debug/logstream.hxx>
-#include <Bucket/newbucket.hxx>
+#include <simgear/bucket/newbucket.hxx>
+#include <simgear/debug/logstream.hxx>
#include "tileentry.hxx"
// Constructor
FGTileEntry::FGTileEntry ( void )
: ncount(0),
- state(Unused),
- vtlist(NULL),
- vnlist(NULL),
- tclist(NULL)
+ state(Unused)
{
nodes.clear();
+ select_ptr = NULL;
}
}
-// Step through the fragment list, deleting the display list, then the
-// fragment, until the list is empty. Also delete the arrays used by
+// recurse an ssg tree and call removeKid() on every node from the
+// bottom up. Leaves the original branch in existance, but empty so
+// it can be removed by the calling routine.
+static void my_remove_branch( ssgBranch * branch ) {
+ for ( ssgEntity *k = branch->getKid( 0 );
+ k != NULL;
+ k = branch->getNextKid() )
+ {
+ if ( k -> isAKindOf ( ssgTypeBranch() ) ) {
+ my_remove_branch( (ssgBranch *)k );
+ branch -> removeKid ( k );
+ } else if ( k -> isAKindOf ( ssgTypeLeaf() ) ) {
+ branch -> removeKid ( k ) ;
+ }
+ }
+}
+
+
+// Clean up the memory used by this tile and delete the arrays used by
// ssg as well as the whole ssg branch
-void
-FGTileEntry::free_tile()
-{
- FG_LOG( FG_TERRAIN, FG_INFO,
+void FGTileEntry::free_tile() {
+ int i;
+ FG_LOG( FG_TERRAIN, FG_DEBUG,
"FREEING TILE = (" << tile_bucket << ")" );
// mark tile unused
mark_unused();
- // delete fragment list
- FG_LOG( FG_TERRAIN, FG_INFO,
- " deleting " << fragment_list.size() << " fragments" );
- // for_each( begin(), end(),
- // mem_fun_ref( &fgFRAGMENT::deleteDisplayList ));
- fragment_list.erase( begin(), end() );
-
- // delete the ssg used structures
- FG_LOG( FG_TERRAIN, FG_INFO,
- " deleting vertex, normal, and texture coordinate arrays" );
- FG_LOG( FG_TERRAIN, FG_INFO,
- " deleting vertex array" );
- if ( vtlist != NULL ) {
- delete vtlist;
+ FG_LOG( FG_TERRAIN, FG_DEBUG,
+ " deleting " << nodes.size() << " nodes" );
+ nodes.clear();
+
+ // delete the ssg structures
+ FG_LOG( FG_TERRAIN, FG_DEBUG,
+ " deleting (leaf data) vertex, normal, and "
+ << " texture coordinate arrays" );
+
+ for ( i = 0; i < (int)vec3_ptrs.size(); ++i ) {
+#ifdef macintosh
+ delete [] vec3_ptrs[i];
+#else
+ delete vec3_ptrs[i];
+#endif
}
- FG_LOG( FG_TERRAIN, FG_INFO,
- " deleting normal array" );
- if ( vnlist != NULL ) {
- delete vnlist;
+ vec3_ptrs.clear();
+
+ for ( i = 0; i < (int)vec2_ptrs.size(); ++i ) {
+#ifdef macintosh
+ delete [] vec2_ptrs[i];
+#else
+ delete vec2_ptrs[i];
+#endif
}
- FG_LOG( FG_TERRAIN, FG_INFO,
- " deleting texture coordinate array" );
- if ( tclist != NULL ) {
- delete tclist;
+ vec2_ptrs.clear();
+
+ for ( i = 0; i < (int)index_ptrs.size(); ++i ) {
+ delete index_ptrs[i];
}
+ index_ptrs.clear();
// delete the ssg branch
- // make sure we have a sane number of parents
int pcount = select_ptr->getNumParents();
if ( pcount > 0 ) {
// find the first parent (should only be one)
ssgBranch *parent = select_ptr->getParent( 0 ) ;
- // find the number of kids this parent has
- int kcount = parent->getNumKids();
- // find the kid that matches our original select_ptr
- bool found_kid = false;
- for ( int i = 0; i < kcount; ++i ) {
- ssgEntity *kid = parent->getKid( i );
- if ( kid == select_ptr ) {
- FG_LOG( FG_TERRAIN, FG_INFO,
- "Found a kid to delete " << kid);
- found_kid = true;
- }
- }
- if ( ! found_kid ) {
+ if( parent ) {
+ // my_remove_branch( select_ptr );
+ parent->removeKid( select_ptr );
+ select_ptr = NULL;
+ } else {
FG_LOG( FG_TERRAIN, FG_ALERT,
- "Couldn't find the kid to delete! Dying" );
+ "parent pointer is NULL! Dying" );
exit(-1);
}
} else {
// selector to disable it from ever being drawn.
void
FGTileEntry::ssg_disable() {
- cout << "TILE STATE = " << state << endl;
+ // cout << "TILE STATE = " << state << endl;
if ( state == Scheduled_for_use ) {
state = Scheduled_for_cache;
} else if ( state == Scheduled_for_cache ) {
// do nothing
} else if ( (state == Loaded) || (state == Cached) ) {
state = Cached;
- cout << "DISABLING SSG NODE" << endl;
+ // cout << "DISABLING SSG NODE" << endl;
select_ptr->select(0);
} else {
FG_LOG( FG_TERRAIN, FG_ALERT,
"Trying to disable an unused tile! Dying" );
exit(-1);
}
- cout << "TILE STATE = " << state << endl;
+ // cout << "TILE STATE = " << state << endl;
}