Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5614


Ignore:
Timestamp:
Aug 10, 2009, 5:36:45 PM (15 years ago)
Author:
rgrieder
Message:

Creating Ogre::Root in non graphics mode as well. This allows to always make use of the ResourceGroupManager.
Also removed resource related parts from GraphicsManager.

This revision does not run!

Location:
code/branches/resource2/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/core/Core.cc

    r3370 r5614  
    313313        // creates the class hierarchy for all classes with factories
    314314        Factory::createClassHierarchy();
     315
     316        // Load OGRE excluding the renderer and the render window
     317        this->graphicsManager_.reset(new GraphicsManager(false));
    315318    }
    316319
     
    328331            return;
    329332
    330         // Load OGRE including the render window
    331         scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());
     333        // Upgrade OGRE to receive a render window
     334        graphicsManager_->upgradeToGraphics();
    332335
    333336        // The render window width and height are used to set up the mouse movement.
    334337        size_t windowHnd = 0;
    335         graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
     338        graphicsManager_->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
    336339
    337340        // Calls the InputManager which sets up the input devices.
     
    339342
    340343        // load the CEGUI interface
    341         guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow()));
    342 
    343         // Dismiss scoped pointers
    344         graphicsManager_.swap(graphicsManager);
     344        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow()));
     345
     346        // Dismiss scoped pointer
    345347        inputManager_.swap(inputManager);
    346348
     
    356358        this->inputManager_.reset();;
    357359        this->graphicsManager_.reset();
     360
     361        // Load Ogre::Root again, but without the render system
     362        this->graphicsManager_.reset(new GraphicsManager(false));
    358363
    359364        bGraphicsLoaded_ = false;
  • code/branches/resource2/src/core/GraphicsManager.cc

    r3370 r5614  
    3737
    3838#include <fstream>
    39 #include <memory>
    4039#include <boost/filesystem.hpp>
    41 #include <boost/shared_ptr.hpp>
    42 
    43 #include <OgreCompositorManager.h>
    44 #include <OgreConfigFile.h>
     40
    4541#include <OgreFrameListener.h>
    4642#include <OgreRoot.h>
     
    4945#include <OgreRenderWindow.h>
    5046#include <OgreRenderSystem.h>
    51 #include <OgreTextureManager.h>
    5247#include <OgreViewport.h>
    5348#include <OgreWindowEventUtilities.h>
     
    6863namespace orxonox
    6964{
    70     using boost::shared_ptr;
    71 
    7265    class OgreWindowEventListener : public Ogre::WindowEventListener
    7366    {
     
    8982        Non-initialising constructor.
    9083    */
    91     GraphicsManager::GraphicsManager()
    92         : ogreRoot_(0)
    93         , ogreLogger_(0)
    94         , renderWindow_(0)
     84    GraphicsManager::GraphicsManager(bool bLoadRenderer)
     85        : renderWindow_(0)
    9586        , viewport_(0)
    9687        , ogreWindowEventListener_(new OgreWindowEventListener())
     
    10091        this->setConfigValues();
    10192
    102         // Ogre setup procedure
    103         setupOgre();
    104 
    105         try
    106         {
    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
     93        // Ogre setup procedure (creating Ogre::Root)
     94        this->loadOgreRoot();
     95        // load all the required plugins for Ogre
     96        this->loadOgrePlugins();
     97
     98        if (bLoadRenderer)
     99        {
     100            // Reads the ogre config and creates the render window
    112101            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         catch (...)
    124         {
    125             // clean up
    126             delete this->ogreRoot_;
    127             delete this->ogreLogger_;
    128             delete this->ogreWindowEventListener_;
    129             throw;
    130         }
    131     }
    132 
    133     /**
    134     @brief
    135         Destroys all the Ogre related objects
     102        }
     103    }
     104
     105    /**
     106    @brief
     107        Destruction is done by the member scoped_ptrs.
    136108    */
    137109    GraphicsManager::~GraphicsManager()
    138110    {
    139 /*
    140         delete this->ccPrintScreen_;
    141 */
    142 
    143         // unload all compositors (this is only necessary because we don't yet destroy all resources!)
    144         Ogre::CompositorManager::getSingleton().removeAll();
    145 
    146         // Delete OGRE main control organ
    147         delete this->ogreRoot_;
    148 
    149         // delete the logManager (since we have created it in the first place).
    150         delete this->ogreLogger_;
    151 
    152         delete this->ogreWindowEventListener_;
    153111    }
    154112
    155113    void GraphicsManager::setConfigValues()
    156114    {
    157         SetConfigValue(resourceFile_,    "resources.cfg")
    158             .description("Location of the resources file in the data path.");
    159115        SetConfigValue(ogreConfigFile_,  "ogre.cfg")
    160116            .description("Location of the Ogre config file");
     
    173129    }
    174130
     131    /**
     132    @brief
     133        Loads the renderer and creates the render window if not yet done so.
     134    @remarks
     135        This operation is irreversible without recreating the GraphicsManager!
     136    */
     137    void GraphicsManager::upgradeToGraphics()
     138    {
     139        if (renderWindow_ == NULL)
     140        {
     141            this->loadRenderer();
     142        }
     143    }
     144
     145    /**
     146    @brief
     147        Creates the Ogre Root object and sets up the ogre log.
     148    */
     149    void GraphicsManager::loadOgreRoot()
     150    {
     151        COUT(3) << "Setting up Ogre..." << std::endl;
     152
     153        if (ogreConfigFile_ == "")
     154        {
     155            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
     156            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
     157        }
     158        if (ogreLogFile_ == "")
     159        {
     160            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
     161            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
     162        }
     163
     164        boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
     165        boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
     166
     167        // create a new logManager
     168        // Ogre::Root will detect that we've already created a Log
     169        ogreLogger_.reset(new Ogre::LogManager());
     170        COUT(4) << "Ogre LogManager created" << std::endl;
     171
     172        // create our own log that we can listen to
     173        Ogre::Log *myLog;
     174        myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
     175        COUT(4) << "Ogre Log created" << std::endl;
     176
     177        myLog->setLogDetail(Ogre::LL_BOREME);
     178        myLog->addListener(this);
     179
     180        COUT(4) << "Creating Ogre Root..." << std::endl;
     181
     182        // check for config file existence because Ogre displays (caught) exceptions if not
     183        if (!boost::filesystem::exists(ogreConfigFilepath))
     184        {
     185            // create a zero sized file
     186            std::ofstream creator;
     187            creator.open(ogreConfigFilepath.string().c_str());
     188            creator.close();
     189        }
     190
     191        // Leave plugins file empty. We're going to do that part manually later
     192        ogreRoot_.reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()));
     193
     194        COUT(3) << "Ogre set up done." << std::endl;
     195    }
     196
     197    void GraphicsManager::loadOgrePlugins()
     198    {
     199        // just to make sure the next statement doesn't segfault
     200        if (ogrePluginsFolder_ == "")
     201            ogrePluginsFolder_ = ".";
     202
     203        boost::filesystem::path folder(ogrePluginsFolder_);
     204        // Do some SubString magic to get the comma separated list of plugins
     205        SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '(', ')', false, '\0');
     206        // Use backslash paths on Windows! file_string() already does that though.
     207        for (unsigned int i = 0; i < plugins.size(); ++i)
     208            ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
     209    }
     210
     211    void GraphicsManager::loadRenderer()
     212    {
     213        CCOUT(4) << "Configuring Renderer" << std::endl;
     214
     215        if (!ogreRoot_->restoreConfig())
     216            if (!ogreRoot_->showConfigDialog())
     217                ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue failed.");
     218
     219        CCOUT(4) << "Creating render window" << std::endl;
     220
     221        this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
     222        // Propagate the size of the new winodw
     223        this->ogreWindowEventListener_->windowResized(renderWindow_);
     224
     225        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_.get());
     226
     227        // create a full screen default viewport
     228        // Note: This may throw when adding a viewport with an existing z-order!
     229        //       But in our case we only have one viewport for now anyway, therefore
     230        //       no ScopeGuards or anything to handle exceptions.
     231        this->viewport_ = this->renderWindow_->addViewport(0, 0);
     232
     233        // add console commands
     234        FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
     235        ccPrintScreen_ = createConsoleCommand(functor1->setObject(this), "printScreen");
     236        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
     237    }
     238
    175239    void GraphicsManager::update(const Clock& time)
    176240    {
     
    207271    {
    208272        this->viewport_->setCamera(camera);
    209     }
    210 
    211     /**
    212     @brief
    213         Creates the Ogre Root object and sets up the ogre log.
    214     */
    215     void GraphicsManager::setupOgre()
    216     {
    217         COUT(3) << "Setting up Ogre..." << std::endl;
    218 
    219         if (ogreConfigFile_ == "")
    220         {
    221             COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
    222             ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
    223         }
    224         if (ogreLogFile_ == "")
    225         {
    226             COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
    227             ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
    228         }
    229 
    230         boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
    231         boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
    232 
    233         // create a new logManager
    234         // Ogre::Root will detect that we've already created a Log
    235         std::auto_ptr<Ogre::LogManager> logger(new Ogre::LogManager());
    236         COUT(4) << "Ogre LogManager created" << std::endl;
    237 
    238         // create our own log that we can listen to
    239         Ogre::Log *myLog;
    240         myLog = logger->createLog(ogreLogFilepath.string(), true, false, false);
    241         COUT(4) << "Ogre Log created" << std::endl;
    242 
    243         myLog->setLogDetail(Ogre::LL_BOREME);
    244         myLog->addListener(this);
    245 
    246         COUT(4) << "Creating Ogre Root..." << std::endl;
    247 
    248         // check for config file existence because Ogre displays (caught) exceptions if not
    249         if (!boost::filesystem::exists(ogreConfigFilepath))
    250         {
    251             // create a zero sized file
    252             std::ofstream creator;
    253             creator.open(ogreConfigFilepath.string().c_str());
    254             creator.close();
    255         }
    256 
    257         // Leave plugins file empty. We're going to do that part manually later
    258         ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
    259         // In case that new Root failed the logger gets destroyed because of the std::auto_ptr
    260         ogreLogger_ = logger.release();
    261 
    262         COUT(3) << "Ogre set up done." << std::endl;
    263     }
    264 
    265     void GraphicsManager::loadOgrePlugins()
    266     {
    267         // just to make sure the next statement doesn't segfault
    268         if (ogrePluginsFolder_ == "")
    269             ogrePluginsFolder_ = ".";
    270 
    271         boost::filesystem::path folder(ogrePluginsFolder_);
    272         // Do some SubString magic to get the comma separated list of plugins
    273         SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '(', ')', false, '\0');
    274         // Use backslash paths on Windows! file_string() already does that though.
    275         for (unsigned int i = 0; i < plugins.size(); ++i)
    276             ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
    277     }
    278 
    279     void GraphicsManager::declareResources()
    280     {
    281         CCOUT(4) << "Declaring Resources" << std::endl;
    282         //TODO: Specify layout of data file and maybe use xml-loader
    283         //TODO: Work with ressource groups (should be generated by a special loader)
    284 
    285         if (resourceFile_ == "")
    286         {
    287             COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
    288             ModifyConfigValue(resourceFile_, tset, "resources.cfg");
    289         }
    290 
    291         // Load resource paths from data file using configfile ressource type
    292         Ogre::ConfigFile cf;
    293         try
    294         {
    295             cf.load((Core::getMediaPath() / resourceFile_).string());
    296         }
    297         catch (...)
    298         {
    299             //COUT(1) << ex.getFullDescription() << std::endl;
    300             COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
    301             throw;
    302         }
    303 
    304         // Go through all sections & settings in the file
    305         Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    306 
    307         std::string secName, typeName, archName;
    308         while (seci.hasMoreElements())
    309         {
    310             try
    311             {
    312                 secName = seci.peekNextKey();
    313                 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
    314                 Ogre::ConfigFile::SettingsMultiMap::iterator i;
    315                 for (i = settings->begin(); i != settings->end(); ++i)
    316                 {
    317                     typeName = i->first; // for instance "FileSystem" or "Zip"
    318                     archName = i->second; // name (and location) of archive
    319 
    320                     Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    321                         (Core::getMediaPath() / archName).string(), typeName, secName);
    322                 }
    323             }
    324             catch (Ogre::Exception& ex)
    325             {
    326                 COUT(1) << ex.getFullDescription() << std::endl;
    327             }
    328         }
    329     }
    330 
    331     void GraphicsManager::loadRenderer()
    332     {
    333         CCOUT(4) << "Configuring Renderer" << std::endl;
    334 
    335         if (!ogreRoot_->restoreConfig())
    336             if (!ogreRoot_->showConfigDialog())
    337                 ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue failed.");
    338 
    339         CCOUT(4) << "Creating render window" << std::endl;
    340 
    341         this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
    342         this->ogreWindowEventListener_->windowResized(renderWindow_);
    343 
    344         Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
    345 
    346         Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
    347 
    348         // create a full screen default viewport
    349         this->viewport_ = this->renderWindow_->addViewport(0, 0);
    350     }
    351 
    352     void GraphicsManager::initialiseResources()
    353     {
    354         CCOUT(4) << "Initialising resources" << std::endl;
    355         //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
    356         //try
    357         //{
    358             Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    359             /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
    360             for (unsigned int i = 0; i < str.size(); i++)
    361             {
    362             Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
    363             }*/
    364         //}
    365         //catch (...)
    366         //{
    367         //    CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
    368         //    throw;
    369         //}
    370273    }
    371274
  • code/branches/resource2/src/core/GraphicsManager.h

    r3370 r5614  
    4242#include <string>
    4343#include <OgreLog.h>
     44#include <boost/scoped_ptr.hpp>
     45
    4446#include "util/Singleton.h"
    4547#include "OrxonoxClass.h"
     
    4749namespace orxonox
    4850{
     51    using boost::scoped_ptr;
     52
    4953    /**
    5054    @brief
     
    5559        friend class Singleton<GraphicsManager>;
    5660    public:
    57         GraphicsManager();
     61        GraphicsManager(bool bLoadRenderer = true);
    5862        ~GraphicsManager();
    5963
     
    6266        void update(const Clock& time);
    6367
    64         inline Ogre::Viewport* getViewport()
    65             { return this->viewport_; }
    66         inline Ogre::RenderWindow* getRenderWindow()
    67             { return this->renderWindow_; }
     68        Ogre::Viewport* getViewport()         { return this->viewport_; }
     69        Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
     70
     71        void upgradeToGraphics();
     72        bool rendererLoaded() const { return renderWindow_ != NULL; }
    6873
    6974        void setCamera(Ogre::Camera* camera);
     
    7378
    7479        // OGRE initialisation
    75         void setupOgre();
     80        void loadOgreRoot();
    7681        void loadOgrePlugins();
    77         void declareResources();
    7882        void loadRenderer();
    79         void initialiseResources();
    8083
    8184        // event from Ogre::LogListener
     
    8790
    8891    private:
    89         Ogre::Root*         ogreRoot_;                 //!< Ogre's root
    90         Ogre::LogManager*   ogreLogger_;
     92        scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
     93        scoped_ptr<Ogre::LogManager>        ogreLogger_;
     94        scoped_ptr<Ogre::Root>              ogreRoot_;                //!< Ogre's root
    9195        Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
    9296        Ogre::Viewport*     viewport_;                 //!< default full size viewport
    93         OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
    9497
    9598        // config values
    96         std::string         resourceFile_;             //!< resources file name
    9799        std::string         ogreConfigFile_;           //!< ogre config file name
    98100        std::string         ogrePluginsFolder_;        //!< Folder where the Ogre plugins are located
  • code/branches/resource2/src/orxonox/gamestates/GSLevel.cc

    r3370 r5614  
    2929
    3030#include "GSLevel.h"
     31
     32#include <OgreCompositorManager.h>
    3133
    3234#include "core/input/InputManager.h"
     
    170172*/
    171173
     174        if (GameMode::showsGraphics())
     175        {
     176            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
     177            Ogre::CompositorManager::getSingleton().removeAll();
     178        }
    172179
    173180        // this call will delete every BaseObject!
Note: See TracChangeset for help on using the changeset viewer.