]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Constant-speed props were seeking to engine speed, not prop speed.
[flightgear.git] / src / Main / main.cxx
index 0085984eae6ea2b69e01d6af4430de9c9c71db31..83d3add39904a22f5f6f4a54b2d44bf119b7599d 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started May 1997.
 //
-// Copyright (C) 1997 - 2002  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 1997 - 2002  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 
 #include <Include/general.hxx>
 #include <Cockpit/cockpit.hxx>
-#include <Cockpit/radiostack.hxx>
 #include <Cockpit/hud.hxx>
 #include <Model/panelnode.hxx>
 #include <Model/modelmgr.hxx>
 #include <Model/acmodel.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
+#include <Sound/beacon.hxx>
+#include <Sound/morse.hxx>
 #include <FDM/flight.hxx>
 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
-#include <FDM/ADA.hxx>
+// #include <FDM/ADA.hxx>
 #include <ATC/ATCdisplay.hxx>
 #include <ATC/ATCmgr.hxx>
 #include <ATC/AIMgr.hxx>
 #include <Environment/environment_mgr.hxx>
 #include <GUI/new_gui.hxx>
 
+#ifdef FG_MPLAYER_AS
+#include <MultiPlayer/multiplaytxmgr.hxx>
+#include <MultiPlayer/multiplayrxmgr.hxx>
+#endif
+
+
 
 #include "fg_commands.hxx"
 #include "fg_io.hxx"
@@ -89,6 +96,7 @@
 
 static double real_delta_time_sec = 0.0;
 double delta_time_sec = 0.0;
+extern float init_volume;
 
 
 #ifdef macintosh
@@ -104,7 +112,6 @@ FGGeneral general;
 int idle_state = 0;
 long global_multi_loop;
 
-
 SGTimeStamp last_time_stamp;
 SGTimeStamp current_time_stamp;
 
@@ -120,8 +127,8 @@ extern int _bootstrap_OSInit;
 void fgUpdateTimeDepCalcs() {
     static bool inited = false;
 
-    static const SGPropertyNode *replay_master
-        = fgGetNode( "/sim/freeze/replay", true );
+    static const SGPropertyNode *replay_state
+        = fgGetNode( "/sim/freeze/replay-state", true );
     static SGPropertyNode *replay_time
         = fgGetNode( "/sim/replay/time", true );
     // static const SGPropertyNode *replay_end_time
@@ -155,15 +162,21 @@ void fgUpdateTimeDepCalcs() {
             inited = true;
         }
 
-        if ( ! replay_master->getBoolValue() ) {
+        if ( replay_state->getIntValue() == 0 ) {
+           // replay off, run fdm
             cur_fdm_state->update( delta_time_sec );
         } else {
             FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
             r->replay( replay_time->getDoubleValue() );
-            replay_time->setDoubleValue( replay_time->getDoubleValue()
-                                         + ( delta_time_sec
-                                             * fgGetInt("/sim/speed-up") ) );
-        }
+           if ( replay_state->getIntValue() == 1 ) {
+                // normal playback
+                replay_time->setDoubleValue( replay_time->getDoubleValue()
+                                             + ( delta_time_sec
+                                               * fgGetInt("/sim/speed-up") ) );
+           } else if ( replay_state->getIntValue() == 2 ) {
+               // paused playback (don't advance replay time)
+           }
+       }
     } else {
         // do nothing, fdm isn't inited yet
     }
@@ -179,8 +192,6 @@ void fgUpdateTimeDepCalcs() {
                                   globals->get_time_params()->getLst(),
                                   cur_fdm_state->get_Latitude() );
 
-    // Update radio stack model
-    current_radiostack->update(delta_time_sec);
 }
 
 
