]> git.mxchange.org Git - flightgear.git/blob - Scenery/tilecache.c
Playing with new fgPrintf command.
[flightgear.git] / Scenery / tilecache.c
1 /**************************************************************************
2  * tilecache.c -- routines to handle scenery tile caching
3  *
4  * Written by Curtis Olson, started January 1998.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef WIN32
28 #  include <windows.h>
29 #endif
30
31 #include <GL/glut.h>
32 #include <XGL/xgl.h>
33
34 #include <Include/general.h>
35 #include <Scenery/bucketutils.h>
36 #include <Scenery/obj.h>
37 #include <Scenery/tilecache.h>
38 #include <Main/fg_debug.h>
39
40
41 /* tile cache */
42 struct fgTILE tile_cache[FG_TILE_CACHE_SIZE];
43
44
45 /* Initialize the tile cache subsystem */
46 void fgTileCacheInit( void ) {
47     int i;
48
49     fgPrintf(FG_TERRAIN, FG_INFO, "Initializing the tile cache.\n");
50
51     for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
52         tile_cache[i].used = 0;
53     }
54 }
55
56
57 /* Return index of next available slot in tile cache */
58 int fgTileCacheNextAvail( void ) {
59      int i;
60      
61      for ( i = 0; i < FG_TILE_CACHE_SIZE; i++ ) {
62          if ( tile_cache[i].used == 0 ) {
63              return(i);
64          }
65      }
66
67      return(-1);
68 }
69
70
71 /* Fill in a tile cache entry with real data for the specified bucket */
72 void fgTileCacheEntryFillIn( int index, struct fgBUCKET *p ) {
73     struct fgGENERAL *g;
74     char base_path[256];
75     char file_name[256];
76
77     g = &general;
78
79     /* Mark this cache entry as used */
80     tile_cache[index].used = 1;
81
82     /* Update the bucket */
83     tile_cache[index].tile_bucket.lon = p->lon;
84     tile_cache[index].tile_bucket.lat = p->lat;
85     tile_cache[index].tile_bucket.x = p->x;
86     tile_cache[index].tile_bucket.y = p->y;
87
88     /* Load the appropriate area and get the display list pointer */
89     fgBucketGenBasePath(p, base_path);
90     sprintf(file_name, "%s/Scenery/%s/%ld.obj", g->root_dir, 
91             base_path, fgBucketGenIndex(p));
92     tile_cache[index].display_list = 
93         fgObjLoad(file_name, &tile_cache[index].local_ref);    
94 }
95
96
97 /* Return info for a tile cache entry */
98 void fgTileCacheEntryInfo( int index, GLint *display_list, 
99                            struct fgCartesianPoint *local_ref ) {
100     *display_list = tile_cache[index].display_list;
101     /* fgPrintf(FG_TERRAIN, FG_DEBUG, "Display list = %d\n", *display_list); */
102
103     local_ref->x = tile_cache[index].local_ref.x;
104     local_ref->y = tile_cache[index].local_ref.y;
105     local_ref->z = tile_cache[index].local_ref.z;
106 }
107
108
109 /* Free the specified cache entry
110 void fgTileCacheEntryFree( in index ) {
111 }
112 */
113
114
115 /* $Log$
116 /* Revision 1.4  1998/01/27 03:26:43  curt
117 /* Playing with new fgPrintf command.
118 /*
119  * Revision 1.3  1998/01/27 00:48:03  curt
120  * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
121  * system and commandline/config file processing code.
122  *
123  * Revision 1.2  1998/01/26 15:55:24  curt
124  * Progressing on building dynamic scenery system.
125  *
126  * Revision 1.1  1998/01/24 00:03:29  curt
127  * Initial revision.
128  *
129  */
130
131