Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1322


Ignore:
Timestamp:
May 19, 2008, 2:33:09 AM (16 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
Files:
10 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_;
  • code/branches/console/src/orxonox/console/InGameConsole.cc

    r1317 r1322  
    4242#include "core/ConfigValueIncludes.h"
    4343#include "core/ConsoleCommand.h"
     44#include "core/InputManager.h"
    4445#include "GraphicsEngine.h"
    4546
     
    4849namespace orxonox
    4950{
     51    ConsoleCommand(InGameConsole, openConsole, AccessLevel::None, true);
     52    ConsoleCommand(InGameConsole, closeConsole, AccessLevel::None, true);
     53
    5054    using namespace Ogre;
    5155
    5256    float InGameConsole::REL_WIDTH = 0.8;
    5357    float InGameConsole::REL_HEIGHT = 0.4;
    54     float InGameConsole::BLINK = 0.25;
     58    float InGameConsole::BLINK = 0.5;
    5559
    5660    /**
     
    6367        this->active_ = false;
    6468        this->cursor_ = 0.0;
     69        this->cursorSymbol_ = '|';
    6570
    6671        this->init();
    6772        this->setConfigValues();
     73
     74        Shell::getInstance().registerListener(this);
    6875    }
    6976
     
    95102        SetConfigValue(REL_WIDTH, 0.8);
    96103        SetConfigValue(REL_HEIGHT, 0.4);
    97         SetConfigValue(BLINK, 0.25);
     104        SetConfigValue(BLINK, 0.5);
    98105    }
    99106
     
    104111    {
    105112        std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();
    106         for (int i = 1; i < LINES && it != Shell::getInstance().getEndIterator(); i++)
    107         {
    108             this->consoleOverlayTextAreas_[i]->setCaption(*it);
    109             ++it;
     113        for (int i = 1; i < LINES; i++)
     114        {
     115            if (it != Shell::getInstance().getEndIterator())
     116            {
     117                this->print(*it, i);
     118                ++it;
     119            }
     120            else
     121            {
     122                this->print("", i);
     123            }
    110124        }
    111125    }
     
    117131    {
    118132        if (LINES > 1)
    119             this->consoleOverlayTextAreas_[1]->setCaption(*Shell::getInstance().getNewestLineIterator());
     133            this->print(*Shell::getInstance().getNewestLineIterator(), 1);
    120134    }
    121135
     
    125139    void InGameConsole::lineAdded()
    126140    {
    127         for (int i = LINES - 1; i > 1; i--)
    128             this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
    129 
    130         if (LINES > 1)
    131             this->consoleOverlayTextAreas_[1]->setCaption(*Shell::getInstance().getNewestLineIterator());
     141        this->linesChanged();
    132142    }
    133143
     
    138148    {
    139149        if (LINES > 0)
    140             this->consoleOverlayTextAreas_[0]->setCaption(Shell::getInstance().getInput());
     150            this->print(Shell::getInstance().getInput(), 0);
    141151    }
    142152
     
    147157    {
    148158        std::string input = Shell::getInstance().getInput();
    149         input.insert(Shell::getInstance().getCursorPosition(), 1, '|');
     159        input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_);
    150160        if (LINES > 0)
    151             this->consoleOverlayTextAreas_[0]->setCaption(input);
     161            this->print(input, 0);
    152162    }
    153163
     
    158168    {
    159169        this->deactivate();
    160         CommandExecutor::execute("set InputMode 2");
     170        InputManager::getSingleton().setInputMode(IM_INGAME);
    161171    }
    162172
     
    266276        if (this->cursor_ >= 2 * InGameConsole::BLINK)
    267277            this->cursor_ = 0;
    268 //        print(convert2UTF(this->ib_->get()));
     278
     279        if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|')
     280        {
     281            this->cursorSymbol_ = ' ';
     282            this->cursorChanged();
     283        }
     284        else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ')
     285        {
     286            this->cursorSymbol_ = '|';
     287            this->cursorChanged();
     288        }
    269289
    270290        // this creates a flickering effect
     
    296316    void InGameConsole::activate()
    297317    {
     318        this->linesChanged();
     319
    298320        this->consoleOverlay_->show();
    299321        // just in case window size has changed...
     
    334356        @param s String to be printed
    335357    */
    336     void InGameConsole::print(Ogre::UTFString s)
    337     {
    338         if (this->cursor_ > InGameConsole::BLINK)
    339             this->consoleOverlayTextAreas_[0]->setCaption(">" + s);
    340         else
    341             this->consoleOverlayTextAreas_[0]->setCaption(">" + s + "_");
    342     }
    343 
    344     /**
    345         @brief Shifts all lines up and clears the bottom line.
    346     */
    347     void InGameConsole::newline()
    348     {
    349         Ogre::UTFString line;
    350         for (int i = LINES - 1; i >= 1; i--)
    351         {
    352             line = this->consoleOverlayTextAreas_[i - 1]->getCaption();
    353             // don't copy the cursor...
    354             int l = line.length();
    355             if (!line.empty() && line.substr(l-1) == "_")
    356                 line.erase(l-1);
    357             this->consoleOverlayTextAreas_[i]->setCaption(line);
    358         }
    359         this->consoleOverlayTextAreas_[0]->setCaption(">");
     358    void InGameConsole::print(const std::string& text, int index)
     359    {
     360        if (LINES > index)
     361            this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(text));
    360362    }
    361363
  • code/branches/console/src/orxonox/console/InGameConsole.h

    r1317 r1322  
    7171            void init();
    7272            void resize();
    73             void print(Ogre::UTFString s);
    74             void newline();
     73            void print(const std::string& text, int index);
    7574            static Ogre::UTFString convert2UTF(std::string s);
    7675
     
    8483            float scrollTimer_;
    8584            float cursor_;
     85            char cursorSymbol_;
    8686            bool active_;
    8787            Ogre::OverlayManager* om_;
Note: See TracChangeset for help on using the changeset viewer.