]> git.mxchange.org Git - flightgear.git/commitdiff
Add a key mapping (F3) for taking a screen snap shot.
authorcurt <curt>
Tue, 26 Oct 1999 03:45:33 +0000 (03:45 +0000)
committercurt <curt>
Tue, 26 Oct 1999 03:45:33 +0000 (03:45 +0000)
Keep track of and free index arrays that are fed to ssg.
Ssg branch deletion memory leak work around.

src/GUI/gui.cxx
src/GUI/gui.h
src/Main/keyboard.cxx
src/Objects/obj.cxx
src/Scenery/tilecache.cxx
src/Scenery/tileentry.cxx
src/Scenery/tileentry.hxx
src/WeatherCM/FGVoronoi.h

index a084813c34d8392f7bc6b719ba68dc1bdcb89892..5158bd046fd3bcd172e5ab5ebd34afc89b97df6c 100644 (file)
@@ -880,8 +880,13 @@ void printScreen ( puObject *obj ) {
 #endif // #ifdef WIN32
 
 
-// do a screen snap shot
 void dumpSnapShot ( puObject *obj ) {
+    fgDumpSnapShot();
+}
+
+
+// do a screen snap shot
+void fgDumpSnapShot () {
     bool show_pu_cursor = false;
 
     mainMenuBar->hide();
index 8a592de0f4e13406670213af0c31956e553e0db6..ac820e27adee9269f1d040fe822f1d6341f6e1ea 100644 (file)
@@ -38,6 +38,8 @@ extern void mkDialog(const char *txt);
 extern void ConfirmExitDialog(void);
 extern void guiFixPanel( void );
 
+extern void fgDumpSnapShot();
+
 extern puFont guiFnt;
 extern fntTexFont *guiFntHandle;
 
index 36d79c7ede24e430eca03e2e8d325c1b3273b59a..825f0860eba402a97edc3ea45d70556511838688 100644 (file)
@@ -413,9 +413,12 @@ void GLUTspecialkey(int k, int x, int y) {
                    t->togglePauseMode();
                return;
            }
+       case GLUT_KEY_F3: // F2 Take a screen shot
+           fgDumpSnapShot();
+           return;
         case GLUT_KEY_F6: // F6 toggles Autopilot target location
-                fgAPToggleWayPoint();
-                return;
+           fgAPToggleWayPoint();
+           return;
        case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
            current_options.cycle_fog();
        
index a7fc342e8152a8729dd21082097e64015f005e07..6c91c59ee7a2941785f4c4abd18b51aeb0c1cf82 100644 (file)
@@ -234,7 +234,9 @@ ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
     }
     
     unsigned short *vindex = new unsigned short [ 4 ];
+    t->free_ptrs.push_back( vindex );
     unsigned short *tindex = new unsigned short [ 4 ];
+    t->free_ptrs.push_back( tindex );
     for ( i = 0; i < 4; ++i ) {
        vindex[i] = i;
        tindex[i] = i;
@@ -284,6 +286,7 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
     ssgSimpleState *state = NULL;
 
     ssgBranch *tile = new ssgBranch () ;
+
     tile -> setName ( (char *)path.c_str() ) ;
 
     // Attempt to open "path.gz" or "path"
@@ -726,8 +729,12 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t) {
                // build the ssg entity
                unsigned short *vindex = 
                    new unsigned short [ fan_vertices.size() ];
+               t->free_ptrs.push_back( vindex );
+
                unsigned short *tindex = 
                    new unsigned short [ fan_tex_coords.size() ];
+               t->free_ptrs.push_back( tindex );
+
                for ( i = 0; i < (int)fan_vertices.size(); ++i ) {
                    vindex[i] = fan_vertices[i];
                }
index 1c82ca66737584469a1113a606faf7291ceeb963..e3c5c61b6a8d85959a199103aa00a6b19f812e05 100644 (file)
@@ -81,11 +81,15 @@ FGTileCache::init( void )
     FG_LOG( FG_TERRAIN, FG_DEBUG, "  current cache size = " 
            << tile_cache.size() );
     FGTileEntry e;
+    e.mark_unused();
+    e.vtlist = NULL;
+    e.vnlist = NULL;
+    e.tclist = NULL;
+    
     FG_LOG( FG_TERRAIN, FG_DEBUG, "  size of tile = " 
            << sizeof( e ) );
     if ( target_cache_size > (int)tile_cache.size() ) {
        // FGTileEntry e;
-       e.mark_unused();
        int expansion_amt = target_cache_size - (int)tile_cache.size();
        for ( i = 0; i < expansion_amt; ++i ) {
            tile_cache.push_back( e );
@@ -129,18 +133,38 @@ FGTileCache::exists( const FGBucket& p )
 }
 
 
+#if 0
+static void print_refs( ssgSelector *sel, ssgTransform *trans, 
+                ssgRangeSelector *range) 
+{
+    cout << "selector -> " << sel->getRef()
+        << "  transform -> " << trans->getRef()
+        << "  range -> " << range->getRef() << endl;
+}
+#endif
+
+
 // Fill in a tile cache entry with real data for the specified bucket
 void
 FGTileCache::fill_in( int index, const FGBucket& p )
 {
     // cout << "FILL IN CACHE ENTRY = " << index << endl;
 
+    tile_cache[index].center = Point3D( 0.0 );
+    if ( (tile_cache[index].vtlist != NULL) || 
+        (tile_cache[index].vnlist != NULL) || 
+        (tile_cache[index].tclist != NULL) )
+    {
+       FG_LOG( FG_TERRAIN, FG_ALERT, 
+               "Attempting to overwrite existing or"
+               << " not properly freed leaf data." );
+       exit(-1);
+    }
     // Force some values in case the tile fails to load (i.e. fill
     // doesn't exist)
-    tile_cache[index].center = Point3D( 0.0 );
-    tile_cache[index].vtlist = NULL;
-    tile_cache[index].vnlist = NULL;
-    tile_cache[index].tclist = NULL;
+    // tile_cache[index].vtlist = NULL;
+    // tile_cache[index].vnlist = NULL;
+    // tile_cache[index].tclist = NULL;
 
     // Load the appropriate data file and build tile fragment list
     FGPath tile_path( current_options.get_fg_root() );
index a709049928f9217168376720a6f2b384cb86d05f..277dff4a57d99bac68994dbd890a12cf8f8f9374 100644 (file)
@@ -58,6 +58,24 @@ FGTileEntry::~FGTileEntry ( void ) {
 }
 
 
+// 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 ) ;
+       }
+    }
+}
+
+
 // 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
@@ -85,17 +103,24 @@ FGTileEntry::free_tile()
            "    deleting vertex array" );
     if ( vtlist != NULL ) {
        delete vtlist;
+       vtlist = NULL;
     }
     FG_LOG( FG_TERRAIN, FG_DEBUG,
            "    deleting normal array" );
     if ( vnlist != NULL ) {
        delete vnlist;
+       vnlist = NULL;
     }
     FG_LOG( FG_TERRAIN, FG_DEBUG,
            "    deleting texture coordinate array" );
     if ( tclist != NULL ) {
        delete tclist;
+       tclist = NULL;
+    }
+    for ( int i = 0; i < (int)free_ptrs.size(); ++i ) {
+       delete free_ptrs[i];
     }
