Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1324


Ignore:
Timestamp:
May 19, 2008, 2:58:22 PM (16 years ago)
Author:
landauf
Message:

Added a command-history to the console. you can scroll through all previously entered commands by pressing [up] key.
The history is stored in orxonox.ini in the section [Shell]. You can configure the maximal amount of stored commands (default: 100).
This allows you to use the history after orxonox was restarted.
The history uses a cyclic vector (with the configured size), meaning the newest command will overwrite the oldest entry (if the maximal size was reached).

additionally I fixed some bugs in ConfigValueContainer and added a mod-function to Math.h, that does basically the same as %, but without returning a negative value in case of a negative input.

-1 % 10 = -1
-11 % 10 = -1

mod(-1, 10) = 9
mod(-11, 10) = 9

Location:
code/branches/console/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/ConfigValueContainer.cc

    r1321 r1324  
    107107        if (this->bIsVector_)
    108108        {
    109             return this->callFunctionWithIndex(&ConfigValueContainer::set, input.getString());
     109            return this->callFunctionWithIndex(&ConfigValueContainer::set, input.toString());
    110110        }
    111111        else
     
    113113            if (this->tset(input))
    114114            {
    115                 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input.getString(), this->value_.isA(MT_string));
     115                ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input.toString(), this->value_.isA(MT_string));
    116116                return true;
    117117            }
     
    132132            if (this->tset(index, input))
    133133            {
    134                 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.getString(), this->value_.isA(MT_string));
     134                ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.toString(), this->value_.isA(MT_string));
    135135                return true;
    136136            }
     
    152152        if (this->bIsVector_)
    153153        {
    154             return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.getString());
     154            return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.toString());
    155155        }
    156156        else
     
    160160            {
    161161                this->value_ = temp;
    162 
    163162                if (this->identifier_)
    164163                    this->identifier_->updateConfigValues();
     
    191190                {
    192191                    this->valueVector_.push_back(MultiTypeMath());
    193                     ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string));
    194192                }
    195193            }
    196194
    197             MultiTypeMath temp = this->valueVector_[index];
     195            MultiTypeMath temp = this->value_;
    198196            if (temp.assimilate(input))
    199197            {
  • code/branches/console/src/core/ConfigValueContainer.h

    r1321 r1324  
    9090            }
    9191
     92            template <typename T>
     93            inline void setVectorType(const std::vector<T>& value)
     94            {
     95                this->value_ = T();
     96            }
     97
    9298            inline const std::string& getName() const
    9399                { return this->varname_; }
  • code/branches/console/src/core/ConfigValueIncludes.h

    r1062 r1324  
    6969            temp.push_back(MultiTypeMath(defvalue[i])); \
    7070        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \
     71        container##varname->setVectorType(varname); \
    7172        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
    7273    } \
  • code/branches/console/src/core/Shell.cc

    r1322 r1324  
    8080        SetConfigValue(maxHistoryLength_, 100);
    8181        SetConfigValue(historyOffset_, 0);
    82         SetConfigValueVector(commandHistory_, std::vector<std::string>());
    83 
    84 std::cout << "gaga1: " << this->commandHistory_[this->historyOffset_] << std::endl;
     82        SetConfigValueVector(commandHistory_, std::vector<std::string>(1, ""));
    8583
    8684        if (this->historyOffset_ >= this->maxHistoryLength_)
     
    9391            ModifyConfigValue(commandHistory_, remove, index);
    9492        }
    95 
    96 std::cout << "gaga2: " << this->commandHistory_[this->historyOffset_] << std::endl;
    9793    }
    9894
     
    163159    void Shell::addToHistory(const std::string& command)
    164160    {
    165 std::cout << "command: " << command << std::endl;
    166 std::cout << "offset: " << this->historyOffset_ << std::endl;
    167161        ModifyConfigValue(commandHistory_, set, this->historyOffset_, command);
    168 //        this->commandHistory_[this->historyOffset_] = command;
    169162        this->historyPosition_ = 0;
    170 std::cout << "gaga3: " << this->commandHistory_[this->historyOffset_] << std::endl;
    171163        ModifyConfigValue(historyOffset_, set, (this->historyOffset_ + 1) % this->maxHistoryLength_);
    172 std::cout << "offset new: " << this->historyOffset_ << std::endl;
    173164    }
    174165
    175166    std::string Shell::getFromHistory() const
    176167    {
    177         return this->commandHistory_[(this->historyOffset_ - this->historyPosition_) % this->maxHistoryLength_];
     168        unsigned int index = mod(((int)this->historyOffset_) - ((int)this->historyPosition_), this->maxHistoryLength_);
     169        if (index < this->commandHistory_.size() && this->historyPosition_ != 0)
     170            return this->commandHistory_[index];
     171        else
     172            return "";
    178173    }
    179174
     
    219214    void Shell::execute()
    220215    {
    221 //        this->addToHistory(this->inputBuffer_.get());
     216        this->addToHistory(this->inputBuffer_.get());
    222217        this->addLine(this->inputBuffer_.get(), 0);
    223218
     
    252247    {
    253248        this->inputBuffer_.clear();
     249        this->historyPosition_ = 0;
    254250        SHELL_UPDATE_LISTENERS(inputChanged);
    255251        SHELL_UPDATE_LISTENERS(cursorChanged);
     
    282278    void Shell::history_up()
    283279    {
    284         if (this->historyPosition_ < (this->commandHistory_.size() - 1))
     280        if (this->historyPosition_ < this->commandHistory_.size())
    285281        {
    286282            this->historyPosition_++;
  • code/branches/console/src/util/Math.h

    r1062 r1324  
    121121
    122122template <typename T>
     123inline int mod(T x, int max)
     124{
     125    if (x >= 0)
     126        return (x % max);
     127    else
     128        return ((x % max) + max);
     129}
     130
     131template <typename T>
    123132T interpolate(float time, const T& start, const T& end)
    124133{
Note: See TracChangeset for help on using the changeset viewer.