Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 13, 2008, 3:45:19 PM (16 years ago)
Author:
rgrieder
Message:
  • merged ogre branch into merge branch
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/merge/src/orxonox/GraphicsEngine.cc

    r1220 r1263  
    4444#include "core/ConfigValueIncludes.h"
    4545#include "core/Debug.h"
    46 #include "core/TclBind.h"
     46#include "core/CommandExecutor.h"
    4747
    4848
     
    5353    @return The only instance of GraphicsEngine.
    5454  */
    55   GraphicsEngine& GraphicsEngine::getSingleton()
     55  /*static*/ GraphicsEngine& GraphicsEngine::getSingleton()
    5656  {
    5757    static GraphicsEngine theOnlyInstance;
     
    6262    @brief Only use constructor to initialise variables and pointers!
    6363  */
    64   GraphicsEngine::GraphicsEngine()
     64  GraphicsEngine::GraphicsEngine() :
     65    root_(0),
     66    scene_(0),
     67    renderWindow_(0),
     68    //configPath_(""),
     69    dataPath_(""),
     70    ogreLogfile_("")
    6571  {
    6672    RegisterObject(GraphicsEngine);
    67     //this->bOverwritePath_ = false;
     73
    6874    this->setConfigValues();
    69     // set to standard values
    70     this->configPath_ = "";
    71     this->root_ = 0;
    72     this->scene_ = 0;
    73     this->renderWindow_ = 0;
    74     COUT(4) << "*** GraphicsEngine: Constructed" << std::endl;
     75    CCOUT(4) << "Constructed" << std::endl;
     76  }
     77
     78  void GraphicsEngine::setConfigValues()
     79  {
     80    SetConfigValue(dataPath_, "../../Media/").description("relative path to media data");
     81    SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
     82    SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
     83    SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
     84    SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
    7585  }
    7686
     
    8999  void GraphicsEngine::destroy()
    90100  {
    91     COUT(4) << "*** GraphicsEngine: Destroying objects..." << std::endl;
     101    COUT(4) << "Destroying objects..." << std::endl;
    92102    Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
    93103    if (this->root_)
     
    103113      delete Ogre::LogManager::getSingletonPtr();
    104114    }
    105     COUT(4) << "*** GraphicsEngine: Destroying objects done" << std::endl;
    106   }
    107 
    108   void GraphicsEngine::setConfigValues()
    109   {
    110     SetConfigValue(dataPath_, "../../Media/").description("relative path to media data");
    111     SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
    112     SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
    113     SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    114     SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
    115 
    116     TclBind::getInstance().setDataPath(this->dataPath_);
     115    COUT(4) << "Destroying objects done" << std::endl;
    117116  }
    118117
     
    120119    @brief Creates the Ogre Root object and sets up the ogre log.
    121120  */
    122   void GraphicsEngine::setup()
    123   {
     121  bool GraphicsEngine::setup(std::string& dataPath)
     122  {
     123    CCOUT(3) << "Setting up..." << std::endl;
     124    // temporary overwrite of dataPath, change ini file for permanent change
     125    if (dataPath != "")
     126      dataPath_ = dataPath;
     127    if (dataPath_ == "")
     128      return false;
     129    if (dataPath_[dataPath_.size() - 1] != '/')
     130      dataPath_ += "/";
     131
    124132    //TODO: Check if file exists (maybe not here)
    125 /*#ifndef OGRE_STATIC_LIB
    126     root_ = new Ogre::Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg",
    127                      configPath_ + "Ogre.log");
    128 #else
    129     root_ = new Ogre::Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
    130 #endif*/
    131133#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG)
    132134    std::string plugin_filename = "plugins_d.cfg";
     
    137139    // create a logManager
    138140    Ogre::LogManager *logger;
    139                 if (Ogre::LogManager::getSingletonPtr() == 0)
    140                         logger = new Ogre::LogManager();
     141    if (Ogre::LogManager::getSingletonPtr() == 0)
     142      logger = new Ogre::LogManager();
    141143    else
    142144      logger = Ogre::LogManager::getSingletonPtr();
    143     COUT(4) << "*** GraphicsEngine: Ogre LogManager created/assigned" << std::endl;
     145    CCOUT(4) << "Ogre LogManager created/assigned" << std::endl;
    144146
    145147    // create our own log that we can listen to
     
    155157
    156158    // Root will detect that we've already created a Log
    157     COUT(4) << "*** GraphicsEngine: Creating Ogre Root..." << std::endl;
     159    CCOUT(4) << "Creating Ogre Root..." << std::endl;
    158160    root_ = new Ogre::Root(plugin_filename);
    159     COUT(4) << "*** GraphicsEngine: Creating Ogre Root done" << std::endl;
    160   }
    161 
    162   /**
    163    * @return scene manager
    164    */
    165   Ogre::SceneManager* GraphicsEngine::getSceneManager()
    166   {
    167     if(!scene_)
    168     {
    169       scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
    170       COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl;
    171     }
    172     return scene_;
    173   }
    174 
    175   bool GraphicsEngine::load(std::string dataPath)
    176   {
    177     // temporary overwrite of dataPath, change ini file for permanent change
    178     if( dataPath != "" )
    179       dataPath_ = dataPath + "/";
    180     loadRessourceLocations(this->dataPath_);
    181     if (!root_->restoreConfig() && !root_->showConfigDialog())
    182       return false;
     161    CCOUT(4) << "Creating Ogre Root done" << std::endl;
     162
     163    // specify where Ogre has to look for resources. This call doesn't parse anything yet!
     164    declareRessourceLocations();
     165
     166    CCOUT(3) << "Set up done." << std::endl;
    183167    return true;
    184168  }
    185169
    186   void GraphicsEngine::initialise()
    187   {
    188     this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
    189     Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
    190     Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    191     //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
    192     Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    193   }
    194 
    195   void GraphicsEngine::loadRessourceLocations(std::string dataPath)
    196   {
     170  void GraphicsEngine::declareRessourceLocations()
     171  {
     172    CCOUT(4) << "Declaring Resources" << std::endl;
    197173    //TODO: Specify layout of data file and maybe use xml-loader
    198174    //TODO: Work with ressource groups (should be generated by a special loader)
    199175    // Load resource paths from data file using configfile ressource type
    200176    Ogre::ConfigFile cf;
    201     cf.load(dataPath + "resources.cfg");
     177    cf.load(dataPath_ + "resources.cfg");
    202178
    203179    // Go through all sections & settings in the file
     
    216192
    217193        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    218                                            std::string(dataPath + archName),
     194                                           std::string(dataPath_ + archName),
    219195                                           typeName, secName);
    220196      }
    221197    }
     198  }
     199
     200  bool GraphicsEngine::loadRenderer()
     201  {
     202    CCOUT(4) << "Configuring Renderer" << std::endl;
     203    if (!root_->restoreConfig() && !root_->showConfigDialog())
     204      return false;
     205
     206    CCOUT(4) << "Creating render window" << std::endl;
     207    this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
     208    if (!root_->isInitialised())
     209    {
     210      CCOUT(2) << "Error: Creating Ogre root object failed" << std::endl;
     211      return false;
     212    }
     213    Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
     214    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
     215    return true;
     216  }
     217
     218  bool GraphicsEngine::initialiseResources()
     219  {
     220    CCOUT(4) << "Initialising resources" << std::endl;
     221    //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
     222    try
     223    {
     224      Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     225      /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
     226      for (unsigned int i = 0; i < str.size(); i++)
     227      {
     228        Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
     229      }*/
     230    }
     231    catch (Ogre::Exception e)
     232    {
     233      CCOUT(2) << "Error: There was an Error when initialising the resources." << std::endl;
     234      CCOUT(2) << "ErrorMessage: " << e.getFullDescription() << std::endl;
     235      return false;
     236    }
     237    return true;
     238  }
     239
     240  /**
     241   * @brief Creates the SceneManager
     242   */
     243  bool GraphicsEngine::createNewScene()
     244  {
     245    CCOUT(4) << "Creating new SceneManager" << std::endl;
     246    if (scene_)
     247    {
     248      CCOUT(2) << "SceneManager already exists! Skipping." << std::endl;
     249      return false;
     250    }
     251    scene_ = root_->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
     252    CCOUT(3) << "Created SceneManager: " << scene_ << std::endl;
     253    return true;
    222254  }
    223255
     
    291323    }
    292324    OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
    293         << "*** Ogre: " << message << std::endl;
    294   }
    295 
    296     void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw){
    297         int w = rw->getWidth();
    298         int h = rw->getHeight();
    299         InputManager::setWindowExtents(w, h);
    300     }
    301 
    302     void GraphicsEngine::windowResized(Ogre::RenderWindow *rw){
    303         int w = rw->getWidth();
    304         int h = rw->getHeight();
    305         InputManager::setWindowExtents(w, h);
    306     }
    307 
    308     void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw){
    309         int w = rw->getWidth();
    310         int h = rw->getHeight();
    311         InputManager::setWindowExtents(w, h);
    312     }
     325        << "Ogre: " << message << std::endl;
     326  }
     327
     328  /**
     329  * Window has resized.
     330  * @param rw The render window it occured in
     331  */
     332  void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw)
     333  {
     334    // note: this doesn't change the window extents
     335  }
     336
     337  /**
     338  * Window has resized.
     339  * @param rw The render window it occured in
     340  * @note GraphicsEngine has a render window stored itself. This is the same
     341  *       as rw. But we have to be careful when using multiple render windows!
     342  */
     343  void GraphicsEngine::windowResized(Ogre::RenderWindow *rw)
     344  {
     345    // change the mouse clipping size for absolute mouse movements
     346    int w = rw->getWidth();
     347    int h = rw->getHeight();
     348    InputManager::setWindowExtents(w, h);
     349  }
     350
     351  /**
     352  * Window has resized.
     353  * @param rw The render window it occured in
     354  */
     355  void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw)
     356  {
     357    // note: this doesn't change the window extents
     358  }
     359
     360  /**
     361  * Window has resized.
     362  * @param rw The render window it occured in
     363  */
     364  void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw)
     365  {
     366    // using CommandExecutor in order to avoid depending on Orxonox class.
     367    CommandExecutor::execute("exit", false);
     368  }
    313369}
Note: See TracChangeset for help on using the changeset viewer.