[Orxonox-commit 891] r5614 - in code/branches/resource2/src: core orxonox/gamestates
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Aug 10 17:36:45 CEST 2009
Author: rgrieder
Date: 2009-08-10 17:36:45 +0200 (Mon, 10 Aug 2009)
New Revision: 5614
Modified:
code/branches/resource2/src/core/Core.cc
code/branches/resource2/src/core/GraphicsManager.cc
code/branches/resource2/src/core/GraphicsManager.h
code/branches/resource2/src/orxonox/gamestates/GSLevel.cc
Log:
Creating Ogre::Root in non graphics mode as well. This allows to always make use of the ResourceGroupManager.
Also removed resource related parts from GraphicsManager.
This revision does not run!
Modified: code/branches/resource2/src/core/Core.cc
===================================================================
--- code/branches/resource2/src/core/Core.cc 2009-08-10 14:44:05 UTC (rev 5613)
+++ code/branches/resource2/src/core/Core.cc 2009-08-10 15:36:45 UTC (rev 5614)
@@ -312,6 +312,9 @@
// creates the class hierarchy for all classes with factories
Factory::createClassHierarchy();
+
+ // Load OGRE excluding the renderer and the render window
+ this->graphicsManager_.reset(new GraphicsManager(false));
}
/**
@@ -327,21 +330,20 @@
if (bGraphicsLoaded_)
return;
- // Load OGRE including the render window
- scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());
+ // Upgrade OGRE to receive a render window
+ graphicsManager_->upgradeToGraphics();
// The render window width and height are used to set up the mouse movement.
size_t windowHnd = 0;
- graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
+ graphicsManager_->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
// Calls the InputManager which sets up the input devices.
scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));
// load the CEGUI interface
- guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow()));
+ guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow()));
- // Dismiss scoped pointers
- graphicsManager_.swap(graphicsManager);
+ // Dismiss scoped pointer
inputManager_.swap(inputManager);
bGraphicsLoaded_ = true;
@@ -356,6 +358,9 @@
this->inputManager_.reset();;
this->graphicsManager_.reset();
+ // Load Ogre::Root again, but without the render system
+ this->graphicsManager_.reset(new GraphicsManager(false));
+
bGraphicsLoaded_ = false;
}
Modified: code/branches/resource2/src/core/GraphicsManager.cc
===================================================================
--- code/branches/resource2/src/core/GraphicsManager.cc 2009-08-10 14:44:05 UTC (rev 5613)
+++ code/branches/resource2/src/core/GraphicsManager.cc 2009-08-10 15:36:45 UTC (rev 5614)
@@ -36,19 +36,14 @@
#include "GraphicsManager.h"
#include <fstream>
-#include <memory>
#include <boost/filesystem.hpp>
-#include <boost/shared_ptr.hpp>
-#include <OgreCompositorManager.h>
-#include <OgreConfigFile.h>
#include <OgreFrameListener.h>
#include <OgreRoot.h>
#include <OgreLogManager.h>
#include <OgreException.h>
#include <OgreRenderWindow.h>
#include <OgreRenderSystem.h>
-#include <OgreTextureManager.h>
#include <OgreViewport.h>
#include <OgreWindowEventUtilities.h>
@@ -67,8 +62,6 @@
namespace orxonox
{
- using boost::shared_ptr;
-
class OgreWindowEventListener : public Ogre::WindowEventListener
{
public:
@@ -88,10 +81,8 @@
@brief
Non-initialising constructor.
*/
- GraphicsManager::GraphicsManager()
- : ogreRoot_(0)
- , ogreLogger_(0)
- , renderWindow_(0)
+ GraphicsManager::GraphicsManager(bool bLoadRenderer)
+ : renderWindow_(0)
, viewport_(0)
, ogreWindowEventListener_(new OgreWindowEventListener())
{
@@ -99,63 +90,28 @@
this->setConfigValues();
- // Ogre setup procedure
- setupOgre();
+ // Ogre setup procedure (creating Ogre::Root)
+ this->loadOgreRoot();
+ // load all the required plugins for Ogre
+ this->loadOgrePlugins();
- try
+ if (bLoadRenderer)
{
- // load all the required plugins for Ogre
- loadOgrePlugins();
- // read resource declaration file
- this->declareResources();
- // Reads ogre config and creates the render window
+ // Reads the ogre config and creates the render window
this->loadRenderer();
-
- // TODO: Spread this
- this->initialiseResources();
-
- // add console commands
- FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
- functor1->setObject(this);
- ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
- CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
}
- catch (...)
- {
- // clean up
- delete this->ogreRoot_;
- delete this->ogreLogger_;
- delete this->ogreWindowEventListener_;
- throw;
- }
}
/**
@brief
- Destroys all the Ogre related objects
+ Destruction is done by the member scoped_ptrs.
*/
GraphicsManager::~GraphicsManager()
{
-/*
- delete this->ccPrintScreen_;
-*/
-
- // unload all compositors (this is only necessary because we don't yet destroy all resources!)
- Ogre::CompositorManager::getSingleton().removeAll();
-
- // Delete OGRE main control organ
- delete this->ogreRoot_;
-
- // delete the logManager (since we have created it in the first place).
- delete this->ogreLogger_;
-
- delete this->ogreWindowEventListener_;
}
void GraphicsManager::setConfigValues()
{
- SetConfigValue(resourceFile_, "resources.cfg")
- .description("Location of the resources file in the data path.");
SetConfigValue(ogreConfigFile_, "ogre.cfg")
.description("Location of the Ogre config file");
SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER)
@@ -172,47 +128,25 @@
.description("Corresponding orxonox debug level for ogre Critical");
}
- void GraphicsManager::update(const Clock& time)
+ /**
+ @brief
+ Loads the renderer and creates the render window if not yet done so.
+ @remarks
+ This operation is irreversible without recreating the GraphicsManager!
+ */
+ void GraphicsManager::upgradeToGraphics()
{
- Ogre::FrameEvent evt;
- evt.timeSinceLastFrame = time.getDeltaTime();
- evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
-
- // don't forget to call _fireFrameStarted to OGRE to make sure
- // everything goes smoothly
- ogreRoot_->_fireFrameStarted(evt);
-
- // Pump messages in all registered RenderWindows
- // This calls the WindowEventListener objects.
- Ogre::WindowEventUtilities::messagePump();
- // make sure the window stays active even when not focused
- // (probably only necessary on windows)
- this->renderWindow_->setActive(true);
-
- // Time before rendering
- uint64_t timeBeforeTick = time.getRealMicroseconds();
-
- // Render frame
- ogreRoot_->_updateAllRenderTargets();
-
- uint64_t timeAfterTick = time.getRealMicroseconds();
- // Subtract the time used for rendering from the tick time counter
- Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick);
-
- // again, just to be sure OGRE works fine
- ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+ if (renderWindow_ == NULL)
+ {
+ this->loadRenderer();
+ }
}
- void GraphicsManager::setCamera(Ogre::Camera* camera)
- {
- this->viewport_->setCamera(camera);
- }
-
/**
@brief
Creates the Ogre Root object and sets up the ogre log.
*/
- void GraphicsManager::setupOgre()
+ void GraphicsManager::loadOgreRoot()
{
COUT(3) << "Setting up Ogre..." << std::endl;
@@ -232,12 +166,12 @@
// create a new logManager
// Ogre::Root will detect that we've already created a Log
- std::auto_ptr<Ogre::LogManager> logger(new Ogre::LogManager());
+ ogreLogger_.reset(new Ogre::LogManager());
COUT(4) << "Ogre LogManager created" << std::endl;
// create our own log that we can listen to
Ogre::Log *myLog;
- myLog = logger->createLog(ogreLogFilepath.string(), true, false, false);
+ myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
COUT(4) << "Ogre Log created" << std::endl;
myLog->setLogDetail(Ogre::LL_BOREME);
@@ -255,9 +189,7 @@
}
// Leave plugins file empty. We're going to do that part manually later
- ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
- // In case that new Root failed the logger gets destroyed because of the std::auto_ptr
- ogreLogger_ = logger.release();
+ ogreRoot_.reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()));
COUT(3) << "Ogre set up done." << std::endl;
}
@@ -276,58 +208,6 @@
ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
}
- void GraphicsManager::declareResources()
- {
- CCOUT(4) << "Declaring Resources" << std::endl;
- //TODO: Specify layout of data file and maybe use xml-loader
- //TODO: Work with ressource groups (should be generated by a special loader)
-
- if (resourceFile_ == "")
- {
- COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
- ModifyConfigValue(resourceFile_, tset, "resources.cfg");
- }
-
- // Load resource paths from data file using configfile ressource type
- Ogre::ConfigFile cf;
- try
- {
- cf.load((Core::getMediaPath() / resourceFile_).string());
- }
- catch (...)
- {
- //COUT(1) << ex.getFullDescription() << std::endl;
- COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
- throw;
- }
-
- // Go through all sections & settings in the file
- Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
-
- std::string secName, typeName, archName;
- while (seci.hasMoreElements())
- {
- try
- {
- secName = seci.peekNextKey();
- Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
- Ogre::ConfigFile::SettingsMultiMap::iterator i;
- for (i = settings->begin(); i != settings->end(); ++i)
- {
- typeName = i->first; // for instance "FileSystem" or "Zip"
- archName = i->second; // name (and location) of archive
-
- Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
- (Core::getMediaPath() / archName).string(), typeName, secName);
- }
- }
- catch (Ogre::Exception& ex)
- {
- COUT(1) << ex.getFullDescription() << std::endl;
- }
- }
- }
-
void GraphicsManager::loadRenderer()
{
CCOUT(4) << "Configuring Renderer" << std::endl;
@@ -339,36 +219,59 @@
CCOUT(4) << "Creating render window" << std::endl;
this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
+ // Propagate the size of the new winodw
this->ogreWindowEventListener_->windowResized(renderWindow_);
- Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
+ Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_.get());
- Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
-
// create a full screen default viewport
+ // Note: This may throw when adding a viewport with an existing z-order!
+ // But in our case we only have one viewport for now anyway, therefore
+ // no ScopeGuards or anything to handle exceptions.
this->viewport_ = this->renderWindow_->addViewport(0, 0);
+
+ // add console commands
+ FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
+ ccPrintScreen_ = createConsoleCommand(functor1->setObject(this), "printScreen");
+ CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
}
- void GraphicsManager::initialiseResources()
+ void GraphicsManager::update(const Clock& time)
{
- CCOUT(4) << "Initialising resources" << std::endl;
- //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
- //try
- //{
- Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
- /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
- for (unsigned int i = 0; i < str.size(); i++)
- {
- Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
- }*/
- //}
- //catch (...)
- //{
- // CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
- // throw;
- //}
+ Ogre::FrameEvent evt;
+ evt.timeSinceLastFrame = time.getDeltaTime();
+ evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
+
+ // don't forget to call _fireFrameStarted to OGRE to make sure
+ // everything goes smoothly
+ ogreRoot_->_fireFrameStarted(evt);
+
+ // Pump messages in all registered RenderWindows
+ // This calls the WindowEventListener objects.
+ Ogre::WindowEventUtilities::messagePump();
+ // make sure the window stays active even when not focused
+ // (probably only necessary on windows)
+ this->renderWindow_->setActive(true);
+
+ // Time before rendering
+ uint64_t timeBeforeTick = time.getRealMicroseconds();
+
+ // Render frame
+ ogreRoot_->_updateAllRenderTargets();
+
+ uint64_t timeAfterTick = time.getRealMicroseconds();
+ // Subtract the time used for rendering from the tick time counter
+ Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick);
+
+ // again, just to be sure OGRE works fine
+ ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
}
+ void GraphicsManager::setCamera(Ogre::Camera* camera)
+ {
+ this->viewport_->setCamera(camera);
+ }
+
/**
@brief
Method called by the LogListener interface from Ogre.
Modified: code/branches/resource2/src/core/GraphicsManager.h
===================================================================
--- code/branches/resource2/src/core/GraphicsManager.h 2009-08-10 14:44:05 UTC (rev 5613)
+++ code/branches/resource2/src/core/GraphicsManager.h 2009-08-10 15:36:45 UTC (rev 5614)
@@ -41,11 +41,15 @@
#include <cassert>
#include <string>
#include <OgreLog.h>
+#include <boost/scoped_ptr.hpp>
+
#include "util/Singleton.h"
#include "OrxonoxClass.h"
namespace orxonox
{
+ using boost::scoped_ptr;
+
/**
@brief
Graphics engine manager class
@@ -54,29 +58,28 @@
{
friend class Singleton<GraphicsManager>;
public:
- GraphicsManager();
+ GraphicsManager(bool bLoadRenderer = true);
~GraphicsManager();
void setConfigValues();
void update(const Clock& time);
- inline Ogre::Viewport* getViewport()
- { return this->viewport_; }
- inline Ogre::RenderWindow* getRenderWindow()
- { return this->renderWindow_; }
+ Ogre::Viewport* getViewport() { return this->viewport_; }
+ Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
+ void upgradeToGraphics();
+ bool rendererLoaded() const { return renderWindow_ != NULL; }
+
void setCamera(Ogre::Camera* camera);
private:
GraphicsManager(GraphicsManager&); // don't mess with singletons
// OGRE initialisation
- void setupOgre();
+ void loadOgreRoot();
void loadOgrePlugins();
- void declareResources();
void loadRenderer();
- void initialiseResources();
// event from Ogre::LogListener
void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
@@ -86,14 +89,13 @@
void printScreen();
private:
- Ogre::Root* ogreRoot_; //!< Ogre's root
- Ogre::LogManager* ogreLogger_;
+ scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
+ scoped_ptr<Ogre::LogManager> ogreLogger_;
+ scoped_ptr<Ogre::Root> ogreRoot_; //!< Ogre's root
Ogre::RenderWindow* renderWindow_; //!< the one and only render window
Ogre::Viewport* viewport_; //!< default full size viewport
- OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
// config values
- std::string resourceFile_; //!< resources file name
std::string ogreConfigFile_; //!< ogre config file name
std::string ogrePluginsFolder_; //!< Folder where the Ogre plugins are located
std::string ogrePlugins_; //!< Comma separated list of all plugins to load
Modified: code/branches/resource2/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/resource2/src/orxonox/gamestates/GSLevel.cc 2009-08-10 14:44:05 UTC (rev 5613)
+++ code/branches/resource2/src/orxonox/gamestates/GSLevel.cc 2009-08-10 15:36:45 UTC (rev 5614)
@@ -29,6 +29,8 @@
#include "GSLevel.h"
+#include <OgreCompositorManager.h>
+
#include "core/input/InputManager.h"
#include "core/input/InputState.h"
#include "core/input/KeyBinder.h"
@@ -169,6 +171,11 @@
}
*/
+ if (GameMode::showsGraphics())
+ {
+ // unload all compositors (this is only necessary because we don't yet destroy all resources!)
+ Ogre::CompositorManager::getSingleton().removeAll();
+ }
// this call will delete every BaseObject!
// But currently this will call methods of objects that exist no more
More information about the Orxonox-commit
mailing list