]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/tilemgr.hxx
Merge branch 'next' of http://git.gitorious.org/fg/flightgear into next
[flightgear.git] / src / Scenery / tilemgr.hxx
1 // tilemgr.hxx -- routines to handle dynamic management of scenery tiles
2 //
3 // Written by Curtis Olson, started January 1998.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _TILEMGR_HXX
25 #define _TILEMGR_HXX
26
27 #include <simgear/compiler.h>
28
29 #include <simgear/structure/subsystem_mgr.hxx>
30 #include <simgear/bucket/newbucket.hxx>
31 #include <simgear/scene/tgdb/TileEntry.hxx>
32 #include <simgear/scene/tgdb/TileCache.hxx>
33
34 class SGReaderWriterBTGOptions;
35
36 namespace osg
37 {
38 class Node;
39 }
40
41 class FGTileMgr : public SGSubsystem, public simgear::ModelLoadHelper {
42
43 private:
44
45     // Tile loading state
46     enum load_state {
47         Start = 0,
48         Inited = 1,
49         Running = 2
50     };
51
52     load_state state;
53     
54     // schedule a tile for loading, returns true when tile is already loaded
55     bool sched_tile( const SGBucket& b, double priority,bool current_view, double request_time);
56
57     // schedule a needed buckets for loading
58     void schedule_needed(const SGBucket& curr_bucket, double rangeM);
59
60     SGBucket previous_bucket;
61     SGBucket current_bucket;
62     SGBucket pending;
63     osg::ref_ptr<SGReaderWriterBTGOptions> _options;
64
65     // x and y distance of tiles to load/draw
66     float vis;
67     int xrange, yrange;
68
69     // current longitude latitude
70     double longitude;
71     double latitude;
72     double scheduled_visibility;
73
74     /**
75      * tile cache
76      */
77     simgear::TileCache tile_cache;
78
79     // Update the various queues maintained by the tilemagr (private
80     // internal function, do not call directly.)
81     void update_queues();
82     
83     SGPropertyNode* _visibilityMeters;
84     SGPropertyChangeListener* _propListener;
85     SGPropertyNode_ptr _randomObjects;
86     SGPropertyNode_ptr _randomVegetation;
87     
88 public:
89     FGTileMgr();
90
91     ~FGTileMgr();
92
93     // Initialize the Tile Manager
94     virtual void init();
95     virtual void reinit();
96
97     virtual void update(double dt);
98
99     // update loader configuration options
100     void configChanged();
101
102     int schedule_tiles_at(const SGGeod& location, double rangeM);
103
104
105     const SGBucket& get_current_bucket () const { return current_bucket; }
106
107     /// Returns true if scenery is available for the given lat, lon position
108     /// within a range of range_m.
109     /// lat and lon are expected to be in degrees.
110     bool schedule_scenery(const SGGeod& position, double range_m, double duration=0.0);
111
112     // Load a model for a tile
113     osg::Node* loadTileModel(const string& modelPath, bool cacheModel);
114
115     // Returns true if tiles around current view position have been loaded
116     bool isSceneryLoaded();
117 };
118
119
120 #endif // _TILEMGR_HXX