Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 31, 2010, 3:37:40 AM (14 years ago)
Author:
landauf
Message:

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

Location:
code/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/input/Button.cc

    r6536 r7284  
    3939#include "util/StringUtils.h"
    4040#include "util/Debug.h"
    41 #include "core/ConsoleCommand.h"
    42 #include "core/CommandEvaluation.h"
    43 #include "core/CommandExecutor.h"
     41#include "core/command/ConsoleCommand.h"
     42#include "core/command/CommandEvaluation.h"
     43#include "core/command/CommandExecutor.h"
    4444#include "core/ConfigFileManager.h"
    4545
     
    117117        // separate the commands
    118118        SubString commandStrings(bindingString_, "|", SubString::WhiteSpaces, false,
    119             '\\', false, '"', false, '(', ')', false, '\0');
     119            '\\', false, '"', false, '{', '}', false, '\0');
    120120
    121121        for (unsigned int iCommand = 0; iCommand < commandStrings.size(); iCommand++)
     
    124124            {
    125125                SubString tokens(commandStrings[iCommand], " ", SubString::WhiteSpaces, false,
    126                     '\\', false, '"', false, '(', ')', false, '\0');
     126                    '\\', false, '"', false, '{', '}', false, '\0');
    127127
    128128                KeybindMode::Value mode = KeybindMode::None;
     
    175175
    176176                // evaluate the command
    177                 const CommandEvaluation& eval = CommandExecutor::evaluate(commandStr);
    178                 if (!eval.isValid())
     177                CommandEvaluation eval = CommandExecutor::evaluate(commandStr);
     178                if (!eval.isValid() || eval.evaluateParams(true))
    179179                {
    180180                    parseError("Command evaluation of \"" + commandStr + "\"failed.", true);
  • code/trunk/src/libraries/core/input/HalfAxis.cc

    r5781 r7284  
    3434
    3535#include "HalfAxis.h"
    36 #include "core/CommandEvaluation.h"
     36#include "core/command/CommandEvaluation.h"
    3737
    3838namespace orxonox
  • code/trunk/src/libraries/core/input/InputCommands.h

    r6417 r7284  
    3737
    3838#include "InputPrereqs.h"
    39 #include "core/CommandEvaluation.h"
     39#include "core/command/CommandEvaluation.h"
    4040
    4141namespace orxonox
  • code/trunk/src/libraries/core/input/InputManager.cc

    r7266 r7284  
    4747#include "core/CoreIncludes.h"
    4848#include "core/ConfigValueIncludes.h"
    49 #include "core/ConsoleCommand.h"
    5049#include "core/CommandLineParser.h"
    51 #include "core/Functor.h"
    5250#include "core/GraphicsManager.h"
     51#include "core/command/ConsoleCommand.h"
     52#include "core/command/Functor.h"
    5353
    5454#include "InputBuffer.h"
     
    6161{
    6262    SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard");
     63
     64    static const std::string __CC_InputManager_name = "InputManager";
     65    static const std::string __CC_calibrate_name = "calibrate";
     66    static const std::string __CC_reload_name = "reload";
     67
     68    SetConsoleCommand(__CC_InputManager_name, __CC_calibrate_name, &InputManager::calibrate).addShortcut();
     69    SetConsoleCommand(__CC_InputManager_name, __CC_reload_name,    &InputManager::reload   );
    6370
    6471    // Abuse of this source file for the InputHandler
     
    118125        this->updateActiveStates();
    119126
    120         // calibrate console command
    121         this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::calibrate, this), "calibrate"), true);
    122         // reload console command
    123         this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::reload, this), "reload"), false);
     127        ModifyConsoleCommand(__CC_InputManager_name, __CC_calibrate_name).setObject(this);
     128        ModifyConsoleCommand(__CC_InputManager_name, __CC_reload_name).setObject(this);
    124129
    125130        CCOUT(4) << "Construction complete." << std::endl;
     
    287292        if (!(internalState_ & Bad))
    288293            this->destroyDevices();
     294
     295        // Reset console commands
     296        ModifyConsoleCommand(__CC_InputManager_name, __CC_calibrate_name).setObject(0);
     297        ModifyConsoleCommand(__CC_InputManager_name, __CC_reload_name).setObject(0);
    289298
    290299        CCOUT(3) << "Destruction complete." << std::endl;
  • code/trunk/src/libraries/core/input/InputState.cc

    r6746 r7284  
    2828
    2929#include "InputState.h"
    30 #include "core/Functor.h"
     30#include "core/command/Functor.h"
    3131
    3232namespace orxonox
  • code/trunk/src/libraries/core/input/InputState.h

    r6746 r7284  
    150150        void left();
    151151        //! Sets a functor to be called upon activation of the state
    152         void setEnterFunctor(Functor* functor) { this->enterFunctor_ = functor; }
     152        void setEnterFunctor(const FunctorPtr& functor) { this->enterFunctor_ = functor; }
    153153        //! Sets a functor to be called upon deactivation of the state
    154         void setLeaveFunctor(Functor* functor) { this->leaveFunctor_ = functor; }
     154        void setLeaveFunctor(const FunctorPtr& functor) { this->leaveFunctor_ = functor; }
    155155
    156156    private:
     
    172172        //! Handler to be used for all joy sticks (needs to be saved in case another joy stick gets attached)
    173173        InputHandler*               joyStickHandlerAll_;
    174         Functor                  enterFunctor_;          //!< Functor to be executed on enter
    175         Functor                  leaveFunctor_;          //!< Functor to be executed on leave
     174        FunctorPtr                  enterFunctor_;          //!< Functor to be executed on enter
     175        FunctorPtr                  leaveFunctor_;          //!< Functor to be executed on leave
    176176    };
    177177
  • code/trunk/src/libraries/core/input/KeyBinderManager.cc

    r6417 r7284  
    3131#include "util/Debug.h"
    3232#include "util/Exception.h"
     33#include "util/ScopedSingletonManager.h"
    3334#include "core/ConfigValueIncludes.h"
    34 #include "core/ConsoleCommand.h"
    3535#include "core/CoreIncludes.h"
    36 #include "core/ScopedSingletonManager.h"
     36#include "core/LuaState.h"
     37#include "core/command/ConsoleCommand.h"
    3738#include "InputManager.h"
    3839#include "KeyDetector.h"
     
    4142{
    4243    ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics, false);
     44
     45    static const std::string __CC_keybind_name = "keybind";
     46    static const std::string __CC_tkeybind_name = "tkeybind";
     47    static const std::string __CC_unbind_name = "unbind";
     48    static const std::string __CC_tunbind_name = "tunbind";
     49
     50    SetConsoleCommand(__CC_keybind_name,  &KeyBinderManager::keybind).defaultValues("").argumentCompleter(0, autocompletion::command());
     51    SetConsoleCommand(__CC_tkeybind_name, &KeyBinderManager::tkeybind).defaultValues("").argumentCompleter(0, autocompletion::command());
     52    SetConsoleCommand(__CC_unbind_name,   &KeyBinderManager::unbind).defaultValues("");
     53    SetConsoleCommand(__CC_tunbind_name,  &KeyBinderManager::tunbind).defaultValues("");
    4354
    4455    KeyBinderManager::KeyBinderManager()
     
    5162
    5263        // keybind console commands
    53         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::keybind,  this), "keybind" ))
    54             .defaultValues("");
    55         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tkeybind, this), "tkeybind"))
    56             .defaultValues("");
    57         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::unbind, this), "unbind"))
    58             .defaultValues("");
    59         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tunbind, this), "tunbind"))
    60             .defaultValues("");
     64        ModifyConsoleCommand(__CC_keybind_name ).setObject(this);
     65        ModifyConsoleCommand(__CC_tkeybind_name).setObject(this);
     66        ModifyConsoleCommand(__CC_unbind_name  ).setObject(this);
     67        ModifyConsoleCommand(__CC_tunbind_name ).setObject(this);
    6168
    6269        // Load default key binder
     
    6976        for (std::map<std::string, KeyBinder*>::const_iterator it = this->binders_.begin(); it != this->binders_.end(); ++it)
    7077            delete it->second;
     78
     79        // Reset console commands
     80        ModifyConsoleCommand(__CC_keybind_name ).setObject(0);
     81        ModifyConsoleCommand(__CC_tkeybind_name).setObject(0);
     82        ModifyConsoleCommand(__CC_unbind_name  ).setObject(0);
     83        ModifyConsoleCommand(__CC_tunbind_name ).setObject(0);
    7184    }
    7285
     
    156169        {
    157170            COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    158             KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this)));
     171            KeyDetector::getInstance().setCallback(createFunctor(&KeyBinderManager::keybindKeyPressed, this));
    159172            InputManager::getInstance().enterState("detector");
    160173            this->command_ = command;
     
    187200        // else: A key was probably pressed within the same tick, ignore it.
    188201    }
     202
     203    void KeyBinderManager::registerKeybindCallback(LuaFunctor* function)
     204    {
     205        this->callbackFunction_ = function;
     206    }
    189207}
  • code/trunk/src/libraries/core/input/KeyBinderManager.h

    r6417 r7284  
    9999        void unbind(const std::string& binding); //tolua_export
    100100        void tunbind(const std::string& binding);
    101         inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export
     101        void registerKeybindCallback(LuaFunctor* function); //tolua_export
    102102
    103103    private:
     
    114114
    115115        // keybind command related
    116         shared_ptr<Functor> callbackFunction_;       //! Function to be called when key was pressed after "keybind" command
     116        SharedPtr<LuaFunctor> callbackFunction_;     //! Function to be called when key was pressed after "keybind" command
    117117        bool bBinding_;                              //! Tells whether a key binding process is active
    118118        bool bTemporary_;                            //! Stores tkeybind/keybind value
  • code/trunk/src/libraries/core/input/KeyDetector.cc

    r6428 r7284  
    2929#include "KeyDetector.h"
    3030
    31 #include "core/ConsoleCommand.h"
     31#include "util/ScopedSingletonManager.h"
    3232#include "core/CoreIncludes.h"
    33 #include "core/ScopedSingletonManager.h"
     33#include "core/command/ConsoleCommand.h"
    3434#include "Button.h"
    3535#include "InputManager.h"
     
    3838namespace orxonox
    3939{
    40     std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
    4140    ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false);
     41
     42    static const std::string __CC_KeyDetector_callback_name = "KeyDetectorKeyPressed";
     43    DeclareConsoleCommand(__CC_KeyDetector_callback_name, &prototype::void__string).hide();
    4244
    4345    KeyDetector::KeyDetector()
     
    4648        RegisterObject(KeyDetector);
    4749
    48         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback,  this), callbackCommand_s));
     50        ModifyConsoleCommand(__CC_KeyDetector_callback_name).setFunction(&KeyDetector::callback, this);
     51
    4952        this->assignCommands();
    5053
     
    5962        inputState_->setHandler(NULL);
    6063        InputManager::getInstance().destroyState("detector");
     64        ModifyConsoleCommand(__CC_KeyDetector_callback_name).resetFunction();
    6165    }
    6266
     
    6569        // Assign every button/axis the same command, but with its name as argument
    6670        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    67             it->second->parse(callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_);
     71            it->second->parse(__CC_KeyDetector_callback_name + ' ' + it->second->groupName_ + "." + it->second->name_);
    6872    }
    6973
  • code/trunk/src/libraries/core/input/KeyDetector.h

    r6417 r7284  
    4646        ~KeyDetector();
    4747
    48         void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; }
     48        void setCallback(const FunctorPtr& function) { this->callbackFunction_ = function; }
    4949
    5050    private:
     
    5555        void assignCommands();
    5656
    57         shared_ptr<Functor> callbackFunction_;
     57        FunctorPtr callbackFunction_;
    5858        InputState* inputState_;
    59         static std::string callbackCommand_s;
    6059        static KeyDetector* singletonPtr_s;
    6160    };
  • code/trunk/src/libraries/core/input/Mouse.cc

    r5929 r7284  
    3030
    3131#include <ois/OISMouse.h>
    32 #include "core/ConsoleCommand.h"
    3332#include "core/CoreIncludes.h"
     33#include "core/command/ConsoleCommand.h"
    3434#include "InputState.h"
    3535
     
    4141namespace orxonox
    4242{
     43#ifdef ORXONOX_PLATFORM_LINUX
     44    static const std::string __CC_Mouse_name = "Mouse";
     45    static const std::string __CC_grab_name = "grab";
     46    static const std::string __CC_ungrab_name = "ungrab";
     47
     48    SetConsoleCommand(__CC_Mouse_name, __CC_grab_name,   &Mouse::grab);
     49    SetConsoleCommand(__CC_Mouse_name, __CC_ungrab_name, &Mouse::ungrab);
     50#endif
     51
    4352    Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager)
    4453        : super(id, oisInputManager)
     
    4857
    4958#ifdef ORXONOX_PLATFORM_LINUX
    50         // Mouse grab console command
    51         this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::grab, this), "grab"), false);
    52         // Mouse ungrab console command
    53         this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::ungrab, this), "ungrab"), false);
     59        ModifyConsoleCommand(__CC_Mouse_name, __CC_grab_name).setObject(this);
     60        ModifyConsoleCommand(__CC_Mouse_name, __CC_ungrab_name).setObject(this);
     61#endif
     62    }
     63
     64    Mouse::~Mouse()
     65    {
     66#ifdef ORXONOX_PLATFORM_LINUX
     67        ModifyConsoleCommand(__CC_Mouse_name, __CC_grab_name).setObject(0);
     68        ModifyConsoleCommand(__CC_Mouse_name, __CC_ungrab_name).setObject(0);
    5469#endif
    5570    }
  • code/trunk/src/libraries/core/input/Mouse.h

    r5781 r7284  
    6464        //! Only sets the clipping size. Initialising is done in the base class.
    6565        Mouse(unsigned int id, OIS::InputManager* oisInputManager);
    66         ~Mouse() { }
     66        ~Mouse();
    6767
    6868#ifdef ORXONOX_PLATFORM_LINUX
Note: See TracChangeset for help on using the changeset viewer.