Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 10:23:58 PM (15 years ago)
Author:
rgrieder
Message:

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
Location:
code/trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r5929 r6417  
    116116        for (unsigned int iCommand = 0; iCommand < commandStrings.size(); iCommand++)
    117117        {
    118             if (commandStrings[iCommand] != "")
     118            if (!commandStrings[iCommand].empty())
    119119            {
    120120                SubString tokens(commandStrings[iCommand], " ", SubString::WhiteSpaces, false,
     
    123123                KeybindMode::Value mode = KeybindMode::None;
    124124                float paramModifier = 1.0f;
    125                 std::string commandStr = "";
     125                std::string commandStr;
    126126
    127127                for (unsigned int iToken = 0; iToken < tokens.size(); ++iToken)
    128128                {
    129                     std::string token = getLowercase(tokens[iToken]);
     129                    const std::string& token = getLowercase(tokens[iToken]);
    130130
    131131                    if (token == "onpress")
     
    159159                        // we interpret everything from here as a command string
    160160                        while (iToken != tokens.size())
    161                             commandStr += tokens[iToken++] + " ";
    162                     }
    163                 }
    164 
    165                 if (commandStr == "")
     161                            commandStr += tokens[iToken++] + ' ';
     162                    }
     163                }
     164
     165                if (commandStr.empty())
    166166                {
    167167                    parseError("No command string given.", false);
     
    242242    }
    243243
    244     inline void Button::parseError(std::string message, bool serious)
     244    inline void Button::parseError(const std::string& message, bool serious)
    245245    {
    246246        if (serious)
  • code/trunk/src/libraries/core/input/Button.h

    r5781 r6417  
    7676
    7777    private:
    78         void parseError(std::string message, bool serious);
     78        void parseError(const std::string& message, bool serious);
    7979    };
    8080
  • code/trunk/src/libraries/core/input/InputBuffer.cc

    r6105 r6417  
    3939        RegisterRootObject(InputBuffer);
    4040
    41         this->buffer_ = "";
    4241        this->cursor_ = 0;
     42        this->maxLength_ = 1024;
    4343        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyz \
    4444                               ABCDEFGHIJKLMNOPQRSTUVWXYZ \
     
    5959        RegisterRootObject(InputBuffer);
    6060
     61        this->maxLength_ = 1024;
    6162        this->allowedChars_ = allowedChars;
    62         this->buffer_ = "";
    6363        this->cursor_ = 0;
    6464
     
    9393    }
    9494
     95    void InputBuffer::setMaxLength(unsigned int length)
     96    {
     97        this->maxLength_ = length;
     98        if (this->buffer_.size() > length)
     99            this->buffer_.resize(length);
     100    }
     101
    95102    void InputBuffer::set(const std::string& input, bool update)
    96103    {
     
    117124        if (this->charIsAllowed(input))
    118125        {
     126            if (this->buffer_.size() >= this->maxLength_)
     127                return;
    119128            this->buffer_.insert(this->cursor_, 1, input);
    120129            ++this->cursor_;
     
    127136    void InputBuffer::clear(bool update)
    128137    {
    129         this->buffer_ = "";
     138        this->buffer_.clear();
    130139        this->cursor_ = 0;
    131140
     
    177186    bool InputBuffer::charIsAllowed(const char& input)
    178187    {
    179         if (this->allowedChars_ == "")
     188        if (this->allowedChars_.empty())
    180189            return true;
    181190        else
  • code/trunk/src/libraries/core/input/InputBuffer.h

    r6105 r6417  
    8282
    8383            void setConfigValues();
     84
     85            unsigned int getMaxLength() const { return this->maxLength_; }
     86            void setMaxLength(unsigned int length);
    8487
    8588            template <class T>
     
    175178            std::list<BaseInputBufferListenerTuple*> listeners_;
    176179            std::string allowedChars_;
     180            unsigned int maxLength_;
    177181            unsigned int cursor_;
    178182
  • code/trunk/src/libraries/core/input/InputCommands.h

    r5781 r6417  
    7171    @brief
    7272        Executes a simple command with no additional paramters.
    73     @return 
     73    @return
    7474        True if command execution was successful, false otherwise.
    7575    */
  • code/trunk/src/libraries/core/input/InputDevice.h

    r5929 r6417  
    203203        {
    204204            // remove the button from the pressedButtons_ list
     205            bool found = false;
    205206            for (unsigned int iButton = 0; iButton < pressedButtons_.size(); iButton++)
    206207            {
     
    208209                {
    209210                    pressedButtons_.erase(pressedButtons_.begin() + iButton);
     211                    found = true;
    210212                    break;
    211213                }
    212214            }
     215            if (!found)
     216                return; // We ignore release strokes when the press was not captured
    213217
    214218            // Call states
  • code/trunk/src/libraries/core/input/InputManager.cc

    r6105 r6417  
    275275        // destroy all user InputStates
    276276        while (statesByName_.size() > 0)
    277             this->destroyStateInternal((*statesByName_.rbegin()).second);
     277            this->destroyStateInternal(statesByName_.rbegin()->second);
    278278
    279279        if (!(internalState_ & Bad))
     
    297297            if (device == NULL)
    298298                continue;
    299             std::string className = device->getClassName();
     299            const std::string& className = device->getClassName();
    300300            try
    301301            {
     
    366366    // ############################################################
    367367
    368     void InputManager::update(const Clock& time)
     368    void InputManager::preUpdate(const Clock& time)
    369369    {
    370370        if (internalState_ & Bad)
     
    466466    @brief
    467467        Updates the currently active states (according to activeStates_) for each device.
    468         Also, a list of all active states (no duplicates!) is compiled for the general update().
     468        Also, a list of all active states (no duplicates!) is compiled for the general preUpdate().
    469469    */
    470470    void InputManager::updateActiveStates()
     
    508508        if (mouseStates.empty())
    509509            requestedMode = MouseMode::Nonexclusive;
    510         else 
     510        else
    511511            requestedMode = mouseStates.front()->getMouseMode();
    512512        if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode)
     
    554554    }
    555555
    556     //! Gets called by WindowEventListener upon focus change --> clear buffers 
     556    //! Gets called by WindowEventListener upon focus change --> clear buffers
    557557    void InputManager::windowFocusChanged()
    558558    {
     
    579579    InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
    580580    {
    581         if (name == "")
     581        if (name.empty())
    582582            return 0;
    583583        if (statesByName_.find(name) == statesByName_.end())
     
    631631                {
    632632                    // not scheduled for destruction
    633                     // prevents a state being added multiple times
     633                    // prevents a state from being added multiple times
    634634                    stateEnterRequests_.insert(it->second);
    635635                    return true;
    636636                }
    637637            }
     638            else if (this->stateLeaveRequests_.find(it->second) != this->stateLeaveRequests_.end())
     639            {
     640                // State already scheduled for leaving --> cancel
     641                this->stateLeaveRequests_.erase(this->stateLeaveRequests_.find(it->second));
     642            }
    638643        }
    639644        return false;
     
    658663                return true;
    659664            }
     665            else if (this->stateEnterRequests_.find(it->second) != this->stateEnterRequests_.end())
     666            {
     667                // State already scheduled for entering --> cancel
     668                this->stateEnterRequests_.erase(this->stateEnterRequests_.find(it->second));
     669            }
    660670        }
    661671        return false;
  • code/trunk/src/libraries/core/input/InputManager.h

    r6084 r6417  
    4141#include "InputState.h"
    4242
     43// tolua_begin
    4344namespace orxonox
    4445{
     
    6364          If the OIS::InputManager or the Keyboard fail, an exception is thrown.
    6465    */
    65     class _CoreExport InputManager : public Singleton<InputManager>, public WindowEventListener
    66     {
     66    class _CoreExport InputManager
     67// tolua_end
     68        : public Singleton<InputManager>, public WindowEventListener
     69    { // tolua_export
    6770        friend class Singleton<InputManager>;
    6871    public:
     
    8083        @brief
    8184            Loads the devices and initialises the KeyDetector and the Calibrator.
    82            
     85
    8386            If either the OIS input system and/or the keyboard could not be created,
    8487            the constructor fails with an std::exception.
     
    9699            was submitted while updating, the request will be postponed until the next update call.
    97100        */
    98         void update(const Clock& time);
     101        void preUpdate(const Clock& time);
    99102        //! Clears all input device buffers. This usually only includes the pressed button list.
    100103        void clearBuffers();
     
    105108            Reloads all the input devices. Use this method to initialise new joy sticks.
    106109        @note
    107             Only reloads immediately if the call stack doesn't include the update() method.
     110            Only reloads immediately if the call stack doesn't include the preUpdate() method.
    108111        */
    109112        void reload();
     
    139142            False if name was not found, true otherwise.
    140143        */
    141         bool enterState(const std::string& name);
     144        bool enterState(const std::string& name); // tolua_export
    142145        /**
    143146        @brief
     
    146149            False if name was not found, true otherwise.
    147150        */
    148         bool leaveState(const std::string& name);
     151        bool leaveState(const std::string& name); // tolua_export
    149152        /**
    150153        @brief
     
    154157        @remarks
    155158            - You can't remove the internal states "empty", "calibrator" and "detector".
    156             - The removal process is being postponed if InputManager::update() is currently running.
     159            - The removal process is being postponed if InputManager::preUpdate() is currently running.
    157160        */
    158161        bool destroyState(const std::string& name);
     
    168171        std::pair<int, int> getMousePosition() const;
    169172
     173        static InputManager& getInstance() { return Singleton<InputManager>::getInstance(); } // tolua_export
     174
    170175    private: // functions
    171176        // don't mess with a Singleton
     
    207212
    208213        static InputManager*                singletonPtr_s;        //!< Pointer reference to the singleton
    209     };
    210 }
     214    }; // tolua_export
     215} // tolua_export
    211216
    212217#endif /* _InputManager_H__ */
  • code/trunk/src/libraries/core/input/InputPrereqs.h

    r5781 r6417  
    202202            MediaSelect   = OIS::KC_MEDIASELECT      // Media Select
    203203        };
    204        
     204
    205205        //! Key codes as strings
    206206        const char* const ByString[] =
  • code/trunk/src/libraries/core/input/InputState.cc

    r5929 r6417  
    102102        if (enterFunctor_)
    103103            (*enterFunctor_)();
    104            
     104
    105105    }
    106106
  • code/trunk/src/libraries/core/input/JoyStick.cc

    r5781 r6417  
    3333#include <boost/foreach.hpp>
    3434
     35#include "util/StringUtils.h"
    3536#include "core/ConfigFileManager.h"
    3637#include "core/ConfigValueIncludes.h"
     
    6162            std::string name = oisDevice_->vendor();
    6263            replaceCharacters(name, ' ', '_');
    63             deviceName_ = name + "_";
    64         }
    65         deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button))  + "_";
    66         deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis))    + "_";
    67         deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider))  + "_";
     64            deviceName_ = name + '_';
     65        }
     66        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button))  + '_';
     67        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis))    + '_';
     68        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider))  + '_';
    6869        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
    6970        //deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
     
    7475            {
    7576                // Make the ID unique for this execution time.
    76                 deviceName_ += "_" + multi_cast<std::string>(this->getDeviceName());
     77                deviceName_ += '_' + multi_cast<std::string>(this->getDeviceName());
    7778                break;
    7879            }
  • code/trunk/src/libraries/core/input/JoyStickQuantityListener.h

    r5781 r6417  
    2929/**
    3030@file
    31 @brief 
     31@brief
    3232*/
    3333
  • code/trunk/src/libraries/core/input/KeyBinder.cc

    r5929 r6417  
    2929#include "KeyBinder.h"
    3030
     31#include <algorithm>
     32#include <sstream>
    3133#include "util/Convert.h"
    3234#include "util/Debug.h"
     
    5052        mouseRelative_[0] = 0;
    5153        mouseRelative_[1] = 0;
    52         mousePosition_[0] = 0;
    53         mousePosition_[1] = 0;
     54        mousePosition_[0] = 0.0;
     55        mousePosition_[1] = 0.0;
    5456
    5557        RegisterRootObject(KeyBinder);
     
    5961        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    6062        {
    61             std::string keyname = KeyCode::ByString[i];
     63            const std::string& keyname = KeyCode::ByString[i];
    6264            if (!keyname.empty())
    6365                keys_[i].name_ = std::string("Key") + keyname;
    6466            else
    65                 keys_[i].name_ = "";
     67                keys_[i].name_.clear();
    6668            keys_[i].paramCommandBuffer_ = &paramCommandBuffer_;
    6769            keys_[i].groupName_ = "Keys";
     
    126128        SetConfigValue(bFilterAnalogNoise_, false)
    127129            .description("Specifies whether to filter small analog values like joy stick fluctuations.");
    128         SetConfigValue(mouseSensitivity_, 1.0f)
     130        SetConfigValue(mouseSensitivity_, 3.0f)
    129131            .description("Mouse sensitivity.");
     132        this->totalMouseSensitivity_ = this->mouseSensitivity_ / this->mouseClippingSize_;
    130133        SetConfigValue(bDeriveMouseInput_, false)
    131134            .description("Whether or not to derive moues movement for the absolute value.");
     
    185188        this->joyStickButtons_.resize(joySticks_.size());
    186189
    187         // reinitialise all joy stick binings (doesn't overwrite the old ones)
     190        // reinitialise all joy stick bindings (doesn't overwrite the old ones)
    188191        for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++)
    189192        {
    190             std::string deviceName = joySticks_[iDev]->getDeviceName();
     193            const std::string& deviceName = joySticks_[iDev]->getDeviceName();
    191194            // joy stick buttons
    192195            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
     
    218221        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    219222            if (!keys_[i].name_.empty())
    220                 allButtons_[keys_[i].groupName_ + "." + keys_[i].name_] = keys_ + i;
     223                allButtons_[keys_[i].groupName_ + '.' + keys_[i].name_] = keys_ + i;
    221224        for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
    222             allButtons_[mouseButtons_[i].groupName_ + "." + mouseButtons_[i].name_] = mouseButtons_ + i;
     225            allButtons_[mouseButtons_[i].groupName_ + '.' + mouseButtons_[i].name_] = mouseButtons_ + i;
    223226        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    224227        {
    225             allButtons_[mouseAxes_[i].groupName_ + "." + mouseAxes_[i].name_] = mouseAxes_ + i;
     228            allButtons_[mouseAxes_[i].groupName_ + '.' + mouseAxes_[i].name_] = mouseAxes_ + i;
    226229            allHalfAxes_.push_back(mouseAxes_ + i);
    227230        }
     
    229232        {
    230233            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    231                 allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + "." + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
     234                allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + '.' + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
    232235            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    233236            {
    234                 allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + "." + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
     237                allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + '.' + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
    235238                allHalfAxes_.push_back(&((*joyStickAxes_[iDev])[i]));
    236239            }
     
    253256        // Parse bindings and create the ConfigValueContainers if necessary
    254257        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
     258        {
    255259            it->second->readConfigValue(this->configFile_);
     260            addButtonToCommand(it->second->bindingString_, it->second);
     261        }
    256262
    257263        COUT(3) << "KeyBinder: Loading key bindings done." << std::endl;
     
    263269        if (it != allButtons_.end())
    264270        {
     271            addButtonToCommand(binding, it->second);
    265272            if (bTemporary)
    266273                it->second->configContainer_->tset(binding);
     
    275282            return false;
    276283        }
     284    }
     285
     286     void KeyBinder::addButtonToCommand(const std::string& command, Button* button)
     287     {
     288        std::ostringstream stream;
     289        stream << button->groupName_  << '.' << button->name_;
     290
     291        std::vector<std::string>& oldKeynames = this->allCommands_[button->bindingString_];
     292        std::vector<std::string>::iterator it = std::find(oldKeynames.begin(), oldKeynames.end(), stream.str());
     293        if(it != oldKeynames.end())
     294        {
     295            oldKeynames.erase(it);
     296        }
     297
     298        if (!command.empty())
     299        {
     300            std::vector<std::string>& keynames = this->allCommands_[command];
     301            if( std::find(keynames.begin(), keynames.end(), stream.str()) == keynames.end())
     302            {
     303                this->allCommands_[command].push_back(stream.str());
     304            }
     305        }
     306     }
     307
     308    /**
     309    @brief
     310        Return the first key name for a specific command
     311    */
     312    const std::string& KeyBinder::getBinding(const std::string& commandName)
     313    {
     314        if( this->allCommands_.find(commandName) != this->allCommands_.end())
     315        {
     316            std::vector<std::string>& keynames = this->allCommands_[commandName];
     317            return keynames.front();
     318        }
     319
     320        return BLANKSTRING;
     321    }
     322
     323    /**
     324    @brief
     325        Return the key name for a specific command at a given index.
     326    @param commandName
     327        The command name the key name is returned for.
     328    @param index
     329        The index at which the key name is returned for.
     330    */
     331    const std::string& KeyBinder::getBinding(const std::string& commandName, unsigned int index)
     332    {
     333        if( this->allCommands_.find(commandName) != this->allCommands_.end())
     334        {
     335            std::vector<std::string>& keynames = this->allCommands_[commandName];
     336            if(index < keynames.size())
     337            {
     338                return keynames[index];
     339            }
     340
     341            return BLANKSTRING;
     342        }
     343
     344        return BLANKSTRING;
     345    }
     346
     347    /**
     348    @brief
     349        Get the number of different key bindings of a specific command.
     350    @param commandName
     351        The command.
     352    */
     353    unsigned int KeyBinder::getNumberOfBindings(const std::string& commandName)
     354    {
     355        if( this->allCommands_.find(commandName) != this->allCommands_.end())
     356        {
     357            std::vector<std::string>& keynames = this->allCommands_[commandName];
     358            return keynames.size();
     359        }
     360
     361        return 0;
    277362    }
    278363
     
    395480
    396481        // these are the actually useful axis bindings for analog input
    397         if (!bFilterAnalogNoise_ || halfAxis.relVal_ > analogThreshold_ || halfAxis.absVal_ > analogThreshold_)
    398         {
    399             halfAxis.execute();
    400         }
     482        halfAxis.execute();
    401483    }
    402484
     
    426508                    mouseAxes_[2*i + 0].hasChanged_ = true;
    427509                    mouseAxes_[2*i + 1].hasChanged_ = true;
    428                     mousePosition_[i] += rel[i];
     510                    mousePosition_[i] += rel[i] * totalMouseSensitivity_;
    429511
    430512                    // clip absolute position
    431                     if (mousePosition_[i] > mouseClippingSize_)
    432                         mousePosition_[i] =  mouseClippingSize_;
    433                     if (mousePosition_[i] < -mouseClippingSize_)
    434                         mousePosition_[i] = -mouseClippingSize_;
    435 
    436                     if (mousePosition_[i] < 0)
     513                    if (mousePosition_[i] > 1.0)
     514                        mousePosition_[i] =  1.0;
     515                    if (mousePosition_[i] < -1.0)
     516                        mousePosition_[i] = -1.0;
     517
     518                    if (mousePosition_[i] < 0.0)
    437519                    {
    438                         mouseAxes_[2*i + 0].absVal_ = -mouseSensitivity_ * mousePosition_[i] / mouseClippingSize_;
     520                        mouseAxes_[2*i + 0].absVal_ = -mousePosition_[i];
    439521                        mouseAxes_[2*i + 1].absVal_ = 0.0f;
    440522                    }
     
    442524                    {
    443525                        mouseAxes_[2*i + 0].absVal_ = 0.0f;
    444                         mouseAxes_[2*i + 1].absVal_ =  mouseSensitivity_ * mousePosition_[i] / mouseClippingSize_;
     526                        mouseAxes_[2*i + 1].absVal_ =  mousePosition_[i];
    445527                    }
    446528                }
     
    452534        {
    453535            if (rel[i] < 0)
    454                 mouseAxes_[0 + 2*i].relVal_ = -mouseSensitivity_ * rel[i] / mouseClippingSize_;
     536                mouseAxes_[0 + 2*i].relVal_ = -rel[i] * totalMouseSensitivity_;
    455537            else
    456                 mouseAxes_[1 + 2*i].relVal_ =  mouseSensitivity_ * rel[i] / mouseClippingSize_;
     538                mouseAxes_[1 + 2*i].relVal_ =  rel[i] * totalMouseSensitivity_;
    457539        }
    458540    }
     
    474556    void KeyBinder::axisMoved(unsigned int device, unsigned int axisID, float value)
    475557    {
     558        // Filter analog noise
     559        if (this->bFilterAnalogNoise_ && std::abs(value) < this->analogThreshold_)
     560            value = 0.0;
    476561        int i = axisID * 2;
    477562        JoyStickAxisVector& axis = *joyStickAxes_[device];
  • code/trunk/src/libraries/core/input/KeyBinder.h

    r5929 r6417  
    3535#include <string>
    3636#include <vector>
     37#include <map>
    3738#include <boost/shared_ptr.hpp>
    3839
     
    4344#include "JoyStickQuantityListener.h"
    4445
     46// tolua_begin
    4547namespace orxonox
    4648{
     49    // tolua_end
    4750    /**
    4851    @brief
     
    5457        KeyBinders. If you need to load other bindings, just create a new one.
    5558    */
    56     class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener
    57     {
     59    class _CoreExport KeyBinder // tolua_export
     60        : public InputHandler, public JoyStickQuantityListener
     61    { // tolua_export
    5862    public:
    5963        KeyBinder (const std::string& filename);
     
    6266        void clearBindings();
    6367        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
     68        const std::string& getBinding(const std::string& commandName); //tolua_export
     69        const std::string& getBinding(const std::string& commandName, unsigned int index); //tolua_export
     70        unsigned int getNumberOfBindings(const std::string& commandName); //tolua_export
     71
    6472        const std::string& getBindingsFilename()
    6573            { return this->filename_; }
     
    130138        //! Pointer list with all half axes
    131139        std::vector<HalfAxis*> allHalfAxes_;
     140        //! Maps input commands to all Button names, including half axes
     141        std::map< std::string, std::vector<std::string> > allCommands_;
    132142
    133143        /**
     
    138148        std::vector<BufferedParamCommand*> paramCommandBuffer_;
    139149
    140         //! Keeps track of the absolute mouse value (incl. scroll wheel)
    141         int mousePosition_[2];
     150        //! Keeps track of the absolute mouse value
     151        float mousePosition_[2];
    142152        //! Used to derive mouse input if requested
    143153        int mouseRelative_[2];
     
    150160
    151161    private:
     162        void addButtonToCommand(const std::string& command, Button* button);
     163
    152164        //##### ConfigValues #####
    153165        //! Whether to filter small value analog input
     
    165177        //! mouse sensitivity if mouse input is derived
    166178        float mouseSensitivityDerived_;
    167         //! Equals one step of the mousewheel
     179        //! Equals one step of the mouse wheel
    168180        int mouseWheelStepSize_;
     181
     182        //! Multiplication of mouse sensitivity and clipping size
     183        float totalMouseSensitivity_;
    169184
    170185        //##### Constant config variables #####
    171186        // Use some value at about 1000. This can be configured with mouseSensitivity_ anyway.
    172187        static const int mouseClippingSize_ = 1024;
    173     };
     188    };// tolua_export
    174189
    175190
     
    216231            mouseAxes_[i].relVal_ = 0.0f;
    217232    }
    218 }
     233}// tolua_export
    219234
    220235#endif /* _KeyBinder_H__ */
  • code/trunk/src/libraries/core/input/KeyBinderManager.cc

    r5929 r6417  
    4040namespace orxonox
    4141{
    42     KeyBinderManager* KeyBinderManager::singletonPtr_s = 0;
    4342    ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics, false);
    4443
     
    4847        , bBinding_(false)
    4948    {
    50         this->callbackFunction_ = createFunctor(&KeyBinderManager::callback, this);
    51 
    5249        RegisterObject(KeyBinderManager);
    5350        this->setConfigValues();
     
    5754            .defaultValues("");
    5855        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"))
    5960            .defaultValues("");
    6061
     
    6869        for (std::map<std::string, KeyBinder*>::const_iterator it = this->binders_.begin(); it != this->binders_.end(); ++it)
    6970            delete it->second;
    70         delete this->callbackFunction_;
    7171    }
    7272
     
    9191        else
    9292            this->bDefaultFileLoaded_ = false;
     93    }
     94
     95    inline void KeyBinderManager::unbind(const std::string& binding)
     96    {
     97        this->currentBinder_->setBinding("", binding, false);
     98    }
     99
     100    inline void KeyBinderManager::tunbind(const std::string& binding)
     101    {
     102        this->currentBinder_->setBinding("", binding, true);
    93103    }
    94104
     
    146156        {
    147157            COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    148             KeyDetector::getInstance().setCallback(callbackFunction_);
     158            KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this)));
    149159            InputManager::getInstance().enterState("detector");
    150160            this->command_ = command;
     
    156166
    157167    // Gets called by the KeyDetector (registered with a Functor)
    158     void KeyBinderManager::callback(const std::string& keyName)
     168    void KeyBinderManager::keybindKeyPressed(const std::string& keyName)
    159169    {
    160170        if (this->bBinding_)
    161171        {
    162             COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl;
    163             this->currentBinder_->setBinding(command_, keyName, bTemporary_);
     172            if (keyName == "Keys.KeyEscape")
     173            {
     174                COUT(0) << "Keybinding aborted." << std::endl;
     175            }
     176            else
     177            {
     178                COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl;
     179                this->currentBinder_->setBinding(command_, keyName, bTemporary_);
     180            }
    164181            InputManager::getInstance().leaveState("detector");
     182            // inform whatever was calling the command
     183            if (this->callbackFunction_)
     184                (*this->callbackFunction_)();
    165185            this->bBinding_ = false;
    166186        }
  • code/trunk/src/libraries/core/input/KeyBinderManager.h

    r5929 r6417  
    3434#include <map>
    3535#include <string>
     36#include <boost/shared_ptr.hpp>
     37
    3638#include "util/Singleton.h"
    3739#include "core/OrxonoxClass.h"
    3840
    39 namespace orxonox
    40 {
     41namespace orxonox //tolua_export
     42{ //tolua_export
    4143    /**
    4244    @brief
     
    4648        maps to the currently active KeyBinder. You can set that with setCurrent().
    4749        There is also a default one, retrieved with getDefault(). The idea is that
    48         mostly the default KeyBinder is active except for special situtations (mini-game for inst).
     50        mostly the default KeyBinder is active except for special situations (mini-game for inst).
    4951    @remarks
    5052        You are not forced to use the KeyBinder imposed by getCurrent(). But be aware that "keybind"
    5153        will not work as expected!
    5254    */
    53     class _CoreExport KeyBinderManager : public Singleton<KeyBinderManager>, public OrxonoxClass
    54     {
     55    class _CoreExport KeyBinderManager //tolua_export
     56        : public Singleton<KeyBinderManager>, public OrxonoxClass
     57    { //tolua_export
    5558        friend class Singleton<KeyBinderManager>;
    5659    public:
     
    5962        void setConfigValues();
    6063
     64        static KeyBinderManager& getInstance() { return Singleton<KeyBinderManager>::getInstance(); } //tolua_export
    6165        //! Returns the currently selected KeyBinder
    62         KeyBinder*    getCurrent()
    63             { return this->currentBinder_; }
     66        KeyBinder* getCurrent() { return this->currentBinder_; } //tolua_export
    6467        //! Like getCurrent(), but returns it as InputHandler* (so you don't have to include KeyBinder.h)
    6568        InputHandler* getCurrentAsHandler();
     
    6871
    6972        //! Returns the default KeyBinder
    70         KeyBinder*    getDefault()
     73        KeyBinder* getDefault()
    7174            { return binders_[this->defaultFilename_]; }
    7275        //! Returns the default KeyBinder as InputHandler* (so you don't have to include KeyBinder.h)
     
    8083
    8184        //! Returns a pointer to a KeyBinder (creates it if not yet loaded)
    82         KeyBinder*    get(const std::string& name);
     85        KeyBinder* get(const std::string& name);
    8386        //! Like get() but return value is of type InputHandler* (so you don't have to include KeyBinder.h)
    8487        InputHandler* getAsHandler(const std::string& name);
    8588
    8689        //! Loads a KeyBinder by creating it (no different from get() except for the return value)
    87         void load  (const std::string& filename);
     90        void load(const std::string& filename);
    8891        //! Destroys a KeyBinder completely (does nothing if not yet loaded)
    8992        void unload(const std::string& filename);
    9093
    9194        //! Bind 'command' to any key pressed after this call (use with care!)
    92         inline void keybind(const std::string& command)
    93             { this->keybindInternal(command, false); }
     95        inline void keybind(const std::string& command) { this->keybindInternal(command, false); } //tolua_export
    9496        //! Bind 'command' to any key pressed after this call (use with care!), but temporarily (no file save)
    9597        inline void tkeybind(const std::string& command)
    9698            { this->keybindInternal(command, true); }
     99        void unbind(const std::string& binding); //tolua_export
     100        void tunbind(const std::string& binding);
     101        inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export
    97102
    98103    private:
    99104        KeyBinderManager(const KeyBinderManager&);
    100105        void keybindInternal(const std::string& command, bool bTemporary);
    101         void callback(const std::string& keyName);
     106        void keybindKeyPressed(const std::string& keyName);
    102107        void defaultFilenameChanged();
    103108
     
    109114
    110115        // keybind command related
    111         Functor* callbackFunction_;                  //! Function to be called when key was pressed after "keybind" command
     116        shared_ptr<Functor> callbackFunction_;       //! Function to be called when key was pressed after "keybind" command
    112117        bool bBinding_;                              //! Tells whether a key binding process is active
    113118        bool bTemporary_;                            //! Stores tkeybind/keybind value
     
    115120
    116121        static KeyBinderManager* singletonPtr_s;
    117     };
    118 }
     122    }; //tolua_export
     123} //tolua_export
    119124
    120125#endif /* _KeyBinderManager_H__ */
  • code/trunk/src/libraries/core/input/KeyDetector.cc

    r5929 r6417  
    3939{
    4040    std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
    41     KeyDetector* KeyDetector::singletonPtr_s = 0;
    4241    ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false);
    4342
     
    6867        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    6968        {
    70             it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_;
     69            it->second->bindingString_ = callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_;
    7170            it->second->parse();
    7271        }
  • code/trunk/src/libraries/core/input/KeyDetector.h

    r5929 r6417  
    3232#include "InputPrereqs.h"
    3333
     34#include <boost/shared_ptr.hpp>
    3435#include "util/Singleton.h"
    3536#include "KeyBinder.h"
     
    4546        ~KeyDetector();
    4647
    47         void setCallback(Functor* function) { this->callbackFunction_ = function; }
     48        void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; }
    4849
    4950    private:
     
    5455        void assignCommands();
    5556
    56         Functor* callbackFunction_;
     57        shared_ptr<Functor> callbackFunction_;
    5758        InputState* inputState_;
    5859        static std::string callbackCommand_s;
  • code/trunk/src/libraries/core/input/Keyboard.cc

    r5781 r6417  
    4343            modifiers_ |= KeyboardModifier::Shift; // shift key
    4444
     45        // Do not distribute the alt+tab event (messes with the operating system)
     46        if ((modifiers_ & KeyboardModifier::Alt) != 0 && arg.key == OIS::KC_TAB)
     47            return true;
     48
    4549        KeyEvent evt(arg);
    4650        super::buttonPressed(evt);
Note: See TracChangeset for help on using the changeset viewer.