1999-06-12 21:15:27 +00:00
|
|
|
// tile.cxx -- routines to handle a scenery tile
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started May 1998.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
#include <simgear/compiler.h>
|
1999-06-12 21:15:27 +00:00
|
|
|
|
|
|
|
#ifdef FG_MATH_EXCEPTION_CLASH
|
|
|
|
# include <math.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include STL_FUNCTIONAL
|
|
|
|
#include STL_ALGORITHM
|
|
|
|
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/bucket/newbucket.hxx>
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
1999-06-12 21:15:27 +00:00
|
|
|
|
|
|
|
#include "tileentry.hxx"
|
|
|
|
|
|
|
|
FG_USING_STD(for_each);
|
|
|
|
FG_USING_STD(mem_fun_ref);
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
FGTileEntry::FGTileEntry ( void )
|
|
|
|
: ncount(0),
|
1999-10-27 00:52:25 +00:00
|
|
|
state(Unused)
|
1999-06-12 21:15:27 +00:00
|
|
|
{
|
|
|
|
nodes.clear();
|
2000-06-15 22:32:26 +00:00
|
|
|
select_ptr = NULL;
|
1999-06-12 21:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
FGTileEntry::~FGTileEntry ( void ) {
|
|
|
|
// cout << "nodes = " << nodes.size() << endl;;
|
|
|
|
// delete[] nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-26 03:45:33 +00:00
|
|
|
// 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 ) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-29 14:57:00 +00:00
|
|
|
// 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
|
1999-10-27 00:52:25 +00:00
|
|
|
void FGTileEntry::free_tile() {
|
|
|
|
int i;
|
1999-09-01 18:52:31 +00:00
|
|
|
FG_LOG( FG_TERRAIN, FG_DEBUG,
|
1999-06-12 21:15:27 +00:00
|
|
|
"FREEING TILE = (" << tile_bucket << ")" );
|
1999-06-29 14:57:00 +00:00
|
|
|
|
|
|
|
// mark tile unused
|
|
|
|
mark_unused();
|
|
|
|
|
1999-09-01 18:52:31 +00:00
|
|
|
// delete fragment list and node list
|
|
|
|
FG_LOG( FG_TERRAIN, FG_DEBUG,
|
1999-07-25 01:52:36 +00:00
|
|
|
" deleting " << fragment_list.size() << " fragments" );
|
1999-09-01 18:52:31 +00:00
|
|
|
fragment_list.clear();
|
|
|
|
FG_LOG( FG_TERRAIN, FG_DEBUG,
|
|
|
|
" deleting " << nodes.size() << " nodes" );
|
|
|
|
nodes.clear();
|
1999-06-29 14:57:00 +00:00
|
|
|
|
1999-09-01 18:52:31 +00:00
|
|
|
// delete the ssg structures
|
|
|
|
FG_LOG( FG_TERRAIN, FG_DEBUG,
|
1999-10-27 00:52:25 +00:00
|
|
|
" deleting (leaf data) vertex, normal, and "
|
|
|
|
<< " texture coordinate arrays" );
|
|
|
|
|
|
|
|
for ( i = 0; i < (int)vec3_ptrs.size(); ++i ) {
|
2000-02-10 23:37:56 +00:00
|
|
|
#ifdef MACOS
|
|
|
|
delete [] vec3_ptrs[i];
|
|
|
|
#else
|
1999-10-27 00:52:25 +00:00
|
|
|
delete vec3_ptrs[i];
|
2000-02-10 23:37:56 +00:00
|
|
|
#endif
|
1999-06-30 00:28:20 +00:00
|
|
|
}
|
1999-10-27 00:52:25 +00:00
|
|
|
vec3_ptrs.clear();
|
|
|
|
|
|
|
|
for ( i = 0; i < (int)vec2_ptrs.size(); ++i ) {
|
2000-02-10 23:37:56 +00:00
|
|
|
#ifdef MACOS
|
|
|
|
delete [] vec2_ptrs[i];
|
|
|
|
#else
|
1999-10-27 00:52:25 +00:00
|
|
|
delete vec2_ptrs[i];
|
2000-02-10 23:37:56 +00:00
|
|
|
#endif
|
1999-10-26 03:45:33 +00:00
|
|
|
}
|
1999-10-27 00:52:25 +00:00
|
|
|
vec2_ptrs.clear();
|
|
|
|
|
|
|
|
for ( i = 0; i < (int)index_ptrs.size(); ++i ) {
|
|
|
|
delete index_ptrs[i];
|
1999-06-30 00:28:20 +00:00
|
|
|
}
|
1999-10-27 00:52:25 +00:00
|
|
|
index_ptrs.clear();
|
1999-06-29 14:57:00 +00:00
|
|
|
|
|
|
|
// delete the ssg branch
|
|
|
|
|
1999-07-04 07:37:30 +00:00
|
|
|
int pcount = select_ptr->getNumParents();
|
1999-06-29 14:57:00 +00:00
|
|
|
if ( pcount > 0 ) {
|
|
|
|
// find the first parent (should only be one)
|
1999-07-04 07:37:30 +00:00
|
|
|
ssgBranch *parent = select_ptr->getParent( 0 ) ;
|
1999-10-06 20:59:52 +00:00
|
|
|
if( parent ) {
|
1999-10-30 02:37:56 +00:00
|
|
|
// my_remove_branch( select_ptr );
|
1999-10-26 03:45:33 +00:00
|
|
|
parent->removeKid( select_ptr );
|
2000-06-15 22:32:26 +00:00
|
|
|
select_ptr = NULL;
|
1999-10-06 20:59:52 +00:00
|
|
|
} else {
|
|
|
|
FG_LOG( FG_TERRAIN, FG_ALERT,
|
|
|
|
"parent pointer is NULL! Dying" );
|
|
|
|
exit(-1);
|
|
|
|
}
|
1999-06-29 14:57:00 +00:00
|
|
|
} else {
|
|
|
|
FG_LOG( FG_TERRAIN, FG_ALERT,
|
|
|
|
"Parent count is zero for an ssg tile! Dying" );
|
|
|
|
exit(-1);
|
1999-06-30 00:28:20 +00:00
|
|
|
}
|
1999-06-12 21:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-31 04:59:28 +00:00
|
|
|
// 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
|
1999-07-04 07:37:30 +00:00
|
|
|
// selector to disable it from ever being drawn.
|
|
|
|
void
|
|
|
|
FGTileEntry::ssg_disable() {
|
1999-08-14 22:07:35 +00:00
|
|
|
// cout << "TILE STATE = " << state << endl;
|
1999-07-04 07:37:30 +00:00
|
|
|
if ( state == Scheduled_for_use ) {
|
|
|
|
state = Scheduled_for_cache;
|
1999-07-31 04:59:28 +00:00
|
|
|
} else if ( state == Scheduled_for_cache ) {
|
|
|
|
// do nothing
|
1999-07-04 07:37:30 +00:00
|
|
|
} else if ( (state == Loaded) || (state == Cached) ) {
|
|
|
|
state = Cached;
|
1999-08-14 22:07:35 +00:00
|
|
|
// cout << "DISABLING SSG NODE" << endl;
|
1999-07-04 07:37:30 +00:00
|
|
|
select_ptr->select(0);
|
|
|
|
} else {
|
|
|
|
FG_LOG( FG_TERRAIN, FG_ALERT,
|
|
|
|
"Trying to disable an unused tile! Dying" );
|
|
|
|
exit(-1);
|
|
|
|
}
|
1999-08-14 22:07:35 +00:00
|
|
|
// cout << "TILE STATE = " << state << endl;
|
1999-07-04 07:37:30 +00:00
|
|
|
}
|