Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2008, 12:31:32 AM (16 years ago)
Author:
rgrieder
Message:

FIRST THINGS FIRST: Delete or rename your keybindings.ini (def_keybindings.ini already has the most important bindings) or else you won't be able to do anything!

Changes:

  • Multiple joy stick support should now fully work with KeyBinder too (only tested with 0/1 joystick)
  • Reloading the OIS Devices now works with KeyBinder too
  • Modified ConfigValueContainer to accept arbitrary section names
  • added tkeybind to temporary bind a command to a key
  • Fixed dlleport issue in ArgumentCompletionFunctions.h

Internal changes:

  • General cleanup in initialisation of KeyBinder
  • All names of keys/buttons/axes are now statically saved in InputInterfaces.h
  • Move a magic value in KeyBinder to a configValue (MouseWheelStepSize_)
  • Separated ConfigValues from Keybinding ConfigValueContainer in KeyBinder (looks much nicer now ;))
  • Moved some performance critical small function to the inline section
  • Removed the ugly keybind function construct from the InputManager
  • More 'harmonising' work in KeyBinder
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/input/InputManager.cc

    r1881 r1887  
    5656#include "SimpleInputState.h"
    5757#include "ExtendedInputState.h"
     58#include "JoyStickDeviceNumberListener.h"
    5859
    5960namespace orxonox
    6061{
    61     SetConsoleCommand(InputManager, keyBind, true);
    62     SetConsoleCommand(InputManager, storeKeyStroke, true);
    6362    SetConsoleCommand(InputManager, calibrate, true);
    6463    SetConsoleCommand(InputManager, reload, false);
     
    165164            if (joyStickSupport)
    166165                _initialiseJoySticks();
     166            // Do this anyway to also inform everyone if a joystick was detached.
     167            _configureNumberOfJoySticks();
    167168
    168169            // Set mouse/joystick region
     
    197198            stateMaster_ = new ExtendedInputState();
    198199            stateMaster_->setName("master");
     200            stateMaster_->setNumOfJoySticks(joySticksSize_);
    199201
    200202            // KeyDetector to evaluate a pressed key's name
    201203            SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101);
    202204            keyDetector_ = new KeyDetector();
    203             keyDetector_->loadBindings("storeKeyStroke");
    204205            detector->setHandler(keyDetector_);
    205206
     
    320321            //CCOUT(ORX_WARNING) << "Warning: Joy stick support requested, but no joy stick was found" << std::endl;
    321322        }
    322         _redimensionLists();
    323323    }
    324324
     
    331331        occupy 2 places in the device number dependent lists.
    332332    */
    333     void InputManager::_redimensionLists()
     333    void InputManager::_configureNumberOfJoySticks()
    334334    {
    335335        joySticksSize_ = joySticks_.size();
     
    357357        for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
    358358            it != inputStatesByPriority_.end(); ++it)
     359        {
    359360            it->second->setNumOfJoySticks(joySticksSize_);
     361        }
     362        // inform master state
     363        if (stateMaster_)
     364            this->stateMaster_->setNumOfJoySticks(joySticksSize_);
     365
     366        // inform all JoyStick Device Number Listeners
     367        for (ObjectList<JoyStickDeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it)
     368            it->JoyStickDeviceNumberChanged(joySticksSize_);
     369
    360370    }
    361371
     
    385395            if (!cont)
    386396            {
    387                 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffPos", coeffPos);
     397                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "CoeffPos", coeffPos);
    388398                getIdentifier()->addConfigValueContainer("CoeffPos", cont);
    389399            }
     
    393403            if (!cont)
    394404            {
    395                 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffNeg", coeffNeg);
     405                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "CoeffNeg", coeffNeg);
    396406                getIdentifier()->addConfigValueContainer("CoeffNeg", cont);
    397407            }
     
    401411            if (!cont)
    402412            {
    403                 cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "Zero", zero);
     413                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), getIdentifier()->getName(), "Zero", zero);
    404414                getIdentifier()->addConfigValueContainer("Zero", cont);
    405415            }
     
    515525
    516526            joySticks_.clear();
    517             // don't use _redimensionLists(), might mess with registered handler if
     527            // don't use _configureNumberOfJoySticks(), might mess with registered handler if
    518528            // downgrading from 2 to 1 joystick
    519             //_redimensionLists();
     529            //_configureNumberOfJoySticks();
    520530            joySticksSize_ = 0;
    521531        }
     
    875885        // check whether the key already is in the list (can happen when focus was lost)
    876886        unsigned int iKey = 0;
    877         while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key)
     887        while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::ByEnum)e.key)
    878888            iKey++;
    879889        if (iKey == keysDown_.size())
     
    912922        for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    913923        {
    914             if (keysDown_[iKey].key == (KeyCode::Enum)e.key)
     924            if (keysDown_[iKey].key == (KeyCode::ByEnum)e.key)
    915925            {
    916926                keysDown_.erase(keysDown_.begin() + iKey);
     
    977987        // check whether the button already is in the list (can happen when focus was lost)
    978988        unsigned int iButton = 0;
    979         while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id)
     989        while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButtonCode::ByEnum)id)
    980990            iButton++;
    981991        if (iButton == mouseButtonsDown_.size())
    982             mouseButtonsDown_.push_back((MouseButton::Enum)id);
    983 
    984         activeStatesTop_[Mouse]->mouseButtonPressed((MouseButton::Enum)id);
    985         stateMaster_->mouseButtonPressed((MouseButton::Enum)id);
     992            mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id);
     993
     994        activeStatesTop_[Mouse]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
     995        stateMaster_->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    986996
    987997        return true;
     
    10011011        for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    10021012        {
    1003             if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id)
     1013            if (mouseButtonsDown_[iButton] == (MouseButtonCode::ByEnum)id)
    10041014            {
    10051015                mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton);
     
    10081018        }
    10091019
    1010         activeStatesTop_[Mouse]->mouseButtonReleased((MouseButton::Enum)id);
    1011         stateMaster_->mouseButtonReleased((MouseButton::Enum)id);
     1020        activeStatesTop_[Mouse]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
     1021        stateMaster_->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    10121022
    10131023        return true;
     
    10381048
    10391049        // check whether the button already is in the list (can happen when focus was lost)
    1040         std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
     1050        std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
    10411051        unsigned int iButton = 0;
    10421052        while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
    10431053            iButton++;
    10441054        if (iButton == buttonsDown.size())
    1045             buttonsDown.push_back((JoyStickButton::Enum)button);
    1046 
    1047         activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButton::Enum)button);
    1048         stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButton::Enum)button);
     1055            buttonsDown.push_back((JoyStickButtonCode::ByEnum)button);
     1056
     1057        activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1058        stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    10491059
    10501060        return true;
     
    10561066
    10571067        // remove the button from the joyStickButtonsDown_ list
    1058         std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
     1068        std::vector<JoyStickButtonCode::ByEnum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
    10591069        for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
    10601070        {
     
    10661076        }
    10671077
    1068         activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButton::Enum)button);
    1069         stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButton::Enum)button);
     1078        activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1079        stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    10701080
    10711081        return true;
     
    11771187    }
    11781188
     1189    /**
     1190    @brief
     1191        Sets the the name of the command used by the KeyDetector as callback.
     1192    @param command
     1193        Command name as string
     1194    */
     1195    void InputManager::setKeyDetectorCallback(const std::string& command)
     1196    {
     1197        this->keyDetector_->setCallbackCommand(command);
     1198    }
    11791199
    11801200    // ###### InputStates ######
     
    13561376    /**
    13571377    @brief
    1358         Method for easily storing a string with the command executor. It is used by the
    1359         KeyDetector to get assign commands. The KeyDetector simply executes
    1360         the command 'storeKeyStroke myName' for each button/axis.
    1361     @remarks
    1362         This is only a temporary hack until we thourouhgly support multiple KeyBinders.
    1363     @param name
    1364         The name of the button/axis.
    1365     */
    1366     void InputManager::storeKeyStroke(const std::string& name)
    1367     {
    1368         getInstance().requestLeaveState("detector");
    1369         COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl;
    1370         CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false);
    1371     }
    1372 
    1373     /**
    1374     @brief
    1375         Assigns a command string to a key/button/axis. The name is determined via KeyDetector
    1376         and InputManager::storeKeyStroke(.).
    1377     @param command
    1378         Command string that can be executed by the CommandExecutor
    1379     */
    1380     void InputManager::keyBind(const std::string& command)
    1381     {
    1382         bindingCommmandString_s = command;
    1383         getInstance().requestEnterState("detector");
    1384         COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    1385     }
    1386 
    1387     /**
    1388     @brief
    13891378        Starts joy stick calibration.
    13901379    */
Note: See TracChangeset for help on using the changeset viewer.