@@ -208,10 +219,8 @@ static void fgMainLoop( void ) {
         = fgGetNode("/sim/freeze/clock", true);
     static const SGPropertyNode *cur_time_override
         = fgGetNode("/sim/time/cur-time-override", true);
-    // static const SGPropertyNode *replay_master
-    //     = fgGetNode("/sim/freeze/replay", true);
 
-    SGCloudLayer::enable_bump_mapping = fgGetBool("/sim/rendering/bump-mapping",true);
+    SGCloudLayer::enable_bump_mapping = fgGetBool("/sim/rendering/bump-mapping");
 
     // Update the elapsed time.
     static bool first_time = true;
@@ -235,6 +244,18 @@ static void fgMainLoop( void ) {
 
     real_delta_time_sec
         = double(current_time_stamp - last_time_stamp) / 1000000.0;
+    // round the real time down to a multiple of 1/model-hz.
+    // this way all systems are updated the _same_ amount of dt.
+    {
+      static double rem = 0.0;
+      real_delta_time_sec += rem;
+      double hz = model_hz;
+      double nit = floor(real_delta_time_sec*hz);
+      rem = real_delta_time_sec - nit/hz;
+      real_delta_time_sec = nit/hz;
+    }
+
+
     if ( clock_freeze->getBoolValue() ) {
         delta_time_sec = 0;
     } else {
@@ -377,6 +398,11 @@ static void fgMainLoop( void ) {
     if (fgGetBool("/sim/ai-traffic/enabled"))
         globals->get_AI_mgr()->update(delta_time_sec);
 
+#ifdef FG_MPLAYER_AS
+    // Update any multiplayer models
+    globals->get_multiplayer_rx_mgr()->Update();
+#endif
+
     // Run flight model
 
     // Calculate model iterations needed for next frame
@@ -529,6 +555,8 @@ static void fgMainLoop( void ) {
 
     if (!scenery_loaded && globals->get_tile_mgr()->all_queues_empty() && cur_fdm_state->get_inited()) {
         fgSetBool("sim/sceneryloaded",true);
+        fgSetFloat("/sim/sound/volume", init_volume);
+        globals->get_soundmgr()->set_volume(init_volume);
     }
 
     if (fgGetBool("/sim/rendering/specular-highlight")) {
@@ -556,8 +584,6 @@ static void fgIdleFunction ( void ) {
     // printf("idle state == %d\n", idle_state);
 
     if ( idle_state == 0 ) {
-        fgSetBool("sim/initialised", false);
-
         // Initialize the splash screen right away
         if ( fgGetBool("/sim/startup/splash-screen") ) {
             fgSplashInit(fgGetString("/sim/startup/splash-texture"));
@@ -634,14 +660,13 @@ static void fgIdleFunction ( void ) {
 
         SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
         globals->get_renderer()->resize( fgGetInt("/sim/startup/xsize"),
-               fgGetInt("/sim/startup/ysize") );
+                                         fgGetInt("/sim/startup/ysize") );
 
     } 
 
     if ( idle_state == 1000 ) {
         // We've finished all our initialization steps, from now on we
         // run the main loop.
-        fgSetBool("sim/initialised",true);
         fgSetBool("sim/sceneryloaded",false);
 
         fgRegisterIdleHandler(fgMainLoop);
@@ -694,7 +719,7 @@ bool fgMainInit( int argc, char **argv ) {
     fgInitFGRoot(argc, argv);
 
     // Check for the correct base package version
-    static char required_version[] = "0.9.6";
+    static char required_version[] = "0.9.8";
     string base_version = fgBasePackageVersion();
     if ( !(base_version == required_version) ) {
         // tell the operator how to use this application
@@ -711,6 +736,8 @@ bool fgMainInit( int argc, char **argv ) {
         exit(-1);
     }
 
+    sgUseDisplayList = fgGetBool( "/sim/rendering/use-display-list", true );
+
     // Initialize the Aircraft directory to "" (UIUC)
     aircraft_dir = "";
 
@@ -731,9 +758,9 @@ bool fgMainInit( int argc, char **argv ) {
     _bootstrap_OSInit++;
 #endif
 
-    fgRegisterWindowResizeHandler( fgReshape );
-    fgRegisterIdleHandler( fgIdleFunction );
-    fgRegisterDrawHandler( fgRenderFrame );
+    fgRegisterWindowResizeHandler( &FGRenderer::resize );
+    fgRegisterIdleHandler( &fgIdleFunction );
+    fgRegisterDrawHandler( &FGRenderer::update );
 
 #ifdef FG_ENABLE_MULTIPASS_CLOUDS
     bool get_stencil_buffer = true;
@@ -927,13 +954,8 @@ bool fgMainInit( int argc, char **argv ) {
     // build our custom render states
     globals->get_renderer()->build_states();
 
-    try {
-        // pass control off to the master event handler
-        fgOSMainLoop();
-    } catch (...) {
-        SG_LOG( SG_ALL, SG_ALERT,
-            "Unknown exception in the main loop. Aborting..." );
-    }
+    // pass control off to the master event handler
+    fgOSMainLoop();
 
     // we never actually get here ... but to avoid compiler warnings,
     // etc.