Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 19, 2009, 9:30:05 PM (15 years ago)
Author:
rgrieder
Message:

Fixed a known bug that occurred when reloading the inputmanager with a new joy stick plugged in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/core/input/KeyBinder.cc

    r3327 r5663  
    5555        mousePosition_[0] = 0;
    5656        mousePosition_[1] = 0;
    57 
    58         joyStickButtons_.reserve(1000);
    59         joyStickAxes_.reserve(1000);
    6057
    6158        RegisterRootObject(KeyBinder);
     
    167164            {
    168165                for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
    169                     joyStickButtons_[iDev][i].readConfigValue(this->configFile_);
     166                    (*joyStickButtons_[iDev])[i].readConfigValue(this->configFile_);
    170167                for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
    171                     joyStickAxes_[iDev][i].readConfigValue(this->configFile_);
     168                    (*joyStickAxes_[iDev])[i].readConfigValue(this->configFile_);
    172169            }
    173170        }
     
    179176    void KeyBinder::initialiseJoyStickBindings()
    180177    {
     178        while (joyStickAxes_.size() < joySticks_.size())
     179            joyStickAxes_.push_back(shared_ptr<JoyStickAxisVector>(new JoyStickAxisVector()));
     180        while (joyStickButtons_.size() < joySticks_.size())
     181            joyStickButtons_.push_back(shared_ptr<JoyStickButtonVector>(new JoyStickButtonVector()));
     182        // For the case the new size is smaller
    181183        this->joyStickAxes_.resize(joySticks_.size());
    182184        this->joyStickButtons_.resize(joySticks_.size());
     
    189191            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    190192            {
    191                 joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i];
    192                 joyStickButtons_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
    193                 joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName;
     193                (*joyStickButtons_[iDev])[i].name_ = JoyStickButtonCode::ByString[i];
     194                (*joyStickButtons_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
     195                (*joyStickButtons_[iDev])[i].groupName_ = "JoyStickButtons_" + deviceName;
    194196            }
    195197            // joy stick axes
    196198            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    197199            {
    198                 joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2];
     200                (*joyStickAxes_[iDev])[i].name_ = JoyStickAxisCode::ByString[i / 2];
    199201                if (i & 1)
    200                     joyStickAxes_[iDev][i].name_ += "Pos";
     202                    (*joyStickAxes_[iDev])[i].name_ += "Pos";
    201203                else
    202                     joyStickAxes_[iDev][i].name_ += "Neg";
    203                 joyStickAxes_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
    204                 joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName;
     204                    (*joyStickAxes_[iDev])[i].name_ += "Neg";
     205                (*joyStickAxes_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
     206                (*joyStickAxes_[iDev])[i].groupName_ = "JoyStickAxes_" + deviceName;
    205207            }
    206208        }
     
    226228        {
    227229            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    228                 allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
     230                allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + "." + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
    229231            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    230232            {
    231                 allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
    232                 allHalfAxes_.push_back(&(joyStickAxes_[iDev][i]));
     233                allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + "." + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
     234                allHalfAxes_.push_back(&((*joyStickAxes_[iDev])[i]));
    233235            }
    234236        }
     
    303305            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    304306            {
    305                 joyStickAxes_[iDev][i].absVal_ = 0.0f;
    306                 joyStickAxes_[iDev][i].relVal_ = 0.0f;
     307                (*joyStickAxes_[iDev])[i].absVal_ = 0.0f;
     308                (*joyStickAxes_[iDev])[i].relVal_ = 0.0f;
    307309            }
    308310        }
     
    366368        for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    367369        {
    368             tickHalfAxis(joyStickAxes_[joyStick][i]);
     370            tickHalfAxis((*joyStickAxes_[joyStick])[i]);
    369371        }
    370372    }
     
    481483    {
    482484        int i = axisID * 2;
    483         JoyStickAxisVector& axis = joyStickAxes_[device];
     485        JoyStickAxisVector& axis = *joyStickAxes_[device];
    484486        if (value < 0)
    485487        {
Note: See TracChangeset for help on using the changeset viewer.