1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
// main.cxx -- FlightGear Launch Control
//
// Written by Bernie Bright, started Oct 2002.
//
// Copyright (c) 2002 Bernie Bright - bbright@users.sourceforge.net
//
// 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 <config.h>
#endif
#include <string>
#include <cstring>
#include <FL/Fl.H>
#include <FL/filename.H>
#include <osgDB/Registry>
#include <simgear/scene/model/ModelRegistry.hxx>
#include <simgear/io/raw_socket.hxx>
#include <simgear/structure/OSGVersion.hxx>
#include "wizard.h"
#include "i18n.h"
std::string def_fg_exe = "/usr/games/fgfs";
std::string def_fg_root = "/usr/share/games/flightgear";
std::string def_fg_scenery = "/usr/share/games/flightgear/Scenery";
std::string def_ts_exe = "/usr/games/terrasync";
std::string version = "";
int def_ts_dir = -1;
static bool silent = false;
static bool fullscreen = false;
/**
* --fg-exe=<PATH>
* --fg-root=<DIR>
* --fg-scenery=<DIR>
*/
static int
parse_args( int, char** argv, int& i )
{
if (strcmp( argv[i], "--silent" ) == 0)
{
silent = true;
++i;
return 1;
}
else if (strncmp( argv[i], "--fg-exe=", 9 ) == 0)
{
def_fg_exe.assign( &argv[i][9] );
++i;
return 1;
}
else if (strncmp( argv[i], "--fg-root=", 10 ) == 0)
{
def_fg_root.assign( &argv[i][10] );
def_fg_scenery = def_fg_root;
def_fg_scenery += "/Scenery";
++i;
return 1;
}
else if (strncmp( argv[i], "--fg-scenery=", 13 ) == 0)
{
def_fg_scenery.assign( &argv[i][13] );
++i;
return 1;
}
else if (strcmp( argv[i], "--fullscreen" ) == 0 ||
strcmp( argv[i], "-f" ) == 0)
{
fullscreen = true;
++i;
return 1;
}
else if (strncmp( argv[i], "--ts-exe=", 9 ) == 0)
{
def_ts_exe.assign( &argv[i][9] );
++i;
return 1;
}
else if (strncmp( argv[i], "--ts-dir=", 9 ) == 0)
{
def_ts_dir = atoi( &argv[i][9] );
++i;
return 1;
}
else if (strncmp( argv[i], "--version=", 10 ) == 0)
{
version.assign( &argv[i][10] );
++i;
return 1;
}
return 0;
}
string
get_locale_directory( const char *argv0 )
{
#ifdef LOCALEDIR
SGPath localedir( LOCALEDIR );
if (localedir.exists())
return localedir.str();
#endif
SGPath path( argv0 );
path = path.dir();
if (path.file() == "bin")
{
SGPath path2 = path.dir();
path2.append( "share/locale" );
if (path2.exists() )
return path2.str();
}
path.append( "locale" );
return path.str();
}
int
main( int argc, char* argv[] )
{
//_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
simgear::Socket::initSockets();
setlocale( LC_ALL, "" );
string localedir = get_locale_directory( argv[0] );
bindtextdomain( PACKAGE, localedir.c_str() );
textdomain( PACKAGE );
osgDB::Registry* registry = osgDB::Registry::instance();
#if ( SG_OSG_VERSION >= 28003 && SG_OSG_VERSION < 29000 ) || SG_OSG_VERSION >= 29006
registry->setExpiryDelay( 0. );
#endif
osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options;
//int cacheOptions = osgDB::ReaderWriter::Options::CACHE_ALL;
//options->setObjectCacheHint((osgDB::ReaderWriter::Options::CacheHintOptions)cacheOptions);
registry->setOptions(options);
// Link with the ModelRegistry class to install the AC replacement loader
simgear::ModelRegistry::instance();
Fl::lock(); // initialize multithreading
int i = 0;
if (Fl::args( argc, argv, i, parse_args ) < argc)
{
Fl::fatal(_("Options are:\n --silent\n --fg-exe=<PATH>\n --fg-root=<DIR>\n --fg-scenery=<DIR>\n --ts-exe=<PATH>\n --ts-dir=#\n --version=<VERSION>\n -f, --fullscreen\n%s"), Fl::help );
}
if ( silent )
{
Fl_Preferences prefs( Fl_Preferences::SYSTEM, "flightgear.org", "fgrun" );
char abs_name[ FL_PATH_MAX ];
if ( !def_fg_exe.empty() )
{
fl_filename_absolute( abs_name, def_fg_exe.c_str() );
prefs.set( "fg_exe_init", abs_name );
prefs.set( "fg_exe", abs_name );
}
if ( !def_fg_root.empty() )
{
fl_filename_absolute( abs_name, def_fg_root.c_str() );
prefs.set( "fg_root_init", abs_name );
prefs.set( "fg_root", abs_name );
}
if ( !def_fg_scenery.empty() )
{
fl_filename_absolute( abs_name, def_fg_scenery.c_str() );
prefs.set( "fg_scenery_init", abs_name );
prefs.set( "fg_scenery", abs_name );
prefs.set( "ts_dir", 0 );
}
if ( !def_ts_exe.empty() )
{
fl_filename_absolute( abs_name, def_ts_exe.c_str() );
prefs.set( "ts_exe_init", abs_name );
prefs.set( "ts_exe", abs_name );
}
if ( def_ts_dir != -1 )
{
prefs.set( "ts_dir_init", def_ts_dir );
prefs.set( "ts_dir", def_ts_dir );
}
if ( !version.empty() )
{
int major, minor, patch;
char c1, c2;
std::istringstream iss(version);
iss >> major >> c1 >> minor >> c2 >> patch;
if (c1 == '.' && c2 == '.') {
prefs.set("version", major * 10000 + minor * 100 + patch);
}
}
return 0;
}
Fl::visual( FL_DOUBLE | FL_INDEX );
Wizard ui;
ui.init( fullscreen );
ui.show();
return Fl::run();
}
|