Changeset 1686
- Timestamp:
- Aug 31, 2008, 2:37:00 PM (16 years ago)
- Location:
- code/branches/gui/src
- Files:
-
- 2 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/GameState.h
r1674 r1686 118 118 void deactivate(); 119 119 120 const std::string 121 Operations 122 GameState* 123 GameState* 124 //bool 125 std::map<std::string, GameState*> 126 std::map<GameState*, GameState*> grandchildrenToChildren_;120 const std::string name_; 121 Operations operation_; 122 GameState* parent_; 123 GameState* activeChild_; 124 //bool bPauseParent_; 125 std::map<std::string, GameState*> allChildren_; 126 std::map<GameState*, GameState*> grandchildrenToChildren_; 127 127 }; 128 128 } -
code/branches/gui/src/orxonox/GraphicsEngine.cc
r1653 r1686 37 37 #include "GraphicsEngine.h" 38 38 39 #include <fstream> 40 41 #include <OgreConfigFile.h> 42 #include <OgreException.h> 43 #include <OgreLogManager.h> 44 #include <OgreRoot.h> 45 #include <OgreSceneManager.h> 46 #include <OgreTextureManager.h> 47 #include <OgreViewport.h> 39 #include <OgreRenderWindow.h> 48 40 49 41 #include "core/CoreIncludes.h" 50 42 #include "core/ConfigValueIncludes.h" 51 43 #include "core/Debug.h" 52 #include "core/CommandExecutor.h"53 #include "core/ConsoleCommand.h"54 #include "core/Exception.h"55 44 56 #include "overlays/console/InGameConsole.h"57 #include "overlays/OverlayGroup.h"58 45 #include "tools/ParticleInterface.h" 59 #include "Settings.h"60 #include "tools/WindowEventListener.h"61 62 #include "objects/CameraHandler.h"63 46 64 47 namespace orxonox 65 48 { 66 SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress);49 //SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress); 67 50 68 51 GraphicsEngine* GraphicsEngine::singletonRef_s = 0; … … 103 86 void GraphicsEngine::setConfigValues() 104 87 { 105 SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path.");106 SetConfigValue(ogreConfigFile_, "ogre.cfg").description("Location of the Ogre config file");107 SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");108 SetConfigValue(ogreLogFile_, "ogre.log").description("Logfile for messages from Ogre. \109 Use \"\" to suppress log file creation.");110 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");111 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal");112 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");113 114 88 unsigned int old = this->detailLevelParticle_; 115 89 SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high"); … … 126 100 GraphicsEngine::~GraphicsEngine() 127 101 { 128 CCOUT(4) << "Destroying objects..." << std::endl;129 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);130 if (this->root_)131 delete this->root_;132 133 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32134 // delete the ogre log and the logManager (since we have created it).135 if (Ogre::LogManager::getSingletonPtr() != 0)136 {137 Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this);138 Ogre::LogManager::getSingleton().destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());139 delete Ogre::LogManager::getSingletonPtr();140 }141 CCOUT(4) << "Destroying objects done" << std::endl;142 #endif143 144 102 singletonRef_s = 0; 145 }146 147 /**148 @brief149 Creates the Ogre Root object and sets up the ogre log.150 */151 void GraphicsEngine::setup()152 {153 CCOUT(3) << "Setting up..." << std::endl;154 155 // TODO: LogManager doesn't work on oli platform. The why is yet unknown.156 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32157 // create a new logManager158 Ogre::LogManager* logger = new Ogre::LogManager();159 CCOUT(4) << "Ogre LogManager created" << std::endl;160 161 // create our own log that we can listen to162 Ogre::Log *myLog;163 if (this->ogreLogFile_ == "")164 myLog = logger->createLog("ogre.log", true, false, true);165 else166 myLog = logger->createLog(this->ogreLogFile_, true, false, false);167 CCOUT(4) << "Ogre Log created" << std::endl;168 169 myLog->setLogDetail(Ogre::LL_BOREME);170 myLog->addListener(this);171 #endif172 173 // Root will detect that we've already created a Log174 CCOUT(4) << "Creating Ogre Root..." << std::endl;175 176 if (ogrePluginsFile_ == "")177 {178 COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;179 ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");180 }181 if (ogreConfigFile_ == "")182 {183 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;184 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");185 }186 if (ogreLogFile_ == "")187 {188 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;189 ModifyConfigValue(ogreLogFile_, tset, "ogre.log");190 }191 192 root_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);193 194 // We don't need plugins for the dedicated..195 //if (!root_->getInstalledPlugins().size() > 0)196 //{197 // ThrowException(PluginsNotFound, "No Ogre plugins declared. Cannot load Ogre.");198 //}199 200 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)201 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32202 // tame the ogre ouput so we don't get all the mess in the console203 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();204 defaultLog->setDebugOutputEnabled(false);205 defaultLog->setLogDetail(Ogre::LL_BOREME);206 defaultLog->addListener(this);207 #endif208 #endif209 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 declareRessourceLocations();214 215 CCOUT(3) << "Set up done." << std::endl;216 }217 218 void GraphicsEngine::declareRessourceLocations()219 {220 CCOUT(4) << "Declaring Resources" << std::endl;221 //TODO: Specify layout of data file and maybe use xml-loader222 //TODO: Work with ressource groups (should be generated by a special loader)223 224 if (resourceFile_ == "")225 {226 COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;227 ModifyConfigValue(resourceFile_, tset, "resources.cfg");228 }229 230 // Load resource paths from data file using configfile ressource type231 Ogre::ConfigFile cf;232 try233 {234 cf.load(Settings::getDataPath() + resourceFile_);235 }236 catch (...)237 {238 //COUT(1) << ex.getFullDescription() << std::endl;239 COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;240 throw;241 }242 243 // Go through all sections & settings in the file244 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();245 246 std::string secName, typeName, archName;247 while (seci.hasMoreElements())248 {249 try250 {251 secName = seci.peekNextKey();252 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();253 Ogre::ConfigFile::SettingsMultiMap::iterator i;254 for (i = settings->begin(); i != settings->end(); ++i)255 {256 typeName = i->first; // for instance "FileSystem" or "Zip"257 archName = i->second; // name (and location) of archive258 259 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(260 std::string(Settings::getDataPath() + archName), typeName, secName);261 }262 }263 catch (Ogre::Exception& ex)264 {265 COUT(1) << ex.getFullDescription() << std::endl;266 }267 }268 }269 270 void GraphicsEngine::loadRenderer()271 {272 CCOUT(4) << "Configuring Renderer" << std::endl;273 274 // check for file existence because Ogre displays exceptions if not275 std::ifstream probe;276 probe.open(ogreConfigFile_.c_str());277 if (!probe)278 {279 // create a zero sized file280 std::ofstream creator;281 creator.open(ogreConfigFile_.c_str());282 creator.close();283 }284 else285 probe.close();286 287 if (!root_->restoreConfig())288 if (!root_->showConfigDialog())289 ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");290 291 CCOUT(4) << "Creating render window" << std::endl;292 293 this->renderWindow_ = root_->initialise(true, "OrxonoxV2");294 295 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);296 297 //Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);298 299 // create a full screen default viewport300 this->viewport_ = this->renderWindow_->addViewport(0, 0);301 }302 303 void GraphicsEngine::initialiseResources()304 {305 CCOUT(4) << "Initialising resources" << std::endl;306 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...307 try308 {309 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();310 /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();311 for (unsigned int i = 0; i < str.size(); i++)312 {313 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);314 }*/315 }316 catch (...)317 {318 CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;319 throw;320 }321 }322 323 /**324 @brief325 Creates the SceneManager326 */327 void GraphicsEngine::createNewScene()328 {329 CCOUT(4) << "Creating new SceneManager..." << std::endl;330 if (levelSceneManager_)331 {332 CCOUT(2) << "SceneManager already exists! Skipping." << std::endl;333 }334 this->levelSceneManager_ = this->root_->createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");335 CCOUT(3) << "Created SceneManager: " << levelSceneManager_->getName() << std::endl;336 }337 338 /**339 @brief340 Returns the window handle of the render window.341 At least the InputHandler uses this to create the OIS::InputManager342 @return343 The window handle of the render window344 */345 size_t GraphicsEngine::getWindowHandle()346 {347 if (this->renderWindow_)348 {349 size_t windowHnd = 0;350 this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);351 return windowHnd;352 }353 else354 return 0;355 103 } 356 104 … … 396 144 return 1.0f; 397 145 } 398 399 /**400 @brief401 Method called by the LogListener interface from Ogre.402 We use it to capture Ogre log messages and handle it ourselves.403 @param message404 The message to be logged405 @param lml406 The message level the log is using407 @param maskDebug408 If we are printing to the console or not409 @param logName410 The name of this log (so you can have several listeners411 for different logs, and identify them)412 */413 void GraphicsEngine::messageLogged(const std::string& message,414 Ogre::LogMessageLevel lml, bool maskDebug, const std::string &logName)415 {416 int orxonoxLevel;417 switch (lml)418 {419 case Ogre::LML_TRIVIAL:420 orxonoxLevel = this->ogreLogLevelTrivial_;421 break;422 case Ogre::LML_NORMAL:423 orxonoxLevel = this->ogreLogLevelNormal_;424 break;425 case Ogre::LML_CRITICAL:426 orxonoxLevel = this->ogreLogLevelCritical_;427 break;428 default:429 orxonoxLevel = 0;430 }431 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)432 << "Ogre: " << message << std::endl;433 }434 435 /**436 @brief437 Window has moved.438 @param rw439 The render window it occured in440 */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 @brief449 Window has resized.450 @param rw451 The render window it occured in452 @note453 GraphicsEngine has a render window stored itself. This is the same454 as rw. But we have to be careful when using multiple render windows!455 */456 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw)457 {458 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)459 it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());460 }461 462 /**463 @brief464 Window focus has changed.465 @param rw466 The render window it occured in467 */468 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw)469 {470 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)471 it->windowFocusChanged();472 }473 474 /**475 @brief476 Window was closed.477 @param rw478 The render window it occured in479 */480 void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw)481 {482 // using CommandExecutor in order to avoid depending on Orxonox.h.483 CommandExecutor::execute("exit", false);484 }485 486 487 /*static*/ void GraphicsEngine::printScreen()488 {489 if (getInstance().renderWindow_)490 {491 getInstance().renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg");492 }493 }494 146 } -
code/branches/gui/src/orxonox/GraphicsEngine.h
r1653 r1686 42 42 43 43 #include <OgrePrerequisites.h> 44 #include <OgreLog.h>45 #include <OgreRenderWindow.h>46 #include <OgreWindowEventUtilities.h>47 44 #include "core/OrxonoxClass.h" 48 45 … … 52 49 @brief Graphics engine manager class 53 50 */ 54 class _OrxonoxExport GraphicsEngine : public O gre::WindowEventListener, public Ogre::LogListener, public OrxonoxClass51 class _OrxonoxExport GraphicsEngine : public OrxonoxClass 55 52 { 53 // HACK: temporary means 54 friend class GSGraphics; 55 56 56 public: 57 57 GraphicsEngine(); … … 59 59 60 60 void setConfigValues(); 61 void setup();62 void declareRessourceLocations();63 void loadRenderer();64 void initialiseResources();65 void createNewScene();66 61 67 62 void setLevelSceneManager(Ogre::SceneManager* sceneMgr) { this->levelSceneManager_ = sceneMgr; } … … 69 64 70 65 Ogre::Viewport* getViewport() { return this->viewport_; } 66 Ogre::Root* getOgreRoot() { return this->root_; } 71 67 72 68 // several window properties 73 Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }74 size_t getWindowHandle();75 69 int getWindowWidth() const; 76 70 int getWindowHeight() const; … … 81 75 void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; } 82 76 83 void setWindowActivity(bool activity)84 { if (this->renderWindow_) this->renderWindow_->setActive(activity); }85 86 77 inline unsigned int getDetailLevelParticle() const 87 78 { return this->detailLevelParticle_; } 88 89 // console commands90 static void printScreen();91 79 92 80 static GraphicsEngine& getInstance(); … … 95 83 private: 96 84 // don't mess with singletons 97 GraphicsEngine(GraphicsEngine&) { } 98 99 //! Method called by the LogListener from Ogre 100 void messageLogged(const std::string&, Ogre::LogMessageLevel, 101 bool, const std::string&); 102 103 // window events from Ogre::WindowEventListener 104 void windowMoved (Ogre::RenderWindow* rw); 105 void windowResized (Ogre::RenderWindow* rw); 106 void windowFocusChanged(Ogre::RenderWindow* rw); 107 void windowClosed (Ogre::RenderWindow* rw); 85 GraphicsEngine(GraphicsEngine&); 108 86 109 87 Ogre::Root* root_; //!< Ogre's root … … 117 95 118 96 // config values 119 std::string resourceFile_; //!< resources file name120 std::string ogreConfigFile_; //!< ogre config file name121 std::string ogrePluginsFile_; //!< ogre plugins file name122 std::string ogreLogFile_; //!< log file name for Ogre log messages123 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL124 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL125 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL126 97 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 127 98 -
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 } -
code/branches/gui/src/orxonox/gui/GUIManager.cc
r1670 r1686 117 117 } 118 118 119 bool GUIManager::initialise( )119 bool GUIManager::initialise(Ogre::RenderWindow* renderWindow) 120 120 { 121 121 using namespace CEGUI; … … 126 126 try 127 127 { 128 // getthe render window129 renderWindow_ = GraphicsEngine::getInstance().getRenderWindow();128 // save the render window 129 renderWindow_ = renderWindow; 130 130 131 131 // Full screen viewport with Z order = 0 (top most). Don't yet feed a camera (so nothing gets rendered) -
code/branches/gui/src/orxonox/gui/GUIManager.h
r1661 r1686 64 64 ~GUIManager(); 65 65 66 bool initialise( );66 bool initialise(Ogre::RenderWindow* renderWindow); 67 67 void tick(float dt) 68 68 { -
code/branches/gui/src/orxonox/objects/Backlight.cc
r1662 r1686 32 32 #include <OgreBillboard.h> 33 33 #include <OgreRibbonTrail.h> 34 #include <OgreSceneManager.h> 34 35 35 36 #include "core/CoreIncludes.h" -
code/branches/gui/src/orxonox/objects/ParticleSpawner.cc
r1653 r1686 30 30 #include "ParticleSpawner.h" 31 31 32 #include <OgreSceneManager.h> 32 33 #include "core/CoreIncludes.h" 33 34 #include "core/Executor.h" -
code/branches/gui/src/orxonox/objects/WorldEntity.cc
r1653 r1686 32 32 #include <string> 33 33 #include <sstream> 34 #include <OgreSceneManager.h> 34 35 35 36 #include "tinyxml/tinyxml.h" -
code/branches/gui/src/orxonox/objects/WorldEntity.h
r1625 r1686 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include <OgreSceneManager.h> 33 #include <OgrePrerequisites.h> 34 35 35 #include <OgreSceneNode.h> 36 37 36 #include "util/Math.h" 38 37 #include "util/XMLIncludes.h"
Note: See TracChangeset
for help on using the changeset viewer.