| 1 |
// OSRail -- a network enabled railroad operations simulator and utilities |
|---|
| 2 |
// Copyright (C) 2007,2008 Samuel E. Henley sehenley@comcast.net |
|---|
| 3 |
// |
|---|
| 4 |
// This program is free software; you can redistribute it and/or modify |
|---|
| 5 |
// it under the terms of the GNU General Public License as published by |
|---|
| 6 |
// the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 |
// (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
// This program is distributed in the hope that it will be useful, |
|---|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
// GNU General Public License for more details. |
|---|
| 13 |
// |
|---|
| 14 |
// You should have received a copy of the GNU General Public License along |
|---|
| 15 |
// with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 16 |
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 17 |
// |
|---|
| 18 |
/// \file |
|---|
| 19 |
/// Main simulator program file, commandline and message loop. |
|---|
| 20 |
|
|---|
| 21 |
// Pre-Compiled Header for Simulator |
|---|
| 22 |
#include "presimulator.h" |
|---|
| 23 |
|
|---|
| 24 |
/// \addtogroup simulator "Simulator" |
|---|
| 25 |
/// @{ |
|---|
| 26 |
/// \addtogroup gameloop "Game Loop" |
|---|
| 27 |
/// @{ |
|---|
| 28 |
|
|---|
| 29 |
// \page simulatorcommandline Simulator Commandline Arguments. |
|---|
| 30 |
// \par Commandline arguments |
|---|
| 31 |
// \par Version |
|---|
| 32 |
// - -v print simulator version |
|---|
| 33 |
// - -version |
|---|
| 34 |
// \par Help |
|---|
| 35 |
// - -h print help message |
|---|
| 36 |
// - --help |
|---|
| 37 |
// \par Select Render System |
|---|
| 38 |
// - -r "<name>" select render system |
|---|
| 39 |
// - --renderer "<name>" |
|---|
| 40 |
// \par Window Size |
|---|
| 41 |
// - -w ["<x>x<y>"] select window mode, optional size, default 1024x768 |
|---|
| 42 |
// - -window ["<x>x<y>"] |
|---|
| 43 |
// \par Fullscreen Mode |
|---|
| 44 |
// - -f ["<x>x<y>"] select fullscreen mode, optional size, default 1024x768 |
|---|
| 45 |
// - -fullscreen ["<x>x<y>"] |
|---|
| 46 |
// \par Display Depth |
|---|
| 47 |
// - -d select display depth, fullscreen mode only |
|---|
| 48 |
// - -depth "<16|24|32>" |
|---|
| 49 |
// \par Shared Memory (IPC) Internal |
|---|
| 50 |
// - -s "name" internal - shared memory for console |
|---|
| 51 |
// - --shared-memory "<name>" |
|---|
| 52 |
// \par Resource Directory |
|---|
| 53 |
// - -x "<path>" simulator resource directory |
|---|
| 54 |
// - --directory "<path>" |
|---|
| 55 |
// \par Ogre Configure File |
|---|
| 56 |
// - -c "<path>" simulator ogre configure file |
|---|
| 57 |
// - --configure "<path>" |
|---|
| 58 |
// \par Ogre Log File |
|---|
| 59 |
// - -l "<path>" simulator log file |
|---|
| 60 |
// - --log "<path>" |
|---|
| 61 |
|
|---|
| 62 |
static const char version[] = "$Id$"; |
|---|
| 63 |
|
|---|
| 64 |
extern ISystem* createSystem(); |
|---|
| 65 |
|
|---|
| 66 |
#ifdef WIN32 |
|---|
| 67 |
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR commandline, int Show ) |
|---|
| 68 |
{ |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
#else //WIN32 (LINUX) |
|---|
| 72 |
int main( int argc, char* argv[] ) |
|---|
| 73 |
{ |
|---|
| 74 |
#endif //WIN32 |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
boost::shared_ptr<ISystem> simulator( createSystem() ); |
|---|
| 78 |
|
|---|
| 79 |
if( !simulator ) |
|---|
| 80 |
{ |
|---|
| 81 |
std::cerr << _("Error: Could not create simulator system program!") << std::endl; |
|---|
| 82 |
return 1; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
boost::program_options::variables_map map; |
|---|
| 86 |
|
|---|
| 87 |
boost::program_options::options_description visible( _("Visible Options") ); |
|---|
| 88 |
|
|---|
| 89 |
// /////////////////////// Process comand-line options /////////////////// |
|---|
| 90 |
try |
|---|
| 91 |
{ |
|---|
| 92 |
visible.add_options() |
|---|
| 93 |
( _("version,v"), _("print simulator version")) |
|---|
| 94 |
( _("help,h"), _("print help message")) |
|---|
| 95 |
( _("renderer,r"), _("select render system")) |
|---|
| 96 |
( _("window,w"), _("select window mode")) |
|---|
| 97 |
( _("fullscreen,f"), _("select fullscreen mode")) |
|---|
| 98 |
( _("directory,x"), _("simulator resource directory")) |
|---|
| 99 |
( _("configure,c"), _("simulator configure file")) |
|---|
| 100 |
( _("log,l"), _("simulator log file")); |
|---|
| 101 |
|
|---|
| 102 |
boost::program_options::options_description hidden( _("Hidden Options") ); |
|---|
| 103 |
hidden.add_options()( _("share,s"), _("Shared memory with comsole")); |
|---|
| 104 |
|
|---|
| 105 |
boost::program_options::options_description command( _("Command-line Options") ); |
|---|
| 106 |
command.add( hidden ).add( visible ); |
|---|
| 107 |
|
|---|
| 108 |
#ifdef WIN32 |
|---|
| 109 |
std::vector<String> args = boost::program_options::split_winmain( commandline ); |
|---|
| 110 |
store( boost::program_options::command_line_parser( args ).options( command ).run(), map ); |
|---|
| 111 |
#else //WIN32 (LINUX) |
|---|
| 112 |
store( boost::program_options::command_line_parser( argc, argv ).options( command ).run(), map ); |
|---|
| 113 |
#endif //WIN32 |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
if( map.count( _("window")) && map.count( _("fullscreen")) ) |
|---|
| 117 |
throw std::logic_error( String(_("Conflicting options window and fullscreen"))); |
|---|
| 118 |
|
|---|
| 119 |
/// \todo copy the command-line map to system(simulator) or put this in system |
|---|
| 120 |
/// and send the command-line to system. |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
} |
|---|
| 124 |
catch( std::exception& e ) |
|---|
| 125 |
{ |
|---|
| 126 |
std::string data = "STL Exception:, Commandline "; |
|---|
| 127 |
data += e.what(); |
|---|
| 128 |
data += ", Class: "; |
|---|
| 129 |
data += typeid( e ).name(); |
|---|
| 130 |
EXCEPTION( "Simulator", "Main", data.c_str() ); |
|---|
| 131 |
MESSAGE( "Simulator", "Main", "Exit Program - Error" ) |
|---|
| 132 |
return 1; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
if( map.count("help") != 0 ) |
|---|
| 136 |
{ |
|---|
| 137 |
std::cout << visible; |
|---|
| 138 |
return 0; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
if( map.count("version") != 0 ) |
|---|
| 142 |
{ |
|---|
| 143 |
std::cout << "Version 1.0"; |
|---|
| 144 |
return 0; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
simulator->setOptions( map ); |
|---|
| 148 |
|
|---|
| 149 |
// ////////////////////// Game Loop //////////////////////////// |
|---|
| 150 |
try |
|---|
| 151 |
{ |
|---|
| 152 |
/// Create window |
|---|
| 153 |
|
|---|
| 154 |
MESSAGE( "Simulator", "Main", "Starting Game Loop" ) |
|---|
| 155 |
|
|---|
| 156 |
/// Game Loop. |
|---|
| 157 |
simulator->startup(); |
|---|
| 158 |
// do { ASSERT( false, "Main", "Test continues Break" ); Sleep(1000); }while(true); |
|---|
| 159 |
|
|---|
| 160 |
do |
|---|
| 161 |
{ |
|---|
| 162 |
|
|---|
| 163 |
PROFILE_START( Simulator, GameLoop, main ) |
|---|
| 164 |
|
|---|
| 165 |
simulator->operator()(); |
|---|
| 166 |
|
|---|
| 167 |
PROFILE_STOP( Simulator, GameLoop, main ) |
|---|
| 168 |
|
|---|
| 169 |
}while( simulator->anyState() /*simulator->running()*/ ); |
|---|
| 170 |
|
|---|
| 171 |
MESSAGE( "Simulator", "Main", "Exit Program - Normal" ) |
|---|
| 172 |
|
|---|
| 173 |
return 0; |
|---|
| 174 |
} |
|---|
| 175 |
catch(Ogre::Exception& e) |
|---|
| 176 |
{ |
|---|
| 177 |
std::string data = "Ogre Exception: "; |
|---|
| 178 |
data += e.getDescription(); |
|---|
| 179 |
data += ", Class: "; |
|---|
| 180 |
data += typeid( e ).name(); |
|---|
| 181 |
EXCEPTION( "Simulator", "Main", data.c_str() ); |
|---|
| 182 |
} |
|---|
| 183 |
catch( std::exception& e ) |
|---|
| 184 |
{ |
|---|
| 185 |
std::string data = "STL Exception: "; |
|---|
| 186 |
data += e.what(); |
|---|
| 187 |
data += ", Class: "; |
|---|
| 188 |
data += typeid( e ).name(); |
|---|
| 189 |
EXCEPTION( "Simulator", "Main", data.c_str() ); |
|---|
| 190 |
} |
|---|
| 191 |
catch( ... ) |
|---|
| 192 |
{ |
|---|
| 193 |
std::string data = "Unknown Exception"; |
|---|
| 194 |
EXCEPTION( "Simulator", "Main", data.c_str() ); |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
MESSAGE( "Simulator", "Main", "Exit Program - Error" ) |
|---|
| 198 |
|
|---|
| 199 |
// ASSERT( false, "Simulator", "Main", "Test Break" ) |
|---|
| 200 |
|
|---|
| 201 |
/// Cleanup. |
|---|
| 202 |
return 1; |
|---|
| 203 |
|
|---|
| 204 |
} |
|---|
| 205 |
/// @} group gameloop |
|---|
| 206 |
/// @} group simulator |
|---|