1 // tileentry.hxx -- routines to handle an individual scenery tile
3 // Written by Curtis Olson, started May 1998.
5 // Copyright (C) 1998, 1999 Curtis L. Olson - curt@flightgear.org
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.
24 #ifndef _TILEENTRY_HXX
25 #define _TILEENTRY_HXX
29 # error This library requires C++
41 #include <simgear/xgl/xgl.h>
43 #include <simgear/compiler.h>
48 #include <plib/ssg.h> // plib includes
50 #include <simgear/bucket/newbucket.hxx>
51 #include <simgear/math/point3d.hxx>
53 #include <Objects/fragment.hxx>
63 typedef vector < Point3D > point_list;
64 typedef point_list::iterator point_list_iterator;
65 typedef point_list::const_iterator const_point_list_iterator;
76 Scheduled_for_use = 1,
77 Scheduled_for_cache = 2,
84 typedef vector < fgFRAGMENT > container;
85 typedef container::iterator FragmentIterator;
86 typedef container::const_iterator FragmentConstIterator;
88 typedef vector < sgVec3 * > free_vec3_list;
89 typedef vector < sgVec2 * > free_vec2_list;
90 typedef vector < unsigned short * > free_index_list;
93 // node list (the per fragment face lists reference this node list)
97 // global tile culling data
99 double bounding_radius;
102 // model view matrix for this tile
103 GLfloat model_view[16];
105 // this tile's official location in the world
106 FGBucket tile_bucket;
108 // the tile cache will keep track here if the tile is being used
111 container fragment_list;
113 // ssg related structures
118 // list of pointers to memory chunks that need to be freed when
119 // tile entry goes away
120 free_vec3_list vec3_ptrs;
121 free_vec2_list vec2_ptrs;
122 free_index_list index_ptrs;
124 // ssg tree structure for this tile is as follows:
126 // - ssgBranch(terrain)
127 // - ssgSelector(tile)
128 // - ssgTransform(tile)
129 // - ssgRangeSelector(tile)
136 // selector (turn tile on/off)
137 ssgSelector *select_ptr;
139 // pointer to ssg transform for this tile
140 ssgTransform *transform_ptr;
142 // pointer to ssg range selector for this tile
143 ssgRangeSelector *range_ptr;
148 FGTileEntry ( void );
151 ~FGTileEntry ( void );
153 FragmentIterator begin() { return fragment_list.begin(); }
154 FragmentConstIterator begin() const { return fragment_list.begin(); }
156 FragmentIterator end() { return fragment_list.end(); }
157 FragmentConstIterator end() const { return fragment_list.end(); }
159 void add_fragment( fgFRAGMENT& frag ) {
160 frag.tile_ptr = this;
161 fragment_list.push_back( frag );
164 size_t num_fragments() const {
165 return fragment_list.size();
168 // Step through the fragment list, deleting the display list, then
169 // the fragment, until the list is empty. Also delete the arrays
170 // used by ssg as well as the whole ssg branch
173 // Calculate this tile's offset
174 void SetOffset( const Point3D& p)
179 // Return this tile's offset
180 inline Point3D get_offset( void ) const { return offset; }
182 // Calculate the model_view transformation matrix for this tile
183 inline void update_view_matrix(GLfloat *MODEL_VIEW)
186 #if defined( USE_MEM ) || defined( WIN32 )
187 memcpy( model_view, MODEL_VIEW, 16*sizeof(GLfloat) );
189 bcopy( MODEL_VIEW, model_view, 16*sizeof(GLfloat) );
192 // This is equivalent to doing a glTranslatef(x, y, z);
193 model_view[12] += (model_view[0]*offset.x() +
194 model_view[4]*offset.y() +
195 model_view[8]*offset.z());
196 model_view[13] += (model_view[1]*offset.x() +
197 model_view[5]*offset.y() +
198 model_view[9]*offset.z());
199 model_view[14] += (model_view[2]*offset.x() +
200 model_view[6]*offset.y() +
201 model_view[10]*offset.z() );
202 // m[15] += (m[3]*x + m[7]*y + m[11]*z);
203 // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
204 // so m[15] is unchanged
207 inline bool is_unused() const { return state == Unused; }
208 inline bool is_scheduled_for_use() const {
209 return state == Scheduled_for_use;
211 inline bool is_scheduled_for_cache() const {
212 return state == Scheduled_for_cache;
214 inline bool is_loaded() const { return state == Loaded; }
215 inline bool is_cached() const { return state == Cached; }
217 inline void mark_unused() { state = Unused; }
218 inline void mark_scheduled_for_use() { state = Scheduled_for_use; }
219 inline void mark_scheduled_for_cache() { state = Scheduled_for_use; }
220 inline void mark_loaded() { state = Loaded; }
223 // when a tile is still in the cache, but not in the immediate
224 // draw l ist, it can still remain in the scene graph, but we use
225 // a range selector to disable it from ever being drawn.
230 typedef vector < FGTileEntry > tile_list;
231 typedef tile_list::iterator tile_list_iterator;
232 typedef tile_list::const_iterator const_tile_list_iterator;
235 #endif // _TILEENTRY_HXX