Changeset 1293 for code/trunk/src/orxonox/GraphicsEngine.cc
- Timestamp:
- May 15, 2008, 5:44:55 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/GraphicsEngine.cc
r1220 r1293 9 9 * modify it under the terms of the GNU General Public License 10 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version.12 * 11 * of the License, or (atl your option) any later version. 12 *lo 13 13 * This program is distributed in the hope that it will be useful, 14 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of … … 44 44 #include "core/ConfigValueIncludes.h" 45 45 #include "core/Debug.h" 46 #include "core/ TclBind.h"46 #include "core/CommandExecutor.h" 47 47 48 48 … … 53 53 @return The only instance of GraphicsEngine. 54 54 */ 55 GraphicsEngine& GraphicsEngine::getSingleton()55 /*static*/ GraphicsEngine& GraphicsEngine::getSingleton() 56 56 { 57 57 static GraphicsEngine theOnlyInstance; … … 62 62 @brief Only use constructor to initialise variables and pointers! 63 63 */ 64 GraphicsEngine::GraphicsEngine() 64 GraphicsEngine::GraphicsEngine() : 65 root_(0), 66 scene_(0), 67 renderWindow_(0), 68 //configPath_(""), 69 dataPath_(""), 70 ogreLogfile_("") 65 71 { 66 72 RegisterObject(GraphicsEngine); 67 //this->bOverwritePath_ = false; 73 68 74 this->setConfigValues(); 69 // set to standard values 70 this->configPath_ = ""; 71 this->root_ = 0; 72 this->scene_ = 0; 73 this->renderWindow_ = 0; 74 COUT(4) << "*** GraphicsEngine: Constructed" << std::endl; 75 CCOUT(4) << "Constructed" << std::endl; 76 } 77 78 void GraphicsEngine::setConfigValues() 79 { 80 SetConfigValue(dataPath_, "../../Media/").description("relative path to media data"); 81 SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use \"\" to suppress log file creation."); 82 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 83 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 84 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 75 85 } 76 86 … … 89 99 void GraphicsEngine::destroy() 90 100 { 91 C OUT(4) << "*** GraphicsEngine:Destroying objects..." << std::endl;101 CCOUT(4) << "Destroying objects..." << std::endl; 92 102 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this); 93 103 if (this->root_) … … 103 113 delete Ogre::LogManager::getSingletonPtr(); 104 114 } 105 COUT(4) << "*** GraphicsEngine: Destroying objects done" << std::endl; 106 } 107 108 void GraphicsEngine::setConfigValues() 109 { 110 SetConfigValue(dataPath_, "../../Media/").description("relative path to media data"); 111 SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use \"\" to suppress log file creation."); 112 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 113 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 114 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 115 116 TclBind::getInstance().setDataPath(this->dataPath_); 115 CCOUT(4) << "Destroying objects done" << std::endl; 117 116 } 118 117 … … 120 119 @brief Creates the Ogre Root object and sets up the ogre log. 121 120 */ 122 void GraphicsEngine::setup() 123 { 121 bool GraphicsEngine::setup(std::string& dataPath) 122 { 123 CCOUT(3) << "Setting up..." << std::endl; 124 // temporary overwrite of dataPath, change ini file for permanent change 125 if (dataPath != "") 126 dataPath_ = dataPath; 127 if (dataPath_ == "") 128 return false; 129 if (dataPath_[dataPath_.size() - 1] != '/') 130 dataPath_ += "/"; 131 124 132 //TODO: Check if file exists (maybe not here) 125 /*#ifndef OGRE_STATIC_LIB126 root_ = new Ogre::Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg",127 configPath_ + "Ogre.log");128 #else129 root_ = new Ogre::Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");130 #endif*/131 133 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) 132 134 std::string plugin_filename = "plugins_d.cfg"; … … 135 137 #endif 136 138 137 // create a logManager 138 Ogre::LogManager *logger; 139 if (Ogre::LogManager::getSingletonPtr() == 0) 140 logger = new Ogre::LogManager(); 141 else 142 logger = Ogre::LogManager::getSingletonPtr(); 143 COUT(4) << "*** GraphicsEngine: Ogre LogManager created/assigned" << std::endl; 139 /* // create a logManager 140 // note: If there's already a logManager, Ogre will complain by a failed assertation. 141 // but that shouldn't happen, since this is the first time to create a logManager.. 142 Ogre::LogManager* logger = new Ogre::LogManager(); 143 CCOUT(4) << "Ogre LogManager created" << std::endl; 144 144 145 145 // create our own log that we can listen to … … 148 148 myLog = logger->createLog("ogre.log", true, false, true); 149 149 else 150 myLog = logger->createLog(this->ogreLogfile_, true, false, false);151 C OUT(4) << "*** GraphicsEngine:Ogre Log created" << std::endl;150 myLog = logger->createLog(this->ogreLogfile_, true, false, false); 151 CCOUT(4) << "Ogre Log created" << std::endl; 152 152 153 153 myLog->setLogDetail(Ogre::LL_BOREME); 154 myLog->addListener(this); 154 myLog->addListener(this);*/ 155 155 156 156 // Root will detect that we've already created a Log 157 C OUT(4) << "*** GraphicsEngine:Creating Ogre Root..." << std::endl;157 CCOUT(4) << "Creating Ogre Root..." << std::endl; 158 158 root_ = new Ogre::Root(plugin_filename); 159 COUT(4) << "*** GraphicsEngine: Creating Ogre Root done" << std::endl; 160 } 161 162 /** 163 * @return scene manager 164 */ 165 Ogre::SceneManager* GraphicsEngine::getSceneManager() 166 { 167 if(!scene_) 168 { 169 scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 170 COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl; 171 } 172 return scene_; 173 } 174 175 bool GraphicsEngine::load(std::string dataPath) 176 { 177 // temporary overwrite of dataPath, change ini file for permanent change 178 if( dataPath != "" ) 179 dataPath_ = dataPath + "/"; 180 loadRessourceLocations(this->dataPath_); 181 if (!root_->restoreConfig() && !root_->showConfigDialog()) 182 return false; 159 CCOUT(4) << "Creating Ogre Root done" << std::endl; 160 161 // specify where Ogre has to look for resources. This call doesn't parse anything yet! 162 declareRessourceLocations(); 163 164 CCOUT(3) << "Set up done." << std::endl; 183 165 return true; 184 166 } 185 167 186 void GraphicsEngine::initialise() 187 { 188 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 189 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 190 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 191 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 192 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 193 } 194 195 void GraphicsEngine::loadRessourceLocations(std::string dataPath) 196 { 168 void GraphicsEngine::declareRessourceLocations() 169 { 170 CCOUT(4) << "Declaring Resources" << std::endl; 197 171 //TODO: Specify layout of data file and maybe use xml-loader 198 172 //TODO: Work with ressource groups (should be generated by a special loader) 199 173 // Load resource paths from data file using configfile ressource type 200 174 Ogre::ConfigFile cf; 201 cf.load(dataPath + "resources.cfg");175 cf.load(dataPath_ + "resources.cfg"); 202 176 203 177 // Go through all sections & settings in the file … … 216 190 217 191 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 218 std::string(dataPath + archName),192 std::string(dataPath_ + archName), 219 193 typeName, secName); 220 194 } 221 195 } 196 } 197 198 bool GraphicsEngine::loadRenderer() 199 { 200 CCOUT(4) << "Configuring Renderer" << std::endl; 201 if (!root_->restoreConfig() && !root_->showConfigDialog()) 202 return false; 203 204 CCOUT(4) << "Creating render window" << std::endl; 205 this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); 206 if (!root_->isInitialised()) 207 { 208 CCOUT(2) << "Error: Creating Ogre root object failed" << std::endl; 209 return false; 210 } 211 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 212 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 213 return true; 214 } 215 216 bool GraphicsEngine::initialiseResources() 217 { 218 CCOUT(4) << "Initialising resources" << std::endl; 219 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 220 try 221 { 222 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 223 /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups(); 224 for (unsigned int i = 0; i < str.size(); i++) 225 { 226 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]); 227 }*/ 228 } 229 catch (Ogre::Exception e) 230 { 231 CCOUT(2) << "Error: There was an Error when initialising the resources." << std::endl; 232 CCOUT(2) << "ErrorMessage: " << e.getFullDescription() << std::endl; 233 return false; 234 } 235 return true; 236 } 237 238 /** 239 * @brief Creates the SceneManager 240 */ 241 bool GraphicsEngine::createNewScene() 242 { 243 CCOUT(4) << "Creating new SceneManager" << std::endl; 244 if (scene_) 245 { 246 CCOUT(2) << "SceneManager already exists! Skipping." << std::endl; 247 return false; 248 } 249 scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 250 CCOUT(3) << "Created SceneManager: " << scene_ << std::endl; 251 return true; 222 252 } 223 253 … … 291 321 } 292 322 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 293 << "*** Ogre: " << message << std::endl; 294 } 295 296 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw){ 297 int w = rw->getWidth(); 298 int h = rw->getHeight(); 299 InputManager::setWindowExtents(w, h); 300 } 301 302 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw){ 303 int w = rw->getWidth(); 304 int h = rw->getHeight(); 305 InputManager::setWindowExtents(w, h); 306 } 307 308 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw){ 309 int w = rw->getWidth(); 310 int h = rw->getHeight(); 311 InputManager::setWindowExtents(w, h); 312 } 323 << "Ogre: " << message << std::endl; 324 } 325 326 /** 327 * Window has resized. 328 * @param rw The render window it occured in 329 */ 330 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw) 331 { 332 // note: this doesn't change the window extents 333 } 334 335 /** 336 * Window has resized. 337 * @param rw The render window it occured in 338 * @note GraphicsEngine has a render window stored itself. This is the same 339 * as rw. But we have to be careful when using multiple render windows! 340 */ 341 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) 342 { 343 // change the mouse clipping size for absolute mouse movements 344 int w = rw->getWidth(); 345 int h = rw->getHeight(); 346 InputManager::setWindowExtents(w, h); 347 } 348 349 /** 350 * Window has resized. 351 * @param rw The render window it occured in 352 */ 353 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw) 354 { 355 // note: this doesn't change the window extents 356 } 357 358 /** 359 * Window has resized. 360 * @param rw The render window it occured in 361 */ 362 void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw) 363 { 364 // using CommandExecutor in order to avoid depending on Orxonox class. 365 CommandExecutor::execute("exit", false); 366 } 313 367 }
Note: See TracChangeset
for help on using the changeset viewer.