+    free_ptrs.clear();
 
     // delete the ssg branch
 
@@ -104,34 +129,13 @@ FGTileEntry::free_tile()
        // find the first parent (should only be one)
        ssgBranch *parent = select_ptr->getParent( 0 ) ;
        if( parent ) {
-           parent->removeKid(select_ptr);
+           my_remove_branch( select_ptr );
+           parent->removeKid( select_ptr );
        } else {
            FG_LOG( FG_TERRAIN, FG_ALERT,
                    "parent pointer is NULL!  Dying" );
            exit(-1);
        }
-
-#if 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_DEBUG,
-                       "Found a kid to delete " << kid);
-               found_kid = true;
-               parent->removeKid( i );
-           }
-       }
-       if ( ! found_kid ) {
-           FG_LOG( FG_TERRAIN, FG_ALERT,
-                   "Couldn't find the kid to delete!  Dying" );
-           exit(-1);
-       }
-#endif
-
     } else {
        FG_LOG( FG_TERRAIN, FG_ALERT,
                "Parent count is zero for an ssg tile!  Dying" );
index 5b6824d6f27ab463c00839c32112b4122f8161c8..8607591ff2f77cfc6afafb9a81cd3b89eee386dd 100644 (file)
@@ -84,6 +84,8 @@ public:
     typedef container::iterator FragmentIterator;
     typedef container::const_iterator FragmentConstIterator;
 
+    typedef vector < unsigned short * > free_list;
+
 public:
     // node list (the per fragment face lists reference this node list)
     point_list nodes;
@@ -109,6 +111,8 @@ public:
     sgVec3 *vtlist;
     sgVec3 *vnlist;
     sgVec2 *tclist;
+    free_list free_ptrs; // list of pointers to free when tile
+                                 // entry goes away
 
     // ssg tree structure for this tile is as follows:
     // ssgRoot(scene)
@@ -160,9 +164,9 @@ public:
     void free_tile();
 
     // Calculate this tile's offset
-    void SetOffset( const Point3D& off)
+    void SetOffset( const Point3D& p)
     {
-       offset = center - off;
+       offset = center - p;
     }
 
     // Return this tile's offset
index da4b337dbf0096cb633cdc9e0fff6f2e2ecc848b..b2906dece27edca56de338129b1d76e5ae2f1e31 100644 (file)
@@ -110,10 +110,3 @@ typedef vector<FGVoronoiOutput> FGVoronoiOutputList;
 FGVoronoiOutputList Voronoiate(const FGVoronoiInputList& input);
 
 #endif /*FGVoronoi_H*/
-
-
-
-
-
-
-