| 1 | // tileentry.hxx -- routines to handle an individual scenery tile |
| 2 | // |
| 3 | // Written by Curtis Olson, started May 1998. |
| 4 | // |
| 5 | // Copyright (C) 1998 - 2001 Curtis L. Olson - http://www.flightgear.org/~curt |
| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | // |
| 21 | // $Id$ |
| 22 | |
| 23 | |
| 24 | #ifndef _TILEENTRY_HXX |
| 25 | #define _TILEENTRY_HXX |
| 26 | |
| 27 | |
| 28 | #ifndef __cplusplus |
| 29 | # error This library requires C++ |
| 30 | #endif |
| 31 | |
| 32 | #include <Main/globals.hxx> |
| 33 | #include <Main/fg_props.hxx> |
| 34 | |
| 35 | #include <simgear/compiler.h> |
| 36 | |
| 37 | #include <vector> |
| 38 | #include <string> |
| 39 | |
| 40 | #include <simgear/bucket/newbucket.hxx> |
| 41 | #include <simgear/misc/sg_path.hxx> |
| 42 | #include <simgear/scene/util/OrthophotoManager.hxx> |
| 43 | #include <simgear/scene/util/SGReaderWriterOptions.hxx> |
| 44 | |
| 45 | #include <osg/ref_ptr> |
| 46 | #include <osgDB/ReaderWriter> |
| 47 | #include <osg/Group> |
| 48 | #include <osg/LOD> |
| 49 | |
| 50 | /** |
| 51 | * A class to encapsulate everything we need to know about a scenery tile. |
| 52 | */ |
| 53 | class TileEntry { |
| 54 | |
| 55 | public: |
| 56 | // this tile's official location in the world |
| 57 | SGBucket tile_bucket; |
| 58 | std::string tileFileName; |
| 59 | |
| 60 | protected: |
| 61 | // pointer to ssg range selector for this tile |
| 62 | osg::ref_ptr<osg::LOD> _node; |
| 63 | |
| 64 | private: |
| 65 | // Reference to DatabaseRequest object set and used by the |
| 66 | // osgDB::DatabasePager. |
| 67 | osg::ref_ptr<osg::Referenced> _databaseRequest; |
| 68 | // Overlay image/orthophoto for this tile |
| 69 | simgear::OrthophotoRef _orthophoto; |
| 70 | |
| 71 | /** |
| 72 | * This value is used by the tile scheduler/loader to load tiles |
| 73 | * in a useful sequence. The priority is set to reflect the tiles |
| 74 | * distance from the center, so all tiles are loaded in an innermost |
| 75 | * to outermost sequence. |
| 76 | */ |
| 77 | float _priority; |
| 78 | /** Flag indicating if tile belongs to current view. */ |
| 79 | bool _current_view; |
| 80 | /** Time when tile expires. */ |
| 81 | double _time_expired; |
| 82 | |
| 83 | void _create_orthophoto(); |
| 84 | |
| 85 | public: |
| 86 | |
| 87 | // Constructor. |
| 88 | TileEntry( const SGBucket& b ); |
| 89 | TileEntry( const TileEntry& t ); |
| 90 | |
| 91 | // Destructor |
| 92 | virtual ~TileEntry() = 0; |
| 93 | |
| 94 | // Update the ssg transform node for this tile so it can be |
| 95 | // properly drawn relative to our (0,0,0) point |
| 96 | void prep_ssg_node(float vis); |
| 97 | |
| 98 | /** |
| 99 | * Return true if the tile entry is loaded, otherwise return false |
| 100 | * indicating that the loading thread is still working on this. |
| 101 | */ |
| 102 | inline bool is_loaded() const |
| 103 | { |
| 104 | return _node->getNumChildren() > 0; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Return the "bucket" for this tile |
| 109 | */ |
| 110 | inline const SGBucket& get_tile_bucket() const { return tile_bucket; } |
| 111 | |
| 112 | /** |
| 113 | * Add terrain mesh and ground lighting to scene graph. |
| 114 | */ |
| 115 | void addToSceneGraph( osg::Group *terrain_branch); |
| 116 | |
| 117 | /** |
| 118 | * disconnect terrain mesh and ground lighting nodes from scene |
| 119 | * graph for this tile. |
| 120 | */ |
| 121 | void removeFromSceneGraph(); |
| 122 | |
| 123 | /** |
| 124 | * return the scenegraph node for the terrain |
| 125 | */ |
| 126 | osg::LOD *getNode() const { return _node.get(); } |
| 127 | |
| 128 | inline double get_time_expired() const { return _time_expired; } |
| 129 | inline void update_time_expired( double time_expired ) { if (_time_expired<time_expired) _time_expired = time_expired; } |
| 130 | |
| 131 | inline void set_priority(float priority) { _priority=priority; } |
| 132 | inline float get_priority() const { return _priority; } |
| 133 | inline void set_current_view(bool current_view) { _current_view = current_view; } |
| 134 | inline bool is_current_view() const { return _current_view; } |
| 135 | |
| 136 | /** |
| 137 | * Return false if the tile entry is still needed, otherwise return true |
| 138 | * indicating that the tile is no longer in active use. |
| 139 | */ |
| 140 | inline bool is_expired(double current_time) const { return (_current_view) ? false : (current_time > _time_expired); } |
| 141 | |
| 142 | // Get the ref_ptr to the DatabaseRequest object, in order to pass |
| 143 | // this to the pager. |
| 144 | osg::ref_ptr<osg::Referenced>& getDatabaseRequest() |
| 145 | { |
| 146 | return _databaseRequest; |
| 147 | } |
| 148 | |
| 149 | enum Extension { |
| 150 | STG, VPB |
| 151 | }; |
| 152 | |
| 153 | virtual TileEntry::Extension getExtension() = 0; |
| 154 | }; |
| 155 | |
| 156 | class STGTileEntry : public TileEntry { |
| 157 | public: |
| 158 | STGTileEntry ( const SGBucket& b ); |
| 159 | ~STGTileEntry(); |
| 160 | inline TileEntry::Extension getExtension() { return TileEntry::Extension::STG; }; |
| 161 | }; |
| 162 | |
| 163 | class VPBTileEntry : public TileEntry { |
| 164 | public: |
| 165 | VPBTileEntry ( const SGBucket& b, osg::ref_ptr<simgear::SGReaderWriterOptions> options ); |
| 166 | ~VPBTileEntry(); |
| 167 | inline TileEntry::Extension getExtension() { return TileEntry::Extension::VPB; }; |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | #endif // _TILEENTRY_HXX |