Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2008, 5:30:11 AM (16 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 copied

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/Shell.cc

    r1445 r1446  
    3333#include "CoreSettings.h"
    3434#include "ConsoleCommand.h"
     35#include "InputManager.h"
    3536
    3637#define SHELL_UPDATE_LISTENERS(function) \
     
    5657        this->clearLines();
    5758
    58         this->inputBuffer_.registerListener(this, &Shell::inputChanged, true);
    59         this->inputBuffer_.registerListener(this, &Shell::execute, '\r', false);
    60         this->inputBuffer_.registerListener(this, &Shell::hintandcomplete, '\t', true);
    61         this->inputBuffer_.registerListener(this, &Shell::backspace, '\b', true);
    62         this->inputBuffer_.registerListener(this, &Shell::deletechar, OIS::KC_DELETE);
    63         this->inputBuffer_.registerListener(this, &Shell::exit, (char)27, true);
    64         this->inputBuffer_.registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT);
    65         this->inputBuffer_.registerListener(this, &Shell::cursor_left, OIS::KC_LEFT);
    66         this->inputBuffer_.registerListener(this, &Shell::cursor_end, OIS::KC_END);
    67         this->inputBuffer_.registerListener(this, &Shell::cursor_home, OIS::KC_HOME);
    68         this->inputBuffer_.registerListener(this, &Shell::history_up, OIS::KC_UP);
    69         this->inputBuffer_.registerListener(this, &Shell::history_down, OIS::KC_DOWN);
    70         this->inputBuffer_.registerListener(this, &Shell::scroll_up, OIS::KC_PGUP);
    71         this->inputBuffer_.registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN);
     59        this->inputBuffer_ = 0;
     60        this->setInputBuffer(new InputBuffer());
    7261
    7362        this->outputBuffer_.registerListener(this);
     
    10897    }
    10998
     99    void Shell::setInputBuffer(InputBuffer* buffer)
     100    {
     101        if (this->inputBuffer_)
     102        {
     103            this->inputBuffer_->unregisterListener(this);
     104            delete this->inputBuffer_;
     105        }
     106
     107        this->inputBuffer_ = buffer;
     108        this->inputBuffer_->registerListener(this, &Shell::inputChanged, true);
     109        this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false);
     110        this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true);
     111        this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true);
     112        this->inputBuffer_->registerListener(this, &Shell::deletechar, OIS::KC_DELETE);
     113        this->inputBuffer_->registerListener(this, &Shell::exit, (char)27, true);
     114        this->inputBuffer_->registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT);
     115        this->inputBuffer_->registerListener(this, &Shell::cursor_left, OIS::KC_LEFT);
     116        this->inputBuffer_->registerListener(this, &Shell::cursor_end, OIS::KC_END);
     117        this->inputBuffer_->registerListener(this, &Shell::cursor_home, OIS::KC_HOME);
     118        this->inputBuffer_->registerListener(this, &Shell::history_up, OIS::KC_UP);
     119        this->inputBuffer_->registerListener(this, &Shell::history_down, OIS::KC_DOWN);
     120        this->inputBuffer_->registerListener(this, &Shell::scroll_up, OIS::KC_PGUP);
     121        this->inputBuffer_->registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN);
     122    }
     123
    110124    void Shell::clearShell()
    111125    {
     
    141155    void Shell::setCursorPosition(unsigned int cursor)
    142156    {
    143         this->inputBuffer_.setCursorPosition(cursor);
     157        this->inputBuffer_->setCursorPosition(cursor);
    144158        SHELL_UPDATE_LISTENERS(cursorChanged);
    145159    }
     
    147161    void Shell::setInput(const std::string& input)
    148162    {
    149         this->inputBuffer_.set(input);
     163        this->inputBuffer_->set(input);
    150164        this->inputChanged();
    151165    }
     
    251265    void Shell::execute()
    252266    {
    253         this->addToHistory(this->inputBuffer_.get());
    254         this->addLine(this->inputBuffer_.get(), 0);
    255 
    256         if (!CommandExecutor::execute(this->inputBuffer_.get()))
    257             this->addLine("Error: Can't execute \"" + this->inputBuffer_.get() + "\".", 1);
     267        this->addToHistory(this->inputBuffer_->get());
     268        this->addLine(this->inputBuffer_->get(), 0);
     269
     270        if (!CommandExecutor::execute(this->inputBuffer_->get()))
     271            this->addLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);
    258272
    259273        this->clear();
     
    262276    void Shell::hintandcomplete()
    263277    {
    264         this->inputBuffer_.set(CommandExecutor::complete(this->inputBuffer_.get()));
    265         this->addLine(CommandExecutor::hint(this->inputBuffer_.get()), -1);
     278        this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get()));
     279        this->addLine(CommandExecutor::hint(this->inputBuffer_->get()), -1);
    266280
    267281        this->inputChanged();
     
    270284    void Shell::backspace()
    271285    {
    272         this->inputBuffer_.removeBehindCursor();
     286        this->inputBuffer_->removeBehindCursor();
    273287        SHELL_UPDATE_LISTENERS(inputChanged);
    274288        SHELL_UPDATE_LISTENERS(cursorChanged);
     
    277291    void Shell::deletechar()
    278292    {
    279         this->inputBuffer_.removeAtCursor();
     293        this->inputBuffer_->removeAtCursor();
    280294        SHELL_UPDATE_LISTENERS(inputChanged);
    281295    }
     
    283297    void Shell::clear()
    284298    {
    285         this->inputBuffer_.clear();
     299        this->inputBuffer_->clear();
    286300        this->historyPosition_ = 0;
    287301        SHELL_UPDATE_LISTENERS(inputChanged);
     
    291305    void Shell::cursor_right()
    292306    {
    293         this->inputBuffer_.increaseCursor();
     307        this->inputBuffer_->increaseCursor();
    294308        SHELL_UPDATE_LISTENERS(cursorChanged);
    295309    }
     
    297311    void Shell::cursor_left()
    298312    {
    299         this->inputBuffer_.decreaseCursor();
     313        this->inputBuffer_->decreaseCursor();
    300314        SHELL_UPDATE_LISTENERS(cursorChanged);
    301315    }
     
    303317    void Shell::cursor_end()
    304318    {
    305         this->inputBuffer_.setCursorToEnd();
     319        this->inputBuffer_->setCursorToEnd();
    306320        SHELL_UPDATE_LISTENERS(cursorChanged);
    307321    }
     
    309323    void Shell::cursor_home()
    310324    {
    311         this->inputBuffer_.setCursorToBegin();
     325        this->inputBuffer_->setCursorToBegin();
    312326        SHELL_UPDATE_LISTENERS(cursorChanged);
    313327    }
     
    318332        {
    319333            this->historyPosition_++;
    320             this->inputBuffer_.set(this->getFromHistory());
     334            this->inputBuffer_->set(this->getFromHistory());
    321335        }
    322336    }
     
    327341        {
    328342            this->historyPosition_--;
    329             this->inputBuffer_.set(this->getFromHistory());
     343            this->inputBuffer_->set(this->getFromHistory());
    330344        }
    331345    }
     
    355369    void Shell::exit()
    356370    {
    357         if (this->inputBuffer_.getSize() > 0)
     371        if (this->inputBuffer_->getSize() > 0)
    358372        {
    359373            this->clear();
Note: See TracChangeset for help on using the changeset viewer.