diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx index 6edbd6ca5..b57fec113 100644 --- a/src/Environment/environment_mgr.cxx +++ b/src/Environment/environment_mgr.cxx @@ -23,6 +23,7 @@ #include #include +#include
#include
#include @@ -30,8 +31,6 @@ #include "environment_ctrl.hxx" #include "environment_mgr.hxx" -extern SGSky *thesky; // FIXME: from main.cxx - FGEnvironmentMgr::FGEnvironmentMgr () : _environment(new FGEnvironment), diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index c4d1a05f2..42272e865 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -42,6 +42,7 @@ #include #include +#include
#include
#include
@@ -51,10 +52,6 @@ #include "preset_dlg.hxx" -// main.cxx hack, should come from an include someplace -extern void fgInitVisuals( void ); -extern void fgRenderFrame( void ); - extern void initDialog (void); extern void mkDialogInit (void); extern void ConfirmExitDialogInit(void); diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index a9f4277a2..5f56ac7c7 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -73,6 +73,7 @@ #include #include #include +#include
#include
#include
#include
@@ -98,10 +99,6 @@ SG_USING_STD(string); SG_USING_STD(cout); -// main.cxx hack, should come from an include someplace -extern void fgInitVisuals( void ); -extern void fgRenderFrame( void ); - extern void fgHUDalphaAdjust( puObject * ); // from cockpit.cxx diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 9981ded31..52ed9d743 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -16,7 +16,6 @@ else NETWORK_LIBS = endif - if WITH_THREADS THREAD_LIBS = -lsgthreads $(thread_LIBS) else @@ -45,10 +44,12 @@ bin_PROGRAMS = fgfs noinst_SCRIPTS = runfgfs.bat runfgfs +noinst_LIBRARIES = libMain.a + # bin_SCRIPTS = runfgfs -fgfs_SOURCES = \ - main.cxx \ +libMain_a_SOURCES = \ + main.cxx main.hxx \ fg_commands.cxx fg_commands.hxx \ fg_init.cxx fg_init.hxx \ fg_io.cxx fg_io.hxx \ @@ -62,7 +63,10 @@ fgfs_SOURCES = \ viewer.cxx viewer.hxx \ viewmgr.cxx viewmgr.hxx +fgfs_SOURCES = bootstrap.cxx + fgfs_LDADD = \ + $(top_builddir)/src/Main/libMain.a \ $(top_builddir)/src/Aircraft/libAircraft.a \ $(top_builddir)/src/ATC/libATC.a \ $(top_builddir)/src/Autopilot/libAutopilot.a \ diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx new file mode 100644 index 000000000..cfa2178f4 --- /dev/null +++ b/src/Main/bootstrap.cxx @@ -0,0 +1,151 @@ +// bootstrap.cxx -- bootstrap routines: main() +// +// Written by Curtis Olson, started May 1997. +// +// Copyright (C) 1997 - 2002 Curtis L. Olson - curt@flightgear.org +// +// 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$ + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#if defined(__linux__) && defined(__i386__) +# include +# include +#endif + +#include + +#include +#include + +#include STL_IOSTREAM +SG_USING_STD(cerr); +SG_USING_STD(endl); + +#include "main.hxx" + + +#ifdef HAVE_WINDOWS_H +# include +# include +#endif + +#include GLUT_H + +#ifdef macintosh +# include // -dw- for command line dialog +#endif + + +#if defined(__linux__) && defined(__i386__) + +static void handleFPE (int); + +static void +initFPE () +{ + fpu_control_t fpe_flags = 0; + _FPU_GETCW(fpe_flags); +// fpe_flags &= ~_FPU_MASK_IM; // invalid operation +// fpe_flags &= ~_FPU_MASK_DM; // denormalized operand +// fpe_flags &= ~_FPU_MASK_ZM; // zero-divide +// fpe_flags &= ~_FPU_MASK_OM; // overflow +// fpe_flags &= ~_FPU_MASK_UM; // underflow +// fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result) + _FPU_SETCW(fpe_flags); + signal(SIGFPE, handleFPE); +} + +static void +handleFPE (int num) +{ + initFPE(); + SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)"); +} +#endif + +#ifdef __APPLE__ + +typedef struct +{ + int lo; + int hi; +} PSN; + +extern "C" { + short CPSGetCurrentProcess(PSN *psn); + short CPSSetProcessName (PSN *psn, char *processname); + short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5); + short CPSSetFrontProcess(PSN *psn); +}; + +#define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103) + +#endif + +// Main entry point; catch any exceptions that have made it this far. +int main ( int argc, char **argv ) { + + // Enable floating-point exceptions for Linux/x86 +#if defined(__linux__) && defined(__i386__) + initFPE(); +#endif + + // Enable floating-point exceptions for Windows +#if defined( _MSC_VER ) && defined( DEBUG ) + // Christian, we should document what this does + _control87( _EM_INEXACT, _MCW_EM ); +#endif + +#if defined( HAVE_BC5PLUS ) + _control87(MCW_EM, MCW_EM); /* defined in float.h */ +#endif + + // Keyboard focus hack +#ifdef __APPLE__ + { + PSN psn; + + glutInit (&argc, argv); + + CPSGetCurrentProcess(&psn); + CPSSetProcessName(&psn, "FlightGear"); + CPSEnableFG(&psn); + CPSSetFrontProcess(&psn); + } +#endif + + // FIXME: add other, more specific + // exceptions. + try { + fgMainInit(argc, argv); + } catch (sg_throwable &t) { + // We must use cerr rather than + // logging, since logging may be + // disabled. + cerr << "Fatal error: " << t.getFormattedMessage() + << "\n (received from " << t.getOrigin() << ')' << endl; + exit(1); + } + + return 0; +} + + diff --git a/src/Main/main.cxx b/src/Main/main.cxx index d557d237d..7d0026bce 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -25,24 +25,13 @@ # include #endif +#include + #if defined(__linux__) && defined(__i386__) # include # include #endif -#include - -#include STL_IOSTREAM -SG_USING_STD(cerr); -SG_USING_STD(endl); - -#include -#include -#include -#include - -#include - #ifdef SG_MATH_EXCEPTION_CLASH # include #endif @@ -52,65 +41,53 @@ SG_USING_STD(endl); # include #endif -#include GLUT_H - -#include -#include // for strcmp() -#include - -#ifdef HAVE_STDLIB_H -# include -#endif - -#ifdef HAVE_SYS_STAT_H -# include // for stat() -#endif - -#ifdef HAVE_UNISTD_H -# include // for stat() -#endif - -#include -#include -#include #include +#include -#include // for VERSION -#include -#include -#include -#include +#include #include +#include +#include +#include #include -#include -#include +#include +#include +#include +#include #include + #ifdef FG_USE_CLOUDS_3D # include # include #endif -#include -#include #include - +#include +#include