fg: move most scenery-related code to simgear
From Till Busch.
This commit is contained in:
parent
87b6632ba6
commit
4dea9807f6
11 changed files with 75 additions and 1236 deletions
|
@ -2133,12 +2133,6 @@
|
|||
<Filter
|
||||
Name="Lib_Scenery"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="..\..\src\Scenery\newcache.cxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\Scenery\newcache.hxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\Scenery\redout.cxx">
|
||||
</File>
|
||||
|
@ -2157,12 +2151,6 @@
|
|||
<File
|
||||
RelativePath="..\..\src\Scenery\SceneryPager.hxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\Scenery\tileentry.cxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\Scenery\tileentry.hxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\Scenery\tilemgr.cxx">
|
||||
</File>
|
||||
|
|
|
@ -81,7 +81,6 @@
|
|||
|
||||
#include <simgear/environment/visual_enviro.hxx>
|
||||
|
||||
#include <Scenery/tileentry.hxx>
|
||||
#include <Time/light.hxx>
|
||||
#include <Time/light.hxx>
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
noinst_LIBRARIES = libScenery.a
|
||||
|
||||
libScenery_a_SOURCES = \
|
||||
newcache.cxx newcache.hxx \
|
||||
redout.cxx redout.hxx \
|
||||
scenery.cxx scenery.hxx \
|
||||
SceneryPager.cxx SceneryPager.hxx \
|
||||
tileentry.cxx tileentry.hxx \
|
||||
tilemgr.cxx tilemgr.hxx
|
||||
|
||||
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
|
||||
|
|
|
@ -52,10 +52,11 @@ void SceneryPager::requestNodeFile(const std::string& fileName,osg::Group* group
|
|||
}
|
||||
|
||||
void SceneryPager::queueRequest(const std::string& fileName, osg::Group* group,
|
||||
float priority, osg::FrameStamp* frameStamp)
|
||||
float priority, osg::FrameStamp* frameStamp,
|
||||
osgDB::ReaderWriter::Options* options)
|
||||
{
|
||||
_pagerRequests.push_back(PagerRequest(fileName, group, priority,
|
||||
frameStamp));
|
||||
frameStamp, options));
|
||||
}
|
||||
|
||||
void SceneryPager::queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr)
|
||||
|
|
|
@ -38,8 +38,16 @@ public:
|
|||
virtual void requestNodeFile(const std::string& fileName,osg::Group* group,
|
||||
float priority, const osg::FrameStamp* framestamp);
|
||||
|
||||
virtual void requestNodeFile(const std::string& fileName,osg::Group* group,
|
||||
float priority, const osg::FrameStamp* framestamp,
|
||||
osgDB::ReaderWriter::Options* options) {
|
||||
osgDB::DatabasePager::requestNodeFile(fileName, group, priority,
|
||||
framestamp, options);
|
||||
}
|
||||
|
||||
void queueRequest(const std::string& fileName, osg::Group* node,
|
||||
float priority, osg::FrameStamp* frameStamp);
|
||||
float priority, osg::FrameStamp* frameStamp,
|
||||
osgDB::ReaderWriter::Options* options);
|
||||
// This is passed a ref_ptr so that it can "take ownership" of the
|
||||
// node to delete and decrement its refcount while holding the
|
||||
// lock on the delete list.
|
||||
|
@ -52,21 +60,27 @@ protected:
|
|||
PagerRequest() {}
|
||||
PagerRequest(const PagerRequest& rhs) :
|
||||
_fileName(rhs._fileName), _group(rhs._group),
|
||||
_priority(rhs._priority), _frameStamp(rhs._frameStamp) {}
|
||||
_priority(rhs._priority), _frameStamp(rhs._frameStamp),
|
||||
_options(rhs._options) {}
|
||||
|
||||
PagerRequest(const std::string& fileName, osg::Group* group,
|
||||
float priority, osg::FrameStamp* frameStamp) :
|
||||
float priority, osg::FrameStamp* frameStamp,
|
||||
osgDB::ReaderWriter::Options* options):
|
||||
_fileName(fileName), _group(group), _priority(priority),
|
||||
_frameStamp(frameStamp) {}
|
||||
_frameStamp(frameStamp), _options(options) {}
|
||||
|
||||
void doRequest(SceneryPager* pager)
|
||||
{
|
||||
if (_group->getNumChildren() == 0)
|
||||
pager->requestNodeFile(_fileName, _group.get(), _priority,
|
||||
_frameStamp.get());
|
||||
_frameStamp.get(), _options.get());
|
||||
}
|
||||
|
||||
std::string _fileName;
|
||||
osg::ref_ptr<osg::Group> _group;
|
||||
float _priority;
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> _options;
|
||||
};
|
||||
typedef std::vector<PagerRequest> PagerRequestList;
|
||||
PagerRequestList _pagerRequests;
|
||||
|
|
|
@ -1,191 +0,0 @@
|
|||
// newcache.cxx -- routines to handle scenery tile caching
|
||||
//
|
||||
// Written by Curtis Olson, started December 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/bucket/newbucket.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/viewer.hxx>
|
||||
#include <Scenery/scenery.hxx> // for scenery.center
|
||||
|
||||
#include "newcache.hxx"
|
||||
#include "tileentry.hxx"
|
||||
|
||||
|
||||
SG_USING_NAMESPACE(std);
|
||||
|
||||
|
||||
// Constructor
|
||||
FGNewCache::FGNewCache( void ) :
|
||||
max_cache_size(100)
|
||||
{
|
||||
tile_cache.clear();
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
FGNewCache::~FGNewCache( void ) {
|
||||
clear_cache();
|
||||
}
|
||||
|
||||
|
||||
// Free a tile cache entry
|
||||
void FGNewCache::entry_free( long cache_index ) {
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING CACHE ENTRY = " << cache_index );
|
||||
FGTileEntry *tile = tile_cache[cache_index];
|
||||
tile->disconnect_ssg_nodes();
|
||||
|
||||
#ifdef WISH_PLIB_WAS_THREADED // but it isn't
|
||||
tile->sched_removal();
|
||||
#else
|
||||
tile->free_tile();
|
||||
delete tile;
|
||||
#endif
|
||||
|
||||
tile_cache.erase( cache_index );
|
||||
}
|
||||
|
||||
|
||||
// Initialize the tile cache subsystem
|
||||
void FGNewCache::init( void ) {
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, "Initializing the tile cache." );
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, " max cache size = "
|
||||
<< max_cache_size );
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, " current cache size = "
|
||||
<< tile_cache.size() );
|
||||
|
||||
#if 0 // don't clear the cache
|
||||
clear_cache();
|
||||
#endif
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, " done with init()" );
|
||||
}
|
||||
|
||||
|
||||
// Search for the specified "bucket" in the cache
|
||||
bool FGNewCache::exists( const SGBucket& b ) const {
|
||||
long tile_index = b.gen_index();
|
||||
const_tile_map_iterator it = tile_cache.find( tile_index );
|
||||
|
||||
return ( it != tile_cache.end() );
|
||||
}
|
||||
|
||||
// Return the index of the oldest tile in the cache, return -1 if
|
||||
// nothing available to be removed.
|
||||
long FGNewCache::get_oldest_tile() {
|
||||
// we need to free the furthest entry
|
||||
long min_index = -1;
|
||||
double timestamp = 0.0;
|
||||
double min_time = DBL_MAX;
|
||||
|
||||
tile_map_iterator current = tile_cache.begin();
|
||||
tile_map_iterator end = tile_cache.end();
|
||||
|
||||
for ( ; current != end; ++current ) {
|
||||
long index = current->first;
|
||||
FGTileEntry *e = current->second;
|
||||
if ( e->is_loaded() ) {
|
||||
|
||||
timestamp = e->get_timestamp();
|
||||
if ( timestamp < min_time ) {
|
||||
min_time = timestamp;
|
||||
min_index = index;
|
||||
}
|
||||
|
||||
} else {
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "loaded = " << e->is_loaded()
|
||||
<< " time stamp = " << e->get_timestamp() );
|
||||
}
|
||||
}
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, " index = " << min_index );
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, " min_time = " << min_time );
|
||||
|
||||
return min_index;
|
||||
}
|
||||
|
||||
|
||||
// Clear the inner ring flag for all tiles in the cache so that the
|
||||
// external tile scheduler can flag the inner ring correctly.
|
||||
void FGNewCache::clear_inner_ring_flags() {
|
||||
tile_map_iterator current = tile_cache.begin();
|
||||
tile_map_iterator end = tile_cache.end();
|
||||
|
||||
for ( ; current != end; ++current ) {
|
||||
FGTileEntry *e = current->second;
|
||||
if ( e->is_loaded() ) {
|
||||
e->set_inner_ring( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear a cache entry, note that the cache only holds pointers
|
||||
// and this does not free the object which is pointed to.
|
||||
void FGNewCache::clear_entry( long cache_index ) {
|
||||
tile_cache.erase( cache_index );
|
||||
}
|
||||
|
||||
|
||||
// Clear all completely loaded tiles (ignores partially loaded tiles)
|
||||
void FGNewCache::clear_cache() {
|
||||
std::vector<long> indexList;
|
||||
tile_map_iterator current = tile_cache.begin();
|
||||
tile_map_iterator end = tile_cache.end();
|
||||
|
||||
for ( ; current != end; ++current ) {
|
||||
long index = current->first;
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "clearing " << index );
|
||||
FGTileEntry *e = current->second;
|
||||
if ( e->is_loaded() ) {
|
||||
e->tile_bucket.make_bad();
|
||||
// entry_free modifies tile_cache, so store index and call entry_free() later;
|
||||
indexList.push_back( index);
|
||||
}
|
||||
}
|
||||
for (unsigned int it = 0; it < indexList.size(); it++) {
|
||||
entry_free( indexList[ it]);
|
||||
}
|
||||
// and ... just in case we missed something ...
|
||||
osg::Group* group = globals->get_scenery()->get_terrain_branch();
|
||||
group->removeChildren(0, group->getNumChildren());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new tile and schedule it for loading.
|
||||
*/
|
||||
bool FGNewCache::insert_tile( FGTileEntry *e ) {
|
||||
// register tile in the cache
|
||||
long tile_index = e->get_tile_bucket().gen_index();
|
||||
tile_cache[tile_index] = e;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
// newcache.hxx -- routines to handle scenery tile caching
|
||||
//
|
||||
// Written by Curtis Olson, started December 2000.
|
||||
//
|
||||
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _NEWCACHE_HXX
|
||||
#define _NEWCACHE_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <simgear/bucket/newbucket.hxx>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
|
||||
#include "tileentry.hxx"
|
||||
|
||||
SG_USING_STD(map);
|
||||
|
||||
// A class to store and manage a pile of tiles
|
||||
class FGNewCache {
|
||||
public:
|
||||
typedef map < long, FGTileEntry * > tile_map;
|
||||
typedef tile_map::iterator tile_map_iterator;
|
||||
typedef tile_map::const_iterator const_tile_map_iterator;
|
||||
private:
|
||||
// cache storage space
|
||||
tile_map tile_cache;
|
||||
|
||||
// maximum cache size
|
||||
int max_cache_size;
|
||||
|
||||
// pointers to allow an external linear traversal of cache entries
|
||||
tile_map_iterator current;
|
||||
|
||||
// Free a tile cache entry
|
||||
void entry_free( long cache_index );
|
||||
|
||||
public:
|
||||
tile_map_iterator begin() { return tile_cache.begin(); }
|
||||
tile_map_iterator end() { return tile_cache.end(); }
|
||||
const_tile_map_iterator begin() const { return tile_cache.begin(); }
|
||||
const_tile_map_iterator end() const { return tile_cache.end(); }
|
||||
|
||||
// Constructor
|
||||
FGNewCache();
|
||||
|
||||
// Destructor
|
||||
~FGNewCache();
|
||||
|
||||
// Initialize the tile cache subsystem
|
||||
void init( void );
|
||||
|
||||
// Check if the specified "bucket" exists in the cache
|
||||
bool exists( const SGBucket& b ) const;
|
||||
|
||||
#if 0
|
||||
// Ensure at least one entry is free in the cache
|
||||
bool make_space();
|
||||
#endif
|
||||
|
||||
// Return the index of the oldest tile in the cache, return -1 if
|
||||
// nothing available to be removed.
|
||||
long get_oldest_tile();
|
||||
|
||||
// Clear the inner ring flag for all tiles in the cache so that
|
||||
// the external tile scheduler can flag the inner ring correctly.
|
||||
void clear_inner_ring_flags();
|
||||
|
||||
// Clear a cache entry, note that the cache only holds pointers
|
||||
// and this does not free the object which is pointed to.
|
||||
void clear_entry( long cache_entry );
|
||||
|
||||
// Clear all completely loaded tiles (ignores partially loaded tiles)
|
||||
void clear_cache();
|
||||
|
||||
// Return a pointer to the specified tile cache entry
|
||||
inline FGTileEntry *get_tile( const long tile_index ) const {
|
||||
const_tile_map_iterator it = tile_cache.find( tile_index );
|
||||
if ( it != tile_cache.end() ) {
|
||||
return it->second;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Return a pointer to the specified tile cache entry
|
||||
inline FGTileEntry *get_tile( const SGBucket& b ) const {
|
||||
return get_tile( b.gen_index() );
|
||||
}
|
||||
|
||||
// Return the cache size
|
||||
inline size_t get_size() const { return tile_cache.size(); }
|
||||
|
||||
// External linear traversal of cache
|
||||
inline void reset_traversal() { current = tile_cache.begin(); }
|
||||
inline bool at_end() { return current == tile_cache.end(); }
|
||||
inline FGTileEntry *get_current() const {
|
||||
// cout << "index = " << current->first << endl;
|
||||
return current->second;
|
||||
}
|
||||
inline void next() { ++current; }
|
||||
|
||||
inline int get_max_cache_size() const { return max_cache_size; }
|
||||
inline void set_max_cache_size( int m ) { max_cache_size = m; }
|
||||
|
||||
/**
|
||||
* Create a new tile and enqueue it for loading.
|
||||
* @param b
|
||||
* @return success/failure
|
||||
*/
|
||||
bool insert_tile( FGTileEntry* e );
|
||||
};
|
||||
|
||||
|
||||
#endif // _NEWCACHE_HXX
|
|
@ -1,592 +0,0 @@
|
|||
// tileentry.cxx -- routines to handle a scenery tile
|
||||
//
|
||||
// Written by Curtis Olson, started May 1998.
|
||||
//
|
||||
// Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <plib/ul.h>
|
||||
#include <Main/main.hxx>
|
||||
|
||||
|
||||
#include STL_STRING
|
||||
#include <sstream>
|
||||
|
||||
#include <osg/Array>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Geode>
|
||||
#include <osg/LOD>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/Math>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Switch>
|
||||
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include <simgear/bucket/newbucket.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/math/polar3d.hxx>
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
#include <simgear/math/sg_random.h>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include <simgear/misc/sgstream.hxx>
|
||||
#include <simgear/scene/material/mat.hxx>
|
||||
#include <simgear/scene/material/matlib.hxx>
|
||||
#include <simgear/scene/model/ModelRegistry.hxx>
|
||||
#include <simgear/scene/tgdb/apt_signs.hxx>
|
||||
#include <simgear/scene/tgdb/obj.hxx>
|
||||
#include <simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx>
|
||||
#include <simgear/scene/model/placementtrans.hxx>
|
||||
#include <simgear/scene/util/SGUpdateVisitor.hxx>
|
||||
|
||||
#include <Aircraft/aircraft.hxx>
|
||||
#include <Include/general.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/viewer.hxx>
|
||||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/light.hxx>
|
||||
|
||||
#include "tileentry.hxx"
|
||||
#include "tilemgr.hxx"
|
||||
|
||||
SG_USING_STD(string);
|
||||
using namespace simgear;
|
||||
|
||||
// FIXME: investigate what huge update flood is clamped away here ...
|
||||
class FGTileUpdateCallback : public osg::NodeCallback {
|
||||
public:
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
assert(dynamic_cast<SGUpdateVisitor*>(nv));
|
||||
SGUpdateVisitor* updateVisitor = static_cast<SGUpdateVisitor*>(nv);
|
||||
|
||||
osg::Vec3 center = node->getBound().center();
|
||||
double distance = dist(updateVisitor->getGlobalEyePos(),
|
||||
SGVec3d(center[0], center[1], center[2]));
|
||||
if (updateVisitor->getVisibility() + node->getBound().radius() < distance)
|
||||
return;
|
||||
|
||||
traverse(node, nv);
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
// Update the timestamp on a tile whenever it is in view.
|
||||
|
||||
class TileCullCallback : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
TileCullCallback() : _timeStamp(0) {}
|
||||
TileCullCallback(const TileCullCallback& tc, const osg::CopyOp& copyOp) :
|
||||
NodeCallback(tc, copyOp), _timeStamp(tc._timeStamp)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
double getTimeStamp() const { return _timeStamp; }
|
||||
void setTimeStamp(double timeStamp) { _timeStamp = timeStamp; }
|
||||
protected:
|
||||
double _timeStamp;
|
||||
};
|
||||
}
|
||||
|
||||
void TileCullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (nv->getFrameStamp())
|
||||
_timeStamp = nv->getFrameStamp()->getReferenceTime();
|
||||
traverse(node, nv);
|
||||
}
|
||||
|
||||
double FGTileEntry::get_timestamp() const
|
||||
{
|
||||
if (_node.valid()) {
|
||||
return (dynamic_cast<TileCullCallback*>(_node->getCullCallback()))
|
||||
->getTimeStamp();
|
||||
} else
|
||||
return DBL_MAX;
|
||||
}
|
||||
|
||||
void FGTileEntry::set_timestamp(double time_ms)
|
||||
{
|
||||
if (_node.valid()) {
|
||||
TileCullCallback* cb
|
||||
= dynamic_cast<TileCullCallback*>(_node->getCullCallback());
|
||||
if (cb)
|
||||
cb->setTimeStamp(time_ms);
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor
|
||||
FGTileEntry::FGTileEntry ( const SGBucket& b )
|
||||
: tile_bucket( b ),
|
||||
_node( new osg::LOD ),
|
||||
is_inner_ring(false),
|
||||
free_tracker(0),
|
||||
tileFileName(b.gen_index_str())
|
||||
{
|
||||
_node->setUpdateCallback(new FGTileUpdateCallback);
|
||||
_node->setCullCallback(new TileCullCallback);
|
||||
tileFileName += ".stg";
|
||||
_node->setName(tileFileName);
|
||||
// Give a default LOD range so that traversals that traverse
|
||||
// active children (like the groundcache lookup) will work before
|
||||
// tile manager has had a chance to update this node.
|
||||
_node->setRange(0, 0.0, 10000.0);
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
FGTileEntry::~FGTileEntry ()
|
||||
{
|
||||
}
|
||||
|
||||
static void WorldCoordinate(osg::Matrix& obj_pos, double lat,
|
||||
double lon, double elev, double hdg)
|
||||
{
|
||||
SGGeod geod = SGGeod::fromDegM(lon, lat, elev);
|
||||
obj_pos = geod.makeZUpFrame();
|
||||
// hdg is not a compass heading, but a counter-clockwise rotation
|
||||
// around the Z axis
|
||||
obj_pos.preMult(osg::Matrix::rotate(hdg * SGD_DEGREES_TO_RADIANS,
|
||||
0.0, 0.0, 1.0));
|
||||
}
|
||||
|
||||
|
||||
// Free "n" leaf elements of an ssg tree. returns the number of
|
||||
// elements freed. An empty branch node is considered a leaf. This
|
||||
// is intended to spread the load of freeing a complex tile out over
|
||||
// several frames.
|
||||
static int fgPartialFreeSSGtree( osg::Group *b, int n ) {
|
||||
int num_deletes = b->getNumChildren();
|
||||
|
||||
b->removeChildren(0, b->getNumChildren());
|
||||
|
||||
return num_deletes;
|
||||
}
|
||||
|
||||
|
||||
// Clean up the memory used by this tile and delete the arrays used by
|
||||
// ssg as well as the whole ssg branch
|
||||
bool FGTileEntry::free_tile() {
|
||||
int delete_size = 100;
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG,
|
||||
"FREEING TILE = (" << tile_bucket << ")" );
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "(start) free_tracker = " << free_tracker );
|
||||
|
||||
if ( !(free_tracker & NODES) ) {
|
||||
free_tracker |= NODES;
|
||||
} else if ( !(free_tracker & VEC_PTRS) ) {
|
||||
free_tracker |= VEC_PTRS;
|
||||
} else if ( !(free_tracker & TERRA_NODE) ) {
|
||||
// delete the terrain branch (this should already have been
|
||||
// disconnected from the scene graph)
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING terra_transform" );
|
||||
if ( fgPartialFreeSSGtree( _node.get(), delete_size ) == 0 ) {
|
||||
_node = 0;
|
||||
free_tracker |= TERRA_NODE;
|
||||
}
|
||||
} else if ( !(free_tracker & LIGHTMAPS) ) {
|
||||
free_tracker |= LIGHTMAPS;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "(end) free_tracker = " << free_tracker );
|
||||
|
||||
// if we fall down to here, we still have work todo, return false
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Update the ssg transform node for this tile so it can be
|
||||
// properly drawn relative to our (0,0,0) point
|
||||
void FGTileEntry::prep_ssg_node(float vis) {
|
||||
if (!is_loaded())
|
||||
return;
|
||||
// visibility can change from frame to frame so we update the
|
||||
// range selector cutoff's each time.
|
||||
float bounding_radius = _node->getChild(0)->getBound().radius();
|
||||
_node->setRange( 0, 0, vis + bounding_radius );
|
||||
}
|
||||
|
||||
bool FGTileEntry::obj_load( const string& path,
|
||||
osg::Group *geometry, bool is_base )
|
||||
{
|
||||
bool use_random_objects =
|
||||
fgGetBool("/sim/rendering/random-objects", true);
|
||||
|
||||
bool use_random_vegetation =
|
||||
fgGetBool("/sim/rendering/random-vegetation", true);
|
||||
|
||||
// try loading binary format
|
||||
osg::ref_ptr<SGReaderWriterBTGOptions> options
|
||||
= new SGReaderWriterBTGOptions();
|
||||
options->setMatlib(globals->get_matlib());
|
||||
options->setCalcLights(is_base);
|
||||
options->setUseRandomObjects(use_random_objects);
|
||||
options->setUseRandomVegetation(use_random_vegetation);
|
||||
osg::Node* node = osgDB::readNodeFile(path, options.get());
|
||||
if (node)
|
||||
geometry->addChild(node);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
typedef enum {
|
||||
OBJECT,
|
||||
OBJECT_SHARED,
|
||||
OBJECT_STATIC,
|
||||
OBJECT_SIGN,
|
||||
OBJECT_RUNWAY_SIGN
|
||||
} object_type;
|
||||
|
||||
|
||||
// storage class for deferred object processing in FGTileEntry::load()
|
||||
struct Object {
|
||||
Object(object_type t, const string& token, const SGPath& p, istream& in)
|
||||
: type(t), path(p)
|
||||
{
|
||||
in >> name;
|
||||
if (type != OBJECT)
|
||||
in >> lon >> lat >> elev >> hdg;
|
||||
in >> ::skipeol;
|
||||
|
||||
if (type == OBJECT)
|
||||
SG_LOG(SG_TERRAIN, SG_INFO, " " << token << " " << name);
|
||||
else
|
||||
SG_LOG(SG_TERRAIN, SG_INFO, " " << token << " " << name << " lon=" <<
|
||||
lon << " lat=" << lat << " elev=" << elev << " hdg=" << hdg);
|
||||
}
|
||||
object_type type;
|
||||
string name;
|
||||
SGPath path;
|
||||
double lon, lat, elev, hdg;
|
||||
};
|
||||
|
||||
// Work in progress... load the tile based entirely by name cuz that's
|
||||
// what we'll want to do with the database pager.
|
||||
|
||||
osg::Node*
|
||||
FGTileEntry::loadTileByName(const string& index_str,
|
||||
const string_list &path_list)
|
||||
{
|
||||
long tileIndex;
|
||||
{
|
||||
istringstream idxStream(index_str);
|
||||
idxStream >> tileIndex;
|
||||
}
|
||||
SGBucket tile_bucket(tileIndex);
|
||||
const string basePath = tile_bucket.gen_base_path();
|
||||
|
||||
bool found_tile_base = false;
|
||||
|
||||
SGPath object_base;
|
||||
vector<const Object*> objects;
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, "Loading tile " << index_str );
|
||||
|
||||
// scan and parse all files and store information
|
||||
for (unsigned int i = 0; i < path_list.size(); i++) {
|
||||
// If we found a terrain tile in Terrain/, we have to process the
|
||||
// Objects/ dir in the same group, too, before we can stop scanning.
|
||||
// FGGlobals::set_fg_scenery() inserts an empty string to path_list
|
||||
// as marker.
|
||||
if (path_list[i].empty()) {
|
||||
if (found_tile_base)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
bool has_base = false;
|
||||
|
||||
SGPath tile_path = path_list[i];
|
||||
tile_path.append(basePath);
|
||||
|
||||
SGPath basename = tile_path;
|
||||
basename.append( index_str );
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, " Trying " << basename.str() );
|
||||
|
||||
|
||||
// Check for master .stg (scene terra gear) file
|
||||
SGPath stg_name = basename;
|
||||
stg_name.concat( ".stg" );
|
||||
|
||||
sg_gzifstream in( stg_name.str() );
|
||||
if ( !in.is_open() )
|
||||
continue;
|
||||
|
||||
while ( ! in.eof() ) {
|
||||
string token;
|
||||
in >> token;
|
||||
|
||||
if ( token.empty() || token[0] == '#' ) {
|
||||
in >> ::skipeol;
|
||||
continue;
|
||||
}
|
||||
// Load only once (first found)
|
||||
if ( token == "OBJECT_BASE" ) {
|
||||
string name;
|
||||
in >> name >> ::skipws;
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, " " << token << " " << name );
|
||||
|
||||
if (!found_tile_base) {
|
||||
found_tile_base = true;
|
||||
has_base = true;
|
||||
|
||||
object_base = tile_path;
|
||||
object_base.append(name);
|
||||
|
||||
} else
|
||||
SG_LOG(SG_TERRAIN, SG_INFO, " (skipped)");
|
||||
|
||||
// Load only if base is not in another file
|
||||
} else if ( token == "OBJECT" ) {
|
||||
if (!found_tile_base || has_base)
|
||||
objects.push_back(new Object(OBJECT, token, tile_path, in));
|
||||
else {
|
||||
string name;
|
||||
in >> name >> ::skipeol;
|
||||
SG_LOG(SG_TERRAIN, SG_INFO, " " << token << " "
|
||||
<< name << " (skipped)");
|
||||
}
|
||||
|
||||
// Always OK to load
|
||||
} else if ( token == "OBJECT_STATIC" ) {
|
||||
objects.push_back(new Object(OBJECT_STATIC, token, tile_path, in));
|
||||
|
||||
} else if ( token == "OBJECT_SHARED" ) {
|
||||
objects.push_back(new Object(OBJECT_SHARED, token, tile_path, in));
|
||||
|
||||
} else if ( token == "OBJECT_SIGN" ) {
|
||||
objects.push_back(new Object(OBJECT_SIGN, token, tile_path, in));
|
||||
|
||||
} else if ( token == "OBJECT_RUNWAY_SIGN" ) {
|
||||
objects.push_back(new Object(OBJECT_RUNWAY_SIGN, token, tile_path, in));
|
||||
|
||||
} else {
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG,
|
||||
"Unknown token '" << token << "' in " << stg_name.str() );
|
||||
in >> ::skipws;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// obj_load() will generate ground lighting for us ...
|
||||
osg::Group* new_tile = new osg::Group;
|
||||
|
||||
if (found_tile_base) {
|
||||
// load tile if found ...
|
||||
obj_load( object_base.str(), new_tile, true );
|
||||
|
||||
} else {
|
||||
// ... or generate an ocean tile on the fly
|
||||
SG_LOG(SG_TERRAIN, SG_INFO, " Generating ocean tile");
|
||||
if ( !SGGenTile( path_list[0], tile_bucket,
|
||||
globals->get_matlib(), new_tile ) ) {
|
||||
SG_LOG( SG_TERRAIN, SG_ALERT,
|
||||
"Warning: failed to generate ocean tile!" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// now that we have a valid center, process all the objects
|
||||
for (unsigned int j = 0; j < objects.size(); j++) {
|
||||
const Object *obj = objects[j];
|
||||
|
||||
if (obj->type == OBJECT) {
|
||||
SGPath custom_path = obj->path;
|
||||
custom_path.append( obj->name );
|
||||
obj_load( custom_path.str(), new_tile, false );
|
||||
|
||||
} else if (obj->type == OBJECT_SHARED || obj->type == OBJECT_STATIC) {
|
||||
// object loading is deferred to main render thread,
|
||||
// but lets figure out the paths right now.
|
||||
SGPath custom_path;
|
||||
if ( obj->type == OBJECT_STATIC ) {
|
||||
custom_path = obj->path;
|
||||
} else {
|
||||
// custom_path = globals->get_fg_root();
|
||||
}
|
||||
custom_path.append( obj->name );
|
||||
|
||||
osg::Matrix obj_pos;
|
||||
WorldCoordinate( obj_pos, obj->lat, obj->lon, obj->elev, obj->hdg );
|
||||
|
||||
osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
|
||||
obj_trans->setMatrix( obj_pos );
|
||||
|
||||
// wire as much of the scene graph together as we can
|
||||
new_tile->addChild( obj_trans );
|
||||
|
||||
osg::Node* model
|
||||
= FGTileMgr::loadTileModel(custom_path.str(),
|
||||
obj->type == OBJECT_SHARED);
|
||||
if (model)
|
||||
obj_trans->addChild(model);
|
||||
} else if (obj->type == OBJECT_SIGN || obj->type == OBJECT_RUNWAY_SIGN) {
|
||||
// load the object itself
|
||||
SGPath custom_path = obj->path;
|
||||
custom_path.append( obj->name );
|
||||
|
||||
osg::Matrix obj_pos;
|
||||
WorldCoordinate( obj_pos, obj->lat, obj->lon, obj->elev, obj->hdg );
|
||||
|
||||
osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
|
||||
obj_trans->setMatrix( obj_pos );
|
||||
|
||||
osg::Node *custom_obj = 0;
|
||||
if (obj->type == OBJECT_SIGN)
|
||||
custom_obj = SGMakeSign(globals->get_matlib(), custom_path.str(), obj->name);
|
||||
else
|
||||
custom_obj = SGMakeRunwaySign(globals->get_matlib(), custom_path.str(), obj->name);
|
||||
|
||||
// wire the pieces together
|
||||
if ( custom_obj != NULL ) {
|
||||
obj_trans -> addChild( custom_obj );
|
||||
}
|
||||
new_tile->addChild( obj_trans );
|
||||
|
||||
}
|
||||
delete obj;
|
||||
}
|
||||
return new_tile;
|
||||
}
|
||||
|
||||
void
|
||||
FGTileEntry::add_ssg_nodes( osg::Group *terrain_branch )
|
||||
{
|
||||
// bump up the ref count so we can remove this later without
|
||||
// having ssg try to free the memory.
|
||||
terrain_branch->addChild( _node.get() );
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG,
|
||||
"connected a tile into scene graph. _node = "
|
||||
<< _node.get() );
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "num parents now = "
|
||||
<< _node->getNumParents() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FGTileEntry::disconnect_ssg_nodes()
|
||||
{
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "disconnecting ssg nodes" );
|
||||
|
||||
if (! is_loaded()) {
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a not-fully loaded tile!" );
|
||||
} else {
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "removing a fully loaded tile! _node = " << _node.get() );
|
||||
}
|
||||
|
||||
// find the terrain branch parent
|
||||
int pcount = _node->getNumParents();
|
||||
if ( pcount > 0 ) {
|
||||
// find the first parent (should only be one)
|
||||
osg::Group *parent = _node->getParent( 0 ) ;
|
||||
if( parent ) {
|
||||
// disconnect the tile (we previously ref()'d it so it
|
||||
// won't get freed now)
|
||||
parent->removeChild( _node.get() );
|
||||
} else {
|
||||
// This should be impossible.
|
||||
SG_LOG( SG_TERRAIN, SG_ALERT,
|
||||
"parent pointer is NULL! Dying" );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class ReaderWriterSTG : public osgDB::ReaderWriter {
|
||||
public:
|
||||
virtual const char* className() const;
|
||||
|
||||
virtual bool acceptsExtension(const string& extension) const;
|
||||
|
||||
virtual ReadResult readNode(const string& fileName,
|
||||
const osgDB::ReaderWriter::Options* options)
|
||||
const;
|
||||
};
|
||||
|
||||
const char* ReaderWriterSTG::className() const
|
||||
{
|
||||
return "STG Database reader";
|
||||
}
|
||||
|
||||
bool ReaderWriterSTG::acceptsExtension(const string& extension) const
|
||||
{
|
||||
return (osgDB::equalCaseInsensitive(extension, "gz")
|
||||
|| osgDB::equalCaseInsensitive(extension, "stg"));
|
||||
}
|
||||
|
||||
//#define SLOW_PAGER 1
|
||||
#ifdef SLOW_PAGER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
osgDB::ReaderWriter::ReadResult
|
||||
ReaderWriterSTG::readNode(const string& fileName,
|
||||
const osgDB::ReaderWriter::Options* options) const
|
||||
{
|
||||
string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if(!acceptsExtension(ext))
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
string stgFileName;
|
||||
if (osgDB::equalCaseInsensitive(ext, "gz")) {
|
||||
stgFileName = osgDB::getNameLessExtension(fileName);
|
||||
if (!acceptsExtension(
|
||||
osgDB::getLowerCaseFileExtension(stgFileName))) {
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
} else {
|
||||
stgFileName = fileName;
|
||||
}
|
||||
osg::Node* result
|
||||
= FGTileEntry::loadTileByName(osgDB::getNameLessExtension(stgFileName),
|
||||
globals->get_fg_scenery());
|
||||
// For debugging race conditions
|
||||
#ifdef SLOW_PAGER
|
||||
sleep(5);
|
||||
#endif
|
||||
if (result)
|
||||
return result; // Constructor converts to ReadResult
|
||||
else
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterSTG> g_readerWriterSTGProxy;
|
||||
ModelRegistryCallbackProxy<LoadOnlyCallback> g_stgCallbackProxy("stg");
|
||||
} // namespace
|
|
@ -1,215 +0,0 @@
|
|||
// tileentry.hxx -- routines to handle an individual scenery tile
|
||||
//
|
||||
// Written by Curtis Olson, started May 1998.
|
||||
//
|
||||
// Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _TILEENTRY_HXX
|
||||
#define _TILEENTRY_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <vector>
|
||||
#include STL_STRING
|
||||
|
||||
#include <simgear/bucket/newbucket.hxx>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/scene/model/placementtrans.hxx>
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Array>
|
||||
#include <osg/Group>
|
||||
#include <osg/LOD>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/Switch>
|
||||
|
||||
#if defined( sgi )
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
SG_USING_STD(string);
|
||||
SG_USING_STD(vector);
|
||||
|
||||
|
||||
typedef vector < Point3D > point_list;
|
||||
typedef point_list::iterator point_list_iterator;
|
||||
typedef point_list::const_iterator const_point_list_iterator;
|
||||
|
||||
|
||||
class FGTileEntry;
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* A class to hold deferred model loading info
|
||||
*/
|
||||
class FGDeferredModel {
|
||||
|
||||
private:
|
||||
|
||||
string model_path;
|
||||
string texture_path;
|
||||
FGTileEntry *tile;
|
||||
osg::ref_ptr<osg::MatrixTransform> obj_trans;
|
||||
SGBucket bucket;
|
||||
bool cache_obj;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
inline FGDeferredModel() { }
|
||||
inline FGDeferredModel( const string& mp, const string& tp, SGBucket b,
|
||||
FGTileEntry *t, osg::MatrixTransform *ot, bool co )
|
||||
{
|
||||
model_path = mp;
|
||||
texture_path = tp;
|
||||
bucket = b;
|
||||
tile = t;
|
||||
obj_trans = ot;
|
||||
cache_obj = co;
|
||||
}
|
||||
inline ~FGDeferredModel() { }
|
||||
inline const string& get_model_path() const { return model_path; }
|
||||
inline const string& get_texture_path() const { return texture_path; }
|
||||
inline const SGBucket& get_bucket() const { return bucket; }
|
||||
inline const bool get_cache_state() const { return cache_obj; }
|
||||
inline FGTileEntry *get_tile() const { return tile; }
|
||||
inline osg::MatrixTransform *get_obj_trans() const { return obj_trans.get(); }
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A class to encapsulate everything we need to know about a scenery tile.
|
||||
*/
|
||||
class FGTileEntry {
|
||||
|
||||
public:
|
||||
// this tile's official location in the world
|
||||
SGBucket tile_bucket;
|
||||
std::string tileFileName;
|
||||
|
||||
private:
|
||||
|
||||
// pointer to ssg range selector for this tile
|
||||
osg::ref_ptr<osg::LOD> _node;
|
||||
|
||||
static bool obj_load( const std::string& path,
|
||||
osg::Group* geometry,
|
||||
bool is_base );
|
||||
|
||||
/**
|
||||
* this value is used by the tile scheduler/loader to mark which
|
||||
* tiles are in the primary ring (i.e. the current tile or the
|
||||
* surrounding eight.) Other routines then can use this as an
|
||||
* optimization and not do some operation to tiles outside of this
|
||||
* inner ring. (For instance vasi color updating)
|
||||
*/
|
||||
bool is_inner_ring;
|
||||
|
||||
/**
|
||||
* this variable tracks the status of the incremental memory
|
||||
* freeing.
|
||||
*/
|
||||
enum {
|
||||
NODES = 0x01,
|
||||
VEC_PTRS = 0x02,
|
||||
TERRA_NODE = 0x04,
|
||||
GROUND_LIGHTS = 0x08,
|
||||
VASI_LIGHTS = 0x10,
|
||||
RWY_LIGHTS = 0x20,
|
||||
TAXI_LIGHTS = 0x40,
|
||||
LIGHTMAPS = 0x80
|
||||
};
|
||||
int free_tracker;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
FGTileEntry( const SGBucket& b );
|
||||
|
||||
// Destructor
|
||||
~FGTileEntry();
|
||||
|
||||
// Clean up the memory used by this tile and delete the arrays
|
||||
// used by ssg as well as the whole ssg branch. This does a
|
||||
// partial clean up and exits so we can spread the load across
|
||||
// multiple frames. Returns false if work remaining to be done,
|
||||
// true if dynamically allocated memory used by this tile is
|
||||
// completely freed.
|
||||
bool free_tile();
|
||||
|
||||
// Update the ssg transform node for this tile so it can be
|
||||
// properly drawn relative to our (0,0,0) point
|
||||
void prep_ssg_node(float vis);
|
||||
|
||||
/**
|
||||
* Transition to OSG database pager
|
||||
*/
|
||||
static osg::Node* loadTileByName(const std::string& index_str,
|
||||
const string_list &path_list);
|
||||
/**
|
||||
* Return true if the tile entry is loaded, otherwise return false
|
||||
* indicating that the loading thread is still working on this.
|
||||
*/
|
||||
inline bool is_loaded() const
|
||||
{
|
||||
return _node->getNumChildren() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the "bucket" for this tile
|
||||
*/
|
||||
inline const SGBucket& get_tile_bucket() const { return tile_bucket; }
|
||||
|
||||
/**
|
||||
* Add terrain mesh and ground lighting to scene graph.
|
||||
*/
|
||||
void add_ssg_nodes( osg::Group *terrain_branch);
|
||||
|
||||
/**
|
||||
* disconnect terrain mesh and ground lighting nodes from scene
|
||||
* graph for this tile.
|
||||
*/
|
||||
void disconnect_ssg_nodes();
|
||||
|
||||
|
||||
/**
|
||||
* return the scenegraph node for the terrain
|
||||
*/
|
||||
osg::LOD *getNode() const { return _node.get(); }
|
||||
|
||||
double get_timestamp() const;
|
||||
void set_timestamp( double time_ms );
|
||||
|
||||
inline bool get_inner_ring() const { return is_inner_ring; }
|
||||
inline void set_inner_ring( bool val ) { is_inner_ring = val; }
|
||||
};
|
||||
|
||||
|
||||
#endif // _TILEENTRY_HXX
|
|
@ -36,6 +36,7 @@
|
|||
#include <simgear/math/vector.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/scene/model/modellib.hxx>
|
||||
#include <simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx>
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
@ -43,7 +44,6 @@
|
|||
#include <Main/viewer.hxx>
|
||||
#include <Scripting/NasalSys.hxx>
|
||||
|
||||
#include "newcache.hxx"
|
||||
#include "scenery.hxx"
|
||||
#include "SceneryPager.hxx"
|
||||
#include "tilemgr.hxx"
|
||||
|
@ -51,20 +51,20 @@
|
|||
using std::for_each;
|
||||
using flightgear::SceneryPager;
|
||||
using simgear::SGModelLib;
|
||||
using simgear::TileEntry;
|
||||
using simgear::TileCache;
|
||||
|
||||
#define TEST_LAST_HIT_CACHE
|
||||
|
||||
// Constructor
|
||||
FGTileMgr::FGTileMgr():
|
||||
state( Start ),
|
||||
current_tile( NULL ),
|
||||
vis( 16000 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
FGTileMgr::~FGTileMgr() {
|
||||
// remove all nodes we might have left behind
|
||||
osg::Group* group = globals->get_scenery()->get_terrain_branch();
|
||||
group->removeChildren(0, group->getNumChildren());
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,6 +72,17 @@ FGTileMgr::~FGTileMgr() {
|
|||
int FGTileMgr::init() {
|
||||
SG_LOG( SG_TERRAIN, SG_INFO, "Initializing Tile Manager subsystem." );
|
||||
|
||||
_options = new SGReaderWriterBTGOptions;
|
||||
_options->setMatlib(globals->get_matlib());
|
||||
_options->setUseRandomObjects(fgGetBool("/sim/rendering/random-objects", true));
|
||||
_options->setUseRandomVegetation(fgGetBool("/sim/rendering/random-vegetation", true));
|
||||
osgDB::FilePathList &fp = _options->getDatabasePathList();
|
||||
const string_list &sc = globals->get_fg_scenery();
|
||||
fp.clear();
|
||||
std::copy(sc.begin(), sc.end(), back_inserter(fp));
|
||||
|
||||
TileEntry::setModelLoadHelper(this);
|
||||
|
||||
tile_cache.init();
|
||||
|
||||
state = Inited;
|
||||
|
@ -84,22 +95,21 @@ int FGTileMgr::init() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// schedule a tile for loading
|
||||
void FGTileMgr::sched_tile( const SGBucket& b, const bool is_inner_ring ) {
|
||||
// see if tile already exists in the cache
|
||||
FGTileEntry *t = tile_cache.get_tile( b );
|
||||
TileEntry *t = tile_cache.get_tile( b );
|
||||
|
||||
if ( t == NULL ) {
|
||||
if ( !t ) {
|
||||
// make space in the cache
|
||||
SceneryPager* pager = FGScenery::getPagerSingleton();
|
||||
while ( (int)tile_cache.get_size() > tile_cache.get_max_cache_size() ) {
|
||||
long index = tile_cache.get_oldest_tile();
|
||||
if ( index >= 0 ) {
|
||||
FGTileEntry *old = tile_cache.get_tile( index );
|
||||
TileEntry *old = tile_cache.get_tile( index );
|
||||
tile_cache.clear_entry( index );
|
||||
osg::ref_ptr<osg::Object> subgraph = old->getNode();
|
||||
old->disconnect_ssg_nodes();
|
||||
old->removeFromSceneGraph();
|
||||
delete old;
|
||||
// zeros out subgraph ref_ptr, so subgraph is owned by
|
||||
// the pager and will be deleted in the pager thread.
|
||||
|
@ -111,7 +121,7 @@ void FGTileMgr::sched_tile( const SGBucket& b, const bool is_inner_ring ) {
|
|||
}
|
||||
|
||||
// create a new entry
|
||||
FGTileEntry *e = new FGTileEntry( b );
|
||||
TileEntry *e = new TileEntry( b );
|
||||
|
||||
// insert the tile into the cache
|
||||
if ( tile_cache.insert_tile( e ) ) {
|
||||
|
@ -122,7 +132,7 @@ void FGTileMgr::sched_tile( const SGBucket& b, const bool is_inner_ring ) {
|
|||
delete e;
|
||||
}
|
||||
// Attach to scene graph
|
||||
e->add_ssg_nodes(globals->get_scenery()->get_terrain_branch());
|
||||
e->addToSceneGraph(globals->get_scenery()->get_terrain_branch());
|
||||
} else {
|
||||
t->set_inner_ring( is_inner_ring );
|
||||
}
|
||||
|
@ -159,7 +169,8 @@ void FGTileMgr::schedule_needed( double vis, const SGBucket& curr_bucket) {
|
|||
if ( xrange < 1 ) { xrange = 1; }
|
||||
if ( yrange < 1 ) { yrange = 1; }
|
||||
|
||||
// note * 2 at end doubles cache size (for fdm and viewer)
|
||||
// make the cache twice as large to avoid losing terrain when switching
|
||||
// between aircraft and tower views
|
||||
tile_cache.set_max_cache_size( (2*xrange + 2) * (2*yrange + 2) * 2 );
|
||||
// cout << "xrange = " << xrange << " yrange = " << yrange << endl;
|
||||
// cout << "max cache size = " << tile_cache.get_max_cache_size()
|
||||
|
@ -221,23 +232,6 @@ void FGTileMgr::initialize_queue()
|
|||
|
||||
double visibility_meters = fgGetDouble("/environment/visibility-m");
|
||||
schedule_needed(visibility_meters, current_bucket);
|
||||
|
||||
// do we really want to lose this? CLO
|
||||
#if 0
|
||||
// Now force a load of the center tile and inner ring so we
|
||||
// have something to see in our first frame.
|
||||
int i;
|
||||
for ( i = 0; i < 9; ++i ) {
|
||||
if ( load_queue.size() ) {
|
||||
SG_LOG( SG_TERRAIN, SG_DEBUG,
|
||||
"Load queue not empty, loading a tile" );
|
||||
|
||||
SGBucket pending = load_queue.front();
|
||||
load_queue.pop_front();
|
||||
load_tile( pending );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
osg::Node*
|
||||
|
@ -246,17 +240,14 @@ FGTileMgr::loadTileModel(const string& modelPath, bool cacheModel)
|
|||
osg::Node* result = 0;
|
||||
try {
|
||||
if(cacheModel)
|
||||
{
|
||||
result =
|
||||
SGModelLib::loadModel(modelPath, globals->get_props(),
|
||||
new FGNasalModelData);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
result=
|
||||
SGModelLib::loadPagedModel(modelPath, globals->get_props(),
|
||||
new FGNasalModelData);
|
||||
}
|
||||
} catch (const sg_io_exception& exc) {
|
||||
string m(exc.getMessage());
|
||||
m += " ";
|
||||
|
@ -269,28 +260,32 @@ FGTileMgr::loadTileModel(const string& modelPath, bool cacheModel)
|
|||
}
|
||||
|
||||
// Helper class for STL fun
|
||||
class TileLoad : public std::unary_function<FGNewCache::tile_map::value_type,
|
||||
class TileLoad : public std::unary_function<TileCache::tile_map::value_type,
|
||||
void>
|
||||
{
|
||||
public:
|
||||
TileLoad(SceneryPager *pager, osg::FrameStamp* framestamp,
|
||||
osg::Group* terrainBranch) :
|
||||
_pager(pager), _framestamp(framestamp) {}
|
||||
osg::Group* terrainBranch, osgDB::ReaderWriter::Options* options) :
|
||||
_pager(pager), _framestamp(framestamp), _options(options) {}
|
||||
|
||||
TileLoad(const TileLoad& rhs) :
|
||||
_pager(rhs._pager), _framestamp(rhs._framestamp) {}
|
||||
void operator()(FGNewCache::tile_map::value_type& tilePair)
|
||||
_pager(rhs._pager), _framestamp(rhs._framestamp),
|
||||
_options(rhs._options) {}
|
||||
|
||||
void operator()(TileCache::tile_map::value_type& tilePair)
|
||||
{
|
||||
FGTileEntry* entry = tilePair.second;
|
||||
TileEntry* entry = tilePair.second;
|
||||
if (entry->getNode()->getNumChildren() == 0) {
|
||||
_pager->queueRequest(entry->tileFileName,
|
||||
entry->getNode(),
|
||||
entry->get_inner_ring() ? 10.0f : 1.0f,
|
||||
_framestamp);
|
||||
_framestamp, _options);
|
||||
}
|
||||
}
|
||||
private:
|
||||
SceneryPager* _pager;
|
||||
osg::FrameStamp* _framestamp;
|
||||
osgDB::ReaderWriter::Options* _options;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -303,7 +298,7 @@ void FGTileMgr::update_queues()
|
|||
for_each(tile_cache.begin(), tile_cache.end(),
|
||||
TileLoad(pager,
|
||||
globals->get_renderer()->getViewer()->getFrameStamp(),
|
||||
globals->get_scenery()->get_terrain_branch()));
|
||||
globals->get_scenery()->get_terrain_branch(), _options.get()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -374,7 +369,7 @@ void FGTileMgr::prep_ssg_nodes(float vis) {
|
|||
// traverse the potentially viewable tile list and update range
|
||||
// selector and transform
|
||||
|
||||
FGTileEntry *e;
|
||||
TileEntry *e;
|
||||
tile_cache.reset_traversal();
|
||||
|
||||
while ( ! tile_cache.at_end() ) {
|
||||
|
@ -395,7 +390,7 @@ bool FGTileMgr::scenery_available(double lat, double lon, double range_m)
|
|||
return false;
|
||||
|
||||
SGBucket bucket(lon, lat);
|
||||
FGTileEntry *te = tile_cache.get_tile(bucket);
|
||||
TileEntry *te = tile_cache.get_tile(bucket);
|
||||
if (!te || !te->is_loaded())
|
||||
return false;
|
||||
|
||||
|
@ -412,7 +407,7 @@ bool FGTileMgr::scenery_available(double lat, double lon, double range_m)
|
|||
// We have already checked for the center tile.
|
||||
if ( x != 0 || y != 0 ) {
|
||||
SGBucket b = sgBucketOffset( lon, lat, x, y );
|
||||
FGTileEntry *te = tile_cache.get_tile(b);
|
||||
TileEntry *te = tile_cache.get_tile(b);
|
||||
if (!te || !te->is_loaded())
|
||||
return false;
|
||||
}
|
||||
|
@ -426,9 +421,9 @@ bool FGTileMgr::scenery_available(double lat, double lon, double range_m)
|
|||
namespace
|
||||
{
|
||||
struct IsTileLoaded :
|
||||
public std::unary_function<FGNewCache::tile_map::value_type, bool>
|
||||
public std::unary_function<TileCache::tile_map::value_type, bool>
|
||||
{
|
||||
bool operator()(const FGNewCache::tile_map::value_type& tilePair) const
|
||||
bool operator()(const TileCache::tile_map::value_type& tilePair) const
|
||||
{
|
||||
return tilePair.second->is_loaded();
|
||||
}
|
||||
|
|
|
@ -24,30 +24,18 @@
|
|||
#ifndef _TILEMGR_HXX
|
||||
#define _TILEMGR_HXX
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include <simgear/scene/model/location.hxx>
|
||||
|
||||
#include <simgear/bucket/newbucket.hxx>
|
||||
#include "newcache.hxx"
|
||||
|
||||
#if defined(USE_MEM) || defined(WIN32)
|
||||
# define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
|
||||
#else
|
||||
# define FG_MEM_COPY(to,from,n) bcopy(from, to, n)
|
||||
#endif
|
||||
|
||||
// forward declaration
|
||||
class FGTileEntry;
|
||||
#include <simgear/scene/tgdb/TileEntry.hxx>
|
||||
#include <simgear/scene/tgdb/TileCache.hxx>
|
||||
|
||||
class SGReaderWriterBTGOptions;
|
||||
class osg::Node;
|
||||
|
||||
class FGTileMgr {
|
||||
class FGTileMgr : public simgear::ModelLoadHelper {
|
||||
|
||||
private:
|
||||
|
||||
|
@ -72,13 +60,12 @@ private:
|
|||
SGBucket previous_bucket;
|
||||
SGBucket current_bucket;
|
||||
SGBucket pending;
|
||||
|
||||
FGTileEntry *current_tile;
|
||||
|
||||
osg::ref_ptr<SGReaderWriterBTGOptions> _options;
|
||||
|
||||
// x and y distance of tiles to load/draw
|
||||
float vis;
|
||||
int xrange, yrange;
|
||||
|
||||
|
||||
// current longitude latitude
|
||||
double longitude;
|
||||
double latitude;
|
||||
|
@ -87,17 +74,14 @@ private:
|
|||
/**
|
||||
* tile cache
|
||||
*/
|
||||
FGNewCache tile_cache;
|
||||
simgear::TileCache tile_cache;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
FGTileMgr();
|
||||
|
||||
// Destructor
|
||||
~FGTileMgr();
|
||||
|
||||
// Initialize the Tile Manager subsystem
|
||||
// Initialize the Tile Manager
|
||||
int init();
|
||||
|
||||
// Update the various queues maintained by the tilemagr (private
|
||||
|
@ -124,7 +108,7 @@ public:
|
|||
bool scenery_available(double lat, double lon, double range_m);
|
||||
|
||||
// Load a model for a tile
|
||||
static osg::Node* loadTileModel(const string& modelPath, bool cacheModel);
|
||||
osg::Node* loadTileModel(const string& modelPath, bool cacheModel);
|
||||
|
||||
// Returns true if all the tiles in the tile cache have been loaded
|
||||
bool isSceneryLoaded();
|
||||
|
|
Loading…
Add table
Reference in a new issue