Changeset 1686 for code/branches/gui/src/orxonox/gamestates
- Timestamp:
- Aug 31, 2008, 2:37:00 PM (16 years ago)
- Location:
- code/branches/gui/src/orxonox/gamestates
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/gamestates/GSGUI.cc
r1674 r1686 30 30 #include "GSGUI.h" 31 31 32 #include <OgreViewport.h> 32 33 #include "GraphicsEngine.h" 33 34 #include "core/input/InputManager.h" -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r1674 r1686 30 30 #include "GSGraphics.h" 31 31 32 #include <fstream> 33 #include <OgreConfigFile.h> 32 34 #include <OgreFrameListener.h> 33 35 #include <OgreRoot.h> 36 #include <OgreException.h> 37 #include <OgreRenderWindow.h> 38 #include <OgreTextureManager.h> 39 #include <OgreViewport.h> 34 40 #include <OgreWindowEventUtilities.h> 35 #include <OgreRenderWindow.h> 36 41 42 #include "core/Debug.h" 37 43 #include "core/ConsoleCommand.h" 38 44 #include "core/ConfigValueIncludes.h" 45 #include "core/CoreIncludes.h" 39 46 #include "core/input/InputManager.h" 47 #include "core/Exception.h" 40 48 #include "overlays/console/InGameConsole.h" 41 49 #include "gui/GUIManager.h" 50 #include "tools/WindowEventListener.h" 51 #include "Settings.h" 52 53 // for compatibility 42 54 #include "GraphicsEngine.h" 43 55 … … 47 59 : GameState("graphics") 48 60 , ogreRoot_(0) 49 , graphicsEngine_(0)50 61 , inputManager_(0) 51 62 , console_(0) … … 57 68 , tickTime_(0) 58 69 { 70 RegisterRootObject(GSGraphics); 59 71 } 60 72 … … 65 77 void GSGraphics::setConfigValues() 66 78 { 79 SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path."); 67 80 SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated."); 68 81 } … … 73 86 74 87 this->ogreRoot_ = Ogre::Root::getSingletonPtr(); 75 this->graphicsEngine_ = GraphicsEngine::getInstancePtr(); 76 77 graphicsEngine_->loadRenderer(); // creates the render window 78 88 89 this->declareResources(); 90 this->loadRenderer(); // creates the render window 79 91 // TODO: Spread this so that this call only initialises things needed for the Console and GUI 80 graphicsEngine_->initialiseResources(); 92 this->initialiseResources(); 93 94 95 // HACK: temporary: 96 GraphicsEngine& graphicsEngine = GraphicsEngine::getInstance(); 97 graphicsEngine.renderWindow_ = this->renderWindow_; 98 graphicsEngine.root_ = this->ogreRoot_; 99 graphicsEngine.viewport_ = this->viewport_; 100 81 101 82 102 // Calls the InputManager which sets up the input devices. 83 103 // The render window width and height are used to set up the mouse movement. 84 104 inputManager_ = new InputManager(); 85 inputManager_->initialise(graphicsEngine_->getWindowHandle(), 86 graphicsEngine_->getWindowWidth(), graphicsEngine_->getWindowHeight(), true); 105 size_t windowHnd = 0; 106 this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd); 107 inputManager_->initialise(windowHnd, renderWindow_->getWidth(), renderWindow_->getHeight(), true); 87 108 88 109 // Load the InGameConsole … … 92 113 // load the CEGUI interface 93 114 guiManager_ = new GUIManager(); 94 guiManager_->initialise( );115 guiManager_->initialise(this->renderWindow_); 95 116 96 117 // reset frame counter … … 99 120 statisticsStartTime_ = 0; 100 121 statisticsStartCount_ = 0; 122 123 // add console commands 124 FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen); 125 functor1->setObject(this); 126 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen")); 101 127 } 102 128 … … 109 135 delete this->inputManager_; 110 136 111 this->ogreRoot_->detachRenderTarget( GraphicsEngine::getInstance().getRenderWindow());112 delete GraphicsEngine::getInstance().getRenderWindow();137 this->ogreRoot_->detachRenderTarget(this->renderWindow_); 138 delete this->renderWindow_; 113 139 //this->ogreRoot_->shutdown 114 140 // TODO: destroy render window … … 166 192 // make sure the window stays active even when not focused 167 193 // (probably only necessary on windows) 168 GraphicsEngine::getInstance().setWindowActivity(true);194 this->renderWindow_->setActive(true); 169 195 170 196 // render … … 176 202 ++frameCount_; 177 203 } 204 205 void GSGraphics::declareResources() 206 { 207 CCOUT(4) << "Declaring Resources" << std::endl; 208 //TODO: Specify layout of data file and maybe use xml-loader 209 //TODO: Work with ressource groups (should be generated by a special loader) 210 211 if (resourceFile_ == "") 212 { 213 COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl; 214 ModifyConfigValue(resourceFile_, tset, "resources.cfg"); 215 } 216 217 // Load resource paths from data file using configfile ressource type 218 Ogre::ConfigFile cf; 219 try 220 { 221 cf.load(Settings::getDataPath() + resourceFile_); 222 } 223 catch (...) 224 { 225 //COUT(1) << ex.getFullDescription() << std::endl; 226 COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl; 227 throw; 228 } 229 230 // Go through all sections & settings in the file 231 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 232 233 std::string secName, typeName, archName; 234 while (seci.hasMoreElements()) 235 { 236 try 237 { 238 secName = seci.peekNextKey(); 239 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 240 Ogre::ConfigFile::SettingsMultiMap::iterator i; 241 for (i = settings->begin(); i != settings->end(); ++i) 242 { 243 typeName = i->first; // for instance "FileSystem" or "Zip" 244 archName = i->second; // name (and location) of archive 245 246 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 247 std::string(Settings::getDataPath() + archName), typeName, secName); 248 } 249 } 250 catch (Ogre::Exception& ex) 251 { 252 COUT(1) << ex.getFullDescription() << std::endl; 253 } 254 } 255 } 256 257 void GSGraphics::loadRenderer() 258 { 259 CCOUT(4) << "Configuring Renderer" << std::endl; 260 261 if (!ogreRoot_->restoreConfig()) 262 if (!ogreRoot_->showConfigDialog()) 263 ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue."); 264 265 CCOUT(4) << "Creating render window" << std::endl; 266 267 this->renderWindow_ = ogreRoot_->initialise(true, "OrxonoxV2"); 268 269 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this); 270 271 //Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 272 273 // create a full screen default viewport 274 this->viewport_ = this->renderWindow_->addViewport(0, 0); 275 } 276 277 void GSGraphics::initialiseResources() 278 { 279 CCOUT(4) << "Initialising resources" << std::endl; 280 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... 281 try 282 { 283 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 284 /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups(); 285 for (unsigned int i = 0; i < str.size(); i++) 286 { 287 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]); 288 }*/ 289 } 290 catch (...) 291 { 292 CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl; 293 throw; 294 } 295 } 296 297 298 /** 299 @brief 300 Window has moved. 301 @param rw 302 The render window it occured in 303 */ 304 void GSGraphics::windowMoved(Ogre::RenderWindow *rw) 305 { 306 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 307 it->windowMoved(); 308 } 309 310 /** 311 @brief 312 Window has resized. 313 @param rw 314 The render window it occured in 315 @note 316 GraphicsEngine has a render window stored itself. This is the same 317 as rw. But we have to be careful when using multiple render windows! 318 */ 319 void GSGraphics::windowResized(Ogre::RenderWindow *rw) 320 { 321 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 322 it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight()); 323 } 324 325 /** 326 @brief 327 Window focus has changed. 328 @param rw 329 The render window it occured in 330 */ 331 void GSGraphics::windowFocusChanged(Ogre::RenderWindow *rw) 332 { 333 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 334 it->windowFocusChanged(); 335 } 336 337 /** 338 @brief 339 Window was closed. 340 @param rw 341 The render window it occured in 342 */ 343 void GSGraphics::windowClosed(Ogre::RenderWindow *rw) 344 { 345 // using CommandExecutor in order to avoid depending on Orxonox.h. 346 //CommandExecutor::execute("exit", false); 347 this->requestState("root"); 348 } 349 350 void GSGraphics::printScreen() 351 { 352 if (this->renderWindow_) 353 { 354 this->renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg"); 355 } 356 } 178 357 } -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r1674 r1686 32 32 #include "OrxonoxPrereqs.h" 33 33 #include <OgrePrerequisites.h> 34 #include <OgreWindowEventUtilities.h> 34 35 #include "core/GameState.h" 35 36 #include "core/OrxonoxClass.h" … … 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport GSGraphics : public GameState, public OrxonoxClass 40 class _OrxonoxExport GSGraphics : public GameState, public OrxonoxClass, public Ogre::WindowEventListener 40 41 { 42 friend class ClassIdentifier<GSGraphics>; 41 43 public: 42 44 GSGraphics(); 43 45 ~GSGraphics(); 44 45 void setConfigValues();46 46 47 47 private: … … 50 50 void ticked(const Clock& time); 51 51 52 void setConfigValues(); 53 54 void declareResources(); 55 void loadRenderer(); 56 void initialiseResources(); 57 58 void printScreen(); 59 60 // window events from Ogre::WindowEventListener 61 void windowMoved (Ogre::RenderWindow* rw); 62 void windowResized (Ogre::RenderWindow* rw); 63 void windowFocusChanged(Ogre::RenderWindow* rw); 64 void windowClosed (Ogre::RenderWindow* rw); 65 52 66 Ogre::Root* ogreRoot_; 53 GraphicsEngine* graphicsEngine_; //!< pointer to GraphicsEngine instance 67 Ogre::RenderWindow* renderWindow_; //!< the current render window 68 Ogre::Viewport* viewport_; //!< default full size viewport 69 70 // managed singletons 54 71 InputManager* inputManager_; 55 72 InGameConsole* console_; … … 62 79 unsigned long statisticsStartCount_; 63 80 unsigned int tickTime_; 81 82 // config values 83 std::string resourceFile_; //!< resources file name 84 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 64 85 }; 65 86 } -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r1674 r1686 30 30 #include "GSLevel.h" 31 31 32 #include <OgreSceneManager.h> 33 #include <OgreRoot.h> 32 34 #include "core/input/InputManager.h" 33 35 #include "core/input/SimpleInputState.h" … … 45 47 : GameState(name) 46 48 , timeFactor_(1.0f) 49 , sceneManager_(0) 47 50 , keyBinder_(0) 48 51 , inputState_(0) … … 65 68 66 69 // create Ogre SceneManager for the level 67 GraphicsEngine::getInstance().createNewScene(); 70 this->sceneManager_ = GraphicsEngine::getInstance().getOgreRoot()-> 71 createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager"); 72 COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl; 73 GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_); 68 74 69 75 // Start the Radar … … 92 98 delete this->radar_; 93 99 94 // TODO: delete SceneManager100 GraphicsEngine::getInstance().getOgreRoot()->destroySceneManager(this->sceneManager_); 95 101 96 102 inputState_->setHandler(0); -
code/branches/gui/src/orxonox/gamestates/GSLevel.h
r1674 r1686 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include <OgrePrerequisites.h> 33 34 #include "core/GameState.h" 34 35 … … 58 59 float timeFactor_; //!< A factor to change the gamespeed 59 60 61 Ogre::SceneManager* sceneManager_; 60 62 KeyBinder* keyBinder_; //!< tool that loads and manages the input bindings 61 63 SimpleInputState* inputState_; -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r1674 r1686 30 30 #include "GSRoot.h" 31 31 32 #include <OgreLogManager.h> 33 #include <OgreRoot.h> 34 32 35 //#include "util/SubString.h" 33 36 #include "core/Factory.h" 34 37 #include "core/ConfigFileManager.h" 35 38 #include "core/ConfigValueIncludes.h" 39 #include "core/CoreIncludes.h" 36 40 #include "core/ConsoleCommand.h" 37 41 #include "core/CommandLine.h" … … 65 69 : RootGameState("root") 66 70 , settings_(0) 71 , ogreRoot_(0) 72 , ogreLogger_(0) 67 73 , graphicsEngine_(0) 68 74 { 75 RegisterRootObject(GSRoot); 69 76 } 70 77 71 78 GSRoot::~GSRoot() 72 79 { 80 } 81 82 void GSRoot::setConfigValues() 83 { 84 SetConfigValue(ogreConfigFile_, "ogre.cfg").description("Location of the Ogre config file"); 85 SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file"); 86 SetConfigValue(ogreLogFile_, "ogre.log").description("Logfile for messages from Ogre. \ 87 Use \"\" to suppress log file creation."); 88 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 89 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 90 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 73 91 } 74 92 … … 108 126 #endif 109 127 128 // do this after the previous call.. 129 setConfigValues(); 130 110 131 // creates the class hierarchy for all classes with factories 111 132 Factory::createClassHierarchy(); … … 128 149 TclThreadManager::getInstance(); 129 150 151 setupOgre(); 152 130 153 // initialise graphics engine. Doesn't load the render window yet! 131 154 graphicsEngine_ = new GraphicsEngine(); 132 graphicsEngine_->setup(); // creates ogre root and other essentials133 155 134 156 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump … … 151 173 { 152 174 delete graphicsEngine_; 175 176 delete this->ogreRoot_; 177 178 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 179 // delete the ogre log and the logManager (since we have created it). 180 this->ogreLogger_->getDefaultLog()->removeListener(this); 181 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 182 delete this->ogreLogger_; 183 #endif 184 153 185 delete settings_; 154 186 … … 199 231 #endif 200 232 } 233 234 /** 235 @brief 236 Creates the Ogre Root object and sets up the ogre log. 237 */ 238 void GSRoot::setupOgre() 239 { 240 COUT(3) << "Setting up Ogre..." << std::endl; 241 242 // TODO: LogManager doesn't work on oli platform. The why is yet unknown. 243 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 244 // create a new logManager 245 ogreLogger_ = new Ogre::LogManager(); 246 COUT(4) << "Ogre LogManager created" << std::endl; 247 248 // create our own log that we can listen to 249 Ogre::Log *myLog; 250 if (this->ogreLogFile_ == "") 251 myLog = ogreLogger_->createLog("ogre.log", true, false, true); 252 else 253 myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false); 254 COUT(4) << "Ogre Log created" << std::endl; 255 256 myLog->setLogDetail(Ogre::LL_BOREME); 257 myLog->addListener(this); 258 #endif 259 260 // Root will detect that we've already created a Log 261 COUT(4) << "Creating Ogre Root..." << std::endl; 262 263 if (ogrePluginsFile_ == "") 264 { 265 COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl; 266 ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg"); 267 } 268 if (ogreConfigFile_ == "") 269 { 270 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl; 271 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg"); 272 } 273 if (ogreLogFile_ == "") 274 { 275 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl; 276 ModifyConfigValue(ogreLogFile_, tset, "ogre.log"); 277 } 278 279 // check for config file existence because Ogre displays (caught) exceptions if not 280 std::ifstream probe; 281 probe.open(ogreConfigFile_.c_str()); 282 if (!probe) 283 { 284 // create a zero sized file 285 std::ofstream creator; 286 creator.open(ogreConfigFile_.c_str()); 287 creator.close(); 288 } 289 else 290 probe.close(); 291 292 ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_); 293 294 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.) 295 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 296 // tame the ogre ouput so we don't get all the mess in the console 297 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 298 defaultLog->setDebugOutputEnabled(false); 299 defaultLog->setLogDetail(Ogre::LL_BOREME); 300 defaultLog->addListener(this); 301 #endif 302 #endif 303 304 COUT(3) << "Ogre set up done." << std::endl; 305 } 306 307 /** 308 @brief 309 Method called by the LogListener interface from Ogre. 310 We use it to capture Ogre log messages and handle it ourselves. 311 @param message 312 The message to be logged 313 @param lml 314 The message level the log is using 315 @param maskDebug 316 If we are printing to the console or not 317 @param logName 318 The name of this log (so you can have several listeners 319 for different logs, and identify them) 320 */ 321 void GSRoot::messageLogged(const std::string& message, 322 Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName) 323 { 324 int orxonoxLevel; 325 switch (lml) 326 { 327 case Ogre::LML_TRIVIAL: 328 orxonoxLevel = this->ogreLogLevelTrivial_; 329 break; 330 case Ogre::LML_NORMAL: 331 orxonoxLevel = this->ogreLogLevelNormal_; 332 break; 333 case Ogre::LML_CRITICAL: 334 orxonoxLevel = this->ogreLogLevelCritical_; 335 break; 336 default: 337 orxonoxLevel = 0; 338 } 339 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 340 << "Ogre: " << message << std::endl; 341 } 201 342 } -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r1674 r1686 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include <OgreLog.h> 33 34 #include "core/RootGameState.h" 35 #include "core/OrxonoxClass.h" 34 36 35 37 namespace orxonox 36 38 { 37 class _OrxonoxExport GSRoot : public RootGameState 39 class _OrxonoxExport GSRoot : public RootGameState, public Ogre::LogListener, public OrxonoxClass 38 40 { 41 friend class ClassIdentifier<GSRoot>; 39 42 public: 40 43 GSRoot(); … … 51 54 void ticked(const Clock& time); 52 55 56 void setConfigValues(); 57 void messageLogged(const std::string& message, Ogre::LogMessageLevel lml, 58 bool maskDebug, const std::string& logName); 53 59 void setThreadAffinity(); 60 void setupOgre(); 54 61 55 62 Settings* settings_; 63 Ogre::Root* ogreRoot_; //!< Ogre's root 64 Ogre::LogManager* ogreLogger_; 56 65 GraphicsEngine* graphicsEngine_; //!< Interface to Ogre 66 67 std::string ogreConfigFile_; //!< ogre config file name 68 std::string ogrePluginsFile_; //!< ogre plugins file name 69 std::string ogreLogFile_; //!< log file name for Ogre log messages 70 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL 71 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 72 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 57 73 }; 58 74 }
Note: See TracChangeset
for help on using the changeset viewer.