]> git.mxchange.org Git - flightgear.git/blob - Scenery/tilemgr.c
Tons of little changes to clean up the code and to remove fatal errors
[flightgear.git] / Scenery / tilemgr.c
1 /**************************************************************************
2  * tilemgr.c -- routines to handle dynamic management of scenery tiles
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 "scenery.h"
35 #include "tileutils.h"
36 #include "obj.h"
37
38 #include "../Aircraft/aircraft.h"
39 #include "../Include/constants.h"
40 #include "../Include/general.h"
41 #include "../Include/types.h"
42
43
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];
48
49
50 /* Initialize the Tile Manager subsystem */
51 void fgTileMgrInit( void ) {
52     printf("Initializing Tile Manager subsystem.\n");
53     /* fgTileCacheInit(); */
54 }
55
56
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 ) {
60     struct fgFLIGHT *f;
61     struct fgGENERAL *g;
62     struct bucket p;
63     struct bucket p_last = {-1000, 0, 0, 0};
64     char base_path[256];
65     char file_name[256];
66     int i, j;
67
68     f = &current_aircraft.flight;
69     g = &general;
70
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);
73
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 */
77     }
78
79     gen_idx_array(&p, local_tiles, 7, 7);
80
81     /* scenery.center = ref; */
82
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]);
89
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];
95         }
96     }
97 }
98
99
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];
105     int i, j;
106
107     for ( i = 0; i < 4; i++ ) {
108         terrain_ambient[i] = terrain_color[i] * 0.5;
109         terrain_diffuse[i] = terrain_color[i];
110     }
111
112     xglMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient);
113     xglMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse);
114
115     for ( i = 0; i < 49; i++ ) {
116         xglPushMatrix();
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]);
121         xglPopMatrix();
122     }
123 }
124
125
126 /* $Log$
127 /* Revision 1.4  1998/01/19 18:40:38  curt
128 /* Tons of little changes to clean up the code and to remove fatal errors
129 /* when building with the c++ compiler.
130 /*
131  * Revision 1.3  1998/01/13 00:23:11  curt
132  * Initial changes to support loading and management of scenery tiles.  Note,
133  * there's still a fair amount of work left to be done.
134  *
135  * Revision 1.2  1998/01/08 02:22:27  curt
136  * Continue working on basic features.
137  *
138  * Revision 1.1  1998/01/07 23:50:51  curt
139  * "area" renamed to "tile"
140  *
141  * Revision 1.2  1998/01/07 03:29:29  curt
142  * Given an arbitrary lat/lon, we can now:
143  *   generate a unique index for the chunk containing the lat/lon
144  *   generate a path name to the chunk file
145  *   build a list of the indexes of all the nearby areas.
146  *
147  * Revision 1.1  1998/01/07 02:05:48  curt
148  * Initial revision.
149  * */
150
151