From eb02aba5c8d0d55d72aaeeff49ce2cc793dd436d Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 27 Oct 1999 00:52:25 +0000 Subject: [PATCH] More tile memory clean ups. --- src/Scenery/tilecache.cxx | 24 +++++++++++---------- src/Scenery/tileentry.cxx | 44 +++++++++++++++------------------------ src/Scenery/tileentry.hxx | 18 ++++++++++------ 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/Scenery/tilecache.cxx b/src/Scenery/tilecache.cxx index e3c5c61b6..c052b233b 100644 --- a/src/Scenery/tilecache.cxx +++ b/src/Scenery/tilecache.cxx @@ -37,6 +37,7 @@ #include #include #include +#include #include
#include
#include @@ -82,9 +83,9 @@ FGTileCache::init( void ) << tile_cache.size() ); FGTileEntry e; e.mark_unused(); - e.vtlist = NULL; - e.vnlist = NULL; - e.tclist = NULL; + e.vec3_ptrs.clear(); + e.vec2_ptrs.clear(); + e.index_ptrs.clear(); FG_LOG( FG_TERRAIN, FG_DEBUG, " size of tile = " << sizeof( e ) ); @@ -151,20 +152,15 @@ 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) ) + if ( tile_cache[index].vec3_ptrs.size() || + tile_cache[index].vec2_ptrs.size() || + tile_cache[index].index_ptrs.size() ) { 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].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() ); @@ -179,6 +175,12 @@ FGTileCache::fill_in( int index, const FGBucket& p ) tile_cache[index].range_ptr = new ssgRangeSelector; ssgBranch *new_tile = fgObjLoad( tile_path.str(), &tile_cache[index] ); + if ( current_options.get_clouds() ) { + ssgLeaf *cloud_layer = fgGenCloudLayer( &tile_cache[index], + current_options.get_clouds_asl() ); + new_tile -> addKid( cloud_layer ); + } + if ( new_tile != NULL ) { tile_cache[index].range_ptr->addKid( new_tile ); } diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index 277dff4a5..d2248c931 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -42,10 +42,7 @@ FG_USING_STD(mem_fun_ref); // Constructor FGTileEntry::FGTileEntry ( void ) : ncount(0), - state(Unused), - vtlist(NULL), - vnlist(NULL), - tclist(NULL) + state(Unused) { nodes.clear(); } @@ -79,9 +76,8 @@ static void my_remove_branch( ssgBranch * branch ) { // 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::free_tile() -{ +void FGTileEntry::free_tile() { + int i; FG_LOG( FG_TERRAIN, FG_DEBUG, "FREEING TILE = (" << tile_bucket << ")" ); @@ -98,29 +94,23 @@ FGTileEntry::free_tile() // delete the ssg structures FG_LOG( FG_TERRAIN, FG_DEBUG, - " deleting vertex, normal, and texture coordinate arrays" ); - FG_LOG( FG_TERRAIN, FG_DEBUG, - " deleting vertex array" ); - if ( vtlist != NULL ) { - delete vtlist; - vtlist = NULL; + " deleting (leaf data) vertex, normal, and " + << " texture coordinate arrays" ); + + for ( i = 0; i < (int)vec3_ptrs.size(); ++i ) { + delete vec3_ptrs[i]; } - FG_LOG( FG_TERRAIN, FG_DEBUG, - " deleting normal array" ); - if ( vnlist != NULL ) { - delete vnlist; - vnlist = NULL; + vec3_ptrs.clear(); + + for ( i = 0; i < (int)vec2_ptrs.size(); ++i ) { + delete vec2_ptrs[i]; } - FG_LOG( FG_TERRAIN, FG_DEBUG, - " deleting texture coordinate array" ); - if ( tclist != NULL ) { - delete tclist; - tclist = NULL; + vec2_ptrs.clear(); + + for ( i = 0; i < (int)index_ptrs.size(); ++i ) { + delete index_ptrs[i]; } - for ( int i = 0; i < (int)free_ptrs.size(); ++i ) { - delete free_ptrs[i]; - } - free_ptrs.clear(); + index_ptrs.clear(); // delete the ssg branch diff --git a/src/Scenery/tileentry.hxx b/src/Scenery/tileentry.hxx index 8607591ff..49e7931fc 100644 --- a/src/Scenery/tileentry.hxx +++ b/src/Scenery/tileentry.hxx @@ -84,7 +84,9 @@ public: typedef container::iterator FragmentIterator; typedef container::const_iterator FragmentConstIterator; - typedef vector < unsigned short * > free_list; + typedef vector < sgVec3 * > free_vec3_list; + typedef vector < sgVec2 * > free_vec2_list; + typedef vector < unsigned short * > free_index_list; public: // node list (the per fragment face lists reference this node list) @@ -108,11 +110,15 @@ public: container fragment_list; // ssg related structures - sgVec3 *vtlist; - sgVec3 *vnlist; - sgVec2 *tclist; - free_list free_ptrs; // list of pointers to free when tile - // entry goes away + // sgVec3 *vtlist; + // sgVec3 *vnlist; + // sgVec2 *tclist; + + // list of pointers to memory chunks that need to be freed when + // tile entry goes away + free_vec3_list vec3_ptrs; + free_vec2_list vec2_ptrs; + free_index_list index_ptrs; // ssg tree structure for this tile is as follows: // ssgRoot(scene)