]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scenery/tileentry.cxx
Fix a small tile cache bug.
[flightgear.git] / src / Scenery / tileentry.cxx
index d90f465f263cb0e6a4926d707155d87a9d81c69d..b4847b367ed349aabbb04e261a5ce3a9915f8891 100644 (file)
@@ -42,7 +42,10 @@ FG_USING_STD(mem_fun_ref);
 // Constructor
 FGTileEntry::FGTileEntry ( void )
     : ncount(0),
-      state(Unused)
+      state(Unused),
+      vtlist(NULL),
+      vnlist(NULL),
+      tclist(NULL)
 {
     nodes.clear();
 }
@@ -55,17 +58,94 @@ FGTileEntry::~FGTileEntry ( void ) {
 }
 
 
-// Step through the fragment list, deleting the display list, then
-// the fragment, until the list is empty.
+// Step through the fragment list, deleting the display list, then the
+// fragment, until the list is empty.  Also delete the arrays used by
+// ssg as well as the whole ssg branch
 void
-FGTileEntry::release_fragments()
+FGTileEntry::free_tile()
 {
-    FG_LOG( FG_TERRAIN, FG_DEBUG,
+    FG_LOG( FG_TERRAIN, FG_INFO,
            "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() );
-    mark_unused();
+
+    // 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_INFO,
+           "    deleting normal array" );
+    if ( vnlist != NULL ) {
+       delete vnlist;
+    }
+    FG_LOG( FG_TERRAIN, FG_INFO,
+           "    deleting texture coordinate array" );
+    if ( tclist != NULL ) {
+       delete tclist;
+    }
+
+    // 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 ) {
+           FG_LOG( FG_TERRAIN, FG_ALERT,
+                   "Couldn't find the kid to delete!  Dying" );
+           exit(-1);
+       }
+    } else {
+       FG_LOG( FG_TERRAIN, FG_ALERT,
+               "Parent count is zero for an ssg tile!  Dying" );
+       exit(-1);
+    }
 }
 
 
+// when a tile is still in the cache, but not in the immediate draw
+// list, it can still remain in the scene graph, but we use a range
+// selector to disable it from ever being drawn.
+void 
+FGTileEntry::ssg_disable() {
+    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;
+       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;
+}