]> git.mxchange.org Git - flightgear.git/blob - Simulator/Scenery/tilecache.hxx
Merge FG_Simulator as subdirectory
[flightgear.git] / Simulator / Scenery / tilecache.hxx
1 // tilecache.hxx -- routines to handle scenery tile caching
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 // (Log is kept at end of this file)
23
24
25 #ifndef _TILECACHE_HXX
26 #define _TILECACHE_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33
34 #ifdef HAVE_CONFIG_H
35 #  include <config.h>
36 #endif
37
38 #ifdef HAVE_WINDOWS_H
39 #  include <windows.h>
40 #endif
41
42 #include <GL/glut.h>
43 #include <XGL/xgl.h>
44
45 #include <Bucket/newbucket.hxx>
46 #include <Math/point3d.hxx>
47
48 #include "tile.hxx"
49
50
51 // For best results ... i.e. to avoid tile load problems and blank areas
52 //
53 // FG_TILE_CACHE_SIZE >= (o->tile_diameter + 1) ** 2 
54 #define FG_TILE_CACHE_SIZE 121
55
56 // A class to store and manage a pile of tiles
57 class fgTILECACHE {
58
59 //     enum
60 //     {
61 //      // For best results... i.e. to avoid tile load problems and blank areas
62 //      // FG_TILE_CACHE_SIZE >= (o->tile_diameter + 1) ** 2 
63 //      FG_TILE_CACHE_SIZE = 121
64 //     };
65
66     // cache storage space
67     fgTILE tile_cache[ FG_TILE_CACHE_SIZE ];
68
69 public:
70
71     // Constructor
72     fgTILECACHE( void );
73
74     // Initialize the tile cache subsystem 
75     void init( void );
76
77     // Search for the specified "bucket" in the cache 
78     int exists( const FGBucket& p );
79
80     // Return index of next available slot in tile cache 
81     int next_avail( void );
82
83     // Free a tile cache entry
84     void entry_free( int index );
85
86     // Fill in a tile cache entry with real data for the specified bucket 
87     void fill_in( int index, FGBucket& p );
88
89     // Return a pointer to the specified tile cache entry 
90     fgTILE *get_tile( int index ) {
91         return &tile_cache[index];
92     }
93
94     // Destructor
95     ~fgTILECACHE( void );
96 };
97
98
99 // the tile cache
100 extern fgTILECACHE global_tile_cache;
101
102
103 #endif // _TILECACHE_HXX 
104
105
106 // $Log$
107 // Revision 1.14  1999/03/25 19:03:27  curt
108 // Converted to use new bucket routines.
109 //
110 // Revision 1.13  1998/11/09 23:40:51  curt
111 // Bernie Bright <bbright@c031.aone.net.au> writes:
112 // I've made some changes to the Scenery handling.  Basically just tidy ups.
113 // The main difference is in tile.[ch]xx where I've changed list<fgFRAGMENT> to
114 // vector<fgFRAGMENT>.  Studying our usage patterns this seems reasonable.
115 // Lists are good if you need to insert/delete elements randomly but we
116 // don't do that.  All access seems to be sequential.  Two additional
117 // benefits are smaller memory usage - each list element requires pointers
118 // to the next and previous elements, and faster access - vector iterators
119 // are smaller and faster than list iterators.  This should also help
120 // Charlie Hotchkiss' problem when compiling with Borland and STLport.
121 //
122 // ./Lib/Bucket/bucketutils.hxx
123 //   Convenience functions for fgBUCKET.
124 //
125 // ./Simulator/Scenery/tile.cxx
126 // ./Simulator/Scenery/tile.hxx
127 //   Changed fragment list to a vector.
128 //   Added some convenience member functions.
129 //
130 // ./Simulator/Scenery/tilecache.cxx
131 // ./Simulator/Scenery/tilecache.hxx
132 //   use const fgBUCKET& instead of fgBUCKET* where appropriate.
133 //
134 // ./Simulator/Scenery/tilemgr.cxx
135 // ./Simulator/Scenery/tilemgr.hxx
136 //   uses all the new convenience functions.
137 //
138 // Revision 1.12  1998/10/16 00:55:49  curt
139 // Converted to Point3D class.
140 //
141 // Revision 1.11  1998/09/14 12:45:25  curt
142 // minor tweaks.
143 //
144 // Revision 1.10  1998/07/04 00:54:31  curt
145 // Added automatic mipmap generation.
146 //
147 // When rendering fragments, use saved model view matrix from associated tile
148 // rather than recalculating it with push() translate() pop().
149 //
150 // Revision 1.9  1998/05/23 14:09:22  curt
151 // Added tile.cxx and tile.hxx.
152 // Working on rewriting the tile management system so a tile is just a list
153 // fragments, and the fragment record contains the display list for that fragment.
154 //
155 // Revision 1.8  1998/05/20 20:53:54  curt
156 // Moved global ref point and radius (bounding sphere info, and offset) to
157 // data file rather than calculating it on the fly.
158 // Fixed polygon winding problem in scenery generation stage rather than
159 // compensating for it on the fly.
160 // Made a fgTILECACHE class.
161 //
162 // Revision 1.7  1998/05/16 13:09:57  curt
163 // Beginning to add support for view frustum culling.
164 // Added some temporary code to calculate bouding radius, until the
165 //   scenery generation tools and scenery can be updated.
166 //
167 // Revision 1.6  1998/05/07 23:15:20  curt
168 // Fixed a glTexImage2D() usage bug where width and height were mis-swapped.
169 // Added support for --tile-radius=n option.
170 //
171 // Revision 1.5  1998/05/02 01:52:17  curt
172 // Playing around with texture coordinates.
173 //
174 // Revision 1.4  1998/04/30 12:35:31  curt
175 // Added a command line rendering option specify smooth/flat shading.
176 //
177 // Revision 1.3  1998/04/25 22:06:32  curt
178 // Edited cvs log messages in source files ... bad bad bad!
179 //
180 // Revision 1.2  1998/04/24 00:51:08  curt
181 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
182 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
183 // or "file.obz" (compressed.)
184 //
185 // Revision 1.1  1998/04/22 13:22:47  curt
186 // C++ - ifing the code a bit.
187 //
188 // Revision 1.10  1998/04/21 17:02:45  curt
189 // Prepairing for C++ integration.
190 //
191 // Revision 1.9  1998/04/14 02:23:17  curt
192 // Code reorganizations.  Added a Lib/ directory for more general libraries.
193 //
194 // Revision 1.8  1998/04/08 23:30:08  curt
195 // Adopted Gnu automake/autoconf system.
196 //
197 // Revision 1.7  1998/04/03 22:11:38  curt
198 // Converting to Gnu autoconf system.
199 //
200 // Revision 1.6  1998/02/18 15:07:10  curt
201 // Tweaks to build with SGI OpenGL (and therefor hopefully other accelerated
202 // drivers will work.)
203 //
204 // Revision 1.5  1998/02/16 13:39:45  curt
205 // Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
206 // tiles to occasionally be missing.
207 //
208 // Revision 1.4  1998/01/31 00:43:27  curt
209 // Added MetroWorks patches from Carmen Volpe.
210 //
211 // Revision 1.3  1998/01/29 00:51:40  curt
212 // First pass at tile cache, dynamic tile loading and tile unloading now works.
213 //
214 // Revision 1.2  1998/01/27 00:48:04  curt
215 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
216 // system and commandline/config file processing code.
217 //
218 // Revision 1.1  1998/01/24 00:03:29  curt
219 // Initial revision.
220
221