Changeset 1653 for code/branches/gui/src/orxonox/Orxonox.cc
- Timestamp:
- Aug 5, 2008, 9:50:26 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/Orxonox.cc
r1646 r1653 112 112 , mode_(GameMode::GM_Unspecified) 113 113 , debugRefreshTime_(0.0f) 114 , ogre_(0)114 , graphicsEngine_(0) 115 115 , inputManager_(0) 116 116 , radar_(0) … … 157 157 delete inputManager_; 158 158 159 if (this-> ogre_)160 delete ogre_;159 if (this->graphicsEngine_) 160 delete graphicsEngine_; 161 161 162 162 if (network::Client::getSingleton()) … … 212 212 } 213 213 214 215 /** 216 * Starts the whole Game. 217 * @param path path to config (in home dir or something) 218 */ 219 void Orxonox::start() 220 { 221 #ifdef _DEBUG 222 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini"); 214 /** 215 @brief 216 Starts the whole Game. 217 @param path 218 path to config (in home dir or something) 219 */ 220 void Orxonox::start() 221 { 222 #if ORXONOX_DEBUG_MODE == 1 223 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox_d.ini"); 223 224 #else 224 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");225 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 225 226 #endif 226 Factory::createClassHierarchy(); 227 228 setConfigValues(); 229 230 const Settings::CommandLineArgument* mode = Settings::getCommandLineArgument("mode"); 231 assert(mode); 232 if (!mode->bHasDefaultValue_) 227 228 // creates the class hierarchy for all classes with factories 229 Factory::createClassHierarchy(); 230 231 setConfigValues(); 232 233 const Settings::CommandLineArgument* mode = Settings::getCommandLineArgument("mode"); 234 assert(mode); 235 if (!mode->bHasDefaultValue_) 236 { 237 Settings::setGameMode(mode->value_); 238 this->mode_ = Settings::getGameMode(); 239 } 240 COUT(3) << "Orxonox: Game mode is " << mode_.name << "." << std::endl; 241 242 const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath"); 243 assert(dataPath); 244 if (!dataPath->bHasDefaultValue_) 245 { 246 if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\') 247 Settings::tsetDataPath(dataPath->value_.getString() + "/"); 248 else 249 Settings::tsetDataPath(dataPath->value_.getString()); 250 } 251 252 try 253 { 254 // initialise TCL 255 TclBind::getInstance().setDataPath(Settings::getDataPath()); 256 257 graphicsEngine_ = new GraphicsEngine(); 258 graphicsEngine_->setup(); // creates ogre root and other essentials 259 260 if (mode_.showsGraphics) 261 { 262 graphicsEngine_->loadRenderer(); // creates the render window 263 264 // TODO: Spread this so that this call only initialises things needed for the Console and GUI 265 graphicsEngine_->initialiseResources(); 266 267 // Calls the InputManager which sets up the input devices. 268 // The render window width and height are used to set up the mouse movement. 269 inputManager_ = new InputManager(); 270 inputManager_->initialise(graphicsEngine_->getWindowHandle(), 271 graphicsEngine_->getWindowWidth(), graphicsEngine_->getWindowHeight(), true, true, true); 272 KeyBinder* keyBinder = new KeyBinder(); 273 keyBinder->loadBindings(); 274 inputManager_->createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder); 275 276 // Load the InGameConsole 277 console_ = new InGameConsole(); 278 console_->initialise(); 279 280 // load the CEGUI interface 281 guiManager_ = new GUIManager(); 282 guiManager_->initialise(); 283 } 284 else 285 { 286 // TODO: Initialise a not yet written console that operates in the shell we 287 // started the game from. 288 // We probably want to use std::cin to catch input (OIS uses DirectX or X server) 289 } 290 291 bool showGUI = true; 292 if (mode_.mode != GameMode::Unspecified) 293 { 294 showGUI = false; 295 // a game mode was specified with the command line 296 // we therefore load the game and level directly 297 298 if (!loadLevel(this->mode_)) 299 { 300 COUT(1) << "Loading with predefined mode failed. Showing main menu." << std::endl; 301 showGUI = true; 302 mode_ = GameMode::GM_Unspecified; 303 } 304 } 305 306 if (showGUI) 307 { 308 // show main menu 309 GUIManager::getInstance().showGUI("MainMenu", 0); 310 GraphicsEngine::getInstance().getViewport()->setCamera(GUIManager::getInstance().getCamera()); 311 } 312 } 313 catch (std::exception& ex) 314 { 315 COUT(1) << ex.what() << std::endl; 316 COUT(1) << "Loading sequence aborted." << std::endl; 317 return; 318 } 319 320 modeRequest_ = mode_; 321 // here happens the game 322 startRenderLoop(); 323 324 if (mode_.mode == GameMode::Client) 325 network::Client::getSingleton()->closeConnection(); 326 327 if (mode_.hasServer) 328 server_g->close(); 329 } 330 331 /*static*/ void Orxonox::loadGame(const std::string& name) 233 332 { 234 Settings::setGameMode(mode->value_); 235 this->mode_ = Settings::getGameMode(); 333 const GameMode& mode = Settings::getGameMode(name); 334 if (mode.mode == GameMode::None) 335 return; 336 337 getSingleton().modeRequest_ = mode; 236 338 } 237 COUT(3) << "Orxonox: Game mode is " << mode_.name << "." << std::endl; 238 239 const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath"); 240 assert(dataPath); 241 if (!dataPath->bHasDefaultValue_) 339 340 bool Orxonox::loadLevel(const GameMode& mode) 242 341 { 243 if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\') 244 Settings::tsetDataPath(dataPath->value_.getString() + "/"); 245 else 246 Settings::tsetDataPath(dataPath->value_.getString()); 342 bool success = true; 343 344 if (mode.showsGraphics) 345 { 346 // create Ogre SceneManager for the level 347 graphicsEngine_->createNewScene(); 348 349 if (!loadPlayground()) 350 return false; 351 } 352 353 switch (mode.mode) 354 { 355 case GameMode::Server: 356 success &= serverLoad(); 357 break; 358 case GameMode::Client: 359 success &= clientLoad(); 360 break; 361 case GameMode::Dedicated: 362 success &= serverLoad(); 363 break; 364 case GameMode::Standalone: 365 success &= standaloneLoad(); 366 break; 367 default: // never happens 368 assert(false); 369 } 370 371 if (success) 372 { 373 InputManager::getInstance().requestEnterState("game"); 374 this->mode_ = mode; 375 } 376 377 return success; 247 378 } 248 249 try250 {251 // initialise TCL252 TclBind::getInstance().setDataPath(Settings::getDataPath());253 254 ogre_ = new GraphicsEngine();255 ogre_->setup(); // creates ogre root and other essentials256 257 if (mode_.showsGraphics)258 {259 ogre_->loadRenderer(); // creates the render window260 261 // TODO: Spread this so that this call only initialises things needed for the Console and GUI262 ogre_->initialiseResources();263 264 // Calls the InputManager which sets up the input devices.265 // The render window width and height are used to set up the mouse movement.266 inputManager_ = new InputManager();267 inputManager_->initialise(ogre_->getWindowHandle(),268 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true);269 KeyBinder* keyBinder = new KeyBinder();270 keyBinder->loadBindings();271 inputManager_->createSimpleInputState("game", 20)->setHandler(keyBinder);272 273 // Load the InGameConsole274 console_ = new InGameConsole();275 console_->initialise();276 277 // load the CEGUI interface278 guiManager_ = new GUIManager();279 guiManager_->initialise();280 }281 282 bool showGUI = true;283 if (mode_.mode != GameMode::Unspecified)284 {285 showGUI = false;286 // a game mode was specified with the command line287 // we therefore load the game and level directly288 289 if (!loadLevel(this->mode_))290 {291 COUT(1) << "Loading with predefined mode failed. Showing main menu." << std::endl;292 showGUI = true;293 mode_ = GameMode::GM_Unspecified;294 }295 }296 297 if (showGUI)298 {299 // show main menu300 GUIManager::getInstance().showGUI("MainMenu", 0);301 GraphicsEngine::getSingleton().getViewport()->setCamera(GUIManager::getInstance().getCamera());302 }303 }304 catch (std::exception& ex)305 {306 COUT(1) << ex.what() << std::endl;307 COUT(1) << "Loading sequence aborted." << std::endl;308 return;309 }310 311 modeRequest_ = mode_;312 // here happens the game313 startRenderLoop();314 315 if (mode_.mode == GameMode::Client)316 network::Client::getSingleton()->closeConnection();317 318 if (mode_.hasServer)319 server_g->close();320 }321 322 /*static*/ void Orxonox::loadGame(const std::string& name)323 {324 const GameMode& mode = Settings::getGameMode(name);325 if (mode.mode == GameMode::None)326 return;327 328 getSingleton().modeRequest_ = mode;329 }330 331 bool Orxonox::loadLevel(const GameMode& mode)332 {333 bool success = true;334 335 if (mode.showsGraphics)336 {337 // create Ogre SceneManager for the level338 ogre_->createNewScene();339 340 if (!loadPlayground())341 return false;342 }343 344 switch (mode.mode)345 {346 case GameMode::Server:347 success &= serverLoad();348 break;349 case GameMode::Client:350 success &= clientLoad();351 break;352 case GameMode::Dedicated:353 success &= serverLoad();354 break;355 case GameMode::Standalone:356 success &= standaloneLoad();357 break;358 default: // never happens359 assert(false);360 }361 362 if (success)363 {364 InputManager::getInstance().requestEnterState("game");365 this->mode_ = mode;366 }367 368 return success;369 }370 379 371 380 /** … … 528 537 if (timeAfterTick > refreshStartTime + refreshTime) 529 538 { 530 GraphicsEngine::get Singleton().setAverageTickTime(539 GraphicsEngine::getInstance().setAverageTickTime( 531 540 (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 532 541 float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0; 533 GraphicsEngine::get Singleton().setAverageFramesPerSecond(avgFPS);542 GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 534 543 535 544 oldFrameCount = frameCount; … … 552 561 // make sure the window stays active even when not focused 553 562 // (probably only necessary on windows) 554 GraphicsEngine::get Singleton().setWindowActivity(true);563 GraphicsEngine::getInstance().setWindowActivity(true); 555 564 556 565 // tick CEGUI
Note: See TracChangeset
for help on using the changeset viewer.