Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 19, 2009, 1:13:43 AM (15 years ago)
Author:
rgrieder
Message:

Keybindings should now map to the correct joy stick by device name (like "WingMan Action Pad" or so).

Location:
code/branches/core4/src/core/input
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/input/JoyStick.cc

    r3286 r3306  
    4343    void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue);
    4444
    45     std::vector<std::string> JoyStick::idStrings_s;
     45    std::vector<std::string> JoyStick::deviceNames_s;
    4646
    4747    JoyStick::JoyStick(unsigned int id, OIS::InputManager* oisInputManager)
     
    5353        this->clearBuffersImpl();
    5454
    55         idString_ = "JoyStick_";
    56         std::string name = oisDevice_->vendor();
    57         replaceCharacters(name, ' ', '_');
    58         idString_ += name + "_";
    59         idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button))  + "_";
    60         idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis))    + "_";
    61         idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider))  + "_";
    62         idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
    63         //idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
    64 
    65 
    66         BOOST_FOREACH(std::string& idString, idStrings_s)
    67         {
    68             if (idString_ == idString)
     55        // Generate unique name
     56        if (oisDevice_->vendor().empty())
     57            deviceName_ = "Unknown_";
     58        else
     59        {
     60            std::string name = oisDevice_->vendor();
     61            replaceCharacters(name, ' ', '_');
     62            deviceName_ = name + "_";
     63        }
     64        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button))  + "_";
     65        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis))    + "_";
     66        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider))  + "_";
     67        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
     68        //deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
     69
     70        BOOST_FOREACH(std::string& idString, deviceNames_s)
     71        {
     72            if (deviceName_ == idString)
    6973            {
    7074                // Make the ID unique for this execution time.
    71                 idString_ += "_" + multi_cast<std::string>(this->getDeviceID());
     75                deviceName_ += "_" + multi_cast<std::string>(this->getDeviceName());
    7276                break;
    7377            }
    7478        }
    7579
    76         COUT(4) << "Created OIS joy stick with ID " << idString_ << std::endl;
     80        COUT(4) << "Created OIS joy stick with ID " << deviceName_ << std::endl;
    7781
    7882        // Load calibration
    7983        size_t axes = sliderAxes_s + static_cast<size_t>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis));
    80         loadCalibration(configMinValues_,  idString_, "MinValue",  axes,  -32768);
    81         loadCalibration(configMaxValues_,  idString_, "MaxValue",  axes,   32768);
    82         loadCalibration(configZeroValues_, idString_, "ZeroValue", axes, 0);
     84        loadCalibration(configMinValues_,  deviceName_, "MinValue",  axes,  -32768);
     85        loadCalibration(configMaxValues_,  deviceName_, "MaxValue",  axes,   32768);
     86        loadCalibration(configZeroValues_, deviceName_, "ZeroValue", axes, 0);
    8387        this->evaluateCalibration();
    8488    }
     
    148152                configMinValues_[i] = -32768;
    149153            ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    150                 idString_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
     154                deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
    151155
    152156            // Maximum values
     
    154158                configMaxValues_[i] = 32767;
    155159            ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    156                 idString_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
     160                deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
    157161
    158162            // Middle values
    159163            ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    160                 idString_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
     164                deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
    161165        }
    162166
  • code/branches/core4/src/core/input/JoyStick.h

    r3286 r3306  
    7171        void setConfigValues();
    7272
    73         //! Returns the ID string generated from the number of knobs and the device name
    74         const std::string& getIDString() const { return this->idString_; }
     73        //! Returns the name generated from the number of knobs and the device name
     74        const std::string& getDeviceName() const { return this->deviceName_; }
    7575
    7676    private:
     
    106106        static std::string getClassNameImpl() { return "JoyStick"; }
    107107
    108         std::string idString_;                //!< ID string generated by the number of knobs and the device name
     108        std::string deviceName_;              //!< Name generated by the number of knobs and the device name
    109109        int povStates_[4];                    //!< Internal states for the POVs
    110110        int sliderStates_[4][2];              //!< Internal states for the Sliders (each slider has X and Y!)
     
    122122        std::string calibrationFilename_;     //!< Joy stick calibration ini filename
    123123
    124         //! Contains a list of all ID strings to avoid duplicates
    125         static std::vector<std::string> idStrings_s;
     124        //! Contains a list of all names to avoid duplicates
     125        static std::vector<std::string> deviceNames_s;
    126126
    127127        //!< Maximum number of slider axes
  • code/branches/core4/src/core/input/KeyBinder.cc

    r3288 r3306  
    4040#include "core/ConfigFileManager.h"
    4141#include "InputCommands.h"
     42#include "JoyStick.h"
    4243
    4344namespace orxonox
     
    4849    */
    4950    KeyBinder::KeyBinder()
    50         : numberOfJoySticks_(0)
    51         , deriveTime_(0.0f)
     51        : deriveTime_(0.0f)
    5252    {
    5353        mouseRelative_[0] = 0;
     
    8282            else
    8383                nameSuffix = mouseWheelNames[i - MouseButtonCode::numberOfButtons];
    84             mouseButtons_[i].name_ = std::string("Mouse") + nameSuffix;
     84            mouseButtons_[i].name_ = nameSuffix;
    8585            mouseButtons_[i].paramCommandBuffer_ = &paramCommandBuffer_;
    8686            mouseButtons_[i].groupName_ = "MouseButtons";
     
    8989        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    9090        {
    91             mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i / 2];
     91            mouseAxes_[i].name_ = MouseAxisCode::ByString[i / 2];
    9292            if (i & 1)
    9393                mouseAxes_[i].name_ += "Pos";
     
    102102
    103103        // initialise joy sticks separatly to allow for reloading
    104         numberOfJoySticks_ = this->getJoyStickList().size();
    105         initialiseJoyStickBindings();
    106 
    107         // collect all Buttons and HalfAxes
    108         compilePointerLists();
     104        this->JoyStickQuantityChanged(this->getJoyStickList());
    109105
    110106        // set them here to use allHalfAxes_
     
    156152    void KeyBinder::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
    157153    {
    158         unsigned int oldValue = numberOfJoySticks_;
    159         numberOfJoySticks_ = joyStickList.size();
     154        unsigned int oldValue = joySticks_.size();
     155        joySticks_ = joyStickList;
    160156
    161157        // initialise joy stick bindings
     
    168164        if (configFile_ != ConfigFileType::NoType)
    169165        {
    170             for (unsigned int iDev = oldValue; iDev < numberOfJoySticks_; ++iDev)
     166            for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev)
    171167            {
    172168                for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
     
    183179    void KeyBinder::initialiseJoyStickBindings()
    184180    {
    185         this->joyStickAxes_.resize(numberOfJoySticks_);
    186         this->joyStickButtons_.resize(numberOfJoySticks_);
     181        this->joyStickAxes_.resize(joySticks_.size());
     182        this->joyStickButtons_.resize(joySticks_.size());
    187183
    188184        // reinitialise all joy stick binings (doesn't overwrite the old ones)
    189         for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)
    190         {
    191             std::string deviceNumber = multi_cast<std::string>(iDev);
     185        for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++)
     186        {
     187            std::string deviceName = joySticks_[iDev]->getDeviceName();
    192188            // joy stick buttons
    193189            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    194190            {
    195                 joyStickButtons_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickButtonCode::ByString[i];
     191                joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i];
    196192                joyStickButtons_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
    197                 joyStickButtons_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Buttons";
     193                joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName;
    198194            }
    199195            // joy stick axes
    200196            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    201197            {
    202                 joyStickAxes_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickAxisCode::ByString[i >> 1];
     198                joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2];
    203199                if (i & 1)
    204200                    joyStickAxes_[iDev][i].name_ += "Pos";
     
    206202                    joyStickAxes_[iDev][i].name_ += "Neg";
    207203                joyStickAxes_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
    208                 joyStickAxes_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Axes";
     204                joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName;
    209205            }
    210206        }
     
    219215        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    220216            if (!keys_[i].name_.empty())
    221                 allButtons_[keys_[i].name_] = keys_ + i;
     217                allButtons_[keys_[i].groupName_ + "." + keys_[i].name_] = keys_ + i;
    222218        for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
    223             allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i;
     219            allButtons_[mouseButtons_[i].groupName_ + "." + mouseButtons_[i].name_] = mouseButtons_ + i;
    224220        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    225221        {
    226             allButtons_[mouseAxes_[i].name_] = mouseAxes_ + i;
     222            allButtons_[mouseAxes_[i].groupName_ + "." + mouseAxes_[i].name_] = mouseAxes_ + i;
    227223            allHalfAxes_.push_back(mouseAxes_ + i);
    228224        }
    229         for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)
     225        for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++)
    230226        {
    231227            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    232                 allButtons_[joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
     228                allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
    233229            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    234230            {
    235                 allButtons_[joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
     231                allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
    236232                allHalfAxes_.push_back(&(joyStickAxes_[iDev][i]));
    237233            }
     
    303299    void KeyBinder::resetJoyStickAxes()
    304300    {
    305         for (unsigned int iDev = 0; iDev < numberOfJoySticks_; ++iDev)
     301        for (unsigned int iDev = 0; iDev < joySticks_.size(); ++iDev)
    306302        {
    307303            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
  • code/branches/core4/src/core/input/KeyBinder.h

    r3288 r3306  
    9797    protected: // variables
    9898        //! Currently active joy sticks
    99         unsigned int numberOfJoySticks_;
     99        std::vector<JoyStick*>  joySticks_;
    100100
    101101        //! Actual key bindings for keys on the keyboard
  • code/branches/core4/src/core/input/KeyDetector.cc

    r3288 r3306  
    2626 *
    2727 */
    28 
    29 /**
    30 @file
    31 @brief
    32     Implementation of the different input handlers.
    33 */
    3428
    3529#include "KeyDetector.h"
     
    6862        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    6963        {
    70             it->second->bindingString_ = callbackCommand_ + it->second->name_;
     64            it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;
    7165            it->second->parse();
    7266        }
  • code/branches/core4/src/core/input/KeyDetector.h

    r3288 r3306  
    2727 */
    2828
    29 /**
    30 @file
    31 @brief
    32     Different definitions of input processing.
    33 */
    34 
    3529#ifndef _KeyDetector_H__
    3630#define _KeyDetector_H__
Note: See TracChangeset for help on using the changeset viewer.