Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2008, 5:30:11 AM (17 years ago)
Author:
landauf
Message:

merged console branch into network branch

after several heavy troubles it compiles, but there is still a bug I couldn't fix: orxonox crashes as soon as one presses a key after opening the console… maybe someone else sees the problem?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/orxonox/Orxonox.cc

    r1443 r1446  
    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"
    7772
    7873// FIXME: is this really file scope?
     
    8378namespace orxonox
    8479{
    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);
     80  SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress);
     81  SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false);
     82  SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0);
    15283
    15384  /**
     
    16596    // turn on frame smoothing by setting a value different from 0
    16697    frameSmoothingTime_(0.0f),
    167     orxonoxConsole_(0),
    16898    orxonoxHUD_(0),
    16999    bAbort_(false),
     
    351281    COUT(3) << "Orxonox: Loading HUD..." << std::endl;
    352282    orxonoxHUD_ = &HUD::getSingleton();
    353 
    354     COUT(3) << "Orxonox: Loading Console..." << std::endl;
    355     InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));
    356     /*
    357     Testconsole* console = new Testconsole(ib);
    358     ib->registerListener(console, &Testconsole::listen, true);
    359     ib->registerListener(console, &Testconsole::execute, '\r', false);
    360     ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);
    361     ib->registerListener(console, &Testconsole::clear, '�', true);
    362     ib->registerListener(console, &Testconsole::removeLast, '\b', true);
    363     ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
    364     */
    365     orxonoxConsole_ = new InGameConsole(ib);
    366     ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);
    367     ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);
    368     ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);
    369     //ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);
    370     ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);
    371     ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);
    372 
    373283    return true;
    374284  }
     
    495405        renderTime = 0.0f;
    496406      }
    497      
     407
    498408      // Call those objects that need the real time
    499409      for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
     
    502412      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    503413        it->tick((float)evt.timeSinceLastFrame * this->timefactor_);
    504       // TODO: currently a hack. Somehow the console doesn't work with OrxonoxClass
    505       orxonoxConsole_->tick((float)evt.timeSinceLastFrame);
    506414
    507415      // don't forget to call _fireFrameStarted in ogre to make sure
     
    571479    return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);
    572480  }
    573 
    574   /**
    575    * Static function that shows the console in game mode.
    576    */
    577   void Orxonox::activateConsole()
    578   {
    579     // currently, the console shows itself when feeded with input.
    580     InputManager::setInputState(InputManager::IS_CONSOLE);
    581   }
    582481}
Note: See TracChangeset for help on using the changeset viewer.