Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5663 for code/branches


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.

Location:
code/branches/resource2/src/core/input
Files:
4 edited

Legend:

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

    r3327 r5663  
    5959        nCommands_[1]=0;
    6060        nCommands_[2]=0;
    61         this->configContainer_ = 0;
    6261    }
    6362
  • 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        {
  • code/branches/resource2/src/core/input/KeyBinder.h

    r3327 r5663  
    4141#include <string>
    4242#include <vector>
     43#include <boost/shared_ptr.hpp>
    4344
    4445#include "InputHandler.h"
     
    115116        };
    116117        //! Actual key bindings for joy stick buttons
    117         std::vector<JoyStickButtonVector> joyStickButtons_;
     118        std::vector<shared_ptr<JoyStickButtonVector> > joyStickButtons_;
    118119        //! Helper class to use something like std:vector<HalfAxis[48]>
    119120        struct JoyStickAxisVector
     
    123124        };
    124125        //! Actual key bindings for joy stick axes (and sliders)
    125         std::vector<JoyStickAxisVector> joyStickAxes_;
     126        std::vector<shared_ptr<JoyStickAxisVector> > joyStickAxes_;
    126127
    127128        //! Pointer map with all Buttons, including half axes
     
    191192
    192193    inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button)
    193     { joyStickButtons_[device][button].execute(KeybindMode::OnPress); }
     194    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress); }
    194195
    195196    inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button)
    196     { joyStickButtons_[device][button].execute(KeybindMode::OnRelease); }
     197    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease); }
    197198
    198199    inline void KeyBinder::buttonHeld    (unsigned int device, JoyStickButtonCode::ByEnum button)
    199     { joyStickButtons_[device][button].execute(KeybindMode::OnHold); }
     200    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnHold); }
    200201
    201202    inline void KeyBinder::allDevicesUpdated(float dt)
  • code/branches/resource2/src/core/input/KeyDetector.cc

    r3327 r5663  
    7070    {
    7171        KeyBinder::JoyStickQuantityChanged(joyStickList);
    72         setCallbackCommand(callbackCommand_);
     72        if (!callbackCommand_.empty())
     73            setCallbackCommand(callbackCommand_);
    7374    }
    7475}
Note: See TracChangeset for help on using the changeset viewer.