Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 19, 2009, 10:58:43 AM (16 years ago)
Author:
rgrieder
Message:

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).

Location:
code/branches/gui/src/orxonox
Files:
22 edited
2 moved

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/orxonox/CMakeLists.txt

    r2748 r2801  
    2020SET_SOURCE_FILES(ORXONOX_SRC_FILES
    2121  CameraManager.cc
    22   GraphicsEngine.cc
     22  GraphicsManager.cc
    2323  LevelManager.cc
    2424  Main.cc
  • code/branches/gui/src/orxonox/GraphicsManager.cc

    r2797 r2801  
    3535
    3636#include "OrxonoxStableHeaders.h"
    37 #include "GraphicsEngine.h"
    38 
     37#include "GraphicsManager.h"
     38
     39#include <fstream>
     40#include <boost/filesystem.hpp>
     41
     42#include <OgreCompositorManager.h>
     43#include <OgreConfigFile.h>
     44#include <OgreFrameListener.h>
     45#include <OgreRoot.h>
     46#include <OgreLogManager.h>
     47#include <OgreException.h>
    3948#include <OgreRenderWindow.h>
    40 
     49#include <OgreRenderSystem.h>
     50#include <OgreTextureManager.h>
     51#include <OgreViewport.h>
     52#include <OgreWindowEventUtilities.h>
     53
     54#include "SpecialConfig.h"
     55#include "util/Debug.h"
     56#include "util/Exception.h"
     57#include "util/String.h"
     58#include "util/SubString.h"
     59#include "core/ConsoleCommand.h"
     60#include "core/ConfigValueIncludes.h"
    4161#include "core/CoreIncludes.h"
    42 #include "core/ConfigValueIncludes.h"
    43 #include "util/Debug.h"
    44 
     62#include "core/Core.h"
     63#include "tools/WindowEventListener.h"
    4564#include "tools/ParticleInterface.h"
    4665
    4766namespace orxonox
    4867{
    49     //SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress);
    50 
    51     GraphicsEngine* GraphicsEngine::singletonRef_s = 0;
    52 
    53     /**
    54     @brief
    55         Returns the singleton instance.
    56     @return
    57         The only instance of GraphicsEngine.
    58     */
    59     /*static*/ GraphicsEngine& GraphicsEngine::getInstance()
    60     {
    61         assert(singletonRef_s);
    62         return *singletonRef_s;
    63     }
     68    class _OrxonoxExport OgreWindowEventListener : public Ogre::WindowEventListener
     69    {
     70        void windowResized     (Ogre::RenderWindow* rw);
     71        void windowFocusChange (Ogre::RenderWindow* rw);
     72        void windowClosed      (Ogre::RenderWindow* rw);
     73        //void windowMoved       (Ogre::RenderWindow* rw);
     74    };
     75
     76    GraphicsManager* GraphicsManager::singletonRef_s = 0;
    6477
    6578    /**
     
    6780        Non-initialising constructor.
    6881    */
    69     GraphicsEngine::GraphicsEngine()
    70 //        : root_(0)
    71 //        , renderWindow_(0)
    72 //        , viewport_(0)
    73     {
    74         RegisterObject(GraphicsEngine);
     82    GraphicsManager::GraphicsManager()
     83        : ogreRoot_(0)
     84        , ogreLogger_(0)
     85        , renderWindow_(0)
     86        , viewport_(0)
     87        , ogreWindowEventListener_(0)
     88        , avgTickTime_(0.0f)
     89        , avgFramesPerSecond_(0.0f)
     90    {
     91        RegisterObject(GraphicsManager);
    7592
    7693        assert(singletonRef_s == 0);
    7794        singletonRef_s = this;
    7895
    79         this->viewport_ = 0;
    80 
    81         this->detailLevelParticle_ = 0;
     96        this->loaded_ = false;
    8297
    8398        this->setConfigValues();
    84         CCOUT(4) << "Constructed" << std::endl;
    85     }
    86 
    87     void GraphicsEngine::setConfigValues()
    88     {
    89         SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high").callback(this, &GraphicsEngine::detailLevelParticleChanged);
    90     }
    91 
    92     void GraphicsEngine::detailLevelParticleChanged()
    93     {
    94         for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
    95             it->detailLevelChanged(this->detailLevelParticle_);
     99    }
     100
     101    void GraphicsManager::initialise()
     102    {
     103        Core::setShowsGraphics(true);
     104
     105        // Ogre setup procedure
     106        setupOgre();
     107        // load all the required plugins for Ogre
     108        loadOgrePlugins();
     109        // read resource declaration file
     110        this->declareResources();
     111        // Reads ogre config and creates the render window
     112        this->loadRenderer();
     113
     114        // TODO: Spread this
     115        this->initialiseResources();
     116
     117        // add console commands
     118        FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
     119        functor1->setObject(this);
     120        ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
     121        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
     122
     123        this->loaded_ = true;
    96124    }
    97125
     
    100128        Destroys all the Ogre related objects
    101129    */
    102     GraphicsEngine::~GraphicsEngine()
    103     {
     130    GraphicsManager::~GraphicsManager()
     131    {
     132        if (this->loaded_)
     133        {
     134            delete this->ccPrintScreen_;
     135
     136            if (this->ogreWindowEventListener_)
     137            {
     138                // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
     139                Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this->ogreWindowEventListener_);
     140                delete this->ogreWindowEventListener_;
     141            }
     142
     143            // unload all compositors
     144            Ogre::CompositorManager::getSingleton().removeAll();
     145
     146            // destroy render window
     147            Ogre::RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
     148            renderer->destroyRenderWindow("Orxonox");
     149
     150            // Delete OGRE main control organ
     151            delete this->ogreRoot_;
     152
     153            // delete the ogre log and the logManager (since we have created it in the first place).
     154            this->ogreLogger_->getDefaultLog()->removeListener(this);
     155            this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
     156            delete this->ogreLogger_;
     157
     158            // Don't showing graphics anymore
     159            Core::setShowsGraphics(false);
     160        }
     161
     162        assert(singletonRef_s);
    104163        singletonRef_s = 0;
    105164    }
     165
     166    void GraphicsManager::setConfigValues()
     167    {
     168        SetConfigValue(resourceFile_,    "resources.cfg")
     169            .description("Location of the resources file in the data path.");
     170        SetConfigValue(ogreConfigFile_,  "ogre.cfg")
     171            .description("Location of the Ogre config file");
     172        SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER)
     173            .description("Folder where the Ogre plugins are located.");
     174        SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
     175            .description("Comma separated list of all plugins to load.");
     176        SetConfigValue(ogreLogFile_,     "ogre.log")
     177            .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
     178        SetConfigValue(ogreLogLevelTrivial_ , 5)
     179            .description("Corresponding orxonox debug level for ogre Trivial");
     180        SetConfigValue(ogreLogLevelNormal_  , 4)
     181            .description("Corresponding orxonox debug level for ogre Normal");
     182        SetConfigValue(ogreLogLevelCritical_, 2)
     183            .description("Corresponding orxonox debug level for ogre Critical");
     184        SetConfigValue(detailLevelParticle_, 2)
     185            .description("O: off, 1: low, 2: normal, 3: high").callback(this, &GraphicsManager::detailLevelParticleChanged);
     186    }
     187
     188    void GraphicsManager::detailLevelParticleChanged()
     189    {
     190        for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
     191            it->detailLevelChanged(this->detailLevelParticle_);
     192    }
     193
     194    void GraphicsManager::update(const Clock& time)
     195    {
     196        if (this->loaded_)
     197        {
     198            Ogre::FrameEvent evt;
     199            evt.timeSinceLastFrame = time.getDeltaTime();
     200            evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
     201
     202            // don't forget to call _fireFrameStarted to OGRE to make sure
     203            // everything goes smoothly
     204            ogreRoot_->_fireFrameStarted(evt);
     205
     206            // Pump messages in all registered RenderWindows
     207            // This calls the WindowEventListener objects.
     208            Ogre::WindowEventUtilities::messagePump();
     209            // make sure the window stays active even when not focused
     210            // (probably only necessary on windows)
     211            this->renderWindow_->setActive(true);
     212
     213            // render
     214            ogreRoot_->_updateAllRenderTargets();
     215
     216            // again, just to be sure OGRE works fine
     217            ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
     218        }
     219    }
     220
     221    /**
     222    @brief
     223        Creates the Ogre Root object and sets up the ogre log.
     224    */
     225    void GraphicsManager::setupOgre()
     226    {
     227        COUT(3) << "Setting up Ogre..." << std::endl;
     228
     229        if (ogreConfigFile_ == "")
     230        {
     231            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
     232            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
     233        }
     234        if (ogreLogFile_ == "")
     235        {
     236            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
     237            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
     238        }
     239
     240        boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
     241        boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
     242
     243        // create a new logManager
     244        // Ogre::Root will detect that we've already created a Log
     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        myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
     251        COUT(4) << "Ogre Log created" << std::endl;
     252
     253        myLog->setLogDetail(Ogre::LL_BOREME);
     254        myLog->addListener(this);
     255
     256        COUT(4) << "Creating Ogre Root..." << std::endl;
     257
     258        // check for config file existence because Ogre displays (caught) exceptions if not
     259        if (!boost::filesystem::exists(ogreConfigFilepath))
     260        {
     261            // create a zero sized file
     262            std::ofstream creator;
     263            creator.open(ogreConfigFilepath.string().c_str());
     264            creator.close();
     265        }
     266
     267        // Leave plugins file empty. We're going to do that part manually later
     268        ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
     269
     270        COUT(3) << "Ogre set up done." << std::endl;
     271    }
     272
     273    void GraphicsManager::loadOgrePlugins()
     274    {
     275        // just to make sure the next statement doesn't segfault
     276        if (ogrePluginsFolder_ == "")
     277            ogrePluginsFolder_ = ".";
     278
     279        boost::filesystem::path folder(ogrePluginsFolder_);
     280        // Do some SubString magic to get the comma separated list of plugins
     281        SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0');
     282        // Use backslash paths on Windows! file_string() already does that though.
     283        for (unsigned int i = 0; i < plugins.size(); ++i)
     284            ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
     285    }
     286
     287    void GraphicsManager::declareResources()
     288    {
     289        CCOUT(4) << "Declaring Resources" << std::endl;
     290        //TODO: Specify layout of data file and maybe use xml-loader
     291        //TODO: Work with ressource groups (should be generated by a special loader)
     292
     293        if (resourceFile_ == "")
     294        {
     295            COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
     296            ModifyConfigValue(resourceFile_, tset, "resources.cfg");
     297        }
     298
     299        // Load resource paths from data file using configfile ressource type
     300        Ogre::ConfigFile cf;
     301        try
     302        {
     303            cf.load((Core::getMediaPath() / resourceFile_).string());
     304        }
     305        catch (...)
     306        {
     307            //COUT(1) << ex.getFullDescription() << std::endl;
     308            COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
     309            throw;
     310        }
     311
     312        // Go through all sections & settings in the file
     313        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
     314
     315        std::string secName, typeName, archName;
     316        while (seci.hasMoreElements())
     317        {
     318            try
     319            {
     320                secName = seci.peekNextKey();
     321                Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
     322                Ogre::ConfigFile::SettingsMultiMap::iterator i;
     323                for (i = settings->begin(); i != settings->end(); ++i)
     324                {
     325                    typeName = i->first; // for instance "FileSystem" or "Zip"
     326                    archName = i->second; // name (and location) of archive
     327
     328                    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
     329                        (Core::getMediaPath() / archName).string(), typeName, secName);
     330                }
     331            }
     332            catch (Ogre::Exception& ex)
     333            {
     334                COUT(1) << ex.getFullDescription() << std::endl;
     335            }
     336        }
     337    }
     338
     339    void GraphicsManager::loadRenderer()
     340    {
     341        CCOUT(4) << "Configuring Renderer" << std::endl;
     342
     343        if (!ogreRoot_->restoreConfig())
     344            if (!ogreRoot_->showConfigDialog())
     345                ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
     346
     347        CCOUT(4) << "Creating render window" << std::endl;
     348
     349        this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
     350
     351        this->ogreWindowEventListener_ = new OgreWindowEventListener();
     352        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
     353
     354        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
     355
     356        // create a full screen default viewport
     357        this->viewport_ = this->renderWindow_->addViewport(0, 0);
     358    }
     359
     360    void GraphicsManager::initialiseResources()
     361    {
     362        CCOUT(4) << "Initialising resources" << std::endl;
     363        //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
     364        //try
     365        //{
     366            Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     367            /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
     368            for (unsigned int i = 0; i < str.size(); i++)
     369            {
     370            Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
     371            }*/
     372        //}
     373        //catch (...)
     374        //{
     375        //    CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
     376        //    throw;
     377        //}
     378    }
     379
     380    /**
     381    @brief
     382        Method called by the LogListener interface from Ogre.
     383        We use it to capture Ogre log messages and handle it ourselves.
     384    @param message
     385        The message to be logged
     386    @param lml
     387        The message level the log is using
     388    @param maskDebug
     389        If we are printing to the console or not
     390    @param logName
     391        The name of this log (so you can have several listeners
     392        for different logs, and identify them)
     393    */
     394    void GraphicsManager::messageLogged(const std::string& message,
     395        Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
     396    {
     397        int orxonoxLevel;
     398        switch (lml)
     399        {
     400        case Ogre::LML_TRIVIAL:
     401            orxonoxLevel = this->ogreLogLevelTrivial_;
     402            break;
     403        case Ogre::LML_NORMAL:
     404            orxonoxLevel = this->ogreLogLevelNormal_;
     405            break;
     406        case Ogre::LML_CRITICAL:
     407            orxonoxLevel = this->ogreLogLevelCritical_;
     408            break;
     409        default:
     410            orxonoxLevel = 0;
     411        }
     412        OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
     413            << "Ogre: " << message << std::endl;
     414    }
     415
     416    void GraphicsManager::printScreen()
     417    {
     418        assert(this->renderWindow_);
     419       
     420        this->renderWindow_->writeContentsToTimestampedFile(Core::getLogPathString() + "screenShot_", ".jpg");
     421    }
     422
     423
     424    /****** OgreWindowEventListener ******/
     425
     426    void OgreWindowEventListener::windowResized(Ogre::RenderWindow* rw)
     427    {
     428        for (ObjectList<orxonox::WindowEventListener>::iterator it
     429            = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
     430            it->windowResized(rw->getWidth(), rw->getHeight());
     431    }
     432    void OgreWindowEventListener::windowFocusChange(Ogre::RenderWindow* rw)
     433    {
     434        for (ObjectList<orxonox::WindowEventListener>::iterator it
     435            = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
     436            it->windowFocusChanged();
     437    }
     438    void OgreWindowEventListener::windowClosed(Ogre::RenderWindow* rw)
     439    {
     440        // TODO: Notify the right class to shut down the Game
     441    }
    106442}
  • code/branches/gui/src/orxonox/GraphicsManager.h

    r2797 r2801  
    2929
    3030/**
    31   @file
    32   @brief Declaration of GraphicsEngine Singleton.
    33   @author Benjamin Knecht <beni_at_orxonox.net>
     31@file
     32@brief
     33    Declaration of GraphicsManager Singleton.
    3434 */
    3535
     
    4040
    4141#include <string>
     42#include <cassert>
     43#include <OgreLog.h>
    4244
    43 #include <OgrePrerequisites.h>
    4445#include "core/OrxonoxClass.h"
    4546
     
    4748{
    4849    /**
    49     @brief Graphics engine manager class
     50    @brief
     51        Graphics engine manager class
    5052    */
    51     class _OrxonoxExport GraphicsEngine : public OrxonoxClass
     53    class _OrxonoxExport GraphicsManager : public OrxonoxClass, public Ogre::LogListener
    5254    {
    53         // HACK: temporary means
    54         friend class GSGraphics;
    55 
    5655    public:
    57         GraphicsEngine();
    58         ~GraphicsEngine();
     56        GraphicsManager();
     57        ~GraphicsManager();
    5958
    6059        void setConfigValues();
     60        void initialise();
     61
     62        void update(const Clock& time);
     63
    6164        void detailLevelParticleChanged();
     65        inline unsigned int getDetailLevelParticle() const
     66            { return this->detailLevelParticle_; }
    6267
     68        // <HACK>
    6369        float getAverageFramesPerSecond() const   { return this->avgFramesPerSecond_; }
    6470        float getAverageTickTime() const          { return this->avgTickTime_; }
    6571        void setAverageTickTime(float tickTime)   { this->avgTickTime_ = tickTime; }
    6672        void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
    67 
    68         inline unsigned int getDetailLevelParticle() const
    69         { return this->detailLevelParticle_; }
    70 
    71         static GraphicsEngine& getInstance();
    72         static GraphicsEngine* getInstancePtr() { return singletonRef_s; }
     73        // </HACK>
    7374
    7475        inline void setViewport(Ogre::Viewport* viewport)
     
    7677        inline Ogre::Viewport* getViewport() const
    7778            { return this->viewport_; }
     79        inline Ogre::RenderWindow* getRenderWindow()
     80            { return this->renderWindow_; }
     81
     82        static GraphicsManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
     83
    7884
    7985    private:
    80         // don't mess with singletons
    81         GraphicsEngine(GraphicsEngine&);
     86        GraphicsManager(GraphicsManager&); // don't mess with singletons
    8287
    83         Ogre::Viewport*     viewport_;              //!< default full size viewport
     88        // OGRE initialisation
     89        void setupOgre();
     90        void loadOgrePlugins();
     91        void declareResources();
     92        void loadRenderer();
     93        void initialiseResources();
    8494
    85         // stats
    86         float               avgTickTime_;           //!< time in ms to tick() one frame
    87         float               avgFramesPerSecond_;    //!< number of frames processed in one second
     95        // event from Ogre::LogListener
     96        void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
     97            bool maskDebug, const std::string& logName);
     98
     99        // console commands
     100        void printScreen();
     101
     102    private:
     103        bool                loaded_;
     104
     105        Ogre::Root*         ogreRoot_;                 //!< Ogre's root
     106        Ogre::LogManager*   ogreLogger_;
     107        Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
     108        Ogre::Viewport*     viewport_;                 //!< default full size viewport
     109        OgreWindowEventListener* ogreWindowEventListener_;
     110
     111        // stats (Hack)
     112        float               avgTickTime_;              //!< time in ms to tick() one frame
     113        float               avgFramesPerSecond_;       //!< number of frames processed in one second
    88114
    89115        // config values
    90         unsigned int        detailLevelParticle_;   //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
     116        unsigned int        detailLevelParticle_;      //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
     117        std::string         resourceFile_;             //!< resources file name
     118        std::string         ogreConfigFile_;           //!< ogre config file name
     119        std::string         ogrePluginsFolder_;        //!< Folder where the Ogre plugins are located
     120        std::string         ogrePlugins_;              //!< Comma separated list of all plugins to load
     121        std::string         ogreLogFile_;              //!< log file name for Ogre log messages
     122        int                 ogreLogLevelTrivial_;      //!< Corresponding Orxonx debug level for LL_TRIVIAL
     123        int                 ogreLogLevelNormal_;       //!< Corresponding Orxonx debug level for LL_NORMAL
     124        int                 ogreLogLevelCritical_;     //!< Corresponding Orxonx debug level for LL_CRITICAL
    91125
    92         static GraphicsEngine* singletonRef_s;      //!< Pointer to the Singleton
     126        // console commands
     127        ConsoleCommand*     ccPrintScreen_;
     128
     129        static GraphicsManager* singletonRef_s;        //!< Pointer to the Singleton
    93130    };
    94131}
  • code/branches/gui/src/orxonox/OrxonoxPrereqs.h

    r2710 r2801  
    9797
    9898
    99     class GraphicsEngine;
     99    class GraphicsManager;
     100    class OgreWindowEventListener;
    100101    class Settings;
    101102
  • code/branches/gui/src/orxonox/gamestates/GSClient.cc

    r2800 r2801  
    5959            ThrowException(InitialisationFailed, "Could not establish connection with server.");
    6060
    61         GSLevel::enter(this->getParent()->getViewport());
     61        GSLevel::enter();
    6262
    6363        // TODO: Get Clock from Game or GameStateManager, but with 0 delta time
  • code/branches/gui/src/orxonox/gamestates/GSDedicated.cc

    r2800 r2801  
    5858        COUT(0) << "Loading scene in server mode" << std::endl;
    5959
    60         GSLevel::enter(0);
     60        GSLevel::enter();
    6161
    6262        server_->open();
  • code/branches/gui/src/orxonox/gamestates/GSGUI.cc

    r2800 r2801  
    3535#include "core/input/SimpleInputState.h"
    3636#include "gui/GUIManager.h"
     37#include "GraphicsManager.h"
    3738
    3839namespace orxonox
     
    4950    void GSGUI::enter()
    5051    {
    51         guiManager_ = getParent()->getGUIManager();
     52        guiManager_ = GUIManager::getInstancePtr();
    5253
    5354        // show main menu
    5455        guiManager_->loadScene("MainMenu");
    5556        guiManager_->showGUI("MainMenu", 0);
    56         getParent()->getViewport()->setCamera(guiManager_->getCamera());
     57        GraphicsManager::getInstance().getViewport()->setCamera(guiManager_->getCamera());
    5758    }
    5859
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r2800 r2801  
    3030#include "GSGraphics.h"
    3131
    32 #include <fstream>
    3332#include <boost/filesystem.hpp>
     33#include <OgreRenderWindow.h>
    3434
    35 #include <OgreCompositorManager.h>
    36 #include <OgreConfigFile.h>
    37 #include <OgreFrameListener.h>
    38 #include <OgreRoot.h>
    39 #include <OgreLogManager.h>
    40 #include <OgreException.h>
    41 #include <OgreRenderWindow.h>
    42 #include <OgreRenderSystem.h>
    43 #include <OgreTextureManager.h>
    44 #include <OgreViewport.h>
    45 #include <OgreWindowEventUtilities.h>
    46 
    47 #include "SpecialConfig.h"
    4835#include "util/Debug.h"
    49 #include "util/Exception.h"
    50 #include "util/String.h"
    51 #include "util/SubString.h"
    52 #include "core/ConsoleCommand.h"
    5336#include "core/ConfigValueIncludes.h"
    5437#include "core/CoreIncludes.h"
     
    6144#include "overlays/console/InGameConsole.h"
    6245#include "gui/GUIManager.h"
    63 #include "tools/WindowEventListener.h"
    6446
    6547// for compatibility
    66 #include "GraphicsEngine.h"
     48#include "GraphicsManager.h"
    6749
    6850namespace orxonox
     
    7052    GSGraphics::GSGraphics()
    7153        : GameState<GSRoot>("graphics")
    72         , renderWindow_(0)
    73         , viewport_(0)
    74         , bWindowEventListenerUpdateRequired_(false)
    7554        , inputManager_(0)
    7655        , console_(0)
    7756        , guiManager_(0)
    78         , ogreRoot_(0)
    79         , ogreLogger_(0)
    80         , graphicsEngine_(0)
     57        , graphicsManager_(0)
    8158        , masterKeyBinder_(0)
    8259        , debugOverlay_(0)
     
    9269    void GSGraphics::setConfigValues()
    9370    {
    94         SetConfigValue(resourceFile_,    "resources.cfg")
    95             .description("Location of the resources file in the data path.");
    96         SetConfigValue(ogreConfigFile_,  "ogre.cfg")
    97             .description("Location of the Ogre config file");
    98         SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER)
    99             .description("Folder where the Ogre plugins are located.");
    100         SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
    101             .description("Comma separated list of all plugins to load.");
    102         SetConfigValue(ogreLogFile_,     "ogre.log")
    103             .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
    104         SetConfigValue(ogreLogLevelTrivial_ , 5)
    105             .description("Corresponding orxonox debug level for ogre Trivial");
    106         SetConfigValue(ogreLogLevelNormal_  , 4)
    107             .description("Corresponding orxonox debug level for ogre Normal");
    108         SetConfigValue(ogreLogLevelCritical_, 2)
    109             .description("Corresponding orxonox debug level for ogre Critical");
    11071    }
    11172
     
    11576
    11677        // initialise graphics engine. Doesn't load the render window yet!
    117         graphicsEngine_ = new GraphicsEngine();
    118 
    119         // Ogre setup procedure
    120         setupOgre();
    121         // load all the required plugins for Ogre
    122         loadOgrePlugins();
    123         // read resource declaration file
    124         this->declareResources();
    125         // Reads ogre config and creates the render window
    126         this->loadRenderer();
    127 
    128         // TODO: Spread this so that this call only initialises things needed for the Console and GUI
    129         this->initialiseResources();
    130 
    131         // We want to get informed whenever an object of type WindowEventListener is created
    132         // in order to later update the window size.
    133         bWindowEventListenerUpdateRequired_ = false;
    134         RegisterConstructionCallback(GSGraphics, orxonox::WindowEventListener, requestWindowEventListenerUpdate);
     78        this->graphicsManager_ = new GraphicsManager();
     79        this->graphicsManager_->initialise();
    13580
    13681        // load debug overlay
     
    14388        inputManager_ = new InputManager();
    14489        size_t windowHnd = 0;
    145         this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
    146         inputManager_->initialise(windowHnd, renderWindow_->getWidth(), renderWindow_->getHeight(), true);
     90        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
     91        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
     92        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
    14793        // Configure master input state with a KeyBinder
    14894        masterKeyBinder_ = new KeyBinder();
     
    15298        // Load the InGameConsole
    15399        console_ = new InGameConsole();
    154         console_->initialise(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
     100        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
    155101
    156102        // load the CEGUI interface
    157103        guiManager_ = new GUIManager();
    158         guiManager_->initialise(this->renderWindow_);
    159 
    160         // add console commands
    161         FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
    162         functor1->setObject(this);
    163         ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
    164         CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
     104        guiManager_->initialise(renderWindow);
    165105    }
    166106
    167107    void GSGraphics::leave()
    168108    {
    169         using namespace Ogre;
    170 
    171         delete this->ccPrintScreen_;
    172 
    173         // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
    174         Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
    175 
    176109        delete this->guiManager_;
    177110
     
    185118        delete this->debugOverlay_;
    186119
    187         // unload all compositors
    188         Ogre::CompositorManager::getSingleton().removeAll();
    189 
    190         // destroy render window
    191         RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
    192         renderer->destroyRenderWindow("Orxonox");
    193 
    194         /*** CODE SNIPPET, UNUSED ***/
    195         // Does the opposite of initialise()
    196         //ogreRoot_->shutdown();
    197         // Remove all resources and resource groups
    198         //StringVector groups = ResourceGroupManager::getSingleton().getResourceGroups();
    199         //for (StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
    200         //{
    201         //    ResourceGroupManager::getSingleton().destroyResourceGroup(*it);
    202         //}
    203 
    204         //ParticleSystemManager::getSingleton().removeAllTemplates();
    205 
    206         // Shutdown the render system
    207         //this->ogreRoot_->setRenderSystem(0);
    208 
    209         delete this->ogreRoot_;
    210 
    211         // delete the ogre log and the logManager (since we have created it).
    212         this->ogreLogger_->getDefaultLog()->removeListener(this);
    213         this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
    214         delete this->ogreLogger_;
    215 
    216         delete graphicsEngine_;
    217 
    218         Core::setShowsGraphics(false);
     120        delete graphicsManager_;
    219121    }
    220122
     
    231133        uint64_t timeBeforeTick = time.getRealMicroseconds();
    232134
    233         float dt = time.getDeltaTime();
    234 
    235         this->inputManager_->update(time);
    236         // tick console
     135        this->inputManager_->update(time);        // tick console
    237136        this->console_->update(time);
    238137        this->tickChild(time);
    239 
    240         if (this->bWindowEventListenerUpdateRequired_)
    241         {
    242             // Update all WindowEventListeners for the case a new one was created.
    243             this->windowResized(this->renderWindow_);
    244             this->bWindowEventListenerUpdateRequired_ = false;
    245         }
    246138
    247139        uint64_t timeAfterTick = time.getRealMicroseconds();
     
    251143
    252144        // Update statistics overlay. Note that the values only change periodically in GSRoot.
    253         GraphicsEngine::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
    254         GraphicsEngine::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
     145        GraphicsManager::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
     146        GraphicsManager::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
    255147
    256         // don't forget to call _fireFrameStarted in ogre to make sure
    257         // everything goes smoothly
    258         Ogre::FrameEvent evt;
    259         evt.timeSinceLastFrame = dt;
    260         evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
    261         ogreRoot_->_fireFrameStarted(evt);
    262 
    263         // Pump messages in all registered RenderWindows
    264         // This calls the WindowEventListener objects.
    265         Ogre::WindowEventUtilities::messagePump();
    266         // make sure the window stays active even when not focused
    267         // (probably only necessary on windows)
    268         this->renderWindow_->setActive(true);
    269 
    270         // render
    271         ogreRoot_->_updateAllRenderTargets();
    272 
    273         // again, just to be sure ogre works fine
    274         ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
    275     }
    276 
    277     /**
    278     @brief
    279         Creates the Ogre Root object and sets up the ogre log.
    280     */
    281     void GSGraphics::setupOgre()
    282     {
    283         COUT(3) << "Setting up Ogre..." << std::endl;
    284 
    285         if (ogreConfigFile_ == "")
    286         {
    287             COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
    288             ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
    289         }
    290         if (ogreLogFile_ == "")
    291         {
    292             COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
    293             ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
    294         }
    295 
    296         boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
    297         boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
    298 
    299         // create a new logManager
    300         // Ogre::Root will detect that we've already created a Log
    301         ogreLogger_ = new Ogre::LogManager();
    302         COUT(4) << "Ogre LogManager created" << std::endl;
    303 
    304         // create our own log that we can listen to
    305         Ogre::Log *myLog;
    306         myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
    307         COUT(4) << "Ogre Log created" << std::endl;
    308 
    309         myLog->setLogDetail(Ogre::LL_BOREME);
    310         myLog->addListener(this);
    311 
    312         COUT(4) << "Creating Ogre Root..." << std::endl;
    313 
    314         // check for config file existence because Ogre displays (caught) exceptions if not
    315         if (!boost::filesystem::exists(ogreConfigFilepath))
    316         {
    317             // create a zero sized file
    318             std::ofstream creator;
    319             creator.open(ogreConfigFilepath.string().c_str());
    320             creator.close();
    321         }
    322 
    323         // Leave plugins file empty. We're going to do that part manually later
    324         ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
    325 
    326         COUT(3) << "Ogre set up done." << std::endl;
    327     }
    328 
    329     void GSGraphics::loadOgrePlugins()
    330     {
    331         // just to make sure the next statement doesn't segfault
    332         if (ogrePluginsFolder_ == "")
    333             ogrePluginsFolder_ = ".";
    334 
    335         boost::filesystem::path folder(ogrePluginsFolder_);
    336         // Do some SubString magic to get the comma separated list of plugins
    337         SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0');
    338         // Use backslash paths on Windows! file_string() already does that though.
    339         for (unsigned int i = 0; i < plugins.size(); ++i)
    340             ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
    341     }
    342 
    343     void GSGraphics::declareResources()
    344     {
    345         CCOUT(4) << "Declaring Resources" << std::endl;
    346         //TODO: Specify layout of data file and maybe use xml-loader
    347         //TODO: Work with ressource groups (should be generated by a special loader)
    348 
    349         if (resourceFile_ == "")
    350         {
    351             COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
    352             ModifyConfigValue(resourceFile_, tset, "resources.cfg");
    353         }
    354 
    355         // Load resource paths from data file using configfile ressource type
    356         Ogre::ConfigFile cf;
    357         try
    358         {
    359             cf.load((Core::getMediaPath() / resourceFile_).string());
    360         }
    361         catch (...)
    362         {
    363             //COUT(1) << ex.getFullDescription() << std::endl;
    364             COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
    365             throw;
    366         }
    367 
    368         // Go through all sections & settings in the file
    369         Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    370 
    371         std::string secName, typeName, archName;
    372         while (seci.hasMoreElements())
    373         {
    374             try
    375             {
    376                 secName = seci.peekNextKey();
    377                 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
    378                 Ogre::ConfigFile::SettingsMultiMap::iterator i;
    379                 for (i = settings->begin(); i != settings->end(); ++i)
    380                 {
    381                     typeName = i->first; // for instance "FileSystem" or "Zip"
    382                     archName = i->second; // name (and location) of archive
    383 
    384                     Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    385                         (Core::getMediaPath() / archName).string(), typeName, secName);
    386                 }
    387             }
    388             catch (Ogre::Exception& ex)
    389             {
    390                 COUT(1) << ex.getFullDescription() << std::endl;
    391             }
    392         }
    393     }
    394 
    395     void GSGraphics::loadRenderer()
    396     {
    397         CCOUT(4) << "Configuring Renderer" << std::endl;
    398 
    399         if (!ogreRoot_->restoreConfig())
    400             if (!ogreRoot_->showConfigDialog())
    401                 ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
    402 
    403         CCOUT(4) << "Creating render window" << std::endl;
    404 
    405         this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
    406 
    407         Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
    408 
    409         Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
    410 
    411         // create a full screen default viewport
    412         this->viewport_ = this->renderWindow_->addViewport(0, 0);
    413 
    414         if (this->graphicsEngine_)
    415             this->graphicsEngine_->setViewport(this->viewport_);
    416     }
    417 
    418     void GSGraphics::initialiseResources()
    419     {
    420         CCOUT(4) << "Initialising resources" << std::endl;
    421         //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
    422         //try
    423         //{
    424             Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    425             /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
    426             for (unsigned int i = 0; i < str.size(); i++)
    427             {
    428             Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
    429             }*/
    430         //}
    431         //catch (...)
    432         //{
    433         //    CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
    434         //    throw;
    435         //}
    436     }
    437 
    438     /**
    439     @brief
    440         Method called by the LogListener interface from Ogre.
    441         We use it to capture Ogre log messages and handle it ourselves.
    442     @param message
    443         The message to be logged
    444     @param lml
    445         The message level the log is using
    446     @param maskDebug
    447         If we are printing to the console or not
    448     @param logName
    449         The name of this log (so you can have several listeners
    450         for different logs, and identify them)
    451     */
    452     void GSGraphics::messageLogged(const std::string& message,
    453         Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
    454     {
    455         int orxonoxLevel;
    456         switch (lml)
    457         {
    458         case Ogre::LML_TRIVIAL:
    459             orxonoxLevel = this->ogreLogLevelTrivial_;
    460             break;
    461         case Ogre::LML_NORMAL:
    462             orxonoxLevel = this->ogreLogLevelNormal_;
    463             break;
    464         case Ogre::LML_CRITICAL:
    465             orxonoxLevel = this->ogreLogLevelCritical_;
    466             break;
    467         default:
    468             orxonoxLevel = 0;
    469         }
    470         OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
    471             << "Ogre: " << message << std::endl;
    472     }
    473 
    474     /**
    475     @brief
    476         Window has moved.
    477     @param rw
    478         The render window it occured in
    479     */
    480     void GSGraphics::windowMoved(Ogre::RenderWindow *rw)
    481     {
    482         for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    483             it->windowMoved();
     148        this->graphicsManager_->update(time);
    484149    }
    485150
     
    490155        The render window it occured in
    491156    @note
    492         GraphicsEngine has a render window stored itself. This is the same
     157        GraphicsManager has a render window stored itself. This is the same
    493158        as rw. But we have to be careful when using multiple render windows!
    494159    */
    495     void GSGraphics::windowResized(Ogre::RenderWindow *rw)
     160    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
    496161    {
    497         for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    498             it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
    499 
    500162        // OIS needs this under linux even if we only use relative input measurement.
    501163        if (this->inputManager_)
    502             this->inputManager_->setWindowExtents(renderWindow_->getWidth(), renderWindow_->getHeight());
     164            this->inputManager_->setWindowExtents(newWidth, newHeight);
    503165    }
    504166
     
    509171        The render window it occured in
    510172    */
    511     void GSGraphics::windowFocusChange(Ogre::RenderWindow *rw)
     173    void GSGraphics::windowFocusChanged()
    512174    {
    513         for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    514             it->windowFocusChanged();
    515 
    516175        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
    517176        if (this->inputManager_)
     
    519178    }
    520179
    521     /**
    522     @brief
    523         Window was closed.
    524     @param rw
    525         The render window it occured in
    526     */
    527     void GSGraphics::windowClosed(Ogre::RenderWindow *rw)
    528     {
    529         this->requestState("root");
    530     }
    531 
    532     void GSGraphics::printScreen()
    533     {
    534         if (this->renderWindow_)
    535         {
    536             this->renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg");
    537         }
    538     }
    539180}
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r2799 r2801  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #define NOMINMAX // required to stop windows.h screwing up std::min definition
    34 #include <OgreWindowEventUtilities.h>
    35 #include <OgreLog.h>
    3633#include "core/GameState.h"
    3734#include "core/OrxonoxClass.h"
     35#include "tools/WindowEventListener.h"
    3836#include "GSRoot.h"
    3937
    4038namespace orxonox
    4139{
    42     class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass,
    43                                       public Ogre::WindowEventListener, public Ogre::LogListener
     40    class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public WindowEventListener
    4441    {
    4542        friend class ClassIdentifier<GSGraphics>;
     
    4845        GSGraphics();
    4946        ~GSGraphics();
    50 
    51         Ogre::Root*     getOgreRoot()   { return this->ogreRoot_  ; }
    52         Ogre::Viewport* getViewport()   { return this->viewport_  ; }
    53         GUIManager*     getGUIManager() { return this->guiManager_; }
    5447
    5548    private: // functions
     
    6053        void setConfigValues();
    6154
    62         void setupOgre();
    63         void loadOgrePlugins();
    64         void declareResources();
    65         void loadRenderer();
    66         void initialiseResources();
     55        // Window events from WindowEventListener
     56        void windowResized(unsigned int newWidth, unsigned int newHeight);
     57        void windowFocusChanged();
    6758
    68         // console commands
    69         void printScreen();
    70 
    71         // event from Ogre::LogListener
    72         void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
    73             bool maskDebug, const std::string& logName);
    74 
    75         // window events from Ogre::WindowEventListener
    76         void windowMoved       (Ogre::RenderWindow* rw);
    77         void windowResized     (Ogre::RenderWindow* rw);
    78         void windowFocusChange (Ogre::RenderWindow* rw);
    79         void windowClosed      (Ogre::RenderWindow* rw);
    80 
    81         void requestWindowEventListenerUpdate() { this->bWindowEventListenerUpdateRequired_ = true; }
    82 
    83     private: // variables
    84         Ogre::RenderWindow*   renderWindow_;          //!< the current render window
    85         Ogre::Viewport*       viewport_;              //!< default full size viewport
    86         bool bWindowEventListenerUpdateRequired_;     //!< True if a new WindowEventListener was created but not yet updated.
    87 
     59    private:
    8860        // managed singletons
    8961        InputManager*         inputManager_;
    9062        InGameConsole*        console_;
    9163        GUIManager*           guiManager_;
    92         Ogre::Root*           ogreRoot_;                  //!< Ogre's root
    93         Ogre::LogManager*     ogreLogger_;
    94         GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
     64        GraphicsManager*      graphicsManager_;       //!< Interface to Ogre
    9565
    9666        KeyBinder*            masterKeyBinder_;
    9767        XMLFile*              debugOverlay_;
    98 
    99         // config values
    100         std::string           resourceFile_;             //!< resources file name
    101         std::string           ogreConfigFile_;           //!< ogre config file name
    102         std::string           ogrePluginsFolder_;        //!< Folder where the Ogre plugins are located
    103         std::string           ogrePlugins_;              //!< Comma separated list of all plugins to load
    104         std::string           ogreLogFile_;              //!< log file name for Ogre log messages
    105         int                   ogreLogLevelTrivial_;      //!< Corresponding Orxonx debug level for LL_TRIVIAL
    106         int                   ogreLogLevelNormal_;       //!< Corresponding Orxonx debug level for LL_NORMAL
    107         int                   ogreLogLevelCritical_;     //!< Corresponding Orxonx debug level for LL_CRITICAL
    108 
    109         // console commands
    110         ConsoleCommand*       ccPrintScreen_;
    11168    };
    11269}
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r2759 r2801  
    4444#include "objects/Radar.h"
    4545#include "CameraManager.h"
     46#include "GraphicsManager.h"
    4647#include "LevelManager.h"
    4748#include "PlayerManager.h"
     
    7778    }
    7879
    79     void GSLevel::enter(Ogre::Viewport* viewport)
     80    void GSLevel::enter()
    8081    {
    8182        if (Core::showsGraphics())
     
    8788
    8889            // create the global CameraManager
    89             assert(viewport);
    90             this->cameraManager_ = new CameraManager(viewport);
     90            this->cameraManager_ = new CameraManager(GraphicsManager::getInstance().getViewport());
    9191
    9292            // Start the Radar
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r2790 r2801  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include <OgrePrerequisites.h>
    3433#include "core/OrxonoxClass.h"
    3534
     
    4746
    4847    protected:
    49         void enter(Ogre::Viewport* viewport);
     48        void enter();
    5049        void leave();
    5150        void ticked(const Clock& time);
  • code/branches/gui/src/orxonox/gamestates/GSServer.cc

    r2800 r2801  
    5555        COUT(0) << "Loading scene in server mode" << std::endl;
    5656
    57         GSLevel::enter(this->getParent()->getViewport());
     57        GSLevel::enter();
    5858
    5959        server_->open();
  • code/branches/gui/src/orxonox/gamestates/GSStandalone.cc

    r2800 r2801  
    3535#include "core/ConsoleCommand.h"
    3636#include "gui/GUIManager.h"
     37#include "GraphicsManager.h"
    3738
    3839namespace orxonox
     
    6061        Core::setIsStandalone(true);
    6162
    62         GSLevel::enter(this->getParent()->getViewport());
     63        GSLevel::enter();
    6364
    64         guiManager_ = getParent()->getGUIManager();
     65        guiManager_ = GUIManager::getInstancePtr();
    6566        // not sure if necessary
    6667        // guiManager_->loadScene("IngameMenu");
     
    7879        if (guiShowing_s)
    7980        {
    80             guiManager_->showGUI("IngameMenu", this->getParent()->getViewport()->getCamera()->getSceneManager());
     81            Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
     82            guiManager_->showGUI("IngameMenu", viewport->getCamera()->getSceneManager());
    8183        }
    8284        else
  • code/branches/gui/src/orxonox/gui/GUIManager.cc

    r2790 r2801  
    271271            try
    272272            {
    273                 COUT (0) << "************* sceneManager: " << sceneManager << std::endl;
     273//                COUT (0) << "************* sceneManager: " << sceneManager << std::endl;
    274274                if (!sceneManager)
    275275                {
  • code/branches/gui/src/orxonox/objects/worldentities/Planet.cc

    r2710 r2801  
    4242#include "CameraManager.h"
    4343#include "Camera.h"
    44 #include "GraphicsEngine.h"
     44#include "GraphicsManager.h"
    4545
    4646namespace orxonox
  • code/branches/gui/src/orxonox/overlays/OrxonoxOverlay.cc

    r2662 r2801  
    3939#include <OgreOverlayManager.h>
    4040#include <OgrePanelOverlayElement.h>
     41#include <OgreRenderWindow.h>
     42
    4143#include "util/Convert.h"
    4244#include "util/Exception.h"
     
    4648#include "core/XMLPort.h"
    4749#include "core/ConsoleCommand.h"
     50#include "GraphicsManager.h"
    4851
    4952namespace orxonox
     
    7780        this->overlay_->add2D(this->background_);
    7881
    79         // We'll have to set the aspect ratio to a default value first.
    80         // GSGraphics gets informed about our construction here and can update us in the next tick.
    81         this->windowAspectRatio_ = 1.0;
     82        // Get aspect ratio from the render window. Later on, we get informed automatically
     83        Ogre::RenderWindow* defaultWindow = GraphicsManager::getInstance().getRenderWindow();
     84        this->windowAspectRatio_ = (float)defaultWindow->getWidth() / defaultWindow->getHeight();
    8285        this->sizeCorrectionChanged();
    8386
     
    175178    /**
    176179    @brief
    177         Called by the GraphicsEngine whenever the window size changes.
     180        Called by the GraphicsManager whenever the window size changes.
    178181        Calculates the aspect ratio only.
    179182    */
    180     void OrxonoxOverlay::windowResized(int newWidth, int newHeight)
     183    void OrxonoxOverlay::windowResized(unsigned int newWidth, unsigned int newHeight)
    181184    {
    182185        this->windowAspectRatio_ = newWidth/(float)newHeight;
  • code/branches/gui/src/orxonox/overlays/OrxonoxOverlay.h

    r2662 r2801  
    200200
    201201    private:
    202         void windowResized(int newWidth, int newHeight);
     202        void windowResized(unsigned int newWidth, unsigned int newHeight);
    203203
    204204        static unsigned int hudOverlayCounter_s;   //!< Static counter for hud elements
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc

    r2800 r2801  
    410410        @brief Resizes the console elements. Call if window size changes.
    411411    */
    412     void InGameConsole::windowResized(int newWidth, int newHeight)
     412    void InGameConsole::windowResized(unsigned int newWidth, unsigned int newHeight)
    413413    {
    414414        this->windowW_ = newWidth;
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.h

    r2800 r2801  
    8181        void print(const std::string& text, int index, bool alwaysShift = false);
    8282
    83         void windowResized(int newWidth, int newHeight);
     83        void windowResized(unsigned int newWidth, unsigned int newHeight);
    8484
    8585        // config value related
  • code/branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc

    r2662 r2801  
    3131#include <OgreTextAreaOverlayElement.h>
    3232#include "core/CoreIncludes.h"
    33 #include "GraphicsEngine.h"
     33#include "GraphicsManager.h"
    3434#include "util/Convert.h"
    3535
     
    5151        SUPER(DebugFPSText, tick, dt);
    5252
    53         float fps = GraphicsEngine::getInstance().getAverageFramesPerSecond();
     53        float fps = GraphicsManager::getInstance().getAverageFramesPerSecond();
    5454        this->setCaption(convertToString(fps));
    5555    }
  • code/branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc

    r2662 r2801  
    3232#include "core/CoreIncludes.h"
    3333#include "util/Convert.h"
    34 #include "GraphicsEngine.h"
     34#include "GraphicsManager.h"
    3535
    3636namespace orxonox
     
    5151        SUPER(DebugRTRText, tick, dt);
    5252
    53         float rtr = GraphicsEngine::getInstance().getAverageTickTime();
     53        float rtr = GraphicsManager::getInstance().getAverageTickTime();
    5454        this->setCaption(convertToString(rtr));
    5555    }
  • code/branches/gui/src/orxonox/tools/ParticleInterface.cc

    r2662 r2801  
    4040#include <cassert>
    4141
    42 #include "GraphicsEngine.h"
     42#include "GraphicsManager.h"
    4343#include "core/Core.h"
    4444#include "core/CoreIncludes.h"
     
    178178    {
    179179        this->detaillevel_ = level;
    180         if (GraphicsEngine::getInstancePtr())
    181             this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle());
     180        if (Core::showsGraphics())
     181            this->detailLevelChanged(GraphicsManager::getInstance().getDetailLevelParticle());
    182182    }
    183183
  • code/branches/gui/src/orxonox/tools/Shader.cc

    r2662 r2801  
    3939#include "core/CoreIncludes.h"
    4040#include "core/Executor.h"
    41 #include "GraphicsEngine.h"
     41#include "GraphicsManager.h"
    4242#include "util/Exception.h"
    4343
     
    5959        this->compositorInstance_ = 0;
    6060        this->bVisible_ = true;
    61         this->bLoadCompositor_ = Core::showsGraphics() && GraphicsEngine::getInstancePtr();
     61        this->bLoadCompositor_ = Core::showsGraphics();
    6262        this->bViewportInitialized_ = false;
    6363        this->compositor_ = "";
     
    8686        if (this->bLoadCompositor_ && this->compositorInstance_)
    8787        {
    88             Ogre::Viewport* viewport = GraphicsEngine::getInstance().getViewport();
     88            Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
    8989            assert(viewport);
    9090            Ogre::CompositorManager::getSingleton().removeCompositor(viewport, this->compositor_);
     
    114114        if (this->bLoadCompositor_)
    115115        {
    116             Ogre::Viewport* viewport = GraphicsEngine::getInstance().getViewport();
     116            Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
    117117            assert(viewport);
    118118            if (this->oldcompositor_ != "")
  • code/branches/gui/src/orxonox/tools/WindowEventListener.h

    r2662 r2801  
    4949
    5050            /** Window has resized */
    51             virtual void windowResized(int newWidth, int newHeight) { }
     51            virtual void windowResized(unsigned int newWidth, unsigned int newHeight) { }
    5252
    5353            /** Window has lost/gained focus */
Note: See TracChangeset for help on using the changeset viewer.