Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 4, 2008, 8:54:43 PM (16 years ago)
Author:
rgrieder
Message:

merged input branch back to trunk

File:
1 edited

Legend:

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

    r1511 r1535  
    2121 *
    2222 *   Author:
    23  *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
     23 *      Reto Grieder
    2424 *   Co-authors:
    25  *      Reto Grieder
     25 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007, Felix Schulthess
    2626 *
    2727 */
     
    3535#include "GraphicsEngine.h"
    3636
     37#include <OgreConfigFile.h>
     38#include <OgreException.h>
     39#include <OgreLogManager.h>
    3740#include <OgreRoot.h>
    38 #include <OgreException.h>
    39 #include <OgreConfigFile.h>
    40 #include <OgreLogManager.h>
     41#include <OgreSceneManager.h>
    4142#include <OgreTextureManager.h>
    42 #include "core/InputManager.h"
     43#include <OgreViewport.h>
     44
    4345#include "core/CoreIncludes.h"
    4446#include "core/ConfigValueIncludes.h"
    4547#include "core/Debug.h"
    4648#include "core/CommandExecutor.h"
    47 #include "core/TclBind.h"
     49#include "core/ConsoleCommand.h"
     50#include "core/input/InputManager.h"
     51
    4852#include "console/InGameConsole.h"
    49 
    50 #include "core/ConsoleCommand.h"
    51 #include <OgreSceneManager.h>
    52 #include <OgreCompositorManager.h>
    53 #include <OgreViewport.h>
     53#include "Settings.h"
     54
    5455
    5556namespace orxonox {
     
    7071    root_(0),
    7172    scene_(0),
    72     renderWindow_(0),
    73     //configPath_(""),
    74     dataPath_(""),
    75     ogreLogfile_("")
     73    renderWindow_(0)
    7674  {
    7775    RegisterObject(GraphicsEngine);
     
    8381  void GraphicsEngine::setConfigValues()
    8482  {
    85     SetConfigValue(dataPath_, "../../Media/").description("relative path to media data");
    86     SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
     83    SetConfigValue(resourceFile_,    "resources.cfg").description("Location of the resources file in the data path.");
     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.");
    8788    SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");
    8889    SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    8990    SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
    90 
    91     TclBind::getInstance().setDataPath(this->dataPath_);
    9291  }
    9392
     
    126125    @brief Creates the Ogre Root object and sets up the ogre log.
    127126  */
    128   bool GraphicsEngine::setup(std::string& dataPath)
     127  bool GraphicsEngine::setup()
    129128  {
    130129    CCOUT(3) << "Setting up..." << std::endl;
    131130    // temporary overwrite of dataPath, change ini file for permanent change
    132     if (dataPath != "")
    133       dataPath_ = dataPath;
    134     if (dataPath_ == "")
    135       return false;
    136     if (dataPath_[dataPath_.size() - 1] != '/')
    137       dataPath_ += "/";
    138 
    139     //TODO: Check if file exists (maybe not here)
    140 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG)
    141     std::string plugin_filename = "plugins_d.cfg";
    142 #else
    143     std::string plugin_filename = "plugins.cfg";
    144 #endif
    145131
    146132// TODO: LogManager doesn't work on specific systems. The why is unknown yet.
     
    154140    // create our own log that we can listen to
    155141    Ogre::Log *myLog;
    156     if (this->ogreLogfile_ == "")
     142    if (this->ogreLogFile_ == "")
    157143      myLog = logger->createLog("ogre.log", true, false, true);
    158144    else
    159       myLog = logger->createLog(this->ogreLogfile_, true, false, false);
     145      myLog = logger->createLog(this->ogreLogFile_, true, false, false);
    160146    CCOUT(4) << "Ogre Log created" << std::endl;
    161147
     
    167153    CCOUT(4) << "Creating Ogre Root..." << std::endl;
    168154
    169     root_ = new Ogre::Root(plugin_filename, "ogre.cfg", this->ogreLogfile_);
     155    if (ogrePluginsFile_ == "")
     156    {
     157      COUT(1) << "Error: Ogre plugins file set to \"\". Cannot load." << std::endl;
     158      return false;
     159    }
     160    if (ogreConfigFile_ == "")
     161    {
     162      COUT(1) << "Error: Ogre config file set to \"\". Cannot load." << std::endl;
     163      return false;
     164    }
     165    if (ogreLogFile_ == "")
     166    {
     167      COUT(1) << "Error: Ogre log file set to \"\". Cannot load." << std::endl;
     168      return false;
     169    }
     170
     171    try
     172    {
     173      root_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);
     174    }
     175    catch (Ogre::Exception ex)
     176    {
     177      COUT(2) << "Error: There was an exception when creating Ogre Root." << std::endl;
     178      return false;
     179    }
     180
     181    if (!root_->getInstalledPlugins().size())
     182    {
     183      COUT(1) << "Error: No plugins declared. Cannot load Ogre." << std::endl;
     184      COUT(0) << "Is the plugins file correctly declared?" << std::endl;
     185      return false;
     186    }
    170187
    171188#if 0
     
    180197
    181198    // specify where Ogre has to look for resources. This call doesn't parse anything yet!
    182     declareRessourceLocations();
     199    if (!declareRessourceLocations())
     200      return false;
    183201
    184202    CCOUT(3) << "Set up done." << std::endl;
     
    186204  }
    187205
    188   void GraphicsEngine::declareRessourceLocations()
     206  bool GraphicsEngine::declareRessourceLocations()
    189207  {
    190208    CCOUT(4) << "Declaring Resources" << std::endl;
    191209    //TODO: Specify layout of data file and maybe use xml-loader
    192210    //TODO: Work with ressource groups (should be generated by a special loader)
     211
     212    if (resourceFile_ == "")
     213    {
     214      COUT(1) << "Error: Resource file set to \"\". Cannot load." << std::endl;
     215      return false;
     216    }
     217
    193218    // Load resource paths from data file using configfile ressource type
    194219    Ogre::ConfigFile cf;
    195     cf.load(dataPath_ + "resources.cfg");
     220    try
     221    {
     222      cf.load(Settings::getDataPath() + resourceFile_);
     223    }
     224    catch (Ogre::Exception ex)
     225    {
     226      COUT(1) << "Error: Could not load resources.cfg in path " << Settings::getDataPath() << std::endl;
     227      COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
     228      return false;
     229    }
    196230
    197231    // Go through all sections & settings in the file
     
    201235    while (seci.hasMoreElements())
    202236    {
    203       secName = seci.peekNextKey();
    204       Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
    205       Ogre::ConfigFile::SettingsMultiMap::iterator i;
    206       for (i = settings->begin(); i != settings->end(); ++i)
     237      try
    207238      {
    208         typeName = i->first; // for instance "FileSystem" or "Zip"
    209         archName = i->second; // name (and location) of archive
    210 
    211         Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    212                                            std::string(dataPath_ + archName),
    213                                            typeName, secName);
     239        secName = seci.peekNextKey();
     240        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
     241        Ogre::ConfigFile::SettingsMultiMap::iterator i;
     242        for (i = settings->begin(); i != settings->end(); ++i)
     243        {
     244          typeName = i->first; // for instance "FileSystem" or "Zip"
     245          archName = i->second; // name (and location) of archive
     246
     247          Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
     248              std::string(Settings::getDataPath() + archName), typeName, secName);
     249        }
    214250      }
    215     }
     251      catch (Ogre::Exception ex)
     252      {
     253        COUT(2) << "Exception while reading resources.cfg. Proceeding.." << ex.getDescription() << std::endl;
     254      }
     255    }
     256    return true;
    216257  }
    217258
     
    223264
    224265    CCOUT(4) << "Creating render window" << std::endl;
    225     this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
     266    try
     267    {
     268      this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
     269    }
     270    catch (Ogre::Exception ex)
     271    {
     272      COUT(2) << "Error: There was an exception when initialising Ogre Root." << std::endl;
     273      return false;
     274    }
     275
    226276    if (!root_->isInitialised())
    227277    {
    228       CCOUT(2) << "Error: Creating Ogre root object failed" << std::endl;
     278      CCOUT(2) << "Error: Initialising Ogre root object failed." << std::endl;
    229279      return false;
    230280    }
Note: See TracChangeset for help on using the changeset viewer.