1 /**************************************************************************
2 * tilemgr.c -- routines to handle dynamic management of scenery tiles
4 * Written by Curtis Olson, started January 1998.
6 * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
23 * (Log is kept at end of this file)
24 **************************************************************************/
34 #include <Scenery/scenery.h>
35 #include <Scenery/tileutils.h>
36 #include <Scenery/obj.h>
38 #include <Aircraft/aircraft.h>
39 #include <Include/constants.h>
40 #include <Include/general.h>
41 #include <Include/types.h>
44 /* here's where we keep the array of closest (potentially viewable) tiles */
45 struct bucket local_tiles[49];
46 GLint local_display_lists[49];
47 struct fgCartesianPoint local_refs[49];
50 /* Initialize the Tile Manager subsystem */
51 void fgTileMgrInit( void ) {
52 printf("Initializing Tile Manager subsystem.\n");
53 /* fgTileCacheInit(); */
57 /* given the current lon/lat, fill in the array of local chunks. If
58 * the chunk isn't already in the cache, then read it from disk. */
59 void fgTileMgrUpdate( void ) {
63 struct bucket p_last = {-1000, 0, 0, 0};
68 f = ¤t_aircraft.flight;
71 find_bucket(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
72 printf("Updating Tile list for %d,%d %d,%d\n", p.lon, p.lat, p.x, p.y);
74 if ( (p.lon == p_last.lon) && (p.lat == p_last.lat) &&
75 (p.x == p_last.x) && (p.y == p_last.y) ) {
76 /* same bucket as last time */
79 gen_idx_array(&p, local_tiles, 7, 7);
81 /* scenery.center = ref; */
83 for ( i = 0; i < 49; i++ ) {
84 gen_base_path(&local_tiles[i], base_path);
85 sprintf(file_name, "%s/Scenery/%s/%ld.obj",
86 g->root_dir, base_path, gen_index(&local_tiles[i]));
87 local_display_lists[i] =
88 fgObjLoad(file_name, &local_refs[i]);
90 if ( (local_tiles[i].lon == p.lon) &&
91 (local_tiles[i].lat == p.lat) &&
92 (local_tiles[i].x == p.x) &&
93 (local_tiles[i].y == p.y) ) {
94 scenery.center = local_refs[i];
100 /* Render the local tiles --- hack, hack, hack */
101 void fgTileMgrRender( void ) {
102 static GLfloat terrain_color[4] = { 0.6, 0.8, 0.4, 1.0 };
103 static GLfloat terrain_ambient[4];
104 static GLfloat terrain_diffuse[4];
107 for ( i = 0; i < 4; i++ ) {
108 terrain_ambient[i] = terrain_color[i] * 0.5;
109 terrain_diffuse[i] = terrain_color[i];
112 xglMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient);
113 xglMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse);
115 for ( i = 0; i < 49; i++ ) {
117 xglTranslatef(local_refs[i].x - scenery.center.x,
118 local_refs[i].y - scenery.center.y,
119 local_refs[i].z - scenery.center.z);
120 xglCallList(local_display_lists[i]);
127 /* Revision 1.5 1998/01/19 19:27:18 curt
128 /* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
129 /* This should simplify things tremendously.
131 * Revision 1.4 1998/01/19 18:40:38 curt
132 * Tons of little changes to clean up the code and to remove fatal errors
133 * when building with the c++ compiler.
135 * Revision 1.3 1998/01/13 00:23:11 curt
136 * Initial changes to support loading and management of scenery tiles. Note,
137 * there's still a fair amount of work left to be done.
139 * Revision 1.2 1998/01/08 02:22:27 curt
140 * Continue working on basic features.
142 * Revision 1.1 1998/01/07 23:50:51 curt
143 * "area" renamed to "tile"
145 * Revision 1.2 1998/01/07 03:29:29 curt
146 * Given an arbitrary lat/lon, we can now:
147 * generate a unique index for the chunk containing the lat/lon
148 * generate a path name to the chunk file
149 * build a list of the indexes of all the nearby areas.
151 * Revision 1.1 1998/01/07 02:05:48 curt