1 // tilemgr.hxx -- routines to handle dynamic management of scenery tiles
3 // Written by Curtis Olson, started January 1998.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
29 # error This library requires C++
32 #include <simgear/compiler.h>
33 #include <simgear/math/point3d.hxx>
39 #include <simgear/bucket/newbucket.hxx>
41 # include <simgear/threads/SGQueue.hxx>
42 #endif // ENABLE_THREADS
44 #include "FGTileLoader.hxx"
45 #include "hitlist.hxx"
46 #include "newcache.hxx"
48 #if defined(USE_MEM) || defined(WIN32)
49 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
51 # define FG_MEM_COPY(to,from,n) bcopy(from, to, n)
54 SG_USING_STD( queue );
57 // forward declaration
59 class FGDeferredModel;
75 // initialize the cache
76 void initialize_queue();
78 // schedule a tile for loading
79 void sched_tile( const SGBucket& b );
81 // schedule a needed buckets for loading
82 void schedule_needed(double visibility_meters, SGBucket curr_bucket);
84 // see comment at prep_ssg_nodes()
85 void prep_ssg_node( int idx );
89 SGBucket previous_bucket;
90 SGBucket current_bucket;
93 FGTileEntry *current_tile;
95 // x and y distance of tiles to load/draw
99 // current longitude latitude
102 double last_longitude;
103 double last_latitude;
108 FGNewCache tile_cache;
111 * Queue tiles for loading.
119 * attach_queue is the tiles that have been loaded [by the pager]
120 * that can be attached to the scene graph by the render thread.
122 * model_queue is the set of models that need to be loaded by the
123 * primary render thread.
125 #ifdef ENABLE_THREADS
126 static SGLockedQueue<FGTileEntry *> attach_queue;
127 static SGLockedQueue<FGDeferredModel *> model_queue;
129 static queue<FGTileEntry *> attach_queue;
130 static queue<FGDeferredModel *> model_queue;
131 #endif // ENABLE_THREADS
136 * Add a loaded tile to the 'attach to the scene graph' queue.
138 static void ready_to_attach( FGTileEntry *t ) { attach_queue.push( t ); }
140 #ifdef WISH_PLIB_WAS_THREADED // but it isn't
142 * Tile is detatched from scene graph and is ready to delete
144 inline void ready_to_delete( FGTileEntry *t ) { loader.remove( t ); }
148 * Add a pending model to the 'deferred model load' queue
150 static void model_ready( FGDeferredModel *dm ) { model_queue.push( dm ); }
160 // Initialize the Tile Manager subsystem
163 // given the current lon/lat (in degrees), fill in the array of
164 // local chunks. If the chunk isn't already in the cache, then
165 // read it from disk.
166 int update( double lon, double lat, double visibility_meters );
167 int update( double lon, double lat, double visibility_meters, sgdVec3 abs_pos_vector, SGBucket p_current, SGBucket p_previous, Point3D center );
168 void setCurrentTile( double longitude, double latitude );
169 int updateCurrentElevAtPos(sgdVec3 abs_pos_vector, Point3D center );
171 // Determine scenery altitude. Normally this just happens when we
172 // render the scene, but we'd also like to be able to do this
173 // explicitely. lat & lon are in radians. abs_view_pos in
174 // meters. Returns result in meters.
175 void my_ssg_los( string s, ssgBranch *branch, sgdMat4 m,
176 const sgdVec3 p, const sgdVec3 dir, sgdVec3 normal );
178 void my_ssg_los( ssgBranch *branch, sgdMat4 m,
179 const sgdVec3 p, const sgdVec3 dir,
182 // Prepare the ssg nodes ... for each tile, set it's proper
183 // transform and update it's range selector based on current
185 void prep_ssg_nodes(float visibility_meters);
186 void prep_ssg_nodes(float visibility_meters, sgVec3 up, Point3D center);
189 // Set flag with event manager so that non-moving view refreshes tiles...
191 void refresh_view_timestamps();
193 inline SGBucket get_current_bucket () { return current_bucket; }
194 inline SGBucket get_previous_bucket () { return previous_bucket; }
199 extern FGTileMgr global_tile_mgr;
202 #endif // _TILEMGR_HXX