]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/tilemgr.hxx
3c6de251a4f6227be177f7309c4be00ba6c97039
[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  - curt@infoplane.com
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _TILEMGR_HXX
25 #define _TILEMGR_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32 #include <Include/compiler.h>
33
34 #include <list>
35
36 #include <Bucket/newbucket.hxx>
37
38
39 FG_USING_STD(list);
40
41
42 #define FG_LOCAL_X_Y         81  // max(o->tile_diameter) ** 2
43
44 #define FG_SQUARE( X ) ( (X) * (X) )
45
46 #if defined(USE_MEM) || defined(WIN32)
47 #  define FG_MEM_COPY(to,from,n)        memcpy(to, from, n)
48 #else
49 #  define FG_MEM_COPY(to,from,n)        bcopy(from, to, n)
50 #endif
51
52
53 class FGLoadRec {
54
55 public:
56
57     FGBucket b;
58     int cache_index;
59 };
60
61
62 class FGTileMgr {
63
64 private:
65
66     // Tile loading state
67     enum load_state {
68         Start = 0,
69         Inited = 1,
70         Running = 2
71     };
72
73     load_state state;
74
75     // pending tile load queue
76     list < FGLoadRec > load_queue;
77
78     // schedule a tile for loading
79     int sched_tile( const FGBucket& b );
80
81     // load a tile
82     void load_tile( const FGBucket& b, int cache_index );
83
84 public:
85
86     // Constructor
87     FGTileMgr ( void );
88
89     // Destructor
90     ~FGTileMgr ( void );
91
92     // Initialize the Tile Manager subsystem
93     int init( void );
94
95     // given the current lon/lat, fill in the array of local chunks.
96     // If the chunk isn't already in the cache, then read it from
97     // disk.
98     int update( void );
99
100     // Determine scenery altitude.  Normally this just happens when we
101     // render the scene, but we'd also like to be able to do this
102     // explicitely.  lat & lon are in radians.  abs_view_pos in
103     // meters.  Returns result in meters.
104     double current_elev( double lon, double lat, const Point3D& abs_view_pos );
105     double current_elev_ssg( const Point3D& abs_view_pos, 
106                              const Point3D& view_pos );
107     double current_elev_new( const FGBucket& p );
108
109     // Prepare the ssg nodes ... for each tile, set it's proper
110     // transform and update it's range selector based on current
111     // visibilty
112     void prep_ssg_nodes( void );
113 };
114
115
116 // the tile manager
117 extern FGTileMgr global_tile_mgr;
118
119
120 #endif // _TILEMGR_HXX
121
122