| 1 | // tilemgr.hxx -- routines to handle dynamic management of scenery tiles |
| 2 | // |
| 3 | // Written by Curtis Olson, started January 1998. |
| 4 | // |
| 5 | // SPDX-FileCopyrightText: 1998 Curtis L. Olson |
| 6 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <simgear/compiler.h> |
| 11 | |
| 12 | #include <simgear/bucket/newbucket.hxx> |
| 13 | #include "SceneryPager.hxx" |
| 14 | #include "tilecache.hxx" |
| 15 | |
| 16 | namespace osg |
| 17 | { |
| 18 | class Node; |
| 19 | } |
| 20 | |
| 21 | namespace simgear |
| 22 | { |
| 23 | class SGReaderWriterOptions; |
| 24 | } |
| 25 | |
| 26 | class FGTileMgr { |
| 27 | |
| 28 | private: |
| 29 | |
| 30 | // Tile loading state |
| 31 | enum load_state { |
| 32 | Start = 0, |
| 33 | Inited = 1, |
| 34 | Running = 2 |
| 35 | }; |
| 36 | |
| 37 | load_state state, last_state; |
| 38 | |
| 39 | // schedule a tile for loading, returns true when tile is already loaded |
| 40 | bool sched_tile( const SGBucket& b, double priority,bool current_view, double request_time); |
| 41 | |
| 42 | // schedule a needed buckets for loading |
| 43 | void schedule_needed(const SGBucket& curr_bucket, double rangeM); |
| 44 | |
| 45 | bool isTileDirSyncing(const std::string& tileFileName) const; |
| 46 | |
| 47 | SGBucket previous_bucket; |
| 48 | SGBucket current_bucket; |
| 49 | SGBucket pending; |
| 50 | osg::ref_ptr<simgear::SGReaderWriterOptions> _options; |
| 51 | |
| 52 | double scheduled_visibility; |
| 53 | |
| 54 | /** |
| 55 | * tile cache |
| 56 | */ |
| 57 | TileCache tile_cache; |
| 58 | |
| 59 | class TileManagerListener; |
| 60 | friend class TileManagerListener; |
| 61 | std::unique_ptr<TileManagerListener> _listener; |
| 62 | |
| 63 | // update various queues internal queues |
| 64 | void update_queues(bool& isDownloadingScenery); |
| 65 | |
| 66 | // schedule tiles for the viewer bucket |
| 67 | void schedule_tiles_at(const SGGeod& location, double rangeM); |
| 68 | |
| 69 | SGPropertyNode_ptr _visibilityMeters; |
| 70 | SGPropertyNode_ptr _lodDetailed, _lodRoughDelta, _lodBareDelta, _disableNasalHooks; |
| 71 | SGPropertyNode_ptr _scenery_loaded, _scenery_override; |
| 72 | |
| 73 | // Statistics from the database pager. |
| 74 | SGPropertyNode_ptr _pager_file_queue_size, _pager_compile_queue_size, _pager_merge_queue_size; |
| 75 | SGPropertyNode_ptr _pager_min_merge_time, _pager_mean_merge_time, _pager_max_merge_time; |
| 76 | |
| 77 | osg::ref_ptr<flightgear::SceneryPager> _pager; |
| 78 | |
| 79 | /// is caching of expired tiles enabled or not? |
| 80 | bool _enableCache; |
| 81 | bool _use_vpb; |
| 82 | public: |
| 83 | FGTileMgr(); |
| 84 | ~FGTileMgr(); |
| 85 | |
| 86 | // Initialize the Tile Manager |
| 87 | void init(); |
| 88 | void reinit(); |
| 89 | void shutdown(); |
| 90 | void update(double dt); |
| 91 | |
| 92 | const SGBucket& get_current_bucket () const { return current_bucket; } |
| 93 | |
| 94 | // Returns true if scenery is available for the given lat, lon position |
| 95 | // within a range of range_m. |
| 96 | // lat and lon are expected to be in degrees. |
| 97 | bool schedule_scenery(const SGGeod& position, double range_m, double duration=0.0); |
| 98 | |
| 99 | // Returns true if tiles around current view position have been loaded |
| 100 | bool isSceneryLoaded(); |
| 101 | |
| 102 | // notify the tile manahger the material library was reloaded, |
| 103 | // so it can pass this through to its options object |
| 104 | void materialLibChanged(); |
| 105 | }; |