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.

Location:
code/trunk/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/Main.cc

    r1755 r1891  
    3939
    4040#include "util/OrxonoxPlatform.h"
     41#include "util/Debug.h"
     42#include "core/ConfigFileManager.h"
    4143#include "SignalHandler.h"
    42 #include "util/Debug.h"
    4344
    4445#include "gamestates/GSRoot.h"
     
    9091    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
    9192
     93    // Specifiy config file before creating the GameStates in order to have
     94    // setConfigValues() in the constructor (required).
     95#if ORXONOX_DEBUG_MODE == 1
     96        ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox_d.ini");
     97#else
     98        ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox.ini");
     99#endif
     100
     101    // create the gamestates
    92102    GSRoot root;
    93103    GSGraphics graphics;
     
    99109    GSIOConsole ioConsole;
    100110
     111    // make the hierarchy
    101112    root.addChild(&graphics);
    102113    graphics.addChild(&standalone);
     
    104115    graphics.addChild(&client);
    105116    graphics.addChild(&gui);
    106 
    107117    root.addChild(&ioConsole);
    108118    root.addChild(&dedicated);
    109119
     120    // Here happens the game
    110121    root.start(argc, argv);
    111122
  • 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    /**
  • code/trunk/src/orxonox/gamestates/GSGraphics.h

    r1878 r1891  
    3939namespace orxonox
    4040{
    41     class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass, public Ogre::WindowEventListener
     41    class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass,
     42                                      public Ogre::WindowEventListener, public Ogre::LogListener
    4243    {
    4344        friend class ClassIdentifier<GSGraphics>;
     45
    4446    public:
    4547        GSGraphics();
    4648        ~GSGraphics();
    4749
    48         Ogre::Viewport* getViewport() { return this->viewport_; }
    49         GUIManager* getGUIManager() { return this->guiManager_; }
     50        Ogre::Root*     getOgreRoot()   { return this->ogreRoot_  ; }
     51        Ogre::Viewport* getViewport()   { return this->viewport_  ; }
     52        GUIManager*     getGUIManager() { return this->guiManager_; }
    5053
    51     private:
     54    private: // functions
    5255        void enter();
    5356        void leave();
     
    5659        void setConfigValues();
    5760
     61        void setupOgre();
    5862        void declareResources();
    5963        void loadRenderer();
    6064        void initialiseResources();
    6165
     66        // console commands
    6267        void printScreen();
     68
     69        // event from Ogre::LogListener
     70        void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
     71            bool maskDebug, const std::string& logName);
    6372
    6473        // window events from Ogre::WindowEventListener
     
    6877        void windowClosed      (Ogre::RenderWindow* rw);
    6978
    70         Ogre::Root*           ogreRoot_;
     79    private: // variables
    7180        Ogre::RenderWindow*   renderWindow_;          //!< the current render window
    7281        Ogre::Viewport*       viewport_;              //!< default full size viewport
     
    7685        InGameConsole*        console_;
    7786        GUIManager*           guiManager_;
     87        Ogre::Root*           ogreRoot_;                  //!< Ogre's root
     88        Ogre::LogManager*     ogreLogger_;
     89        GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
    7890
    7991        KeyBinder*            masterKeyBinder_;
     
    88100        // config values
    89101        std::string           resourceFile_;          //!< resources file name
     102        std::string           ogreConfigFile_;        //!< ogre config file name
     103        std::string           ogrePluginsFile_;       //!< ogre plugins file name
     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
    90108        unsigned int          detailLevelParticle_;   //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
    91109    };
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r1826 r1891  
    3030#include "GSRoot.h"
    3131
    32 #include <OgreLogManager.h>
    33 #include <OgreRoot.h>
    34 
    3532#include "util/Exception.h"
    3633#include "util/Debug.h"
    3734#include "core/Factory.h"
    38 #include "core/ConfigFileManager.h"
    3935#include "core/ConfigValueIncludes.h"
    4036#include "core/CoreIncludes.h"
     
    7167        : RootGameState("root")
    7268        , settings_(0)
    73         , ogreRoot_(0)
    74         , ogreLogger_(0)
    75         , graphicsEngine_(0)
    7669        , tclBind_(0)
    7770        , tclThreadManager_(0)
     
    7972    {
    8073        RegisterRootObject(GSRoot);
     74        setConfigValues();
    8175    }
    8276
     
    8781    void GSRoot::setConfigValues()
    8882    {
    89         SetConfigValue(ogreConfigFile_,  "ogre.cfg").description("Location of the Ogre config file");
    90         SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");
    91         SetConfigValue(ogreLogFile_,     "ogre.log").description("Logfile for messages from Ogre. \
    92                                                                  Use \"\" to suppress log file creation.");
    93         SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
    94         SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    95         SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
    9683    }
    9784
    9885    void GSRoot::enter()
    9986    {
    100 #if ORXONOX_DEBUG_MODE == 1
    101         ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox_d.ini");
    102 #else
    103         ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox.ini");
    104 #endif
    105 
    106         // do this after the previous call..
    107         setConfigValues();
    108 
    10987        // creates the class hierarchy for all classes with factories
    11088        Factory::createClassHierarchy();
     
    130108        this->shell_ = new Shell();
    131109
    132         setupOgre();
    133 
    134         // initialise graphics engine. Doesn't load the render window yet!
    135         graphicsEngine_ = new GraphicsEngine();
    136 
    137110        // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
    138111        // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
     
    157130    {
    158131        // TODO: remove and destroy console commands
    159 
    160         delete graphicsEngine_;
    161 
    162         delete this->ogreRoot_;
    163 
    164 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    165         // delete the ogre log and the logManager (since we have created it).
    166         this->ogreLogger_->getDefaultLog()->removeListener(this);
    167         this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
    168         delete this->ogreLogger_;
    169 #endif
    170132
    171133        delete this->shell_;
     
    203165            DWORD procMask;
    204166            DWORD sysMask;
    205 #if _MSC_VER >= 1400 && defined (_M_X64)
     167#  if _MSC_VER >= 1400 && defined (_M_X64)
    206168            GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
    207 #else
     169#  else
    208170            GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
    209 #endif
     171#  endif
    210172
    211173            // If procMask is 0, consider there is only one core available
     
    227189#endif
    228190    }
    229 
    230     /**
    231     @brief
    232         Creates the Ogre Root object and sets up the ogre log.
    233     */
    234     void GSRoot::setupOgre()
    235     {
    236         COUT(3) << "Setting up Ogre..." << std::endl;
    237 
    238         // TODO: LogManager doesn't work on oli platform. The why is yet unknown.
    239 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    240         // create a new logManager
    241         ogreLogger_ = new Ogre::LogManager();
    242         COUT(4) << "Ogre LogManager created" << std::endl;
    243 
    244         // create our own log that we can listen to
    245         Ogre::Log *myLog;
    246         if (this->ogreLogFile_ == "")
    247             myLog = ogreLogger_->createLog("ogre.log", true, false, true);
    248         else
    249             myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false);
    250         COUT(4) << "Ogre Log created" << std::endl;
    251 
    252         myLog->setLogDetail(Ogre::LL_BOREME);
    253         myLog->addListener(this);
    254 #endif
    255 
    256         // Root will detect that we've already created a Log
    257         COUT(4) << "Creating Ogre Root..." << std::endl;
    258 
    259         if (ogrePluginsFile_ == "")
    260         {
    261             COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;
    262             ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");
    263         }
    264         if (ogreConfigFile_ == "")
    265         {
    266             COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
    267             ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
    268         }
    269         if (ogreLogFile_ == "")
    270         {
    271             COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
    272             ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
    273         }
    274 
    275         // check for config file existence because Ogre displays (caught) exceptions if not
    276         std::ifstream probe;
    277         probe.open(ogreConfigFile_.c_str());
    278         if (!probe)
    279         {
    280             // create a zero sized file
    281             std::ofstream creator;
    282             creator.open(ogreConfigFile_.c_str());
    283             creator.close();
    284         }
    285         else
    286             probe.close();
    287 
    288         ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);
    289 
    290 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)
    291 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
    292         // tame the ogre ouput so we don't get all the mess in the console
    293         Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
    294         defaultLog->setDebugOutputEnabled(false);
    295         defaultLog->setLogDetail(Ogre::LL_BOREME);
    296         defaultLog->addListener(this);
    297 #endif
    298 #endif
    299 
    300         COUT(3) << "Ogre set up done." << std::endl;
    301     }
    302 
    303     /**
    304     @brief
    305         Method called by the LogListener interface from Ogre.
    306         We use it to capture Ogre log messages and handle it ourselves.
    307     @param message
    308         The message to be logged
    309     @param lml
    310         The message level the log is using
    311     @param maskDebug
    312         If we are printing to the console or not
    313     @param logName
    314         The name of this log (so you can have several listeners
    315         for different logs, and identify them)
    316     */
    317     void GSRoot::messageLogged(const std::string& message,
    318         Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
    319     {
    320         int orxonoxLevel;
    321         switch (lml)
    322         {
    323         case Ogre::LML_TRIVIAL:
    324             orxonoxLevel = this->ogreLogLevelTrivial_;
    325             break;
    326         case Ogre::LML_NORMAL:
    327             orxonoxLevel = this->ogreLogLevelNormal_;
    328             break;
    329         case Ogre::LML_CRITICAL:
    330             orxonoxLevel = this->ogreLogLevelCritical_;
    331             break;
    332         default:
    333             orxonoxLevel = 0;
    334         }
    335         OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
    336             << "Ogre: " << message << std::endl;
    337     }
    338191}
  • code/trunk/src/orxonox/gamestates/GSRoot.h

    r1792 r1891  
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSRoot : public RootGameState, public Ogre::LogListener, public OrxonoxClass
     39    class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
    4040    {
    4141        friend class ClassIdentifier<GSRoot>;
     
    4747        { requestState("root"); }
    4848
    49         Ogre::Root* getOgreRoot() { return this->ogreRoot_; }
    50         GraphicsEngine* getGraphicsEngine() { return this->graphicsEngine_; }
    51 
    5249    private:
    5350        void enter();
     
    5653
    5754        void setConfigValues();
    58         void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
    59             bool maskDebug, const std::string& logName);
    6055        void setThreadAffinity(unsigned int limitToCPU);
    61         void setupOgre();
    6256
    6357        Settings*             settings_;
    64         Ogre::Root*           ogreRoot_;                  //!< Ogre's root
    65         Ogre::LogManager*     ogreLogger_;
    66         GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
    6758        TclBind*              tclBind_;
    6859        TclThreadManager*     tclThreadManager_;
    6960        Shell*                shell_;
    70 
    71         std::string           ogreConfigFile_;        //!< ogre config file name
    72         std::string           ogrePluginsFile_;       //!< ogre plugins file name
    73         std::string           ogreLogFile_;           //!< log file name for Ogre log messages
    74         int                   ogreLogLevelTrivial_;   //!< Corresponding Orxonx debug level for LL_TRIVIAL
    75         int                   ogreLogLevelNormal_;    //!< Corresponding Orxonx debug level for LL_NORMAL
    76         int                   ogreLogLevelCritical_;  //!< Corresponding Orxonx debug level for LL_CRITICAL
    7761    };
    7862}
Note: See TracChangeset for help on using the changeset viewer.