]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Working on putting engine data on "the bus"
[flightgear.git] / src / Main / main.cxx
index f49f3373e051e5a3919335d6b8a3b878ea1bb23d..987eb13e5b0e89ff2e10e43a26286777c8663bd0 100644 (file)
@@ -21,7 +21,8 @@
 // $Id$
 
 
-#define MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
+#define USE_NEW_ENGINE_CODE
+#undef MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
 
 
 #ifdef HAVE_CONFIG_H
@@ -66,7 +67,6 @@
 
 #include <simgear/constants.h>  // for VERSION
 #include <simgear/debug/logstream.hxx>
-#include <simgear/math/fg_geodesy.hxx>
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/fg_random.h>
 #include <simgear/misc/fgpath.hxx>
 
 
 // -dw- use custom sioux settings so I can see output window
-#ifdef MACOS
+#ifdef macintosh
 #  ifndef FG_NDEBUG
 #    include <sioux.h> // settings for output window
 #  endif
@@ -130,6 +130,9 @@ FGGeneral general;
 static int idle_state = 0;
 static int global_multi_loop;
 
+// attempt to avoid a large bounce at startup
+static bool initial_freeze = true;
+
 // Another hack
 int use_signals = 0;
 
@@ -617,7 +620,7 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) {
        multi_loop = 1;
     }
 
-    if ( !globals->get_freeze() ) {
+    if ( !globals->get_freeze() && !initial_freeze ) {
        // run Autopilot system
        current_autopilot->run();
 
@@ -633,6 +636,10 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) {
        //              fdm_state, 0, remainder );
        cur_fdm_state->update( 0 );
        FGSteam::update( 0 );
+
+       if ( global_tile_mgr.queue_size() == 0 ) {
+           initial_freeze = false;
+       }
     }
 
     fdm_list.push_back( *cur_fdm_state );
@@ -874,7 +881,7 @@ static void fgMainLoop( void ) {
        }
     }
 
-#if ! defined( MACOS )
+#if ! defined( macintosh )
     // Do any I/O channel work that might need to be done
     fgIOProcess();
 #endif
@@ -890,7 +897,7 @@ static void fgMainLoop( void ) {
 #ifdef ENABLE_AUDIO_SUPPORT
     if ( current_options.get_sound() && !audio_sched->not_working() ) {
 
-#   ifdef MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
+#   if defined(MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO)
 
        static double kts_to_fts = NM_TO_METER * METER_TO_FEET / 3600.0;
 
@@ -906,7 +913,7 @@ static void fgMainLoop( void ) {
 
        double pitch = log((controls.get_throttle(0) * 14.0) + 1.0);
        //fprintf(stderr, "pitch1: %f ", pitch);
-       // if (controls.get_throttle(0) > 0.0 || 
+       // if (controls.get_throttle(0) > 0.0 ||
        //     cur_fdm_state->get_V_calibrated_kts() > 40.0) {
 
        //fprintf(stderr, "rel_wind: %f ", cur_fdm_state->get_V_calibrated_kts());
@@ -938,13 +945,45 @@ static void fgMainLoop( void ) {
        // }
        // fprintf(stderr, "pitch4: %f\n", pitch);
 
-       double volume = controls.get_throttle(0) * 1.15 + 0.3 +
+       double volume = controls.get_throttle(0) * 0.1 + 0.3 +
            log(cur_fdm_state->get_V_calibrated_kts() * kts_to_fts + 1.0)/14.0;
+       if ( volume > 1.0 ) { volume = 1.0; }
+
        // fprintf(stderr, "volume: %f\n", volume);
 
        pitch_envelope.setStep  ( 0, 0.01, pitch );
        volume_envelope.setStep ( 0, 0.01, volume );
 
+#   elif defined(USE_NEW_ENGINE_CODE)
+
+       // pitch corresponds to rpm
+       // volume corresponds to manifold pressure
+
+       double rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0;
+       cout << "rpm = " << cur_fdm_state->get_engine(0)->get_RPM() << endl;
+
+       double pitch = 0.3 + rpm_factor * 3.0;
+       
+       // don't run at absurdly slow rates -- not realistic
+       // and sounds bad to boot.  :-)
+       if (pitch < 0.7) { pitch = 0.7; }
+       if (pitch > 5.0) { pitch = 5.0; }
+       cout << "pitch = " << pitch << endl;
+
+       double mp_factor =
+           cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 28;
+       cout << "mp = " << cur_fdm_state->get_engine(0)->get_Manifold_Pressure()
+            << endl;
+
+       double volume = mp_factor;
+
+       if ( volume < 0.3 ) { volume = 0.3; }
+       if ( volume > 2.0 ) { volume = 2.0; }
+       cout << "volume = " << volume << endl;
+
+       pitch_envelope.setStep  ( 0, 0.01, pitch );
+       volume_envelope.setStep ( 0, 0.01, volume );
+
 #   else
 
        double param = controls.get_throttle( 0 ) * 2.0 + 1.0;
@@ -1152,7 +1191,7 @@ void fgReshape( int width, int height ) {
 // Initialize GLUT and define a main window
 int fgGlutInit( int *argc, char **argv ) {
 
-#if !defined( MACOS )
+#if !defined( macintosh )
     // GLUT will extract all glut specific options so later on we only
     // need wory about our own.
     glutInit(argc, argv);
@@ -1194,8 +1233,11 @@ int fgGlutInit( int *argc, char **argv ) {
     general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
     general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
     general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
-
+    int tmp;
+    glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
+    general.set_glMaxTexSize( tmp );
     FG_LOG ( FG_GENERAL, FG_INFO, general.get_glRenderer() );
+    FG_LOG ( FG_GENERAL, FG_INFO, "Max texture size = " << tmp );
 
 #if 0
     // try to determine if we should adjust the initial default
@@ -1265,7 +1307,7 @@ int fgGlutInitEvents( void ) {
 // Main ...
 int main( int argc, char **argv ) {
 
-#if defined( MACOS )
+#if defined( macintosh )
     freopen ("stdout.txt", "w", stdout );
     freopen ("stderr.txt", "w", stderr );
     argc = ccommand( &argv );
@@ -1283,7 +1325,22 @@ int main( int argc, char **argv ) {
     // seed the random number generater
     fg_srandom();
 
-    aircraft_dir = ""; // Initialize the Aircraft directory to "" (UIUC)
+    // Read global preferences from $FG_ROOT/preferences.xml
+    // FIXME: this will *not* work with an --fg_root option because
+    // we have not read the command-line yet.  Suggestions?
+
+    FGPath props_path(current_options.get_fg_root());
+    props_path.append("preferences.xml");
+    FG_LOG(FG_INPUT, FG_INFO, "Reading global preferences");
+    if (!readPropertyList(props_path.str(), &current_properties)) {
+      FG_LOG(FG_INPUT, FG_ALERT, "Failed to read global preferences from "
+            << props_path.str());
+    } else {
+      FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences");
+    }
+
+    // Initialize the Aircraft directory to "" (UIUC)
+    aircraft_dir = "";
 
     // needs to happen before we parse command line options
     globals = new FGGlobals;