]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/tilemgr.hxx
Replaced Durk's mymath.* with plib/sg.h (contributed by Durk).
[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 <simgear/compiler.h>
33
34 #include <list>
35
36 #include <plib/ssg.h>
37
38 #include <simgear/bucket/newbucket.hxx>
39
40
41 FG_USING_STD(list);
42
43
44 #define FG_LOCAL_X_Y         81  // max(o->tile_diameter) ** 2
45
46 #define FG_SQUARE( X ) ( (X) * (X) )
47
48 #if defined(USE_MEM) || defined(WIN32)
49 #  define FG_MEM_COPY(to,from,n)        memcpy(to, from, n)
50 #else
51 #  define FG_MEM_COPY(to,from,n)        bcopy(from, to, n)
52 #endif
53
54
55 class FGLoadRec {
56
57 public:
58
59     FGBucket b;
60     int cache_index;
61 };
62
63
64 #define MAX_HITS 100
65
66
67 class FGTileMgr {
68
69 private:
70
71     // Tile loading state
72     enum load_state {
73         Start = 0,
74         Inited = 1,
75         Running = 2
76     };
77
78     load_state state;
79
80     // pending tile load queue
81     list < FGLoadRec > load_queue;
82
83     // schedule a tile for loading
84     int sched_tile( const FGBucket& b );
85
86     // load a tile
87     void load_tile( const FGBucket& b, int cache_index );
88
89     int hitcount;
90     sgdVec3 hit_pts [ MAX_HITS ] ;
91
92 public:
93
94     // Constructor
95     FGTileMgr ( void );
96
97     // Destructor
98     ~FGTileMgr ( void );
99
100     // Initialize the Tile Manager subsystem
101     int init( void );
102
103     // given the current lon/lat, fill in the array of local chunks.
104     // If the chunk isn't already in the cache, then read it from
105     // disk.
106     int update( void );
107
108     // Determine scenery altitude.  Normally this just happens when we
109     // render the scene, but we'd also like to be able to do this
110     // explicitely.  lat & lon are in radians.  abs_view_pos in
111     // meters.  Returns result in meters.
112     double current_elev( double lon, double lat, const Point3D& abs_view_pos );
113     void my_ssg_los( string s, ssgBranch *branch, sgdMat4 m, 
114                      const sgdVec3 p, const sgdVec3 dir );
115     bool current_elev_ssg( const Point3D& abs_view_pos, 
116                              const Point3D& view_pos );
117     double current_elev_new( const FGBucket& p );
118
119     // Prepare the ssg nodes ... for each tile, set it's proper
120     // transform and update it's range selector based on current
121     // visibilty
122     void prep_ssg_nodes( void );
123 };
124
125
126 // the tile manager
127 extern FGTileMgr global_tile_mgr;
128
129
130 #endif // _TILEMGR_HXX
131
132