1998-05-20 20:53:53 +00:00
|
|
|
// tilemgr.hxx -- routines to handle dynamic management of scenery tiles
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started January 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
|
|
|
//
|
|
|
|
// 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$
|
1998-01-07 23:50:01 +00:00
|
|
|
|
|
|
|
|
1998-04-22 13:21:26 +00:00
|
|
|
#ifndef _TILEMGR_HXX
|
|
|
|
#define _TILEMGR_HXX
|
1998-01-22 02:59:23 +00:00
|
|
|
|
|
|
|
|
1998-04-22 13:21:26 +00:00
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
1998-04-21 17:02:27 +00:00
|
|
|
#endif
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
#include <simgear/compiler.h>
|
2002-05-20 16:13:37 +00:00
|
|
|
#include <simgear/math/point3d.hxx>
|
2003-05-06 23:54:17 +00:00
|
|
|
#include <simgear/scene/model/location.hxx>
|
1999-06-13 05:58:02 +00:00
|
|
|
|
2001-05-18 20:31:23 +00:00
|
|
|
#include <queue>
|
|
|
|
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/bucket/newbucket.hxx>
|
2004-04-30 00:52:11 +00:00
|
|
|
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
2001-04-16 20:03:52 +00:00
|
|
|
# include <simgear/threads/SGQueue.hxx>
|
|
|
|
#endif // ENABLE_THREADS
|
1998-12-03 01:18:16 +00:00
|
|
|
|
2001-04-14 03:11:39 +00:00
|
|
|
#include "FGTileLoader.hxx"
|
2000-06-15 22:32:26 +00:00
|
|
|
#include "hitlist.hxx"
|
2001-04-11 02:47:15 +00:00
|
|
|
#include "newcache.hxx"
|
1999-06-13 05:58:02 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2001-07-12 17:55:44 +00:00
|
|
|
SG_USING_STD( queue );
|
|
|
|
|
1999-06-13 05:58:02 +00:00
|
|
|
|
2000-06-15 22:32:26 +00:00
|
|
|
// forward declaration
|
2004-09-20 13:21:51 +00:00
|
|
|
class ssgBranch;
|
|
|
|
class ssgEntity;
|
2000-06-15 22:32:26 +00:00
|
|
|
class FGTileEntry;
|
2001-05-19 16:59:43 +00:00
|
|
|
class FGDeferredModel;
|
2000-06-15 22:32:26 +00:00
|
|
|
|
|
|
|
|
1999-06-13 05:58:02 +00:00
|
|
|
class FGTileMgr {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Tile loading state
|
|
|
|
enum load_state {
|
|
|
|
Start = 0,
|
|
|
|
Inited = 1,
|
|
|
|
Running = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
load_state state;
|
|
|
|
|
2000-06-15 22:32:26 +00:00
|
|
|
// initialize the cache
|
2000-07-23 21:32:59 +00:00
|
|
|
void initialize_queue();
|
2000-06-15 22:32:26 +00:00
|
|
|
|
1999-06-13 05:58:02 +00:00
|
|
|
// schedule a tile for loading
|
2003-12-30 15:12:04 +00:00
|
|
|
void sched_tile( const SGBucket& b, const bool is_inner_ring );
|
1999-06-13 05:58:02 +00:00
|
|
|
|
2000-12-03 20:15:46 +00:00
|
|
|
// schedule a needed buckets for loading
|
From: "Jim Wilson" <jimw@kelcomaine.com>
This is a new improved patch for the previous tile manager fixes.
Rather than building dependencies between FGlocation or the viewer or fdm with
tilemgr what I ended up doing was linking the pieces together in the Mainloop
in main.cxx. You'll see what I mean...it's been commented fairly well. More
than likely we should move that chunk somewhere...just not sure where yet.
The changes seem clean now. As I get more ideas there could be some further
improvement in organizing the update in tilemgr. You'll note that I left an
override in there for the tilemgr::update() function to preserve earlier
functionality if someone needs it (e.g. usage independent of an fdm or
viewer), not to mention there are a few places in flightgear that call it
directly that have not been changed to the new interface (and may not need to be).
The code has been optimized to avoid duplicate traversals and seems to run
generally quite well. Note that there can be a short delay reloading tiles
that have been dropped from static views. We could call the tile scheduler on
a view switch, but it's not a big deal and at the moment I'd like to get this
in so people can try it and comment on it as it is.
Everything has been resycned with CVS tonight and I've included the
description submitted earlier (below).
Best,
Jim
Changes synced with CVS approx 20:30EDT 2002-05-09 (after this evenings updates).
Files:
http://www.spiderbark.com/fgfs/viewer-update-20020516.tar.gz
or
http://www.spiderbark.com/fgfs/viewer-update-20020516.diffs.gz
Description:
In a nutshell, these patches begin to take what was one value for ground
elevation and calculate ground elevation values seperately for the FDM and the
viewer (eye position). Several outstanding view related bugs have been fixed.
With the introduction of the new viewer code a lot of that Flight Gear code
broke related to use of a global variable called "scenery.cur_elev".
Therefore the ground_elevation and other associated items (like the current
tile bucket) is maintained per FDM instance and per View. Each of these has a
"point" or location that can be identified. See changes to FGLocation class
and main.cxx.
Most of the problems related to the new viewer in terms of sky, ground and
runway lights, and tower views are fixed.
There are four minor problems remaining. 1) The sun/moon spins when you pan
the "lookat" tower view only (view #3). 2) Under stress (esp. magic carpet
full speed with max visibility), there is a memory leak in the tile caching
that was not introduced with these changes. 3) I have not tested these
changes or made corrections to the ADA or External FDM interfaces. 4) The
change view function doesn't call the time/light update (not a problem unless
a tower is very far away).
Details:
FDM/flight.cxx, flight.hxx - FGInterface ties to FGAircraftModel so that it's
location data can be accessed for runway (ground elevation under aircraft)
elevation.
FDM/larsim.cxx, larcsim.hxx - gets runway elevation from FGInterface now.
Commented out function that is causing a namespace conflict, hasn't been
called with recent code anyway.
FDM/JSBSim/JSBSim.cxx, YASim/YASim.cxx - gets runway elevation from
FGInterface now.
Scenery/newcache.cxx, newcache.hxx - changed caching scheme to time based
(oldest tiles discard).
Scenery/tileentry.cxx, tileentry.hxx - added place to record time, changed
rendering to reference viewer altitude in order to fix a problem with ground
and runway lights.
Scenery/tilemgr.cxx, tilemgr.hxx - Modified update() to accept values for
multiple locations. Refresh function added in order to periodically make
the tiles current for a non-moving view (like a tower).
Main/fg_init.cxx - register event for making tiles current in a non-moving
view (like a tower).
Main/location.hxx - added support for current ground elevation data.
Main/main.cxx - added second tilemgr call for fdm, fixed places where viewer
position data was required for correct sky rendering.
Main/options.cxx - fixed segfault reported by Curtis when using --view-offset
command line parameter.
Main/viewer.cxx, viewer.hxx - removed fudging of view position. Fixed numerous
bugs that were causing eye and target values to get mixed up.
2002-05-17 17:25:28 +00:00
|
|
|
void schedule_needed(double visibility_meters, SGBucket curr_bucket);
|
2000-06-15 22:32:26 +00:00
|
|
|
|
|
|
|
FGHitList hit_list;
|
|
|
|
|
2000-12-13 20:36:04 +00:00
|
|
|
SGBucket previous_bucket;
|
|
|
|
SGBucket current_bucket;
|
|
|
|
SGBucket pending;
|
2000-06-15 22:32:26 +00:00
|
|
|
|
|
|
|
FGTileEntry *current_tile;
|
|
|
|
|
2000-12-03 20:15:46 +00:00
|
|
|
// x and y distance of tiles to load/draw
|
2000-12-04 05:24:38 +00:00
|
|
|
float vis;
|
2000-12-03 20:15:46 +00:00
|
|
|
int xrange, yrange;
|
2000-06-15 22:32:26 +00:00
|
|
|
|
|
|
|
// current longitude latitude
|
|
|
|
double longitude;
|
|
|
|
double latitude;
|
2003-11-21 04:41:01 +00:00
|
|
|
double altitude_m;
|
1999-11-03 21:01:59 +00:00
|
|
|
|
2001-04-11 02:47:15 +00:00
|
|
|
/**
|
2001-04-14 03:11:39 +00:00
|
|
|
* tile cache
|
2001-04-11 02:47:15 +00:00
|
|
|
*/
|
|
|
|
FGNewCache tile_cache;
|
|
|
|
|
2001-04-14 03:11:39 +00:00
|
|
|
/**
|
|
|
|
* Queue tiles for loading.
|
|
|
|
*/
|
|
|
|
FGTileLoader loader;
|
|
|
|
|
2001-04-16 20:03:52 +00:00
|
|
|
/**
|
2001-05-19 16:59:43 +00:00
|
|
|
* Work queues.
|
|
|
|
*
|
|
|
|
* attach_queue is the tiles that have been loaded [by the pager]
|
|
|
|
* that can be attached to the scene graph by the render thread.
|
|
|
|
*
|
|
|
|
* model_queue is the set of models that need to be loaded by the
|
|
|
|
* primary render thread.
|
2001-04-16 20:03:52 +00:00
|
|
|
*/
|
2004-04-30 00:52:11 +00:00
|
|
|
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
2001-05-19 16:59:43 +00:00
|
|
|
static SGLockedQueue<FGTileEntry *> attach_queue;
|
|
|
|
static SGLockedQueue<FGDeferredModel *> model_queue;
|
2001-05-18 20:31:23 +00:00
|
|
|
#else
|
2001-05-19 16:59:43 +00:00
|
|
|
static queue<FGTileEntry *> attach_queue;
|
|
|
|
static queue<FGDeferredModel *> model_queue;
|
2001-05-18 20:31:23 +00:00
|
|
|
#endif // ENABLE_THREADS
|
2002-07-25 21:57:58 +00:00
|
|
|
static queue<FGTileEntry *> delete_queue;
|
2001-04-16 20:03:52 +00:00
|
|
|
|
2004-04-02 14:42:42 +00:00
|
|
|
/**
|
|
|
|
* Tile filter indicator, to implement multipass rendering
|
|
|
|
*/
|
|
|
|
static bool tile_filter;
|
|
|
|
|
2001-04-16 20:03:52 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2001-05-19 16:59:43 +00:00
|
|
|
* Add a loaded tile to the 'attach to the scene graph' queue.
|
2001-04-16 20:03:52 +00:00
|
|
|
*/
|
2001-05-19 16:59:43 +00:00
|
|
|
static void ready_to_attach( FGTileEntry *t ) { attach_queue.push( t ); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a pending model to the 'deferred model load' queue
|
|
|
|
*/
|
|
|
|
static void model_ready( FGDeferredModel *dm ) { model_queue.push( dm ); }
|
2001-04-16 20:03:52 +00:00
|
|
|
|
1999-06-13 05:58:02 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
2000-12-03 20:15:46 +00:00
|
|
|
FGTileMgr();
|
1999-06-13 05:58:02 +00:00
|
|
|
|
|
|
|
// Destructor
|
2000-12-03 20:15:46 +00:00
|
|
|
~FGTileMgr();
|
1998-01-07 23:50:01 +00:00
|
|
|
|
1999-06-13 05:58:02 +00:00
|
|
|
// Initialize the Tile Manager subsystem
|
2000-12-03 20:15:46 +00:00
|
|
|
int init();
|
1998-01-07 23:50:01 +00:00
|
|
|
|
2002-11-30 02:21:04 +00:00
|
|
|
// Update the various queues maintained by the tilemagr (private
|
|
|
|
// internal function, do not call directly.)
|
|
|
|
void update_queues();
|
|
|
|
|
2004-07-22 16:42:14 +00:00
|
|
|
// get state of all the scenery loading queues
|
|
|
|
bool all_queues_empty();
|
|
|
|
|
2000-07-23 21:32:59 +00:00
|
|
|
// given the current lon/lat (in degrees), fill in the array of
|
|
|
|
// local chunks. If the chunk isn't already in the cache, then
|
|
|
|
// read it from disk.
|
2002-11-30 03:05:34 +00:00
|
|
|
int update( double visibility_meters );
|
2003-05-13 03:18:42 +00:00
|
|
|
int update( SGLocation *location, double visibility_meters,
|
2002-12-06 22:29:46 +00:00
|
|
|
sgdVec3 abs_pos_vector );
|
|
|
|
|
2003-11-21 04:41:01 +00:00
|
|
|
int updateCurrentElevAtPos( sgdVec3 abs_pos_vector, double altitude_m,
|
|
|
|
Point3D center );
|
1998-01-07 23:50:01 +00:00
|
|
|
|
1999-06-13 05:58:02 +00:00
|
|
|
// Determine scenery altitude. Normally this just happens when we
|
|
|
|
// render the scene, but we'd also like to be able to do this
|
|
|
|
// explicitely. lat & lon are in radians. abs_view_pos in
|
|
|
|
// meters. Returns result in meters.
|
1999-11-04 22:55:00 +00:00
|
|
|
void my_ssg_los( string s, ssgBranch *branch, sgdMat4 m,
|
2000-06-15 22:32:26 +00:00
|
|
|
const sgdVec3 p, const sgdVec3 dir, sgdVec3 normal );
|
|
|
|
|
|
|
|
void my_ssg_los( ssgBranch *branch, sgdMat4 m,
|
|
|
|
const sgdVec3 p, const sgdVec3 dir,
|
|
|
|
FGHitList *list );
|
1998-01-07 23:50:01 +00:00
|
|
|
|
2002-11-28 01:08:25 +00:00
|
|
|
// Prepare the ssg nodes corresponding to each tile. For each
|
|
|
|
// tile, set the ssg transform and update it's range selector
|
|
|
|
// based on current visibilty void prep_ssg_nodes( float
|
|
|
|
// visibility_meters );
|
2003-05-13 03:18:42 +00:00
|
|
|
void prep_ssg_nodes( SGLocation *location, float visibility_meters );
|
From: "Jim Wilson" <jimw@kelcomaine.com>
This is a new improved patch for the previous tile manager fixes.
Rather than building dependencies between FGlocation or the viewer or fdm with
tilemgr what I ended up doing was linking the pieces together in the Mainloop
in main.cxx. You'll see what I mean...it's been commented fairly well. More
than likely we should move that chunk somewhere...just not sure where yet.
The changes seem clean now. As I get more ideas there could be some further
improvement in organizing the update in tilemgr. You'll note that I left an
override in there for the tilemgr::update() function to preserve earlier
functionality if someone needs it (e.g. usage independent of an fdm or
viewer), not to mention there are a few places in flightgear that call it
directly that have not been changed to the new interface (and may not need to be).
The code has been optimized to avoid duplicate traversals and seems to run
generally quite well. Note that there can be a short delay reloading tiles
that have been dropped from static views. We could call the tile scheduler on
a view switch, but it's not a big deal and at the moment I'd like to get this
in so people can try it and comment on it as it is.
Everything has been resycned with CVS tonight and I've included the
description submitted earlier (below).
Best,
Jim
Changes synced with CVS approx 20:30EDT 2002-05-09 (after this evenings updates).
Files:
http://www.spiderbark.com/fgfs/viewer-update-20020516.tar.gz
or
http://www.spiderbark.com/fgfs/viewer-update-20020516.diffs.gz
Description:
In a nutshell, these patches begin to take what was one value for ground
elevation and calculate ground elevation values seperately for the FDM and the
viewer (eye position). Several outstanding view related bugs have been fixed.
With the introduction of the new viewer code a lot of that Flight Gear code
broke related to use of a global variable called "scenery.cur_elev".
Therefore the ground_elevation and other associated items (like the current
tile bucket) is maintained per FDM instance and per View. Each of these has a
"point" or location that can be identified. See changes to FGLocation class
and main.cxx.
Most of the problems related to the new viewer in terms of sky, ground and
runway lights, and tower views are fixed.
There are four minor problems remaining. 1) The sun/moon spins when you pan
the "lookat" tower view only (view #3). 2) Under stress (esp. magic carpet
full speed with max visibility), there is a memory leak in the tile caching
that was not introduced with these changes. 3) I have not tested these
changes or made corrections to the ADA or External FDM interfaces. 4) The
change view function doesn't call the time/light update (not a problem unless
a tower is very far away).
Details:
FDM/flight.cxx, flight.hxx - FGInterface ties to FGAircraftModel so that it's
location data can be accessed for runway (ground elevation under aircraft)
elevation.
FDM/larsim.cxx, larcsim.hxx - gets runway elevation from FGInterface now.
Commented out function that is causing a namespace conflict, hasn't been
called with recent code anyway.
FDM/JSBSim/JSBSim.cxx, YASim/YASim.cxx - gets runway elevation from
FGInterface now.
Scenery/newcache.cxx, newcache.hxx - changed caching scheme to time based
(oldest tiles discard).
Scenery/tileentry.cxx, tileentry.hxx - added place to record time, changed
rendering to reference viewer altitude in order to fix a problem with ground
and runway lights.
Scenery/tilemgr.cxx, tilemgr.hxx - Modified update() to accept values for
multiple locations. Refresh function added in order to periodically make
the tiles current for a non-moving view (like a tower).
Main/fg_init.cxx - register event for making tiles current in a non-moving
view (like a tower).
Main/location.hxx - added support for current ground elevation data.
Main/main.cxx - added second tilemgr call for fdm, fixed places where viewer
position data was required for correct sky rendering.
Main/options.cxx - fixed segfault reported by Curtis when using --view-offset
command line parameter.
Main/viewer.cxx, viewer.hxx - removed fudging of view position. Fixed numerous
bugs that were causing eye and target values to get mixed up.
2002-05-17 17:25:28 +00:00
|
|
|
|
2002-11-28 01:08:25 +00:00
|
|
|
// Set flag with event manager so that non-moving view refreshes
|
|
|
|
// tiles...
|
From: "Jim Wilson" <jimw@kelcomaine.com>
This is a new improved patch for the previous tile manager fixes.
Rather than building dependencies between FGlocation or the viewer or fdm with
tilemgr what I ended up doing was linking the pieces together in the Mainloop
in main.cxx. You'll see what I mean...it's been commented fairly well. More
than likely we should move that chunk somewhere...just not sure where yet.
The changes seem clean now. As I get more ideas there could be some further
improvement in organizing the update in tilemgr. You'll note that I left an
override in there for the tilemgr::update() function to preserve earlier
functionality if someone needs it (e.g. usage independent of an fdm or
viewer), not to mention there are a few places in flightgear that call it
directly that have not been changed to the new interface (and may not need to be).
The code has been optimized to avoid duplicate traversals and seems to run
generally quite well. Note that there can be a short delay reloading tiles
that have been dropped from static views. We could call the tile scheduler on
a view switch, but it's not a big deal and at the moment I'd like to get this
in so people can try it and comment on it as it is.
Everything has been resycned with CVS tonight and I've included the
description submitted earlier (below).
Best,
Jim
Changes synced with CVS approx 20:30EDT 2002-05-09 (after this evenings updates).
Files:
http://www.spiderbark.com/fgfs/viewer-update-20020516.tar.gz
or
http://www.spiderbark.com/fgfs/viewer-update-20020516.diffs.gz
Description:
In a nutshell, these patches begin to take what was one value for ground
elevation and calculate ground elevation values seperately for the FDM and the
viewer (eye position). Several outstanding view related bugs have been fixed.
With the introduction of the new viewer code a lot of that Flight Gear code
broke related to use of a global variable called "scenery.cur_elev".
Therefore the ground_elevation and other associated items (like the current
tile bucket) is maintained per FDM instance and per View. Each of these has a
"point" or location that can be identified. See changes to FGLocation class
and main.cxx.
Most of the problems related to the new viewer in terms of sky, ground and
runway lights, and tower views are fixed.
There are four minor problems remaining. 1) The sun/moon spins when you pan
the "lookat" tower view only (view #3). 2) Under stress (esp. magic carpet
full speed with max visibility), there is a memory leak in the tile caching
that was not introduced with these changes. 3) I have not tested these
changes or made corrections to the ADA or External FDM interfaces. 4) The
change view function doesn't call the time/light update (not a problem unless
a tower is very far away).
Details:
FDM/flight.cxx, flight.hxx - FGInterface ties to FGAircraftModel so that it's
location data can be accessed for runway (ground elevation under aircraft)
elevation.
FDM/larsim.cxx, larcsim.hxx - gets runway elevation from FGInterface now.
Commented out function that is causing a namespace conflict, hasn't been
called with recent code anyway.
FDM/JSBSim/JSBSim.cxx, YASim/YASim.cxx - gets runway elevation from
FGInterface now.
Scenery/newcache.cxx, newcache.hxx - changed caching scheme to time based
(oldest tiles discard).
Scenery/tileentry.cxx, tileentry.hxx - added place to record time, changed
rendering to reference viewer altitude in order to fix a problem with ground
and runway lights.
Scenery/tilemgr.cxx, tilemgr.hxx - Modified update() to accept values for
multiple locations. Refresh function added in order to periodically make
the tiles current for a non-moving view (like a tower).
Main/fg_init.cxx - register event for making tiles current in a non-moving
view (like a tower).
Main/location.hxx - added support for current ground elevation data.
Main/main.cxx - added second tilemgr call for fdm, fixed places where viewer
position data was required for correct sky rendering.
Main/options.cxx - fixed segfault reported by Curtis when using --view-offset
command line parameter.
Main/viewer.cxx, viewer.hxx - removed fudging of view position. Fixed numerous
bugs that were causing eye and target values to get mixed up.
2002-05-17 17:25:28 +00:00
|
|
|
void refresh_view_timestamps();
|
|
|
|
|
|
|
|
inline SGBucket get_current_bucket () { return current_bucket; }
|
|
|
|
inline SGBucket get_previous_bucket () { return previous_bucket; }
|
2004-04-02 14:42:42 +00:00
|
|
|
|
|
|
|
static bool set_tile_filter( bool f );
|
|
|
|
static int tile_filter_cb( ssgEntity *, int );
|
1999-06-13 05:58:02 +00:00
|
|
|
};
|
1998-08-22 14:49:55 +00:00
|
|
|
|
|
|
|
|
1998-05-20 20:53:53 +00:00
|
|
|
#endif // _TILEMGR_HXX
|