X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FScenery%2Ftilecache.cxx;h=41dc85b8bb33417e6caddae550fe2ed997712e9a;hb=1294aed4650ec2aacef27a7fdeb2f4e012516ca0;hp=f60bad41bece96f0e61084dcb2a2bc10e7efb549;hpb=8d58f642575718f4e5b7ddd480a8c1e86333cfab;p=flightgear.git diff --git a/src/Scenery/tilecache.cxx b/src/Scenery/tilecache.cxx index f60bad41b..41dc85b8b 100644 --- a/src/Scenery/tilecache.cxx +++ b/src/Scenery/tilecache.cxx @@ -2,7 +2,7 @@ // // Written by Curtis Olson, started January 1998. // -// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +// Copyright (C) 1998, 1999 Curtis L. Olson - curt@flightgear.org // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -30,17 +30,21 @@ #endif #include -#include +#include -#include // plib include +#include // plib include + +#include +#include +#include +#include -#include #include -#include +#include #include
#include
-#include #include +#include // for scenery.center #include "tilecache.hxx" #include "tileentry.hxx" @@ -81,11 +85,15 @@ FGTileCache::init( void ) FG_LOG( FG_TERRAIN, FG_DEBUG, " current cache size = " << tile_cache.size() ); FGTileEntry e; + e.mark_unused(); + e.vec3_ptrs.clear(); + e.vec2_ptrs.clear(); + e.index_ptrs.clear(); + 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 ); @@ -103,6 +111,10 @@ FGTileCache::init( void ) tile_cache[i].mark_unused(); tile_cache[i].tile_bucket.make_bad(); } + + // and ... just in case we missed something ... + terrain->removeAllKids(); + FG_LOG( FG_TERRAIN, FG_DEBUG, " done with init()" ); } @@ -125,47 +137,117 @@ 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; + // cout << "FILL IN CACHE ENTRY = " << index << endl; - // 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; - - // Load the appropriate data file and build tile fragment list - FGPath tile_path( current_options.get_fg_root() ); - tile_path.append( "Scenery" ); - tile_path.append( p.gen_base_path() ); - tile_path.append( p.gen_index_str() ); - - tile_cache[index].tile_bucket = p; + 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); + } tile_cache[index].select_ptr = new ssgSelector; tile_cache[index].transform_ptr = new ssgTransform; tile_cache[index].range_ptr = new ssgRangeSelector; + tile_cache[index].tile_bucket = p; + + FGPath tile_path( current_options.get_fg_root() ); + tile_path.append( "Scenery" ); + tile_path.append( p.gen_base_path() ); + + // Load the appropriate data file and build tile fragment list + FGPath tile_base = tile_path; + tile_base.append( p.gen_index_str() ); + ssgBranch *new_tile = fgObjLoad( tile_base.str(), &tile_cache[index], + true ); - ssgBranch *new_tile = fgObjLoad( tile_path.str(), &tile_cache[index] ); if ( new_tile != NULL ) { tile_cache[index].range_ptr->addKid( new_tile ); } + + // load custom objects + cout << "CUSTOM OBJECTS" << endl; + + FGPath index_path = tile_path; + index_path.append( p.gen_index_str() ); + index_path.concat( ".ind" ); + + cout << "Looking in " << index_path.str() << endl; + + fg_gzifstream in( index_path.str() ); + + if ( in.is_open() ) { + string token, name; + + while ( ! in.eof() ) { + in >> token; + in >> name; +#ifdef MACOS + in >> ::skipws; +#else + in >> skipws; +#endif + cout << "token = " << token << " name = " << name << endl; + + FGPath custom_path = tile_path; + custom_path.append( name ); + ssgBranch *custom_obj = fgObjLoad( custom_path.str(), + &tile_cache[index], false ); + if ( (new_tile != NULL) && (custom_obj != NULL) ) { + new_tile -> addKid( custom_obj ); + } + } + } + + // generate cloud layer + if ( current_options.get_clouds() ) { + ssgLeaf *cloud_layer = fgGenCloudLayer( &tile_cache[index], + current_options.get_clouds_asl() ); + cloud_layer->clrTraversalMaskBits( SSGTRAV_HOT ); + new_tile -> addKid( cloud_layer ); + } + tile_cache[index].transform_ptr->addKid( tile_cache[index].range_ptr ); + + // calculate initial tile offset + tile_cache[index].SetOffset( scenery.center ); + sgCoord sgcoord; + sgSetCoord( &sgcoord, + tile_cache[index].offset.x(), + tile_cache[index].offset.y(), tile_cache[index].offset.z(), + 0.0, 0.0, 0.0 ); + tile_cache[index].transform_ptr->setTransform( &sgcoord ); + tile_cache[index].select_ptr->addKid( tile_cache[index].transform_ptr ); terrain->addKid( tile_cache[index].select_ptr ); if ( tile_cache[index].is_scheduled_for_cache() ) { - cout << "FOUND ONE SCHEDULED FOR CACHE" << endl; + // cout << "FOUND ONE SCHEDULED FOR CACHE" << endl; // load, but not needed now so disable tile_cache[index].mark_loaded(); tile_cache[index].ssg_disable(); tile_cache[index].select_ptr->select(0); } else { - cout << "FOUND ONE READY TO LOAD" << endl; + // cout << "FOUND ONE READY TO LOAD" << endl; tile_cache[index].mark_loaded(); tile_cache[index].select_ptr->select(1); } @@ -176,7 +258,7 @@ FGTileCache::fill_in( int index, const FGBucket& p ) void FGTileCache::entry_free( int cache_index ) { - cout << "FREEING CACHE ENTRY = " << cache_index << endl; + // cout << "FREEING CACHE ENTRY = " << cache_index << endl; tile_cache[cache_index].free_tile(); } @@ -243,8 +325,8 @@ FGTileCache::next_avail( void ) // index. if ( max_index >=0 ) { - FG_LOG( FG_TERRAIN, FG_INFO, " max_dist = " << max_dist ); - FG_LOG( FG_TERRAIN, FG_INFO, " index = " << max_index ); + FG_LOG( FG_TERRAIN, FG_DEBUG, " max_dist = " << max_dist ); + FG_LOG( FG_TERRAIN, FG_DEBUG, " index = " << max_index ); entry_free( max_index ); return( max_index ); } else {