Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (16 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
File:
1 edited

Legend:

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

    r1407 r1502  
    5151//#include "util/Sleep.h"
    5252#include "util/ArgReader.h"
    53 #include "util/ExprParser.h"
    5453
    5554// core
     
    5756#include "core/ConsoleCommand.h"
    5857#include "core/Debug.h"
    59 #include "core/Factory.h"
    6058#include "core/Loader.h"
    6159#include "core/Tickable.h"
    62 #include "core/InputBuffer.h"
    6360#include "core/InputManager.h"
    6461#include "core/TclBind.h"
     
    7269
    7370// objects and tools
    74 #include "tools/Timer.h"
    7571#include "hud/HUD.h"
    76 #include "console/InGameConsole.h"
     72#include <Ogre.h>
     73
     74#include "GraphicsEngine.h"
    7775
    7876// FIXME: is this really file scope?
     
    8381namespace orxonox
    8482{
    85   ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None).setKeybindMode(KeybindMode::OnPress);
    86   ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0)
    87     .setAxisParamIndex(0).setIsAxisRelative(false);
    88   ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0);
    89   ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None);
    90   class Testconsole : public InputBufferListener
    91   {
    92     public:
    93       Testconsole(InputBuffer* ib) : ib_(ib) {}
    94       void listen() const
    95       {
    96         std::cout << "> " << this->ib_->get() << std::endl;
    97       }
    98       void execute() const
    99       {
    100         std::cout << ">> " << this->ib_->get() << std::endl;
    101         if (!CommandExecutor::execute(this->ib_->get()))
    102           std::cout << "Error" << std::endl;
    103         this->ib_->clear();
    104       }
    105       void hintandcomplete() const
    106       {
    107         std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl;
    108         this->ib_->set(CommandExecutor::complete(this->ib_->get()));
    109       }
    110       void clear() const
    111       {
    112         this->ib_->clear();
    113       }
    114       void removeLast() const
    115       {
    116         this->ib_->removeLast();
    117       }
    118       void exit() const
    119       {
    120         InputManager::setInputState(InputManager::IS_NORMAL);
    121       }
    122 
    123     private:
    124       InputBuffer* ib_;
    125   };
    126 
    127   class Calculator
    128   {
    129   public:
    130     static float calculate(const std::string& calculation)
    131     {
    132       ExprParser expr(calculation);
    133       if (expr.getSuccess())
    134       {
    135         if (expr.getResult() == 42.0)
    136           std::cout << "Greetings from the restaurant at the end of the universe." << std::endl;
    137         // FIXME: insert modifier to display in full precision
    138         std::cout << "Result is: " << expr.getResult() << std::endl;
    139         if (expr.getRemains() != "")
    140           std::cout << "Warning: Expression could not be parsed to the end! Remains: '"
    141               << expr.getRemains() << "'" << std::endl;
    142         return expr.getResult();
    143       }
    144       else
    145       {
    146         std::cout << "Cannot calculate expression: Parse error" << std::endl;
    147         return 0;
    148       }
    149     }
    150   };
    151   ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None);
     83  SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress);
     84  SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false);
     85  SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0);
    15286
    15387  /**
     
    16599    // turn on frame smoothing by setting a value different from 0
    166100    frameSmoothingTime_(0.0f),
    167     orxonoxConsole_(0),
    168101    orxonoxHUD_(0),
    169102    bAbort_(false),
    170103    timefactor_(1.0f),
    171104    mode_(STANDALONE),
    172     serverIp_("")
     105    serverIp_(""),
     106    serverPort_(NETWORK_PORT)
    173107  {
    174108  }
     
    180114  {
    181115    // keep in mind: the order of deletion is very important!
    182     if (this->orxonoxHUD_)
    183       delete this->orxonoxHUD_;
     116//    if (this->orxonoxHUD_)
     117//      delete this->orxonoxHUD_;
    184118    Loader::close();
    185119    InputManager::destroy();
     
    244178    ar.checkArgument("data", dataPath, false);
    245179    ar.checkArgument("ip", serverIp_, false);
     180    ar.checkArgument("port", serverPort_, false);
    246181    if(ar.errorHandling())
    247182      return false;
     
    251186    else if (mode == "server")
    252187      mode_ = SERVER;
     188    else if (mode == "dedicated")
     189      mode_ = DEDICATED;
    253190    else
    254191    {
     
    265202    // procedure until the GUI is identical
    266203
    267     TclBind::getInstance().setDataPath(dataPath);
    268204    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    269205    Factory::createClassHierarchy();
     
    281217  bool Orxonox::start()
    282218  {
    283     //if (mode == DEDICATED)
    284     // do something else
    285     //else
    286 
    287     if (!ogre_->loadRenderer())    // creates the render window
    288       return false;
    289 
    290     // Calls the InputManager which sets up the input devices.
    291     // The render window width and height are used to set up the mouse movement.
    292     if (!InputManager::initialise(ogre_->getWindowHandle(),
    293           ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true))
    294       return false;
    295 
    296     // TODO: Spread this so that this call only initialises things needed for the GUI
    297     if (!ogre_->initialiseResources())
    298       return false;
    299 
    300     // TOOD: load the GUI here
    301     // set InputManager to GUI mode
    302     InputManager::setInputState(InputManager::IS_GUI);
    303     // TODO: run GUI here
    304 
    305     // The following lines depend very much on the GUI output, so they're probably misplaced here..
    306 
    307     InputManager::setInputState(InputManager::IS_NONE);
    308 
    309     if (!loadPlayground())
    310       return false;
     219    if (mode_ == DEDICATED)
     220    {
     221      // do something else
     222    }
     223    else
     224    { // not dedicated server
     225      if (!ogre_->loadRenderer())    // creates the render window
     226        return false;
     227
     228      // Calls the InputManager which sets up the input devices.
     229      // The render window width and height are used to set up the mouse movement.
     230      if (!InputManager::initialise(ogre_->getWindowHandle(),
     231            ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true))
     232        return false;
     233
     234      // TODO: Spread this so that this call only initialises things needed for the GUI
     235      if (!ogre_->initialiseResources())
     236        return false;
     237
     238      // TOOD: load the GUI here
     239      // set InputManager to GUI mode
     240      InputManager::setInputState(InputManager::IS_GUI);
     241      // TODO: run GUI here
     242
     243      // The following lines depend very much on the GUI output, so they're probably misplaced here..
     244
     245      InputManager::setInputState(InputManager::IS_NONE);
     246
     247      // create Ogre SceneManager
     248      ogre_->createNewScene();
     249
     250      if (!loadPlayground())
     251        return false;
     252    }
    311253
    312254    switch (mode_)
     
    320262        return false;
    321263      break;
     264    case DEDICATED:
     265      if (!serverLoad())
     266        return false;
     267      break;
    322268    default:
    323269      if (!standaloneLoad())
     
    336282  bool Orxonox::loadPlayground()
    337283  {
    338     ogre_->createNewScene();
    339 
    340           // Init audio
     284    // Init audio
    341285    //auMan_ = new audio::AudioManager();
    342286    //auMan_->ambientAdd("a1");
     
    348292    // Load the HUD
    349293    COUT(3) << "Orxonox: Loading HUD..." << std::endl;
    350     orxonoxHUD_ = new HUD(1);
    351 
    352     COUT(3) << "Orxonox: Loading Console..." << std::endl;
    353     InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));
    354     /*
    355     Testconsole* console = new Testconsole(ib);
    356     ib->registerListener(console, &Testconsole::listen, true);
    357     ib->registerListener(console, &Testconsole::execute, '\r', false);
    358     ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);
    359     ib->registerListener(console, &Testconsole::clear, '§', true);
    360     ib->registerListener(console, &Testconsole::removeLast, '\b', true);
    361     ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
    362     */
    363     orxonoxConsole_ = new InGameConsole(ib);
    364     ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);
    365     ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);
    366     ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);
    367     ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);
    368     ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);
    369     ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);
    370 
     294    orxonoxHUD_ = &HUD::getSingleton();
    371295    return true;
    372296  }
     
    379303    COUT(2) << "Loading level in server mode" << std::endl;
    380304
    381     server_g = new network::Server();
     305    server_g = new network::Server(serverPort_);
    382306
    383307    if (!loadScene())
     
    399323      client_g = network::Client::createSingleton();
    400324    else
    401       client_g = network::Client::createSingleton(serverIp_, NETWORK_PORT);
    402 
    403     client_g->establishConnection();
     325
     326      client_g = network::Client::createSingleton(serverIp_, serverPort_);
     327
     328    if(!client_g->establishConnection())
     329      return false;
    404330    client_g->tick(0);
    405331
     
    427353    Level* startlevel = new Level("levels/sample.oxw");
    428354    Loader::open(startlevel);
    429 
     355   
     356    // HACK: shader stuff for presentation
     357    /*Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     358    mSceneMgr->setAmbientLight(ColourValue(0.4,0.4,0.4));
     359    Ogre::Light* dirlight = mSceneMgr->createLight("Light1");
     360
     361    dirlight->setType(Ogre::Light::LT_DIRECTIONAL);
     362    dirlight->setDirection(Vector3( 0, 1, 5 ));
     363    dirlight->setDiffuseColour(ColourValue(0.6, 0.6, 0.4));
     364    dirlight->setSpecularColour(ColourValue(1.0, 1.0, 1.0));*/
     365   
    430366    return true;
    431367  }
     
    453389    // Contains the times of recently fired events
    454390    // eventTimes[4] is the list for the times required for the fps counter
    455     std::deque<unsigned long> eventTimes[4];
     391    std::deque<unsigned long> eventTimes[3];
    456392    // Clear event times
    457     for (int i = 0; i < 4; ++i)
     393    for (int i = 0; i < 3; ++i)
    458394      eventTimes[i].clear();
    459     // fill the fps time list with zeros
    460     for (int i = 0; i < 50; i++)
    461       eventTimes[3].push_back(0);
    462395
    463396    // use the ogre timer class to measure time.
     
    466399    timer_->reset();
    467400
     401    float renderTime = 0.0f;
     402    float frameTime = 0.0f;
     403    clock_t time = 0;
     404
     405    //Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     406    //Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     407   
     408    //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom");
     409    //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur");
     410
    468411    COUT(3) << "Orxonox: Starting the main loop." << std::endl;
    469           while (!bAbort_)
    470           {
    471                   // Pump messages in all registered RenderWindows
    472       // This calls the WindowEventListener objects.
    473       Ogre::WindowEventUtilities::messagePump();
    474 
     412    while (!bAbort_)
     413    {
    475414      // get current time
    476415      unsigned long now = timer_->getMilliseconds();
    477       eventTimes[3].push_back(now);
    478       eventTimes[3].erase(eventTimes[3].begin());
    479416
    480417      // create an event to pass to the frameStarted method in ogre
     
    482419      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
    483420      evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]);
     421      frameTime += evt.timeSinceLastFrame;
    484422
    485423      // show the current time in the HUD
    486 //      orxonoxHUD_->setTime((int)now, 0);
    487 //      orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber());
    488       if (eventTimes[3].back() - eventTimes[3].front() != 0)
    489 //        orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front())));
    490 
    491       // Iterate through all Tickables and call their tick(dt) function
     424      // HUD::getSingleton().setTime(now);
     425      if (mode_ != DEDICATED && frameTime > 0.4f)
     426      {
     427        HUD::getSingleton().setRenderTimeRatio(renderTime / frameTime);
     428        frameTime = 0.0f;
     429        renderTime = 0.0f;
     430      }
     431
     432      // Call those objects that need the real time
     433      for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
     434        it->tick((float)evt.timeSinceLastFrame);
     435      // Call the scene objects
    492436      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    493437        it->tick((float)evt.timeSinceLastFrame * this->timefactor_);
    494       // Iterate through all TickableReals and call their tick(dt) function
    495       for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
    496         it->tick((float)evt.timeSinceLastFrame);
    497       orxonoxConsole_->tick((float)evt.timeSinceLastFrame);
    498438
    499439      // don't forget to call _fireFrameStarted in ogre to make sure
     
    501441      ogreRoot._fireFrameStarted(evt);
    502442
    503       // server still renders at the moment
    504       //if (mode_ != SERVER)
    505       ogreRoot._updateAllRenderTargets(); // only render in non-server mode
    506 
    507443      // get current time
    508444      now = timer_->getMilliseconds();
     445      calculateEventTime(now, eventTimes[2]);
     446
     447      if (mode_ != DEDICATED)
     448      {
     449        // Pump messages in all registered RenderWindows
     450        // This calls the WindowEventListener objects.
     451        Ogre::WindowEventUtilities::messagePump();
     452
     453        // render
     454        ogreRoot._updateAllRenderTargets();
     455      }
     456
     457      // get current time
     458      now = timer_->getMilliseconds();
    509459
    510460      // create an event to pass to the frameEnded method in ogre
    511461      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
    512       evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[2]);
     462      renderTime += calculateEventTime(now, eventTimes[2]);
    513463
    514464      // again, just to be sure ogre works fine
    515465      ogreRoot._fireFrameEnded(evt);
    516           }
    517 
    518     if(mode_==CLIENT)
     466      //msleep(200);
     467    }
     468
     469    if (mode_ == CLIENT)
    519470      network::Client::getSingleton()->closeConnection();
    520     else if(mode_==SERVER)
     471    else if (mode_ == SERVER)
    521472      server_g->close();
     473
    522474    return true;
    523475  }
     
    560512    return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);
    561513  }
    562 
    563   /**
    564    * Static function that shows the console in game mode.
    565    */
    566   void Orxonox::activateConsole()
    567   {
    568     // currently, the console shows itself when feeded with input.
    569     InputManager::setInputState(InputManager::IS_CONSOLE);
    570   }
    571514}
Note: See TracChangeset for help on using the changeset viewer.