Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1263


Ignore:
Timestamp:
May 13, 2008, 3:45:19 PM (17 years ago)
Author:
rgrieder
Message:
  • merged ogre branch into merge branch
Location:
code/branches/merge/src
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • code/branches/merge/src/core/BaseObject.cc

    r1209 r1263  
    4545        @brief Constructor: Registers the object in the BaseObject-list.
    4646    */
    47     BaseObject::BaseObject()
     47    BaseObject::BaseObject() :
     48      bActive_(true),
     49      bVisible_(true),
     50      level_(0),
     51      namespace_(0)
    4852    {
    4953        RegisterRootObject(BaseObject);
    50 
    51         this->bActive_ = true;
    52         this->bVisible_ = true;
    53         this->level_ = 0;
    54         this->namespace_ = 0;
    5554    }
    5655
  • code/branches/merge/src/core/CoreIncludes.h

    r1062 r1263  
    5959    if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \
    6060        this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \
    61     orxonox::ClassManager<ClassName>::getIdentifier()->addObject(this)
     61    orxonox::ClassManager<ClassName>::getIdentifier()->addObject(this); \
     62    if (orxonox::Identifier::isCreatingHierarchy()) \
     63      return
    6264
    6365/**
  • code/branches/merge/src/core/Debug.h

    r1219 r1263  
    273273#define CCOUT_EXEC(x) \
    274274  orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
    275   << "*** " << this->getIdentifier()->getName() << ": "
     275  << this->getIdentifier()->getName() << ": "
    276276
    277277#ifndef CCOUT
  • code/branches/merge/src/core/Error.cc

    r1062 r1263  
    3737namespace orxonox
    3838{
    39         Error::Error()
    40         {
    41                 Error(0,"");
    42         }
    43 
    4439        Error::Error(std::string errorMsg, int errorCode)
    45         {
    46                 Error(errorCode, errorMsg);
    47         }
    48 
    49         Error::Error(int errorCode, std::string errorMsg)
    5040        {
    5141                COUT(1) << "############################ "<< std::endl
  • code/branches/merge/src/core/Error.h

    r1062 r1263  
    4444        {
    4545        public:
    46                 Error();
    47                 Error(std::string errorMsg, int errorCode = 0);
    48                 Error(int errorCode, std::string errorMsg = "");
     46                Error(std::string errorMsg = "", int errorCode = 0);
    4947        private:
    5048
  • code/branches/merge/src/core/Namespace.cc

    r1062 r1263  
    3737    CreateFactory(Namespace);
    3838
    39     Namespace::Namespace()
     39    Namespace::Namespace() :
     40      bAutogeneratedFileRootNamespace_(false),
     41      bRoot_(false),
     42      operator_("or")
    4043    {
    4144        RegisterObject(Namespace);
    42 
    43         this->bAutogeneratedFileRootNamespace_ = false;
    44         this->bRoot_ = false;
    45         this->operator_ = "or";
    4645    }
    4746
  • code/branches/merge/src/core/OrxonoxClass.cc

    r1056 r1263  
    3737{
    3838    /** @brief Constructor: Sets the default values. */
    39     OrxonoxClass::OrxonoxClass()
     39    OrxonoxClass::OrxonoxClass() :
     40      identifier_(0),
     41      parents_(0)
    4042    {
    4143        this->setConfigValues();
    42 
    43         this->identifier_ = 0;
    44         this->parents_ = 0;
    4544    }
    4645
  • 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}
  • code/branches/merge/src/orxonox/GraphicsEngine.h

    r1214 r1263  
    5252    @brief Graphics engine manager class
    5353    */
    54     class _OrxonoxExport GraphicsEngine : public Ogre::WindowEventListener, public OrxonoxClass, public Ogre::LogListener
     54    class _OrxonoxExport GraphicsEngine : public Ogre::WindowEventListener, public Ogre::LogListener, public OrxonoxClass
    5555    {
    56         friend class ClassIdentifier<GraphicsEngine>;
    5756        public:
    58             void setConfigPath(std::string path) { this->configPath_ = path; };
    5957            void setConfigValues();
    60             void setup();
    61             bool load(std::string path);
    62             void loadRessourceLocations(std::string path);
    63             Ogre::SceneManager* getSceneManager();
    64             void initialise();
     58            bool setup(std::string& dataPath);
     59            void declareRessourceLocations();
     60            bool loadRenderer();
     61            bool initialiseResources();
     62            bool createNewScene();
     63
    6564            void destroy();
     65
     66            Ogre::SceneManager* getSceneManager() { return scene_; }
     67            std::string& getDataPath() { return dataPath_; }
    6668
    6769            // several window properties
     
    7173            int getWindowHeight() const;
    7274
     75            void windowMoved       (Ogre::RenderWindow* rw);
     76            void windowResized     (Ogre::RenderWindow* rw);
     77            void windowFocusChanged(Ogre::RenderWindow* rw);
     78            void windowClosed      (Ogre::RenderWindow* rw);
     79
    7380            static GraphicsEngine& getSingleton();
    7481            static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }
    75 
    76             void windowMoved(Ogre::RenderWindow* rw);
    77             void windowResized(Ogre::RenderWindow* rw);
    78             void windowFocusChanged(Ogre::RenderWindow* rw);
    7982
    8083        private:
     
    9295            Ogre::RenderWindow* renderWindow_;//!< the current render window
    9396            //bool               bOverwritePath_; //!< overwrites path
    94             std::string         configPath_;  //!< path to config file
     97            //std::string         configPath_;  //!< path to config file
    9598            std::string         dataPath_;    //!< path to data file
    9699            std::string         ogreLogfile_; //!< log file name for Ogre log messages
  • code/branches/merge/src/orxonox/Main.cc

    r1214 r1263  
    7878    Orxonox* orx = Orxonox::getSingleton();
    7979
     80    bool res = false;
    8081#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
    81     orx->init(argc, argv, macBundlePath());
     82    res = orx->init(argc, argv, macBundlePath());
    8283#else
    83     orx->init(argc, argv, "");
     84    res = orx->init(argc, argv, "");
    8485#endif
    8586
    86     orx->start();
     87    if (res)
     88      orx->start();
    8789    orx->destroySingleton();
    8890  /*}
  • code/branches/merge/src/orxonox/Orxonox.cc

    r1219 r1263  
    3737
    3838//****** STD *******
    39 //#include <iostream>
    40 //#include <exception>
    4139#include <deque>
    4240
    4341//****** OGRE ******
    44 //#include <OgreException.h>
    4542#include <OgreFrameListener.h>
    4643#include <OgreOverlay.h>
     
    6562#include "core/InputBuffer.h"
    6663#include "core/InputManager.h"
     64#include "core/TclBind.h"
    6765
    6866// audio
     
    158156
    159157  /**
    160    * create a new instance of Orxonox
    161    */
    162   Orxonox::Orxonox()
    163   {
    164     this->mode_ = STANDALONE;
    165     this->serverIp_ = "";
    166     this->ogre_ = &GraphicsEngine::getSingleton();
    167     this->timer_ = 0;
    168     this->dataPath_ = "";
    169     this->auMan_ = 0;
    170     this->orxonoxHUD_ = 0;
    171     this->inputHandler_ = 0;
     158   * Create a new instance of Orxonox. Avoid doing any actual work here.
     159   */
     160  Orxonox::Orxonox() :
     161    ogre_(&GraphicsEngine::getSingleton()),
     162    //auMan_(0),
     163    timer_(0),
    172164    // turn on frame smoothing by setting a value different from 0
    173     this->frameSmoothingTime_ = 0.0f;
    174     this->bAbort_ = false;
    175     this->timefactor_ = 1.0f;
    176   }
    177 
    178   /**
    179    * destruct Orxonox
     165    frameSmoothingTime_(0.0f),
     166    orxonoxConsole_(0),
     167    orxonoxHUD_(0),
     168    bAbort_(false),
     169    timefactor_(1.0f),
     170    mode_(STANDALONE),
     171    serverIp_("")
     172  {
     173  }
     174
     175  /**
     176   * Destruct Orxonox.
    180177   */
    181178  Orxonox::~Orxonox()
     
    186183    Loader::close();
    187184    InputManager::destroy();
    188     if (this->auMan_)
    189       delete this->auMan_;
     185    //if (this->auMan_)
     186    //  delete this->auMan_;
    190187    if (this->timer_)
    191188      delete this->timer_;
     
    199196
    200197  /**
    201     @brief Immediately deletes the orxonox object.
    202     Never use if you can help it while rendering!
    203   */
    204   void Orxonox::abortImmediateForce()
    205   {
    206     COUT(1) << "*** Orxonox Error: Orxonox object was unexpectedly destroyed." << std::endl;
    207     delete this;
    208   }
    209 
    210   /**
    211198    Asks the mainloop nicely to abort.
    212199  */
     
    218205
    219206  /**
    220    * @return singleton object
     207   * @return singleton reference
    221208   */
    222209  Orxonox* Orxonox::getSingleton()
     
    243230   * @param path path to config (in home dir or something)
    244231   */
    245   void Orxonox::init(int argc, char **argv, std::string path)
     232  bool Orxonox::init(int argc, char **argv, std::string path)
    246233  {
    247234    //TODO: find config file (assuming executable directory)
     
    249236    //TODO: give config file to Ogre
    250237    std::string mode;
     238    std::string dataPath;
    251239
    252240    ArgReader ar(argc, argv);
    253241    ar.checkArgument("mode", mode, false);
    254     ar.checkArgument("data", this->dataPath_, false);
     242    ar.checkArgument("data", dataPath, false);
    255243    ar.checkArgument("ip", serverIp_, false);
    256     if(ar.errorHandling()) abortImmediateForce();
    257     if(mode == std::string("client"))
     244    if(ar.errorHandling())
     245      return false;
     246
     247    COUT(3) << "*** Orxonox: Mode is " << mode << "." << std::endl;
     248    if (mode == "client")
     249      mode_ = CLIENT;
     250    else if (mode == "server")
     251      mode_ = SERVER;
     252    else
     253      mode_ = STANDALONE;
     254
     255    //if (mode_ == DEDICATED)
     256      // TODO: decide what to do here
     257    //else
     258
     259    // for playable server, client and standalone, the startup
     260    // procedure until the GUI is identical
     261
     262    TclBind::getInstance().setDataPath(dataPath);
     263    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
     264    Factory::createClassHierarchy();
     265
     266    if (!ogre_->setup(path))       // creates ogre root and other essentials
     267      return false;
     268
     269    return true;
     270  }
     271
     272  /**
     273   * start modules
     274   */
     275  bool Orxonox::start()
     276  {
     277    //if (mode == DEDICATED)
     278    // do something else
     279    //else
     280
     281    if (!ogre_->loadRenderer())    // creates the render window
     282      return false;
     283
     284    // Calls the InputManager which sets up the input devices.
     285    // The render window width and height are used to set up the mouse movement.
     286    if (!InputManager::initialise(ogre_->getWindowHandle(),
     287          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
     288      return false;
     289
     290    // TODO: Spread this so that this call only initialises things needed for the GUI
     291    if (!ogre_->initialiseResources())
     292      return false;
     293
     294    // TOOD: load the GUI here
     295    // set InputManager to GUI mode
     296    InputManager::setInputState(InputManager::IS_GUI);
     297    // TODO: run GUI here
     298
     299    // The following lines depend very much on the GUI output, so they're probably misplaced here..
     300
     301    InputManager::setInputState(InputManager::IS_NONE);
     302
     303    if (!loadPlayground())
     304      return false;
     305
     306    switch (mode_)
    258307    {
    259       mode_ = CLIENT;
    260       clientInit(path);
    261     }
    262     else if(mode== std::string("server")){
    263       mode_ = SERVER;
    264       serverInit(path);
    265     }
    266     else{
    267       mode_ = STANDALONE;
    268       standaloneInit(path);
    269     }
    270   }
    271 
    272   void Orxonox::serverInit(std::string path)
    273   {
    274     COUT(2) << "initialising server" << std::endl;
    275 
    276     ogre_->setConfigPath(path);
    277     ogre_->setup();
    278     //root_ = ogre_->getRoot();
    279     if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */);
    280 
    281     server_g = new network::Server();
    282   }
    283 
    284   void Orxonox::clientInit(std::string path)
    285   {
    286     COUT(2) << "initialising client" << std::endl;\
    287 
    288     ogre_->setConfigPath(path);
    289     ogre_->setup();
    290     if(serverIp_.compare("")==0)
    291       client_g = new network::Client();
    292     else
    293       client_g = new network::Client(serverIp_, NETWORK_PORT);
    294     if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */);
    295   }
    296 
    297   void Orxonox::standaloneInit(std::string path)
    298   {
    299     COUT(2) << "initialising standalone mode" << std::endl;
    300 
    301     ogre_->setConfigPath(path);
    302     ogre_->setup();
    303     if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */);
    304   }
    305 
    306   /**
    307    * start modules
    308    */
    309   void Orxonox::start()
    310   {
    311     switch(mode_){
     308    case SERVER:
     309      if (!serverLoad())
     310        return false;
     311      break;
    312312    case CLIENT:
    313       clientStart();
    314       break;
    315     case SERVER:
    316       serverStart();
     313      if (!clientLoad())
     314        return false;
    317315      break;
    318316    default:
    319       standaloneStart();
     317      if (!standaloneLoad())
     318        return false;
    320319    }
    321   }
    322 
    323   void Orxonox::clientStart(){
    324     ogre_->initialise();
    325     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    326     Factory::createClassHierarchy();
    327 
    328 
    329     auMan_ = new audio::AudioManager();
    330 
     320
     321    InputManager::setInputState(InputManager::IS_NORMAL);
     322
     323    return startRenderLoop();
     324  }
     325
     326  /**
     327   * Loads everything in the scene except for the actual objects.
     328   * This includes HUD, Console..
     329   */
     330  bool Orxonox::loadPlayground()
     331  {
     332    ogre_->createNewScene();
     333
     334          // Init audio
     335    //auMan_ = new audio::AudioManager();
     336    //auMan_->ambientAdd("a1");
     337    //auMan_->ambientAdd("a2");
     338    //auMan_->ambientAdd("a3");
     339    //auMan->ambientAdd("ambient1");
     340    //auMan_->ambientStart();
     341
     342    // Load the HUD
     343    COUT(3) << "*** Orxonox: Loading HUD..." << std::endl;
    331344    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
    332345    orxonoxHUD_ = new HUD();
     
    335348    hudOverlay->show();
    336349
    337     client_g->establishConnection();
    338     client_g->tick(0);
    339 
    340 
    341     //setupInputSystem();
    342 
    343     startRenderLoop();
    344   }
    345 
    346   void Orxonox::serverStart(){
    347     //TODO: start modules
    348     ogre_->initialise();
    349     //TODO: run engine
    350     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    351     Factory::createClassHierarchy();
    352     createScene();
    353     setupInputSystem();
    354 
    355     server_g->open();
    356 
    357     startRenderLoop();
    358   }
    359 
    360   void Orxonox::standaloneStart(){
    361     //TODO: start modules
    362     ogre_->initialise();
    363     //TODO: run engine
    364     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    365     Factory::createClassHierarchy();
    366     createScene();
    367     setupInputSystem();
    368 
    369     startRenderLoop();
    370   }
    371 
    372   void Orxonox::createScene(void)
    373   {
    374           // Init audio
    375     auMan_ = new audio::AudioManager();
    376 
    377     // load this file from config
    378     Level* startlevel = new Level("levels/sample.oxw");
    379     Loader::open(startlevel);
    380 
    381     Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
    382     orxonoxHUD_ = new HUD();
    383     orxonoxHUD_->setEnergyValue(20);
    384     orxonoxHUD_->setEnergyDistr(20,20,60);
    385     hudOverlay->show();
    386 
    387         /*
    388     auMan_->ambientAdd("a1");
    389     auMan_->ambientAdd("a2");
    390     auMan_->ambientAdd("a3");
    391     //auMan->ambientAdd("ambient1");
    392     auMan_->ambientStart();
    393   */
    394   }
    395 
    396   /**
    397     @brief Calls the InputHandler which sets up the input devices.
    398     The render window width and height are used to set up the mouse movement.
    399   */
    400   void Orxonox::setupInputSystem()
    401   {
    402     if (!InputManager::initialise(ogre_->getWindowHandle(),
    403           ogre_->getWindowWidth(), ogre_->getWindowHeight()))
    404       abortImmediateForce();
    405     InputManager::setInputState(InputManager::IS_NORMAL);
    406   }
    407 
    408   /**
    409     Main loop of the orxonox game.
    410     This is a new solution, using the ogre engine instead of being used by it.
    411     An alternative solution would be to simply use the timer of the Root object,
    412     but that implies using Ogre in any case. There would be no way to test
    413     our code without the help of the root object.
    414     There's even a chance that we can dispose of the root object entirely
    415     in server mode.
    416     About the loop: The design is almost exactly like the one in ogre, so that
    417     if any part of ogre registers a framelisteners, it will still behave
    418     correctly. Furthermore the time smoothing feature from ogre has been
    419     implemented too. If turned on (see orxonox constructor), it will calculate
    420     the dt_n by means of the recent most dt_n-1, dt_n-2, etc.
    421   */
    422   void Orxonox::startRenderLoop()
    423   {
     350    COUT(3) << "*** Orxonox: Loading Console..." << std::endl;
    424351    InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));
    425352    /*
     
    432359    ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
    433360    */
    434 
    435361    orxonoxConsole_ = new InGameConsole(ib);
    436362    ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);
     
    441367    ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);
    442368
     369    return true;
     370  }
     371
     372  /**
     373   * Level loading method for server mode.
     374   */
     375  bool Orxonox::serverLoad()
     376  {
     377    COUT(2) << "Loading level in server mode" << std::endl;
     378
     379    server_g = new network::Server();
     380
     381    if (!loadScene())
     382      return false;
     383
     384    server_g->open();
     385
     386    return true;
     387  }
     388
     389  /**
     390   * Level loading method for client mode.
     391   */
     392  bool Orxonox::clientLoad()
     393  {
     394    COUT(2) << "Loading level in client mode" << std::endl;\
     395
     396    if (serverIp_.compare("") == 0)
     397      client_g = new network::Client();
     398    else
     399      client_g = new network::Client(serverIp_, NETWORK_PORT);
     400
     401    client_g->establishConnection();
     402    client_g->tick(0);
     403
     404    return true;
     405  }
     406
     407  /**
     408   * Level loading method for standalone mode.
     409   */
     410  bool Orxonox::standaloneLoad()
     411  {
     412    COUT(2) << "Loading level in standalone mode" << std::endl;
     413
     414    if (!loadScene())
     415      return false;
     416
     417    return true;
     418  }
     419
     420  /**
     421   * Helper method to load a level.
     422   */
     423  bool Orxonox::loadScene()
     424  {
     425    Level* startlevel = new Level("levels/sample.oxw");
     426    Loader::open(startlevel);
     427
     428    return true;
     429  }
     430
     431
     432  /**
     433    Main loop of the orxonox game.
     434    About the loop: The design is almost exactly like the one in ogre, so that
     435    if any part of ogre registers a framelisteners, it will still behave
     436    correctly. Furthermore the time smoothing feature from ogre has been
     437    implemented too. If turned on (see orxonox constructor), it will calculate
     438    the dt_n by means of the recent most dt_n-1, dt_n-2, etc.
     439  */
     440  bool Orxonox::startRenderLoop()
     441  {
    443442    // first check whether ogre root object has been created
    444443    if (Ogre::Root::getSingletonPtr() == 0)
    445444    {
    446445      COUT(2) << "*** Orxonox Error: Could not start rendering. No Ogre root object found" << std::endl;
    447       return;
     446      return false;
    448447    }
    449448    Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
     
    465464    timer_->reset();
    466465
     466    COUT(3) << "*** Orxonox: Starting the main loop." << std::endl;
    467467          while (!bAbort_)
    468468          {
     
    510510      ogreRoot._fireFrameEnded(evt);
    511511          }
     512
     513    return true;
    512514  }
    513515
     
    550552  }
    551553
     554  /**
     555   * Static function that shows the console in game mode.
     556   */
    552557  void Orxonox::activateConsole()
    553558  {
     559    // currently, the console shows itself when feeded with input.
    554560    InputManager::setInputState(InputManager::IS_CONSOLE);
    555561  }
  • code/branches/merge/src/orxonox/Orxonox.h

    r1219 r1263  
    5757  {
    5858    public:
    59       void init(int argc, char **argv, std::string path);
    60       void start();
    61       void abortImmediateForce();
     59      bool init(int argc, char **argv, std::string path);
     60      bool start();
     61
    6262      void abortRequest();
    63       inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
     63      //inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
    6464
    6565      static Orxonox* getSingleton();
     
    7979      ~Orxonox();
    8080
    81       // init functions
    82       void serverInit(std::string path);
    83       void clientInit(std::string path);
    84       void standaloneInit(std::string path);
     81      bool loadPlayground();
    8582
    86       // run functions
    87       void serverStart();
    88       void clientStart();
    89       void standaloneStart();
     83      bool serverLoad();
     84      bool clientLoad();
     85      bool standaloneLoad();
    9086
    91       void createScene();
    92       void setupInputSystem();
    93       void startRenderLoop();
     87      bool loadScene();
     88
     89      bool startRenderLoop();
     90
    9491      float calculateEventTime(unsigned long, std::deque<unsigned long>&);
    9592
    9693    private:
    9794      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
    98       std::string           dataPath_;      //!< path to data
    99       audio::AudioManager*  auMan_;         //!< audio manager
    100       InputManager*         inputHandler_;  //!< Handles input with key bindings
     95      //audio::AudioManager*  auMan_;         //!< audio manager
    10196      Ogre::Timer*          timer_;         //!< Main loop timer
    10297      // TODO: make this a config-value by creating a config class for orxonox
  • code/branches/merge/src/orxonox/OrxonoxPlatform.h

    r1064 r1263  
    2121 *
    2222 *   Author:
    23  *      An unknown man from the Ogre development crew
     23 *      ...
    2424 *   Co-authors:
    2525 *      Reto Grieder
  • code/branches/merge/src/orxonox/console/InGameConsole.cc

    r1223 r1263  
    5454    const float BLINK = 0.25;
    5555
    56     InGameConsole::InGameConsole(InputBuffer* ib){
     56    InGameConsole::InGameConsole(InputBuffer* ib) :
     57        windowW(0), windowH(0),
     58        scroll(0), scrollTimer(0.0f),
     59        cursor(0.0f),
     60        active(false),
     61        ib_(ib),
     62        om(0),
     63        consoleOverlay(0),
     64        consoleOverlayContainer(0),
     65        consoleOverlayNoise(0),
     66        consoleOverlayBorder(0),
     67        consoleOverlayTextAreas(0)
     68    {
    5769        //RegisterObject(InGameConsole);
    58         ib_ = ib;
    59         active = false;
    60         cursor = 0.0;
    6170        init();
    6271    }
  • code/branches/merge/src/orxonox/objects/Explosion.cc

    r1056 r1263  
    4545    CreateFactory(Explosion);
    4646
    47     Explosion::Explosion(WorldEntity* owner)
     47    Explosion::Explosion(WorldEntity* owner) :
     48      particle_(0),
     49      lifetime_(0.4)
    4850    {
    4951        RegisterObject(Explosion);
    50 
    51         this->particle_ = 0;
    52         this->lifetime_ = 0.4;
    5352
    5453        if (owner)
  • code/branches/merge/src/orxonox/objects/Model.cc

    r1209 r1263  
    4949    }
    5050
    51     void Model::loadParams(TiXmlElement* xmlElem)
    52     {
    53         WorldEntity::loadParams(xmlElem);
    54 
    55         if (xmlElem->Attribute("mesh"))
    56         {
    57             meshSrc_ = xmlElem->Attribute("mesh");
    58         }
    59         create();
    60     }
    61 
    6251    /**
    6352        @brief XML loading and saving.
  • code/branches/merge/src/orxonox/objects/Model.h

    r1056 r1263  
    4343            Model();
    4444            virtual ~Model();
    45             virtual void loadParams(TiXmlElement* xmlElem);
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4746            void setMesh(const std::string& meshname);
  • code/branches/merge/src/orxonox/objects/NPC.cc

    r1056 r1263  
    3636  CreateFactory(NPC);
    3737
    38   NPC::NPC()
     38  NPC::NPC() :
     39    movable_(true)
    3940  {
    4041    RegisterObject(NPC);
    41     movable_ = true;
    4242  }
    4343
  • code/branches/merge/src/orxonox/objects/Projectile.cc

    r1056 r1263  
    4242    CreateFactory(Projectile);
    4343
    44     Projectile::Projectile(SpaceShip* owner)
     44    Projectile::Projectile(SpaceShip* owner) :
     45      owner_(owner)
    4546    {
    4647        RegisterObject(Projectile);
    4748
    4849        this->setConfigValues();
    49 
    50         this->owner_ = owner;
    5150
    5251        this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
  • code/branches/merge/src/orxonox/objects/SpaceShip.cc

    r1219 r1263  
    6464    SpaceShip::SpaceShip()
    6565    {
    66         RegisterObject(SpaceShip);
    67         this->registerAllVariables();
    68 
    6966        SpaceShip::instance_s = this;
    70 
    71         this->setConfigValues();
    7267
    7368        this->setMouseEventCallback_ = false;
     
    139134//         this->create();
    140135
     136        RegisterObject(SpaceShip);
     137        this->registerAllVariables();
     138        this->setConfigValues();
    141139
    142140        COUT(3) << "Info: SpaceShip was loaded" << std::endl;
     
    166164    void SpaceShip::init()
    167165    {
     166        if (!setMouseEventCallback_)
     167        {
     168          InputManager::addMouseHandler(this, "SpaceShip");
     169          setMouseEventCallback_ = true;
     170        }
     171
    168172        // START CREATING THRUSTER
    169173        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     
    428432    void SpaceShip::tick(float dt)
    429433    {
    430         if (!setMouseEventCallback_)
    431         {
    432           InputManager::addMouseHandler(this, "SpaceShip");
    433           setMouseEventCallback_ = true;
    434         }
    435 
    436434        if (this->redNode_ && this->greenNode_)
    437435        {
  • code/branches/merge/src/orxonox/objects/WorldEntity.cc

    r1209 r1263  
    4545    unsigned int WorldEntity::worldEntityCounter_s = 0;
    4646
    47     WorldEntity::WorldEntity()
     47    WorldEntity::WorldEntity() :
     48      velocity_    (0, 0, 0),
     49      acceleration_(0, 0, 0),
     50      rotationAxis_(0, 1, 0),
     51      rotationRate_(0),
     52      momentum_    (0),
     53      node_        (0),
     54      bStatic_     (true)
    4855    {
    4956        RegisterObject(WorldEntity);
    50 
    51         //create();
    52 
    53         this->bStatic_ = true;
    54         this->velocity_ = Vector3(0, 0, 0);
    55         this->acceleration_ = Vector3(0, 0, 0);
    56         this->rotationAxis_ = Vector3(0, 1, 0);
    57         this->rotationRate_ = 0;
    58         this->momentum_ = 0;
    5957
    6058        if (GraphicsEngine::getSingleton().getSceneManager())
     
    6664
    6765          registerAllVariables();
    68         }
    69         else
    70         {
    71           this->node_ = 0;
    7266        }
    7367    }
     
    9488        BaseObject::loadParams(xmlElem);
    9589        create();
    96 /*
    97         if (xmlElem->Attribute("position"))
    98         {
    99             std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");
    100             float x, y, z;
    101             String2Number<float>(x, pos[0]);
    102             String2Number<float>(y, pos[1]);
    103             String2Number<float>(z, pos[2]);
    104             this->setPosition(x, y, z);
    105         }
    106 
    107         if (xmlElem->Attribute("direction"))
    108         {
    109             std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");
    110             float x, y, z;
    111             String2Number<float>(x, pos[0]);
    112             String2Number<float>(y, pos[1]);
    113             String2Number<float>(z, pos[2]);
    114             this->setDirection(x, y, z);
    115         }
    116 
    117         if (xmlElem->Attribute("yaw") || xmlElem->Attribute("pitch") || xmlElem->Attribute("roll"))
    118         {
    119             float yaw = 0.0, pitch = 0.0, roll = 0.0;
    120             if (xmlElem->Attribute("yaw"))
    121                 String2Number<float>(yaw,xmlElem->Attribute("yaw"));
    122 
    123             if (xmlElem->Attribute("pitch"))
    124                 String2Number<float>(pitch,xmlElem->Attribute("pitch"));
    125 
    126             if (xmlElem->Attribute("roll"))
    127                 String2Number<float>(roll,xmlElem->Attribute("roll"));
    128 
    129             this->yaw(Degree(yaw));
    130             this->pitch(Degree(pitch));
    131             this->roll(Degree(roll));
    132         }
    133 
    134         if (xmlElem->Attribute("scale"))
    135         {
    136             std::string scaleStr = xmlElem->Attribute("scale");
    137             float scale;
    138             String2Number<float>(scale, scaleStr);
    139             this->setScale(scale);
    140         }
    141 
    142         if (xmlElem->Attribute("rotationAxis"))
    143         {
    144             std::vector<std::string> pos = tokenize(xmlElem->Attribute("rotationAxis"),",");
    145             float x, y, z;
    146             String2Number<float>(x, pos[0]);
    147             String2Number<float>(y, pos[1]);
    148             String2Number<float>(z, pos[2]);
    149             this->setRotationAxis(x, y, z);
    150         }
    151 
    152         if (xmlElem->Attribute("rotationRate"))
    153         {
    154             float rotationRate;
    155             String2Number<float>(rotationRate, xmlElem->Attribute("rotationRate"));
    156             this->setRotationRate(Degree(rotationRate));
    157             if (rotationRate != 0)
    158                 this->setStatic(false);
    159         }
    160 
    161         create();
    162 */
    16390    }
    16491
  • code/branches/merge/src/orxonox/tools/Timer.cc

    r1063 r1263  
    6868    TimerBase::TimerBase()
    6969    {
    70         RegisterRootObject(TimerBase);
    71 
    7270        this->executor_ = 0;
    7371        this->interval_ = 0;
     
    7674
    7775        this->time_ = 0;
     76
     77        RegisterRootObject(TimerBase);
    7878    }
    7979
     
    8383    TimerBase::~TimerBase()
    8484    {
    85         delete this->executor_;
     85      if (this->executor_)
     86          delete this->executor_;
    8687    }
    8788
Note: See TracChangeset for help on using the changeset viewer.