]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Moved random ground cover object management code (userdata.[ch]xx) over
[flightgear.git] / src / Main / main.cxx
index 6fd0c837fa96ee3800da7cabc2643e62cb492b48..32a6ed112b83bcd06d7eab3d02bef4d3dbb8614e 100644 (file)
@@ -77,6 +77,11 @@ SG_USING_STD(endl);
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/scene/material/matlib.hxx>
+#include <simgear/scene/model/animation.hxx>
+#include <simgear/scene/model/location.hxx>
+#include <simgear/scene/model/model.hxx>
+#include <simgear/scene/model/modellib.hxx>
 #ifdef FG_USE_CLOUDS_3D
 #  include <simgear/sky/clouds3d/SkySceneLoader.hpp>
 #  include <simgear/sky/clouds3d/SkyUtil.hpp>
@@ -102,10 +107,7 @@ SG_USING_STD(endl);
 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
 #include <GUI/gui.h>
 #include <Model/acmodel.hxx>
-#include <Model/loader.hxx>
-#include <Model/model.hxx>
 #include <Model/modelmgr.hxx>
-#include <Main/location.hxx>
 #include <Model/panelnode.hxx>
 #ifdef FG_NETWORK_OLK
 #include <NetworkOLK/network.h>
@@ -116,11 +118,9 @@ SG_USING_STD(endl);
 #include <MultiPlayer/multiplayrxmgr.hxx>
 #endif
 
-#include <Objects/matlib.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #ifdef ENABLE_AUDIO_SUPPORT
-#  include <Sound/soundmgr.hxx>
 #  include <Sound/fg_fx.hxx>
 #  include <Sound/morse.hxx>
 #endif
