Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2008, 7:39:38 PM (16 years ago)
Author:
rgrieder
Message:

Moved all Ogre related code from GSRoot to GSGraphics.
You should now be able to start the gui, goto ioConsole, then start the gui again and load the level.
gui —> level —> gui doesn't yet work. But I will not dig into that until our object hierarchy has been replaced.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r1887 r1891  
    3434#include <OgreFrameListener.h>
    3535#include <OgreRoot.h>
     36#include <OgreLogManager.h>
    3637#include <OgreException.h>
    3738#include <OgreRenderWindow.h>
     
    6162    GSGraphics::GSGraphics()
    6263        : GameState<GSRoot>("graphics")
    63         , ogreRoot_(0)
     64        , renderWindow_(0)
     65        , viewport_(0)
    6466        , inputManager_(0)
    6567        , console_(0)
    6668        , guiManager_(0)
     69        , ogreRoot_(0)
     70        , ogreLogger_(0)
     71        , graphicsEngine_(0)
    6772        , masterKeyBinder_(0)
    6873        , frameCount_(0)
     
    7378    {
    7479        RegisterRootObject(GSGraphics);
     80        setConfigValues();
    7581    }
    7682
     
    8288    {
    8389        SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path.");
    84         SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated.");
     90        SetConfigValue(ogreConfigFile_,  "ogre.cfg").description("Location of the Ogre config file");
     91        SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");
     92        SetConfigValue(ogreLogFile_,     "ogre.log").description("Logfile for messages from Ogre. \
     93                                                                 Use \"\" to suppress log file creation.");
     94        SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
     95        SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
     96        SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
     97        SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at \
     98                                                                    which average fps, etc. get updated.");
    8599    }
    86100
     
    89103        Settings::_getInstance().bShowsGraphics_ = true;
    90104
    91         setConfigValues();
    92 
    93         this->ogreRoot_ = getParent()->getOgreRoot();
    94 
     105        // initialise graphics engine. Doesn't load the render window yet!
     106        graphicsEngine_ = new GraphicsEngine();
     107
     108        // Ogre setup procedure
     109        setupOgre();
    95110        this->declareResources();
    96111        this->loadRenderer();    // creates the render window
     
    100115
    101116        // HACK: temporary:
    102         GraphicsEngine* graphicsEngine = getParent()->getGraphicsEngine();
    103         graphicsEngine->renderWindow_  = this->renderWindow_;
    104         graphicsEngine->root_          = this->ogreRoot_;
    105         graphicsEngine->viewport_      = this->viewport_;
     117        graphicsEngine_->renderWindow_  = this->renderWindow_;
     118        graphicsEngine_->root_          = this->ogreRoot_;
     119        graphicsEngine_->viewport_      = this->viewport_;
    106120
    107121
     
    141155        using namespace Ogre;
    142156
    143         // remove our WindowEventListener first to avoid bad calls in the procedures
     157        // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
    144158        Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
    145159
     
    156170        renderer->destroyRenderWindow("Orxonox");
    157171
     172        /*** CODE SNIPPET, UNUSED ***/
    158173        // Does the opposite of initialise()
    159         ogreRoot_->shutdown();
    160 
     174        //ogreRoot_->shutdown();
    161175        // Remove all resources and resource groups
    162176        //StringVector groups = ResourceGroupManager::getSingleton().getResourceGroups();
     
    170184        // Shutdown the render system
    171185        //this->ogreRoot_->setRenderSystem(0);
     186
     187        delete this->ogreRoot_;
     188
     189#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     190        // delete the ogre log and the logManager (since we have created it).
     191        this->ogreLogger_->getDefaultLog()->removeListener(this);
     192        this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
     193        delete this->ogreLogger_;
     194#endif
     195
     196        delete graphicsEngine_;
    172197
    173198        Settings::_getInstance().bShowsGraphics_ = false;
     
    234259
    235260        ++frameCount_;
     261    }
     262
     263    /**
     264    @brief
     265        Creates the Ogre Root object and sets up the ogre log.
     266    */
     267    void GSGraphics::setupOgre()
     268    {
     269        COUT(3) << "Setting up Ogre..." << std::endl;
     270
     271        // TODO: LogManager doesn't work on oli platform. The why is yet unknown.
     272#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     273        // create a new logManager
     274        ogreLogger_ = new Ogre::LogManager();
     275        COUT(4) << "Ogre LogManager created" << std::endl;
     276
     277        // create our own log that we can listen to
     278        Ogre::Log *myLog;
     279        if (this->ogreLogFile_ == "")
     280            myLog = ogreLogger_->createLog("ogre.log", true, false, true);
     281        else
     282            myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false);
     283        COUT(4) << "Ogre Log created" << std::endl;
     284
     285        myLog->setLogDetail(Ogre::LL_BOREME);
     286        myLog->addListener(this);
     287#endif
     288
     289        // Root will detect that we've already created a Log
     290        COUT(4) << "Creating Ogre Root..." << std::endl;
     291
     292        if (ogrePluginsFile_ == "")
     293        {
     294            COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;
     295            ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");
     296        }
     297        if (ogreConfigFile_ == "")
     298        {
     299            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
     300            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
     301        }
     302        if (ogreLogFile_ == "")
     303        {
     304            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
     305            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
     306        }
     307
     308        // check for config file existence because Ogre displays (caught) exceptions if not
     309        std::ifstream probe;
     310        probe.open(ogreConfigFile_.c_str());
     311        if (!probe)
     312        {
     313            // create a zero sized file
     314            std::ofstream creator;
     315            creator.open(ogreConfigFile_.c_str());
     316            creator.close();
     317        }
     318        else
     319            probe.close();
     320
     321        ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);
     322
     323#if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)
     324#if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
     325        // tame the ogre ouput so we don't get all the mess in the console
     326        Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
     327        defaultLog->setDebugOutputEnabled(false);
     328        defaultLog->setLogDetail(Ogre::LL_BOREME);
     329        defaultLog->addListener(this);
     330#endif
     331#endif
     332
     333        COUT(3) << "Ogre set up done." << std::endl;
    236334    }
    237335
     
    328426    }
    329427
     428    /**
     429    @brief
     430        Method called by the LogListener interface from Ogre.
     431        We use it to capture Ogre log messages and handle it ourselves.
     432    @param message
     433        The message to be logged
     434    @param lml
     435        The message level the log is using
     436    @param maskDebug
     437        If we are printing to the console or not
     438    @param logName
     439        The name of this log (so you can have several listeners
     440        for different logs, and identify them)
     441    */
     442    void GSGraphics::messageLogged(const std::string& message,
     443        Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
     444    {
     445        int orxonoxLevel;
     446        switch (lml)
     447        {
     448        case Ogre::LML_TRIVIAL:
     449            orxonoxLevel = this->ogreLogLevelTrivial_;
     450            break;
     451        case Ogre::LML_NORMAL:
     452            orxonoxLevel = this->ogreLogLevelNormal_;
     453            break;
     454        case Ogre::LML_CRITICAL:
     455            orxonoxLevel = this->ogreLogLevelCritical_;
     456            break;
     457        default:
     458            orxonoxLevel = 0;
     459        }
     460        OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
     461            << "Ogre: " << message << std::endl;
     462    }
    330463
    331464    /**
Note: See TracChangeset for help on using the changeset viewer.