Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 19, 2008, 2:33:09 AM (17 years ago)
Author:
landauf
Message:

The InGameConsole is now using the new Shell. There's a clear separation between the two classes: InGameConsole implements all graphical parts of the console (and has a tick), while Shell handles the internal actions (like listening on input and output changes). That's why InGameConsole has no longer it's own InputBuffer and doesn't care about command-executing or anything else.

There are currently three new features:

  • Every output through COUT(level) is now visible in the InGameConsole, provided the configured output-level for the shell matches. default: 1 (only forced output and errors)
  • The cursor in the input-line is movable with the left and right arrow keys (home and end works too)
  • You can scroll through all output-lines by pressing page up and page down

There's another feature to come, providing a command history, accessible with up and down arrow keys, but I couldn't finish it yet, because there's still a bug, causing Orxonox to scroll through the entire memory - that's maybe a bit too much history ;)

Location:
code/branches/console/src/core
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/InputBuffer.h

    r1313 r1322  
    6262            InputBuffer();
    6363            InputBuffer(const std::string allowedChars);
     64
     65            inline void setKeyboard(OIS::Keyboard* keyboard)
     66                { this->keyboard_ = keyboard; }
    6467
    6568            template <class T>
  • code/branches/console/src/core/InputHandler.cc

    r1313 r1322  
    3939#include "InputEvent.h"
    4040#include "InputManager.h"
     41#include "CommandExecutor.h"
    4142
    4243namespace orxonox
     
    8990    {
    9091      InputManager::getSingleton().setInputMode(IM_KEYBOARD);
     92      CommandExecutor::execute("openConsole");
    9193    }
    9294    else
  • code/branches/console/src/core/InputManager.cc

    r1089 r1322  
    105105        // create a keyboard. If none are available the exception is caught.
    106106        keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
    107         COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl;
     107        COUT(ORX_DEBUG) << "*** InputManager: Created OIS keyboard" << std::endl;
     108
     109        if (this->handlerBuffer_)
     110            this->handlerBuffer_->setKeyboard(this->keyboard_);
    108111
    109112        // create a mouse. If none are available the exception is caught.
    110113        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
    111         COUT(ORX_DEBUG) << "*** InputManager: Created OIS keyboard" << std::endl;
     114        COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl;
    112115
    113116        // Set mouse region
  • code/branches/console/src/core/OutputBuffer.cc

    r1313 r1322  
    4949    }
    5050
     51    OutputBuffer& OutputBuffer::operator<<(std::ostream& (*manipulator)(std::ostream&))
     52    {
     53                this->stream_ << manipulator;
     54                this->callListeners();
     55                return *this;
     56    }
     57
     58    OutputBuffer& OutputBuffer::operator<<(std::ios& (*manipulator)(std::ios&))
     59    {
     60                this->stream_ << manipulator;
     61                this->callListeners();
     62                return *this;
     63    }
     64
     65    OutputBuffer& OutputBuffer::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
     66    {
     67                this->stream_ << manipulator;
     68                this->callListeners();
     69                return *this;
     70    }
     71
    5172    bool OutputBuffer::getLine(std::string* output)
    5273    {
     
    5980
    6081        if (eof)
     82        {
    6183            this->stream_.flush();
     84            this->stream_.clear();
     85        }
    6286
    63         // Return true if this was a whole new line, ended by \n
    6487        return (!eof);
    6588    }
  • code/branches/console/src/core/OutputBuffer.h

    r1313 r1322  
    3232#include <list>
    3333#include <sstream>
     34#include <iostream>
    3435
    3536#include "CorePrereqs.h"
     
    5758                return *this;
    5859            }
     60
     61            OutputBuffer& operator<<(std::ostream& (*manipulator)(std::ostream&));
     62            OutputBuffer& operator<<(std::ios& (*manipulator)(std::ios&));
     63            OutputBuffer& operator<<(std::ios_base& (*manipulator)(std::ios_base&));
    5964
    6065            template <class T>
     
    8893            void unregisterListener(OutputBufferListener* listener);
    8994
    90             inline operator std::stringstream&()
    91             {
    92                 return this->stream_;
    93             }
    94 
    9595        private:
    9696            void callListeners();
  • code/branches/console/src/core/OutputHandler.cc

    r1313 r1322  
    124124
    125125        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    126             manipulator(Shell::getInstance().getOutputBuffer());
     126            Shell::getInstance().getOutputBuffer() << manipulator;
    127127
    128128        return *this;
     
    146146
    147147        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    148             manipulator(Shell::getInstance().getOutputBuffer());
     148            Shell::getInstance().getOutputBuffer() << manipulator;
    149149
    150150        return *this;
     
    168168
    169169        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    170             manipulator(Shell::getInstance().getOutputBuffer());
     170            Shell::getInstance().getOutputBuffer() << manipulator;
    171171
    172172        return *this;
  • code/branches/console/src/core/Shell.cc

    r1317 r1322  
    4646        this->historyPosition_ = 0;
    4747        this->historyOffset_ = 0;
     48        this->finishedLastLine_ = true;
    4849
    4950        this->clearLines();
    50 /*
     51
    5152        this->inputBuffer_.registerListener(this, &Shell::inputChanged, true);
    5253        this->inputBuffer_.registerListener(this, &Shell::execute, '\r', false);
     
    6364        this->inputBuffer_.registerListener(this, &Shell::scroll_up, OIS::KC_PGUP);
    6465        this->inputBuffer_.registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN);
    65 */
     66
     67        this->outputBuffer_.registerListener(this);
     68
    6669        this->setConfigValues();
    6770    }
     
    7780        SetConfigValue(maxHistoryLength_, 100);
    7881        SetConfigValue(historyOffset_, 0);
    79         SetConfigValueVector(commandHistory_, std::vector<std::string>(1, ""));
     82        SetConfigValueVector(commandHistory_, std::vector<std::string>());
     83
     84std::cout << "gaga1: " << this->commandHistory_[this->historyOffset_] << std::endl;
    8085
    8186        if (this->historyOffset_ >= this->maxHistoryLength_)
     
    8893            ModifyConfigValue(commandHistory_, remove, index);
    8994        }
     95
     96std::cout << "gaga2: " << this->commandHistory_[this->historyOffset_] << std::endl;
    9097    }
    9198
     
    120127    void Shell::addLine(const std::string& line, unsigned int level)
    121128    {
    122         if ((*this->lines_.begin()) != "")
    123         {
    124             orxonox::OutputHandler::getOutStream().setOutputLevel(level) << std::endl;
    125         }
    126         orxonox::OutputHandler::getOutStream().setOutputLevel(level) << line << std::endl;
     129        int original_level = OutputHandler::getOutStream().getOutputLevel();
     130        OutputHandler::getOutStream().setOutputLevel(level);
     131
     132        if (!this->finishedLastLine_)
     133            this->outputBuffer_ << std::endl;
     134
     135        this->outputBuffer_ << line << std::endl;
     136        OutputHandler::getOutStream().setOutputLevel(original_level);
    127137    }
    128138
     
    130140    {
    131141        this->lines_.clear();
    132         this->lines_.insert(this->lines_.begin(), "");
    133142        this->scrollIterator_ = this->lines_.begin();
    134143
    135144        this->scrollPosition_ = 0;
     145        this->finishedLastLine_ = true;
    136146
    137147        SHELL_UPDATE_LISTENERS(linesChanged);
     
    141151    {
    142152        if (this->scrollPosition_)
    143         {
    144153            return this->scrollIterator_;
    145         }
    146154        else
    147         {
    148             if ((*this->lines_.begin()) == "" && this->lines_.size() > 1)
    149                 return (++this->lines_.begin());
    150             else
    151                 return this->lines_.begin();
    152         }
     155            return this->lines_.begin();
    153156    }
    154157
     
    160163    void Shell::addToHistory(const std::string& command)
    161164    {
    162         this->historyOffset_ = (this->historyOffset_ + 1) % this->maxHistoryLength_;
     165std::cout << "command: " << command << std::endl;
     166std::cout << "offset: " << this->historyOffset_ << std::endl;
    163167        ModifyConfigValue(commandHistory_, set, this->historyOffset_, command);
    164         this->commandHistory_[this->historyOffset_] = command;
     168//        this->commandHistory_[this->historyOffset_] = command;
    165169        this->historyPosition_ = 0;
     170std::cout << "gaga3: " << this->commandHistory_[this->historyOffset_] << std::endl;
     171        ModifyConfigValue(historyOffset_, set, (this->historyOffset_ + 1) % this->maxHistoryLength_);
     172std::cout << "offset new: " << this->historyOffset_ << std::endl;
    166173    }
    167174
     
    174181    {
    175182        std::string output;
    176         while (this->outputBuffer_.getLine(&output))
    177         {
    178             bool newline = false;
    179             if ((*this->lines_.begin()) == "")
    180                 newline = true;
    181 
    182             (*this->lines_.begin()) += output;
    183 
    184             SHELL_UPDATE_LISTENERS(onlyLastLineChanged);
    185 
    186             this->lines_.insert(this->lines_.begin(), "");
    187 
    188             if (this->scrollPosition_)
    189                 this->scrollPosition_++;
    190             else
    191                 this->scrollIterator_ = this->lines_.begin();
    192 
    193             if (newline)
     183        bool newline;
     184        do
     185        {
     186            newline = this->outputBuffer_.getLine(&output);
     187
     188            if (!newline && output == "")
     189                break;
     190
     191            if (this->finishedLastLine_)
    194192            {
     193                this->lines_.insert(this->lines_.begin(), output);
     194
     195                if (this->scrollPosition_)
     196                    this->scrollPosition_++;
     197                else
     198                    this->scrollIterator_ = this->lines_.begin();
     199
     200                this->finishedLastLine_ = newline;
    195201                SHELL_UPDATE_LISTENERS(lineAdded);
    196202            }
    197         }
    198 
    199         (*this->lines_.begin()) += output;
    200         SHELL_UPDATE_LISTENERS(onlyLastLineChanged);
     203            else
     204            {
     205                (*this->lines_.begin()) += output;
     206                this->finishedLastLine_ = newline;
     207                SHELL_UPDATE_LISTENERS(onlyLastLineChanged);
     208            }
     209
     210        } while (newline);
    201211    }
    202212
     
    209219    void Shell::execute()
    210220    {
    211         if (CommandExecutor::execute(this->inputBuffer_.get()))
    212             this->addLine(this->inputBuffer_.get(), 0);
    213         else
     221//        this->addToHistory(this->inputBuffer_.get());
     222        this->addLine(this->inputBuffer_.get(), 0);
     223
     224        if (!CommandExecutor::execute(this->inputBuffer_.get()))
    214225            this->addLine("Error: Can't execute \"" + this->inputBuffer_.get() + "\".", 1);
    215226
     
    282293        if (this->historyPosition_ > 0)
    283294        {
    284             this->historyPosition_++;
     295            this->historyPosition_--;
    285296            this->inputBuffer_.set(this->getFromHistory());
    286297        }
  • code/branches/console/src/core/Shell.h

    r1317 r1322  
    118118            InputBuffer inputBuffer_;
    119119            OutputBuffer outputBuffer_;
     120            bool finishedLastLine_;
    120121            std::list<std::string> lines_;
    121122            std::list<std::string>::const_iterator scrollIterator_;
Note: See TracChangeset for help on using the changeset viewer.