Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1887 for code/trunk/src


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
Location:
code/trunk/src
Files:
2 added
30 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/ArgumentCompletionFunctions.h

    r1505 r1887  
    3535
    3636#define ARGUMENT_COMPLETION_FUNCTION_DECLARATION(functionname) \
    37     ArgumentCompleter* functionname(); \
     37    _CoreExport ArgumentCompleter* functionname(); \
    3838    _CoreExport ArgumentCompletionList acf_##functionname
    3939
  • code/trunk/src/core/CMakeLists.txt

    r1844 r1887  
    4747  input/InputCommands.cc
    4848  input/InputManager.cc
     49  input/JoyStickDeviceNumberListener.cc
    4950  input/KeyBinder.cc
    5051  input/KeyDetector.cc
  • code/trunk/src/core/ConfigFileManager.h

    r1795 r1887  
    4545        CFT_Settings,
    4646        CFT_Keybindings,
    47         CFT_JoyStickCalibration,
    48         CFT_KeyNames
     47        CFT_JoyStickCalibration
    4948    };
    5049
  • code/trunk/src/core/ConfigValueContainer.cc

    r1795 r1887  
    5050        @brief Initializes the ConfigValueContainer with defaultvalues.
    5151    */
    52     void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& varname)
     52    void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname)
    5353    {
    5454        this->type_ = type;
    5555        this->identifier_ = identifier;
    56         this->sectionname_ = identifier->getName();
     56        this->sectionname_ = sectionname;
    5757        this->varname_ = varname;
    5858        this->callback_ = 0;
     
    331331        if (!this->bAddedDescription_)
    332332        {
    333             this->description_ = std::string("ConfigValueDescription::" + this->identifier_->getName() + "::" + this->varname_);
     333            this->description_ = std::string("ConfigValueDescription::" + this->sectionname_ + "::" + this->varname_);
    334334            AddLanguageEntry(this->description_, description);
    335335            this->bAddedDescription_ = true;
  • code/trunk/src/core/ConfigValueContainer.h

    r1747 r1887  
    9999                @param type The type of the corresponding config-file
    100100                @param identifier The identifier of the class the variable belongs to
     101                @param sectionname Name of the section the configValue should be put in.
    101102                @param varname The name of the variable
    102103                @param defvalue The default-value
     
    104105            */
    105106            template <class D, class V>
    106             ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const D& defvalue, const V& value)
    107             {
    108                 this->init(type, identifier, varname);
     107            ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const D& defvalue, const V& value)
     108            {
     109                this->init(type, identifier, sectionname, varname);
    109110                this->initValue((V)defvalue);
    110111            }
     
    118119            */
    119120            template <class V>
    120             ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<V>& defvalue)
    121             {
    122                 this->init(type, identifier, varname);
     121            ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<V>& defvalue)
     122            {
     123                this->init(type, identifier, sectionname, varname);
    123124
    124125                this->value_ = V();
     
    266267
    267268        private:
    268             void init(ConfigFileType type, Identifier* identifier, const std::string& varname);
     269            void init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname);
    269270            void initValue(const MultiType& defvalue);
    270271            void initVector();
  • code/trunk/src/core/ConfigValueIncludes.h

    r1747 r1887  
    5252    if (!container##varname) \
    5353    { \
    54         container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, defvalue, varname); \
     54        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, identifier##varname->getName(), #varname, defvalue, varname); \
    5555        identifier##varname->addConfigValueContainer(#varname, container##varname); \
    5656    } \
     
    7171    if (!container##varname) \
    7272    { \
    73         container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, defvalue); \
     73        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, identifier##varname->getName(), #varname, defvalue); \
    7474        identifier##varname->addConfigValueContainer(#varname, container##varname); \
    7575    } \
  • code/trunk/src/core/input/Button.cc

    r1783 r1887  
    3434
    3535#include "Button.h"
     36
    3637#include "util/Convert.h"
    3738#include "util/SubString.h"
     
    4142#include "core/CommandEvaluation.h"
    4243#include "core/CommandExecutor.h"
    43 #include "InputCommands.h"
     44#include "core/ConfigValueContainer.h"
    4445
    4546namespace orxonox
    4647{
     48    /**
     49    @note
     50        bButtonThresholdUser_: We set it to true so that setConfigValues in KeyBinder sets the value
     51        correctly the first time. It is then set to false first and changed later in Button::parse().
     52    */
     53    Button::Button()
     54        : configContainer_(0)
     55        , bButtonThresholdUser_(false)
     56        , paramCommandBuffer_(0)
     57    {
     58        nCommands_[0]=0;
     59        nCommands_[1]=0;
     60        nCommands_[2]=0;
     61        clear();
     62    }
     63
    4764    void Button::clear()
    4865    {
     
    6582    }
    6683
    67     void Button::parse(std::vector<BufferedParamCommand*>& paramCommandBuffer)
    68     {
     84    void Button::readConfigValue()
     85    {
     86        // create/get ConfigValueContainer
     87        if (!configContainer_)
     88        {
     89            configContainer_ = new ConfigValueContainer(CFT_Keybindings, 0, groupName_, name_, "", name_);
     90            configContainer_->callback(this, &Button::parse);
     91        }
     92        configContainer_->getValue(&bindingString_, this);
     93    }
     94
     95    void Button::parse()
     96    {
     97        // delete all commands
     98        clear();
     99
    69100        if (isEmpty(bindingString_))
    70         {
    71             clear();
    72101            return;
    73         }
     102
     103        // reset this to false first when parsing (was true before when parsing for the first time)
     104        bButtonThresholdUser_ = false;
    74105
    75106        // use std::vector for a temporary dynamic array
    76107        std::vector<BaseCommand*> commands[3];
    77 
    78108
    79109        // separate the commands
     
    112142                            parseError("Could not parse 'ButtonThreshold' argument. \
    113143                                Switching to default value.", true);
     144                        else
     145                            this->bButtonThresholdUser_ = true;
    114146                    }
    115147                    else if (token == "scale")
     
    152184
    153185                    // add command to the buffer if not yet existing
    154                     for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer.size(); iParamCmd++)
    155                     {
    156                         if (getLowercase(paramCommandBuffer[iParamCmd]->evaluation_.getOriginalCommand())
     186                    for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer_->size(); iParamCmd++)
     187                    {
     188                        if (getLowercase((*paramCommandBuffer_)[iParamCmd]->evaluation_.getOriginalCommand())
    157189                            == getLowercase(commandStr))
    158190                        {
    159191                            // already in list
    160                             cmd->paramCommand_ = paramCommandBuffer[iParamCmd];
     192                            cmd->paramCommand_ = (*paramCommandBuffer_)[iParamCmd];
    161193                            break;
    162194                        }
     
    165197                    {
    166198                        cmd->paramCommand_ = new BufferedParamCommand();
    167                         paramCommandBuffer.push_back(cmd->paramCommand_);
     199                        paramCommandBuffer_->push_back(cmd->paramCommand_);
    168200                        cmd->paramCommand_->evaluation_ = eval;
    169201                        cmd->paramCommand_->paramIndex_ = paramIndex;
     
    208240    }
    209241
    210     bool Button::execute(KeybindMode::Enum mode, float abs, float rel)
    211     {
    212         // execute all the parsed commands in the string
    213         for (unsigned int iCommand = 0; iCommand < nCommands_[mode]; iCommand++)
    214             commands_[mode][iCommand]->execute(abs, rel);
    215         return true;
    216     }
    217 
    218242    inline void Button::parseError(std::string message, bool serious)
    219243    {
  • code/trunk/src/core/input/Button.h

    r1755 r1887  
    4040#include <string>
    4141#include <vector>
     42#include "InputCommands.h"
    4243
    4344namespace orxonox
     
    4647    {
    4748    public:
    48         Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); }
     49        Button();
    4950        virtual ~Button() { clear(); }
    5051        virtual void clear();
    5152        virtual bool addParamCommand(ParamCommand* command) { return false; }
    52         void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer);
     53        void parse();
     54        void readConfigValue();
    5355        bool execute(KeybindMode::Enum mode, float abs = 1.0f, float rel = 1.0f);
    5456
     57        //! Container to allow for better configValue support
     58        ConfigValueContainer* configContainer_;
    5559        //! The configured string value
    5660        std::string bindingString_;
    5761        //! Name of the trigger as strings
    5862        std::string name_;
     63        //! Name of the group of input triggers
     64        std::string groupName_;
    5965        //! Basic commands for OnPress, OnHold and OnRelease
    6066        BaseCommand** commands_[3];
     
    6470        //! Note: This variable is here to have only one parse() function.
    6571        float buttonThreshold_;
     72        bool bButtonThresholdUser_;
     73        //! Pointer to the list of parametrised commands
     74        std::vector<BufferedParamCommand*>* paramCommandBuffer_;
    6675
    6776    private:
    6877        void parseError(std::string message, bool serious);
    6978    };
     79
     80    inline bool Button::execute(KeybindMode::Enum mode, float abs, float rel)
     81    {
     82        // execute all the parsed commands in the string
     83        for (unsigned int iCommand = 0; iCommand < nCommands_[mode]; iCommand++)
     84            commands_[mode][iCommand]->execute(abs, rel);
     85        return true;
     86    }
     87
    7088}
    7189
  • code/trunk/src/core/input/ExtendedInputState.cc

    r1881 r1887  
    9292    }
    9393
    94     void ExtendedInputState::mouseButtonPressed(MouseButton::Enum id)
     94    void ExtendedInputState::mouseButtonPressed(MouseButtonCode::ByEnum id)
    9595    {
    9696        for (unsigned int i = 0; i < mouseHandlers_.size(); i++)
     
    9898    }
    9999
    100     void ExtendedInputState::mouseButtonReleased(MouseButton::Enum id)
     100    void ExtendedInputState::mouseButtonReleased(MouseButtonCode::ByEnum id)
    101101    {
    102102        for (unsigned int i = 0; i < mouseHandlers_.size(); i++)
     
    104104    }
    105105
    106     void ExtendedInputState::mouseButtonHeld(MouseButton::Enum id)
     106    void ExtendedInputState::mouseButtonHeld(MouseButtonCode::ByEnum id)
    107107    {
    108108        for (unsigned int i = 0; i < mouseHandlers_.size(); i++)
     
    118118    }
    119119
    120     void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton::Enum id)
     120    void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
    121121    {
    122122        assert(joyStickID < joyStickHandlers_.size());
     
    125125    }
    126126
    127     void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
     127    void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
    128128    {
    129129        assert(joyStickID < joyStickHandlers_.size());
     
    132132    }
    133133
    134     void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton::Enum id)
     134    void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
    135135    {
    136136        assert(joyStickID < joyStickHandlers_.size());
  • code/trunk/src/core/input/ExtendedInputState.h

    r1881 r1887  
    7575        void keyHeld    (const KeyEvent& evt);
    7676
    77         void mouseButtonPressed (MouseButton::Enum id);
    78         void mouseButtonReleased(MouseButton::Enum id);
    79         void mouseButtonHeld    (MouseButton::Enum id);
     77        void mouseButtonPressed (MouseButtonCode::ByEnum id);
     78        void mouseButtonReleased(MouseButtonCode::ByEnum id);
     79        void mouseButtonHeld    (MouseButtonCode::ByEnum id);
    8080        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    8181        void mouseScrolled      (int abs, int rel);
    8282
    83         void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
    84         void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
    85         void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
     83        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     84        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     85        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
    8686        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);        void updateTickables();
    8787
  • code/trunk/src/core/input/HalfAxis.cc

    r1755 r1887  
    3535#include "HalfAxis.h"
    3636#include "core/CommandEvaluation.h"
    37 #include "InputCommands.h"
    3837
    3938namespace orxonox
     
    6867        return true;
    6968    }
    70 
    71     bool HalfAxis::execute()
    72     {
    73         bool success = true;
    74         for (unsigned int i = 0; i < nParamCommands_; i++)
    75             success = success && paramCommands_[i]->execute(absVal_, relVal_);
    76         return success;
    77     }
    7869}
  • code/trunk/src/core/input/HalfAxis.h

    r1755 r1887  
    3838#include "core/CorePrereqs.h"
    3939#include "Button.h"
     40#include "InputCommands.h"
    4041
    4142namespace orxonox
     
    6768        bool hasChanged_;
    6869    };
     70
     71    inline bool HalfAxis::execute()
     72    {
     73        bool success = true;
     74        for (unsigned int i = 0; i < nParamCommands_; i++)
     75            success = paramCommands_[i]->execute(absVal_, relVal_) && success;
     76        return success;
     77    }
    6978}
    7079
  • code/trunk/src/core/input/InputBuffer.h

    r1755 r1887  
    4444    public:
    4545        BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput,
    46             bool trueKeyFalseChar, char _char, KeyCode::Enum key)
     46            bool trueKeyFalseChar, char _char, KeyCode::ByEnum key)
    4747            : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput),
    4848              trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key)
     
    5454        bool trueKeyFalseChar_;
    5555        char char_;
    56         KeyCode::Enum key_;
     56        KeyCode::ByEnum key_;
    5757    };
    5858
     
    6262    public:
    6363        InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges,
    64             bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key)
     64            bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::ByEnum key)
    6565            : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key),
    6666              listener_(listener), function_(function)
     
    109109
    110110            template <class T>
    111             void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key)
     111            void registerListener(T* listener, void (T::*function)(), KeyCode::ByEnum key)
    112112            {
    113113                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);
     
    115115            }
    116116            template <class T>
    117             void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key)
     117            void registerListener(T* listener, void (T::*function)() const, KeyCode::ByEnum key)
    118118            {
    119119                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);
     
    178178            unsigned int cursor_;
    179179
    180             KeyCode::Enum lastKey_;
     180            KeyCode::ByEnum lastKey_;
    181181            float timeSinceKeyPressed_;
    182182            float timeSinceKeyRepeated_;
  • code/trunk/src/core/input/InputCommands.cc

    r1755 r1887  
    6565
    6666    // ###############################
    67     // #####    SimpleCommand    #####
    68     // ###############################
    69 
    70     /**
    71     @brief
    72         Executes a simple command with no additional paramters.
    73     @return
    74         True if command execution was successful, false otherwise.
    75     */
    76     bool SimpleCommand::execute(float abs, float rel)
    77     {
    78         return evaluation_.execute();
    79     }
    80 
    81     // ###############################
    8267    // #####    ParamCommand     #####
    8368    // ###############################
  • code/trunk/src/core/input/InputCommands.h

    r1755 r1887  
    6868    };
    6969
     70    /**
     71    @brief
     72        Executes a simple command with no additional paramters.
     73    @return
     74        True if command execution was successful, false otherwise.
     75    */
     76    inline bool SimpleCommand::execute(float abs, float rel)
     77    {
     78        return evaluation_.execute();
     79    }
     80
    7081    class _CoreExport ParamCommand : public BaseCommand
    7182    {
  • code/trunk/src/core/input/InputInterfaces.h

    r1878 r1887  
    4747    namespace KeyCode
    4848    {
     49        const unsigned int numberOfKeys = 0xEE; // 238
     50
    4951        // note: KeyCode comments were directly copied from OISKeyboard.h
    50         enum Enum
     52        enum ByEnum
    5153        {
    5254            Unassigned    = OIS::KC_UNASSIGNED,
     
    119121            F9            = OIS::KC_F9,
    120122            F10           = OIS::KC_F10,
    121             Numlock       = OIS::KC_NUMLOCK,
    122             Scrolllock    = OIS::KC_SCROLL,          // Scroll Lock
     123            NumLock       = OIS::KC_NUMLOCK,
     124            ScrollLock    = OIS::KC_SCROLL,          // Scroll Lock
    123125            Numpad7       = OIS::KC_NUMPAD7,
    124126            Numpad8       = OIS::KC_NUMPAD8,
     
    167169            NumpadComma   = OIS::KC_NUMPADCOMMA,     // , on numeric keypad (NEC PC98)
    168170            Divide        = OIS::KC_DIVIDE,          // / on numeric keypad
    169             SYSRQ        = OIS::KC_SYSRQ,
     171            SystemRequest = OIS::KC_SYSRQ,
    170172            RightAlt      = OIS::KC_RMENU,           // right Alt
    171173            Pause         = OIS::KC_PAUSE,           // Pause
     
    196198            MediaSelect   = OIS::KC_MEDIASELECT      // Media Select
    197199        };
    198     }
    199 
    200     namespace MouseButton
    201     {
    202         enum Enum
     200       
     201        // Names as string. Has no real linkage!
     202        const char* const ByString[] =
     203        {
     204            "Unassigned",
     205            "Escape",
     206            "NumRow1", "NumRow2", "NumRow3", "NumRow4", "NumRow5",
     207            "NumRow6", "NumRow7", "NumRow8", "NumRow9", "NumRow0",
     208            "Minus", "Equals", "Back", "Tab",
     209            "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
     210            "LeftBracket", "RightBracket",
     211            "Return", "LeftControl",
     212            "A", "S", "D", "F", "G", "H", "J", "K", "L",
     213            "Semicolon", "Apostrophe", "Grave",
     214            "LeftShift", "Backslash",
     215            "Z", "X", "C", "V", "B", "N", "M",
     216            "Comma", "Period", "Slash",
     217            "RightShift",
     218            "Multiply",
     219            "LeftAlt",
     220            "Space",
     221            "CapsLock",
     222            "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",
     223            "NumLock", "ScrollLock",
     224            "Numpad7", "Numpad8", "Numpad9",
     225            "NumpadSubtract",
     226            "Numpad4", "Numpad5", "Numpad6",
     227            "NumpadAdd",
     228            "Numpad1", "Numpad2", "Numpad3", "Numpad0",
     229            "NumpadPeriod",
     230            "","",
     231            "LessThan",
     232            "F11", "F12",
     233            "","","","","","","","","","","",
     234            "F13", "F14", "F15",
     235            "","","","","","","","","","",
     236            "Kana",
     237            "","",
     238            "ABNT_C1",
     239            "","","","","",
     240            "Convert",
     241            "",
     242            "NoConvert",
     243            "",
     244            "Yen",
     245            "ABNT_C2",
     246            "","","","","","","","","","","","","","",
     247            "NumpadEquals",
     248            "","",
     249            "PreviousTrack",
     250            "AT",
     251            "Colon", "Underline",
     252            "Kanji",
     253            "Stop",
     254            "AX",
     255            "Unlabeled",
     256            "NextTrack",
     257            "","",
     258            "NumpadEnter",
     259            "RightControl",
     260            "","",
     261            "Mute",
     262            "Calculator",
     263            "PlayPause",
     264            "",
     265            "MediaStop",
     266            "","","","","","","","","",
     267            "VolumeDown",
     268            "",
     269            "VolumeUp",
     270            "",
     271            "WebHome",
     272            "NumpadComma",
     273            "",
     274            "Divide",
     275            "",
     276            "SystemRequest",
     277            "RightAlt",
     278            "","","","","","","","","","","","",
     279            "Pause",
     280            "",
     281            "Home",
     282            "UP",
     283            "PageUp",
     284            "",
     285            "Left",
     286            "",
     287            "Right",
     288            "",
     289            "End", "Down", "PageDown", "Insert", "Delete",
     290            "","","","","","","",
     291            "LeftWindows", "RightWindows", "Apps",
     292            "Power", "Sleep",
     293            "","","",
     294            "Wake",
     295            "",
     296            "WebSearch", "WebFavorites", "WebRefresh", "WebStop", "WebForward", "WebBack",
     297            "MyComputer", "Mail", "MediaSelect"
     298        };
     299    }
     300
     301    namespace MouseButtonCode
     302    {
     303        const unsigned int numberOfButtons = 8;
     304
     305        enum ByEnum
    203306        {
    204307            Left    = OIS::MB_Left,
     
    209312            Button5 = OIS::MB_Button5,
    210313            Button6 = OIS::MB_Button6,
    211             Button7 = OIS::MB_Button7
    212         };
    213     }
    214 
    215     namespace JoyStickButton
    216     {
    217         enum Enum
     314            Button7 = OIS::MB_Button7,
     315        };
     316
     317        // Names as string. Has no real linkage!
     318        const char* const ByString[] =
     319        {
     320            "Left",
     321            "Right",
     322            "Middle",
     323            "Button3",
     324            "Button4",
     325            "Button5",
     326            "Button6",
     327            "Button7",
     328        };
     329    }
     330
     331    namespace MouseAxisCode
     332    {
     333        const unsigned int numberOfAxes = 2;
     334
     335        enum ByEnum
     336        {
     337            X,
     338            Y
     339        };
     340
     341        // Names as string. Has no real linkage!
     342        const char* const ByString[] =
     343        {
     344            "X",
     345            "Y"
     346        };
     347    }
     348
     349    namespace JoyStickButtonCode
     350    {
     351        const unsigned int numberOfButtons = 64;
     352
     353        enum ByEnum
    218354        {
    219355            Button0       =  0, Button1       =  1, Button2       =  2, Button3       =  3,
     
    238374            POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63,
    239375        };
     376
     377        // Names as string. Has no real linkage!
     378        const char* const ByString[] =
     379        {
     380            "Button0",       "Button1",       "Button2",       "Button3",
     381            "Button4",       "Button5",       "Button6",       "Button7",
     382            "Button8",       "Button9",       "Button10",      "Button11",
     383            "Button12",      "Button13",      "Button14",      "Button15",
     384            "Button16",      "Button17",      "Button18",      "Button19",
     385            "Button20",      "Button21",      "Button22",      "Button23",
     386            "Button24",      "Button25",      "Button26",      "Button27",
     387            "Button28",      "Button29",      "Button30",      "Button31",
     388            "POV0North",     "POV0South",     "POV0East",      "POV0West",
     389            "POV0NorthEast", "POV0SouthEast", "POV0NorthWest", "POV0SouthWest",
     390            "POV1North",     "POV1South",     "POV1East",      "POV1West",
     391            "POV1NorthEast", "POV1SouthEast", "POV1NorthWest", "POV1SouthWest",
     392            "POV2North",     "POV2South",     "POV2East",      "POV2West",
     393            "POV2NorthEast", "POV2SouthEast", "POV2NorthWest", "POV2SouthWest",
     394            "POV3North",     "POV3South",     "POV3East",      "POV3West",
     395            "POV3NorthEast", "POV3SouthEast", "POV3NorthWest", "POV3SouthWest"
     396        };
     397    }
     398
     399    namespace JoyStickAxisCode
     400    {
     401        const unsigned int numberOfAxes = 24;
     402
     403        enum ByEnum
     404        {
     405            Slider0 =  0, Slider1 =  1, Slider2 =  2, Slider3 =  3,
     406            Slider4 =  4, Slider5 =  5, Slider6 =  6, Slider7 =  7,
     407            Axis0   =  8, Axis1   =  9, Axis2   = 10, Axis3   = 11,
     408            Axis4   = 12, Axis5   = 13, Axis6   = 14, Axis7   = 15,
     409            Axis8   = 16, Axis9   = 17, Axis10  = 18, Axis11  = 19,
     410            Axis12  = 20, Axis13  = 21, Axis14  = 22, Axis15  = 23
     411        };
     412
     413        // Names as string. Has no real linkage!
     414        const char* const ByString[] =
     415        {
     416            "Slider0", "Slider1", "Slider2", "Slider3",
     417            "Slider4", "Slider5", "Slider6", "Slider7",
     418            "Axis0",   "Axis1",   "Axis2",   "Axis3",
     419            "Axis4",   "Axis5",   "Axis6",   "Axis7",
     420            "Axis8",   "Axis9",   "Axis10",  "Axis11",
     421            "Axis12",  "Axis13",  "Axis14",  "Axis15"
     422        };
    240423    }
    241424
     
    259442            JoyStick1,
    260443            JoyStick2,
    261             JoyStick3,
     444            JoyStick3
    262445            // note: No problem if there are more joy sticks. This enum is just for convenience.
    263446        };
     
    266449    struct _CoreExport Key
    267450    {
    268         Key(const OIS::KeyEvent& evt) : key((KeyCode::Enum)evt.key), text(evt.text) { }
    269         KeyCode::Enum key;
     451        Key(const OIS::KeyEvent& evt) : key((KeyCode::ByEnum)evt.key), text(evt.text) { }
     452        KeyCode::ByEnum key;
    270453        unsigned int text;
    271454    };
     
    274457    {
    275458    public:
    276         KeyEvent(KeyCode::Enum key, unsigned int text) : key(key), text(text) { }
     459        KeyEvent(KeyCode::ByEnum key, unsigned int text) : key(key), text(text) { }
    277460        KeyEvent(const OIS::KeyEvent& evt, unsigned int mod)
    278             : key((KeyCode::Enum)evt.key), text(evt.text), modifiers(mod) { }
     461            : key((KeyCode::ByEnum)evt.key), text(evt.text), modifiers(mod) { }
    279462        KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { }
    280463        bool isModifierDown(KeyboardModifier::Enum modifier) const
    281464            { return (KeyboardModifier::Enum)modifier&modifiers; }
    282465
    283         const KeyCode::Enum key;
     466        const KeyCode::ByEnum key;
    284467        unsigned int text;
    285468        unsigned int modifiers;
     
    316499    public:
    317500        virtual ~MouseHandler() { }
    318         virtual void mouseButtonPressed (MouseButton::Enum id) = 0;
    319         virtual void mouseButtonReleased(MouseButton::Enum id) = 0;
    320         virtual void mouseButtonHeld    (MouseButton::Enum id) = 0;
     501        virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0;
     502        virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0;
     503        virtual void mouseButtonHeld    (MouseButtonCode::ByEnum id) = 0;
    321504        virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    322505        virtual void mouseScrolled      (int abs, int rel)     = 0;
     
    333516    public:
    334517        virtual ~JoyStickHandler() { }
    335         virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
    336         virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0;
    337         virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
     518        virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
     519        virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
     520        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
    338521        virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    339522        virtual void tickJoyStick          (float dt, unsigned int joyStick) = 0;
     
    357540        void keyHeld    (const KeyEvent& evt) { }
    358541
    359         void mouseButtonPressed (MouseButton::Enum id) { }
    360         void mouseButtonReleased(MouseButton::Enum id) { }
    361         void mouseButtonHeld    (MouseButton::Enum id) { }
     542        void mouseButtonPressed (MouseButtonCode::ByEnum id) { }
     543        void mouseButtonReleased(MouseButtonCode::ByEnum id) { }
     544        void mouseButtonHeld    (MouseButtonCode::ByEnum id) { }
    362545        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { }
    363546        void mouseScrolled      (int abs, int rel) { }
    364547
    365         void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) { }
    366         void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) { }
    367         void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) { }
     548        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) { }
     549        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) { }
     550        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) { }
    368551        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) { }
    369552    };
  • 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    */
  • code/trunk/src/core/input/InputManager.h

    r1881 r1887  
    110110        void clearBuffers();
    111111
    112         int  numberOfKeyboards() { return keyboard_ ? 1 : 0; }
    113         int  numberOfMice()      { return mouse_    ? 1 : 0; }
    114         int  numberOfJoySticks() { return joySticksSize_; }
     112        unsigned int  numberOfKeyboards() { return keyboard_ ? 1 : 0; }
     113        unsigned int  numberOfMice()      { return mouse_    ? 1 : 0; }
     114        unsigned int  numberOfJoySticks() { return joySticksSize_; }
    115115
    116116        void setWindowExtents(const int width, const int height);
     117        void setKeyDetectorCallback(const std::string& command);
    117118
    118119        template <class T>
     
    132133
    133134        // console commands
    134         static void storeKeyStroke(const std::string& name);
    135         static void keyBind(const std::string& command);
    136135        static void calibrate();
    137136        static void reload(bool joyStickSupport = true);
     
    148147        void _initialiseMouse();
    149148        void _initialiseJoySticks();
    150         void _redimensionLists();
     149        void _configureNumberOfJoySticks();
    151150
    152151        void _destroyKeyboard();
     
    223222
    224223        std::vector<Key>                    keysDown_;
    225         std::vector<MouseButton::Enum>      mouseButtonsDown_;
    226         std::vector<std::vector<JoyStickButton::Enum> >  joyStickButtonsDown_;
     224        std::vector<MouseButtonCode::ByEnum>      mouseButtonsDown_;
     225        std::vector<std::vector<JoyStickButtonCode::ByEnum> >  joyStickButtonsDown_;
    227226
    228227        static std::string                  bindingCommmandString_s;
  • code/trunk/src/core/input/InputState.h

    r1880 r1887  
    7878        virtual void keyHeld    (const KeyEvent& evt) = 0;
    7979
    80         virtual void mouseButtonPressed (MouseButton::Enum id) = 0;
    81         virtual void mouseButtonReleased(MouseButton::Enum id) = 0;
    82         virtual void mouseButtonHeld    (MouseButton::Enum id) = 0;
     80        virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0;
     81        virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0;
     82        virtual void mouseButtonHeld    (MouseButtonCode::ByEnum id) = 0;
    8383        virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    8484        virtual void mouseScrolled      (int abs, int rel) = 0;
    8585
    86         virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
    87         virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0;
    88         virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
     86        virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
     87        virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
     88        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
    8989        virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    9090
  • code/trunk/src/core/input/KeyBinder.cc

    r1795 r1887  
    4141#include "core/ConfigFileManager.h"
    4242#include "InputCommands.h"
     43#include "InputManager.h"
    4344
    4445namespace orxonox
     
    4950    */
    5051    KeyBinder::KeyBinder()
    51         : deriveTime_(0.0f)
     52        : numberOfJoySticks_(0)
     53        , deriveTime_(0.0f)
    5254    {
    5355        mouseRelative_[0] = 0;
     
    5860        RegisterRootObject(KeyBinder);
    5961
     62        // intialise all buttons and half axes to avoid creating everything with 'new'
    6063        // keys
    61         std::string keyNames[] = {
    62         "UNASSIGNED",
    63         "ESCAPE",
    64         "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
    65         "MINUS", "EQUALS", "BACK", "TAB",
    66         "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
    67         "LBRACKET", "RBRACKET",
    68         "RETURN", "LCONTROL",
    69         "A", "S", "D", "F", "G", "H", "J", "K", "L",
    70         "SEMICOLON", "APOSTROPHE", "GRAVE",
    71         "LSHIFT", "BACKSLASH",
    72         "Z", "X", "C", "V", "B", "N", "M",
    73         "COMMA", "PERIOD", "SLASH",
    74         "RSHIFT",
    75         "MULTIPLY",
    76         "LMENU",
    77         "SPACE",
    78         "CAPITAL",
    79         "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",
    80         "NUMLOCK", "SCROLL",
    81         "NUMPAD7", "NUMPAD8", "NUMPAD9",
    82         "SUBTRACT",
    83         "NUMPAD4", "NUMPAD5", "NUMPAD6",
    84         "ADD",
    85         "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD0",
    86         "DECIMAL",
    87         "","",
    88         "OEM_102",
    89         "F11", "F12",
    90         "","","","","","","","","","","",
    91         "F13", "F14", "F15",
    92         "","","","","","","","","","",
    93         "KANA",
    94         "","",
    95         "ABNT_C1",
    96         "","","","","",
    97         "CONVERT",
    98         "",
    99         "NOCONVERT",
    100         "",
    101         "YEN",
    102         "ABNT_C2",
    103         "","","","","","","","","","","","","","",
    104         "NUMPADEQUALS",
    105         "","",
    106         "PREVTRACK",
    107         "AT",
    108         "COLON", "UNDERLINE",
    109         "KANJI",
    110         "STOP",
    111         "AX",
    112         "UNLABELED",
    113         "NEXTTRACK",
    114         "","",
    115         "NUMPADENTER",
    116         "RCONTROL",
    117         "","",
    118         "MUTE",
    119         "CALCULATOR",
    120         "PLAYPAUSE",
    121         "",
    122         "MEDIASTOP",
    123         "","","","","","","","","",
    124         "VOLUMEDOWN",
    125         "",
    126         "VOLUMEUP",
    127         "",
    128         "WEBHOME",
    129         "NUMPADCOMMA",
    130         "",
    131         "DIVIDE",
    132         "",
    133         "SYSRQ",
    134         "RMENU",
    135         "","","","","","","","","","","","",
    136         "PAUSE",
    137         "",
    138         "HOME",
    139         "UP",
    140         "PGUP",
    141         "",
    142         "LEFT",
    143         "",
    144         "RIGHT",
    145         "",
    146         "END", "DOWN", "PGDOWN", "INSERT", "DELETE",
    147         "","","","","","","",
    148         "LWIN", "RWIN", "APPS",
    149         "POWER", "SLEEP",
    150         "","","",
    151         "WAKE",
    152         "",
    153         "WEBSEARCH", "WEBFAVORITES", "WEBREFRESH", "WEBSTOP", "WEBFORWARD", "WEBBACK",
    154         "MYCOMPUTER", "MAIL", "MEDIASELECT"
    155         };
    156         for (unsigned int i = 0; i < nKeys_s; i++)
    157             keys_[i].name_ = "Key" + keyNames[i];
    158 
    159         // mouse buttons
    160         std::string mouseButtonNames[] = {
    161             "MouseLeft",     "MouseRight",   "MouseMiddle",
    162             "MouseButton3",  "MouseButton4", "MouseButton5",
    163             "MouseButton6",  "MouseButton7",
    164             "MouseWheel1Up", "MouseWheel1Down",
    165             "MouseWheel2Up", "MouseWheel2Down"
    166         };
    167         for (unsigned int i = 0; i < nMouseButtons_s; i++)
    168             mouseButtons_[i].name_ = mouseButtonNames[i];
    169 
    170         // joy stick buttons
    171         for (unsigned int i = 0; i < 32; i++)
    172             joyStickButtons_[i].name_ = "JoyButton" + getConvertedValue<int, std::string>(i);
    173         for (unsigned int i = 32; i < nJoyStickButtons_s; i += 4)
    174         {
    175             joyStickButtons_[i + 0].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "North";
    176             joyStickButtons_[i + 1].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "South";
    177             joyStickButtons_[i + 2].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "East";
    178             joyStickButtons_[i + 3].name_ = "JoyPOV" + convertToString((i - 32)/4 + 1) + "West";
    179         }
    180 
    181         // half axes
    182         std::string rawNames[nHalfAxes_s/2];
    183         rawNames[0] = "MouseX";
    184         rawNames[1] = "MouseY";
    185         rawNames[2] = "Empty1";
    186         rawNames[3] = "Empty2";
    187         for (unsigned int i = 4; i < nHalfAxes_s/2; i++)
    188             rawNames[i] = "JoyAxis" + convertToString(i - 3);
    189         for (unsigned int i = 0; i < nHalfAxes_s/2; i++)
    190         {
    191             halfAxes_[i * 2 + 0].name_ = rawNames[i] + "Pos";
    192             halfAxes_[i * 2 + 1].name_ = rawNames[i] + "Neg";
    193         }
    194 
    195         for (unsigned int i = 0; i < this->nHalfAxes_s; i++)
    196             halfAxes_[i].buttonThreshold_ = buttonThreshold_;
     64        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
     65        {
     66            std::string keyname = KeyCode::ByString[i];
     67            if (!keyname.empty())
     68            {
     69                keys_[i].name_ = std::string("Key") + keyname;
     70            }
     71            else
     72            {
     73                // some keys have name "" because the code is not occupied by OIS
     74                // Use "Key_" plus the number as name to put it at the end of the config file section
     75                std::string number = convertToString(i);
     76                if (i < 100)
     77                    number.insert(0, "0");
     78                keys_[i].name_ = std::string("Key_") + number;
     79            }
     80            keys_[i].paramCommandBuffer_ = &paramCommandBuffer_;
     81            keys_[i].groupName_ = "Keys";
     82        }
     83        // mouse buttons plus 4 mouse wheel buttons only 'generated' by KeyBinder
     84        const char* const mouseWheelNames[] = { "Wheel1Down", "Wheel1Up", "Wheel2Down", "Wheel2Up" };
     85        for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
     86        {
     87            std::string nameSuffix;
     88            if (i < MouseButtonCode::numberOfButtons)
     89                nameSuffix = MouseButtonCode::ByString[i];
     90            else
     91                nameSuffix = mouseWheelNames[i - MouseButtonCode::numberOfButtons];
     92            mouseButtons_[i].name_ = std::string("Mouse") + nameSuffix;
     93            mouseButtons_[i].paramCommandBuffer_ = &paramCommandBuffer_;
     94            mouseButtons_[i].groupName_ = "MouseButtons";
     95        }
     96        // mouse axes
     97        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
     98        {
     99            mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i >> 1];
     100            if (i & 1)
     101                mouseAxes_[i].name_ += "Pos";
     102            else
     103                mouseAxes_[i].name_ += "Neg";
     104            mouseAxes_[i].paramCommandBuffer_ = &paramCommandBuffer_;
     105            mouseAxes_[i].groupName_ = "MouseAxes";
     106        }
     107
     108        // initialise joy sticks separatly to allow for reloading
     109        numberOfJoySticks_ = InputManager::getInstance().numberOfJoySticks();
     110        initialiseJoyStickBindings();
     111
     112        // collect all Buttons and HalfAxes
     113        compilePointerLists();
     114
     115        // set them here to use allHalfAxes_
     116        setConfigValues();
    197117    }
    198118
     
    209129    /**
    210130    @brief
    211         Loads the key and button bindings.
    212     @return
    213         True if loading succeeded.
    214     */
    215     void KeyBinder::loadBindings()
    216     {
    217         COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
    218 
    219         clearBindings();
    220 
    221         std::ifstream infile;
    222         infile.open("keybindings.ini");
    223         if (!infile)
    224         {
    225             ConfigFileManager::getInstance().setFile(CFT_Keybindings, "def_keybindings.ini");
    226             ConfigFileManager::getInstance().save(CFT_Keybindings, "keybindings.ini");
    227         }
    228         else
    229             infile.close();
    230         ConfigFileManager::getInstance().setFile(CFT_Keybindings, "keybindings.ini");
    231 
    232         // parse key bindings
    233         setConfigValues();
    234 
    235         COUT(3) << "KeyBinder: Loading key bindings done." << std::endl;
    236     }
    237 
    238     /**
    239     @brief
    240131        Loader for the key bindings, managed by config values.
    241132    */
    242133    void KeyBinder::setConfigValues()
    243134    {
     135        SetConfigValue(defaultKeybindings_, "def_keybindings.ini")
     136            .description("Filename of default keybindings.");
    244137        SetConfigValue(analogThreshold_, 0.05f)
    245138            .description("Threshold for analog axes until which the state is 0.");
     
    252145        SetConfigValue(mouseSensitivityDerived_, 1.0f)
    253146            .description("Mouse sensitivity if mouse input is derived.");
    254         SetConfigValue(bClipMouse_, true)
    255             .description("Whether or not to clip absolute value of mouse in non derive mode.");
    256 
    257         float oldThresh = buttonThreshold_;
     147        SetConfigValue(mouseWheelStepSize_, 120.0f)
     148            .description("Equals one step of the mousewheel.");
    258149        SetConfigValue(buttonThreshold_, 0.80f)
    259             .description("Threshold for analog axes until which the button is not pressed.");
    260         if (oldThresh != buttonThreshold_)
    261             for (unsigned int i = 0; i < nHalfAxes_s; i++)
    262                 if (halfAxes_[i].buttonThreshold_ == oldThresh)
    263                     halfAxes_[i].buttonThreshold_ = buttonThreshold_;
    264 
    265         // keys
    266         for (unsigned int i = 0; i < nKeys_s; i++)
    267             readTrigger(keys_[i]);
    268         // mouse buttons
    269         for (unsigned int i = 0; i < nMouseButtons_s; i++)
    270             readTrigger(mouseButtons_[i]);
    271         // joy stick buttons
    272         for (unsigned int i = 0; i < nJoyStickButtons_s; i++)
    273             readTrigger(joyStickButtons_[i]);
    274         // half axes
    275         for (unsigned int i = 0; i < nHalfAxes_s; i++)
    276             readTrigger(halfAxes_[i]);
    277     }
    278 
    279     void KeyBinder::readTrigger(Button& button)
    280     {
    281         // config value stuff
    282         ConfigValueContainer* cont
    283             = ClassIdentifier<KeyBinder>::getIdentifier()->getConfigValueContainer(button.name_);
    284         if (!cont)
    285         {
    286             cont = new ConfigValueContainer
    287                 (CFT_Keybindings, ClassIdentifier<KeyBinder>::getIdentifier(), button.name_, "", button.name_);
    288             ClassIdentifier<KeyBinder>::getIdentifier()->addConfigValueContainer(button.name_, cont);
    289         }
    290         std::string old = button.bindingString_;
    291         cont->getValue(&button.bindingString_, this);
    292 
    293         // keybinder stuff
    294         if (old != button.bindingString_)
    295         {
    296             // clear everything so we don't get old axis ParamCommands mixed up
    297             button.clear();
    298 
    299             // binding has changed
    300             button.parse(paramCommandBuffer_);
     150            .description("Threshold for analog axes until which the button is not pressed.")
     151            .callback(this, &KeyBinder::buttonThresholdChanged);
     152    }
     153
     154    void KeyBinder::buttonThresholdChanged()
     155    {
     156        for (unsigned int i = 0; i < allHalfAxes_.size(); i++)
     157            if (!allHalfAxes_[i]->bButtonThresholdUser_)
     158                allHalfAxes_[i]->buttonThreshold_ = this->buttonThreshold_;
     159    }
     160
     161    void KeyBinder::JoyStickDeviceNumberChanged(unsigned int value)
     162    {
     163        unsigned int oldValue = numberOfJoySticks_;
     164        numberOfJoySticks_ = value;
     165
     166        // initialise joy stick bindings
     167        initialiseJoyStickBindings();
     168
     169        // collect all Buttons and HalfAxes again
     170        compilePointerLists();
     171
     172        // load the bindings if required
     173        if (!configFile_.empty())
     174        {
     175            for (unsigned int iDev = oldValue; iDev < numberOfJoySticks_; ++iDev)
     176            {
     177                for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
     178                    joyStickButtons_[iDev][i].readConfigValue();
     179                for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
     180                    joyStickAxes_[iDev][i].readConfigValue();
     181            }
     182        }
     183
     184        // Set the button threshold for potential new axes
     185        buttonThresholdChanged();
     186    }
     187
     188    void KeyBinder::initialiseJoyStickBindings()
     189    {
     190        this->joyStickAxes_.resize(numberOfJoySticks_);
     191        this->joyStickButtons_.resize(numberOfJoySticks_);
     192
     193        // reinitialise all joy stick binings (doesn't overwrite the old ones)
     194        for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)
     195        {
     196            std::string deviceNumber = convertToString(iDev);
     197            // joy stick buttons
     198            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
     199            {
     200                joyStickButtons_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickButtonCode::ByString[i];
     201                joyStickButtons_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
     202                joyStickButtons_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Buttons";
     203            }
     204            // joy stick axes
     205            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
     206            {
     207                joyStickAxes_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickAxisCode::ByString[i >> 1];
     208                if (i & 1)
     209                    joyStickAxes_[iDev][i].name_ += "Pos";
     210                else
     211                    joyStickAxes_[iDev][i].name_ += "Neg";
     212                joyStickAxes_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
     213                joyStickAxes_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Axes";
     214            }
     215        }
     216    }
     217
     218    void KeyBinder::compilePointerLists()
     219    {
     220        allButtons_.clear();
     221        allHalfAxes_.clear();
     222
     223        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
     224            allButtons_[keys_[i].name_] = keys_ + i;
     225        for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
     226            allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i;
     227        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
     228        {
     229            allButtons_[mouseAxes_[i].name_] = mouseAxes_ + i;
     230            allHalfAxes_.push_back(mouseAxes_ + i);
     231        }
     232        for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)
     233        {
     234            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
     235                allButtons_[joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
     236            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
     237            {
     238                allButtons_[joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
     239                allHalfAxes_.push_back(&(joyStickAxes_[iDev][i]));
     240            }
     241        }
     242    }
     243
     244    /**
     245    @brief
     246        Loads the key and button bindings.
     247    @return
     248        True if loading succeeded.
     249    */
     250    void KeyBinder::loadBindings(const std::string& filename)
     251    {
     252        COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
     253
     254        configFile_ = filename;
     255        if (configFile_.empty())
     256            return;
     257
     258        // get bindings from default file if filename doesn't exist.
     259        std::ifstream infile;
     260        infile.open(configFile_.c_str());
     261        if (!infile)
     262        {
     263            ConfigFileManager::getInstance().setFile(CFT_Keybindings, defaultKeybindings_);
     264            ConfigFileManager::getInstance().save(CFT_Keybindings, configFile_);
     265        }
     266        else
     267            infile.close();
     268        ConfigFileManager::getInstance().setFile(CFT_Keybindings, configFile_);
     269
     270        // Parse bindings and create the ConfigValueContainers if necessary
     271        clearBindings();
     272        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
     273            it->second->readConfigValue();
     274
     275        COUT(3) << "KeyBinder: Loading key bindings done." << std::endl;
     276    }
     277
     278    bool KeyBinder::setBinding(const std::string& binding, const std::string& name, bool bTemporary)
     279    {
     280        std::map<std::string, Button*>::iterator it = allButtons_.find(name);
     281        if (it != allButtons_.end())
     282        {
     283            if (bTemporary)
     284                it->second->configContainer_->tset(binding);
     285            else
     286                it->second->configContainer_->set(binding);
     287            it->second->configContainer_->getValue(&(it->second->bindingString_), it->second);
     288            return true;
     289        }
     290        else
     291        {
     292            COUT(2) << "Could not find key/button/axis with name '" << name << "'." << std::endl;
     293            return false;
    301294        }
    302295    }
     
    308301    void KeyBinder::clearBindings()
    309302    {
    310         for (unsigned int i = 0; i < nKeys_s; i++)
    311             keys_[i].clear();
    312 
    313         for (unsigned int i = 0; i < nMouseButtons_s; i++)
    314             mouseButtons_[i].clear();
    315 
    316         for (unsigned int i = 0; i < nJoyStickButtons_s; i++)
    317             joyStickButtons_[i].clear();
    318 
    319         for (unsigned int i = 0; i < nHalfAxes_s; i++)
    320             halfAxes_[i].clear();
     303        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
     304            it->second->clear();
    321305
    322306        for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
     
    327311    void KeyBinder::resetJoyStickAxes()
    328312    {
    329         for (unsigned int i = 8; i < nHalfAxes_s; i++)
    330         {
    331             halfAxes_[i].absVal_ = 0.0f;
    332             halfAxes_[i].relVal_ = 0.0f;
     313        for (unsigned int iDev = 0; iDev < numberOfJoySticks_; ++iDev)
     314        {
     315            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
     316            {
     317                joyStickAxes_[iDev][i].absVal_ = 0.0f;
     318                joyStickAxes_[iDev][i].relVal_ = 0.0f;
     319            }
    333320        }
    334321    }
     
    336323    void KeyBinder::tickMouse(float dt)
    337324    {
    338         tickDevices(0, 8);
     325        tickDevices(mouseAxes_, mouseAxes_ + MouseAxisCode::numberOfAxes * 2);
    339326
    340327        if (bDeriveMouseInput_)
     
    342329            if (deriveTime_ > derivePeriod_)
    343330            {
    344                 //CCOUT(3) << "mouse abs: ";
    345331                for (int i = 0; i < 2; i++)
    346332                {
    347333                    if (mouseRelative_[i] > 0)
    348334                    {
    349                         halfAxes_[2*i + 0].absVal_
     335                        mouseAxes_[2*i + 0].absVal_
    350336                            =  mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    351                         halfAxes_[2*i + 1].absVal_ = 0.0f;
     337                        mouseAxes_[2*i + 1].absVal_ = 0.0f;
    352338                    }
    353339                    else if (mouseRelative_[i] < 0)
    354340                    {
    355                         halfAxes_[2*i + 0].absVal_ = 0.0f;
    356                         halfAxes_[2*i + 1].absVal_
     341                        mouseAxes_[2*i + 0].absVal_ = 0.0f;
     342                        mouseAxes_[2*i + 1].absVal_
    357343                            = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    358344                    }
    359345                    else
    360346                    {
    361                         halfAxes_[2*i + 0].absVal_ = 0.0f;
    362                         halfAxes_[2*i + 1].absVal_ = 0.0f;
     347                        mouseAxes_[2*i + 0].absVal_ = 0.0f;
     348                        mouseAxes_[2*i + 1].absVal_ = 0.0f;
    363349                    }
    364                     //COUT(3) << mouseRelative_[i] << " | ";
    365350                    mouseRelative_[i] = 0;
    366                     halfAxes_[2*i + 0].hasChanged_ = true;
    367                     halfAxes_[2*i + 1].hasChanged_ = true;
     351                    mouseAxes_[2*i + 0].hasChanged_ = true;
     352                    mouseAxes_[2*i + 1].hasChanged_ = true;
    368353                }
    369354                deriveTime_ = 0.0f;
    370                 //COUT(3) << std::endl;
    371355            }
    372356            else
     
    375359    }
    376360
    377     void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
    378     {
    379         tickDevices(8, nHalfAxes_s);
    380     }
    381 
    382     void KeyBinder::tickInput(float dt)
    383     {
    384         // execute all buffered bindings (additional parameter)
    385         for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
    386             paramCommandBuffer_[i]->execute();
    387 
    388         // always reset the relative movement of the mouse
    389         for (unsigned int i = 0; i < 8; i++)
    390             halfAxes_[i].relVal_ = 0.0f;
    391     }
    392 
    393     void KeyBinder::tickDevices(unsigned int begin, unsigned int end)
    394     {
    395         for (unsigned int i = begin; i < end; i++)
     361    void KeyBinder::tickDevices(HalfAxis* begin, HalfAxis* end)
     362    {
     363        for (HalfAxis* current = begin; current < end; ++current) // pointer arithmetic
    396364        {
    397365            // button mode
    398366            // TODO: optimize out all the half axes that don't act as a button at the moment
    399             if (halfAxes_[i].hasChanged_)
    400             {
    401                 if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_)
     367            if (current->hasChanged_)
     368            {
     369                if (!current->wasDown_ && current->absVal_ > current->buttonThreshold_)
    402370                {
    403                     halfAxes_[i].wasDown_ = true;
    404                     if (halfAxes_[i].nCommands_[KeybindMode::OnPress])
    405                         halfAxes_[i].execute(KeybindMode::OnPress);
     371                    current->wasDown_ = true;
     372                    if (current->nCommands_[KeybindMode::OnPress])
     373                        current->execute(KeybindMode::OnPress);
    406374                }
    407                 else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_)
     375                else if (current->wasDown_ && current->absVal_ < current->buttonThreshold_)
    408376                {
    409                     halfAxes_[i].wasDown_ = false;
    410                     if (halfAxes_[i].nCommands_[KeybindMode::OnRelease])
    411                         halfAxes_[i].execute(KeybindMode::OnRelease);
     377                    current->wasDown_ = false;
     378                    if (current->nCommands_[KeybindMode::OnRelease])
     379                        current->execute(KeybindMode::OnRelease);
    412380                }
    413                 halfAxes_[i].hasChanged_ = false;
    414             }
    415 
    416             if (halfAxes_[i].wasDown_)
    417             {
    418                 if (halfAxes_[i].nCommands_[KeybindMode::OnHold])
    419                     halfAxes_[i].execute(KeybindMode::OnHold);
     381                current->hasChanged_ = false;
     382            }
     383
     384            if (current->wasDown_)
     385            {
     386                if (current->nCommands_[KeybindMode::OnHold])
     387                    current->execute(KeybindMode::OnHold);
    420388            }
    421389
    422390            // these are the actually useful axis bindings for analog input
    423             if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_)
    424             {
    425                 //COUT(3) << halfAxes_[i].name_ << "\t" << halfAxes_[i].absVal_ << std::endl;
    426                 halfAxes_[i].execute();
    427             }
    428         }
    429     }
    430 
    431     void KeyBinder::keyPressed (const KeyEvent& evt)
    432     { keys_[evt.key].execute(KeybindMode::OnPress); }
    433 
    434     void KeyBinder::keyReleased(const KeyEvent& evt)
    435     { keys_[evt.key].execute(KeybindMode::OnRelease); }
    436 
    437     void KeyBinder::keyHeld    (const KeyEvent& evt)
    438     { keys_[evt.key].execute(KeybindMode::OnHold); }
    439 
    440 
    441     void KeyBinder::mouseButtonPressed (MouseButton::Enum id)
    442     { mouseButtons_[id].execute(KeybindMode::OnPress); }
    443 
    444     void KeyBinder::mouseButtonReleased(MouseButton::Enum id)
    445     { mouseButtons_[id].execute(KeybindMode::OnRelease); }
    446 
    447     void KeyBinder::mouseButtonHeld    (MouseButton::Enum id)
    448     { mouseButtons_[id].execute(KeybindMode::OnHold); }
    449 
    450 
    451     void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id)
    452     { joyStickButtons_[id].execute(KeybindMode::OnPress); }
    453 
    454     void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
    455     { joyStickButtons_[id].execute(KeybindMode::OnRelease); }
    456 
    457     void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id)
    458     { joyStickButtons_[id].execute(KeybindMode::OnHold); }
     391            if (current->relVal_ > analogThreshold_ || current->absVal_ > analogThreshold_)
     392            {
     393                current->execute();
     394            }
     395        }
     396    }
    459397
    460398    /**
     
    473411            for (int i = 0; i < 2; i++)
    474412            {
    475                 if (rel[i])
     413                if (rel[i]) // performance opt. if rel[i] == 0
    476414                {
    477                     // absolute
    478                     halfAxes_[2*i + 0].hasChanged_ = true;
    479                     halfAxes_[2*i + 1].hasChanged_ = true;
     415                    // write absolute values
     416                    mouseAxes_[2*i + 0].hasChanged_ = true;
     417                    mouseAxes_[2*i + 1].hasChanged_ = true;
    480418                    mousePosition_[i] += rel[i];
    481419
    482                     if (bClipMouse_)
    483                     {
    484                         if (mousePosition_[i] > 1024)
    485                             mousePosition_[i] =  1024;
    486                         if (mousePosition_[i] < -1024)
    487                             mousePosition_[i] = -1024;
    488                     }
     420                    // clip absolute position
     421                    if (mousePosition_[i] > mouseClippingSize_)
     422                        mousePosition_[i] =  mouseClippingSize_;
     423                    if (mousePosition_[i] < -mouseClippingSize_)
     424                        mousePosition_[i] = -mouseClippingSize_;
    489425
    490426                    if (mousePosition_[i] >= 0)
    491427                    {
    492                         halfAxes_[2*i + 0].absVal_ =   mousePosition_[i]/1024.0f * mouseSensitivity_;
    493                         halfAxes_[2*i + 1].absVal_ =  0.0f;
     428                        mouseAxes_[2*i + 0].absVal_ =   mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
     429                        mouseAxes_[2*i + 1].absVal_ =  0.0f;
    494430                    }
    495431                    else
    496432                    {
    497                         halfAxes_[2*i + 0].absVal_ =  0.0f;
    498                         halfAxes_[2*i + 1].absVal_ =  -mousePosition_[i]/1024.0f * mouseSensitivity_;
     433                        mouseAxes_[2*i + 0].absVal_ =  0.0f;
     434                        mouseAxes_[2*i + 1].absVal_ =  -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
    499435                    }
    500436                }
     
    511447        {
    512448            if (rel[i] > 0)
    513                 halfAxes_[0 + 2*i].relVal_ =  ((float)rel[i])/1024 * mouseSensitivity_;
    514             else
    515                 halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024 * mouseSensitivity_;
     449                mouseAxes_[0 + 2*i].relVal_ =  ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
     450            else
     451                mouseAxes_[1 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
    516452        }
    517453    }
     
    523459    void KeyBinder::mouseScrolled(int abs, int rel)
    524460    {
    525         //COUT(3) << mouseButtons_[8].name_ << "   " << abs << " | " << rel << std::endl;
    526 
    527461        if (rel > 0)
    528             for (int i = 0; i < rel/120; i++)
    529                 mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/120.0f);
     462            for (int i = 0; i < rel/mouseWheelStepSize_; i++)
     463                mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_);
    530464        else
    531             for (int i = 0; i < -rel/120; i++)
    532                 mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/120.0f);
     465            for (int i = 0; i < -rel/mouseWheelStepSize_; i++)
     466                mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_);
    533467    }
    534468
    535469    void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value)
    536470    {
    537         int i = 8 + axis * 2;
     471        int i = axis * 2;
    538472        if (value >= 0)
    539473        {
    540             //if (value > 10000)
    541             //{ CCOUT(3) << halfAxes_[i].name_ << std::endl; }
    542 
    543             halfAxes_[i].absVal_ = value;
    544             halfAxes_[i].relVal_ = value;
    545             halfAxes_[i].hasChanged_ = true;
    546             if (halfAxes_[i + 1].absVal_ > 0.0f)
    547             {
    548                 halfAxes_[i + 1].absVal_ = -0.0f;
    549                 halfAxes_[i + 1].relVal_ = -0.0f;
    550                 halfAxes_[i + 1].hasChanged_ = true;
     474            joyStickAxes_[joyStickID][i].absVal_ = value;
     475            joyStickAxes_[joyStickID][i].relVal_ = value;
     476            joyStickAxes_[joyStickID][i].hasChanged_ = true;
     477            if (joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f)
     478            {
     479                joyStickAxes_[joyStickID][i + 1].absVal_ = -0.0f;
     480                joyStickAxes_[joyStickID][i + 1].relVal_ = -0.0f;
     481                joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;
    551482            }
    552483        }
    553484        else
    554485        {
    555             //if (value < -10000)
    556             //{ CCOUT(3) << halfAxes_[i + 1].name_ << std::endl; }
    557 
    558             halfAxes_[i + 1].absVal_ = -value;
    559             halfAxes_[i + 1].relVal_ = -value;
    560             halfAxes_[i + 1].hasChanged_ = true;
    561             if (halfAxes_[i].absVal_ > 0.0f)
    562             {
    563                 halfAxes_[i].absVal_ = -0.0f;
    564                 halfAxes_[i].relVal_ = -0.0f;
    565                 halfAxes_[i].hasChanged_ = true;
     486            joyStickAxes_[joyStickID][i + 1].absVal_ = -value;
     487            joyStickAxes_[joyStickID][i + 1].relVal_ = -value;
     488            joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;
     489            if (joyStickAxes_[joyStickID][i].absVal_ > 0.0f)
     490            {
     491                joyStickAxes_[joyStickID][i].absVal_ = -0.0f;
     492                joyStickAxes_[joyStickID][i].relVal_ = -0.0f;
     493                joyStickAxes_[joyStickID][i].hasChanged_ = true;
    566494            }
    567495        }
  • code/trunk/src/core/input/KeyBinder.h

    r1755 r1887  
    3939
    4040#include <vector>
    41 
    42 #include "core/OrxonoxClass.h"
    4341#include "InputInterfaces.h"
    4442#include "Button.h"
    4543#include "HalfAxis.h"
     44#include "InputCommands.h"
     45#include "JoyStickDeviceNumberListener.h"
    4646
    4747namespace orxonox
     
    5252        Manages the key bindings.
    5353    */
    54     class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
     54    class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler,
     55                                  public JoyStickDeviceNumberListener
    5556    {
    5657    public:
     
    5859        virtual ~KeyBinder();
    5960
    60         void loadBindings();
     61        void loadBindings(const std::string& filename);
    6162        void clearBindings();
     63        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
    6264        void setConfigValues();
    6365        void resetJoyStickAxes();
     
    6567    protected: // functions
    6668        void tickInput(float dt);
    67         //void tickInput(float dt, int device);
    6869        void tickKey(float dt) { }
    6970        void tickMouse(float dt);
    7071        void tickJoyStick(float dt, unsigned int joyStick);
    71         void tickDevices(unsigned int begin, unsigned int end);
    72 
    73         virtual void readTrigger(Button& button);
     72        // internal
     73        void tickDevices(HalfAxis* begin, HalfAxis* end);
     74
     75        void buttonThresholdChanged();
     76        // from JoyStickDeviceNumberListener interface
     77        virtual void JoyStickDeviceNumberChanged(unsigned int value);
     78        void initialiseJoyStickBindings();
     79        void compilePointerLists();
    7480
    7581        void keyPressed (const KeyEvent& evt);
     
    7783        void keyHeld    (const KeyEvent& evt);
    7884
    79         void mouseButtonPressed (MouseButton::Enum id);
    80         void mouseButtonReleased(MouseButton::Enum id);
    81         void mouseButtonHeld    (MouseButton::Enum id);
     85        void mouseButtonPressed (MouseButtonCode::ByEnum id);
     86        void mouseButtonReleased(MouseButtonCode::ByEnum id);
     87        void mouseButtonHeld    (MouseButtonCode::ByEnum id);
    8288        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    8389        void mouseScrolled      (int abs, int rel);
    8490
    85         void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
    86         void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
    87         void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
     91        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     92        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     93        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
    8894        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
    8995
    9096    protected: // variables
    91         //! denotes the number of different keys there are in OIS.
    92         static const unsigned int nKeys_s = 0xEE;
    93         //! Actual key bindings as bundle for Press, Hold and Release
    94         Button keys_ [nKeys_s];
    95 
    96         //! denotes the number of different mouse buttons there are in OIS.
    97         static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels
    98         //! Actual key bindings as bundle for Press, Hold and Release
    99         Button mouseButtons_ [nMouseButtons_s];
    100 
    101         //! denotes the number of different joy stick buttons there are in OIS.
    102         static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons
    103         //! Actual key bindings as bundle for Press, Hold and Release
    104         Button joyStickButtons_ [nJoyStickButtons_s];
    105 
    106         //! denotes the number of half axes (every axis twice) there can be.
    107         static const unsigned int nHalfAxes_s = 56;
    108         /**
    109         * Array with all the half axes for mouse and joy sticks.
    110         * Keep in mind that the positions are fixed and that the first entry is the
    111         * positive one and the second is negative.
    112         * Sequence is as follows:
    113         *  0 -  3: Mouse x and y
    114         *  4 -  7: empty
    115         *  8 - 23: joy stick slider axes 1 to 8
    116         * 24 - 55: joy stick axes 1 - 16
    117         */
    118         HalfAxis halfAxes_[nHalfAxes_s];
     97        //! Currently active joy sticks
     98        unsigned int numberOfJoySticks_;
     99
     100        //! Actual key bindings for keys on the keyboard
     101        Button keys_            [KeyCode::numberOfKeys];
     102        //! Number of mouse buttons in KeyBinder (+4)
     103        static const int numberOfMouseButtons_ = MouseButtonCode::numberOfButtons + 4;
     104        //! Actual key bindings for mouse buttons including the wheel(s)
     105        Button mouseButtons_    [numberOfMouseButtons_];
     106        //! Actual key bindings for mouse axes
     107        HalfAxis mouseAxes_     [MouseAxisCode::numberOfAxes * 2];
     108
     109        //! Helper class to use something like std:vector<Button[64]>
     110        struct JoyStickButtonVector
     111        {
     112            Button& operator[](unsigned int index) { return buttons[index]; }
     113            Button buttons[JoyStickButtonCode::numberOfButtons];
     114        };
     115        //! Actual key bindings for joy stick buttons
     116        std::vector<JoyStickButtonVector> joyStickButtons_;
     117        //! Helper class to use something like std:vector<HalfAxis[48]>
     118        struct JoyStickAxisVector
     119        {
     120            HalfAxis& operator[](unsigned int index) { return halfAxes[index]; }
     121            HalfAxis halfAxes[JoyStickAxisCode::numberOfAxes * 2];
     122        };
     123        //! Actual key bindings for joy stick axes (and sliders)
     124        std::vector<JoyStickAxisVector> joyStickAxes_;
     125
     126        //! Pointer map with all Buttons, including half axes
     127        std::map<std::string, Button*> allButtons_;
     128        //! Pointer list with all half axes
     129        std::vector<HalfAxis*> allHalfAxes_;
    119130
    120131        /**
     
    131142        float deriveTime_;
    132143
    133 
     144        //! Config file used. "" in case of KeyDetector. Also indicates whether we've already loaded.
     145        std::string configFile_;
     146
     147    private:
    134148        //##### ConfigValues #####
    135 
     149        //! Filename of default keybindings.
     150        std::string defaultKeybindings_;
    136151        //! Threshold for analog triggers until which the state is 0.
    137152        float analogThreshold_;
     
    146161        //! mouse sensitivity if mouse input is derived
    147162        float mouseSensitivityDerived_;
    148         //! Whether or not to clip abslute mouse values to 1024
    149         bool bClipMouse_;
     163        //! Equals one step of the mousewheel
     164        float mouseWheelStepSize_;
     165
     166        //##### Constant config variables #####
     167        // Use some value at about 1000. This can be configured with mouseSensitivity_ anyway.
     168        static const int mouseClippingSize_ = 1024;
    150169    };
     170
     171    inline void KeyBinder::keyPressed (const KeyEvent& evt)
     172    { keys_[evt.key].execute(KeybindMode::OnPress); }
     173
     174    inline void KeyBinder::keyReleased(const KeyEvent& evt)
     175    { keys_[evt.key].execute(KeybindMode::OnRelease); }
     176
     177    inline void KeyBinder::keyHeld    (const KeyEvent& evt)
     178    { keys_[evt.key].execute(KeybindMode::OnHold); }
     179
     180
     181    inline void KeyBinder::mouseButtonPressed (MouseButtonCode::ByEnum id)
     182    { mouseButtons_[id].execute(KeybindMode::OnPress); }
     183
     184    inline void KeyBinder::mouseButtonReleased(MouseButtonCode::ByEnum id)
     185    { mouseButtons_[id].execute(KeybindMode::OnRelease); }
     186
     187    inline void KeyBinder::mouseButtonHeld    (MouseButtonCode::ByEnum id)
     188    { mouseButtons_[id].execute(KeybindMode::OnHold); }
     189
     190
     191    inline void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     192    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnPress); }
     193
     194    inline void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     195    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnRelease); }
     196
     197    inline void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     198    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); }
     199
     200    inline void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
     201    {
     202        tickDevices(&joyStickAxes_[joyStick][0], &joyStickAxes_[joyStick][JoyStickAxisCode::numberOfAxes * 2]);
     203    }
     204
     205    inline void KeyBinder::tickInput(float dt)
     206    {
     207        // execute all buffered bindings (additional parameter)
     208        for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
     209            paramCommandBuffer_[i]->execute();
     210
     211        // always reset the relative movement of the mouse
     212        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
     213            mouseAxes_[i].relVal_ = 0.0f;
     214    }
    151215}
    152216
  • code/trunk/src/core/input/KeyDetector.cc

    r1755 r1887  
    6262    /**
    6363    @brief
    64         Loads the key and button bindings.
    65     @return
    66         True if loading succeeded.
     64        Assigns all the buttons 'command' plus the button's name.
    6765    */
    68     void KeyDetector::loadBindings(const std::string& command)
     66    void KeyDetector::setCallbackCommand(const std::string& command)
    6967    {
    70         this->command_ = command;
     68        callbackCommand_ = command;
    7169        clearBindings();
    72         setConfigValues();
     70        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
     71        {
     72            it->second->bindingString_ = callbackCommand_ + it->second->name_;
     73            it->second->parse();
     74        }
    7375    }
    7476
    75     void KeyDetector::readTrigger(Button& button)
     77    void KeyDetector::JoyStickDeviceNumberChanged(unsigned int value)
    7678    {
    77         SimpleCommand* cmd = new SimpleCommand();
    78         cmd->evaluation_ = CommandExecutor::evaluate(this->command_ + " " + button.name_);
    79         button.commands_[KeybindMode::OnPress] = new BaseCommand*[1];
    80         button.commands_[KeybindMode::OnPress][0] = cmd;
    81         button.nCommands_[KeybindMode::OnPress] = 1;
     79        KeyBinder::JoyStickDeviceNumberChanged(value);
     80        setCallbackCommand(callbackCommand_);
    8281    }
    8382}
  • code/trunk/src/core/input/KeyDetector.h

    r1755 r1887  
    4747        KeyDetector();
    4848        ~KeyDetector();
    49         void loadBindings(const std::string& command);
    50 
    51     protected:
    52         void readTrigger(Button& button);
     49        void setCallbackCommand(const std::string& command);
     50        void JoyStickDeviceNumberChanged(unsigned int value);
    5351
    5452    private:
    55         std::string command_;
     53        std::string callbackCommand_;
    5654    };
    5755}
  • code/trunk/src/core/input/SimpleInputState.cc

    r1881 r1887  
    3535#include "SimpleInputState.h"
    3636
    37 #include <assert.h>
    38 #include "util/Debug.h"
    39 #include "core/Executor.h"
    40 
    4137namespace orxonox
    4238{
    43     using namespace InputDevice;
    44 
    4539    SimpleInputState::SimpleInputState()
    4640        : keyHandler_(0)
     
    7064        if (keyHandler_)
    7165            keyHandler_->keyPressed(evt);
    72     }
    73 
    74     void SimpleInputState::keyReleased(const KeyEvent& evt)
    75     {
    76         if (keyHandler_)
    77             keyHandler_->keyReleased(evt);
    78     }
    79 
    80     void SimpleInputState::keyHeld(const KeyEvent& evt)
    81     {
    82         if (keyHandler_)
    83             keyHandler_->keyHeld(evt);
    84     }
    85 
    86 
    87     void SimpleInputState::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    88     {
    89         if (mouseHandler_)
    90             mouseHandler_->mouseMoved(abs, rel, clippingSize);
    91     }
    92 
    93     void SimpleInputState::mouseScrolled(int abs, int rel)
    94     {
    95         if (mouseHandler_)
    96             mouseHandler_->mouseScrolled(abs, rel);
    97     }
    98 
    99     void SimpleInputState::mouseButtonPressed(MouseButton::Enum id)
    100     {
    101         if (mouseHandler_)
    102             mouseHandler_->mouseButtonPressed(id);
    103     }
    104 
    105     void SimpleInputState::mouseButtonReleased(MouseButton::Enum id)
    106     {
    107         if (mouseHandler_)
    108             mouseHandler_->mouseButtonReleased(id);
    109     }
    110 
    111     void SimpleInputState::mouseButtonHeld(MouseButton::Enum id)
    112     {
    113         if (mouseHandler_)
    114             mouseHandler_->mouseButtonHeld(id);
    115     }
    116 
    117 
    118     void SimpleInputState::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value)
    119     {
    120         assert(joyStickID < joyStickHandler_.size());
    121         if (joyStickHandler_[joyStickID])
    122             joyStickHandler_[joyStickID]->joyStickAxisMoved(joyStickID, axis, value);
    123     }
    124 
    125     void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton::Enum id)
    126     {
    127         assert(joyStickID < joyStickHandler_.size());
    128         if (joyStickHandler_[joyStickID])
    129             joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, id);
    130     }
    131 
    132     void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
    133     {
    134         assert(joyStickID < joyStickHandler_.size());
    135         if (joyStickHandler_[joyStickID])
    136             joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, id);
    137     }
    138 
    139     void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton::Enum id)
    140     {
    141         assert(joyStickID < joyStickHandler_.size());
    142         if (joyStickHandler_[joyStickID])
    143             joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, id);
    14466    }
    14567
     
    199121    }
    200122
    201     void SimpleInputState::tickInput(float dt)
    202     {
    203         for (unsigned int i = 0; i < allHandlers_.size(); ++i)
    204         {
    205             allHandlers_[i]->tickInput(dt);
    206         }
    207     }
    208 
    209     void SimpleInputState::tickInput(float dt, unsigned int device)
    210     {
    211         switch (device)
    212         {
    213         case Keyboard:
    214             if (keyHandler_)
    215                 keyHandler_->tickKey(dt);
    216             break;
    217 
    218         case Mouse:
    219             if (mouseHandler_)
    220                 mouseHandler_->tickMouse(dt);
    221             break;
    222 
    223         default: // joy sticks
    224             if (joyStickHandler_[device - 2])
    225                 joyStickHandler_[device - 2]->tickJoyStick(dt, device - 2);
    226             break;
    227         }
    228     }
    229 
    230123    void SimpleInputState::update()
    231124    {
     
    247140
    248141        // update the deviceEnabled options
    249         setInputDeviceEnabled(Keyboard, (keyHandler_ != 0));
    250         setInputDeviceEnabled(Mouse, (mouseHandler_ != 0));
     142        setInputDeviceEnabled(InputDevice::Keyboard, (keyHandler_ != 0));
     143        setInputDeviceEnabled(InputDevice::Mouse, (mouseHandler_ != 0));
    251144        for (unsigned int i = 0; i < joyStickHandler_.size(); ++i)
    252145            setInputDeviceEnabled(2 + i, (joyStickHandler_[i] != 0));
  • code/trunk/src/core/input/SimpleInputState.h

    r1881 r1887  
    3838
    3939#include <vector>
     40#include <cassert>
    4041#include "InputInterfaces.h"
    4142#include "InputState.h"
     
    6566        void keyHeld    (const KeyEvent& evt);
    6667
    67         void mouseButtonPressed (MouseButton::Enum id);
    68         void mouseButtonReleased(MouseButton::Enum id);
    69         void mouseButtonHeld    (MouseButton::Enum id);
     68        void mouseButtonPressed (MouseButtonCode::ByEnum id);
     69        void mouseButtonReleased(MouseButtonCode::ByEnum id);
     70        void mouseButtonHeld    (MouseButtonCode::ByEnum id);
    7071        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    7172        void mouseScrolled      (int abs, int rel);
    7273
    73         void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
    74         void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
    75         void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
     74        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     75        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
     76        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
    7677        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
    7778
     
    8384        std::vector<JoyStickHandler*> joyStickHandler_;
    8485        JoyStickHandler*              joyStickHandlerAll_;
    85         std::vector<InputHandler*>   allHandlers_;
     86        std::vector<InputHandler*>    allHandlers_;
    8687    };
     88
     89    inline void SimpleInputState::tickInput(float dt)
     90    {
     91        for (unsigned int i = 0; i < allHandlers_.size(); ++i)
     92        {
     93            allHandlers_[i]->tickInput(dt);
     94        }
     95    }
     96
     97    inline void SimpleInputState::tickInput(float dt, unsigned int device)
     98    {
     99        switch (device)
     100        {
     101        case InputDevice::Keyboard:
     102            if (keyHandler_)
     103                keyHandler_->tickKey(dt);
     104            break;
     105
     106        case InputDevice::Mouse:
     107            if (mouseHandler_)
     108                mouseHandler_->tickMouse(dt);
     109            break;
     110
     111        default: // joy sticks
     112            if (joyStickHandler_[device - 2])
     113                joyStickHandler_[device - 2]->tickJoyStick(dt, device - 2);
     114            break;
     115        }
     116    }
     117
     118    inline void SimpleInputState::keyReleased(const KeyEvent& evt)
     119    {
     120        if (keyHandler_)
     121            keyHandler_->keyReleased(evt);
     122    }
     123
     124    inline void SimpleInputState::keyHeld(const KeyEvent& evt)
     125    {
     126        if (keyHandler_)
     127            keyHandler_->keyHeld(evt);
     128    }
     129
     130    inline void SimpleInputState::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
     131    {
     132        if (mouseHandler_)
     133            mouseHandler_->mouseMoved(abs, rel, clippingSize);
     134    }
     135
     136    inline void SimpleInputState::mouseScrolled(int abs, int rel)
     137    {
     138        if (mouseHandler_)
     139            mouseHandler_->mouseScrolled(abs, rel);
     140    }
     141
     142    inline void SimpleInputState::mouseButtonPressed(MouseButtonCode::ByEnum id)
     143    {
     144        if (mouseHandler_)
     145            mouseHandler_->mouseButtonPressed(id);
     146    }
     147
     148    inline void SimpleInputState::mouseButtonReleased(MouseButtonCode::ByEnum id)
     149    {
     150        if (mouseHandler_)
     151            mouseHandler_->mouseButtonReleased(id);
     152    }
     153
     154    inline void SimpleInputState::mouseButtonHeld(MouseButtonCode::ByEnum id)
     155    {
     156        if (mouseHandler_)
     157            mouseHandler_->mouseButtonHeld(id);
     158    }
     159
     160    inline void SimpleInputState::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value)
     161    {
     162        assert(joyStickID < joyStickHandler_.size());
     163        if (joyStickHandler_[joyStickID])
     164            joyStickHandler_[joyStickID]->joyStickAxisMoved(joyStickID, axis, value);
     165    }
     166
     167    inline void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     168    {
     169        assert(joyStickID < joyStickHandler_.size());
     170        if (joyStickHandler_[joyStickID])
     171            joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, id);
     172    }
     173
     174    inline void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     175    {
     176        assert(joyStickID < joyStickHandler_.size());
     177        if (joyStickHandler_[joyStickID])
     178            joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, id);
     179    }
     180
     181    inline void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
     182    {
     183        assert(joyStickID < joyStickHandler_.size());
     184        if (joyStickHandler_[joyStickID])
     185            joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, id);
     186    }
    87187}
    88188
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r1878 r1887  
    114114        // Configure master input state with a KeyBinder
    115115        //masterKeyBinder_ = new KeyBinder();
     116        //masterKeyBinder_->loadBindings("master_keybindings.ini");
    116117        //inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_);
    117118
  • code/trunk/src/orxonox/gamestates/GSLevel.cc

    r1826 r1887  
    3636#include "core/input/KeyBinder.h"
    3737#include "core/Loader.h"
     38#include "core/CommandExecutor.h"
     39#include "core/ConsoleCommand.h"
     40#include "core/ConfigValueIncludes.h"
     41#include "core/CoreIncludes.h"
    3842#include "objects/Backlight.h"
    3943#include "objects/Tickable.h"
     
    5559        , hud_(0)
    5660    {
     61        RegisterObject(GSLevel);
     62        setConfigValues();
    5763    }
    5864
    5965    GSLevel::~GSLevel()
    6066    {
     67    }
     68
     69    void GSLevel::setConfigValues()
     70    {
     71        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
    6172    }
    6273
     
    6576        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
    6677        keyBinder_ = new KeyBinder();
    67         keyBinder_->loadBindings();
     78        keyBinder_->loadBindings("keybindings.ini");
    6879        inputState_->setHandler(keyBinder_);
    6980
     
    8899        // TODO: insert slomo console command with
    89100        // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
     101
     102        // keybind console command
     103        FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
     104        functor1->setObject(this);
     105        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
     106        FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
     107        functor2->setObject(this);
     108        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
     109        // set our console command as callback for the key detector
     110        InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
    90111    }
    91112
     
    145166        delete this->startLevel_;
    146167    }
     168
     169    void GSLevel::keybind(const std::string &command)
     170    {
     171        this->keybindInternal(command, false);
     172    }
     173
     174    void GSLevel::tkeybind(const std::string &command)
     175    {
     176        this->keybindInternal(command, true);
     177    }
     178
     179    /**
     180    @brief
     181        Assigns a command string to a key/button/axis. The name is determined via KeyDetector.
     182    @param command
     183        Command string that can be executed by the CommandExecutor
     184        OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
     185        the key/button/axis that has been activated. This is configured above in enter().
     186    */
     187    void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
     188    {
     189        static std::string bindingString = "";
     190        static bool bTemporarySaved = false;
     191        static bool bound = true;
     192        // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
     193        // Howerver there will be no real issue if it happens anyway.
     194        if (command.find(keyDetectorCallbackCode_) != 0)
     195        {
     196            if (bound)
     197            {
     198                COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
     199                InputManager::getInstance().requestEnterState("detector");
     200                bindingString = command;
     201                bTemporarySaved = bTemporary;
     202                bound = false;
     203            }
     204            //else:  We're still in a keybind command. ignore this call.
     205        }
     206        else
     207        {
     208            if (!bound)
     209            {
     210                // user has pressed the key
     211                std::string name = command.substr(this->keyDetectorCallbackCode_.size());
     212                COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
     213                this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
     214                InputManager::getInstance().requestLeaveState("detector");
     215                bound = true;
     216            }
     217            // else: A key was pressed within the same tick, ignore it.
     218        }
     219    }
    147220}
  • code/trunk/src/orxonox/gamestates/GSLevel.h

    r1755 r1887  
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSLevel : public GameState<GSGraphics>
     39    class _OrxonoxExport GSLevel : public GameState<GSGraphics>, public OrxonoxClass
    4040    {
     41        friend class ClassIdentifier<GSLevel>;
    4142    public:
    4243        GSLevel(const std::string& name);
     
    5859        float timeFactor_;       //!< A factor to change the gamespeed
    5960
     61        // console commands
     62        void keybind(const std::string& command);
     63        void tkeybind(const std::string& command);
     64        void keybindInternal(const std::string& command, bool bTemporary);
     65
    6066        Ogre::SceneManager*   sceneManager_;
    6167        KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
     
    6470        Level*                startLevel_;       //!< current hard coded default level
    6571        Level*                hud_;              //!< 'level' object fo the HUD
     72
     73        // config values
     74        std::string           keyDetectorCallbackCode_;
     75       
     76    private:
     77        void setConfigValues();
     78
    6679    };
    6780}
  • code/trunk/src/orxonox/gui/GUIManager.cc

    r1878 r1887  
    279279    }
    280280
    281     void GUIManager::mouseButtonPressed(MouseButton::Enum id)
     281    void GUIManager::mouseButtonPressed(MouseButtonCode::ByEnum id)
    282282    {
    283283        try
     
    292292    }
    293293
    294     void GUIManager::mouseButtonReleased(MouseButton::Enum id)
     294    void GUIManager::mouseButtonReleased(MouseButtonCode::ByEnum id)
    295295    {
    296296        try
     
    306306
    307307
    308     inline CEGUI::MouseButton GUIManager::convertButton(MouseButton::Enum button)
     308    inline CEGUI::MouseButton GUIManager::convertButton(MouseButtonCode::ByEnum button)
    309309    {
    310310        switch (button)
    311311        {
    312         case MouseButton::Left:
     312        case MouseButtonCode::Left:
    313313            return CEGUI::LeftButton;
    314314
    315         case MouseButton::Right:
     315        case MouseButtonCode::Right:
    316316            return CEGUI::RightButton;
    317317
    318         case MouseButton::Middle:
     318        case MouseButtonCode::Middle:
    319319            return CEGUI::MiddleButton;
    320320
    321         case MouseButton::Button3:
     321        case MouseButtonCode::Button3:
    322322            return CEGUI::X1Button;
    323323
    324         case MouseButton::Button4:
     324        case MouseButtonCode::Button4:
    325325            return CEGUI::X2Button;
    326326
  • code/trunk/src/orxonox/gui/GUIManager.h

    r1755 r1887  
    9393        { }
    9494
    95         void mouseButtonPressed (MouseButton::Enum id);
    96         void mouseButtonReleased(MouseButton::Enum id);
    97         void mouseButtonHeld    (MouseButton::Enum id)
     95        void mouseButtonPressed (MouseButtonCode::ByEnum id);
     96        void mouseButtonReleased(MouseButtonCode::ByEnum id);
     97        void mouseButtonHeld    (MouseButtonCode::ByEnum id)
    9898        { }
    9999        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
     
    123123        State state_;
    124124
    125         static CEGUI::MouseButton convertButton(MouseButton::Enum button);
     125        static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
    126126
    127127        static GUIManager*        singletonRef_s;
Note: See TracChangeset for help on using the changeset viewer.