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 **************************************************************************/
32 #include "../XGL/xgl.h"
35 #include "tileutils.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() {
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() {
67 f = ¤t_aircraft.flight;
70 find_bucket(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
71 printf("Updating Tile list for %d,%d %d,%d\n", p.lon, p.lat, p.x, p.y);
73 gen_idx_array(&p, local_tiles, 7, 7);
75 /* scenery.center = ref; */
77 for ( i = 0; i < 49; i++ ) {
78 gen_base_path(&local_tiles[i], base_path);
79 sprintf(file_name, "%s/Scenery/%s/%ld.obj",
80 g->root_dir, base_path, gen_index(&local_tiles[i]));
81 local_display_lists[i] =
82 fgObjLoad(file_name, &local_refs[i]);
84 if ( (local_tiles[i].lon == p.lon) &&
85 (local_tiles[i].lat == p.lat) &&
86 (local_tiles[i].x == p.x) &&
87 (local_tiles[i].y == p.y) ) {
88 scenery.center = local_refs[i];
94 /* Render the local tiles --- hack, hack, hack */
95 void fgTileMgrRender() {
96 static GLfloat terrain_color[4] = { 0.6, 0.8, 0.4, 1.0 };
97 static GLfloat terrain_ambient[4];
98 static GLfloat terrain_diffuse[4];
101 for ( i = 0; i < 4; i++ ) {
102 terrain_ambient[i] = terrain_color[i] * 0.5;
103 terrain_diffuse[i] = terrain_color[i];
106 xglMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient);
107 xglMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse);
109 for ( i = 0; i < 49; i++ ) {
111 xglTranslatef(local_refs[i].x - scenery.center.x,
112 local_refs[i].y - scenery.center.y,
113 local_refs[i].z - scenery.center.z);
114 xglCallList(local_display_lists[i]);
121 /* Revision 1.3 1998/01/13 00:23:11 curt
122 /* Initial changes to support loading and management of scenery tiles. Note,
123 /* there's still a fair amount of work left to be done.
125 * Revision 1.2 1998/01/08 02:22:27 curt
126 * Continue working on basic features.
128 * Revision 1.1 1998/01/07 23:50:51 curt
129 * "area" renamed to "tile"
131 * Revision 1.2 1998/01/07 03:29:29 curt
132 * Given an arbitrary lat/lon, we can now:
133 * generate a unique index for the chunk containing the lat/lon
134 * generate a path name to the chunk file
135 * build a list of the indexes of all the nearby areas.
137 * Revision 1.1 1998/01/07 02:05:48 curt