Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1686


Ignore:
Timestamp:
Aug 31, 2008, 2:37:00 PM (16 years ago)
Author:
rgrieder
Message:

Moved most of the GraphicsEngine code to GSRoot and GSGraphics.
GraphicsEngine is now more of a legacy object to ensure functionality until there is a new solution.

Location:
code/branches/gui/src
Files:
2 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/GameState.h

    r1674 r1686  
    118118        void deactivate();
    119119
    120         const std::string                          name_;
    121         Operations                                 operation_;
    122         GameState*                             parent_;
    123         GameState*                                 activeChild_;
    124         //bool                                       bPauseParent_;
    125         std::map<std::string, GameState*>      allChildren_;
    126         std::map<GameState*, GameState*>   grandchildrenToChildren_;
     120        const std::string                   name_;
     121        Operations                          operation_;
     122        GameState*                          parent_;
     123        GameState*                          activeChild_;
     124        //bool                                bPauseParent_;
     125        std::map<std::string, GameState*>   allChildren_;
     126        std::map<GameState*, GameState*>    grandchildrenToChildren_;
    127127    };
    128128}
  • code/branches/gui/src/orxonox/GraphicsEngine.cc

    r1653 r1686  
    3737#include "GraphicsEngine.h"
    3838
    39 #include <fstream>
    40 
    41 #include <OgreConfigFile.h>
    42 #include <OgreException.h>
    43 #include <OgreLogManager.h>
    44 #include <OgreRoot.h>
    45 #include <OgreSceneManager.h>
    46 #include <OgreTextureManager.h>
    47 #include <OgreViewport.h>
     39#include <OgreRenderWindow.h>
    4840
    4941#include "core/CoreIncludes.h"
    5042#include "core/ConfigValueIncludes.h"
    5143#include "core/Debug.h"
    52 #include "core/CommandExecutor.h"
    53 #include "core/ConsoleCommand.h"
    54 #include "core/Exception.h"
    5544
    56 #include "overlays/console/InGameConsole.h"
    57 #include "overlays/OverlayGroup.h"
    5845#include "tools/ParticleInterface.h"
    59 #include "Settings.h"
    60 #include "tools/WindowEventListener.h"
    61 
    62 #include "objects/CameraHandler.h"
    6346
    6447namespace orxonox
    6548{
    66     SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress);
     49    //SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress);
    6750
    6851    GraphicsEngine* GraphicsEngine::singletonRef_s = 0;
     
    10386    void GraphicsEngine::setConfigValues()
    10487    {
    105         SetConfigValue(resourceFile_,    "resources.cfg").description("Location of the resources file in the data path.");
    106         SetConfigValue(ogreConfigFile_,  "ogre.cfg").description("Location of the Ogre config file");
    107         SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");
    108         SetConfigValue(ogreLogFile_,     "ogre.log").description("Logfile for messages from Ogre. \
    109                                                                  Use \"\" to suppress log file creation.");
    110         SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
    111         SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    112         SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
    113 
    11488        unsigned int old = this->detailLevelParticle_;
    11589        SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high");
     
    126100    GraphicsEngine::~GraphicsEngine()
    127101    {
    128         CCOUT(4) << "Destroying objects..." << std::endl;
    129         Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
    130         if (this->root_)
    131             delete this->root_;
    132 
    133 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    134         // delete the ogre log and the logManager (since we have created it).
    135         if (Ogre::LogManager::getSingletonPtr() != 0)
    136         {
    137             Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this);
    138             Ogre::LogManager::getSingleton().destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
    139             delete Ogre::LogManager::getSingletonPtr();
    140         }
    141         CCOUT(4) << "Destroying objects done" << std::endl;
    142 #endif
    143 
    144102        singletonRef_s = 0;
    145     }
    146 
    147     /**
    148     @brief
    149         Creates the Ogre Root object and sets up the ogre log.
    150     */
    151     void GraphicsEngine::setup()
    152     {
    153         CCOUT(3) << "Setting up..." << std::endl;
    154 
    155         // TODO: LogManager doesn't work on oli platform. The why is yet unknown.
    156 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    157         // create a new logManager
    158         Ogre::LogManager* logger = new Ogre::LogManager();
    159         CCOUT(4) << "Ogre LogManager created" << std::endl;
    160 
    161         // create our own log that we can listen to
    162         Ogre::Log *myLog;
    163         if (this->ogreLogFile_ == "")
    164             myLog = logger->createLog("ogre.log", true, false, true);
    165         else
    166             myLog = logger->createLog(this->ogreLogFile_, true, false, false);
    167         CCOUT(4) << "Ogre Log created" << std::endl;
    168 
    169         myLog->setLogDetail(Ogre::LL_BOREME);
    170         myLog->addListener(this);
    171 #endif
    172 
    173         // Root will detect that we've already created a Log
    174         CCOUT(4) << "Creating Ogre Root..." << std::endl;
    175 
    176         if (ogrePluginsFile_ == "")
    177         {
    178             COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;
    179             ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");
    180         }
    181         if (ogreConfigFile_ == "")
    182         {
    183             COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
    184             ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
    185         }
    186         if (ogreLogFile_ == "")
    187         {
    188             COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
    189             ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
    190         }
    191 
    192         root_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);
    193 
    194         // We don't need plugins for the dedicated..
    195         //if (!root_->getInstalledPlugins().size() > 0)
    196         //{
    197         //    ThrowException(PluginsNotFound, "No Ogre plugins declared. Cannot load Ogre.");
    198         //}
    199 
    200 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)
    201 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
    202         // tame the ogre ouput so we don't get all the mess in the console
    203         Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
    204         defaultLog->setDebugOutputEnabled(false);
    205         defaultLog->setLogDetail(Ogre::LL_BOREME);
    206         defaultLog->addListener(this);
    207 #endif
    208 #endif
    209 
    210         CCOUT(4) << "Creating Ogre Root done" << std::endl;
    211 
    212         // specify where Ogre has to look for resources. This call doesn't parse anything yet!
    213         declareRessourceLocations();
    214 
    215         CCOUT(3) << "Set up done." << std::endl;
    216     }
    217 
    218     void GraphicsEngine::declareRessourceLocations()
    219     {
    220         CCOUT(4) << "Declaring Resources" << std::endl;
    221         //TODO: Specify layout of data file and maybe use xml-loader
    222         //TODO: Work with ressource groups (should be generated by a special loader)
    223 
    224         if (resourceFile_ == "")
    225         {
    226             COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
    227             ModifyConfigValue(resourceFile_, tset, "resources.cfg");
    228         }
    229 
    230         // Load resource paths from data file using configfile ressource type
    231         Ogre::ConfigFile cf;
    232         try
    233         {
    234             cf.load(Settings::getDataPath() + resourceFile_);
    235         }
    236         catch (...)
    237         {
    238             //COUT(1) << ex.getFullDescription() << std::endl;
    239             COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
    240             throw;
    241         }
    242 
    243         // Go through all sections & settings in the file
    244         Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    245 
    246         std::string secName, typeName, archName;
    247         while (seci.hasMoreElements())
    248         {
    249             try
    250             {
    251                 secName = seci.peekNextKey();
    252                 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
    253                 Ogre::ConfigFile::SettingsMultiMap::iterator i;
    254                 for (i = settings->begin(); i != settings->end(); ++i)
    255                 {
    256                     typeName = i->first; // for instance "FileSystem" or "Zip"
    257                     archName = i->second; // name (and location) of archive
    258 
    259                     Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    260                         std::string(Settings::getDataPath() + archName), typeName, secName);
    261                 }
    262             }
    263             catch (Ogre::Exception& ex)
    264             {
    265                 COUT(1) << ex.getFullDescription() << std::endl;
    266             }
    267         }
    268     }
    269 
    270     void GraphicsEngine::loadRenderer()
    271     {
    272         CCOUT(4) << "Configuring Renderer" << std::endl;
    273 
    274         // check for file existence because Ogre displays exceptions if not
    275         std::ifstream probe;
    276         probe.open(ogreConfigFile_.c_str());
    277         if (!probe)
    278         {
    279             // create a zero sized file
    280             std::ofstream creator;
    281             creator.open(ogreConfigFile_.c_str());
    282             creator.close();
    283         }
    284         else
    285             probe.close();
    286 
    287         if (!root_->restoreConfig())
    288             if (!root_->showConfigDialog())
    289                 ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
    290 
    291         CCOUT(4) << "Creating render window" << std::endl;
    292 
    293         this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
    294 
    295         Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
    296 
    297         //Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    298 
    299         // create a full screen default viewport
    300         this->viewport_ = this->renderWindow_->addViewport(0, 0);
    301     }
    302 
    303     void GraphicsEngine::initialiseResources()
    304     {
    305         CCOUT(4) << "Initialising resources" << std::endl;
    306         //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
    307         try
    308         {
    309             Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    310             /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
    311             for (unsigned int i = 0; i < str.size(); i++)
    312             {
    313             Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
    314             }*/
    315         }
    316         catch (...)
    317         {
    318             CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
    319             throw;
    320         }
    321     }
    322 
    323     /**
    324     @brief
    325         Creates the SceneManager
    326     */
    327     void GraphicsEngine::createNewScene()
    328     {
    329         CCOUT(4) << "Creating new SceneManager..." << std::endl;
    330         if (levelSceneManager_)
    331         {
    332             CCOUT(2) << "SceneManager already exists! Skipping." << std::endl;
    333         }
    334         this->levelSceneManager_ = this->root_->createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
    335         CCOUT(3) << "Created SceneManager: " << levelSceneManager_->getName() << std::endl;
    336     }
    337 
    338     /**
    339     @brief
    340         Returns the window handle of the render window.
    341         At least the InputHandler uses this to create the OIS::InputManager
    342     @return
    343         The window handle of the render window
    344     */
    345     size_t GraphicsEngine::getWindowHandle()
    346     {
    347         if (this->renderWindow_)
    348         {
    349             size_t windowHnd = 0;
    350             this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
    351             return windowHnd;
    352         }
    353         else
    354             return 0;
    355103    }
    356104
     
    396144            return 1.0f;
    397145    }
    398 
    399     /**
    400     @brief
    401         Method called by the LogListener interface from Ogre.
    402         We use it to capture Ogre log messages and handle it ourselves.
    403     @param message
    404         The message to be logged
    405     @param lml
    406         The message level the log is using
    407     @param maskDebug
    408         If we are printing to the console or not
    409     @param logName
    410         The name of this log (so you can have several listeners
    411         for different logs, and identify them)
    412     */
    413     void GraphicsEngine::messageLogged(const std::string& message,
    414         Ogre::LogMessageLevel lml, bool maskDebug, const std::string &logName)
    415     {
    416         int orxonoxLevel;
    417         switch (lml)
    418         {
    419         case Ogre::LML_TRIVIAL:
    420             orxonoxLevel = this->ogreLogLevelTrivial_;
    421             break;
    422         case Ogre::LML_NORMAL:
    423             orxonoxLevel = this->ogreLogLevelNormal_;
    424             break;
    425         case Ogre::LML_CRITICAL:
    426             orxonoxLevel = this->ogreLogLevelCritical_;
    427             break;
    428         default:
    429             orxonoxLevel = 0;
    430         }
    431         OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
    432             << "Ogre: " << message << std::endl;
    433     }
    434 
    435     /**
    436     @brief
    437         Window has moved.
    438     @param rw
    439         The render window it occured in
    440     */
    441     void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw)
    442     {
    443         for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)
    444             it->windowMoved();
    445     }
    446 
    447     /**
    448     @brief
    449         Window has resized.
    450     @param rw
    451         The render window it occured in
    452     @note
    453         GraphicsEngine has a render window stored itself. This is the same
    454         as rw. But we have to be careful when using multiple render windows!
    455     */
    456     void GraphicsEngine::windowResized(Ogre::RenderWindow *rw)
    457     {
    458         for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)
    459             it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
    460     }
    461 
    462     /**
    463     @brief
    464         Window focus has changed.
    465     @param rw
    466         The render window it occured in
    467     */
    468     void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw)
    469     {
    470         for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)
    471             it->windowFocusChanged();
    472     }
    473 
    474     /**
    475     @brief
    476         Window was closed.
    477     @param rw
    478         The render window it occured in
    479     */
    480     void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw)
    481     {
    482         // using CommandExecutor in order to avoid depending on Orxonox.h.
    483         CommandExecutor::execute("exit", false);
    484     }
    485 
    486 
    487     /*static*/ void GraphicsEngine::printScreen()
    488     {
    489         if (getInstance().renderWindow_)
    490         {
    491             getInstance().renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg");
    492         }
    493     }
    494146}
  • code/branches/gui/src/orxonox/GraphicsEngine.h

    r1653 r1686  
    4242
    4343#include <OgrePrerequisites.h>
    44 #include <OgreLog.h>
    45 #include <OgreRenderWindow.h>
    46 #include <OgreWindowEventUtilities.h>
    4744#include "core/OrxonoxClass.h"
    4845
     
    5249    @brief Graphics engine manager class
    5350    */
    54     class _OrxonoxExport GraphicsEngine : public Ogre::WindowEventListener, public Ogre::LogListener, public OrxonoxClass
     51    class _OrxonoxExport GraphicsEngine : public OrxonoxClass
    5552    {
     53        // HACK: temporary means
     54        friend class GSGraphics;
     55
    5656    public:
    5757        GraphicsEngine();
     
    5959
    6060        void setConfigValues();
    61         void setup();
    62         void declareRessourceLocations();
    63         void loadRenderer();
    64         void initialiseResources();
    65         void createNewScene();
    6661
    6762        void setLevelSceneManager(Ogre::SceneManager* sceneMgr) { this->levelSceneManager_ = sceneMgr; }
     
    6964
    7065        Ogre::Viewport* getViewport() { return this->viewport_; }
     66        Ogre::Root*     getOgreRoot() { return this->root_; }
    7167
    7268        // several window properties
    73         Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
    74         size_t getWindowHandle();
    7569        int getWindowWidth() const;
    7670        int getWindowHeight() const;
     
    8175        void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
    8276
    83         void setWindowActivity(bool activity)
    84         { if (this->renderWindow_) this->renderWindow_->setActive(activity); }
    85 
    8677        inline unsigned int getDetailLevelParticle() const
    8778        { return this->detailLevelParticle_; }
    88 
    89         // console commands
    90         static void printScreen();
    9179
    9280        static GraphicsEngine& getInstance();
     
    9583    private:
    9684        // don't mess with singletons
    97         GraphicsEngine(GraphicsEngine&) { }
    98 
    99         //! Method called by the LogListener from Ogre
    100         void messageLogged(const std::string&, Ogre::LogMessageLevel,
    101             bool, const std::string&);
    102 
    103         // window events from Ogre::WindowEventListener
    104         void windowMoved       (Ogre::RenderWindow* rw);
    105         void windowResized     (Ogre::RenderWindow* rw);
    106         void windowFocusChanged(Ogre::RenderWindow* rw);
    107         void windowClosed      (Ogre::RenderWindow* rw);
     85        GraphicsEngine(GraphicsEngine&);
    10886
    10987        Ogre::Root*         root_;                  //!< Ogre's root
     
    11795
    11896        // config values
    119         std::string         resourceFile_;          //!< resources file name
    120         std::string         ogreConfigFile_;        //!< ogre config file name
    121         std::string         ogrePluginsFile_;       //!< ogre plugins file name
    122         std::string         ogreLogFile_;           //!< log file name for Ogre log messages
    123         int                 ogreLogLevelTrivial_;   //!< Corresponding Orxonx debug level for LL_TRIVIAL
    124         int                 ogreLogLevelNormal_;    //!< Corresponding Orxonx debug level for LL_NORMAL
    125         int                 ogreLogLevelCritical_;  //!< Corresponding Orxonx debug level for LL_CRITICAL
    12697        unsigned int        detailLevelParticle_;   //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
    12798
  • code/branches/gui/src/orxonox/gamestates/GSGUI.cc

    r1674 r1686  
    3030#include "GSGUI.h"
    3131
     32#include <OgreViewport.h>
    3233#include "GraphicsEngine.h"
    3334#include "core/input/InputManager.h"
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r1674 r1686  
    3030#include "GSGraphics.h"
    3131
     32#include <fstream>
     33#include <OgreConfigFile.h>
    3234#include <OgreFrameListener.h>
    3335#include <OgreRoot.h>
     36#include <OgreException.h>
     37#include <OgreRenderWindow.h>
     38#include <OgreTextureManager.h>
     39#include <OgreViewport.h>
    3440#include <OgreWindowEventUtilities.h>
    35 #include <OgreRenderWindow.h>
    36 
     41
     42#include "core/Debug.h"
    3743#include "core/ConsoleCommand.h"
    3844#include "core/ConfigValueIncludes.h"
     45#include "core/CoreIncludes.h"
    3946#include "core/input/InputManager.h"
     47#include "core/Exception.h"
    4048#include "overlays/console/InGameConsole.h"
    4149#include "gui/GUIManager.h"
     50#include "tools/WindowEventListener.h"
     51#include "Settings.h"
     52
     53// for compatibility
    4254#include "GraphicsEngine.h"
    4355
     
    4759        : GameState("graphics")
    4860        , ogreRoot_(0)
    49         , graphicsEngine_(0)
    5061        , inputManager_(0)
    5162        , console_(0)
     
    5768        , tickTime_(0)
    5869    {
     70        RegisterRootObject(GSGraphics);
    5971    }
    6072
     
    6577    void GSGraphics::setConfigValues()
    6678    {
     79        SetConfigValue(resourceFile_,    "resources.cfg").description("Location of the resources file in the data path.");
    6780        SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    6881    }
     
    7386
    7487        this->ogreRoot_ = Ogre::Root::getSingletonPtr();
    75         this->graphicsEngine_ = GraphicsEngine::getInstancePtr();
    76 
    77         graphicsEngine_->loadRenderer();    // creates the render window
    78 
     88
     89        this->declareResources();
     90        this->loadRenderer();    // creates the render window
    7991        // TODO: Spread this so that this call only initialises things needed for the Console and GUI
    80         graphicsEngine_->initialiseResources();
     92        this->initialiseResources();
     93
     94
     95        // HACK: temporary:
     96        GraphicsEngine& graphicsEngine = GraphicsEngine::getInstance();
     97        graphicsEngine.renderWindow_ = this->renderWindow_;
     98        graphicsEngine.root_ = this->ogreRoot_;
     99        graphicsEngine.viewport_ = this->viewport_;
     100
    81101
    82102        // Calls the InputManager which sets up the input devices.
    83103        // The render window width and height are used to set up the mouse movement.
    84104        inputManager_ = new InputManager();
    85         inputManager_->initialise(graphicsEngine_->getWindowHandle(),
    86             graphicsEngine_->getWindowWidth(), graphicsEngine_->getWindowHeight(), true);
     105        size_t windowHnd = 0;
     106        this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
     107        inputManager_->initialise(windowHnd, renderWindow_->getWidth(), renderWindow_->getHeight(), true);
    87108
    88109        // Load the InGameConsole
     
    92113        // load the CEGUI interface
    93114        guiManager_ = new GUIManager();
    94         guiManager_->initialise();
     115        guiManager_->initialise(this->renderWindow_);
    95116
    96117        // reset frame counter
     
    99120        statisticsStartTime_ = 0;
    100121        statisticsStartCount_ = 0;
     122
     123        // add console commands
     124        FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
     125        functor1->setObject(this);
     126        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen"));
    101127    }
    102128
     
    109135        delete this->inputManager_;
    110136
    111         this->ogreRoot_->detachRenderTarget(GraphicsEngine::getInstance().getRenderWindow());
    112         delete GraphicsEngine::getInstance().getRenderWindow();
     137        this->ogreRoot_->detachRenderTarget(this->renderWindow_);
     138        delete this->renderWindow_;
    113139        //this->ogreRoot_->shutdown
    114140        // TODO: destroy render window
     
    166192        // make sure the window stays active even when not focused
    167193        // (probably only necessary on windows)
    168         GraphicsEngine::getInstance().setWindowActivity(true);
     194        this->renderWindow_->setActive(true);
    169195
    170196        // render
     
    176202        ++frameCount_;
    177203    }
     204
     205    void GSGraphics::declareResources()
     206    {
     207        CCOUT(4) << "Declaring Resources" << std::endl;
     208        //TODO: Specify layout of data file and maybe use xml-loader
     209        //TODO: Work with ressource groups (should be generated by a special loader)
     210
     211        if (resourceFile_ == "")
     212        {
     213            COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
     214            ModifyConfigValue(resourceFile_, tset, "resources.cfg");
     215        }
     216
     217        // Load resource paths from data file using configfile ressource type
     218        Ogre::ConfigFile cf;
     219        try
     220        {
     221            cf.load(Settings::getDataPath() + resourceFile_);
     222        }
     223        catch (...)
     224        {
     225            //COUT(1) << ex.getFullDescription() << std::endl;
     226            COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
     227            throw;
     228        }
     229
     230        // Go through all sections & settings in the file
     231        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
     232
     233        std::string secName, typeName, archName;
     234        while (seci.hasMoreElements())
     235        {
     236            try
     237            {
     238                secName = seci.peekNextKey();
     239                Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
     240                Ogre::ConfigFile::SettingsMultiMap::iterator i;
     241                for (i = settings->begin(); i != settings->end(); ++i)
     242                {
     243                    typeName = i->first; // for instance "FileSystem" or "Zip"
     244                    archName = i->second; // name (and location) of archive
     245
     246                    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
     247                        std::string(Settings::getDataPath() + archName), typeName, secName);
     248                }
     249            }
     250            catch (Ogre::Exception& ex)
     251            {
     252                COUT(1) << ex.getFullDescription() << std::endl;
     253            }
     254        }
     255    }
     256
     257    void GSGraphics::loadRenderer()
     258    {
     259        CCOUT(4) << "Configuring Renderer" << std::endl;
     260
     261        if (!ogreRoot_->restoreConfig())
     262            if (!ogreRoot_->showConfigDialog())
     263                ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
     264
     265        CCOUT(4) << "Creating render window" << std::endl;
     266
     267        this->renderWindow_ = ogreRoot_->initialise(true, "OrxonoxV2");
     268
     269        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
     270
     271        //Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
     272
     273        // create a full screen default viewport
     274        this->viewport_ = this->renderWindow_->addViewport(0, 0);
     275    }
     276
     277    void GSGraphics::initialiseResources()
     278    {
     279        CCOUT(4) << "Initialising resources" << std::endl;
     280        //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
     281        try
     282        {
     283            Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     284            /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
     285            for (unsigned int i = 0; i < str.size(); i++)
     286            {
     287            Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
     288            }*/
     289        }
     290        catch (...)
     291        {
     292            CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
     293            throw;
     294        }
     295    }
     296
     297
     298    /**
     299    @brief
     300        Window has moved.
     301    @param rw
     302        The render window it occured in
     303    */
     304    void GSGraphics::windowMoved(Ogre::RenderWindow *rw)
     305    {
     306        for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)
     307            it->windowMoved();
     308    }
     309
     310    /**
     311    @brief
     312        Window has resized.
     313    @param rw
     314        The render window it occured in
     315    @note
     316        GraphicsEngine has a render window stored itself. This is the same
     317        as rw. But we have to be careful when using multiple render windows!
     318    */
     319    void GSGraphics::windowResized(Ogre::RenderWindow *rw)
     320    {
     321        for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)
     322            it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
     323    }
     324
     325    /**
     326    @brief
     327        Window focus has changed.
     328    @param rw
     329        The render window it occured in
     330    */
     331    void GSGraphics::windowFocusChanged(Ogre::RenderWindow *rw)
     332    {
     333        for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it)
     334            it->windowFocusChanged();
     335    }
     336
     337    /**
     338    @brief
     339        Window was closed.
     340    @param rw
     341        The render window it occured in
     342    */
     343    void GSGraphics::windowClosed(Ogre::RenderWindow *rw)
     344    {
     345        // using CommandExecutor in order to avoid depending on Orxonox.h.
     346        //CommandExecutor::execute("exit", false);
     347        this->requestState("root");
     348    }
     349
     350    void GSGraphics::printScreen()
     351    {
     352        if (this->renderWindow_)
     353        {
     354            this->renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg");
     355        }
     356    }
    178357}
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r1674 r1686  
    3232#include "OrxonoxPrereqs.h"
    3333#include <OgrePrerequisites.h>
     34#include <OgreWindowEventUtilities.h>
    3435#include "core/GameState.h"
    3536#include "core/OrxonoxClass.h"
     
    3738namespace orxonox
    3839{
    39     class _OrxonoxExport GSGraphics : public GameState, public OrxonoxClass
     40    class _OrxonoxExport GSGraphics : public GameState, public OrxonoxClass, public Ogre::WindowEventListener
    4041    {
     42        friend class ClassIdentifier<GSGraphics>;
    4143    public:
    4244        GSGraphics();
    4345        ~GSGraphics();
    44 
    45         void setConfigValues();
    4646
    4747    private:
     
    5050        void ticked(const Clock& time);
    5151
     52        void setConfigValues();
     53
     54        void declareResources();
     55        void loadRenderer();
     56        void initialiseResources();
     57
     58        void printScreen();
     59
     60        // window events from Ogre::WindowEventListener
     61        void windowMoved       (Ogre::RenderWindow* rw);
     62        void windowResized     (Ogre::RenderWindow* rw);
     63        void windowFocusChanged(Ogre::RenderWindow* rw);
     64        void windowClosed      (Ogre::RenderWindow* rw);
     65
    5266        Ogre::Root*           ogreRoot_;
    53         GraphicsEngine*       graphicsEngine_;   //!< pointer to GraphicsEngine instance
     67        Ogre::RenderWindow*   renderWindow_;          //!< the current render window
     68        Ogre::Viewport*       viewport_;              //!< default full size viewport
     69
     70        // managed singletons
    5471        InputManager*         inputManager_;
    5572        InGameConsole*        console_;
     
    6279        unsigned long         statisticsStartCount_;
    6380        unsigned int          tickTime_;
     81
     82        // config values
     83        std::string           resourceFile_;          //!< resources file name
     84        unsigned int          detailLevelParticle_;   //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
    6485    };
    6586}
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r1674 r1686  
    3030#include "GSLevel.h"
    3131
     32#include <OgreSceneManager.h>
     33#include <OgreRoot.h>
    3234#include "core/input/InputManager.h"
    3335#include "core/input/SimpleInputState.h"
     
    4547        : GameState(name)
    4648        , timeFactor_(1.0f)
     49        , sceneManager_(0)
    4750        , keyBinder_(0)
    4851        , inputState_(0)
     
    6568
    6669        // create Ogre SceneManager for the level
    67         GraphicsEngine::getInstance().createNewScene();
     70        this->sceneManager_ = GraphicsEngine::getInstance().getOgreRoot()->
     71            createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
     72        COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl;
     73        GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_);
    6874
    6975        // Start the Radar
     
    9298        delete this->radar_;
    9399
    94         // TODO: delete SceneManager
     100        GraphicsEngine::getInstance().getOgreRoot()->destroySceneManager(this->sceneManager_);
    95101
    96102        inputState_->setHandler(0);
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r1674 r1686  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include <OgrePrerequisites.h>
    3334#include "core/GameState.h"
    3435
     
    5859        float timeFactor_;       //!< A factor to change the gamespeed
    5960
     61        Ogre::SceneManager*   sceneManager_;
    6062        KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
    6163        SimpleInputState*     inputState_;
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r1674 r1686  
    3030#include "GSRoot.h"
    3131
     32#include <OgreLogManager.h>
     33#include <OgreRoot.h>
     34
    3235//#include "util/SubString.h"
    3336#include "core/Factory.h"
    3437#include "core/ConfigFileManager.h"
    3538#include "core/ConfigValueIncludes.h"
     39#include "core/CoreIncludes.h"
    3640#include "core/ConsoleCommand.h"
    3741#include "core/CommandLine.h"
     
    6569        : RootGameState("root")
    6670        , settings_(0)
     71        , ogreRoot_(0)
     72        , ogreLogger_(0)
    6773        , graphicsEngine_(0)
    6874    {
     75        RegisterRootObject(GSRoot);
    6976    }
    7077
    7178    GSRoot::~GSRoot()
    7279    {
     80    }
     81
     82    void GSRoot::setConfigValues()
     83    {
     84        SetConfigValue(ogreConfigFile_,  "ogre.cfg").description("Location of the Ogre config file");
     85        SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");
     86        SetConfigValue(ogreLogFile_,     "ogre.log").description("Logfile for messages from Ogre. \
     87                                                                 Use \"\" to suppress log file creation.");
     88        SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
     89        SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
     90        SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
    7391    }
    7492
     
    108126#endif
    109127
     128        // do this after the previous call..
     129        setConfigValues();
     130
    110131        // creates the class hierarchy for all classes with factories
    111132        Factory::createClassHierarchy();
     
    128149        TclThreadManager::getInstance();
    129150
     151        setupOgre();
     152
    130153        // initialise graphics engine. Doesn't load the render window yet!
    131154        graphicsEngine_ = new GraphicsEngine();
    132         graphicsEngine_->setup();       // creates ogre root and other essentials
    133155
    134156        // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
     
    151173    {
    152174        delete graphicsEngine_;
     175
     176        delete this->ogreRoot_;
     177
     178#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     179        // delete the ogre log and the logManager (since we have created it).
     180        this->ogreLogger_->getDefaultLog()->removeListener(this);
     181        this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
     182        delete this->ogreLogger_;
     183#endif
     184
    153185        delete settings_;
    154186
     
    199231#endif
    200232    }
     233
     234    /**
     235    @brief
     236        Creates the Ogre Root object and sets up the ogre log.
     237    */
     238    void GSRoot::setupOgre()
     239    {
     240        COUT(3) << "Setting up Ogre..." << std::endl;
     241
     242        // TODO: LogManager doesn't work on oli platform. The why is yet unknown.
     243#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     244        // create a new logManager
     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        if (this->ogreLogFile_ == "")
     251            myLog = ogreLogger_->createLog("ogre.log", true, false, true);
     252        else
     253            myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false);
     254        COUT(4) << "Ogre Log created" << std::endl;
     255
     256        myLog->setLogDetail(Ogre::LL_BOREME);
     257        myLog->addListener(this);
     258#endif
     259
     260        // Root will detect that we've already created a Log
     261        COUT(4) << "Creating Ogre Root..." << std::endl;
     262
     263        if (ogrePluginsFile_ == "")
     264        {
     265            COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;
     266            ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");
     267        }
     268        if (ogreConfigFile_ == "")
     269        {
     270            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
     271            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
     272        }
     273        if (ogreLogFile_ == "")
     274        {
     275            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
     276            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
     277        }
     278
     279        // check for config file existence because Ogre displays (caught) exceptions if not
     280        std::ifstream probe;
     281        probe.open(ogreConfigFile_.c_str());
     282        if (!probe)
     283        {
     284            // create a zero sized file
     285            std::ofstream creator;
     286            creator.open(ogreConfigFile_.c_str());
     287            creator.close();
     288        }
     289        else
     290            probe.close();
     291
     292        ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);
     293
     294#if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)
     295#if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
     296        // tame the ogre ouput so we don't get all the mess in the console
     297        Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
     298        defaultLog->setDebugOutputEnabled(false);
     299        defaultLog->setLogDetail(Ogre::LL_BOREME);
     300        defaultLog->addListener(this);
     301#endif
     302#endif
     303
     304        COUT(3) << "Ogre set up done." << std::endl;
     305    }
     306
     307    /**
     308    @brief
     309        Method called by the LogListener interface from Ogre.
     310        We use it to capture Ogre log messages and handle it ourselves.
     311    @param message
     312        The message to be logged
     313    @param lml
     314        The message level the log is using
     315    @param maskDebug
     316        If we are printing to the console or not
     317    @param logName
     318        The name of this log (so you can have several listeners
     319        for different logs, and identify them)
     320    */
     321    void GSRoot::messageLogged(const std::string& message,
     322        Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
     323    {
     324        int orxonoxLevel;
     325        switch (lml)
     326        {
     327        case Ogre::LML_TRIVIAL:
     328            orxonoxLevel = this->ogreLogLevelTrivial_;
     329            break;
     330        case Ogre::LML_NORMAL:
     331            orxonoxLevel = this->ogreLogLevelNormal_;
     332            break;
     333        case Ogre::LML_CRITICAL:
     334            orxonoxLevel = this->ogreLogLevelCritical_;
     335            break;
     336        default:
     337            orxonoxLevel = 0;
     338        }
     339        OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
     340            << "Ogre: " << message << std::endl;
     341    }
    201342}
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r1674 r1686  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include <OgreLog.h>
    3334#include "core/RootGameState.h"
     35#include "core/OrxonoxClass.h"
    3436
    3537namespace orxonox
    3638{
    37     class _OrxonoxExport GSRoot : public RootGameState
     39    class _OrxonoxExport GSRoot : public RootGameState, public Ogre::LogListener, public OrxonoxClass
    3840    {
     41        friend class ClassIdentifier<GSRoot>;
    3942    public:
    4043        GSRoot();
     
    5154        void ticked(const Clock& time);
    5255
     56        void setConfigValues();
     57        void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
     58            bool maskDebug, const std::string& logName);
    5359        void setThreadAffinity();
     60        void setupOgre();
    5461
    5562        Settings*             settings_;
     63        Ogre::Root*           ogreRoot_;                  //!< Ogre's root
     64        Ogre::LogManager*     ogreLogger_;
    5665        GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
     66
     67        std::string           ogreConfigFile_;        //!< ogre config file name
     68        std::string           ogrePluginsFile_;       //!< ogre plugins file name
     69        std::string           ogreLogFile_;           //!< log file name for Ogre log messages
     70        int                   ogreLogLevelTrivial_;   //!< Corresponding Orxonx debug level for LL_TRIVIAL
     71        int                   ogreLogLevelNormal_;    //!< Corresponding Orxonx debug level for LL_NORMAL
     72        int                   ogreLogLevelCritical_;  //!< Corresponding Orxonx debug level for LL_CRITICAL
    5773    };
    5874}
  • code/branches/gui/src/orxonox/gui/GUIManager.cc

    r1670 r1686  
    117117    }
    118118
    119     bool GUIManager::initialise()
     119    bool GUIManager::initialise(Ogre::RenderWindow* renderWindow)
    120120    {
    121121        using namespace CEGUI;
     
    126126            try
    127127            {
    128                 // get the render window
    129                 renderWindow_ = GraphicsEngine::getInstance().getRenderWindow();
     128                // save the render window
     129                renderWindow_ = renderWindow;
    130130
    131131                // Full screen viewport with Z order = 0 (top most). Don't yet feed a camera (so nothing gets rendered)
  • code/branches/gui/src/orxonox/gui/GUIManager.h

    r1661 r1686  
    6464        ~GUIManager();
    6565
    66         bool initialise();
     66        bool initialise(Ogre::RenderWindow* renderWindow);
    6767        void tick(float dt)
    6868        {
  • code/branches/gui/src/orxonox/objects/Backlight.cc

    r1662 r1686  
    3232#include <OgreBillboard.h>
    3333#include <OgreRibbonTrail.h>
     34#include <OgreSceneManager.h>
    3435
    3536#include "core/CoreIncludes.h"
  • code/branches/gui/src/orxonox/objects/ParticleSpawner.cc

    r1653 r1686  
    3030#include "ParticleSpawner.h"
    3131
     32#include <OgreSceneManager.h>
    3233#include "core/CoreIncludes.h"
    3334#include "core/Executor.h"
  • code/branches/gui/src/orxonox/objects/WorldEntity.cc

    r1653 r1686  
    3232#include <string>
    3333#include <sstream>
     34#include <OgreSceneManager.h>
    3435
    3536#include "tinyxml/tinyxml.h"
  • code/branches/gui/src/orxonox/objects/WorldEntity.h

    r1625 r1686  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include <OgreSceneManager.h>
     33#include <OgrePrerequisites.h>
     34
    3535#include <OgreSceneNode.h>
    36 
    3736#include "util/Math.h"
    3837#include "util/XMLIncludes.h"
Note: See TracChangeset for help on using the changeset viewer.