From 39ae3864defa9be90667638efa000bc0ac2fbdfb Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 23 Jun 2000 00:30:04 +0000 Subject: [PATCH] Cleaned up all the old fragment and material_mgr stuff which originated from the pre-ssg / render everything ourselves days. Replaced with a material library manager that is much better suited for working in the context of ssg. This simplified and cleaned up a ton of old junk. --- src/Airports/Makefile.am | 1 - src/Airports/genapt.cxx | 296 ------------------------- src/Airports/genapt.hxx | 65 ------ src/Main/Makefile.am | 1 - src/Main/fg_init.cxx | 12 +- src/Main/keyboard.cxx | 19 +- src/Main/main.cxx | 1 - src/Makefile.am | 1 - src/Objects/Makefile.am | 5 +- src/Objects/fragment.cxx | 330 ---------------------------- src/Objects/fragment.hxx | 171 --------------- src/Objects/material.cxx | 286 ------------------------ src/Objects/material.hxx | 106 --------- src/Objects/materialmgr.cxx | 418 ------------------------------------ src/Objects/materialmgr.hxx | 181 ---------------- src/Objects/obj.cxx | 158 ++++---------- src/Objects/obj.hxx | 2 +- src/Scenery/tilecache.cxx | 14 +- src/Scenery/tilecache.hxx | 2 +- src/Scenery/tileentry.cxx | 7 +- src/Scenery/tileentry.hxx | 34 +-- src/Scenery/tilemgr.cxx | 6 - 22 files changed, 70 insertions(+), 2046 deletions(-) delete mode 100644 src/Airports/genapt.cxx delete mode 100644 src/Airports/genapt.hxx delete mode 100644 src/Objects/fragment.cxx delete mode 100644 src/Objects/fragment.hxx delete mode 100644 src/Objects/material.cxx delete mode 100644 src/Objects/material.hxx delete mode 100644 src/Objects/materialmgr.cxx delete mode 100644 src/Objects/materialmgr.hxx diff --git a/src/Airports/Makefile.am b/src/Airports/Makefile.am index adee6d991..6ececcd0f 100644 --- a/src/Airports/Makefile.am +++ b/src/Airports/Makefile.am @@ -3,7 +3,6 @@ noinst_LIBRARIES = libAirports.a noinst_PROGRAMS = buildsimple libAirports_a_SOURCES = \ - genapt.cxx genapt.hxx \ simple.cxx simple.hxx buildsimple_SOURCES = buildsimple.cxx diff --git a/src/Airports/genapt.cxx b/src/Airports/genapt.cxx deleted file mode 100644 index 0c57045e6..000000000 --- a/src/Airports/genapt.cxx +++ /dev/null @@ -1,296 +0,0 @@ -// -// genapt.cxx -- generate airport scenery from the given definition file -// -// Written by Curtis Olson, started September 1998. -// -// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// $Id$ - - -#include - -#include STL_STRING -#include - -#ifdef __BORLANDC__ -# define exception c_exception -#endif -#include - -#ifdef FG_HAVE_NATIVE_SGI_COMPILERS -# include -#endif - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include "genapt.hxx" - -FG_USING_STD(string); -FG_USING_STD(vector); - - -typedef vector < Point3D > container; -typedef container::iterator iterator; -typedef container::const_iterator const_iterator; - - -#define FG_APT_BASE_TEX_CONSTANT 2000.0 - -// Calculate texture coordinates for a given point. -static Point3D calc_tex_coords(const Point3D& node, const Point3D& ref) { - Point3D cp; - Point3D pp; - - cp = Point3D( node[0] + ref.x(), node[1] + ref.y(), node[2] + ref.z() ); - - pp = fgCartToPolar3d(cp); - - pp.setx( fmod(FG_APT_BASE_TEX_CONSTANT * pp.x(), 10.0) ); - pp.sety( fmod(FG_APT_BASE_TEX_CONSTANT * pp.y(), 10.0) ); - - if ( pp.x() < 0.0 ) { - pp.setx( pp.x() + 10.0 ); - } - - if ( pp.y() < 0.0 ) { - pp.sety( pp.y() + 10.0 ); - } - - return(pp); -} - - -// generate the actual base area for the airport -static void -gen_base( const Point3D& average, const container& perimeter, FGTileEntry *t) -{ - GLint display_list; - Point3D cart, cart_trans, tex; - sgVec3 normal; - double dist, max_dist; - int center_num, i; - - fgFRAGMENT fragment; - - max_dist = 0.0; - - FG_LOG( FG_TERRAIN, FG_INFO, - "generating airport base for size = " << perimeter.size() ); - - fragment.init(); - fragment.tile_ptr = t; - - // find airport base material in the properties list - if ( ! material_mgr.find( APT_BASE_MATERIAL, fragment.material_ptr )) { - FG_LOG( FG_TERRAIN, FG_ALERT, - "Ack! unknown material name = " << APT_BASE_MATERIAL - << " in fgAptGenerat()" ); - } - - FG_LOG( FG_TERRAIN, FG_INFO, - " tile center = " - << t->center.x() << " " << t->center.y() << " " << t->center.z() ); - FG_LOG( FG_TERRAIN, FG_INFO, - " airport center = " - << average.x() << " " << average.y() << " " << average.z() ); - fragment.center = average; - - sgSetVec3( normal, average.x(), average.y(), average.z() ); - sgNormalizeVec3( normal ); - - display_list = xglGenLists(1); - xglNewList(display_list, GL_COMPILE); - xglBegin(GL_TRIANGLE_FAN); - - // first point center of fan - cart_trans = average - t->center; - t->nodes[t->ncount][0] = cart_trans.x(); - t->nodes[t->ncount][1] = cart_trans.y(); - t->nodes[t->ncount][2] = cart_trans.z(); - center_num = t->ncount; - t->ncount++; - - tex = calc_tex_coords( t->nodes[t->ncount-1], t->center ); - xglTexCoord2f(tex.x(), tex.y()); - xglNormal3fv(normal); - xglVertex3d(t->nodes[t->ncount-1][0], - t->nodes[t->ncount-1][1], - t->nodes[t->ncount-1][2]); - - // first point on perimeter - const_iterator current = perimeter.begin(); - cart = fgGeodToCart( *current ); - cart_trans = cart - t->center; - t->nodes[t->ncount][0] = cart_trans.x(); - t->nodes[t->ncount][1] = cart_trans.y(); - t->nodes[t->ncount][2] = cart_trans.z(); - t->ncount++; - - i = 1; - tex = calc_tex_coords( t->nodes[i], t->center ); - dist = cart.distance3Dsquared(average); - if ( dist > max_dist ) { - max_dist = dist; - } - xglTexCoord2f(tex.x(), tex.y()); - xglVertex3dv(t->nodes[i].get_n()); - ++current; - ++i; - - const_iterator last = perimeter.end(); - for ( ; current != last; ++current ) { - cart = fgGeodToCart( *current ); - cart_trans = cart - t->center; - t->nodes[t->ncount][0] = cart_trans.x(); - t->nodes[t->ncount][1] = cart_trans.y(); - t->nodes[t->ncount][2] = cart_trans.z(); - t->ncount++; - fragment.add_face(center_num, i - 1, i); - - tex = calc_tex_coords( t->nodes[i], t->center ); - dist = cart.distance3Dsquared(average); - if ( dist > max_dist ) { - max_dist = dist; - } - xglTexCoord2f(tex.x(), tex.y()); - xglVertex3dv(t->nodes[i].get_n()); - i++; - } - - // last point (first point in perimeter list) - current = perimeter.begin(); - cart = fgGeodToCart( *current ); - cart_trans = cart - t->center; - fragment.add_face(center_num, i - 1, 1); - - tex = calc_tex_coords( t->nodes[1], t->center ); - xglTexCoord2f(tex.x(), tex.y()); - xglVertex3dv(t->nodes[1].get_n()); - - xglEnd(); - xglEndList(); - - fragment.bounding_radius = sqrt(max_dist); - // fragment.display_list = display_list; - - t->fragment_list.push_back(fragment); -} - - -// Load a .apt file and register the GL fragments with the -// corresponding tile -int -fgAptGenerate(const string& path, FGTileEntry *tile) -{ - string token; - string apt_id, apt_name; - char c; - int i = 1; - - // face list (this indexes into the master tile vertex list) - container perimeter; - Point3D p, average; - double avex = 0.0, avey = 0.0, avez = 0.0; - int size; - - // gpc_vertex p_2d, list_2d[MAX_PERIMETER]; - // gpc_vertex_list perimeter_2d; - - fg_gzifstream in( path ); - if ( !in.is_open() ) { - // return immediately assuming an airport file for this tile - // doesn't exist. - return 0; - } - - apt_id = ""; - - // read in each line of the file - in >> skipcomment; - while ( ! in.eof() ) - { - in >> token; - - if ( token == "a" ) { - // airport info record (start of airport) - - if ( apt_id.length() > 0 ) { - // we have just finished reading and airport record. - // process the info - gen_base(average, perimeter, tile); - } - - FG_LOG( FG_TERRAIN, FG_INFO, "Reading airport record" ); - in >> apt_id; - apt_name = ""; - i = 1; - avex = avey = avez = 0.0; - perimeter.erase( perimeter.begin(), perimeter.end() ); - // skip to end of line. - while ( in.get(c) && c != '\n' ) { - apt_name += c; - } - FG_LOG( FG_TERRAIN, FG_INFO, - "\tID = " << apt_id << " Name = " << apt_name ); - } else if ( token == "p" ) { - // airport area bounding polygon coordinate. These - // specify a convex hull that should already have been cut - // out of the base terrain. The points are given in - // counter clockwise order and are specified in lon/lat - // degrees. - in >> p; - avex += tile->nodes[i][0]; - avey += tile->nodes[i][1]; - avez += tile->nodes[i][2]; - perimeter.push_back(p); - ++i; - } else if ( token == "r" ) { - // runway record - // skip for now - while ( in.get(c) && c != '\n' ); - } - - in >> skipcomment; - } - - if ( apt_id.length() > 0 ) { - // we have just finished reading and airport record. - // process the info - size = perimeter.size(); - average = Point3D( avex / (double)size + tile->center.x(), - avey / (double)size + tile->center.y(), - avez / (double)size + tile->center.z() ); - - gen_base(average, perimeter, tile); - } - - return 1; -} - - diff --git a/src/Airports/genapt.hxx b/src/Airports/genapt.hxx deleted file mode 100644 index 2092a36c0..000000000 --- a/src/Airports/genapt.hxx +++ /dev/null @@ -1,65 +0,0 @@ -// -// getapt.hxx -- generate airport scenery from the given definition file -// -// Written by Curtis Olson, started September 1998. -// -// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// $Id$ - - -#ifndef _GENAPT_HXX -#define _GENAPT_HXX - - -#ifndef __cplusplus -# error This library requires C++ -#endif - - -#include - -#include STL_STRING -#include - -#ifdef __BORLANDC__ -# define exception c_exception -#endif - -#include - -FG_USING_STD(string); -FG_USING_STD(set); - - -// maximum size of airport perimeter structure, even for complex -// airports such as KORD this number is typically not very big. -#define MAX_PERIMETER 20 - -// name of the material to use for the airport base -#define APT_BASE_MATERIAL "grass" - - -// Load a .apt file and register the GL fragments with the -// corresponding tile -int -fgAptGenerate(const string& path, FGTileEntry *tile); - - -#endif /* _AIRPORTS_HXX */ - - diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 2c4695402..198532724 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -62,7 +62,6 @@ fgfs_LDADD = \ $(top_builddir)/src/Airports/libAirports.a \ $(NETWORK_LIBS) \ $(top_builddir)/src/Objects/libObjects.a \ - $(top_builddir)/src/Clouds/libClouds.a \ $(top_builddir)/src/Time/libTime.a \ $(WEATHER_LIBS) \ $(top_builddir)/src/Sky/libSky.a \ diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 7ef96dd4c..e73b39fbb 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -273,9 +274,18 @@ bool fgInitSubsystems( void ) { // set the initial position fgInitPosition(); + // Initialize the material property lib + FGPath mpath( current_options.get_fg_root() ); + mpath.append( "materials" ); + if ( material_lib.load( mpath.str() ) ) { + } else { + FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" ); + exit(-1); + } + // Initialize the Scenery Management subsystem if ( fgSceneryInit() ) { - // Scenery initialized ok. + // Material lib initialized ok. } else { FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" ); exit(-1); diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index 4e6b61761..eff00308b 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include