]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/tilemgr.hxx
e3f49e54cec7e3ed10b893367c0a6b0f67427af6
[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 <plib/ssg.h>
35
36 #include <simgear/bucket/newbucket.hxx>
37
38 #include "hitlist.hxx"
39 #include "newcache.hxx"
40
41 #if defined(USE_MEM) || defined(WIN32)
42 #  define FG_MEM_COPY(to,from,n)        memcpy(to, from, n)
43 #else
44 #  define FG_MEM_COPY(to,from,n)        bcopy(from, to, n)
45 #endif
46
47
48 // forward declaration
49 class FGTileEntry;
50
51
52 class FGTileMgr {
53
54 private:
55
56     // Tile loading state
57     enum load_state {
58         Start = 0,
59         Inited = 1,
60         Running = 2
61     };
62
63     load_state state;
64
65     // initialize the cache
66     void initialize_queue();
67
68     // forced emptying of the queue.  This is necessay to keep
69     // bookeeping straight for the tile_cache -- which actually
70     // handles all the (de)allocations
71     void destroy_queue();
72
73     // schedule a tile for loading
74     void sched_tile( const SGBucket& b );
75
76     // schedule a needed buckets for loading
77     void schedule_needed();
78
79     // see comment at prep_ssg_nodes()
80     void prep_ssg_node( int idx );
81         
82     // int hitcount;
83     // sgdVec3 hit_pts [ MAX_HITS ] ;
84
85     // ssgEntity *last_hit;
86     FGHitList hit_list;
87
88     SGBucket previous_bucket;
89     SGBucket current_bucket;
90     SGBucket pending;
91         
92     FGTileEntry *current_tile;
93         
94     // x and y distance of tiles to load/draw
95     float vis;
96     int xrange, yrange;
97         
98     // current longitude latitude
99     double longitude;
100     double latitude;
101     double last_longitude;
102     double last_latitude;
103
104     /**
105      * 
106      */
107     FGNewCache tile_cache;
108
109 public:
110
111     // Constructor
112     FGTileMgr();
113
114     // Destructor
115     ~FGTileMgr();
116
117     // Initialize the Tile Manager subsystem
118     int init();
119
120     // given the current lon/lat (in degrees), fill in the array of
121     // local chunks.  If the chunk isn't already in the cache, then
122     // read it from disk.
123     int update( double lon, double lat );
124
125     // Determine scenery altitude.  Normally this just happens when we
126     // render the scene, but we'd also like to be able to do this
127     // explicitely.  lat & lon are in radians.  abs_view_pos in
128     // meters.  Returns result in meters.
129     void my_ssg_los( string s, ssgBranch *branch, sgdMat4 m, 
130                      const sgdVec3 p, const sgdVec3 dir, sgdVec3 normal );
131         
132     void my_ssg_los( ssgBranch *branch, sgdMat4 m, 
133                      const sgdVec3 p, const sgdVec3 dir,
134                      FGHitList *list );
135
136     bool current_elev_ssg( sgdVec3 abs_view_pos, double *terrain_elev );
137         
138     // Prepare the ssg nodes ... for each tile, set it's proper
139     // transform and update it's range selector based on current
140     // visibilty
141     void prep_ssg_nodes();
142 };
143
144
145 // the tile manager
146 extern FGTileMgr global_tile_mgr;
147
148
149 #endif // _TILEMGR_HXX