[Orxonox-commit 106] r2801 - in branches/gui/src/orxonox: . gamestates gui objects/worldentities overlays overlays/console overlays/debug tools
rgrieder at orxonox.net
rgrieder at orxonox.net
Thu Mar 19 10:58:43 CET 2009
Author: rgrieder
Date: 2009-03-19 09:58:43 +0000 (Thu, 19 Mar 2009)
New Revision: 2801
Added:
branches/gui/src/orxonox/GraphicsManager.cc
branches/gui/src/orxonox/GraphicsManager.h
Removed:
branches/gui/src/orxonox/GraphicsEngine.cc
branches/gui/src/orxonox/GraphicsEngine.h
Modified:
branches/gui/src/orxonox/CMakeLists.txt
branches/gui/src/orxonox/OrxonoxPrereqs.h
branches/gui/src/orxonox/gamestates/GSClient.cc
branches/gui/src/orxonox/gamestates/GSDedicated.cc
branches/gui/src/orxonox/gamestates/GSGUI.cc
branches/gui/src/orxonox/gamestates/GSGraphics.cc
branches/gui/src/orxonox/gamestates/GSGraphics.h
branches/gui/src/orxonox/gamestates/GSLevel.cc
branches/gui/src/orxonox/gamestates/GSLevel.h
branches/gui/src/orxonox/gamestates/GSServer.cc
branches/gui/src/orxonox/gamestates/GSStandalone.cc
branches/gui/src/orxonox/gui/GUIManager.cc
branches/gui/src/orxonox/objects/worldentities/Planet.cc
branches/gui/src/orxonox/overlays/OrxonoxOverlay.cc
branches/gui/src/orxonox/overlays/OrxonoxOverlay.h
branches/gui/src/orxonox/overlays/console/InGameConsole.cc
branches/gui/src/orxonox/overlays/console/InGameConsole.h
branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc
branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc
branches/gui/src/orxonox/tools/ParticleInterface.cc
branches/gui/src/orxonox/tools/Shader.cc
branches/gui/src/orxonox/tools/WindowEventListener.h
Log:
Move graphic related content of GSGraphics to GraphicsManager which originally was GraphisEngine (but since we don't have an engine of our own, I renamed it).
Reduced OgreWindowEventUtilities.h dependency from GraphisManager.h (includes windows.h).
Modified: branches/gui/src/orxonox/CMakeLists.txt
===================================================================
--- branches/gui/src/orxonox/CMakeLists.txt 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/CMakeLists.txt 2009-03-19 09:58:43 UTC (rev 2801)
@@ -19,7 +19,7 @@
SET_SOURCE_FILES(ORXONOX_SRC_FILES
CameraManager.cc
- GraphicsEngine.cc
+ GraphicsManager.cc
LevelManager.cc
Main.cc
PawnManager.cc
Deleted: branches/gui/src/orxonox/GraphicsEngine.cc
===================================================================
--- branches/gui/src/orxonox/GraphicsEngine.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/GraphicsEngine.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -1,106 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
- * Co-authors:
- * Felix Schulthess
- *
- */
-
-/**
- at file
- at brief
- Implementation of an partial interface to Ogre.
-*/
-
-#include "OrxonoxStableHeaders.h"
-#include "GraphicsEngine.h"
-
-#include <OgreRenderWindow.h>
-
-#include "core/CoreIncludes.h"
-#include "core/ConfigValueIncludes.h"
-#include "util/Debug.h"
-
-#include "tools/ParticleInterface.h"
-
-namespace orxonox
-{
- //SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress);
-
- GraphicsEngine* GraphicsEngine::singletonRef_s = 0;
-
- /**
- @brief
- Returns the singleton instance.
- @return
- The only instance of GraphicsEngine.
- */
- /*static*/ GraphicsEngine& GraphicsEngine::getInstance()
- {
- assert(singletonRef_s);
- return *singletonRef_s;
- }
-
- /**
- @brief
- Non-initialising constructor.
- */
- GraphicsEngine::GraphicsEngine()
-// : root_(0)
-// , renderWindow_(0)
-// , viewport_(0)
- {
- RegisterObject(GraphicsEngine);
-
- assert(singletonRef_s == 0);
- singletonRef_s = this;
-
- this->viewport_ = 0;
-
- this->detailLevelParticle_ = 0;
-
- this->setConfigValues();
- CCOUT(4) << "Constructed" << std::endl;
- }
-
- void GraphicsEngine::setConfigValues()
- {
- SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high").callback(this, &GraphicsEngine::detailLevelParticleChanged);
- }
-
- void GraphicsEngine::detailLevelParticleChanged()
- {
- for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
- it->detailLevelChanged(this->detailLevelParticle_);
- }
-
- /**
- @brief
- Destroys all the Ogre related objects
- */
- GraphicsEngine::~GraphicsEngine()
- {
- singletonRef_s = 0;
- }
-}
Deleted: branches/gui/src/orxonox/GraphicsEngine.h
===================================================================
--- branches/gui/src/orxonox/GraphicsEngine.h 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/GraphicsEngine.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -1,96 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
- * Co-authors:
- * Felix Schulthess
- *
- */
-
-/**
- @file
- @brief Declaration of GraphicsEngine Singleton.
- @author Benjamin Knecht <beni_at_orxonox.net>
- */
-
-#ifndef _GraphicsEngine_H__
-#define _GraphicsEngine_H__
-
-#include "OrxonoxPrereqs.h"
-
-#include <string>
-
-#include <OgrePrerequisites.h>
-#include "core/OrxonoxClass.h"
-
-namespace orxonox
-{
- /**
- @brief Graphics engine manager class
- */
- class _OrxonoxExport GraphicsEngine : public OrxonoxClass
- {
- // HACK: temporary means
- friend class GSGraphics;
-
- public:
- GraphicsEngine();
- ~GraphicsEngine();
-
- void setConfigValues();
- void detailLevelParticleChanged();
-
- float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; }
- float getAverageTickTime() const { return this->avgTickTime_; }
- void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; }
- void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
-
- inline unsigned int getDetailLevelParticle() const
- { return this->detailLevelParticle_; }
-
- static GraphicsEngine& getInstance();
- static GraphicsEngine* getInstancePtr() { return singletonRef_s; }
-
- inline void setViewport(Ogre::Viewport* viewport)
- { this->viewport_ = viewport; }
- inline Ogre::Viewport* getViewport() const
- { return this->viewport_; }
-
- private:
- // don't mess with singletons
- GraphicsEngine(GraphicsEngine&);
-
- Ogre::Viewport* viewport_; //!< default full size viewport
-
- // stats
- float avgTickTime_; //!< time in ms to tick() one frame
- float avgFramesPerSecond_; //!< number of frames processed in one second
-
- // config values
- unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
-
- static GraphicsEngine* singletonRef_s; //!< Pointer to the Singleton
- };
-}
-
-#endif /* _GraphicsEngine_H__ */
Copied: branches/gui/src/orxonox/GraphicsManager.cc (from rev 2797, branches/gui/src/orxonox/GraphicsEngine.cc)
===================================================================
--- branches/gui/src/orxonox/GraphicsManager.cc (rev 0)
+++ branches/gui/src/orxonox/GraphicsManager.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -0,0 +1,442 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ * Co-authors:
+ * Felix Schulthess
+ *
+ */
+
+/**
+ at file
+ at brief
+ Implementation of an partial interface to Ogre.
+*/
+
+#include "OrxonoxStableHeaders.h"
+#include "GraphicsManager.h"
+
+#include <fstream>
+#include <boost/filesystem.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>
+
+#include "SpecialConfig.h"
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "util/String.h"
+#include "util/SubString.h"
+#include "core/ConsoleCommand.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+#include "core/Core.h"
+#include "tools/WindowEventListener.h"
+#include "tools/ParticleInterface.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport OgreWindowEventListener : public Ogre::WindowEventListener
+ {
+ void windowResized (Ogre::RenderWindow* rw);
+ void windowFocusChange (Ogre::RenderWindow* rw);
+ void windowClosed (Ogre::RenderWindow* rw);
+ //void windowMoved (Ogre::RenderWindow* rw);
+ };
+
+ GraphicsManager* GraphicsManager::singletonRef_s = 0;
+
+ /**
+ @brief
+ Non-initialising constructor.
+ */
+ GraphicsManager::GraphicsManager()
+ : ogreRoot_(0)
+ , ogreLogger_(0)
+ , renderWindow_(0)
+ , viewport_(0)
+ , ogreWindowEventListener_(0)
+ , avgTickTime_(0.0f)
+ , avgFramesPerSecond_(0.0f)
+ {
+ RegisterObject(GraphicsManager);
+
+ assert(singletonRef_s == 0);
+ singletonRef_s = this;
+
+ this->loaded_ = false;
+
+ this->setConfigValues();
+ }
+
+ void GraphicsManager::initialise()
+ {
+ Core::setShowsGraphics(true);
+
+ // Ogre setup procedure
+ setupOgre();
+ // load all the required plugins for Ogre
+ loadOgrePlugins();
+ // read resource declaration file
+ this->declareResources();
+ // Reads 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_);
+
+ this->loaded_ = true;
+ }
+
+ /**
+ @brief
+ Destroys all the Ogre related objects
+ */
+ GraphicsManager::~GraphicsManager()
+ {
+ if (this->loaded_)
+ {
+ delete this->ccPrintScreen_;
+
+ if (this->ogreWindowEventListener_)
+ {
+ // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
+ Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this->ogreWindowEventListener_);
+ delete this->ogreWindowEventListener_;
+ }
+
+ // unload all compositors
+ Ogre::CompositorManager::getSingleton().removeAll();
+
+ // destroy render window
+ Ogre::RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
+ renderer->destroyRenderWindow("Orxonox");
+
+ // Delete OGRE main control organ
+ delete this->ogreRoot_;
+
+ // delete the ogre log and the logManager (since we have created it in the first place).
+ this->ogreLogger_->getDefaultLog()->removeListener(this);
+ this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
+ delete this->ogreLogger_;
+
+ // Don't showing graphics anymore
+ Core::setShowsGraphics(false);
+ }
+
+ assert(singletonRef_s);
+ singletonRef_s = 0;
+ }
+
+ 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)
+ .description("Folder where the Ogre plugins are located.");
+ SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
+ .description("Comma separated list of all plugins to load.");
+ SetConfigValue(ogreLogFile_, "ogre.log")
+ .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
+ SetConfigValue(ogreLogLevelTrivial_ , 5)
+ .description("Corresponding orxonox debug level for ogre Trivial");
+ SetConfigValue(ogreLogLevelNormal_ , 4)
+ .description("Corresponding orxonox debug level for ogre Normal");
+ SetConfigValue(ogreLogLevelCritical_, 2)
+ .description("Corresponding orxonox debug level for ogre Critical");
+ SetConfigValue(detailLevelParticle_, 2)
+ .description("O: off, 1: low, 2: normal, 3: high").callback(this, &GraphicsManager::detailLevelParticleChanged);
+ }
+
+ void GraphicsManager::detailLevelParticleChanged()
+ {
+ for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
+ it->detailLevelChanged(this->detailLevelParticle_);
+ }
+
+ void GraphicsManager::update(const Clock& time)
+ {
+ if (this->loaded_)
+ {
+ 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);
+
+ // render
+ ogreRoot_->_updateAllRenderTargets();
+
+ // again, just to be sure OGRE works fine
+ ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+ }
+ }
+
+ /**
+ @brief
+ Creates the Ogre Root object and sets up the ogre log.
+ */
+ void GraphicsManager::setupOgre()
+ {
+ COUT(3) << "Setting up Ogre..." << std::endl;
+
+ if (ogreConfigFile_ == "")
+ {
+ COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
+ ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
+ }
+ if (ogreLogFile_ == "")
+ {
+ COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
+ ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
+ }
+
+ boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
+ boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
+
+ // create a new logManager
+ // Ogre::Root will detect that we've already created a Log
+ ogreLogger_ = new Ogre::LogManager();
+ COUT(4) << "Ogre LogManager created" << std::endl;
+
+ // create our own log that we can listen to
+ Ogre::Log *myLog;
+ myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
+ COUT(4) << "Ogre Log created" << std::endl;
+
+ myLog->setLogDetail(Ogre::LL_BOREME);
+ myLog->addListener(this);
+
+ COUT(4) << "Creating Ogre Root..." << std::endl;
+
+ // check for config file existence because Ogre displays (caught) exceptions if not
+ if (!boost::filesystem::exists(ogreConfigFilepath))
+ {
+ // create a zero sized file
+ std::ofstream creator;
+ creator.open(ogreConfigFilepath.string().c_str());
+ creator.close();
+ }
+
+ // Leave plugins file empty. We're going to do that part manually later
+ ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
+
+ COUT(3) << "Ogre set up done." << std::endl;
+ }
+
+ void GraphicsManager::loadOgrePlugins()
+ {
+ // just to make sure the next statement doesn't segfault
+ if (ogrePluginsFolder_ == "")
+ ogrePluginsFolder_ = ".";
+
+ boost::filesystem::path folder(ogrePluginsFolder_);
+ // Do some SubString magic to get the comma separated list of plugins
+ SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0');
+ // Use backslash paths on Windows! file_string() already does that though.
+ for (unsigned int i = 0; i < plugins.size(); ++i)
+ 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;
+
+ if (!ogreRoot_->restoreConfig())
+ if (!ogreRoot_->showConfigDialog())
+ ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
+
+ CCOUT(4) << "Creating render window" << std::endl;
+
+ this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
+
+ this->ogreWindowEventListener_ = new OgreWindowEventListener();
+ Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
+
+ Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
+
+ // create a full screen default viewport
+ this->viewport_ = this->renderWindow_->addViewport(0, 0);
+ }
+
+ void GraphicsManager::initialiseResources()
+ {
+ 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;
+ //}
+ }
+
+ /**
+ @brief
+ Method called by the LogListener interface from Ogre.
+ We use it to capture Ogre log messages and handle it ourselves.
+ @param message
+ The message to be logged
+ @param lml
+ The message level the log is using
+ @param maskDebug
+ If we are printing to the console or not
+ @param logName
+ The name of this log (so you can have several listeners
+ for different logs, and identify them)
+ */
+ void GraphicsManager::messageLogged(const std::string& message,
+ Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
+ {
+ int orxonoxLevel;
+ switch (lml)
+ {
+ case Ogre::LML_TRIVIAL:
+ orxonoxLevel = this->ogreLogLevelTrivial_;
+ break;
+ case Ogre::LML_NORMAL:
+ orxonoxLevel = this->ogreLogLevelNormal_;
+ break;
+ case Ogre::LML_CRITICAL:
+ orxonoxLevel = this->ogreLogLevelCritical_;
+ break;
+ default:
+ orxonoxLevel = 0;
+ }
+ OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
+ << "Ogre: " << message << std::endl;
+ }
+
+ void GraphicsManager::printScreen()
+ {
+ assert(this->renderWindow_);
+
+ this->renderWindow_->writeContentsToTimestampedFile(Core::getLogPathString() + "screenShot_", ".jpg");
+ }
+
+
+ /****** OgreWindowEventListener ******/
+
+ void OgreWindowEventListener::windowResized(Ogre::RenderWindow* rw)
+ {
+ for (ObjectList<orxonox::WindowEventListener>::iterator it
+ = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
+ it->windowResized(rw->getWidth(), rw->getHeight());
+ }
+ void OgreWindowEventListener::windowFocusChange(Ogre::RenderWindow* rw)
+ {
+ for (ObjectList<orxonox::WindowEventListener>::iterator it
+ = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
+ it->windowFocusChanged();
+ }
+ void OgreWindowEventListener::windowClosed(Ogre::RenderWindow* rw)
+ {
+ // TODO: Notify the right class to shut down the Game
+ }
+}
Copied: branches/gui/src/orxonox/GraphicsManager.h (from rev 2797, branches/gui/src/orxonox/GraphicsEngine.h)
===================================================================
--- branches/gui/src/orxonox/GraphicsManager.h (rev 0)
+++ branches/gui/src/orxonox/GraphicsManager.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -0,0 +1,133 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ * Co-authors:
+ * Felix Schulthess
+ *
+ */
+
+/**
+ at file
+ at brief
+ Declaration of GraphicsManager Singleton.
+ */
+
+#ifndef _GraphicsEngine_H__
+#define _GraphicsEngine_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <string>
+#include <cassert>
+#include <OgreLog.h>
+
+#include "core/OrxonoxClass.h"
+
+namespace orxonox
+{
+ /**
+ @brief
+ Graphics engine manager class
+ */
+ class _OrxonoxExport GraphicsManager : public OrxonoxClass, public Ogre::LogListener
+ {
+ public:
+ GraphicsManager();
+ ~GraphicsManager();
+
+ void setConfigValues();
+ void initialise();
+
+ void update(const Clock& time);
+
+ void detailLevelParticleChanged();
+ inline unsigned int getDetailLevelParticle() const
+ { return this->detailLevelParticle_; }
+
+ // <HACK>
+ float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; }
+ float getAverageTickTime() const { return this->avgTickTime_; }
+ void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; }
+ void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
+ // </HACK>
+
+ inline void setViewport(Ogre::Viewport* viewport)
+ { this->viewport_ = viewport; }
+ inline Ogre::Viewport* getViewport() const
+ { return this->viewport_; }
+ inline Ogre::RenderWindow* getRenderWindow()
+ { return this->renderWindow_; }
+
+ static GraphicsManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
+
+
+ private:
+ GraphicsManager(GraphicsManager&); // don't mess with singletons
+
+ // OGRE initialisation
+ void setupOgre();
+ void loadOgrePlugins();
+ void declareResources();
+ void loadRenderer();
+ void initialiseResources();
+
+ // event from Ogre::LogListener
+ void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
+ bool maskDebug, const std::string& logName);
+
+ // console commands
+ void printScreen();
+
+ private:
+ bool loaded_;
+
+ Ogre::Root* ogreRoot_; //!< Ogre's root
+ Ogre::LogManager* ogreLogger_;
+ Ogre::RenderWindow* renderWindow_; //!< the one and only render window
+ Ogre::Viewport* viewport_; //!< default full size viewport
+ OgreWindowEventListener* ogreWindowEventListener_;
+
+ // stats (Hack)
+ float avgTickTime_; //!< time in ms to tick() one frame
+ float avgFramesPerSecond_; //!< number of frames processed in one second
+
+ // config values
+ unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
+ 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
+ std::string ogreLogFile_; //!< log file name for Ogre log messages
+ int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL
+ int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL
+ int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL
+
+ // console commands
+ ConsoleCommand* ccPrintScreen_;
+
+ static GraphicsManager* singletonRef_s; //!< Pointer to the Singleton
+ };
+}
+
+#endif /* _GraphicsEngine_H__ */
Modified: branches/gui/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- branches/gui/src/orxonox/OrxonoxPrereqs.h 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/OrxonoxPrereqs.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -96,7 +96,8 @@
}
- class GraphicsEngine;
+ class GraphicsManager;
+ class OgreWindowEventListener;
class Settings;
class RadarViewable;
Modified: branches/gui/src/orxonox/gamestates/GSClient.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSClient.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSClient.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -58,7 +58,7 @@
if(!client_->establishConnection())
ThrowException(InitialisationFailed, "Could not establish connection with server.");
- GSLevel::enter(this->getParent()->getViewport());
+ GSLevel::enter();
// TODO: Get Clock from Game or GameStateManager, but with 0 delta time
client_->update(Clock());
Modified: branches/gui/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSDedicated.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSDedicated.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -57,7 +57,7 @@
this->server_ = new Server(CommandLine::getValue("port"));
COUT(0) << "Loading scene in server mode" << std::endl;
- GSLevel::enter(0);
+ GSLevel::enter();
server_->open();
}
Modified: branches/gui/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGUI.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSGUI.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -34,6 +34,7 @@
#include "core/input/InputManager.h"
#include "core/input/SimpleInputState.h"
#include "gui/GUIManager.h"
+#include "GraphicsManager.h"
namespace orxonox
{
@@ -48,12 +49,12 @@
void GSGUI::enter()
{
- guiManager_ = getParent()->getGUIManager();
+ guiManager_ = GUIManager::getInstancePtr();
// show main menu
guiManager_->loadScene("MainMenu");
guiManager_->showGUI("MainMenu", 0);
- getParent()->getViewport()->setCamera(guiManager_->getCamera());
+ GraphicsManager::getInstance().getViewport()->setCamera(guiManager_->getCamera());
}
void GSGUI::leave()
Modified: branches/gui/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGraphics.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSGraphics.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -29,27 +29,10 @@
#include "OrxonoxStableHeaders.h"
#include "GSGraphics.h"
-#include <fstream>
#include <boost/filesystem.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>
-#include "SpecialConfig.h"
#include "util/Debug.h"
-#include "util/Exception.h"
-#include "util/String.h"
-#include "util/SubString.h"
-#include "core/ConsoleCommand.h"
#include "core/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
#include "core/Core.h"
@@ -60,24 +43,18 @@
#include "core/XMLFile.h"
#include "overlays/console/InGameConsole.h"
#include "gui/GUIManager.h"
-#include "tools/WindowEventListener.h"
// for compatibility
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
namespace orxonox
{
GSGraphics::GSGraphics()
: GameState<GSRoot>("graphics")
- , renderWindow_(0)
- , viewport_(0)
- , bWindowEventListenerUpdateRequired_(false)
, inputManager_(0)
, console_(0)
, guiManager_(0)
- , ogreRoot_(0)
- , ogreLogger_(0)
- , graphicsEngine_(0)
+ , graphicsManager_(0)
, masterKeyBinder_(0)
, debugOverlay_(0)
{
@@ -91,22 +68,6 @@
void GSGraphics::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)
- .description("Folder where the Ogre plugins are located.");
- SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
- .description("Comma separated list of all plugins to load.");
- SetConfigValue(ogreLogFile_, "ogre.log")
- .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
- SetConfigValue(ogreLogLevelTrivial_ , 5)
- .description("Corresponding orxonox debug level for ogre Trivial");
- SetConfigValue(ogreLogLevelNormal_ , 4)
- .description("Corresponding orxonox debug level for ogre Normal");
- SetConfigValue(ogreLogLevelCritical_, 2)
- .description("Corresponding orxonox debug level for ogre Critical");
}
void GSGraphics::enter()
@@ -114,25 +75,9 @@
Core::setShowsGraphics(true);
// initialise graphics engine. Doesn't load the render window yet!
- graphicsEngine_ = new GraphicsEngine();
+ this->graphicsManager_ = new GraphicsManager();
+ this->graphicsManager_->initialise();
- // Ogre setup procedure
- setupOgre();
- // load all the required plugins for Ogre
- loadOgrePlugins();
- // read resource declaration file
- this->declareResources();
- // Reads ogre config and creates the render window
- this->loadRenderer();
-
- // TODO: Spread this so that this call only initialises things needed for the Console and GUI
- this->initialiseResources();
-
- // We want to get informed whenever an object of type WindowEventListener is created
- // in order to later update the window size.
- bWindowEventListenerUpdateRequired_ = false;
- RegisterConstructionCallback(GSGraphics, orxonox::WindowEventListener, requestWindowEventListenerUpdate);
-
// load debug overlay
COUT(3) << "Loading Debug Overlay..." << std::endl;
this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").string());
@@ -142,8 +87,9 @@
// The render window width and height are used to set up the mouse movement.
inputManager_ = new InputManager();
size_t windowHnd = 0;
- this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
- inputManager_->initialise(windowHnd, renderWindow_->getWidth(), renderWindow_->getHeight(), true);
+ Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
+ renderWindow->getCustomAttribute("WINDOW", &windowHnd);
+ inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
// Configure master input state with a KeyBinder
masterKeyBinder_ = new KeyBinder();
masterKeyBinder_->loadBindings("masterKeybindings.ini");
@@ -151,28 +97,15 @@
// Load the InGameConsole
console_ = new InGameConsole();
- console_->initialise(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
+ console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
// load the CEGUI interface
guiManager_ = new GUIManager();
- guiManager_->initialise(this->renderWindow_);
-
- // add console commands
- FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
- functor1->setObject(this);
- ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
- CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
+ guiManager_->initialise(renderWindow);
}
void GSGraphics::leave()
{
- using namespace Ogre;
-
- delete this->ccPrintScreen_;
-
- // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
- Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
-
delete this->guiManager_;
delete this->console_;
@@ -184,38 +117,7 @@
Loader::unload(this->debugOverlay_);
delete this->debugOverlay_;
- // unload all compositors
- Ogre::CompositorManager::getSingleton().removeAll();
-
- // destroy render window
- RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
- renderer->destroyRenderWindow("Orxonox");
-
- /*** CODE SNIPPET, UNUSED ***/
- // Does the opposite of initialise()
- //ogreRoot_->shutdown();
- // Remove all resources and resource groups
- //StringVector groups = ResourceGroupManager::getSingleton().getResourceGroups();
- //for (StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
- //{
- // ResourceGroupManager::getSingleton().destroyResourceGroup(*it);
- //}
-
- //ParticleSystemManager::getSingleton().removeAllTemplates();
-
- // Shutdown the render system
- //this->ogreRoot_->setRenderSystem(0);
-
- delete this->ogreRoot_;
-
- // delete the ogre log and the logManager (since we have created it).
- this->ogreLogger_->getDefaultLog()->removeListener(this);
- this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
- delete this->ogreLogger_;
-
- delete graphicsEngine_;
-
- Core::setShowsGraphics(false);
+ delete graphicsManager_;
}
/**
@@ -230,276 +132,36 @@
{
uint64_t timeBeforeTick = time.getRealMicroseconds();
- float dt = time.getDeltaTime();
-
- this->inputManager_->update(time);
- // tick console
+ this->inputManager_->update(time); // tick console
this->console_->update(time);
this->tickChild(time);
- if (this->bWindowEventListenerUpdateRequired_)
- {
- // Update all WindowEventListeners for the case a new one was created.
- this->windowResized(this->renderWindow_);
- this->bWindowEventListenerUpdateRequired_ = false;
- }
-
uint64_t timeAfterTick = time.getRealMicroseconds();
// Also add our tick time to the list in GSRoot
this->getParent()->addTickTime(timeAfterTick - timeBeforeTick);
// Update statistics overlay. Note that the values only change periodically in GSRoot.
- GraphicsEngine::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
- GraphicsEngine::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
+ GraphicsManager::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
+ GraphicsManager::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
- // don't forget to call _fireFrameStarted in ogre to make sure
- // everything goes smoothly
- Ogre::FrameEvent evt;
- evt.timeSinceLastFrame = dt;
- evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
- 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);
-
- // render
- ogreRoot_->_updateAllRenderTargets();
-
- // again, just to be sure ogre works fine
- ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+ this->graphicsManager_->update(time);
}
/**
@brief
- Creates the Ogre Root object and sets up the ogre log.
- */
- void GSGraphics::setupOgre()
- {
- COUT(3) << "Setting up Ogre..." << std::endl;
-
- if (ogreConfigFile_ == "")
- {
- COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
- ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
- }
- if (ogreLogFile_ == "")
- {
- COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
- ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
- }
-
- boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
- boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
-
- // create a new logManager
- // Ogre::Root will detect that we've already created a Log
- ogreLogger_ = new Ogre::LogManager();
- COUT(4) << "Ogre LogManager created" << std::endl;
-
- // create our own log that we can listen to
- Ogre::Log *myLog;
- myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
- COUT(4) << "Ogre Log created" << std::endl;
-
- myLog->setLogDetail(Ogre::LL_BOREME);
- myLog->addListener(this);
-
- COUT(4) << "Creating Ogre Root..." << std::endl;
-
- // check for config file existence because Ogre displays (caught) exceptions if not
- if (!boost::filesystem::exists(ogreConfigFilepath))
- {
- // create a zero sized file
- std::ofstream creator;
- creator.open(ogreConfigFilepath.string().c_str());
- creator.close();
- }
-
- // Leave plugins file empty. We're going to do that part manually later
- ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
-
- COUT(3) << "Ogre set up done." << std::endl;
- }
-
- void GSGraphics::loadOgrePlugins()
- {
- // just to make sure the next statement doesn't segfault
- if (ogrePluginsFolder_ == "")
- ogrePluginsFolder_ = ".";
-
- boost::filesystem::path folder(ogrePluginsFolder_);
- // Do some SubString magic to get the comma separated list of plugins
- SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0');
- // Use backslash paths on Windows! file_string() already does that though.
- for (unsigned int i = 0; i < plugins.size(); ++i)
- ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
- }
-
- void GSGraphics::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 GSGraphics::loadRenderer()
- {
- CCOUT(4) << "Configuring Renderer" << std::endl;
-
- if (!ogreRoot_->restoreConfig())
- if (!ogreRoot_->showConfigDialog())
- ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
-
- CCOUT(4) << "Creating render window" << std::endl;
-
- this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
-
- Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
-
- Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
-
- // create a full screen default viewport
- this->viewport_ = this->renderWindow_->addViewport(0, 0);
-
- if (this->graphicsEngine_)
- this->graphicsEngine_->setViewport(this->viewport_);
- }
-
- void GSGraphics::initialiseResources()
- {
- 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;
- //}
- }
-
- /**
- @brief
- Method called by the LogListener interface from Ogre.
- We use it to capture Ogre log messages and handle it ourselves.
- @param message
- The message to be logged
- @param lml
- The message level the log is using
- @param maskDebug
- If we are printing to the console or not
- @param logName
- The name of this log (so you can have several listeners
- for different logs, and identify them)
- */
- void GSGraphics::messageLogged(const std::string& message,
- Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
- {
- int orxonoxLevel;
- switch (lml)
- {
- case Ogre::LML_TRIVIAL:
- orxonoxLevel = this->ogreLogLevelTrivial_;
- break;
- case Ogre::LML_NORMAL:
- orxonoxLevel = this->ogreLogLevelNormal_;
- break;
- case Ogre::LML_CRITICAL:
- orxonoxLevel = this->ogreLogLevelCritical_;
- break;
- default:
- orxonoxLevel = 0;
- }
- OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
- << "Ogre: " << message << std::endl;
- }
-
- /**
- @brief
- Window has moved.
- @param rw
- The render window it occured in
- */
- void GSGraphics::windowMoved(Ogre::RenderWindow *rw)
- {
- for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
- it->windowMoved();
- }
-
- /**
- @brief
Window has resized.
@param rw
The render window it occured in
@note
- GraphicsEngine has a render window stored itself. This is the same
+ GraphicsManager has a render window stored itself. This is the same
as rw. But we have to be careful when using multiple render windows!
*/
- void GSGraphics::windowResized(Ogre::RenderWindow *rw)
+ void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
{
- for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
- it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
-
// OIS needs this under linux even if we only use relative input measurement.
if (this->inputManager_)
- this->inputManager_->setWindowExtents(renderWindow_->getWidth(), renderWindow_->getHeight());
+ this->inputManager_->setWindowExtents(newWidth, newHeight);
}
/**
@@ -508,32 +170,11 @@
@param rw
The render window it occured in
*/
- void GSGraphics::windowFocusChange(Ogre::RenderWindow *rw)
+ void GSGraphics::windowFocusChanged()
{
- for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
- it->windowFocusChanged();
-
// instruct InputManager to clear the buffers (core library so we cannot use the interface)
if (this->inputManager_)
this->inputManager_->clearBuffers();
}
- /**
- @brief
- Window was closed.
- @param rw
- The render window it occured in
- */
- void GSGraphics::windowClosed(Ogre::RenderWindow *rw)
- {
- this->requestState("root");
- }
-
- void GSGraphics::printScreen()
- {
- if (this->renderWindow_)
- {
- this->renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg");
- }
- }
}
Modified: branches/gui/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSGraphics.h 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSGraphics.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -30,17 +30,14 @@
#define _GSGraphics_H__
#include "OrxonoxPrereqs.h"
-#define NOMINMAX // required to stop windows.h screwing up std::min definition
-#include <OgreWindowEventUtilities.h>
-#include <OgreLog.h>
#include "core/GameState.h"
#include "core/OrxonoxClass.h"
+#include "tools/WindowEventListener.h"
#include "GSRoot.h"
namespace orxonox
{
- class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass,
- public Ogre::WindowEventListener, public Ogre::LogListener
+ class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public WindowEventListener
{
friend class ClassIdentifier<GSGraphics>;
@@ -48,10 +45,6 @@
GSGraphics();
~GSGraphics();
- Ogre::Root* getOgreRoot() { return this->ogreRoot_ ; }
- Ogre::Viewport* getViewport() { return this->viewport_ ; }
- GUIManager* getGUIManager() { return this->guiManager_; }
-
private: // functions
void enter();
void leave();
@@ -59,55 +52,19 @@
void setConfigValues();
- void setupOgre();
- void loadOgrePlugins();
- void declareResources();
- void loadRenderer();
- void initialiseResources();
+ // Window events from WindowEventListener
+ void windowResized(unsigned int newWidth, unsigned int newHeight);
+ void windowFocusChanged();
- // console commands
- void printScreen();
-
- // event from Ogre::LogListener
- void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
- bool maskDebug, const std::string& logName);
-
- // window events from Ogre::WindowEventListener
- void windowMoved (Ogre::RenderWindow* rw);
- void windowResized (Ogre::RenderWindow* rw);
- void windowFocusChange (Ogre::RenderWindow* rw);
- void windowClosed (Ogre::RenderWindow* rw);
-
- void requestWindowEventListenerUpdate() { this->bWindowEventListenerUpdateRequired_ = true; }
-
- private: // variables
- Ogre::RenderWindow* renderWindow_; //!< the current render window
- Ogre::Viewport* viewport_; //!< default full size viewport
- bool bWindowEventListenerUpdateRequired_; //!< True if a new WindowEventListener was created but not yet updated.
-
+ private:
// managed singletons
InputManager* inputManager_;
InGameConsole* console_;
GUIManager* guiManager_;
- Ogre::Root* ogreRoot_; //!< Ogre's root
- Ogre::LogManager* ogreLogger_;
- GraphicsEngine* graphicsEngine_; //!< Interface to Ogre
+ GraphicsManager* graphicsManager_; //!< Interface to Ogre
KeyBinder* masterKeyBinder_;
XMLFile* debugOverlay_;
-
- // 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
- std::string ogreLogFile_; //!< log file name for Ogre log messages
- int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL
- int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL
- int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL
-
- // console commands
- ConsoleCommand* ccPrintScreen_;
};
}
Modified: branches/gui/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSLevel.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -43,6 +43,7 @@
#include "objects/Tickable.h"
#include "objects/Radar.h"
#include "CameraManager.h"
+#include "GraphicsManager.h"
#include "LevelManager.h"
#include "PlayerManager.h"
@@ -76,7 +77,7 @@
SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
}
- void GSLevel::enter(Ogre::Viewport* viewport)
+ void GSLevel::enter()
{
if (Core::showsGraphics())
{
@@ -86,8 +87,7 @@
inputState_->setHandler(keyBinder_);
// create the global CameraManager
- assert(viewport);
- this->cameraManager_ = new CameraManager(viewport);
+ this->cameraManager_ = new CameraManager(GraphicsManager::getInstance().getViewport());
// Start the Radar
this->radar_ = new Radar();
Modified: branches/gui/src/orxonox/gamestates/GSLevel.h
===================================================================
--- branches/gui/src/orxonox/gamestates/GSLevel.h 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSLevel.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -30,7 +30,6 @@
#define _GSLevel_H__
#include "OrxonoxPrereqs.h"
-#include <OgrePrerequisites.h>
#include "core/OrxonoxClass.h"
namespace orxonox
@@ -46,7 +45,7 @@
void setConfigValues();
protected:
- void enter(Ogre::Viewport* viewport);
+ void enter();
void leave();
void ticked(const Clock& time);
Modified: branches/gui/src/orxonox/gamestates/GSServer.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSServer.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSServer.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -54,7 +54,7 @@
this->server_ = new Server(CommandLine::getValue("port"));
COUT(0) << "Loading scene in server mode" << std::endl;
- GSLevel::enter(this->getParent()->getViewport());
+ GSLevel::enter();
server_->open();
}
Modified: branches/gui/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSStandalone.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gamestates/GSStandalone.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -34,6 +34,7 @@
#include "core/Core.h"
#include "core/ConsoleCommand.h"
#include "gui/GUIManager.h"
+#include "GraphicsManager.h"
namespace orxonox
{
@@ -59,9 +60,9 @@
{
Core::setIsStandalone(true);
- GSLevel::enter(this->getParent()->getViewport());
+ GSLevel::enter();
- guiManager_ = getParent()->getGUIManager();
+ guiManager_ = GUIManager::getInstancePtr();
// not sure if necessary
// guiManager_->loadScene("IngameMenu");
}
@@ -77,7 +78,8 @@
{
if (guiShowing_s)
{
- guiManager_->showGUI("IngameMenu", this->getParent()->getViewport()->getCamera()->getSceneManager());
+ Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
+ guiManager_->showGUI("IngameMenu", viewport->getCamera()->getSceneManager());
}
else
{
Modified: branches/gui/src/orxonox/gui/GUIManager.cc
===================================================================
--- branches/gui/src/orxonox/gui/GUIManager.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/gui/GUIManager.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -270,7 +270,7 @@
COUT(3) << "Loading GUI " << name << std::endl;
try
{
- COUT (0) << "************* sceneManager: " << sceneManager << std::endl;
+// COUT (0) << "************* sceneManager: " << sceneManager << std::endl;
if (!sceneManager)
{
// currently, only an image is loaded. We could do 3D, see loadBackground.
Modified: branches/gui/src/orxonox/objects/worldentities/Planet.cc
===================================================================
--- branches/gui/src/orxonox/objects/worldentities/Planet.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/objects/worldentities/Planet.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -41,7 +41,7 @@
#include "objects/Scene.h"
#include "CameraManager.h"
#include "Camera.h"
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
namespace orxonox
{
Modified: branches/gui/src/orxonox/overlays/OrxonoxOverlay.cc
===================================================================
--- branches/gui/src/orxonox/overlays/OrxonoxOverlay.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/overlays/OrxonoxOverlay.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -38,6 +38,8 @@
#include <OgreOverlay.h>
#include <OgreOverlayManager.h>
#include <OgrePanelOverlayElement.h>
+#include <OgreRenderWindow.h>
+
#include "util/Convert.h"
#include "util/Exception.h"
#include "util/String.h"
@@ -45,6 +47,7 @@
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
#include "core/ConsoleCommand.h"
+#include "GraphicsManager.h"
namespace orxonox
{
@@ -76,9 +79,9 @@
"OrxonoxOverlay_background_" + convertToString(hudOverlayCounter_s++)));
this->overlay_->add2D(this->background_);
- // We'll have to set the aspect ratio to a default value first.
- // GSGraphics gets informed about our construction here and can update us in the next tick.
- this->windowAspectRatio_ = 1.0;
+ // Get aspect ratio from the render window. Later on, we get informed automatically
+ Ogre::RenderWindow* defaultWindow = GraphicsManager::getInstance().getRenderWindow();
+ this->windowAspectRatio_ = (float)defaultWindow->getWidth() / defaultWindow->getHeight();
this->sizeCorrectionChanged();
this->changedVisibility();
@@ -174,10 +177,10 @@
/**
@brief
- Called by the GraphicsEngine whenever the window size changes.
+ Called by the GraphicsManager whenever the window size changes.
Calculates the aspect ratio only.
*/
- void OrxonoxOverlay::windowResized(int newWidth, int newHeight)
+ void OrxonoxOverlay::windowResized(unsigned int newWidth, unsigned int newHeight)
{
this->windowAspectRatio_ = newWidth/(float)newHeight;
this->sizeCorrectionChanged();
Modified: branches/gui/src/orxonox/overlays/OrxonoxOverlay.h
===================================================================
--- branches/gui/src/orxonox/overlays/OrxonoxOverlay.h 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/overlays/OrxonoxOverlay.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -199,7 +199,7 @@
RotationState rotState_; //!< horizontal, vertical or inbetween
private:
- void windowResized(int newWidth, int newHeight);
+ void windowResized(unsigned int newWidth, unsigned int newHeight);
static unsigned int hudOverlayCounter_s; //!< Static counter for hud elements
/** Contains all the overlays in a map for quick access via console commands.
Modified: branches/gui/src/orxonox/overlays/console/InGameConsole.cc
===================================================================
--- branches/gui/src/orxonox/overlays/console/InGameConsole.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/overlays/console/InGameConsole.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -409,7 +409,7 @@
/**
@brief Resizes the console elements. Call if window size changes.
*/
- void InGameConsole::windowResized(int newWidth, int newHeight)
+ void InGameConsole::windowResized(unsigned int newWidth, unsigned int newHeight)
{
this->windowW_ = newWidth;
this->windowH_ = newHeight;
Modified: branches/gui/src/orxonox/overlays/console/InGameConsole.h
===================================================================
--- branches/gui/src/orxonox/overlays/console/InGameConsole.h 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/overlays/console/InGameConsole.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -80,7 +80,7 @@
void setCursorPosition(unsigned int pos);
void print(const std::string& text, int index, bool alwaysShift = false);
- void windowResized(int newWidth, int newHeight);
+ void windowResized(unsigned int newWidth, unsigned int newHeight);
// config value related
void bHidesAllInputChanged();
Modified: branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc
===================================================================
--- branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -30,7 +30,7 @@
#include "DebugFPSText.h"
#include <OgreTextAreaOverlayElement.h>
#include "core/CoreIncludes.h"
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
#include "util/Convert.h"
namespace orxonox
@@ -50,7 +50,7 @@
{
SUPER(DebugFPSText, tick, dt);
- float fps = GraphicsEngine::getInstance().getAverageFramesPerSecond();
+ float fps = GraphicsManager::getInstance().getAverageFramesPerSecond();
this->setCaption(convertToString(fps));
}
}
Modified: branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc
===================================================================
--- branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -31,7 +31,7 @@
#include <OgreTextAreaOverlayElement.h>
#include "core/CoreIncludes.h"
#include "util/Convert.h"
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
namespace orxonox
{
@@ -50,7 +50,7 @@
{
SUPER(DebugRTRText, tick, dt);
- float rtr = GraphicsEngine::getInstance().getAverageTickTime();
+ float rtr = GraphicsManager::getInstance().getAverageTickTime();
this->setCaption(convertToString(rtr));
}
}
Modified: branches/gui/src/orxonox/tools/ParticleInterface.cc
===================================================================
--- branches/gui/src/orxonox/tools/ParticleInterface.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/tools/ParticleInterface.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -39,7 +39,7 @@
#include <OgreSceneManager.h>
#include <cassert>
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
#include "core/Core.h"
#include "core/CoreIncludes.h"
#include "util/Convert.h"
@@ -177,8 +177,8 @@
void ParticleInterface::setDetailLevel(unsigned int level)
{
this->detaillevel_ = level;
- if (GraphicsEngine::getInstancePtr())
- this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle());
+ if (Core::showsGraphics())
+ this->detailLevelChanged(GraphicsManager::getInstance().getDetailLevelParticle());
}
void ParticleInterface::detailLevelChanged(unsigned int newlevel)
Modified: branches/gui/src/orxonox/tools/Shader.cc
===================================================================
--- branches/gui/src/orxonox/tools/Shader.cc 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/tools/Shader.cc 2009-03-19 09:58:43 UTC (rev 2801)
@@ -38,7 +38,7 @@
#include "core/Core.h"
#include "core/CoreIncludes.h"
#include "core/Executor.h"
-#include "GraphicsEngine.h"
+#include "GraphicsManager.h"
#include "util/Exception.h"
#include <OgreMaterial.h>
@@ -58,7 +58,7 @@
this->scenemanager_ = scenemanager;
this->compositorInstance_ = 0;
this->bVisible_ = true;
- this->bLoadCompositor_ = Core::showsGraphics() && GraphicsEngine::getInstancePtr();
+ this->bLoadCompositor_ = Core::showsGraphics();
this->bViewportInitialized_ = false;
this->compositor_ = "";
this->oldcompositor_ = "";
@@ -85,7 +85,7 @@
if (this->bLoadCompositor_ && this->compositorInstance_)
{
- Ogre::Viewport* viewport = GraphicsEngine::getInstance().getViewport();
+ Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
assert(viewport);
Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->compositor_);
}
@@ -113,7 +113,7 @@
{
if (this->bLoadCompositor_)
{
- Ogre::Viewport* viewport = GraphicsEngine::getInstance().getViewport();
+ Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
assert(viewport);
if (this->oldcompositor_ != "")
{
Modified: branches/gui/src/orxonox/tools/WindowEventListener.h
===================================================================
--- branches/gui/src/orxonox/tools/WindowEventListener.h 2009-03-19 09:34:54 UTC (rev 2800)
+++ branches/gui/src/orxonox/tools/WindowEventListener.h 2009-03-19 09:58:43 UTC (rev 2801)
@@ -48,7 +48,7 @@
virtual void windowMoved() { }
/** Window has resized */
- virtual void windowResized(int newWidth, int newHeight) { }
+ virtual void windowResized(unsigned int newWidth, unsigned int newHeight) { }
/** Window has lost/gained focus */
virtual void windowFocusChanged() { }
More information about the Orxonox-commit
mailing list