@@ -445,12 +445,12 @@ void fgRenderFrame() {
     // Process/manage pending events
     global_events.update( delta_time_sec );
 
-    static const SGPropertyNode *longitude
-        = fgGetNode("/position/longitude-deg");
-    static const SGPropertyNode *latitude
-        = fgGetNode("/position/latitude-deg");
-    static const SGPropertyNode *altitude
-        = fgGetNode("/position/altitude-ft");
+    // static const SGPropertyNode *longitude
+    //     = fgGetNode("/position/longitude-deg");
+    // static const SGPropertyNode *latitude
+    //     = fgGetNode("/position/latitude-deg");
+    // static const SGPropertyNode *altitude
+    //     = fgGetNode("/position/altitude-ft");
     static const SGPropertyNode *groundlevel_nearplane
         = fgGetNode("/sim/current-view/ground-level-nearplane-m");
 
@@ -497,6 +497,7 @@ void fgRenderFrame() {
         }
         // Keep resetting sim time while the sim is initializing
         globals->set_sim_time_sec( 0.0 );
+        SGAnimation::set_sim_time_sec( 0.0 );
     } else {
         // idle_state is now 1000 meaning we've finished all our
         // initializations and are running the main loop, so this will
@@ -590,38 +591,15 @@ void fgRenderFrame() {
                     "    sun_angle = " << cur_light_params.sun_angle
              << "    moon_angle = " << cur_light_params.moon_angle );
             */
-
-            // Some insane defaults.
-            static int init = 50;
-            static double sun_pos_angle = 9999.0;
-            static double sun_pos_rotation = 9999.0;
-            static float view_heading = 9999.0;
-            static float view_heading_offset = 9999.0;
-
-            if ((fabs(sun_pos_rotation - cur_light_params.sun_rotation) > 5e-3)
-                || (fabs(sun_pos_angle - cur_light_params.sun_angle) > 5e-3)
-                || (fabs(view_heading - current__view->getHeading_deg()) > 5e-3)
-                || (fabs(view_heading_offset
-                                - current__view->getHeadingOffset_deg()) > 5e-3)
-                || init || fgGetBool("/sim/rendering/debug"))
-            {
-                if ( init )
-                   init--;
-
-                sun_pos_angle = cur_light_params.sun_angle;
-                sun_pos_rotation = cur_light_params.sun_rotation;
-                view_heading = current__view->getHeading_deg ();
-                view_heading_offset = current__view->getHeadingOffset_deg();
-
-                thesky->repaint( cur_light_params.sky_color,
+            thesky->repaint( cur_light_params.sky_color,
                              cur_light_params.adj_fog_color,
+                             cur_light_params.cloud_color,
                              cur_light_params.sun_angle,
                              cur_light_params.moon_angle,
                              globals->get_ephem()->getNumPlanets(),
                              globals->get_ephem()->getPlanets(),
                              globals->get_ephem()->getNumStars(),
                              globals->get_ephem()->getStars() );
-            }
 
             /*
             SG_LOG( SG_GENERAL, SG_BULK,
@@ -1048,6 +1026,7 @@ static void fgMainLoop( void ) {
         delta_time_sec = 0;
     last_time_stamp = current_time_stamp;
     globals->inc_sim_time_sec( delta_time_sec );
+    SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
 
     static long remainder = 0;
     long elapsed;
@@ -1062,10 +1041,11 @@ static void fgMainLoop( void ) {
     SGTime *t = globals->get_time_params();
 
     sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") );
+    sglog().setLogLevels( SG_ALL, SG_INFO );
 
-    FGLocation * acmodel_location = 0;
+    SGLocation * acmodel_location = 0;
     if(cur_fdm_state->getACModel() != 0) {
-      acmodel_location = (FGLocation *)  cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
+      acmodel_location = (SGLocation *)  cur_fdm_state->getACModel()->get3DModel()->getSGLocation();
     }
 
     SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
@@ -1249,7 +1229,7 @@ static void fgMainLoop( void ) {
     globals->get_io()->update( delta_time_sec );
 
     // see if we need to load any deferred-load textures
-    material_lib.load_next_deferred();
+    globals->get_matlib()->load_next_deferred();
 
     // Run audio scheduler
 #ifdef ENABLE_AUDIO_SUPPORT
@@ -1271,14 +1251,14 @@ static void fgMainLoop( void ) {
 
     // update tile manager for FDM...
     // ...only if location is different than the viewer (to avoid duplicating effort)
-    if( acmodel_location != current_view->getFGLocation() ) {
+    if( acmodel_location != current_view->getSGLocation() ) {
       if( acmodel_location != 0 ) {
         globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
                                                  visibility_meters );
         globals->get_tile_mgr()->
             update( acmodel_location, visibility_meters,
-                    acmodel_location->get_absolute_view_pos() );
-        // save results of update in FGLocation for fdm...
+                    acmodel_location->get_absolute_view_pos(globals->get_scenery()->get_center()) );
+        // save results of update in SGLocation for fdm...
         if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
           acmodel_location->
               set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
@@ -1288,24 +1268,24 @@ static void fgMainLoop( void ) {
       }
     }
 
-    globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(),
+    globals->get_tile_mgr()->prep_ssg_nodes( current_view->getSGLocation(),
                                              visibility_meters );
     // update tile manager for view...
     // IMPORTANT!!! the tilemgr update for view location _must_ be done last 
     // after the FDM's until all of Flight Gear code references the viewer's location
     // for elevation instead of the "scenery's" current elevation.
-    FGLocation *view_location = globals->get_current_view()->getFGLocation();
+    SGLocation *view_location = globals->get_current_view()->getSGLocation();
     globals->get_tile_mgr()->update( view_location, visibility_meters,
                                      current_view->get_absolute_view_pos() );
-    // save results of update in FGLocation for fdm...
+    // save results of update in SGLocation for fdm...
     if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
-      current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
+      current_view->getSGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
     }
-    current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
+    current_view->getSGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
 
     // If fdm location is same as viewer's then we didn't do the update for fdm location 
-    //   above so we need to save the viewer results in the fdm FGLocation as well...
-    if( acmodel_location == current_view->getFGLocation() ) {
+    //   above so we need to save the viewer results in the fdm SGLocation as well...
+    if( acmodel_location == current_view->getSGLocation() ) {
       if( acmodel_location != 0 ) {
         if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
           acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
@@ -1701,33 +1681,36 @@ static bool fgMainInit( int argc, char **argv ) {
     SGPath modelpath( globals->get_fg_root() );
     ssgModelPath( (char *)modelpath.c_str() );
 
-    // Initialize the global scenery manager
-    globals->set_scenery( new FGScenery );
-    globals->get_scenery()->init();
-    globals->get_scenery()->bind();
-
-    // Initialize the global tile manager
-    globals->set_tile_mgr( new FGTileMgr );
-
     ////////////////////////////////////////////////////////////////////
     // Initialize the property-based built-in commands
     ////////////////////////////////////////////////////////////////////
     fgInitCommands();
 
     ////////////////////////////////////////////////////////////////////
-    // Initialize the general model subsystem.
+    // Initialize the material manager
     ////////////////////////////////////////////////////////////////////
+    globals->set_matlib( new SGMaterialLib );
 
-    globals->set_model_loader(new FGModelLoader);
-    globals->set_texture_loader(new FGTextureLoader);
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the general model subsystem.
+    ////////////////////////////////////////////////////////////////////
+    globals->set_model_lib(new SGModelLib);
     globals->set_model_mgr(new FGModelMgr);
     globals->get_model_mgr()->init();
     globals->get_model_mgr()->bind();
 
     ////////////////////////////////////////////////////////////////////
-    // Initialize the 3D aircraft model subsystem.
+    // Initialize the TG scenery subsystem.
     ////////////////////////////////////////////////////////////////////
+    globals->set_scenery( new FGScenery );
+    globals->get_scenery()->init();
+    globals->get_scenery()->bind();
+    globals->set_tile_mgr( new FGTileMgr );
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the 3D aircraft model subsystem (has a dependency on
+    // the scenery subsystem.)
+    ////////////////////////////////////////////////////////////////////
     globals->set_aircraft_model(new FGAircraftModel);
     globals->get_aircraft_model()->init();
     globals->get_aircraft_model()->bind();
@@ -1955,7 +1938,7 @@ void fgLoadDCS(void) {
 
                 if ( strcmp(obj_filename,"repeat") != 0) {
                     ship_obj =
-                        globals->get_model_loader()->load_model( obj_filename );
+                      globals->get_model_lib()->load_model( globals->get_fg_root(), obj_filename, globals->get_props(), globals->get_sim_time_sec() );
                 }
       
                 if ( ship_obj != NULL ) {
@@ -1976,11 +1959,11 @@ void fgLoadDCS(void) {
                             // temporary hack for deck lights - ultimately should move to PLib (when??)
                             //const char *extn = file_extension ( obj_filename ) ;
                             if ( objc == 1 ){
-                                ssgVertexArray *lights = new ssgVertexArray( 100 );
+                                // ssgVertexArray *lights = new ssgVertexArray( 100 );
                                ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
                                ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
                                ssgVertexArray *lightdir = new ssgVertexArray( 100 );
-                               int ltype[500], light_type;
+                               int ltype[500], light_type = 0;
                                static int ltcount = 0;
                                 string token;
                                sgVec3 rway_dir,rway_normal,lightpt;
@@ -2045,7 +2028,8 @@ void fgLoadDCS(void) {
                                                        if (in1.eof()) break;
                                                } 
                                        }  //while
-        
+
+#if 0        
                                        if ( lightpoints->getNum() ) {
                                                ssgBranch *lightpoints_branch;
                                                long int dummy = -999;
@@ -2064,6 +2048,7 @@ void fgLoadDCS(void) {
                                                lightpoints_transform->ref();
                                                globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
                                        } 
+#endif
                                } //if in1 
                 } //if objc
                             // end hack for deck lights
@@ -2191,7 +2176,7 @@ void fgUpdateDCS (void) {
 //             if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
 //             if (ref_elev < -0.51) sel = 0x30;
 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
-            dummy_tile->lightmaps_sequence->select(sel);
+            // dummy_tile->lightmaps_sequence->select(sel);
 
             sgVec3 up;
             sgCopyVec3 (up, ship_up);
@@ -2199,7 +2184,7 @@ void fgUpdateDCS (void) {
                     sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
             else
                     sgScaleVec3 (up, 4.0*ref_elev);
-            dummy_tile->ols_transform->setTransform(up);
+            // dummy_tile->ols_transform->setTransform(up);
             //cout << "ref_elev  " << ref_elev << endl;
         }
     // end hack for deck lights