]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/bootstrap.cxx
Make sound audiable not until after the scenery is loaded.
[flightgear.git] / src / Main / bootstrap.cxx
index 4f12ad1eedbbd4c5e72d27de67e8df6850217557..5f2b24a54f149ee568cdf07996e26e331dcd64a5 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
 #endif
 
 #include <stdlib.h>
+#include <stdio.h>
 
 #include <simgear/compiler.h>
-#include <simgear/misc/exception.hxx>
+#include <simgear/structure/exception.hxx>
 #include <simgear/debug/logstream.hxx>
 
 #include STL_IOSTREAM
@@ -41,6 +42,7 @@ SG_USING_STD(cerr);
 SG_USING_STD(endl);
 
 #include "main.hxx"
+#include "globals.hxx"
 
 
 #ifdef HAVE_WINDOWS_H
@@ -48,12 +50,14 @@ SG_USING_STD(endl);
 #  include <float.h>
 #endif
 
-#include GLUT_H
+#include "fg_os.hxx"
 
 #ifdef macintosh
 #  include <console.h>         // -dw- for command line dialog
 #endif
 
+// foreward declaration.
+void fgExitCleanup();
 
 #if defined(__linux__) && defined(__i386__)
 
@@ -101,14 +105,54 @@ extern "C" {
 
 #endif
 
+#ifdef _MSC_VER
+int main ( int argc, char **argv );
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+                             LPSTR lpCmdLine, int nCmdShow) {
+
+  main( __argc, __argv );
+}
+#endif
+
+#if defined( sgi )
+#include <sys/fpu.h>
+
+/*
+    set the special "flush zero" bit (FS, bit 24) in the Control Status
+    Register of the FPU of R4k and beyond so that the result of any
+    underflowing operation will be clamped to zero, and no exception of
+    any kind will be generated on the CPU.  This has no effect on an
+    R3000.
+
+    the FS bit is inherited by processes fork()ed out of this one,
+    but it is not inherited across an exec().  so anytime you exec()
+    a process, you must re-set the FS bit in that process.
+  */
+void flush_fpe(void)
+{
+    union fpc_csr f;
+    f.fc_word = get_fpc_csr();
+    f.fc_struct.flush = 1;
+    set_fpc_csr(f.fc_word);
+}
+#endif
+
+int _bootstrap_OSInit;
+
 // Main entry point; catch any exceptions that have made it this far.
 int main ( int argc, char **argv ) {
 
+    _bootstrap_OSInit = 0;
+
     // Enable floating-point exceptions for Linux/x86
 #if defined(__linux__) && defined(__i386__)
     initFPE();
 #endif
 
+#if defined(sgi)
+    flush_fpe();
+#endif
+
     // Enable floating-point exceptions for Windows
 #if defined( _MSC_VER ) && defined( DEBUG )
     // Christian, we should document what this does
@@ -120,11 +164,12 @@ int main ( int argc, char **argv ) {
 #endif
 
     // Keyboard focus hack
-#ifdef __APPLE__
+#if defined(__APPLE__) && !defined(OSX_BUNDLE)
     {
       PSN psn;
 
-      glutInit (&argc, argv);
+      fgOSInit (&argc, argv);
+      _bootstrap_OSInit++;
 
       CPSGetCurrentProcess(&psn);
       CPSSetProcessName(&psn, "FlightGear");
@@ -136,6 +181,7 @@ int main ( int argc, char **argv ) {
     // FIXME: add other, more specific
     // exceptions.
     try {
+        atexit(fgExitCleanup);
         fgMainInit(argc, argv);
     } catch (sg_throwable &t) {
                             // We must use cerr rather than
@@ -143,10 +189,22 @@ int main ( int argc, char **argv ) {
                             // disabled.
         cerr << "Fatal error: " << t.getFormattedMessage()
              << "\n (received from " << t.getOrigin() << ')' << endl;
-        exit(1);
+    } catch (...) {
+        cerr << "Unknown exception in the main loop. Aborting..." << endl;
+        perror("Possible cause");
     }
 
     return 0;
 }
 
+// do some clean up on exit.  Specifically we want to call alutExit()
+// which happens in the sound manager destructor.
+void fgExitCleanup() {
+
+    if (_bootstrap_OSInit != 0)
+        fgSetMouseCursor(MOUSE_CURSOR_POINTER);
+
+    if (globals)
+        delete globals;
+}