Changeset 1638 for code/branches/gui/src/orxonox
- Timestamp:
- Jul 20, 2008, 7:49:26 PM (16 years ago)
- Location:
- code/branches/gui
- Files:
-
- 9 added
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui
-
Property
svn:mergeinfo
set to
/code/branches/input merged eligible
-
Property
svn:mergeinfo
set to
-
code/branches/gui/src/orxonox/GraphicsEngine.cc
r1625 r1638 27 27 */ 28 28 29 /** 30 @file orxonox.cc 31 @brief Orxonox class 32 */ 29 /** 30 @file 31 @brief 32 Implementation of an partial interface to Ogre. 33 */ 33 34 34 35 #include "OrxonoxStableHeaders.h" … … 50 51 #include "core/CommandExecutor.h" 51 52 #include "core/ConsoleCommand.h" 53 #include "core/Exception.h" 52 54 53 55 #include "overlays/console/InGameConsole.h" … … 57 59 #include "tools/WindowEventListener.h" 58 60 61 #include "objects/CameraHandler.h" 59 62 60 63 namespace orxonox 61 64 { 62 /** 63 @brief Returns the singleton instance and creates it the first time. 64 @return The only instance of GraphicsEngine. 65 */ 66 /*static*/ GraphicsEngine& GraphicsEngine::getSingleton() 67 { 68 static GraphicsEngine theOnlyInstance; 69 return theOnlyInstance; 70 } 71 72 /** 73 @brief Only use constructor to initialise variables and pointers! 74 */ 75 GraphicsEngine::GraphicsEngine() : 76 root_(0), 77 scene_(0), 78 renderWindow_(0) 79 { 80 RegisterObject(GraphicsEngine); 81 82 this->detailLevelParticle_ = 0; 83 84 this->setConfigValues(); 85 CCOUT(4) << "Constructed" << std::endl; 86 } 87 88 void GraphicsEngine::setConfigValues() 89 { 90 SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path."); 91 SetConfigValue(ogreConfigFile_, "ogre.cfg").description("Location of the Ogre config file"); 92 SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file"); 93 SetConfigValue(ogreLogFile_, "ogre.log").description("Logfile for messages from Ogre. \ 94 Use \"\" to suppress log file creation."); 95 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 96 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 97 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 98 99 unsigned int old = this->detailLevelParticle_; 100 SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high"); 101 102 if (this->detailLevelParticle_ != old) 103 for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) 104 it->detailLevelChanged(this->detailLevelParticle_); 105 } 106 107 /** 108 @brief Called after main() --> call destroyObjects()! 109 */ 110 GraphicsEngine::~GraphicsEngine() 111 { 112 this->destroy(); 113 } 114 115 /** 116 @brief Destroys all the internal objects. Call this method when you 117 normally would call the destructor. 118 */ 119 void GraphicsEngine::destroy() 120 { 121 CCOUT(4) << "Destroying objects..." << std::endl; 122 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this); 123 if (this->root_) 124 delete this->root_; 125 this->root_ = 0; 126 this->scene_ = 0; 127 this->renderWindow_ = 0; 128 // delete the ogre log and the logManager (since we have created it). 129 if (Ogre::LogManager::getSingletonPtr() != 0) 130 { 131 Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this); 132 Ogre::LogManager::getSingleton().destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 133 delete Ogre::LogManager::getSingletonPtr(); 134 } 135 CCOUT(4) << "Destroying objects done" << std::endl; 136 } 137 138 /** 139 @brief Creates the Ogre Root object and sets up the ogre log. 140 */ 141 bool GraphicsEngine::setup() 142 { 143 CCOUT(3) << "Setting up..." << std::endl; 144 // temporary overwrite of dataPath, change ini file for permanent change 145 146 // TODO: LogManager doesn't work on specific systems. The why is unknown yet. 65 GraphicsEngine* GraphicsEngine::singletonRef_s = 0; 66 67 /** 68 @brief 69 Returns the singleton instance. 70 @return 71 The only instance of GraphicsEngine. 72 */ 73 /*static*/ GraphicsEngine& GraphicsEngine::getSingleton() 74 { 75 assert(singletonRef_s); 76 return *singletonRef_s; 77 } 78 79 /** 80 @brief 81 Non-initialising constructor. 82 */ 83 GraphicsEngine::GraphicsEngine() 84 : root_(0) 85 , renderWindow_(0) 86 , levelSceneManager_(0) 87 , levelViewport_(0) 88 { 89 RegisterObject(GraphicsEngine); 90 91 singletonRef_s = this; 92 93 this->detailLevelParticle_ = 0; 94 95 this->setConfigValues(); 96 CCOUT(4) << "Constructed" << std::endl; 97 } 98 99 void GraphicsEngine::setConfigValues() 100 { 101 SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path."); 102 SetConfigValue(ogreConfigFile_, "ogre.cfg").description("Location of the Ogre config file"); 103 SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file"); 104 SetConfigValue(ogreLogFile_, "ogre.log").description("Logfile for messages from Ogre. \ 105 Use \"\" to suppress log file creation."); 106 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 107 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 108 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 109 110 unsigned int old = this->detailLevelParticle_; 111 SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high"); 112 113 if (this->detailLevelParticle_ != old) 114 for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) 115 it->detailLevelChanged(this->detailLevelParticle_); 116 } 117 118 /** 119 @brief 120 Destroys all the Ogre related objects 121 */ 122 GraphicsEngine::~GraphicsEngine() 123 { 124 CCOUT(4) << "Destroying objects..." << std::endl; 125 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this); 126 if (this->root_) 127 delete this->root_; 128 this->root_ = 0; 129 this->levelSceneManager_ = 0; 130 this->renderWindow_ = 0; 131 147 132 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 148 // create a logManager 149 // note: If there's already a logManager, Ogre will complain by a failed assertation. 150 // but that shouldn't happen, since this is the first time to create a logManager.. 151 Ogre::LogManager* logger = new Ogre::LogManager(); 152 CCOUT(4) << "Ogre LogManager created" << std::endl; 153 154 // create our own log that we can listen to 155 Ogre::Log *myLog; 156 if (this->ogreLogFile_ == "") 157 myLog = logger->createLog("ogre.log", true, false, true); 158 else 159 myLog = logger->createLog(this->ogreLogFile_, true, false, false); 160 CCOUT(4) << "Ogre Log created" << std::endl; 161 162 myLog->setLogDetail(Ogre::LL_BOREME); 163 myLog->addListener(this); 133 // delete the ogre log and the logManager (since we have created it). 134 if (Ogre::LogManager::getSingletonPtr() != 0) 135 { 136 Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this); 137 Ogre::LogManager::getSingleton().destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 138 delete Ogre::LogManager::getSingletonPtr(); 139 } 140 CCOUT(4) << "Destroying objects done" << std::endl; 164 141 #endif 165 142 166 // Root will detect that we've already created a Log 167 CCOUT(4) << "Creating Ogre Root..." << std::endl; 168 169 if (ogrePluginsFile_ == "") 170 { 171 COUT(1) << "Error: Ogre plugins file set to \"\". Cannot load." << std::endl; 172 return false; 173 } 174 if (ogreConfigFile_ == "") 175 { 176 COUT(1) << "Error: Ogre config file set to \"\". Cannot load." << std::endl; 177 return false; 178 } 179 if (ogreLogFile_ == "") 180 { 181 COUT(1) << "Error: Ogre log file set to \"\". Cannot load." << std::endl; 182 return false; 183 } 184 185 try 186 { 187 root_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_); 188 } 189 catch (Ogre::Exception ex) 190 { 191 COUT(2) << "Error: There was an exception when creating Ogre Root." << std::endl; 192 return false; 193 } 194 195 if (!root_->getInstalledPlugins().size()) 196 { 197 COUT(1) << "Error: No plugins declared. Cannot load Ogre." << std::endl; 198 COUT(0) << "Is the plugins file correctly declared?" << std::endl; 199 return false; 200 } 201 202 #if 0 203 // tame the ogre ouput so we don't get all the mess in the console 204 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 205 defaultLog->setDebugOutputEnabled(false); 206 defaultLog->setLogDetail(Ogre::LL_BOREME); 207 defaultLog->addListener(this); 143 singletonRef_s = 0; 144 } 145 146 /** 147 @brief 148 Creates the Ogre Root object and sets up the ogre log. 149 */ 150 void GraphicsEngine::setup() 151 { 152 CCOUT(3) << "Setting up..." << std::endl; 153 154 // TODO: LogManager doesn't work on linux platform. The why is yet unknown. 155 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 156 // create a new logManager 157 Ogre::LogManager* logger = new Ogre::LogManager(); 158 CCOUT(4) << "Ogre LogManager created" << std::endl; 159 160 // create our own log that we can listen to 161 Ogre::Log *myLog; 162 if (this->ogreLogFile_ == "") 163 myLog = logger->createLog("ogre.log", true, false, true); 164 else 165 myLog = logger->createLog(this->ogreLogFile_, true, false, false); 166 CCOUT(4) << "Ogre Log created" << std::endl; 167 168 myLog->setLogDetail(Ogre::LL_BOREME); 169 myLog->addListener(this); 208 170 #endif 209 171 210 CCOUT(4) << "Creating Ogre Root done" << std::endl; 211 212 // specify where Ogre has to look for resources. This call doesn't parse anything yet! 213 if (!declareRessourceLocations()) 214 return false; 215 216 CCOUT(3) << "Set up done." << std::endl; 217 return true; 218 } 219 220 bool GraphicsEngine::declareRessourceLocations() 221 { 222 CCOUT(4) << "Declaring Resources" << std::endl; 223 //TODO: Specify layout of data file and maybe use xml-loader 224 //TODO: Work with ressource groups (should be generated by a special loader) 225 226 if (resourceFile_ == "") 227 { 228 COUT(1) << "Error: Resource file set to \"\". Cannot load." << std::endl; 229 return false; 230 } 231 232 // Load resource paths from data file using configfile ressource type 233 Ogre::ConfigFile cf; 234 try 235 { 236 cf.load(Settings::getDataPath() + resourceFile_); 237 } 238 catch (Ogre::Exception ex) 239 { 240 COUT(1) << "Error: Could not load resources.cfg in path " << Settings::getDataPath() << std::endl; 241 COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl; 242 return false; 243 } 244 245 // Go through all sections & settings in the file 246 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 247 248 std::string secName, typeName, archName; 249 while (seci.hasMoreElements()) 250 { 251 try 252 { 253 secName = seci.peekNextKey(); 254 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 255 Ogre::ConfigFile::SettingsMultiMap::iterator i; 256 for (i = settings->begin(); i != settings->end(); ++i) 257 { 258 typeName = i->first; // for instance "FileSystem" or "Zip" 259 archName = i->second; // name (and location) of archive 260 261 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 262 std::string(Settings::getDataPath() + archName), typeName, secName); 263 } 264 } 265 catch (Ogre::Exception ex) 266 { 267 COUT(2) << "Exception while reading resources.cfg. Proceeding.." << ex.getDescription() << std::endl; 268 } 269 } 270 return true; 271 } 272 273 bool GraphicsEngine::loadRenderer() 274 { 275 CCOUT(4) << "Configuring Renderer" << std::endl; 276 277 // check for file existence because Ogre displays exceptions if not 278 std::ifstream probe; 279 probe.open(ogreConfigFile_.c_str()); 280 if (!probe) 281 { 282 // create a zero sized file 283 std::ofstream creator; 284 creator.open(ogreConfigFile_.c_str()); 285 creator.close(); 286 } 287 else 288 probe.close(); 289 290 if (!root_->restoreConfig()) 291 if (!root_->showConfigDialog()) 292 return false; 293 294 CCOUT(4) << "Creating render window" << std::endl; 295 try 296 { 297 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 298 } 299 catch (Ogre::Exception ex) 300 { 301 COUT(2) << "Error: There was an exception when initialising Ogre Root." << std::endl; 302 return false; 303 } 304 305 if (!root_->isInitialised()) 306 { 307 CCOUT(2) << "Error: Initialising Ogre root object failed." << std::endl; 308 return false; 309 } 310 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 311 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 312 return true; 313 } 314 315 bool GraphicsEngine::initialiseResources() 316 { 317 CCOUT(4) << "Initialising resources" << std::endl; 318 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 319 try 320 { 321 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 322 /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups(); 323 for (unsigned int i = 0; i < str.size(); i++) 324 { 325 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]); 326 }*/ 327 } 328 catch (Ogre::Exception e) 329 { 330 CCOUT(2) << "Error: There was an Error when initialising the resources." << std::endl; 331 CCOUT(2) << "ErrorMessage: " << e.getFullDescription() << std::endl; 332 return false; 333 } 334 return true; 335 } 336 337 /** 338 * @brief Creates the SceneManager 339 */ 340 bool GraphicsEngine::createNewScene() 341 { 342 CCOUT(4) << "Creating new SceneManager..." << std::endl; 343 if (scene_) 344 { 345 CCOUT(2) << "SceneManager already exists! Skipping." << std::endl; 346 return false; 347 } 348 scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 349 CCOUT(3) << "Created SceneManager: " << scene_ << std::endl; 350 return true; 351 } 352 353 /** 354 Returns the window handle of the render window. 355 At least the InputHandler uses this to create the OIS::InputManager 356 @return The window handle of the render window 357 */ 358 size_t GraphicsEngine::getWindowHandle() 359 { 360 if (this->renderWindow_) 361 { 362 size_t windowHnd = 0; 363 this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd); 364 return windowHnd; 365 } 366 else 367 return 0; 368 } 369 370 /** 371 Get the width of the current render window 372 @return The width of the current render window 373 */ 374 int GraphicsEngine::getWindowWidth() const 375 { 376 if (this->renderWindow_) 377 return this->renderWindow_->getWidth(); 378 else 379 return 0; 380 } 381 382 /** 383 Get the height of the current render window 384 @return The height of the current render window 385 */ 386 int GraphicsEngine::getWindowHeight() const 387 { 388 if (this->renderWindow_) 389 return this->renderWindow_->getHeight(); 390 else 391 return 0; 392 } 393 394 /** 395 @brief Returns the window aspect ratio height/width. 396 @return The ratio 397 */ 398 float GraphicsEngine::getWindowAspectRatio() const 399 { 400 if (this->renderWindow_) 401 return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth(); 402 else 403 return 1.0f; 404 } 405 406 /** 407 @brief Method called by the LogListener interface from Ogre. 408 We use it to capture Ogre log messages and handle it ourselves. 409 @param message The message to be logged 410 @param lml The message level the log is using 411 @param maskDebug If we are printing to the console or not 412 @param logName the name of this log (so you can have several listeners 413 for different logs, and identify them) 414 */ 415 void GraphicsEngine::messageLogged(const std::string& message, 416 Ogre::LogMessageLevel lml, bool maskDebug, const std::string &logName) 417 { 418 int orxonoxLevel; 419 switch (lml) 420 { 421 case Ogre::LML_TRIVIAL: 422 orxonoxLevel = this->ogreLogLevelTrivial_; 423 break; 424 case Ogre::LML_NORMAL: 425 orxonoxLevel = this->ogreLogLevelNormal_; 426 break; 427 case Ogre::LML_CRITICAL: 428 orxonoxLevel = this->ogreLogLevelCritical_; 429 break; 430 default: 431 orxonoxLevel = 0; 432 } 433 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 434 << "Ogre: " << message << std::endl; 435 } 436 437 /** 438 * Window has moved. 439 * @param rw The render window it occured in 440 */ 441 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw) 442 { 443 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 444 it->windowMoved(); 445 } 446 447 /** 448 * Window has resized. 449 * @param rw The render window it occured in 450 * @note GraphicsEngine has a render window stored itself. This is the same 451 * as rw. But we have to be careful when using multiple render windows! 452 */ 453 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) 454 { 455 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 456 it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight()); 457 } 458 459 /** 460 * Window has changed Focus. 461 * @param rw The render window it occured in 462 */ 463 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw) 464 { 465 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 466 it->windowFocusChanged(); 467 } 468 469 /** 470 * Window was closed. 471 * @param rw The render window it occured in 472 */ 473 void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw) 474 { 475 // using CommandExecutor in order to avoid depending on Orxonox.h. 476 CommandExecutor::execute("exit", false); 477 } 172 // Root will detect that we've already created a Log 173 CCOUT(4) << "Creating Ogre Root..." << std::endl; 174 175 if (ogrePluginsFile_ == "") 176 { 177 COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl; 178 ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg"); 179 } 180 if (ogreConfigFile_ == "") 181 { 182 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl; 183 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg"); 184 } 185 if (ogreLogFile_ == "") 186 { 187 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl; 188 ModifyConfigValue(ogreLogFile_, tset, "ogre.log"); 189 } 190 191 root_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_); 192 193 if (!root_->getInstalledPlugins().size()) 194 { 195 ThrowException(PluginsNotFound, "No Ogre plugins declared. Cannot load Ogre."); 196 } 197 198 #if 0 // Ogre 1.4.3 doesn't support setDebugOutputEnabled(.) 199 //#if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 200 // tame the ogre ouput so we don't get all the mess in the console 201 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 202 defaultLog->setDebugOutputEnabled(false); 203 defaultLog->setLogDetail(Ogre::LL_BOREME); 204 defaultLog->addListener(this); 205 #endif 206 207 CCOUT(4) << "Creating Ogre Root done" << std::endl; 208 209 // specify where Ogre has to look for resources. This call doesn't parse anything yet! 210 declareRessourceLocations(); 211 212 CCOUT(3) << "Set up done." << std::endl; 213 } 214 215 void GraphicsEngine::declareRessourceLocations() 216 { 217 CCOUT(4) << "Declaring Resources" << std::endl; 218 //TODO: Specify layout of data file and maybe use xml-loader 219 //TODO: Work with ressource groups (should be generated by a special loader) 220 221 if (resourceFile_ == "") 222 { 223 COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl; 224 ModifyConfigValue(resourceFile_, tset, "resources.cfg"); 225 } 226 227 // Load resource paths from data file using configfile ressource type 228 Ogre::ConfigFile cf; 229 try 230 { 231 cf.load(Settings::getDataPath() + resourceFile_); 232 } 233 catch (Ogre::Exception& ex) 234 { 235 COUT(1) << ex.getFullDescription() << std::endl; 236 COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl; 237 throw; 238 } 239 240 // Go through all sections & settings in the file 241 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 242 243 std::string secName, typeName, archName; 244 while (seci.hasMoreElements()) 245 { 246 try 247 { 248 secName = seci.peekNextKey(); 249 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 250 Ogre::ConfigFile::SettingsMultiMap::iterator i; 251 for (i = settings->begin(); i != settings->end(); ++i) 252 { 253 typeName = i->first; // for instance "FileSystem" or "Zip" 254 archName = i->second; // name (and location) of archive 255 256 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 257 std::string(Settings::getDataPath() + archName), typeName, secName); 258 } 259 } 260 catch (Ogre::Exception& ex) 261 { 262 COUT(1) << ex.getFullDescription() << std::endl; 263 } 264 } 265 } 266 267 bool GraphicsEngine::loadRenderer() 268 { 269 CCOUT(4) << "Configuring Renderer" << std::endl; 270 271 // check for file existence because Ogre displays exceptions if not 272 std::ifstream probe; 273 probe.open(ogreConfigFile_.c_str()); 274 if (!probe) 275 { 276 // create a zero sized file 277 std::ofstream creator; 278 creator.open(ogreConfigFile_.c_str()); 279 creator.close(); 280 } 281 else 282 probe.close(); 283 284 if (!root_->restoreConfig()) 285 if (!root_->showConfigDialog()) 286 return false; 287 288 CCOUT(4) << "Creating render window" << std::endl; 289 try 290 { 291 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 292 } 293 catch (...) 294 { 295 COUT(2) << "Error: There was an exception when initialising Ogre Root." << std::endl; 296 return false; 297 } 298 299 if (!root_->isInitialised()) 300 { 301 CCOUT(2) << "Error: Initialising Ogre root object failed." << std::endl; 302 return false; 303 } 304 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 305 //Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 306 307 // create a full screen viewport in which to render the scene and the loading screen 308 // The GUI uses its own one to be able to render on top of everything. 309 // That explains why the Z order here is only 1 and not 0 (top most) 310 this->levelViewport_ = this->renderWindow_->addViewport(0, 1); 311 312 return true; 313 } 314 315 bool GraphicsEngine::initialiseResources() 316 { 317 CCOUT(4) << "Initialising resources" << std::endl; 318 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 319 try 320 { 321 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 322 /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups(); 323 for (unsigned int i = 0; i < str.size(); i++) 324 { 325 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]); 326 }*/ 327 } 328 catch (Ogre::Exception& e) 329 { 330 CCOUT(2) << "Error: There was an Error when initialising the resources." << std::endl; 331 CCOUT(2) << "ErrorMessage: " << e.getFullDescription() << std::endl; 332 return false; 333 } 334 return true; 335 } 336 337 /** 338 @brief 339 Creates the SceneManager 340 */ 341 bool GraphicsEngine::createNewScene() 342 { 343 CCOUT(4) << "Creating new SceneManager..." << std::endl; 344 if (levelSceneManager_) 345 { 346 CCOUT(2) << "SceneManager already exists! Skipping." << std::endl; 347 return false; 348 } 349 this->levelSceneManager_ = this->root_->createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager"); 350 CCOUT(3) << "Created SceneManager: " << levelSceneManager_ << std::endl; 351 return true; 352 } 353 354 /** 355 @brief 356 Returns the window handle of the render window. 357 At least the InputHandler uses this to create the OIS::InputManager 358 @return 359 The window handle of the render window 360 */ 361 size_t GraphicsEngine::getWindowHandle() 362 { 363 if (this->renderWindow_) 364 { 365 size_t windowHnd = 0; 366 this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd); 367 return windowHnd; 368 } 369 else 370 return 0; 371 } 372 373 /** 374 @brief 375 Get the width of the render window 376 @return 377 The width of the render window 378 */ 379 int GraphicsEngine::getWindowWidth() const 380 { 381 if (this->renderWindow_) 382 return this->renderWindow_->getWidth(); 383 else 384 return 0; 385 } 386 387 /** 388 @brief 389 Get the height of the render window 390 @return 391 The height of the render window 392 */ 393 int GraphicsEngine::getWindowHeight() const 394 { 395 if (this->renderWindow_) 396 return this->renderWindow_->getHeight(); 397 else 398 return 0; 399 } 400 401 /** 402 @brief 403 Returns the window aspect ratio height/width. 404 @return 405 The window aspect ratio 406 */ 407 float GraphicsEngine::getWindowAspectRatio() const 408 { 409 if (this->renderWindow_) 410 return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth(); 411 else 412 return 1.0f; 413 } 414 415 /** 416 @brief 417 Method called by the LogListener interface from Ogre. 418 We use it to capture Ogre log messages and handle it ourselves. 419 @param message 420 The message to be logged 421 @param lml 422 The message level the log is using 423 @param maskDebug 424 If we are printing to the console or not 425 @param logName 426 The name of this log (so you can have several listeners 427 for different logs, and identify them) 428 */ 429 void GraphicsEngine::messageLogged(const std::string& message, 430 Ogre::LogMessageLevel lml, bool maskDebug, const std::string &logName) 431 { 432 int orxonoxLevel; 433 switch (lml) 434 { 435 case Ogre::LML_TRIVIAL: 436 orxonoxLevel = this->ogreLogLevelTrivial_; 437 break; 438 case Ogre::LML_NORMAL: 439 orxonoxLevel = this->ogreLogLevelNormal_; 440 break; 441 case Ogre::LML_CRITICAL: 442 orxonoxLevel = this->ogreLogLevelCritical_; 443 break; 444 default: 445 orxonoxLevel = 0; 446 } 447 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 448 << "Ogre: " << message << std::endl; 449 } 450 451 /** 452 @brief 453 Window has moved. 454 @param rw 455 The render window it occured in 456 */ 457 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw) 458 { 459 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 460 it->windowMoved(); 461 } 462 463 /** 464 @brief 465 Window has resized. 466 @param rw 467 The render window it occured in 468 @note 469 GraphicsEngine has a render window stored itself. This is the same 470 as rw. But we have to be careful when using multiple render windows! 471 */ 472 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) 473 { 474 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 475 it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight()); 476 } 477 478 /** 479 @brief 480 Window focus has changed. 481 @param rw 482 The render window it occured in 483 */ 484 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw) 485 { 486 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 487 it->windowFocusChanged(); 488 } 489 490 /** 491 @brief 492 Window was closed. 493 @param rw 494 The render window it occured in 495 */ 496 void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw) 497 { 498 // using CommandExecutor in order to avoid depending on Orxonox.h. 499 CommandExecutor::execute("exit", false); 500 } 478 501 479 502 } -
code/branches/gui/src/orxonox/GraphicsEngine.h
r1625 r1638 54 54 class _OrxonoxExport GraphicsEngine : public Ogre::WindowEventListener, public Ogre::LogListener, public OrxonoxClass 55 55 { 56 public: 57 void setConfigValues(); 58 bool setup(); 59 bool declareRessourceLocations(); 60 bool loadRenderer(); 61 bool initialiseResources(); 62 bool createNewScene(); 56 public: 57 GraphicsEngine(); 58 ~GraphicsEngine(); 63 59 64 void destroy(); 60 void setConfigValues(); 61 void setup(); 62 void declareRessourceLocations(); 63 bool loadRenderer(); 64 bool initialiseResources(); 65 bool createNewScene(); 65 66 66 Ogre::SceneManager* getSceneManager() { return scene_; } 67 void setLevelSceneManager(Ogre::SceneManager* sceneMgr) { this->levelSceneManager_ = sceneMgr; } 68 Ogre::SceneManager* getLevelSceneManager() { return levelSceneManager_; } 67 69 68 // several window properties 69 Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; } 70 size_t getWindowHandle(); 71 int getWindowWidth() const; 72 int getWindowHeight() const; 73 float getWindowAspectRatio() const; 74 float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; } 75 float getAverageTickTime() const { return this->avgTickTime_; } 76 void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; } 77 void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; } 70 Ogre::Viewport* getLevelViewport() { return this->levelViewport_; } 78 71 79 void setWindowActivity(bool activity) 80 { if (this->renderWindow_) this->renderWindow_->setActive(activity); } 72 // several window properties 73 Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; } 74 size_t getWindowHandle(); 75 int getWindowWidth() const; 76 int getWindowHeight() const; 77 float getWindowAspectRatio() const; 78 float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; } 79 float getAverageTickTime() const { return this->avgTickTime_; } 80 void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; } 81 void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; } 81 82 82 void windowMoved (Ogre::RenderWindow* rw); 83 void windowResized (Ogre::RenderWindow* rw); 84 void windowFocusChanged(Ogre::RenderWindow* rw); 85 void windowClosed (Ogre::RenderWindow* rw); 83 void setWindowActivity(bool activity) 84 { if (this->renderWindow_) this->renderWindow_->setActive(activity); } 86 85 87 88 86 inline unsigned int getDetailLevelParticle() const 87 { return this->detailLevelParticle_; } 89 88 90 91 89 static GraphicsEngine& getSingleton(); 90 static GraphicsEngine* getSingletonPtr() { return &getSingleton(); } 92 91 92 private: 93 // don't mess with singletons 94 GraphicsEngine(GraphicsEngine&) { } 93 95 94 private: 95 // don't mess with singletons 96 GraphicsEngine(); 97 ~GraphicsEngine(); 98 GraphicsEngine(GraphicsEngine&) { } 96 //! Method called by the LogListener from Ogre 97 void messageLogged(const std::string&, Ogre::LogMessageLevel, 98 bool, const std::string&); 99 99 100 //! Method called by the LogListener from Ogre 101 void messageLogged(const std::string&, Ogre::LogMessageLevel, 102 bool, const std::string&); 100 // window events from Ogre::WindowEventListener 101 void windowMoved (Ogre::RenderWindow* rw); 102 void windowResized (Ogre::RenderWindow* rw); 103 void windowFocusChanged(Ogre::RenderWindow* rw); 104 void windowClosed (Ogre::RenderWindow* rw); 103 105 104 Ogre::Root* root_; //!< Ogre's root 105 Ogre::SceneManager* scene_; //!< scene manager of the game 106 Ogre::RenderWindow* renderWindow_; //!< the current render window 107 std::string resourceFile_; //!< resources file name 108 std::string ogreConfigFile_; //!< ogre config file name 109 std::string ogrePluginsFile_; //!< ogre plugins file name 110 std::string ogreLogFile_; //!< log file name for Ogre log messages 111 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL 112 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 113 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 114 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 115 float avgTickTime_; //!< time in ms to tick() one frame 116 float avgFramesPerSecond_; //!< number of frames processed in one second 106 Ogre::Root* root_; //!< Ogre's root 107 Ogre::RenderWindow* renderWindow_; //!< the current render window 108 Ogre::SceneManager* levelSceneManager_; //!< scene manager of the game 109 Ogre::Viewport* levelViewport_; //!< default full size viewport for the level 110 111 // stats 112 float avgTickTime_; //!< time in ms to tick() one frame 113 float avgFramesPerSecond_; //!< number of frames processed in one second 114 115 // config values 116 std::string resourceFile_; //!< resources file name 117 std::string ogreConfigFile_; //!< ogre config file name 118 std::string ogrePluginsFile_; //!< ogre plugins file name 119 std::string ogreLogFile_; //!< log file name for Ogre log messages 120 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL 121 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 122 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 123 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 124 125 static GraphicsEngine* singletonRef_s; //!< Pointer to the Singleton 117 126 }; 118 127 } -
code/branches/gui/src/orxonox/Main.cc
r1535 r1638 22 22 * Author: 23 23 * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 35 36 36 37 #include <exception> 38 #include <cassert> 37 39 38 40 #include "util/OrxonoxPlatform.h" 41 #include "util/ArgReader.h" 39 42 #include "core/SignalHandler.h" 43 #include "core/Debug.h" 44 #include "network/ClientConnection.h" 45 #include "Settings.h" 40 46 #include "Orxonox.h" 41 47 42 48 using namespace orxonox; 49 43 50 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 44 51 #include <CoreFoundation/CoreFoundation.h> … … 49 56 std::string macBundlePath() 50 57 { 51 char path[1024];52 CFBundleRef mainBundle = CFBundleGetMainBundle();53 assert(mainBundle);58 char path[1024]; 59 CFBundleRef mainBundle = CFBundleGetMainBundle(); 60 assert(mainBundle); 54 61 55 CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);56 assert(mainBundleURL);62 CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); 63 assert(mainBundleURL); 57 64 58 CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);59 assert(cfStringRef);65 CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); 66 assert(cfStringRef); 60 67 61 CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);68 CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); 62 69 63 CFRelease(mainBundleURL);64 CFRelease(cfStringRef);70 CFRelease(mainBundleURL); 71 CFRelease(cfStringRef); 65 72 66 return std::string(path);73 return std::string(path); 67 74 } 68 75 #endif 76 77 bool parseCommandLine(int argc, char** argv) 78 { 79 ArgReader args; 80 std::string errorStr = args.parse(argc, argv); 81 if (errorStr != "") 82 { 83 COUT(1) << "Command Line: Parsing failed.\n" << errorStr << std::endl; 84 return false; 85 } 86 87 // Argument reader parses the command line to check syntax. 88 // Settings Singleton then stores the arguments. It always 89 // expects a default value. 90 bool success = true; 91 success &= Settings::addCommandLineArgument<std::string> 92 ("mode", args.getArgument("mode"), "standalone"); 93 success &= Settings::addCommandLineArgument<std::string> 94 ("dataPath", args.getArgument("dataPath"), "./"); 95 success &= Settings::addCommandLineArgument<std::string> 96 ("ip", args.getArgument("ip"), "127.0.0.0"); 97 success &= Settings::addCommandLineArgument<int> 98 ("port", args.getArgument("port"), NETWORK_PORT); 99 100 if (!success) 101 return false; 102 103 if (!args.allChecked()) 104 { 105 COUT(1) << "Command Line: Parsing failed.\nNot all arguments were matched." << std::endl; 106 return false; 107 } 108 109 return true; 110 } 69 111 70 112 #ifdef __cplusplus … … 72 114 #endif 73 115 74 int main(int argc, char **argv)116 int main(int argc, char** argv) 75 117 { 76 //try {118 // create a signal handler (only works for linux) 77 119 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 78 Orxonox* orx = Orxonox::getSingleton();79 120 80 bool res = false; 121 if (!parseCommandLine(argc, argv)) 122 { 123 COUT(0) << "Usage:" << std::endl << "orxonox [--mode client|server|dedicated|standalone] " 124 << "[--data PATH] [--ip IP] [--port PORT]" << std::endl; 125 return 0; 126 } 127 128 Orxonox orxonoxInstance; 129 130 try 131 { 81 132 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 82 res = orx->init(argc, argv,macBundlePath());133 orxonoxInstance.start(macBundlePath()); 83 134 #else 84 res = orx->init(argc, argv);135 orxonoxInstance.start(); 85 136 #endif 137 } 138 catch (std::exception& ex) 139 { 140 COUT(1) << ex.what() << std::endl; 141 COUT(1) << "Abort." << std::endl; 142 } 86 143 87 if (res) 88 orx->start(); 89 orx->destroySingleton(); 90 /*} 91 catch (std::exception &ex) 92 { 93 std::cerr << "Exception:\n"; 94 std::cerr << ex.what() << "\n"; 95 return 1; 96 }*/ 97 98 return 0; 144 return 0; 99 145 } 100 146 -
code/branches/gui/src/orxonox/Orxonox.cc
r1625 r1638 22 22 * Author: 23 23 * Reto Grieder 24 * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 24 25 * Co-authors: 25 * Benjamin Knecht <beni_at_orxonox.net>, (C) 200726 * ... 26 27 * 27 28 */ … … 38 39 //****** STD ******* 39 40 #include <deque> 41 #include <cassert> 40 42 41 43 //****** OGRE ****** … … 50 52 // util 51 53 //#include "util/Sleep.h" 52 #include "util/ArgReader.h"53 54 54 55 // core 55 56 #include "core/ConfigFileManager.h" 57 #include "core/ConfigValueIncludes.h" 56 58 #include "core/ConsoleCommand.h" 57 59 #include "core/Debug.h" 58 60 #include "core/Loader.h" 61 #include "core/Exception.h" 59 62 #include "core/input/InputManager.h" 63 #include "core/input/SimpleInputState.h" 64 #include "core/input/KeyBinder.h" 60 65 #include "core/TclBind.h" 61 66 #include "core/Core.h" … … 69 74 70 75 // objects and tools 71 #include "overlays/OverlayGroup.h"72 76 #include "overlays/console/InGameConsole.h" 73 77 #include "objects/Tickable.h" 74 78 #include "objects/Backlight.h" 75 79 #include "tools/ParticleInterface.h" 80 #include "gui/GUIManager.h" 76 81 77 82 #include "GraphicsEngine.h" … … 85 90 namespace orxonox 86 91 { 87 SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress); 88 SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 89 SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 92 SetConsoleCommand(Orxonox, exit, true).setKeybindMode(KeybindMode::OnPress); 93 SetConsoleCommand(Orxonox, slomo, true).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 94 SetConsoleCommand(Orxonox, setTimeFactor, true).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 95 SetConsoleCommand(Orxonox, loadGame, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, "standalone"); 90 96 91 97 /** … … 106 112 , bAbort_(false) 107 113 , timefactor_(1.0f) 108 , mode_(STANDALONE) 109 , serverIp_("") 110 , serverPort_(NETWORK_PORT) 111 { 114 , mode_(GameMode::GM_Unspecified) 115 , debugRefreshTime_(0.0f) 116 { 117 RegisterRootObject(Orxonox); 118 119 assert(singletonRef_s == 0); 120 singletonRef_s = this; 112 121 } 113 122 … … 118 127 { 119 128 // keep in mind: the order of deletion is very important! 120 Loader::unload( startLevel_);129 Loader::unload(); 121 130 if (this->startLevel_) 122 131 delete this->startLevel_; … … 136 145 delete this->timer_; 137 146 InputManager::destroy(); 138 GraphicsEngine::getSingleton().destroy(); 147 148 if (this->ogre_) 149 delete ogre_; 139 150 140 151 if (network::Client::getSingleton()) … … 142 153 if (server_g) 143 154 delete network::Server::getSingleton(); 155 156 singletonRef_s = 0; 157 } 158 159 void Orxonox::setConfigValues() 160 { 161 SetConfigValue(debugRefreshTime_, 0.2).description("Sets the time interval at which average fps, etc. get updated."); 144 162 } 145 163 … … 157 175 * @return singleton reference 158 176 */ 159 Orxonox* Orxonox::getSingleton() 160 { 161 if (!singletonRef_s) 162 singletonRef_s = new Orxonox(); 163 return singletonRef_s; 164 } 165 166 /** 167 @brief Destroys the Orxonox singleton. 168 */ 169 void Orxonox::destroySingleton() 170 { 171 if (singletonRef_s) 172 delete singletonRef_s; 173 singletonRef_s = 0; 177 Orxonox& Orxonox::getSingleton() 178 { 179 assert(singletonRef_s); 180 return *singletonRef_s; 174 181 } 175 182 … … 179 186 void Orxonox::setTimeFactor(float factor) 180 187 { 181 float change = factor / Orxonox::getSingleton() ->getTimeFactor();182 Orxonox::getSingleton() ->timefactor_ = factor;188 float change = factor / Orxonox::getSingleton().getTimeFactor(); 189 Orxonox::getSingleton().timefactor_ = factor; 183 190 for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) 184 191 it->setSpeedFactor(it->getSpeedFactor() * change); 185 192 186 193 for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it) 187 it->setTimeFactor(Orxonox::getSingleton()->getTimeFactor()); 188 } 189 190 /** 191 * initialization of Orxonox object 192 * @param argc argument counter 193 * @param argv list of argumenst 194 it->setTimeFactor(Orxonox::getSingleton().getTimeFactor()); 195 } 196 197 198 /** 199 * Starts the whole Game. 194 200 * @param path path to config (in home dir or something) 195 201 */ 196 bool Orxonox::init(int argc, char **argv)202 void Orxonox::start() 197 203 { 198 204 #ifdef _DEBUG … … 203 209 Factory::createClassHierarchy(); 204 210 205 std::string mode; 206 std::string tempDataPath; 207 208 ArgReader ar(argc, argv); 209 ar.checkArgument("mode", &mode, false); 210 ar.checkArgument("data", &tempDataPath, false); 211 ar.checkArgument("ip", &serverIp_, false); 212 ar.checkArgument("port", &serverPort_, false); 213 if(ar.errorHandling()) 214 { 215 COUT(1) << "Error while parsing command line arguments" << std::endl; 216 COUT(1) << ar.getErrorString(); 217 COUT(0) << "Usage:" << std::endl << "orxonox [mode client|server|dedicated|standalone] " 218 << "[--data PATH] [--ip IP] [--port PORT]" << std::endl; 219 return false; 220 } 221 222 if (mode == "client") 223 mode_ = CLIENT; 224 else if (mode == "server") 225 mode_ = SERVER; 226 else if (mode == "dedicated") 227 mode_ = DEDICATED; 228 else 229 { 230 if (mode == "") 231 mode = "standalone"; 232 if (mode != "standalone") 211 setConfigValues(); 212 213 const Settings::CommandLineArgument* mode = Settings::getCommandLineArgument("mode"); 214 assert(mode); 215 if (!mode->bHasDefaultValue_) 216 { 217 Settings::setGameMode(mode->value_); 218 this->mode_ = Settings::getGameMode(); 219 } 220 COUT(3) << "Orxonox: Game mode is " << mode_.name << "." << std::endl; 221 222 const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath"); 223 assert(dataPath); 224 if (!dataPath->bHasDefaultValue_) 225 { 226 if (*dataPath->value_.getString().end() != '/' && *dataPath->value_.getString().end() != '\\') 227 Settings::tsetDataPath(dataPath->value_.getString() + "/"); 228 else 229 Settings::tsetDataPath(dataPath->value_.getString()); 230 } 231 232 try 233 { 234 // initialise TCL 235 TclBind::getInstance().setDataPath(Settings::getDataPath()); 236 237 ogre_ = new GraphicsEngine(); 238 ogre_->setup(); // creates ogre root and other essentials 239 240 if (mode_.showsGraphics) 241 { 242 ogre_->loadRenderer(); // creates the render window 243 244 // TODO: Spread this so that this call only initialises things needed for the Console and GUI 245 ogre_->initialiseResources(); 246 247 // Calls the InputManager which sets up the input devices. 248 // The render window width and height are used to set up the mouse movement. 249 InputManager::initialise(ogre_->getWindowHandle(), 250 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true); 251 KeyBinder* keyBinder = new KeyBinder(); 252 InputManager::createSimpleInputState("game", 20)->setHandler(keyBinder); 253 254 // Load the InGameConsole 255 InGameConsole::getInstance().initialise(); 256 257 // load the CEGUI interface 258 GUIManager::getInstance().initialise(); 259 } 260 261 bool showGUI = true; 262 if (mode_.mode != GameMode::Unspecified) 263 { 264 showGUI = false; 265 // a game mode was specified with the command line 266 // we therefore load the game and level directly 267 268 if (!loadLevel(this->mode_)) 269 { 270 COUT(1) << "Loading with predefined mode failed. Showing main menu." << std::endl; 271 showGUI = true; 272 mode_ = GameMode::GM_Unspecified; 273 } 274 } 275 276 if (showGUI) 277 { 278 // show main menu 279 //GraphicsEngine::getSingleton().createNewScene(); 280 GUIManager::getInstance().showGUI("MainMenu", true); 281 } 282 } 283 catch (std::exception& ex) 284 { 285 COUT(1) << ex.what() << std::endl; 286 COUT(1) << "Loading sequence aborted." << std::endl; 287 return; 288 } 289 290 modeRequest_ = mode_; 291 // here happens the game 292 startRenderLoop(); 293 294 if (mode_.mode == GameMode::Client) 295 network::Client::getSingleton()->closeConnection(); 296 297 if (mode_.hasServer) 298 server_g->close(); 299 } 300 301 void Orxonox::loadGame(const std::string& name) 302 { 303 const GameMode& mode = Settings::getGameMode(name); 304 if (mode.mode == GameMode::None) 305 return; 306 307 getSingleton().modeRequest_ = mode; 308 } 309 310 bool Orxonox::loadLevel(const GameMode& mode) 311 { 312 bool success = true; 313 314 if (mode.showsGraphics) 233 315 { 234 COUT(2) << "Warning: mode \"" << mode << "\" doesn't exist. " 235 << "Defaulting to standalone" << std::endl; 236 mode = "standalone"; 316 // create Ogre SceneManager for the level 317 ogre_->createNewScene(); 318 319 if (!loadPlayground()) 320 return false; 237 321 } 238 mode_ = STANDALONE; 239 } 240 COUT(3) << "Orxonox: Mode is " << mode << "." << std::endl; 241 242 if (tempDataPath != "") 243 { 244 if (tempDataPath[tempDataPath.size() - 1] != '/') 245 tempDataPath += "/"; 246 Settings::tsetDataPath(tempDataPath); 247 } 248 249 // initialise TCL 250 TclBind::getInstance().setDataPath(Settings::getDataPath()); 251 252 //if (mode_ == DEDICATED) 253 // TODO: decide what to do here 254 //else 255 256 // for playable server, client and standalone, the startup 257 // procedure until the GUI is identical 258 259 ogre_ = &GraphicsEngine::getSingleton(); 260 if (!ogre_->setup()) // creates ogre root and other essentials 261 return false; 262 263 return true; 264 } 265 266 /** 267 * start modules 268 */ 269 bool Orxonox::start() 270 { 271 if (mode_ == DEDICATED) 272 { 273 // do something else 274 } 275 else 276 { // not dedicated server 277 if (!ogre_->loadRenderer()) // creates the render window 278 return false; 279 280 // TODO: Spread this so that this call only initialises things needed for the Console 281 if (!ogre_->initialiseResources()) 282 return false; 283 284 // Load the InGameConsole 285 InGameConsole::getInstance().initialise(); 286 287 // Calls the InputManager which sets up the input devices. 288 // The render window width and height are used to set up the mouse movement. 289 if (!InputManager::initialise(ogre_->getWindowHandle(), 290 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true)) 291 return false; 292 293 // TOOD: load the GUI here 294 // set InputManager to GUI mode 295 InputManager::setInputState(InputManager::IS_GUI); 296 // TODO: run GUI here 297 298 // The following lines depend very much on the GUI output, so they're probably misplaced here.. 299 300 InputManager::setInputState(InputManager::IS_NONE); 301 302 // create Ogre SceneManager 303 ogre_->createNewScene(); 304 305 if (!loadPlayground()) 306 return false; 307 } 308 309 switch (mode_) 310 { 311 case SERVER: 312 if (!serverLoad()) 313 return false; 314 break; 315 case CLIENT: 316 if (!clientLoad()) 317 return false; 318 break; 319 case DEDICATED: 320 if (!serverLoad()) 321 return false; 322 break; 323 default: 324 if (!standaloneLoad()) 325 return false; 326 } 327 328 InputManager::setInputState(InputManager::IS_NORMAL); 329 330 return startRenderLoop(); 322 323 switch (mode.mode) 324 { 325 case GameMode::Server: 326 success &= serverLoad(); 327 break; 328 case GameMode::Client: 329 success &= clientLoad(); 330 break; 331 case GameMode::Dedicated: 332 success &= serverLoad(); 333 break; 334 case GameMode::Standalone: 335 success &= standaloneLoad(); 336 break; 337 default: // never happens 338 assert(false); 339 } 340 341 if (success) 342 InputManager::requestEnterState("game"); 343 344 return success; 331 345 } 332 346 … … 337 351 bool Orxonox::loadPlayground() 338 352 { 339 // Init audio 340 //auMan_ = new audio::AudioManager(); 341 //auMan_->ambientAdd("a1"); 342 //auMan_->ambientAdd("a2"); 343 //auMan_->ambientAdd("a3"); 344 //auMan->ambientAdd("ambient1"); 345 //auMan_->ambientStart(); 353 // Start the Radar 354 this->radar_ = new Radar(); 346 355 347 356 // Load the HUD 348 357 COUT(3) << "Orxonox: Loading HUD" << std::endl; 349 358 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 350 Loader::load(hud_); 351 352 // Start the Radar 353 this->radar_ = new Radar(); 354 355 return true; 359 return Loader::load(hud_); 360 } 361 362 /** 363 * Helper method to load a level. 364 */ 365 bool Orxonox::loadScene() 366 { 367 COUT(0) << "Loading level..." << std::endl; 368 startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw"); 369 return Loader::open(startLevel_); 356 370 } 357 371 … … 363 377 COUT(0) << "Loading level in server mode" << std::endl; 364 378 379 assert(Settings::getCommandLineArgument("port")); 380 int serverPort = Settings::getCommandLineArgument("port")->value_; 365 381 //server_g = new network::Server(serverPort_); 366 server_g = network::Server::createSingleton(serverPort _);382 server_g = network::Server::createSingleton(serverPort); 367 383 368 384 if (!loadScene()) … … 381 397 COUT(0) << "Loading level in client mode" << std::endl;\ 382 398 383 if (serverIp_.compare("") == 0) 399 assert(Settings::getCommandLineArgument("port")); 400 assert(Settings::getCommandLineArgument("ip")); 401 int serverPort = Settings::getCommandLineArgument("port")->value_; 402 std::string serverIP = Settings::getCommandLineArgument("ip")->value_; 403 404 if (serverIP.compare("") == 0) 384 405 client_g = network::Client::createSingleton(); 385 406 else 386 387 client_g = network::Client::createSingleton(serverIp_, serverPort_); 407 client_g = network::Client::createSingleton(serverIP, serverPort); 388 408 389 409 if(!client_g->establishConnection()) … … 408 428 409 429 /** 410 * Helper method to load a level.411 */412 bool Orxonox::loadScene()413 {414 startLevel_ = new Level("levels/sample.oxw");415 Loader::open(startLevel_);416 417 return true;418 }419 420 421 /**422 430 Main loop of the orxonox game. 423 About the loop: The design is almost exactly like the one in ogre, so that 424 if any part of ogre registers a framelisteners, it will still behave 425 correctly. Furthermore the time smoothing feature from ogre has been 426 implemented too. If turned on (see orxonox constructor), it will calculate 427 the dt_n by means of the recent most dt_n-1, dt_n-2, etc. 431 We use the Ogre::Timer to measure time since it uses the most precise 432 method an a platform (however the windows timer lacks time when under 433 heavy kernel load!). 434 There is a simple mechanism to measure the average time spent in our 435 ticks as it may indicate performance issues. 436 A note about the Ogre::FrameListener: Even though we don't use them, 437 they still get called. However, the delta times are not correct (except 438 for timeSinceLastFrame, which is the most important). A little research 439 as shown that there is probably only one FrameListener that doesn't even 440 need the time. So we shouldn't run into problems. 428 441 */ 429 bool Orxonox::startRenderLoop() 430 { 431 // first check whether ogre root object has been created 432 if (Ogre::Root::getSingletonPtr() == 0) 433 { 434 COUT(2) << "Orxonox Error: Could not start rendering. No Ogre root object found" << std::endl; 435 return false; 436 } 442 void Orxonox::startRenderLoop() 443 { 437 444 Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); 438 439 445 440 446 // use the ogre timer class to measure time. … … 444 450 unsigned long frameCount = 0; 445 451 446 // TODO: this would very well fit into a configValue 447 const unsigned long refreshTime = 200000; 452 const unsigned long refreshTime = debugRefreshTime_ * 1000000.0f; 448 453 unsigned long refreshStartTime = 0; 449 454 unsigned long tickTime = 0; … … 454 459 unsigned long timeAfterTick = 0; 455 460 461 int sleepTime = 0; 462 463 // TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight) 464 456 465 COUT(3) << "Orxonox: Starting the main loop." << std::endl; 457 466 467 try 468 { 458 469 timer_->reset(); 459 470 while (!bAbort_) 460 471 { 461 // get current time 462 timeBeforeTickOld = timeBeforeTick; 463 timeBeforeTick = timer_->getMicroseconds(); 464 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; 465 466 467 // tick the core (needs real time for input and tcl thread management) 468 Core::tick(dt); 469 470 // Call those objects that need the real time 471 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 472 it->tick(dt); 473 // Call the scene objects 474 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 475 it->tick(dt * this->timefactor_); 476 477 // call server/client with normal dt 478 if (client_g) 479 client_g->tick(dt * this->timefactor_); 480 if (server_g) 481 server_g->tick(dt * this->timefactor_); 482 483 484 // get current time once again 485 timeAfterTick = timer_->getMicroseconds(); 486 487 tickTime += timeAfterTick - timeBeforeTick; 488 if (timeAfterTick > refreshStartTime + refreshTime) 489 { 490 GraphicsEngine::getSingleton().setAverageTickTime( 491 (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 492 GraphicsEngine::getSingleton().setAverageFramesPerSecond( 493 (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0); 494 oldFrameCount = frameCount; 495 tickTime = 0; 496 refreshStartTime = timeAfterTick; 497 } 498 499 500 // don't forget to call _fireFrameStarted in ogre to make sure 501 // everything goes smoothly 502 Ogre::FrameEvent evt; 503 evt.timeSinceLastFrame = dt; 504 evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway 505 ogreRoot._fireFrameStarted(evt); 506 507 if (mode_ != DEDICATED) 508 { 509 // Pump messages in all registered RenderWindows 510 // This calls the WindowEventListener objects. 511 Ogre::WindowEventUtilities::messagePump(); 512 // make sure the window stays active even when not focused 513 // (probably only necessary on windows) 514 GraphicsEngine::getSingleton().setWindowActivity(true); 515 516 // render 517 ogreRoot._updateAllRenderTargets(); 518 } 519 520 // again, just to be sure ogre works fine 521 ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 522 523 ++frameCount; 524 } 525 526 if (mode_ == CLIENT) 527 network::Client::getSingleton()->closeConnection(); 528 else if (mode_ == SERVER) 529 server_g->close(); 530 531 return true; 472 // get current time 473 timeBeforeTickOld = timeBeforeTick; 474 timeBeforeTick = timer_->getMicroseconds(); 475 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; 476 477 // check whether we have to load a game 478 if (mode_.mode != modeRequest_.mode && mode_.mode == GameMode::Unspecified) 479 { 480 this->loadLevel(modeRequest_); 481 this->modeRequest_ = GameMode::GM_None; 482 } 483 484 485 // tick the core (needs real time for input and tcl thread management) 486 Core::tick(dt); 487 488 // Call those objects that need the real time 489 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 490 it->tick(dt); 491 // Call the scene objects 492 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 493 it->tick(dt * this->timefactor_); 494 495 // call server/client with normal dt 496 if (client_g) 497 client_g->tick(dt * this->timefactor_); 498 if (server_g) 499 server_g->tick(dt * this->timefactor_); 500 501 502 // get current time once again 503 timeAfterTick = timer_->getMicroseconds(); 504 505 tickTime += timeAfterTick - timeBeforeTick; 506 if (timeAfterTick > refreshStartTime + refreshTime) 507 { 508 GraphicsEngine::getSingleton().setAverageTickTime( 509 (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 510 float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0; 511 GraphicsEngine::getSingleton().setAverageFramesPerSecond(avgFPS); 512 513 if (avgFPS > 60.0) 514 sleepTime++; 515 else 516 sleepTime--; 517 if (sleepTime < 0) 518 sleepTime = 0; 519 520 oldFrameCount = frameCount; 521 tickTime = 0; 522 refreshStartTime = timeAfterTick; 523 } 524 525 // do some sleeping when the frameRate is over 60 526 if (sleepTime > 0) 527 msleep(sleepTime); 528 529 530 // don't forget to call _fireFrameStarted in ogre to make sure 531 // everything goes smoothly 532 Ogre::FrameEvent evt; 533 evt.timeSinceLastFrame = dt; 534 evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway 535 ogreRoot._fireFrameStarted(evt); 536 537 if (mode_.showsGraphics) 538 { 539 // Pump messages in all registered RenderWindows 540 // This calls the WindowEventListener objects. 541 Ogre::WindowEventUtilities::messagePump(); 542 // make sure the window stays active even when not focused 543 // (probably only necessary on windows) 544 GraphicsEngine::getSingleton().setWindowActivity(true); 545 546 // tick CEGUI 547 GUIManager::getInstance().tick(dt); 548 549 // render 550 ogreRoot._updateAllRenderTargets(); 551 } 552 553 // again, just to be sure ogre works fine 554 ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 555 556 ++frameCount; 557 } 558 } 559 catch (std::exception& ex) 560 { 561 // something went wrong. 562 COUT(1) << ex.what() << std::endl; 563 COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl; 564 } 532 565 } 533 566 } -
code/branches/gui/src/orxonox/Orxonox.h
r1625 r1638 22 22 * Author: 23 23 * Reto Grieder 24 * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 24 25 * Co-authors: 25 * Benjamin Knecht <beni_at_orxonox.net>, (C) 200726 * ... 26 27 * 27 28 */ … … 41 42 42 43 #include <OgrePrerequisites.h> 44 45 #include "core/OrxonoxClass.h" 43 46 #include "audio/AudioPrereqs.h" 47 #include "GraphicsEngine.h" 48 #include "Settings.h" 44 49 45 #include "GraphicsEngine.h" 46 47 namespace orxonox { 48 49 enum gameMode{ 50 SERVER, 51 CLIENT, 52 STANDALONE, 53 DEDICATED 54 }; 55 50 namespace orxonox 51 { 56 52 //! Orxonox singleton class 57 class _OrxonoxExport Orxonox53 class _OrxonoxExport Orxonox : public OrxonoxClass 58 54 { 59 55 public: 60 bool init(int argc, char **argv); 61 bool start(); 56 Orxonox(); 57 ~Orxonox(); 58 59 void start(); 60 void setConfigValues(); 62 61 63 62 void abortRequest(); 64 63 65 static Orxonox* getSingleton(); 66 static void destroySingleton(); 64 static Orxonox& getSingleton(); 67 65 68 static inline void slomo(float factor) { Orxonox::setTimeFactor(factor); } 66 static void slomo(float factor) { Orxonox::setTimeFactor(factor); } 67 static float getTimeFactor() { return Orxonox::getSingleton().timefactor_; } 68 static void loadGame(const std::string& name); 69 static void exit() { Orxonox::getSingleton().abortRequest(); } 69 70 static void setTimeFactor(float factor = 1.0); 70 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; }71 static inline void exit() { Orxonox::getSingleton()->abortRequest(); }72 71 73 72 private: 74 73 // don't mess with singletons 75 Orxonox();76 74 Orxonox(Orxonox& instance); 77 Orxonox& operator=(const Orxonox& instance);78 ~Orxonox();79 75 80 bool loadPlayground(); 81 76 bool loadLevel(const GameMode& mode); 82 77 bool serverLoad(); 83 78 bool clientLoad(); 84 79 bool standaloneLoad(); 85 80 81 bool loadPlayground(); 86 82 bool loadScene(); 87 88 bool startRenderLoop(); 89 90 float calculateEventTime(unsigned long, std::deque<unsigned long>&); 83 void startRenderLoop(); 91 84 92 85 private: … … 101 94 102 95 // this is used to identify the mode (server/client/...) we're in 103 gameMode mode_; 104 std::string serverIp_; 105 int serverPort_; 96 GameMode mode_; 97 GameMode modeRequest_; 98 99 // config values 100 float debugRefreshTime_; 106 101 107 102 static Orxonox *singletonRef_s; -
code/branches/gui/src/orxonox/OrxonoxStableHeaders.h
r1631 r1638 45 45 # define WIN32_LEAN_AND_MEAN 46 46 #endif 47 // not including the entire Ogre.h doesn't exceed the default heap size for pch 48 //#include <Ogre.h> 49 #include <OgreBillboardSet.h> 50 #include <OgreCamera.h> 51 #include <OgreColourValue.h> 52 #include <OgreConfigFile.h> 53 #include <OgreEntity.h> 54 #include <OgreException.h> 55 #include <OgreFrameListener.h> 56 #include <OgreLight.h> 57 #include <OgreLog.h> 58 #include <OgreLogManager.h> 59 #include <OgreMath.h> 60 #include <OgreMatrix3.h> 61 #include <OgreMatrix4.h> 62 #include <OgreMesh.h> 63 #include <OgreOverlay.h> 64 #include <OgreOverlayElement.h> 65 #include <OgreOverlayManager.h> 66 #include <OgreParticleEmitter.h> 67 #include <OgreParticleSystem.h> 68 #include <OgreQuaternion.h> 69 #include <OgreResourceGroupManager.h> 70 #include <OgreRenderWindow.h> 71 #include <OgreRoot.h> 72 #include <OgreSceneManager.h> 73 #include <OgreSceneNode.h> 74 #include <OgreString.h> 75 #include <OgreStringConverter.h> 76 #include <OgreTextureManager.h> 77 #include <OgreTimer.h> 78 #include <OgreVector2.h> 79 #include <OgreVector3.h> 80 #include <OgreVector3.h> 81 #include <OgreViewport.h> 82 #include <OgreWindowEventUtilities.h> 47 48 #include <Ogre.h> 49 #include <CEGUI.h> 50 #include <boost/thread/recursive_mutex.hpp> 83 51 84 52 //----------------------------------------------------------------------- … … 86 54 //----------------------------------------------------------------------- 87 55 88 #include "ois/OIS.h"89 #include "cpptcl/CppTcl.h"90 56 #include "tinyxml/ticpp.h" 91 57 #include "tinyxml/tinyxml.h" … … 104 70 #include "core/CoreIncludes.h" 105 71 #include "core/ConfigValueIncludes.h" 72 #include "core/CommandExecutor.h" 106 73 #include "core/Debug.h" 74 #include "core/Executor.h" 107 75 #include "core/OutputBuffer.h" 108 76 #include "core/OutputHandler.h" 109 #include "core/Executor.h"110 77 #include "core/XMLPort.h" 111 78 -
code/branches/gui/src/orxonox/Radar.cc
r1625 r1638 34 34 #include "OrxonoxStableHeaders.h" 35 35 #include "Radar.h" 36 #include <float.h> 36 #include <cfloat> 37 #include <cassert> 37 38 #include "objects/WorldEntity.h" 38 39 #include "objects/SpaceShip.h" -
code/branches/gui/src/orxonox/RadarViewable.h
r1625 r1638 32 32 #include "OrxonoxPrereqs.h" 33 33 #include <string> 34 #include <cassert> 34 35 #include "util/Math.h" 35 36 #include "core/Debug.h" -
code/branches/gui/src/orxonox/Settings.cc
r1535 r1638 28 28 29 29 /** 30 @file 31 @brief Implementation of the Settings class. 30 @file 31 @brief 32 Implementation of the Settings class. 32 33 */ 33 34 … … 35 36 #include "Settings.h" 36 37 38 #include "util/String.h" 37 39 #include "core/CoreIncludes.h" 38 40 #include "core/ConfigValueIncludes.h" … … 40 42 namespace orxonox 41 43 { 42 /**43 @brief Constructor: Registers the object and sets the config-values.44 */45 Settings::Settings()46 {47 RegisterRootObject(Settings);48 setConfigValues();49 }50 44 51 Settings::~Settings() 52 { 53 } 45 // Using a macro makes the above list much more readable. 46 // Settings::addGameMode adds the mode in a map, so we can access game modes by string. 47 #define CreateGameMode(name, showsGraphics, isMaster, hasServer) \ 48 const GameMode GameMode::GM_##name = { GameMode::name, showsGraphics, isMaster, hasServer, #name }; \ 49 bool temporaryVariable##name = Settings::addGameMode(&GameMode::GM_##name) 54 50 55 /** 56 @brief Returns a unique instance of Core. 57 @return The instance 58 */ 59 Settings& Settings::getSingleton() 60 { 61 static Settings instance; 62 return instance; 63 } 51 // showsGraphics isMaster hasServer 52 CreateGameMode(None, false, false, false); 53 CreateGameMode(Unspecified, true, false, false); 54 CreateGameMode(Server, true, true, true ); 55 CreateGameMode(Client, true, false, false); 56 CreateGameMode(Standalone, true, true, false); 57 CreateGameMode(Dedicated, false, true, true ); 64 58 65 /** 66 @brief Function to collect the SetConfigValue-macro calls. 67 */ 68 void Settings::setConfigValues() 69 { 70 SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data."); 71 if (dataPath_ != "" && dataPath_[dataPath_.size() - 1] != '/') 59 /** 60 @brief 61 Constructor: Registers the object and sets the config-values. 62 */ 63 Settings::Settings() 72 64 { 73 ModifyConfigValue(dataPath_, set, dataPath_ + "/"); 65 RegisterRootObject(Settings); 66 gameMode_ = GameMode::GM_Unspecified; 67 setConfigValues(); 74 68 } 75 69 76 if (dataPath_ == "") 70 /** 71 @brief 72 Returns a unique instance of Core. 73 @return 74 The instance 75 */ 76 Settings& Settings::getInstance() 77 77 { 78 ModifyConfigValue(dataPath_, set, "/");79 COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl;78 static Settings instance; 79 return instance; 80 80 } 81 }82 81 83 /** 84 @brief Temporary sets the data path 85 @param path The new data path 86 */ 87 void Settings::_tsetDataPath(const std::string& path) 88 { 89 ModifyConfigValue(dataPath_, tset, path); 90 } 82 /** 83 @brief 84 Function to collect the SetConfigValue-macro calls. 85 */ 86 void Settings::setConfigValues() 87 { 88 SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data."); 89 if (dataPath_ != "" && dataPath_[dataPath_.size() - 1] != '/') 90 { 91 ModifyConfigValue(dataPath_, set, dataPath_ + "/"); 92 } 91 93 92 /*static*/ void Settings::tsetDataPath(const std::string& path) 93 { 94 getSingleton()._tsetDataPath(path); 95 } 94 if (dataPath_ == "") 95 { 96 ModifyConfigValue(dataPath_, set, "/"); 97 COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl; 98 } 99 } 96 100 97 /** 98 @brief Returns the relative path to the game data. 99 @return The path to the game data 100 */ 101 /*static*/ const std::string& Settings::getDataPath() 102 { 103 return getSingleton().dataPath_; 104 } 101 /** 102 @brief 103 Temporary sets the data path 104 @param path 105 The new data path 106 */ 107 void Settings::_tsetDataPath(const std::string& path) 108 { 109 ModifyConfigValue(dataPath_, tset, path); 110 } 111 112 /** 113 @brief 114 Sets the game mode. 115 */ 116 /*static*/ void Settings::setGameMode(const std::string& mode) 117 { 118 std::string modeL = getLowercase(mode); 119 std::map<std::string, const GameMode*>::const_iterator it = getInstance().gameModes_.find(modeL); 120 if (it != getInstance().gameModes_.end()) 121 getInstance().gameMode_ = *(*it).second; 122 else 123 { 124 COUT(2) << "Warning: mode \"" << mode << "\" doesn't exist. " 125 << "Defaulting to 'Standalone'" << std::endl; 126 getInstance().gameMode_ = GameMode::GM_Standalone; 127 } 128 } 129 130 /*static*/ bool Settings::addGameMode(const GameMode* mode) 131 { 132 getInstance().gameModes_[getLowercase(mode->name)] = mode; 133 return true; 134 } 135 136 137 /** 138 @brief 139 Gets an argument from the command line by name. 140 @return 141 Is 0 if name was not found. 142 */ 143 /*static*/ const Settings::CommandLineArgument* Settings::getCommandLineArgument(const std::string &name) 144 { 145 std::map<std::string, CommandLineArgument>::const_iterator it = getInstance().commandArguments_.find(name); 146 if (it != getInstance().commandArguments_.end()) 147 { 148 return &((*it).second); 149 } 150 else 151 return 0; 152 } 153 105 154 } -
code/branches/gui/src/orxonox/Settings.h
r1535 r1638 29 29 /** 30 30 @file Core.h 31 @brief De finition of the Settings class.31 @brief Declaration of the Settings class. 32 32 33 33 The static Settings class is only used to configure some variables … … 41 41 #include <string> 42 42 #include "core/OrxonoxClass.h" 43 #include "core/Debug.h" 44 #include "util/MultiTypeMath.h" 45 #include "util/Convert.h" 43 46 44 47 namespace orxonox 45 48 { 46 class _OrxonoxExport Settings : public OrxonoxClass 47 { 49 /** 50 @brief 51 Defines a bit field structure that holds the mode as enum plus 52 the attributes as single named bits. 53 Every different GameMode is stored as static const, but if you wish to 54 compare two modes, you will have to use the 'mode' member variable. 55 */ 56 struct GameMode 57 { 58 enum Mode 59 { 60 None, 61 Unspecified, 62 Server, 63 Client, 64 Standalone, 65 Dedicated, 66 }; 67 68 Mode mode; 69 bool showsGraphics; 70 bool isMaster; 71 bool hasServer; 72 std::string name; 73 74 static const GameMode GM_None; 75 static const GameMode GM_Unspecified; 76 static const GameMode GM_Server; 77 static const GameMode GM_Client; 78 static const GameMode GM_Standalone; 79 static const GameMode GM_Dedicated; 80 }; 81 82 83 class _OrxonoxExport Settings : public OrxonoxClass 84 { 48 85 public: 49 void setConfigValues(); 86 struct CommandLineArgument 87 { 88 std::string name_; 89 MultiTypeMath value_; 90 bool bHasDefaultValue_; 91 }; 50 92 51 static const std::string& getDataPath();93 void setConfigValues(); 52 94 53 static void tsetDataPath(const std::string& path); 95 static const std::string& getDataPath(); 96 static void tsetDataPath(const std::string& path); 97 98 static const GameMode& getGameMode(); 99 static const GameMode& getGameMode(const std::string& name); 100 static void setGameMode(const GameMode& mode); 101 static void setGameMode(const std::string& mode); 102 static bool addGameMode(const GameMode* mode); 103 104 static const CommandLineArgument* getCommandLineArgument(const std::string& name); 105 template <class T> 106 static bool addCommandLineArgument(const std::string &name, const std::string& valueStr, const T& defaultValue); 54 107 55 108 private: 56 Settings();57 Settings(const Settings& instance);58 ~Settings();59 static Settings& getSingleton();109 Settings(); 110 Settings(const Settings& instance); 111 ~Settings() { } 112 static Settings& getInstance(); 60 113 61 void _tsetDataPath(const std::string& path);114 void _tsetDataPath(const std::string& path); 62 115 63 std::string dataPath_; //!< Path to the game data 64 }; 116 std::string dataPath_; //!< Path to the game data 117 GameMode gameMode_; //!< Current game mode 118 std::map<std::string, const GameMode*> gameModes_; //!< Holds all game modes for easy string access 119 //! holds all command line arguments (even if not given!) 120 std::map<std::string, CommandLineArgument> commandArguments_; 121 }; 122 123 /** 124 @brief 125 Returns the relative path to the game data. 126 */ 127 inline const std::string& Settings::getDataPath() 128 { 129 return getInstance().dataPath_; 130 } 131 132 inline void Settings::tsetDataPath(const std::string& path) 133 { 134 getInstance()._tsetDataPath(path); 135 } 136 137 inline const GameMode& Settings::getGameMode() 138 { 139 return getInstance().gameMode_; 140 } 141 142 inline const GameMode& Settings::getGameMode(const std::string& name) 143 { 144 if (getInstance().gameModes_.find(name) != getInstance().gameModes_.end()) 145 return *getInstance().gameModes_[name]; 146 else 147 { 148 COUT(2) << "Warning: GameMode '" << name << "' doesn't exist." << std::endl; 149 return GameMode::GM_None; 150 } 151 } 152 153 inline void Settings::setGameMode(const GameMode& mode) 154 { 155 getInstance().gameMode_ = mode; 156 } 157 158 /** 159 @brief 160 Adds one argument of the command line to the map of command line arguments. 161 @param name 162 Name of the command line option. 163 @param valueStr 164 The value of the command line option as string 165 @param defaultValue 166 Default value for the option (marked when used). 167 @return 168 Dummy return value to enable code execution before main(). 169 */ 170 template <class T> 171 bool Settings::addCommandLineArgument(const std::string &name, const std::string& valueStr, const T& defaultValue) 172 { 173 T value; 174 bool useDefault = false; 175 if (valueStr == "") 176 { 177 // note: ArgReader only returns "" for not found arguments, " " otherwise for empty ones. 178 value = defaultValue; 179 useDefault = true; 180 } 181 else if (!convertValue(&value, valueStr)) 182 { 183 COUT(1) << "Command Line: Couldn't read option '" << name << "'." << std::endl; 184 return false; 185 } 186 CommandLineArgument arg = { name, MultiTypeMath(value), useDefault }; 187 getInstance().commandArguments_[name] = arg; 188 return true; 189 } 65 190 } 66 191 -
code/branches/gui/src/orxonox/objects/Ambient.cc
r1625 r1638 65 65 66 66 bool Ambient::create(){ 67 GraphicsEngine::getSingleton().get SceneManager()->setAmbientLight(ambientLight_);67 GraphicsEngine::getSingleton().getLevelSceneManager()->setAmbientLight(ambientLight_); 68 68 return Synchronisable::create(); 69 69 } … … 76 76 void Ambient::setAmbientLight(const ColourValue& colour) 77 77 { 78 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour);78 GraphicsEngine::getSingleton().getLevelSceneManager()->setAmbientLight(colour); 79 79 ambientLight_=colour; 80 80 } -
code/branches/gui/src/orxonox/objects/Backlight.cc
r1608 r1638 58 58 this->attachObject(this->billboard_.getBillboardSet()); 59 59 60 this->ribbonTrail_ = GraphicsEngine::getSingleton().get SceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");61 this->ribbonTrailNode_ = GraphicsEngine::getSingleton().get SceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");60 this->ribbonTrail_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail"); 61 this->ribbonTrailNode_ = GraphicsEngine::getSingleton().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode"); 62 62 this->ribbonTrailNode_->attachObject(this->ribbonTrail_); 63 63 this->ribbonTrail_->addNode(this->getNode()); … … 68 68 this->ribbonTrail_->setMaterialName("Trail/backlighttrail"); 69 69 70 this->setTimeFactor(Orxonox::getSingleton() ->getTimeFactor());70 this->setTimeFactor(Orxonox::getSingleton().getTimeFactor()); 71 71 } 72 72 … … 76 76 { 77 77 this->detachObject(this->billboard_.getBillboardSet()); 78 GraphicsEngine::getSingleton().get SceneManager()->destroySceneNode(this->getName() + "RibbonTrailNode");79 GraphicsEngine::getSingleton().get SceneManager()->destroyRibbonTrail(this->ribbonTrail_);78 GraphicsEngine::getSingleton().getLevelSceneManager()->destroySceneNode(this->getName() + "RibbonTrailNode"); 79 GraphicsEngine::getSingleton().getLevelSceneManager()->destroyRibbonTrail(this->ribbonTrail_); 80 80 } 81 81 } -
code/branches/gui/src/orxonox/objects/Camera.cc
r1505 r1638 52 52 { 53 53 this->bHasFocus_ = false; 54 this->cameraNode_ = GraphicsEngine::getSingleton().get SceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera");54 this->cameraNode_ = GraphicsEngine::getSingleton().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera"); 55 55 if( node != NULL ) 56 56 this->setPositionNode(node); … … 60 60 { 61 61 CameraHandler::getInstance()->releaseFocus(this); 62 GraphicsEngine::getSingleton().get SceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName());62 GraphicsEngine::getSingleton().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName()); 63 63 } 64 64 -
code/branches/gui/src/orxonox/objects/CameraHandler.cc
r1505 r1638 44 44 CameraHandler::CameraHandler() 45 45 { 46 this->cam_ = GraphicsEngine::getSingleton().getSceneManager()->createCamera("Cam"); 47 GraphicsEngine::getSingleton().getRenderWindow()->addViewport(this->cam_); 46 this->cam_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createCamera("Cam"); 47 GraphicsEngine::getSingleton().getLevelViewport()->setCamera(this->cam_); 48 GraphicsEngine::getSingleton().getRenderWindow()->addViewport(this->cam_, 2, 0.4, 0.4, 0.2, 0.2); 48 49 /*this->activeCamera_ = *ObjectList<Camera>::begin(); 49 50 this->activeCamera_->cam_ = this->cam_;*/ -
code/branches/gui/src/orxonox/objects/ParticleSpawner.cc
r1608 r1638 79 79 this->setPosition(this->getNode()->getParent()->getPosition()); 80 80 this->getNode()->getParent()->removeChild(this->getNode()); 81 GraphicsEngine::getSingleton().get SceneManager()->getRootSceneNode()->addChild(this->getNode());81 GraphicsEngine::getSingleton().getLevelSceneManager()->getRootSceneNode()->addChild(this->getNode()); 82 82 if (this->particle_) 83 83 this->particle_->setEnabled(false); -
code/branches/gui/src/orxonox/objects/Projectile.cc
r1602 r1638 75 75 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second"); 76 76 77 77 if(this->owner_) 78 78 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 79 79 } -
code/branches/gui/src/orxonox/objects/Skybox.cc
r1558 r1638 56 56 void Skybox::setSkybox(const std::string& skyboxname) 57 57 { 58 GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname);58 GraphicsEngine::getSingleton().getLevelSceneManager()->setSkyBox(true, skyboxname); 59 59 } 60 60 … … 92 92 { 93 93 BaseObject::changedVisibility(); 94 GraphicsEngine::getSingleton().get SceneManager()->setSkyBox(this->isVisible(), this->skyboxSrc_);94 GraphicsEngine::getSingleton().getLevelSceneManager()->setSkyBox(this->isVisible(), this->skyboxSrc_); 95 95 } 96 96 } -
code/branches/gui/src/orxonox/objects/Tickable.h
r1535 r1638 29 29 /*! 30 30 @file Tickable.h 31 @brief De finition of the Tickable interface.31 @brief Declaration of the Tickable interface. 32 32 33 33 The Tickable interface provides a tick(dt) function, that gets called every frame. -
code/branches/gui/src/orxonox/objects/WorldEntity.cc
r1625 r1638 49 49 RegisterObject(WorldEntity); 50 50 51 if (GraphicsEngine::getSingleton().get SceneManager())51 if (GraphicsEngine::getSingleton().getLevelSceneManager()) 52 52 { 53 53 std::ostringstream name; 54 54 name << (WorldEntity::worldEntityCounter_s++); 55 55 this->setName("WorldEntity" + name.str()); 56 this->node_ = GraphicsEngine::getSingleton().get SceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());56 this->node_ = GraphicsEngine::getSingleton().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName()); 57 57 58 58 registerAllVariables(); … … 77 77 { 78 78 this->getNode()->removeAndDestroyAllChildren(); 79 GraphicsEngine::getSingleton().get SceneManager()->destroySceneNode(this->getName());79 GraphicsEngine::getSingleton().getLevelSceneManager()->destroySceneNode(this->getName()); 80 80 } 81 81 } … … 178 178 void WorldEntity::attachObject(const WorldEntity& obj) const 179 179 { 180 GraphicsEngine::getSingleton().get SceneManager()->getRootSceneNode()->removeChild(obj.getNode());180 GraphicsEngine::getSingleton().getLevelSceneManager()->getRootSceneNode()->removeChild(obj.getNode()); 181 181 this->getNode()->addChild(obj.getNode()); 182 182 } … … 184 184 void WorldEntity::attachObject(WorldEntity* obj) const 185 185 { 186 GraphicsEngine::getSingleton().get SceneManager()->getRootSceneNode()->removeChild(obj->getNode());186 GraphicsEngine::getSingleton().getLevelSceneManager()->getRootSceneNode()->removeChild(obj->getNode()); 187 187 this->getNode()->addChild(obj->getNode()); 188 188 } -
code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
r1633 r1638 59 59 @brief Constructor: Creates and initializes the InGameConsole. 60 60 */ 61 InGameConsole::InGameConsole() : 62 consoleOverlay_(0), consoleOverlayContainer_(0), 63 consoleOverlayNoise_(0), consoleOverlayCursor_(0), consoleOverlayBorder_(0), 64 consoleOverlayTextAreas_(0) 61 InGameConsole::InGameConsole() 62 : consoleOverlay_(0) 63 , consoleOverlayContainer_(0) 64 , consoleOverlayNoise_(0) 65 , consoleOverlayCursor_(0) 66 , consoleOverlayBorder_(0) 67 , consoleOverlayTextAreas_(0) 68 , emptySceneManager_(0) 69 , emptyCamera_(0) 70 , viewport_(0) 65 71 { 66 72 RegisterObject(InGameConsole); … … 188 194 189 195 Shell::getInstance().addOutputLevel(true); 196 197 // create a sceneManager in order to render in our own viewport 198 this->emptySceneManager_ = Ogre::Root::getSingleton() 199 .createSceneManager(Ogre::ST_GENERIC, "Console/EmptySceneManager"); 200 this->emptyCamera_ = this->emptySceneManager_->createCamera("Console/EmptyCamera"); 201 this->viewport_ = GraphicsEngine::getSingleton().getRenderWindow()->addViewport(emptyCamera_, 10); 202 this->viewport_->setOverlaysEnabled(true); 203 this->viewport_->setClearEveryFrame(false); 190 204 191 205 COUT(4) << "Info: InGameConsole initialized" << std::endl; … … 476 490 { 477 491 this->bActive_ = true; 478 InputManager:: setInputState(InputManager::IS_CONSOLE);492 InputManager::requestEnterState("console"); 479 493 Shell::getInstance().registerListener(this); 480 494 … … 498 512 { 499 513 this->bActive_ = false; 500 InputManager:: setInputState(InputManager::IS_NORMAL);514 InputManager::requestLeaveState("console"); 501 515 Shell::getInstance().unregisterListener(this); 502 516 -
code/branches/gui/src/orxonox/overlays/console/InGameConsole.h
r1625 r1638 45 45 class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener, public WindowEventListener 46 46 { 47 48 49 50 47 public: // functions 48 void initialise(); 49 void destroy(); 50 void setConfigValues(); 51 51 52 52 void tick(float dt); 53 53 54 54 static InGameConsole& getInstance(); 55 55 56 57 56 static void openConsole(); 57 static void closeConsole(); 58 58 59 60 61 62 59 private: // functions 60 InGameConsole(); 61 InGameConsole(const InGameConsole& other) {} 62 ~InGameConsole(); 63 63 64 65 64 void activate(); 65 void deactivate(); 66 66 67 68 69 70 71 72 67 void linesChanged(); 68 void onlyLastLineChanged(); 69 void lineAdded(); 70 void inputChanged(); 71 void cursorChanged(); 72 void exit(); 73 73 74 75 76 77 74 void shiftLines(); 75 void colourLine(int colourcode, int index); 76 void setCursorPosition(unsigned int pos); 77 void print(const std::string& text, int index, bool alwaysShift = false); 78 78 79 79 void windowResized(int newWidth, int newHeight); 80 80 81 81 static Ogre::UTFString convert2UTF(std::string s); 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 83 private: // variables 84 bool bActive_; 85 int windowW_; 86 int windowH_; 87 int desiredTextWidth_; 88 unsigned int maxCharsPerLine_; 89 unsigned int numLinesShifted_; 90 int scroll_; 91 float cursor_; 92 unsigned int inputWindowStart_; 93 bool bShowCursor_; 94 std::string displayedText_; 95 Ogre::Overlay* consoleOverlay_; 96 Ogre::OverlayContainer* consoleOverlayContainer_; 97 Ogre::PanelOverlayElement* consoleOverlayNoise_; 98 Ogre::TextAreaOverlayElement* consoleOverlayCursor_; 99 Ogre::BorderPanelOverlayElement* consoleOverlayBorder_; 100 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 101 101 102 // config values 103 float relativeWidth; 104 float relativeHeight; 105 float blinkTime; 106 float scrollSpeed_; 107 float noiseSize_; 108 char cursorSymbol_; 102 Ogre::SceneManager* emptySceneManager_; //!< dummy SceneManager to render overlays in empty windows 103 Ogre::Camera* emptyCamera_; //!< dummy camera to render overlays in empty windows 104 Ogre::Viewport* viewport_; 105 106 // config values 107 float relativeWidth; 108 float relativeHeight; 109 float blinkTime; 110 float scrollSpeed_; 111 float noiseSize_; 112 char cursorSymbol_; 109 113 }; 110 114 } -
code/branches/gui/src/orxonox/overlays/hud/HUDSpeedBar.cc
r1626 r1638 54 54 float v = ship->getVelocity().length(); 55 55 float value = v / ship->getMaxSpeed(); 56 56 if (value != this->getValue()) 57 57 this->setValue(value); 58 58 } -
code/branches/gui/src/orxonox/tolua/tolua.pkg
r1505 r1638 1 $cfile "../../src/orxonox/gui/GUIManager.h" -
code/branches/gui/src/orxonox/tools/BillboardSet.cc
r1602 r1638 50 50 std::ostringstream name; 51 51 name << (BillboardSet::billboardSetCounter_s++); 52 this->billboardSet_ = GraphicsEngine::getSingleton().get SceneManager()->createBillboardSet("Billboard" + name.str(), count);52 this->billboardSet_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 53 53 this->billboardSet_->createBillboard(Vector3::ZERO); 54 54 this->billboardSet_->setMaterialName(file); … … 59 59 std::ostringstream name; 60 60 name << (BillboardSet::billboardSetCounter_s++); 61 this->billboardSet_ = GraphicsEngine::getSingleton().get SceneManager()->createBillboardSet("Billboard" + name.str(), count);61 this->billboardSet_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 62 62 this->billboardSet_->createBillboard(Vector3::ZERO, colour); 63 63 this->billboardSet_->setMaterialName(file); … … 68 68 std::ostringstream name; 69 69 name << (BillboardSet::billboardSetCounter_s++); 70 this->billboardSet_ = GraphicsEngine::getSingleton().get SceneManager()->createBillboardSet("Billboard" + name.str(), count);70 this->billboardSet_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 71 71 this->billboardSet_->createBillboard(position); 72 72 this->billboardSet_->setMaterialName(file); … … 77 77 std::ostringstream name; 78 78 name << (BillboardSet::billboardSetCounter_s++); 79 this->billboardSet_ = GraphicsEngine::getSingleton().get SceneManager()->createBillboardSet("Billboard" + name.str(), count);79 this->billboardSet_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 80 80 this->billboardSet_->createBillboard(position, colour); 81 81 this->billboardSet_->setMaterialName(file); … … 85 85 { 86 86 if (this->billboardSet_) 87 GraphicsEngine::getSingleton().get SceneManager()->destroyBillboardSet(this->billboardSet_);87 GraphicsEngine::getSingleton().getLevelSceneManager()->destroyBillboardSet(this->billboardSet_); 88 88 } 89 89 } -
code/branches/gui/src/orxonox/tools/Light.cc
r1505 r1638 49 49 std::ostringstream name; 50 50 name << (Light::lightCounter_s++); 51 this->light_ = GraphicsEngine::getSingleton().get SceneManager()->createLight("Light" + name.str());51 this->light_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createLight("Light" + name.str()); 52 52 this->light_->setType(type); 53 53 this->light_->setDiffuseColour(diffuse); … … 58 58 { 59 59 if (this->light_) 60 GraphicsEngine::getSingleton().get SceneManager()->destroyLight(this->light_);60 GraphicsEngine::getSingleton().getLevelSceneManager()->destroyLight(this->light_); 61 61 } 62 62 } -
code/branches/gui/src/orxonox/tools/Mesh.cc
r1505 r1638 49 49 std::ostringstream name; 50 50 name << (Mesh::meshCounter_s++); 51 this->entity_ = GraphicsEngine::getSingleton().get SceneManager()->createEntity("Mesh" + name.str(), file);51 this->entity_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createEntity("Mesh" + name.str(), file); 52 52 } 53 53 … … 55 55 { 56 56 if (this->entity_) 57 GraphicsEngine::getSingleton().get SceneManager()->destroyEntity(this->entity_);57 GraphicsEngine::getSingleton().getLevelSceneManager()->destroyEntity(this->entity_); 58 58 } 59 59 } -
code/branches/gui/src/orxonox/tools/ParticleInterface.cc
r1563 r1638 55 55 this->bEnabled_ = true; 56 56 this->detaillevel_ = (unsigned int)detaillevel; 57 this->particleSystem_ = GraphicsEngine::getSingleton().get SceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);58 this->particleSystem_->setSpeedFactor(Orxonox::getSingleton() ->getTimeFactor());57 this->particleSystem_ = GraphicsEngine::getSingleton().getLevelSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 58 this->particleSystem_->setSpeedFactor(Orxonox::getSingleton().getTimeFactor()); 59 59 60 60 if (GraphicsEngine::getSingleton().getDetailLevelParticle() < (unsigned int)this->detaillevel_) … … 72 72 { 73 73 this->particleSystem_->removeAllEmitters(); 74 GraphicsEngine::getSingleton().get SceneManager()->destroyParticleSystem(particleSystem_);74 GraphicsEngine::getSingleton().getLevelSceneManager()->destroyParticleSystem(particleSystem_); 75 75 } 76 76 … … 171 171 void ParticleInterface::setSpeedFactor(float factor) 172 172 { 173 this->particleSystem_->setSpeedFactor(Orxonox::getSingleton() ->getTimeFactor() * factor);173 this->particleSystem_->setSpeedFactor(Orxonox::getSingleton().getTimeFactor() * factor); 174 174 } 175 175 float ParticleInterface::getSpeedFactor() const 176 176 { 177 return (this->particleSystem_->getSpeedFactor() / Orxonox::getSingleton() ->getTimeFactor());177 return (this->particleSystem_->getSpeedFactor() / Orxonox::getSingleton().getTimeFactor()); 178 178 } 179 179 -
code/branches/gui/src/orxonox/tools/WindowEventListener.h
r1625 r1638 45 45 virtual ~WindowEventListener() { } 46 46 47 48 47 /** Window has moved position */ 48 virtual void windowMoved() { } 49 49 50 51 50 /** Window has resized */ 51 virtual void windowResized(int newWidth, int newHeight) { } 52 52 53 54 53 /** Window has lost/gained focus */ 54 virtual void windowFocusChanged() { } 55 55 }; 56 56 }
Note: See TracChangeset
for help on using the changeset viewer.