Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 955 for code


Ignore:
Timestamp:
Mar 30, 2008, 12:12:18 AM (17 years ago)
Author:
landauf
Message:
  • added input buffer: this class captures key-input (at the moment it's using OIS directly, later it will use the InputHandler) and writes it into a string - other classes can listen to changes and can read and modify the string.
  • fixed some bugs in CommandExecutor
  • fixed a small bug (or changed a questionable feature) in Functor
Location:
code/branches/core2/src/orxonox
Files:
2 added
7 edited

Legend:

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

    r874 r955  
    8686#include "objects/test3.h"
    8787
     88#include "core/CommandExecutor.h"
     89#include "core/InputBuffer.h"
     90
    8891#include "Orxonox.h"
    8992
    9093namespace orxonox
    9194{
     95    class Testlistener : public InputBufferListener
     96    {
     97        public:
     98            Testlistener(InputBuffer* ib) : ib_(ib) {}
     99            void listen() const
     100            {
     101                std::cout << "> -->" << this->ib_->get() << "<--" << std::endl;
     102            }
     103            void execute() const
     104            {
     105std::cout << "### EXECUTE!" << std::endl;
     106                CommandExecutor::execute(this->ib_->get());
     107                this->ib_->clear();
     108            }
     109            void hintandcomplete() const
     110            {
     111std::cout << "### HINT!" << std::endl;
     112                std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl;
     113                this->ib_->set(CommandExecutor::complete(this->ib_->get()));
     114            }
     115            void clear() const
     116            {
     117std::cout << "### CLEAR!" << std::endl;
     118                this->ib_->clear();
     119            }
     120            void removeLast() const
     121            {
     122std::cout << "### REMOVELAST!" << std::endl;
     123                this->ib_->removeLast();
     124            }
     125
     126        private:
     127            InputBuffer* ib_;
     128    };
     129
    92130   // put this in a seperate Class or solve the problem in another fashion
    93131  class OrxListener : public Ogre::FrameListener
     
    11461184        std::cout << "2\n";
    11471185*/
     1186        InputBuffer* ib = new InputBuffer(this->getKeyboard());
     1187        Testlistener* testlistener = new Testlistener(ib);
     1188        ib->registerListener(testlistener, &Testlistener::listen, true);
     1189        ib->registerListener(testlistener, &Testlistener::execute, '\r', false);
     1190        ib->registerListener(testlistener, &Testlistener::hintandcomplete, '\t', true);
     1191        ib->registerListener(testlistener, &Testlistener::clear, '§', true);
     1192        ib->registerListener(testlistener, &Testlistener::removeLast, '\b', true);
     1193
    11481194    startRenderLoop();
    11491195  }
     
    13641410    try
    13651411    {
    1366       keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false));
     1412      keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, true));
    13671413      mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true));
    13681414    }
  • code/branches/core2/src/orxonox/core/CMakeLists.txt

    r947 r955  
    2020  NamespaceNode.cc
    2121  CommandExecutor.cc
     22  InputBuffer.cc
    2223)
    2324
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r953 r955  
    4949    // CommandEvaluation //
    5050    ///////////////////////
     51    CommandEvaluation::CommandEvaluation()
     52    {
     53        this->processedCommand_ = "";
     54        this->additionalParameter_ = "";
     55
     56        this->functionclass_ = 0;
     57        this->configvalueclass_ = 0;
     58        this->shortcut_ = 0;
     59        this->function_ = 0;
     60        this->configvalue_ = 0;
     61        this->key_ = 0;
     62
     63        this->errorMessage_ = "";
     64        this->state_ = CS_Uninitialized;
     65    }
     66
    5167    KeybindMode CommandEvaluation::getKeybindMode()
    5268    {
     
    156172    bool CommandExecutor::execute(const std::string& command)
    157173    {
    158         if (CommandExecutor::getEvaluation().processedCommand_ != command)
     174        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    159175            CommandExecutor::parse(command);
    160176
     
    169185        switch (evaluation.state_)
    170186        {
     187            case CS_Uninitialized:
     188                break;
    171189            case CS_Empty:
    172190                break;
     
    227245    std::string CommandExecutor::complete(const std::string& command)
    228246    {
    229         if (CommandExecutor::getEvaluation().processedCommand_ != command)
     247        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    230248            CommandExecutor::parse(command);
    231249
     
    246264        switch (evaluation.state_)
    247265        {
     266            case CS_Uninitialized:
     267                break;
    248268            case CS_Empty:
    249                 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(temp));
     269                return (CommandExecutor::getCommonBegin(temp));
    250270                break;
    251271            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
     
    258278                break;
    259279            case CS_Function:
    260                 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_));
     280                if (tokens.size() >= 1)
     281                    return tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_);
    261282                break;
    262283            case CS_Function_Params:
     
    267288                break;
    268289            case CS_ConfigValueClass:
    269                 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_));
     290                if (tokens.size() >= 1)
     291                    return tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_);
    270292                break;
    271293            case CS_ConfigValue:
    272                 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_));
     294                if (tokens.size() >= 2)
     295                    return tokens[0] + " " + tokens[1] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_);
    273296                break;
    274297            case CS_ConfigValueType:
     
    279302                break;
    280303            case CS_KeybindKey:
    281                 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_));
     304                if (tokens.size() >= 1)
     305                    return tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_);
    282306                break;
    283307            case CS_KeybindCommand:
     
    296320    std::string CommandExecutor::hint(const std::string& command)
    297321    {
    298         if (CommandExecutor::getEvaluation().processedCommand_ != command)
     322        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    299323            CommandExecutor::parse(command);
    300324
     
    308332        switch (evaluation.state_)
    309333        {
     334            case CS_Uninitialized:
     335                break;
    310336            case CS_Empty:
    311337                return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_));
     
    358384                break;
    359385            case CS_Error:
    360                 return "Error";
     386                return CommandExecutor::getEvaluation().errorMessage_;
    361387                break;
    362388        }
     
    381407        switch (CommandExecutor::getEvaluation().state_)
    382408        {
     409            case CS_Uninitialized:
     410                // Impossible
     411                break;
    383412            case CS_Empty:
    384413                if (CommandExecutor::argumentsGiven() == 0)
     
    635664                        {
    636665                            CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
    637                             if (CommandExecutor::getEvaluation().configvalueclass_ != 0)
     666                            if (CommandExecutor::getEvaluation().configvalue_ != 0)
    638667                            {
    639668                                // There is a perfect match: Add a whitespace and continue parsing
     
    791820            if ((*it).second->hasConsoleCommands())
    792821            {
    793                 if ((*it).first.find(getLowercase(fragment)) == 0)
     822                if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    794823                {
    795824                    CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(&(*it).first);
     
    805834        for (std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
    806835        {
    807             if ((*it).first.find(getLowercase(fragment)) == 0)
     836            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    808837            {
    809838                CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(&(*it).first);
     
    818847        for (std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
    819848        {
    820             if ((*it).first.find(getLowercase(fragment)) == 0)
     849            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    821850            {
    822851                CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(&(*it).first);
     
    833862            if ((*it).second->hasConfigValues())
    834863            {
    835                 if ((*it).first.find(getLowercase(fragment)) == 0)
     864                if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    836865                {
    837866                    CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(&(*it).first);
     
    847876        for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMapBegin(); it != identifier->getLowercaseConfigValueMapEnd(); ++it)
    848877        {
    849             if ((*it).first.find(getLowercase(fragment)) == 0)
     878            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    850879            {
    851880                CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(&(*it).first);
     
    908937        std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMap().find(getLowercase(name));
    909938        if (it != identifier->getLowercaseConfigValueMapEnd())
     939        {
    910940            return (*it).second;
     941        }
    911942
    912943        return 0;
  • code/branches/core2/src/orxonox/core/CommandExecutor.h

    r953 r955  
    3434
    3535#include "util/SubString.h"
     36#include "util/MultiTypeMath.h"
    3637#include "CorePrereqs.h"
    3738
     
    4243    enum CommandState
    4344    {
     45        CS_Uninitialized,
    4446        CS_Empty,
    4547        CS_FunctionClass_Or_Shortcut_Or_Keyword,
     
    6769    {
    6870        public:
     71            CommandEvaluation();
     72
    6973            KeybindMode getKeybindMode();
    7074            void setAdditionalParameter(const std::string& param);
  • code/branches/core2/src/orxonox/core/Functor.h

    r947 r955  
    5252#define CreateTypeToStringTemplate(type) \
    5353    template <> \
    54     inline std::string typeToString<type>() { return #type; }
     54    inline std::string typeToString<type>() { return #type; } \
     55    template <> \
     56    inline std::string typeToString<type&>() { return #type; } \
     57    template <> \
     58    inline std::string typeToString<const type>() { return #type; } \
     59    template <> \
     60    inline std::string typeToString<const type&>() { return #type; }
    5561
    5662    CreateTypeToStringTemplate(int);
     
    6672    CreateTypeToStringTemplate(long double);
    6773    CreateTypeToStringTemplate(bool);
    68     CreateTypeToStringTemplate(std::string);
    69     CreateTypeToStringTemplate(orxonox::Vector2);
    70     CreateTypeToStringTemplate(orxonox::Vector3);
    71     CreateTypeToStringTemplate(orxonox::Quaternion);
    72     CreateTypeToStringTemplate(orxonox::ColourValue);
    73     CreateTypeToStringTemplate(orxonox::Radian);
    74     CreateTypeToStringTemplate(orxonox::Degree);
    75 
     74    CreateTypeToStringTemplate(Vector2);
     75    CreateTypeToStringTemplate(Vector3);
     76    CreateTypeToStringTemplate(Quaternion);
     77    CreateTypeToStringTemplate(ColourValue);
     78    CreateTypeToStringTemplate(Radian);
     79    CreateTypeToStringTemplate(Degree);
     80
     81    template <> \
     82    inline std::string typeToString<std::string>() { return "string"; } \
     83    template <> \
     84    inline std::string typeToString<std::string&>() { return "string"; } \
     85    template <> \
     86    inline std::string typeToString<const std::string>() { return "string"; } \
     87    template <> \
     88    inline std::string typeToString<const std::string&>() { return "string"; }
    7689
    7790    class _CoreExport Functor
     
    88101            inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; }
    89102
    90             std::string getTypenameParam(unsigned int param) const { return (param > 0 && param <= 5) ? this->typeParam_[param-1] : ""; }
     103            std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; }
    91104            std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; }
    92105
  • code/branches/core2/src/orxonox/core/OutputHandler.h

    r949 r955  
    6161            /** @brief Puts some text on the outstream. @param text The text */
    6262            static inline void log(const std::string& text)
    63                 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text); }
     63                { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); }
    6464
    6565            /** @brief Returns a reference to the logfile. @return The logfile */
  • code/branches/core2/src/orxonox/objects/SpaceShip.cc

    r947 r955  
    5252{
    5353    ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);
     54    ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);
     55    ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);
     56    ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);
    5457
    5558    CreateFactory(SpaceShip);
Note: See TracChangeset for help on using the changeset viewer.