Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3274


Ignore:
Timestamp:
Jul 12, 2009, 4:12:04 PM (15 years ago)
Author:
rgrieder
Message:

Added a few more generic parts to the input library:

  • Created Mouse and Keyboard to join JoyStick and provided them with a templated base class (InputDeviceTemplated) that does most of the work (reduces quite some redundancy)
  • Created InputPrereqs.h from InputInterfaces.h and destroyed the latter
  • Exported InputHandler to its own file and replaced KeyHandler, MouseHandler and JoyStickHandler with the single InputHandler.
  • Deleted the SimpleInputState: There is only one class now which fulfills all our needs.

In general there is now less code and the code itself has more 'pluses'. However I haven't really thrown away any feature at all.

Location:
code/branches/core4/src
Files:
5 added
1 deleted
27 edited
1 copied
4 moved

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/CorePrereqs.h

    r3272 r3274  
    176176    class HalfAxis;
    177177    class InputBuffer;
     178    class InputDevice;
     179    template <class Traits>
     180    class InputDeviceTemplated;
     181    class InputHandler;
    178182    class InputManager;
    179183    class InputState;
    180184    class JoyStick;
    181     class JoyStickHandler;
    182     class MouseHandler;
     185    class Mouse;
     186    class Keyboard;
    183187    class KeyBinder;
    184188    class KeyDetector;
    185     class KeyHandler;
    186189    class ParamCommand;
    187190    class SimpleCommand;
    188     class SimpleInputState;
     191
    189192}
    190193
  • code/branches/core4/src/core/OrxonoxClass.h

    r3271 r3274  
    4040#include "CorePrereqs.h"
    4141#include <set>
     42#include <vector>
    4243
    4344namespace orxonox
  • code/branches/core4/src/core/input/Button.h

    r3257 r3274  
    3636#define _Button_H__
    3737
    38 #include "core/CorePrereqs.h"
     38#include "InputPrereqs.h"
    3939
    4040#include <string>
  • code/branches/core4/src/core/input/CMakeLists.txt

    r3273 r3274  
    55  InputCommands.cc
    66  InputManager.cc
     7  InputState.cc
    78  JoyStick.cc
    8   JoyStickDeviceNumberListener.cc
     9  JoyStickQuantityListener.cc
    910  KeyBinder.cc
     11  Keyboard.cc
    1012  KeyDetector.cc
    11   SimpleInputState.cc
     13  Mouse.cc
    1214)
  • code/branches/core4/src/core/input/HalfAxis.h

    r3196 r3274  
    3636#define _HalfAxis_H__
    3737
    38 #include "core/CorePrereqs.h"
     38#include "InputPrereqs.h"
    3939
    4040#include "Button.h"
  • code/branches/core4/src/core/input/InputBuffer.cc

    r3196 r3274  
    184184
    185185
    186     void InputBuffer::processKey(const KeyEvent &evt)
    187     {
    188         if (evt.isModifierDown(KeyboardModifier::Alt) && evt.key == KeyCode::Tab)
     186    void InputBuffer::processKey(const KeyEvent& evt)
     187    {
     188        if (evt.isModifierDown(KeyboardModifier::Alt) && evt.getKeyCode() == KeyCode::Tab)
    189189            return;
    190190
    191191        for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    192192        {
    193             if ((*it)->trueKeyFalseChar_ && ((*it)->key_ == evt.key))
     193            if ((*it)->trueKeyFalseChar_ && ((*it)->key_ == evt.getKeyCode()))
    194194                (*it)->callFunction();
    195195        }
     
    197197        if (evt.isModifierDown(KeyboardModifier::Ctrl))
    198198        {
    199             if (evt.key == KeyCode::V)
     199            if (evt.getKeyCode() == KeyCode::V)
    200200                this->insert(fromClipboard());
    201             else if (evt.key == KeyCode::C)
     201            else if (evt.getKeyCode() == KeyCode::C)
    202202                toClipboard(this->buffer_);
    203             else if (evt.key == KeyCode::X)
     203            else if (evt.getKeyCode() == KeyCode::X)
    204204            {
    205205                toClipboard(this->buffer_);
     
    209209        else if (evt.isModifierDown(KeyboardModifier::Shift))
    210210        {
    211             if (evt.key == KeyCode::Insert)
     211            if (evt.getKeyCode() == KeyCode::Insert)
    212212                this->insert(fromClipboard());
    213             else if (evt.key == KeyCode::Delete)
     213            else if (evt.getKeyCode() == KeyCode::Delete)
    214214            {
    215215                toClipboard(this->buffer_);
     
    218218        }
    219219
    220         this->insert((char)evt.text);
     220        this->insert((char)evt.getText());
    221221    }
    222222
     
    225225        @param dt Delta time
    226226    */
    227     void InputBuffer::updateInput(float dt)
     227    void InputBuffer::keyboardUpdated(float dt)
    228228    {
    229229        timeSinceKeyPressed_ += dt;
     
    239239    }
    240240
    241     void InputBuffer::keyPressed(const KeyEvent &evt)
    242     {
    243         lastKey_ = evt.key;
     241    void InputBuffer::buttonPressed(const KeyEvent& evt)
     242    {
     243        lastKey_ = evt.getKeyCode();
    244244        timeSinceKeyPressed_ = 0.0;
    245245        timeSinceKeyRepeated_ = keyRepeatDeleay_;
     
    249249    }
    250250
    251     void InputBuffer::keyHeld(const KeyEvent& evt)
    252     {
    253         if (evt.key == lastKey_)
     251    void InputBuffer::buttonHeld(const KeyEvent& evt)
     252    {
     253        if (evt.getKeyCode() == lastKey_)
    254254        {
    255255            while (keysToRepeat_)
  • code/branches/core4/src/core/input/InputBuffer.h

    r3196 r3274  
    3030#define _InputBuffer_H__
    3131
    32 #include "core/CorePrereqs.h"
     32#include "InputPrereqs.h"
    3333
    3434#include <list>
    3535#include <string>
    3636#include "core/OrxonoxClass.h"
    37 #include "InputInterfaces.h"
     37#include "InputHandler.h"
    3838
    3939namespace orxonox
     
    7474    };
    7575
    76     class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass
     76    class _CoreExport InputBuffer : public InputHandler, public OrxonoxClass
    7777    {
    7878        public:
     
    165165            bool charIsAllowed(const char& input);
    166166
    167             void keyPressed (const KeyEvent& evt);
    168             void keyReleased(const KeyEvent& evt) { }
    169             void keyHeld    (const KeyEvent& evt);
    170             void processKey (const KeyEvent &e);
     167            void buttonPressed(const KeyEvent& evt);
     168            void buttonHeld   (const KeyEvent& evt);
     169            void processKey   (const KeyEvent& evt);
    171170
    172             void updateInput(float dt);
    173             void updateKey(float dt) { }
     171            void keyboardUpdated(float dt);
    174172
    175173            std::string buffer_;
  • code/branches/core4/src/core/input/InputCommands.h

    r2087 r3274  
    3636#define _InputCommands_H__
    3737
    38 #include "core/CorePrereqs.h"
     38#include "InputPrereqs.h"
    3939#include "core/CommandEvaluation.h"
    4040
  • code/branches/core4/src/core/input/InputHandler.h

    r3273 r3274  
    3333*/
    3434
    35 #ifndef _InputInterfaces_H__
    36 #define _InputInterfaces_H__
     35#ifndef _InputHandler_H__
     36#define _InputHandler_H__
    3737
    38 #include "core/CorePrereqs.h"
    39 
    40 #include <ois/OISKeyboard.h>
    41 #include <ois/OISMouse.h>
    42 #include <ois/OISJoyStick.h>
     38#include "InputPrereqs.h"
    4339#include "util/Math.h"
    4440
    4541namespace orxonox
    4642{
    47     namespace KeyCode
    48     {
    49         const unsigned int numberOfKeys = 0xEE; // 238
    50 
    51         // note: KeyCode comments were directly copied from OISKeyboard.h
    52         enum ByEnum
    53         {
    54             Unassigned    = OIS::KC_UNASSIGNED,
    55             Escape        = OIS::KC_ESCAPE,
    56             NumRow1       = OIS::KC_1,
    57             NumRow2       = OIS::KC_2,
    58             NumRow3       = OIS::KC_3,
    59             NumRow4       = OIS::KC_4,
    60             NumRow5       = OIS::KC_5,
    61             NumRow6       = OIS::KC_6,
    62             NumRow7       = OIS::KC_7,
    63             NumRow8       = OIS::KC_8,
    64             NumRow9       = OIS::KC_9,
    65             NumRow0       = OIS::KC_0,
    66             Minus         = OIS::KC_MINUS,           // - on main keyboard
    67             Equals        = OIS::KC_EQUALS,
    68             Back          = OIS::KC_BACK,            // backspace
    69             Tab           = OIS::KC_TAB,
    70             Q             = OIS::KC_Q,
    71             W             = OIS::KC_W,
    72             E             = OIS::KC_E,
    73             R             = OIS::KC_R,
    74             T             = OIS::KC_T,
    75             Y             = OIS::KC_Y,
    76             U             = OIS::KC_U,
    77             I             = OIS::KC_I,
    78             O             = OIS::KC_O,
    79             P             = OIS::KC_P,
    80             LeftBracket   = OIS::KC_LBRACKET,
    81             RightBracket  = OIS::KC_RBRACKET,
    82             Return        = OIS::KC_RETURN,          // Enter on main keyboard
    83             LeftControl   = OIS::KC_LCONTROL,
    84             A             = OIS::KC_A,
    85             S             = OIS::KC_S,
    86             D             = OIS::KC_D,
    87             F             = OIS::KC_F,
    88             G             = OIS::KC_G,
    89             H             = OIS::KC_H,
    90             J             = OIS::KC_J,
    91             K             = OIS::KC_K,
    92             L             = OIS::KC_L,
    93             Semicolon     = OIS::KC_SEMICOLON,
    94             Apostrophe    = OIS::KC_APOSTROPHE,
    95             Grave         = OIS::KC_GRAVE,           // accent
    96             LeftShift     = OIS::KC_LSHIFT,
    97             Backslash     = OIS::KC_BACKSLASH,
    98             Z             = OIS::KC_Z,
    99             X             = OIS::KC_X,
    100             C             = OIS::KC_C,
    101             V             = OIS::KC_V,
    102             B             = OIS::KC_B,
    103             N             = OIS::KC_N,
    104             M             = OIS::KC_M,
    105             Comma         = OIS::KC_COMMA,
    106             Period        = OIS::KC_PERIOD,          // . on main keyboard
    107             Slash         = OIS::KC_SLASH,           // / on main keyboard
    108             RightShift    = OIS::KC_RSHIFT,
    109             Multiply      = OIS::KC_MULTIPLY,        // * on numeric keypad
    110             LeftAlt       = OIS::KC_LMENU,           // left Alt
    111             Space         = OIS::KC_SPACE,
    112             CapsLock      = OIS::KC_CAPITAL,
    113             F1            = OIS::KC_F1,
    114             F2            = OIS::KC_F2,
    115             F3            = OIS::KC_F3,
    116             F4            = OIS::KC_F4,
    117             F5            = OIS::KC_F5,
    118             F6            = OIS::KC_F6,
    119             F7            = OIS::KC_F7,
    120             F8            = OIS::KC_F8,
    121             F9            = OIS::KC_F9,
    122             F10           = OIS::KC_F10,
    123             NumLock       = OIS::KC_NUMLOCK,
    124             ScrollLock    = OIS::KC_SCROLL,          // Scroll Lock
    125             Numpad7       = OIS::KC_NUMPAD7,
    126             Numpad8       = OIS::KC_NUMPAD8,
    127             Numpad9       = OIS::KC_NUMPAD9,
    128             NumpadSubtract= OIS::KC_SUBTRACT,        // - on numeric keypad
    129             Numpad4       = OIS::KC_NUMPAD4,
    130             Numpad5       = OIS::KC_NUMPAD5,
    131             Numpad6       = OIS::KC_NUMPAD6,
    132             NumpadAdd     = OIS::KC_ADD,             // + on numeric keypad
    133             Numpad1       = OIS::KC_NUMPAD1,
    134             Numpad2       = OIS::KC_NUMPAD2,
    135             Numpad3       = OIS::KC_NUMPAD3,
    136             Numpad0       = OIS::KC_NUMPAD0,
    137             NumpadPeriod  = OIS::KC_DECIMAL,         // . on numeric keypad
    138             LessThan      = OIS::KC_OEM_102,         // < > | on UK/Germany keyboards
    139             F11           = OIS::KC_F11,
    140             F12           = OIS::KC_F12,
    141             F13           = OIS::KC_F13,             //                     (NEC PC98)
    142             F14           = OIS::KC_F14,             //                     (NEC PC98)
    143             F15           = OIS::KC_F15,             //                     (NEC PC98)
    144             Kana          = OIS::KC_KANA,            // (Japanese keyboard)
    145             ABNT_C1       = OIS::KC_ABNT_C1,         // / ? on Portugese (Brazilian) keyboards
    146             Convert       = OIS::KC_CONVERT,         // (Japanese keyboard)
    147             NoConvert     = OIS::KC_NOCONVERT,       // (Japanese keyboard)
    148             Yen           = OIS::KC_YEN,             // (Japanese keyboard)
    149             ABNT_C2       = OIS::KC_ABNT_C2,         // Numpad . on Portugese (Brazilian) keyboards
    150             NumpadEquals  = OIS::KC_NUMPADEQUALS,    // = on numeric keypad (NEC PC98)
    151             PreviousTrack = OIS::KC_PREVTRACK,       // Previous Track (KC_CIRCUMFLEX on Japanese keyboard)
    152             AT            = OIS::KC_AT,              //                     (NEC PC98)
    153             Colon         = OIS::KC_COLON,           //                     (NEC PC98)
    154             Underline     = OIS::KC_UNDERLINE,       //                     (NEC PC98)
    155             Kanji         = OIS::KC_KANJI,           // (Japanese keyboard)
    156             Stop          = OIS::KC_STOP,            //                     (NEC PC98)
    157             AX            = OIS::KC_AX,              //                     (Japan AX)
    158             Unlabeled     = OIS::KC_UNLABELED,       //                        (J3100)
    159             NextTrack     = OIS::KC_NEXTTRACK,       // Next Track
    160             NumpadEnter   = OIS::KC_NUMPADENTER,     // Enter on numeric keypad
    161             RightControl  = OIS::KC_RCONTROL,
    162             Mute          = OIS::KC_MUTE,            // Mute
    163             Calculator    = OIS::KC_CALCULATOR,      // Calculator
    164             PlayPause     = OIS::KC_PLAYPAUSE,       // Play / Pause
    165             MediaStop     = OIS::KC_MEDIASTOP,       // Media Stop
    166             VolumeDown    = OIS::KC_VOLUMEDOWN,      // Volume -
    167             VolumeUp      = OIS::KC_VOLUMEUP,        // Volume +
    168             WebHome       = OIS::KC_WEBHOME,         // Web home
    169             NumpadComma   = OIS::KC_NUMPADCOMMA,     // , on numeric keypad (NEC PC98)
    170             Divide        = OIS::KC_DIVIDE,          // / on numeric keypad
    171             SystemRequest = OIS::KC_SYSRQ,
    172             RightAlt      = OIS::KC_RMENU,           // right Alt
    173             Pause         = OIS::KC_PAUSE,           // Pause
    174             Home          = OIS::KC_HOME,            // Home on arrow keypad
    175             Up            = OIS::KC_UP,              // UpArrow on arrow keypad
    176             PageUp        = OIS::KC_PGUP,            // PgUp on arrow keypad
    177             Left          = OIS::KC_LEFT,            // LeftArrow on arrow keypad
    178             Right         = OIS::KC_RIGHT,           // RightArrow on arrow keypad
    179             End           = OIS::KC_END,             // End on arrow keypad
    180             Down          = OIS::KC_DOWN,            // DownArrow on arrow keypad
    181             PageDown      = OIS::KC_PGDOWN,          // PgDn on arrow keypad
    182             Insert        = OIS::KC_INSERT,          // Insert on arrow keypad
    183             Delete        = OIS::KC_DELETE,          // Delete on arrow keypad
    184             LeftWindows   = OIS::KC_LWIN,            // Left Windows key
    185             RightWindows  = OIS::KC_RWIN,            // Right Windows key
    186             Apps          = OIS::KC_APPS,            // AppMenu key
    187             Power         = OIS::KC_POWER,           // System Power
    188             Sleep         = OIS::KC_SLEEP,           // System Sleep
    189             Wake          = OIS::KC_WAKE,            // System Wake
    190             WebSearch     = OIS::KC_WEBSEARCH,       // Web Search
    191             WebFavorites  = OIS::KC_WEBFAVORITES,    // Web Favorites
    192             WebRefresh    = OIS::KC_WEBREFRESH,      // Web Refresh
    193             WebStop       = OIS::KC_WEBSTOP,         // Web Stop
    194             WebForward    = OIS::KC_WEBFORWARD,      // Web Forward
    195             WebBack       = OIS::KC_WEBBACK,         // Web Back
    196             MyComputer    = OIS::KC_MYCOMPUTER,      // My Computer
    197             Mail          = OIS::KC_MAIL,            // Mail
    198             MediaSelect   = OIS::KC_MEDIASELECT      // Media Select
    199         };
    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
    306         {
    307             Left    = OIS::MB_Left,
    308             Right   = OIS::MB_Right,
    309             Middle  = OIS::MB_Middle,
    310             Button3 = OIS::MB_Button3,
    311             Button4 = OIS::MB_Button4,
    312             Button5 = OIS::MB_Button5,
    313             Button6 = OIS::MB_Button6,
    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
    354         {
    355             Button0       =  0, Button1       =  1, Button2       =  2, Button3       =  3,
    356             Button4       =  4, Button5       =  5, Button6       =  6, Button7       =  7,
    357             Button8       =  8, Button9       =  9, Button10      = 10, Button11      = 11,
    358             Button12      = 12, Button13      = 13, Button14      = 14, Button15      = 15,
    359             Button16      = 16, Button17      = 17, Button18      = 18, Button19      = 19,
    360             Button20      = 20, Button21      = 21, Button22      = 22, Button23      = 23,
    361             Button24      = 24, Button25      = 25, Button26      = 26, Button27      = 27,
    362             Button28      = 28, Button29      = 29, Button30      = 30, Button31      = 31,
    363 
    364             POV0North     = 32, POV0South     = 33, POV0East      = 34, POV0West      = 35,
    365             POV0NorthEast = 36, POV0SouthEast = 37, POV0NorthWest = 38, POV0SouthWest = 39,
    366 
    367             POV1North     = 40, POV1South     = 41, POV1East      = 42, POV1West      = 43,
    368             POV1NorthEast = 44, POV1SouthEast = 45, POV1NorthWest = 46, POV1SouthWest = 47,
    369 
    370             POV2North     = 48, POV2South     = 49, POV2East      = 50, POV2West      = 51,
    371             POV2NorthEast = 52, POV2SouthEast = 53, POV2NorthWest = 54, POV2SouthWest = 55,
    372 
    373             POV3North     = 56, POV3South     = 57, POV3East      = 58, POV3West      = 59,
    374             POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63,
    375         };
    376 
    377         // Names as string. Has no real linkage!
    378         const char* const ByString[] =
    379         {
    380             "Button00",      "Button01",      "Button02",      "Button03",
    381             "Button04",      "Button05",      "Button06",      "Button07",
    382             "Button08",      "Button09",      "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             "Axis00",  "Axis01",  "Axis02",  "Axis03",
    419             "Axis04",  "Axis05",  "Axis06",  "Axis07",
    420             "Axis08",  "Axis09",  "Axis10",  "Axis11",
    421             "Axis12",  "Axis13",  "Axis14",  "Axis15"
    422         };
    423     }
    424 
    425     namespace KeyboardModifier
    426     {
    427         enum Enum
    428         {
    429             Shift = 0x0000001,
    430             Ctrl  = 0x0000010,
    431             Alt   = 0x0000100
    432         };
    433     }
    434    
    435     namespace InputDevice
    436     {
    437         enum Enum
    438         {
    439             Keyboard,
    440             Mouse,
    441             JoyStick0,
    442             JoyStick1,
    443             JoyStick2,
    444             JoyStick3
    445             // note: No problem if there are more joy sticks. This enum is just for convenience.
    446         };
    447     }
    448 
    449     struct _CoreExport Key
    450     {
    451         Key(const OIS::KeyEvent& evt) : key((KeyCode::ByEnum)evt.key), text(evt.text) { }
    452         KeyCode::ByEnum key;
    453         unsigned int text;
    454     };
    455 
    456     class _CoreExport KeyEvent
    457     {
    458     public:
    459         KeyEvent(KeyCode::ByEnum key, unsigned int text) : key(key), text(text) { }
    460         KeyEvent(const OIS::KeyEvent& evt, unsigned int mod)
    461             : key((KeyCode::ByEnum)evt.key), text(evt.text), modifiers(mod) { }
    462         KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { }
    463         bool isModifierDown(KeyboardModifier::Enum modifier) const
    464             { return (KeyboardModifier::Enum)modifier&modifiers; }
    465 
    466         const KeyCode::ByEnum key;
    467         unsigned int text;
    468         unsigned int modifiers;
    469     };
    470 
    471 
     43    /**
     44    @brief
     45    */
    47246    class _CoreExport InputHandler
    47347    {
    47448    public:
    47549        virtual ~InputHandler() { }
    476         virtual void updateInput(float dt) = 0;
     50
     51        template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::TPress)
     52            { this->buttonPressed(button); }
     53        template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::TRelease)
     54            { this->buttonReleased(button); }
     55        template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::THold)
     56            { this->buttonHeld(button); }
     57        void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::TPress)
     58            { this->buttonPressed(device - InputDeviceEnumerator::FirstJoyStick, button); }
     59        void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::TRelease)
     60            { this->buttonReleased(device - InputDeviceEnumerator::FirstJoyStick, button); }
     61        void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::THold)
     62            { this->buttonHeld(device - InputDeviceEnumerator::FirstJoyStick, button); }
     63
     64        virtual void buttonPressed (const KeyEvent& evt) { }
     65        virtual void buttonReleased(const KeyEvent& evt) { }
     66        virtual void buttonHeld    (const KeyEvent& evt) { }
     67
     68        virtual void buttonPressed (MouseButtonCode::ByEnum button) { }
     69        virtual void buttonReleased(MouseButtonCode::ByEnum button) { }
     70        virtual void buttonHeld    (MouseButtonCode::ByEnum button) { }
     71        virtual void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { }
     72        virtual void mouseScrolled (int abs, int rel) { }
     73
     74        virtual void buttonPressed (unsigned int joyStick, JoyStickButtonCode::ByEnum button) { }
     75        virtual void buttonReleased(unsigned int joyStick, JoyStickButtonCode::ByEnum button) { }
     76        virtual void buttonHeld    (unsigned int joyStick, JoyStickButtonCode::ByEnum button) { }
     77        virtual void axisMoved     (unsigned int joyStick, unsigned int axis, float value){ }
     78
     79        virtual void keyboardUpdated(float dt) { }
     80        virtual void mouseUpdated   (float dt) { }
     81        virtual void joyStickUpdated(unsigned int joyStick, float dt) { }
     82
     83        virtual void allDevicesUpdated(float dt) { }
     84
     85        static InputHandler EMPTY;
    47786    };
    478 
    479     /**
    480     @brief
    481         Interface class used for key input listeners.
    482     */
    483     class _CoreExport KeyHandler : virtual public InputHandler
    484     {
    485     public:
    486         virtual ~KeyHandler() { }
    487         virtual void keyPressed (const KeyEvent& evt) = 0;
    488         virtual void keyReleased(const KeyEvent& evt) = 0;
    489         virtual void keyHeld    (const KeyEvent& evt) = 0;
    490         virtual void updateKey    (float dt) = 0;
    491     };
    492 
    493     /**
    494     @brief
    495         Interface class used for mouse input listeners.
    496     */
    497     class _CoreExport MouseHandler : virtual public InputHandler
    498     {
    499     public:
    500         virtual ~MouseHandler() { }
    501         virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0;
    502         virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0;
    503         virtual void mouseButtonHeld    (MouseButtonCode::ByEnum id) = 0;
    504         virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    505         virtual void mouseScrolled      (int abs, int rel)     = 0;
    506         virtual void updateMouse          (float dt) = 0;
    507     };
    508 
    509 
    510     /**
    511     @brief
    512         Interface class used for joy stick input listeners.
    513     */
    514     class _CoreExport JoyStickHandler : virtual public InputHandler
    515     {
    516     public:
    517         virtual ~JoyStickHandler() { }
    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;
    521         virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    522         virtual void updateJoyStick          (float dt, unsigned int joyStick) = 0;
    523     };
    524 
    525     class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
    526     {
    527         friend class InputManager;
    528     private:
    529         EmptyHandler() { }
    530         EmptyHandler(EmptyHandler&);
    531         virtual ~EmptyHandler() { }
    532 
    533         void updateInput(float dt) { }
    534         void updateJoyStick(float dt, unsigned int joyStick) { }
    535         void updateMouse(float dt) { }
    536         void updateKey(float dt) { }
    537 
    538         void keyPressed (const KeyEvent& evt) { }
    539         void keyReleased(const KeyEvent& evt) { }
    540         void keyHeld    (const KeyEvent& evt) { }
    541 
    542         void mouseButtonPressed (MouseButtonCode::ByEnum id) { }
    543         void mouseButtonReleased(MouseButtonCode::ByEnum id) { }
    544         void mouseButtonHeld    (MouseButtonCode::ByEnum id) { }
    545         void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { }
    546         void mouseScrolled      (int abs, int rel) { }
    547 
    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) { }
    551         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) { }
    552     };
    553 
    55487}
    55588
    556 #endif /* _InputInterfaces_H__ */
     89#endif /* _InputHandler_H__ */
  • code/branches/core4/src/core/input/InputManager.cc

    r3272 r3274  
    5050#include "core/ConsoleCommand.h"
    5151#include "core/CommandLine.h"
     52#include "core/Functor.h"
    5253
    5354#include "InputBuffer.h"
    5455#include "KeyDetector.h"
     56#include "InputHandler.h"
    5557#include "InputState.h"
    56 #include "SimpleInputState.h"
    57 #include "JoyStickDeviceNumberListener.h"
     58#include "JoyStickQuantityListener.h"
    5859#include "JoyStick.h"
     60#include "Mouse.h"
     61#include "Keyboard.h"
    5962
    6063// HACK (include this as last, X11 seems to define some macros...)
     
    7376    SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard");
    7477
    75     EmptyHandler InputManager::EMPTY_HANDLER;
     78    InputHandler InputHandler::EMPTY;
    7679    InputManager* InputManager::singletonRef_s = 0;
    77 
    78     using namespace InputDevice;
    7980
    8081    /**
     
    109110    InputManager::InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight)
    110111        : inputSystem_(0)
    111         , keyboard_(0)
    112         , mouse_(0)
    113         , devicesNum_(0)
     112        , devices_(2)
    114113        , windowHnd_(0)
    115114        , internalState_(Uninitialised)
     
    117116        , keyDetector_(0)
    118117        , calibratorCallbackBuffer_(0)
    119         , keyboardModifiers_(0)
    120118    {
    121119        RegisterRootObject(InputManager);
     
    182180#endif
    183181
     182            // TODO: clean this up
    184183            try
    185184            {
     
    199198            }
    200199
     200            // TODO: Remove the two parameters
    201201            _initialiseMouse(windowWidth, windowHeight);
    202202
     
    220220
    221221            // Lowest priority empty InputState
    222             stateEmpty_ = createInputState<SimpleInputState>("empty", false, false, InputStatePriority::Empty);
    223             stateEmpty_->setHandler(&EMPTY_HANDLER);
     222            stateEmpty_ = createInputState("empty", false, false, InputStatePriority::Empty);
     223            stateEmpty_->setHandler(&InputHandler::EMPTY);
    224224            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
    225225
    226226            // KeyDetector to evaluate a pressed key's name
    227             SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector);
     227            InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector);
     228            FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers);
     229            bufferFunctor->setObject(this);
     230            detector->setLeaveFunctor(bufferFunctor);
    228231            keyDetector_ = new KeyDetector();
    229232            detector->setHandler(keyDetector_);
    230233
    231234            // Joy stick calibration helper callback
    232             SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator);
    233             calibrator->setHandler(&EMPTY_HANDLER);
     235            InputState* calibrator = createInputState("calibrator", false, false, InputStatePriority::Calibrator);
     236            calibrator->setHandler(&InputHandler::EMPTY);
    234237            calibratorCallbackBuffer_ = new InputBuffer();
    235             calibratorCallbackBuffer_->registerListener(this, &InputManager::_completeCalibration, '\r', true);
     238            calibratorCallbackBuffer_->registerListener(this, &InputManager::_stopCalibration, '\r', true);
    236239            calibrator->setKeyHandler(calibratorCallbackBuffer_);
    237240
     
    246249    }
    247250
    248     /**
    249     @brief
    250         Creates a keyboard and sets the event handler.
    251     @return
    252         False if keyboard stays uninitialised, true otherwise.
    253     */
    254251    void InputManager::_initialiseKeyboard()
    255252    {
    256         if (keyboard_ != 0)
    257         {
    258             CCOUT(2) << "Warning: Keyboard already initialised, skipping." << std::endl;
    259             return;
    260         }
     253        assert(devices_[InputDeviceEnumerator::Keyboard] == 0);
    261254        if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)
    262         {
    263             keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true);
    264             // register our listener in OIS.
    265             keyboard_->setEventCallback(this);
    266             // note: OIS will not detect keys that have already been down when the keyboard was created.
    267             CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
    268         }
     255            devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard);
    269256        else
    270         {
    271257            ThrowException(InitialisationFailed, "InputManager: No keyboard found, cannot proceed!");
    272         }
    273     }
    274 
    275     /**
    276     @brief
    277         Creates a mouse and sets the event handler.
    278     @return
    279         False if mouse stays uninitialised, true otherwise.
    280     */
     258    }
     259
    281260    void InputManager::_initialiseMouse(unsigned int windowWidth, unsigned int windowHeight)
    282261    {
    283         if (mouse_ != 0)
    284         {
    285             CCOUT(2) << "Warning: Mouse already initialised, skipping." << std::endl;
    286             return;
    287         }
    288         try
    289         {
    290             if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
    291             {
    292                 mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
    293                 // register our listener in OIS.
    294                 mouse_->setEventCallback(this);
    295                 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl;
    296 
    297                 // Set mouse region
    298                 setWindowExtents(windowWidth, windowHeight);
    299             }
    300             else
    301             {
    302                 CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
    303             }
    304         }
    305         catch (OIS::Exception ex)
    306         {
    307             CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n"
    308                 << "OIS error message: \"" << ex.eText << "\"\n Proceeding without mouse support." << std::endl;
    309             mouse_ = 0;
    310         }
     262        assert(devices_[InputDeviceEnumerator::Mouse] == 0);
     263        if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
     264        {
     265            try
     266            {
     267                devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, windowWidth, windowHeight);
     268            }
     269            catch (const OIS::Exception& ex)
     270            {
     271                CCOUT(2) << "Warning: Failed to create Mouse:" << ex.eText << std::endl
     272                         << "Proceeding without mouse support." << std::endl;
     273            }
     274        }
     275        else
     276            CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
    311277    }
    312278
     
    319285    void InputManager::_initialiseJoySticks()
    320286    {
    321         if (!this->joySticks_.empty())
    322         {
    323             CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl;
    324             return;
    325         }
    326 
    327         devicesNum_ = 2 + inputSystem_->getNumberOfDevices(OIS::OISJoyStick);
    328         // state management
    329         activeStatesTriggered_.resize(devicesNum_);
     287        assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
    330288
    331289        for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++)
     
    333291            try
    334292            {
    335                 joySticks_.push_back(new JoyStick(activeStatesTriggered_[2 + i], i));
     293                devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i));
    336294            }
    337295            catch (std::exception ex)
     
    342300
    343301        // inform all JoyStick Device Number Listeners
    344         for (ObjectList<JoyStickDeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it)
    345             it->JoyStickDeviceNumberChanged(joySticks_.size());
     302        for (ObjectList<JoyStickQuantityListener>::iterator it = ObjectList<JoyStickQuantityListener>::begin(); it; ++it)
     303            it->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick);
    346304    }
    347305
    348306    void InputManager::_startCalibration()
    349307    {
    350         BOOST_FOREACH(JoyStick* stick, joySticks_)
    351             stick->startCalibration();
     308        BOOST_FOREACH(InputDevice* device, devices_)
     309            device->startCalibration();
    352310
    353311        getInstance().internalState_ |= Calibrating;
     
    355313    }
    356314
    357     void InputManager::_completeCalibration()
    358     {
    359         BOOST_FOREACH(JoyStick* stick, joySticks_)
    360             stick->stopCalibration();
     315    void InputManager::_stopCalibration()
     316    {
     317        BOOST_FOREACH(InputDevice* device, devices_)
     318            device->stopCalibration();
    361319
    362320        // restore old input state
    363321        requestLeaveState("calibrator");
    364322        internalState_ &= ~Calibrating;
     323        // Clear buffers to prevent button hold events
     324        this->clearBuffers();
    365325    }
    366326
     
    374334        Destroys all the created input devices and states.
    375335    */
     336    // TODO: export this to be used with reload()
    376337    InputManager::~InputManager()
    377338    {
     
    379340        {
    380341            CCOUT(3) << "Destroying ..." << std::endl;
    381 
    382             // kick all active states 'nicely'
    383             for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
    384                 rit != activeStates_.rend(); ++rit)
    385             {
    386                 (*rit).second->onLeave();
    387             }
    388342
    389343            // Destroy calibrator helper handler and state
     
    401355
    402356            // destroy the devices
    403             _destroyKeyboard();
    404             _destroyMouse();
    405             _destroyJoySticks();
     357            BOOST_FOREACH(InputDevice*& device, devices_)
     358            {
     359                std::string className = device->getClassName();
     360                try
     361                {
     362                    if (device)
     363                        delete device;
     364                    device = 0;
     365                    CCOUT(4) << className << " destroyed." << std::endl;
     366                }
     367                catch (...)
     368                {
     369                    CCOUT(1) << className << " destruction failed! Potential resource leak!" << std::endl;
     370                }
     371            }
     372            devices_.resize(InputDeviceEnumerator::FirstJoyStick);
    406373
    407374            try
     
    416383
    417384        singletonRef_s = 0;
    418     }
    419 
    420     /**
    421     @brief
    422         Destroys the keyboard and sets it to 0.
    423     */
    424     void InputManager::_destroyKeyboard()
    425     {
    426         assert(inputSystem_);
    427         try
    428         {
    429             if (keyboard_)
    430                 inputSystem_->destroyInputObject(keyboard_);
    431             keyboard_ = 0;
    432             CCOUT(4) << "Keyboard destroyed." << std::endl;
    433         }
    434         catch (...)
    435         {
    436             CCOUT(1) << "Keyboard destruction failed! Potential resource leak!" << std::endl;
    437         }
    438     }
    439 
    440     /**
    441     @brief
    442         Destroys the mouse and sets it to 0.
    443     */
    444     void InputManager::_destroyMouse()
    445     {
    446         assert(inputSystem_);
    447         try
    448         {
    449             if (mouse_)
    450                 inputSystem_->destroyInputObject(mouse_);
    451             mouse_ = 0;
    452             CCOUT(4) << "Mouse destroyed." << std::endl;
    453         }
    454         catch (...)
    455         {
    456             CCOUT(1) << "Mouse destruction failed! Potential resource leak!" << std::endl;
    457         }
    458     }
    459 
    460     /**
    461     @brief
    462         Destroys all the joy sticks and resizes the lists to 0.
    463     */
    464     void InputManager::_destroyJoySticks()
    465     {
    466         assert(inputSystem_);
    467         while (!joySticks_.empty())
    468         {
    469             try
    470             {
    471                 delete joySticks_.back();
    472             }
    473             catch (...)
    474             {
    475                 CCOUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl;
    476             }
    477             joySticks_.pop_back();
    478             devicesNum_ = 2;
    479         }
    480         CCOUT(4) << "Joy sticks destroyed." << std::endl;
    481385    }
    482386
     
    539443
    540444            // Save mouse clipping size
    541             int mouseWidth  = mouse_->getMouseState().width;
    542             int mouseHeight = mouse_->getMouseState().height;
     445            int mouseWidth  = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingWidth();
     446            int mouseHeight = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingHeight();
    543447
    544448            internalState_ &= ~OISReady;
    545449
    546450            // destroy the devices
    547             _destroyKeyboard();
    548             _destroyMouse();
    549             _destroyJoySticks();
     451            // destroy the devices
     452            BOOST_FOREACH(InputDevice*& device, devices_)
     453            {
     454                try
     455                {
     456                    if (device)
     457                        delete device;
     458                    device = 0;
     459                    CCOUT(4) << device->getClassName() << " destroyed." << std::endl;
     460                }
     461                catch (...)
     462                {
     463                    CCOUT(1) << device->getClassName() << " destruction failed! Potential resource leak!" << std::endl;
     464                }
     465            }
     466            devices_.resize(InputDeviceEnumerator::FirstJoyStick);
    550467
    551468            OIS::InputManager::destroyInputSystem(inputSystem_);
     
    592509                it != stateLeaveRequests_.end(); ++it)
    593510            {
    594                 (*it)->onLeave();
     511                (*it)->left();
    595512                // just to be sure that the state actually is registered
    596513                assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     
    631548                activeStates_[(*it)->getPriority()] = (*it);
    632549                _updateActiveStates();
    633                 (*it)->onEnter();
     550                (*it)->entered();
    634551            }
    635552            stateEnterRequests_.clear();
     
    647564        }
    648565
    649         // check whether a state has changed its EMPTY_HANDLER situation
     566        // check whether a state has changed its EMPTY situation
    650567        bool bUpdateRequired = false;
    651568        for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
    652569        {
    653             if (it->second->handlersChanged())
    654             {
    655                 it->second->resetHandlersChanged();
     570            if (it->second->hasExpired())
     571            {
     572                it->second->resetExpiration();
    656573                bUpdateRequired = true;
    657574            }
     
    664581
    665582        // Capture all the input. This calls the event handlers in InputManager.
    666         if (keyboard_)
    667             keyboard_->capture();
    668         if (mouse_)
    669             mouse_->capture();
    670         BOOST_FOREACH(JoyStick* stick, joySticks_)
    671             stick->capture();
     583        BOOST_FOREACH(InputDevice* device, devices_)
     584            device->update(time);
    672585
    673586        if (!(internalState_ & Calibrating))
    674587        {
    675             // call all the handlers for the held key events
    676             for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    677             {
    678                 KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_);
    679 
    680                 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
    681                     activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt);
    682             }
    683 
    684             // call all the handlers for the held mouse button events
    685             for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    686             {
    687                 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    688                     activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    689             }
    690 
    691             // update the handlers for each active handler
    692             for (unsigned int i = 0; i < devicesNum_; ++i)
    693             {
    694                 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
    695                     activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i);
    696             }
    697 
    698             // update the handler with a general tick afterwards
     588            // update the states with a general tick afterwards
    699589            for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
    700                 activeStatesTicked_[i]->updateInput(time.getDeltaTime());
     590                activeStatesTicked_[i]->update(time.getDeltaTime());
    701591        }
    702592
     
    711601    void InputManager::_updateActiveStates()
    712602    {
    713         for (unsigned int i = 0; i < devicesNum_; ++i)
    714         {
     603        // temporary resize
     604        for (unsigned int i = 0; i < devices_.size(); ++i)
     605        {
     606            std::vector<InputState*>& states = devices_[i]->getStateListRef();
    715607            bool occupied = false;
    716             activeStatesTriggered_[i].clear();
    717             for (std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
     608            states.clear();
     609            for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
    718610            {
    719611                if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_))
    720612                {
    721                     activeStatesTriggered_[i].push_back(rit->second);
     613                    states.push_back(rit->second);
    722614                    if (!rit->second->bTransparent_)
    723615                        occupied = true;
     
    729621        // Using a std::set to avoid duplicates
    730622        std::set<InputState*> tempSet;
    731         for (unsigned int i = 0; i < devicesNum_; ++i)
    732             for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
    733                 tempSet.insert(activeStatesTriggered_[i][iState]);
     623        for (unsigned int i = 0; i < devices_.size(); ++i)
     624            for (unsigned int iState = 0; iState < devices_[i]->getStateListRef().size(); ++iState)
     625                tempSet.insert(devices_[i]->getStateListRef()[iState]);
    734626
    735627        // copy the content of the std::set back to the actual vector
     
    737629        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
    738630            activeStatesTicked_.push_back(*it);
    739 
    740         this->mouseButtonsDown_.clear();
    741631    }
    742632
     
    747637    void InputManager::clearBuffers()
    748638    {
    749         keysDown_.clear();
    750         keyboardModifiers_ = 0;
    751         mouseButtonsDown_.clear();
    752         BOOST_FOREACH(JoyStick* stick, joySticks_)
    753             stick->clearBuffer();
    754     }
    755 
    756 
    757     // ############################################################
    758     // #####                    OIS events                    #####
    759     // ##########                                        ##########
    760     // ############################################################
    761 
    762     // ###### Key Events ######
    763 
    764     /**
    765     @brief
    766         Event handler for the keyPressed Event.
    767     @param e
    768         Event information
    769     */
    770     bool InputManager::keyPressed(const OIS::KeyEvent &e)
    771     {
    772         // check whether the key already is in the list (can happen when focus was lost)
    773         unsigned int iKey = 0;
    774         while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::ByEnum)e.key)
    775             iKey++;
    776         if (iKey == keysDown_.size())
    777             keysDown_.push_back(Key(e));
    778         else
    779         {
    780             // This happens when XAutoRepeat is set under linux. The KeyPressed event gets then sent
    781             // continuously.
    782             return true;
    783         }
    784 
    785         // update modifiers
    786         if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
    787             keyboardModifiers_ |= KeyboardModifier::Alt;   // alt key
    788         if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
    789             keyboardModifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
    790         if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
    791             keyboardModifiers_ |= KeyboardModifier::Shift; // shift key
    792 
    793         KeyEvent kEvt(e, keyboardModifiers_);
    794         for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
    795             activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt);
    796 
    797         return true;
    798     }
    799 
    800     /**
    801     @brief
    802         Event handler for the keyReleased Event.
    803     @param e
    804         Event information
    805     */
    806     bool InputManager::keyReleased(const OIS::KeyEvent &e)
    807     {
    808         // remove the key from the keysDown_ list
    809         for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    810         {
    811             if (keysDown_[iKey].key == (KeyCode::ByEnum)e.key)
    812             {
    813                 keysDown_.erase(keysDown_.begin() + iKey);
    814                 break;
    815             }
    816         }
    817 
    818         // update modifiers
    819         if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
    820             keyboardModifiers_ &= ~KeyboardModifier::Alt;   // alt key
    821         if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
    822             keyboardModifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
    823         if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
    824             keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key
    825 
    826         KeyEvent kEvt(e, keyboardModifiers_);
    827         for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
    828             activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt);
    829 
    830         return true;
    831     }
    832 
    833 
    834     // ###### Mouse Events ######
    835 
    836     /**
    837     @brief
    838         Event handler for the mouseMoved Event.
    839     @param e
    840         Event information
    841     */
    842     bool InputManager::mouseMoved(const OIS::MouseEvent &e)
    843     {
    844         // check for actual moved event
    845         if (e.state.X.rel != 0 || e.state.Y.rel != 0)
    846         {
    847             IntVector2 abs(e.state.X.abs, e.state.Y.abs);
    848             IntVector2 rel(e.state.X.rel, e.state.Y.rel);
    849             IntVector2 clippingSize(e.state.width, e.state.height);
    850             for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    851                 activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize);
    852         }
    853 
    854         // check for mouse scrolled event
    855         if (e.state.Z.rel != 0)
    856         {
    857             for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    858                 activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    859         }
    860 
    861         return true;
    862     }
    863 
    864     /**
    865     @brief
    866         Event handler for the mousePressed Event.
    867     @param e
    868         Event information
    869     @param id
    870         The ID of the mouse button
    871     */
    872     bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    873     {
    874         // check whether the button already is in the list (can happen when focus was lost)
    875         unsigned int iButton = 0;
    876         while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButtonCode::ByEnum)id)
    877             iButton++;
    878         if (iButton == mouseButtonsDown_.size())
    879             mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id);
    880 
    881         for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    882             activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    883 
    884         return true;
    885     }
    886 
    887     /**
    888     @brief
    889         Event handler for the mouseReleased Event.
    890     @param e
    891         Event information
    892     @param id
    893         The ID of the mouse button
    894     */
    895     bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    896     {
    897         // remove the button from the keysDown_ list
    898         for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    899         {
    900             if (mouseButtonsDown_[iButton] == (MouseButtonCode::ByEnum)id)
    901             {
    902                 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton);
    903                 break;
    904             }
    905         }
    906 
    907         for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    908             activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    909 
    910         return true;
     639        BOOST_FOREACH(InputDevice* device, devices_)
     640            device->clearBuffers();
    911641    }
    912642
     
    923653        Returns true if ID is ok (unique), false otherwise.
    924654    */
    925     bool InputManager::checkJoyStickID(const std::string& idString)
    926     {
    927         BOOST_FOREACH(JoyStick* stick, joySticks_)
    928         {
    929             if (stick->getIDString() == idString)
     655    bool InputManager::checkJoyStickID(const std::string& idString) const
     656    {
     657        for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i)
     658            if (static_cast<JoyStick*>(devices_[i])->getIDString() == idString)
    930659                return false;
    931         }
    932660        return true;
    933661    }
     
    938666    // ##########                                        ##########
    939667    // ############################################################
    940 
    941     /**
    942     @brief
    943         Adjusts the mouse window metrics.
    944         This method has to be called every time the size of the window changes.
    945     @param width
    946         The new width of the render window
    947     @param^height
    948         The new height of the render window
    949     */
    950     void InputManager::setWindowExtents(const int width, const int height)
    951     {
    952         if (mouse_)
    953         {
    954             // Set mouse region (if window resizes, we should alter this to reflect as well)
    955             mouse_->getMouseState().width  = width;
    956             mouse_->getMouseState().height = height;
    957         }
    958     }
    959668
    960669    /**
     
    970679
    971680    // ###### InputStates ######
     681
     682    /**
     683    @brief
     684        Creates a new InputState by type, name and priority.
     685       
     686        You will have to use this method because the
     687        c'tors and d'tors are private.
     688    @remarks
     689        The InputManager will take care of the state completely. That also
     690        means it gets deleted when the InputManager is destroyed!
     691    @param name
     692        Name of the InputState when referenced as string
     693    @param priority
     694        Priority matters when multiple states are active. You can specify any
     695        number, but 1 - 99 is preferred (99 means high).
     696    */
     697    InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
     698    {
     699        InputState* state = new InputState;
     700        if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))
     701            return state;
     702        else
     703        {
     704            delete state;
     705            return 0;
     706        }
     707    }
    972708
    973709    /**
     
    1008744            }
    1009745            inputStatesByName_[name] = state;
    1010             state->JoyStickDeviceNumberChanged(numberOfJoySticks());
     746            state->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick);
    1011747            state->setName(name);
    1012748            state->bAlwaysGetsInput_ = bAlwaysGetsInput;
  • code/branches/core4/src/core/input/InputManager.h

    r3270 r3274  
    3737#define _InputManager_H__
    3838
    39 #include "core/CorePrereqs.h"
     39#include "InputPrereqs.h"
    4040
    4141#include <map>
     
    4343#include <string>
    4444#include <vector>
    45 #include <ois/OISKeyboard.h>
    46 #include <ois/OISMouse.h>
    47 #include <ois/OISJoyStick.h>
    4845
    4946#include "util/Math.h"
    5047#include "util/OrxEnum.h"
    5148#include "core/OrxonoxClass.h"
    52 #include "InputInterfaces.h"
    5349
    5450namespace orxonox
     
    7167        Captures and distributes mouse and keyboard input.
    7268    */
    73     class _CoreExport InputManager
    74         : public OrxonoxClass,
    75         public OIS::KeyListener, public OIS::MouseListener
     69    class _CoreExport InputManager : public OrxonoxClass
    7670    {
    7771        // --> setConfigValues is private
    7872        friend class ClassIdentifier<InputManager>;
    79         friend class JoyStick;
    8073
    8174    public:
     
    9992        void clearBuffers();
    10093
    101         unsigned int  numberOfKeyboards() { return keyboard_ ? 1 : 0; }
    102         unsigned int  numberOfMice()      { return mouse_    ? 1 : 0; }
    103         unsigned int  numberOfJoySticks() { return joySticks_.size(); }
    104 
    10594        void setWindowExtents(const int width, const int height);
    10695        void setKeyDetectorCallback(const std::string& command);
    10796
    108         template <class T>
    109         T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
     97        InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
    11098
    11199        InputState* getState       (const std::string& name);
     
    114102        bool requestEnterState     (const std::string& name);
    115103        bool requestLeaveState     (const std::string& name);
     104
     105        OIS::InputManager* getInputSystem() { return this->inputSystem_; }
     106        bool checkJoyStickID(const std::string& idString) const;
     107        unsigned int getJoyStickQuantity() const
     108            { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
    116109
    117110#ifdef ORXONOX_PLATFORM_LINUX
     
    130123        static void reload();
    131124
    132     public: // variables
    133         static EmptyHandler                 EMPTY_HANDLER;
    134 
    135     private: // functions for friends
    136         OIS::InputManager* getInputSystem() { return this->inputSystem_; }
    137         bool checkJoyStickID(const std::string&);
    138 
    139125    private: // functions
    140126        // don't mess with a Singleton
    141         InputManager (const InputManager&);
     127        InputManager(const InputManager&);
    142128
    143129        // Intenal methods
     
    145131        void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight);
    146132        void _initialiseJoySticks();
    147         void _configureJoySticks();
    148133
    149         void _loadCalibration();
    150134        void _startCalibration();
    151         void _completeCalibration();
    152         void _evaluateCalibration();
     135        void _stopCalibration();
    153136
    154         void _destroyKeyboard();
    155         void _destroyMouse();
    156         void _destroyJoySticks();
    157137        void _destroyState(InputState* state);
    158138
    159139        void _reload();
    160140
    161         void _fireAxis(unsigned int iJoyStick, int axis, int value);
    162         unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
    163 
    164141        void _updateActiveStates();
    165142        bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);
    166143
    167         // input events
    168         bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
    169         bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
    170         bool mouseMoved    (const OIS::MouseEvent    &arg);
    171         bool keyPressed    (const OIS::KeyEvent      &arg);
    172         bool keyReleased   (const OIS::KeyEvent      &arg);
    173 
    174144        void setConfigValues();
    175         void _calibrationFileCallback();
    176145
    177146    private: // variables
    178147        OIS::InputManager*                  inputSystem_;          //!< OIS input manager
    179         OIS::Keyboard*                      keyboard_;             //!< OIS mouse
    180         OIS::Mouse*                         mouse_;                //!< OIS keyboard
    181         std::vector<JoyStick*>              joySticks_;            //!< Orxonox joy sticks
    182         unsigned int                        devicesNum_;
     148        std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
    183149        size_t                              windowHnd_;            //!< Render window handle
    184150        InputManagerState                   internalState_;        //!< Current internal state
    185151
    186152        // some internally handled states and handlers
    187         SimpleInputState*                   stateEmpty_;
     153        InputState*                         stateEmpty_;
    188154        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    189155        InputBuffer*                        calibratorCallbackBuffer_;
     
    196162
    197163        std::map<int, InputState*>          activeStates_;
    198         std::vector<std::vector<InputState*> > activeStatesTriggered_;
    199164        std::vector<InputState*>            activeStatesTicked_;
    200 
    201         unsigned int                        keyboardModifiers_;    //!< Bit mask representing keyboard modifiers.
    202 
    203         std::vector<Key>                    keysDown_;
    204         std::vector<MouseButtonCode::ByEnum> mouseButtonsDown_;
    205165
    206166        static InputManager*                singletonRef_s;
    207167    };
    208 
    209     /**
    210     @brief
    211         Creates a new InputState by type, name and priority.
    212        
    213         You will have to use this method because the
    214         c'tors and d'tors are private.
    215     @remarks
    216         The InputManager will take care of the state completely. That also
    217         means it gets deleted when the InputManager is destroyed!
    218     @param name
    219         Name of the InputState when referenced as string
    220     @param priority
    221         Priority matters when multiple states are active. You can specify any
    222         number, but 1 - 99 is preferred (99 means high).
    223     */
    224     template <class T>
    225     T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
    226     {
    227         T* state = new T;
    228         if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))
    229             return state;
    230         else
    231         {
    232             delete state;
    233             return 0;
    234         }
    235     }
    236168}
    237169
  • code/branches/core4/src/core/input/InputPrereqs.h

    r3251 r3274  
    3333*/
    3434
    35 #ifndef _InputInterfaces_H__
    36 #define _InputInterfaces_H__
     35#ifndef _InputPrereqs_H__
     36#define _InputPrereqs_H__
    3737
    3838#include "core/CorePrereqs.h"
     
    4141#include <ois/OISMouse.h>
    4242#include <ois/OISJoyStick.h>
    43 #include "util/Math.h"
    4443
    4544namespace orxonox
    4645{
     46    //-----------------------------------------------------------------------
     47    // Code enumerations
     48    //-----------------------------------------------------------------------
     49
    4750    namespace KeyCode
    4851    {
     
    299302    }
    300303
     304
    301305    namespace MouseButtonCode
    302306    {
     
    346350        };
    347351    }
     352
    348353
    349354    namespace JoyStickButtonCode
     
    423428    }
    424429
     430
     431    //-----------------------------------------------------------------------
     432    // Miscellaneous
     433    //-----------------------------------------------------------------------
     434
     435    namespace InputDeviceEnumerator
     436    {
     437        enum Value
     438        {
     439            Keyboard = 0,
     440            Mouse = 1,
     441            FirstJoyStick = 2
     442        };
     443    }
     444
     445    namespace ButtonEvent
     446    {
     447        enum Value
     448        {
     449            Press,
     450            Release,
     451            Hold
     452        };
     453
     454        template <ButtonEvent::Value Event>
     455        struct EnumToType { };
     456        typedef EnumToType<Press>   TPress;
     457        typedef EnumToType<Release> TRelease;
     458        typedef EnumToType<Hold>    THold;
     459    }
     460
     461
    425462    namespace KeyboardModifier
    426463    {
     
    432469        };
    433470    }
    434    
    435     namespace InputDevice
    436     {
    437         enum Enum
    438         {
    439             Keyboard,
    440             Mouse,
    441             JoyStick0,
    442             JoyStick1,
    443             JoyStick2,
    444             JoyStick3
    445             // note: No problem if there are more joy sticks. This enum is just for convenience.
    446         };
    447     }
    448 
    449     struct _CoreExport Key
    450     {
    451         Key(const OIS::KeyEvent& evt) : key((KeyCode::ByEnum)evt.key), text(evt.text) { }
    452         KeyCode::ByEnum key;
    453         unsigned int text;
     471
     472    class _CoreExport KeyEvent
     473    {
     474    public:
     475        KeyEvent(const OIS::KeyEvent& evt)
     476            : key_(static_cast<KeyCode::ByEnum>(evt.key))
     477            , text_(evt.text)
     478            , modifiers_(0)
     479        { }
     480        bool operator==(const KeyEvent& rhs) const
     481            { return rhs.key_ == key_; }
     482        bool operator!=(const KeyEvent& rhs) const
     483            { return rhs.key_ != key_; }
     484        void setModifiers(int modifiers)
     485            { modifiers_ = modifiers; }
     486
     487        bool isModifierDown(KeyboardModifier::Enum modifier) const
     488            { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); }
     489        KeyCode::ByEnum getKeyCode() const
     490            { return key_; }
     491        unsigned int getText() const { return text_; }
     492
     493    private:
     494        KeyCode::ByEnum key_;
     495        unsigned int text_;
     496        int modifiers_;
    454497    };
    455498
    456     class _CoreExport KeyEvent
    457     {
    458     public:
    459         KeyEvent(KeyCode::ByEnum key, unsigned int text) : key(key), text(text) { }
    460         KeyEvent(const OIS::KeyEvent& evt, unsigned int mod)
    461             : key((KeyCode::ByEnum)evt.key), text(evt.text), modifiers(mod) { }
    462         KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { }
    463         bool isModifierDown(KeyboardModifier::Enum modifier) const
    464             { return (KeyboardModifier::Enum)modifier&modifiers; }
    465 
    466         const KeyCode::ByEnum key;
    467         unsigned int text;
    468         unsigned int modifiers;
     499
     500    //-----------------------------------------------------------------------
     501    // Device type traits
     502    //-----------------------------------------------------------------------
     503
     504    struct KeyboardTraits
     505    {
     506        typedef Keyboard DeviceClass;
     507        typedef OIS::Keyboard OISDeviceClass;
     508        typedef KeyEvent ButtonType;
     509        typedef KeyEvent& ButtonTypeParam;
     510        static const OIS::Type OISDeviceValue = OIS::OISKeyboard;
    469511    };
    470512
    471 
    472     class _CoreExport InputHandler
    473     {
    474     public:
    475         virtual ~InputHandler() { }
    476         virtual void updateInput(float dt) = 0;
     513    struct MouseTraits
     514    {
     515        typedef Mouse DeviceClass;
     516        typedef OIS::Mouse OISDeviceClass;
     517        typedef MouseButtonCode::ByEnum ButtonType;
     518        typedef MouseButtonCode::ByEnum ButtonTypeParam;
     519        static const OIS::Type OISDeviceValue = OIS::OISMouse;
    477520    };
    478521
    479     /**
    480     @brief
    481         Interface class used for key input listeners.
    482     */
    483     class _CoreExport KeyHandler : virtual public InputHandler
    484     {
    485     public:
    486         virtual ~KeyHandler() { }
    487         virtual void keyPressed (const KeyEvent& evt) = 0;
    488         virtual void keyReleased(const KeyEvent& evt) = 0;
    489         virtual void keyHeld    (const KeyEvent& evt) = 0;
    490         virtual void updateKey    (float dt) = 0;
     522    struct JoyStickTraits
     523    {
     524        typedef JoyStick DeviceClass;
     525        typedef OIS::JoyStick OISDeviceClass;
     526        typedef JoyStickButtonCode::ByEnum ButtonType;
     527        typedef JoyStickButtonCode::ByEnum ButtonTypeParam;
     528        static const OIS::Type OISDeviceValue = OIS::OISJoyStick;
    491529    };
    492530
    493     /**
    494     @brief
    495         Interface class used for mouse input listeners.
    496     */
    497     class _CoreExport MouseHandler : virtual public InputHandler
    498     {
    499     public:
    500         virtual ~MouseHandler() { }
    501         virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0;
    502         virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0;
    503         virtual void mouseButtonHeld    (MouseButtonCode::ByEnum id) = 0;
    504         virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    505         virtual void mouseScrolled      (int abs, int rel)     = 0;
    506         virtual void updateMouse          (float dt) = 0;
    507     };
    508 
    509 
    510     /**
    511     @brief
    512         Interface class used for joy stick input listeners.
    513     */
    514     class _CoreExport JoyStickHandler : virtual public InputHandler
    515     {
    516     public:
    517         virtual ~JoyStickHandler() { }
    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;
    521         virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    522         virtual void updateJoyStick          (float dt, unsigned int joyStick) = 0;
    523     };
    524 
    525     class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
    526     {
    527         friend class InputManager;
    528     private:
    529         EmptyHandler() { }
    530         EmptyHandler(EmptyHandler&);
    531         virtual ~EmptyHandler() { }
    532 
    533         void updateInput(float dt) { }
    534         void updateJoyStick(float dt, unsigned int joyStick) { }
    535         void updateMouse(float dt) { }
    536         void updateKey(float dt) { }
    537 
    538         void keyPressed (const KeyEvent& evt) { }
    539         void keyReleased(const KeyEvent& evt) { }
    540         void keyHeld    (const KeyEvent& evt) { }
    541 
    542         void mouseButtonPressed (MouseButtonCode::ByEnum id) { }
    543         void mouseButtonReleased(MouseButtonCode::ByEnum id) { }
    544         void mouseButtonHeld    (MouseButtonCode::ByEnum id) { }
    545         void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { }
    546         void mouseScrolled      (int abs, int rel) { }
    547 
    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) { }
    551         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) { }
    552     };
    553 
     531    // Note: Entries correspond to OIS::Type enum
     532    namespace InputDeviceNames
     533    {
     534        const char* const values[] = { "", "Keyboard", "Mouse", "JoyStick" };
     535    }
    554536}
    555537
    556 #endif /* _InputInterfaces_H__ */
     538#endif /* _InputPrereqs_H__ */
  • code/branches/core4/src/core/input/InputState.cc

    r3272 r3274  
    2727 */
    2828
    29 /**
    30 @file
    31 @brief
    32     Implementation of the SimpleInputState class.
    33 */
    34 
    35 #include "SimpleInputState.h"
    36 #include "core/Executor.h"
     29#include "InputState.h"
     30#include "core/Functor.h"
    3731
    3832namespace orxonox
    3933{
    40     SimpleInputState::SimpleInputState()
    41         : keyHandler_(0)
    42         , mouseHandler_(0)
     34    InputState::InputState()
     35        : priority_(0)
     36        , bAlwaysGetsInput_(false)
     37        , bTransparent_(false)
     38        , bExpired_(true)
     39        , handlers_(2)
    4340        , joyStickHandlerAll_(0)
     41        , enterFunctor_(0)
     42        , leaveFunctor_(0)
    4443    {
    4544    }
    4645
    47     void SimpleInputState::numberOfJoySticksChanged(unsigned int n)
     46    bool InputState::isInputDeviceEnabled(unsigned int device)
    4847    {
    49         unsigned int oldSize = joyStickHandler_.size();
    50         joyStickHandler_.resize(n);
     48        if (device < handlers_.size())
     49            return handlers_[device] != NULL;
     50        else
     51            return false;
     52    }
    5153
    52         if (n > oldSize)
    53         {
    54             // we have to add the handler in joyStickHandlerAll_ to the joyStickHandler_[>n]
    55             for (unsigned int i = oldSize; i < n; ++i)
    56             {
    57                 joyStickHandler_[i] = joyStickHandlerAll_;
    58             }
    59         }
    60         update();
     54    void InputState::JoyStickQuantityChanged(unsigned int n)
     55    {
     56        unsigned int oldSize = handlers_.size();
     57        handlers_.resize(InputDeviceEnumerator::FirstJoyStick + n, NULL);
     58
     59        for (unsigned int i = oldSize; i < handlers_.size(); ++i)
     60            handlers_[i] = joyStickHandlerAll_;
     61
     62        bExpired_ = true;
    6163    }
    6264
     
    7173        True if added, false otherwise.
    7274    */
    73     bool SimpleInputState::setJoyStickHandler(JoyStickHandler* handler, unsigned int joyStickID)
     75    bool InputState::setJoyStickHandler(InputHandler* handler, unsigned int joyStick)
    7476    {
    75         if (joyStickID >= joyStickHandler_.size())
     77        unsigned device = joyStick + firstJoyStickIndex_s;
     78        if (joyStick >= handlers_.size() - device)
    7679            return false;
    7780
    78         joyStickHandler_[joyStickID] = handler;
    79         update();
     81        handlers_[device] = handler;
     82        bExpired_ = true;
    8083        return true;
    8184    }
     
    8992        True if added, false if handler already existed.
    9093    */
    91     bool SimpleInputState::setJoyStickHandler(JoyStickHandler* handler)
     94    bool InputState::setJoyStickHandler(InputHandler* handler)
    9295    {
    93         if (handler == joyStickHandlerAll_)
    94             return false;
    95 
    9696        joyStickHandlerAll_ = handler;
    97         for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); ++iJoyStick)
    98             setJoyStickHandler(handler, iJoyStick);
    99         update();
     97        for (unsigned int i = firstJoyStickIndex_s; i < handlers_.size(); ++i)
     98            handlers_[i] = handler;
     99        bExpired_ = true;
    100100        return true;
    101101    }
     
    109109        True if added, false if handler already existed.
    110110    */
    111     bool SimpleInputState::setHandler(InputHandler* handler)
     111    bool InputState::setHandler(InputHandler* handler)
    112112    {
    113         setKeyHandler(dynamic_cast<KeyHandler*>(handler));
    114         setMouseHandler(dynamic_cast<MouseHandler*>(handler));
    115         return setJoyStickHandler(dynamic_cast<JoyStickHandler*>(handler));
     113        setKeyHandler(handler);
     114        setMouseHandler(handler);
     115        return setJoyStickHandler(handler);
    116116    }
    117117
    118     void SimpleInputState::update()
     118    void InputState::entered()
    119119    {
    120         // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
    121         std::set<InputHandler*> tempSet;
    122         if (keyHandler_)
    123             tempSet.insert(keyHandler_);
    124         if (mouseHandler_)
    125             tempSet.insert(mouseHandler_);
    126         for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); iJoyStick++)
    127             if (joyStickHandler_[iJoyStick])
    128                 tempSet.insert(joyStickHandler_[iJoyStick]);
    129 
    130         // copy the content of the map back to the actual vector
    131         allHandlers_.clear();
    132         for (std::set<InputHandler*>::const_iterator itHandler = tempSet.begin();
    133             itHandler != tempSet.end(); itHandler++)
    134             allHandlers_.push_back(*itHandler);
    135 
    136         // update the deviceEnabled options
    137         setInputDeviceEnabled(InputDevice::Keyboard, (keyHandler_ != 0));
    138         setInputDeviceEnabled(InputDevice::Mouse, (mouseHandler_ != 0));
    139         for (unsigned int i = 0; i < joyStickHandler_.size(); ++i)
    140             setInputDeviceEnabled(2 + i, (joyStickHandler_[i] != 0));
    141 
    142         // inform InputManager that there might be changes in EMPTY_HANDLER situation
    143         bHandlersChanged_ = true;
     120        if (enterFunctor_)
     121            (*enterFunctor_)();
     122           
    144123    }
    145124
    146     void SimpleInputState::onEnter()
     125    void InputState::left()
    147126    {
    148         if (executorOnEnter_)
    149             (*executorOnEnter_)();
    150     }
    151 
    152     void SimpleInputState::onLeave()
    153     {
    154         if (executorOnLeave_)
    155             (*executorOnLeave_)();
     127        if (leaveFunctor_)
     128            (*leaveFunctor_)();
    156129    }
    157130}
  • code/branches/core4/src/core/input/InputState.h

    r3270 r3274  
    2727 */
    2828
    29 /**
    30 @file
    31 @brief
    32 */
    33 
    3429#ifndef _InputState_H__
    3530#define _InputState_H__
    3631
    37 #include "core/CorePrereqs.h"
     32#include "InputPrereqs.h"
    3833
     34#include <cassert>
    3935#include <string>
    4036#include <vector>
    41 #include "InputInterfaces.h"
    42 #include "JoyStickDeviceNumberListener.h"
     37
     38#include "InputHandler.h"
     39#include "JoyStickQuantityListener.h"
    4340
    4441namespace orxonox
    4542{
    46     class _CoreExport InputState : public JoyStickDeviceNumberListener
     43    class _CoreExport InputState : public JoyStickQuantityListener
    4744    {
    4845        friend class InputManager;
    4946
     47        static const InputDeviceEnumerator::Value keyboardIndex_s      = InputDeviceEnumerator::Keyboard;
     48        static const InputDeviceEnumerator::Value mouseIndex_s         = InputDeviceEnumerator::Mouse;
     49        static const InputDeviceEnumerator::Value firstJoyStickIndex_s = InputDeviceEnumerator::FirstJoyStick;
     50
    5051    public:
     52        void setKeyHandler     (InputHandler* handler)
     53            { handlers_[keyboardIndex_s] = handler; bExpired_ = true; }
     54        void setMouseHandler   (InputHandler* handler)
     55            { handlers_[mouseIndex_s]    = handler; bExpired_ = true; }
     56        bool setJoyStickHandler(InputHandler* handler, unsigned int joyStick);
     57        bool setJoyStickHandler(InputHandler* handler);
     58        bool setHandler        (InputHandler* handler);
     59
    5160        const std::string& getName() const { return name_; }
    5261        int getPriority()            const { return priority_; }
    5362
    54         bool isInputDeviceEnabled(unsigned int device)
    55         {
    56             if (device < bInputDeviceEnabled_.size())
    57                 return bInputDeviceEnabled_[device];
    58             else
    59                 return false;
    60         }
     63        bool isInputDeviceEnabled(unsigned int device);
    6164
    62         bool handlersChanged() { return this->bHandlersChanged_; }
    63         void resetHandlersChanged() { bHandlersChanged_ = false; }
     65        bool hasExpired()      { return this->bExpired_; }
     66        void resetExpiration() { bExpired_ = false; }
    6467
    65         virtual void onEnter() = 0;
    66         virtual void onLeave() = 0;
     68        void update(float dt, unsigned int device);
     69        void update(float dt);
    6770
    68         virtual void registerOnEnter(Executor* executor)      { executorOnEnter_ = executor; }
    69         virtual void unRegisterOnEnter()                      { executorOnEnter_ = 0; }
    70         virtual void registerOnLeave(Executor* executor)      { executorOnLeave_ = executor; }
    71         virtual void unRegisterOnLeave()                      { executorOnLeave_ = 0; }
     71        template <typename EventType, class Traits>
     72        void buttonEvent(unsigned int device, const typename Traits::ButtonTypeParam button);
    7273
    73         virtual void updateInput(float dt, unsigned int device) = 0;
    74         virtual void updateInput(float dt) = 0;
     74        void mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
     75        void mouseScrolled(int abs, int rel);
     76        void joyStickAxisMoved(unsigned int device, unsigned int axis, float value);
    7577
    76         virtual void keyPressed (const KeyEvent& evt) = 0;
    77         virtual void keyReleased(const KeyEvent& evt) = 0;
    78         virtual void keyHeld    (const KeyEvent& evt) = 0;
    79 
    80         virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0;
    81         virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0;
    82         virtual void mouseButtonHeld    (MouseButtonCode::ByEnum id) = 0;
    83         virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    84         virtual void mouseScrolled      (int abs, int rel) = 0;
    85 
    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;
    89         virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    90 
    91     protected:
    92         InputState()
    93             : bHandlersChanged_(false)
    94             , executorOnEnter_(0)
    95             , executorOnLeave_(0)
    96             , priority_(0)
    97             , bAlwaysGetsInput_(false)
    98             , bTransparent_(false)
    99         { }
    100         virtual ~InputState() { }
    101 
    102         virtual void numberOfJoySticksChanged(unsigned int n) = 0;
    103         void setInputDeviceEnabled(unsigned int device, bool bEnabled)
    104         {
    105             if (device < bInputDeviceEnabled_.size())
    106                 bInputDeviceEnabled_[device] = bEnabled;
    107         }
    108 
    109         bool bHandlersChanged_;
    110         Executor*                                   executorOnEnter_;
    111         Executor*                                   executorOnLeave_;
     78        // Functors
     79        void entered();
     80        void left();
     81        void setEnterFunctor(Functor* functor) { this->enterFunctor_ = functor; }
     82        void setLeaveFunctor(Functor* functor) { this->leaveFunctor_ = functor; }
    11283
    11384    private:
    114         void JoyStickDeviceNumberChanged(unsigned int n)
     85        InputState();
     86        ~InputState() { }
     87
     88        void JoyStickQuantityChanged(unsigned int n);
     89
     90        void setName(const std::string& name) { name_ = name; }
     91        void setPriority(int priority)        { priority_ = priority; }
     92
     93        std::string                 name_;
     94        int                         priority_;
     95        bool                        bAlwaysGetsInput_;
     96        bool                        bTransparent_;
     97        bool                        bExpired_;
     98        std::vector<InputHandler*>  handlers_;
     99        InputHandler*               joyStickHandlerAll_;
     100        Functor*                    enterFunctor_;
     101        Functor*                    leaveFunctor_;
     102    };
     103
     104    inline void InputState::update(float dt)
     105    {
     106        for (unsigned int i = 0; i < handlers_.size(); ++i)
     107            if (handlers_[i] != NULL)
     108                handlers_[i]->allDevicesUpdated(dt);
     109    }
     110
     111    inline void InputState::update(float dt, unsigned int device)
     112    {
     113        switch (device)
    115114        {
    116             bInputDeviceEnabled_.resize(n + 2);
    117             numberOfJoySticksChanged(n);
     115        case InputDeviceEnumerator::Keyboard:
     116            if (handlers_[keyboardIndex_s] != NULL)
     117                handlers_[keyboardIndex_s]->keyboardUpdated(dt);
     118            break;
     119
     120        case InputDeviceEnumerator::Mouse:
     121            if (handlers_[mouseIndex_s] != NULL)
     122                handlers_[mouseIndex_s]->mouseUpdated(dt);
     123            break;
     124
     125        default: // joy sticks
     126            if (handlers_[device] != NULL)
     127                handlers_[device]->joyStickUpdated(device - firstJoyStickIndex_s, dt);
     128            break;
    118129        }
    119         void setName(const std::string& name)  { name_ = name; }
    120         void setPriority(int priority)         { priority_ = priority; }
     130    }
    121131
    122         std::string                                 name_;
    123         int                                         priority_;
    124         std::vector<bool>                           bInputDeviceEnabled_;
    125         bool                                        bAlwaysGetsInput_;
    126         bool                                        bTransparent_;
    127     };
     132    template <typename EventType, class Traits>
     133    inline void InputState::buttonEvent(unsigned int device, const typename Traits::ButtonTypeParam button)
     134    {
     135        assert(device < handlers_.size());
     136        if (handlers_[device] != NULL)
     137            handlers_[device]->buttonEvent(device, button, EventType());
     138    }
     139
     140    inline void InputState::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
     141    {
     142        if (handlers_[mouseIndex_s] != NULL)
     143            handlers_[mouseIndex_s]->mouseMoved(abs, rel, clippingSize);
     144    }
     145
     146    inline void InputState::mouseScrolled(int abs, int rel)
     147    {
     148        if (handlers_[mouseIndex_s] != NULL)
     149            handlers_[mouseIndex_s]->mouseScrolled(abs, rel);
     150    }
     151
     152    inline void InputState::joyStickAxisMoved(unsigned int device, unsigned int axis, float value)
     153    {
     154        assert(device < handlers_.size());
     155        if (handlers_[device] != NULL)
     156            handlers_[device]->axisMoved(device - firstJoyStickIndex_s, axis, value);
     157    }
    128158}
    129159
  • code/branches/core4/src/core/input/JoyStick.cc

    r3270 r3274  
    2626 *
    2727 */
    28 
    29 /**
    30 @file
    31 @brief
    32     Implementation of the JoyStick wrapper class.
    33 */
    3428
    3529#include "JoyStick.h"
     
    5448    void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue);
    5549
    56     JoyStick::JoyStick(const std::vector<InputState*>& states, unsigned int id)
    57         : id_(id)
    58         , bCalibrating_(false)
    59         , inputStates_(states)
     50    JoyStick::JoyStick(unsigned int id)
     51        : super(id)
    6052    {
    6153        RegisterRootObject(JoyStick);
    6254        this->setConfigValues();
    63 
    64         OIS::InputManager* system = InputManager::getInstance().getInputSystem();
    65         oisJoyStick_ = static_cast<OIS::JoyStick*>(system->createInputObject(OIS::OISJoyStick, true));
    66         oisJoyStick_->setEventCallback(this);
     55        // Initialise POV and Slider states
     56        this->clearBuffersImpl();
    6757
    6858        idString_ = "JoyStick_";
    69         std::string name = oisJoyStick_->vendor();
     59        std::string name = oisDevice_->vendor();
    7060        replaceCharacters(name, ' ', '_');
    7161        idString_ += name + "_";
    72         idString_ += multi_cast<std::string>(oisJoyStick_->getNumberOfComponents(OIS::OIS_Button))  + "_";
    73         idString_ += multi_cast<std::string>(oisJoyStick_->getNumberOfComponents(OIS::OIS_Axis))    + "_";
    74         idString_ += multi_cast<std::string>(oisJoyStick_->getNumberOfComponents(OIS::OIS_Slider))  + "_";
    75         idString_ += multi_cast<std::string>(oisJoyStick_->getNumberOfComponents(OIS::OIS_POV));
    76         //idString_ += multi_cast<std::string>(oisJoyStick_->getNumberOfComponents(OIS::OIS_Vector3));
     62        idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button))  + "_";
     63        idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis))    + "_";
     64        idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider))  + "_";
     65        idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
     66        //idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
    7767
    7868        if (InputManager::getInstance().checkJoyStickID(idString_) == false)
    7969        {
    8070            // Make the ID unique for this execution time.
    81             idString_ += "_" + multi_cast<std::string>(id_);
     71            idString_ += "_" + multi_cast<std::string>(this->getDeviceID());
    8272        }
    8373
     
    8575
    8676        // Load calibration
    87         size_t axes = sliderAxes_s + static_cast<size_t>(oisJoyStick_->getNumberOfComponents(OIS::OIS_Axis));
     77        size_t axes = sliderAxes_s + static_cast<size_t>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis));
    8878        loadCalibration(configMinValues_,  idString_, "MinValue",  axes,  -32768);
    8979        loadCalibration(configMaxValues_,  idString_, "MaxValue",  axes,   32768);
     
    9282    }
    9383
    94     JoyStick::~JoyStick()
    95     {
    96         try
    97         {
    98             OIS::InputManager* system = InputManager::getInstance().getInputSystem();
    99             system->destroyInputObject(oisJoyStick_);
    100         }
    101         catch (...)
    102         {
    103             COUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl;
    104         }
    105     }
    106 
    107     /**
    108     @brief
    109         Callback for the joy stick calibration config file. @see setConfigValues.
    110     */
     84    //!< Callback for the joy stick calibration config file.
    11185    void JoyStick::calibrationFileCallback()
    11286    {
     
    11488    }
    11589
    116     /**
    117     @brief
    118         Sets the configurable values.
    119     */
    12090    void JoyStick::setConfigValues()
    12191    {
     
    140110        // fill the rest with default values
    141111        for (unsigned int i = configValueVectorSize; i < size; ++i)
    142         {
    143112            list[i] = defaultValue;
    144         }
    145     }
    146 
    147     void JoyStick::startCalibration()
    148     {
    149         bCalibrating_ = true;
    150 
     113    }
     114
     115    //! Called by InputDevice when calibration mode has started
     116    void JoyStick::calibrationStarted()
     117    {
    151118        // Set initial values
    152119        BOOST_FOREACH(int& minVal, configMinValues_)
     
    158125    }
    159126
    160     void JoyStick::stopCalibration()
     127    //! Called by InputDevice when calibration mode has stopped
     128    void JoyStick::calibrationStopped()
    161129    {
    162130        // Get the middle positions now
     
    164132        for (unsigned int i = 0; i < sliderAxes_s/2; ++i)
    165133        {
    166             configZeroValues_[iAxis++] = oisJoyStick_->getJoyStickState().mSliders[i].abX;
    167             configZeroValues_[iAxis++] = oisJoyStick_->getJoyStickState().mSliders[i].abY;
    168         }
    169         // Note: joyStickMiddleValues_[iJoyStick] was already correctly resised in loadCalibration()
    170         assert(oisJoyStick_->getJoyStickState().mAxes.size() == configZeroValues_.size() - sliderAxes_s);
     134            configZeroValues_[iAxis++] = oisDevice_->getJoyStickState().mSliders[i].abX;
     135            configZeroValues_[iAxis++] = oisDevice_->getJoyStickState().mSliders[i].abY;
     136        }
     137        // Note: joyStickZeroValues_[iJoyStick] was already correctly resised in loadCalibration()
     138        assert(oisDevice_->getJoyStickState().mAxes.size() == configZeroValues_.size() - sliderAxes_s);
    171139        for (unsigned int i = 0; i < configZeroValues_.size() - sliderAxes_s; ++i)
    172             configZeroValues_[iAxis++] = oisJoyStick_->getJoyStickState().mAxes[i].abs;
     140            configZeroValues_[iAxis++] = oisDevice_->getJoyStickState().mAxes[i].abs;
    173141
    174142        for (unsigned int i = 0; i < configMinValues_.size(); ++i)
     
    192160
    193161        this->evaluateCalibration();
    194 
    195         bCalibrating_ = false;
    196     }
    197 
     162    }
     163
     164    //! Evaluates the accumulated values during calibration
    198165    void JoyStick::evaluateCalibration()
    199166    {
     
    206173    }
    207174
    208     void JoyStick::clearBuffer()
    209     {
    210         pressedButtons_.clear();
     175    // TODO: What do we really need to reset here?
     176    void JoyStick::clearBuffersImpl()
     177    {
    211178        for (int j = 0; j < 4; ++j)
    212179        {
     
    217184    }
    218185
    219 
    220     // ###### Events ######
    221 
    222     void JoyStick::capture()
    223     {
    224         oisJoyStick_->capture();
    225 
    226         // call all the handlers for the held joy stick button events
    227         for (unsigned int iButton = 0; iButton < pressedButtons_.size(); iButton++)
    228         {
    229             BOOST_FOREACH(InputState* state, inputStates_)
    230                 state->joyStickButtonHeld(id_, pressedButtons_[iButton]);
    231         }
    232     }
    233 
    234     bool JoyStick::buttonPressed(const OIS::JoyStickEvent &arg, int button)
    235     {
    236         // check whether the button already is in the list (can happen when focus was lost)
    237         unsigned int iButton = 0;
    238         while (iButton < pressedButtons_.size() && pressedButtons_[iButton] != button)
    239             iButton++;
    240         if (iButton == pressedButtons_.size())
    241             pressedButtons_.push_back(static_cast<JoyStickButtonCode::ByEnum>(button));
    242 
    243         BOOST_FOREACH(InputState* state, inputStates_)
    244             state->joyStickButtonPressed(id_, static_cast<JoyStickButtonCode::ByEnum>(button));
    245 
    246         return true;
    247     }
    248 
    249     bool JoyStick::buttonReleased(const OIS::JoyStickEvent &arg, int button)
    250     {
    251         // remove the button from the pressedButtons_ list
    252         for (unsigned int iButton = 0; iButton < pressedButtons_.size(); iButton++)
    253         {
    254             if (static_cast<int>(pressedButtons_[iButton]) == button)
    255             {
    256                 pressedButtons_.erase(pressedButtons_.begin() + iButton);
    257                 break;
    258             }
    259         }
    260 
    261         BOOST_FOREACH(InputState* state, inputStates_)
    262             state->joyStickButtonPressed(id_, static_cast<JoyStickButtonCode::ByEnum>(button));
    263 
    264         return true;
    265     }
    266 
    267     /**
    268     @brief
    269         Calls the states for a particular axis with our enumeration.
    270         Used by OIS sliders and OIS axes.
    271     */
     186    //! Generic method to forward axis events
    272187    void JoyStick::fireAxis(int axis, int value)
    273188    {
    274         if (bCalibrating_)
     189        if (this->isCalibrating())
    275190        {
    276191            if (value < configMinValues_[axis])
     
    288203
    289204            BOOST_FOREACH(InputState* state, inputStates_)
    290                 state->joyStickAxisMoved(id_, axis, fValue);
    291         }
    292     }
    293 
     205                state->joyStickAxisMoved(this->getDeviceID(), axis, fValue);
     206        }
     207    }
     208
     209    //! OIS joy stick axis event handler
    294210    bool JoyStick::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    295211    {
     
    300216    }
    301217
     218    //! A Slider always has an X and an Y direction!
    302219    bool JoyStick::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    303220    {
     
    310227    }
    311228
     229    //! A POV is the big button that can point in all directions (but only in one at once)
    312230    bool JoyStick::povMoved(const OIS::JoyStickEvent &arg, int id)
    313231    {
  • code/branches/core4/src/core/input/JoyStick.h

    r3270 r3274  
    2727 */
    2828
    29 /**
    30 @file
    31 @brief
    32 */
     29#ifndef _Core_JoyStick_H__
     30#define _Core_JoyStick_H__
    3331
    34 #ifndef _JoyStick_H__
    35 #define _JoyStick_H__
    36 
    37 #include "core/CorePrereqs.h"
     32#include "InputPrereqs.h"
    3833
    3934#include <string>
    4035#include <vector>
    41 #include "InputInterfaces.h"
     36#include "InputDevice.h"
    4237
    4338namespace orxonox
    4439{
    45     class _CoreExport JoyStick : public OrxonoxClass, public OIS::JoyStickListener
     40    /**
     41    @brief
     42        Wraps around an OIS::JoyStick and forwards the input events to
     43        a list of input states.
     44
     45        The class also supports joy stick calibration and stores the values
     46        in an ini-file.
     47    */
     48    class _CoreExport JoyStick
     49        : public OrxonoxClass
     50        , public InputDeviceTemplated<JoyStickTraits>
     51        , public OIS::JoyStickListener
    4652    {
    47     private:
    48         struct JoyStickCalibration
    49         {
    50         };
     53        friend class InputDeviceTemplated<JoyStickTraits>;
     54        //! Super class alias
     55        typedef InputDeviceTemplated<JoyStickTraits> super;
    5156
    5257    public:
    53         JoyStick(const std::vector<InputState*>& states, unsigned int id);
    54         ~JoyStick();
    55 
     58        //! Assigns a generated ID string and loads the calibration (if present)
     59        JoyStick(unsigned int id);
     60        ~JoyStick() { }
    5661        void setConfigValues();
    5762
    58         OIS::JoyStick* getOISJoyStick() { return this->oisJoyStick_; }
     63        //! Returns the generated (from the number of knobs and the device name) ID string
    5964        const std::string& getIDString() const { return this->idString_; }
    6065
    61         void startCalibration();
    62         void stopCalibration();
     66    private:
     67        void calibrationStarted();
     68        void calibrationStopped();
     69        void evaluateCalibration();
    6370
    64         void capture();
    65         void clearBuffer();
    66 
    67     private:
     71        void clearBuffersImpl();
    6872        void calibrationFileCallback();
    69         void evaluateCalibration();
    7073        void fireAxis(int axis, int value);
    7174
    72         bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
    73         bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     75        //! OIS event handler
     76        bool buttonPressed (const OIS::JoyStickEvent &arg, int button)
     77        {
     78            super::buttonPressed(static_cast<JoyStickButtonCode::ByEnum>(button));
     79            return true;
     80        }
     81
     82        //! OIS event handler
     83        bool buttonReleased(const OIS::JoyStickEvent &arg, int button)
     84        {
     85            super::buttonReleased(static_cast<JoyStickButtonCode::ByEnum>(button));
     86            return true;
     87        }
     88
    7489        bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
    7590        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    7691        bool povMoved      (const OIS::JoyStickEvent &arg, int id);
    77         // don't remove that! Or else add OIS as dependency library to orxonox (it actually is..)
     92        //!< OIS event handler (don't remove that because of OIS version issues!)
    7893        bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
    7994
    80         static const unsigned int sliderAxes_s = 8;
    81 
    82         OIS::JoyStick* oisJoyStick_;
    83         const unsigned int id_;
    84         std::string idString_;
     95        std::string idString_;                //!< ID string generated by the number of knobs and the device name
     96        int povStates_[4];                    //!< Internal states for the POVs
     97        int sliderStates_[4][2];              //!< Internal states for the Sliders (each slider has X and Y!)
    8598
    8699        // calibration
    87         bool bCalibrating_;
    88         int zeroValues_[24];
    89         float positiveCoeffs_[24];
    90         float negativeCoeffs_[24];
     100        int zeroValues_[24];                  //!< Axes values when the knob is in the middle
     101        float positiveCoeffs_[24];            //!< Maps the negative part of an axis to a 0.0 to 1.0 floating range
     102        float negativeCoeffs_[24];            //!< Maps the positive part of an axis to a 0.0 to 1.0 floating range
    91103
    92         std::vector<int> configMinValues_;
    93         std::vector<int> configMaxValues_;
    94         std::vector<int> configZeroValues_;
    95 
    96         int povStates_[4];
    97         int sliderStates_[4][2];
    98         std::vector<JoyStickButtonCode::ByEnum> pressedButtons_;
    99 
    100         // InputState handling
    101         const std::vector<InputState*>& inputStates_;
     104        std::vector<int> configZeroValues_;   //!< Config file stored axis values when the knob is in the middle
     105        std::vector<int> configMinValues_;    //!< Config file stored minimum axis values
     106        std::vector<int> configMaxValues_;    //!< Config file stored maximum axis values
    102107
    103108        // ConfigValues
    104         std::string calibrationFilename_;  //!< Joy stick calibration ini filename
     109        std::string calibrationFilename_;     //!< Joy stick calibration ini filename
     110
     111        //!< Maximum number of slider axes
     112        static const unsigned int sliderAxes_s = 8;
    105113    };
    106114}
    107115
    108 #endif /* _JoyStick_H__ */
     116#endif /* _Core_JoyStick_H__ */
  • code/branches/core4/src/core/input/JoyStickQuantityListener.cc

    r3273 r3274  
    3030@file
    3131@brief
    32     Implementation of the JoyStickDeviceNumberListener class.
     32    Implementation of the JoyStickQuantityListener class.
    3333*/
    3434
    35 #include "JoyStickDeviceNumberListener.h"
     35#include "JoyStickQuantityListener.h"
    3636#include "core/CoreIncludes.h"
    3737
    3838namespace orxonox
    3939{
    40     JoyStickDeviceNumberListener::JoyStickDeviceNumberListener()
     40    JoyStickQuantityListener::JoyStickQuantityListener()
    4141    {
    42         RegisterObject(JoyStickDeviceNumberListener);
     42        RegisterObject(JoyStickQuantityListener);
    4343    }
    4444}
  • code/branches/core4/src/core/input/JoyStickQuantityListener.h

    r3273 r3274  
    3232*/
    3333
    34 #ifndef _JoyStickDeviceNumberListener_H__
    35 #define _JoyStickDeviceNumberListener_H__
     34#ifndef _JoyStickQuantityListener_H__
     35#define _JoyStickQuantityListener_H__
    3636
    37 #include "core/CorePrereqs.h"
     37#include "InputPrereqs.h"
    3838#include "core/OrxonoxClass.h"
    3939
    4040namespace orxonox
    4141{
    42     class _CoreExport JoyStickDeviceNumberListener : virtual public OrxonoxClass
     42    class _CoreExport JoyStickQuantityListener : virtual public OrxonoxClass
    4343    {
    4444    public:
    45         JoyStickDeviceNumberListener();
    46         virtual ~JoyStickDeviceNumberListener() { }
     45        JoyStickQuantityListener();
     46        virtual ~JoyStickQuantityListener() { }
    4747
    48         virtual void JoyStickDeviceNumberChanged(unsigned int value) = 0;
     48        virtual void JoyStickQuantityChanged(unsigned int value) = 0;
    4949    };
    5050}
    5151
    52 #endif /* _JoyStickDeviceNumberListener_H__ */
     52#endif /* _JoyStickQuantityListener_H__ */
  • code/branches/core4/src/core/input/KeyBinder.cc

    r3269 r3274  
    100100
    101101        // initialise joy sticks separatly to allow for reloading
    102         numberOfJoySticks_ = InputManager::getInstance().numberOfJoySticks();
     102        numberOfJoySticks_ = InputManager::getInstance().getJoyStickQuantity();
    103103        initialiseJoyStickBindings();
    104104
     
    152152    }
    153153
    154     void KeyBinder::JoyStickDeviceNumberChanged(unsigned int value)
     154    void KeyBinder::JoyStickQuantityChanged(unsigned int value)
    155155    {
    156156        unsigned int oldValue = numberOfJoySticks_;
     
    311311    }
    312312
    313     void KeyBinder::updateMouse(float dt)
     313    void KeyBinder::mouseUpdated(float dt)
    314314    {
    315315        if (bDeriveMouseInput_)
     
    364364    }
    365365
    366     void KeyBinder::updateJoyStick(float dt, unsigned int joyStick)
     366    void KeyBinder::joyStickUpdated(unsigned int joyStick, float dt)
    367367    {
    368368        for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
     
    480480    }
    481481
    482     void KeyBinder::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value)
    483     {
    484         int i = axis * 2;
     482    void KeyBinder::axisMoved(unsigned int device, unsigned int axisID, float value)
     483    {
     484        int i = axisID * 2;
     485        JoyStickAxisVector& axis = joyStickAxes_[device];
    485486        if (value < 0)
    486487        {
    487             joyStickAxes_[joyStickID][i].absVal_ = -value;
    488             joyStickAxes_[joyStickID][i].relVal_ = -value;
    489             joyStickAxes_[joyStickID][i].hasChanged_ = true;
    490             if (joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f)
    491             {
    492                 joyStickAxes_[joyStickID][i + 1].absVal_ = -0.0f;
    493                 joyStickAxes_[joyStickID][i + 1].relVal_ = -0.0f;
    494                 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;
     488            axis[i].absVal_ = -value;
     489            axis[i].relVal_ = -value;
     490            axis[i].hasChanged_ = true;
     491            if (axis[i + 1].absVal_ > 0.0f)
     492            {
     493                axis[i + 1].absVal_ = -0.0f;
     494                axis[i + 1].relVal_ = -0.0f;
     495                axis[i + 1].hasChanged_ = true;
    495496            }
    496497        }
    497498        else
    498499        {
    499             joyStickAxes_[joyStickID][i + 1].absVal_ = value;
    500             joyStickAxes_[joyStickID][i + 1].relVal_ = value;
    501             joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;
    502             if (joyStickAxes_[joyStickID][i].absVal_ > 0.0f)
    503             {
    504                 joyStickAxes_[joyStickID][i].absVal_ = -0.0f;
    505                 joyStickAxes_[joyStickID][i].relVal_ = -0.0f;
    506                 joyStickAxes_[joyStickID][i].hasChanged_ = true;
     500            axis[i + 1].absVal_ = value;
     501            axis[i + 1].relVal_ = value;
     502            axis[i + 1].hasChanged_ = true;
     503            if (axis[i].absVal_ > 0.0f)
     504            {
     505                axis[i].absVal_ = -0.0f;
     506                axis[i].relVal_ = -0.0f;
     507                axis[i].hasChanged_ = true;
    507508            }
    508509        }
  • code/branches/core4/src/core/input/KeyBinder.h

    r3196 r3274  
    3636#define _KeyBinder_H__
    3737
    38 #include "core/CorePrereqs.h"
     38#include "InputPrereqs.h"
    3939
    4040#include <cassert>
     
    4242#include <vector>
    4343
    44 #include "InputInterfaces.h"
     44#include "InputHandler.h"
    4545#include "Button.h"
    4646#include "HalfAxis.h"
    4747#include "InputCommands.h"
    48 #include "JoyStickDeviceNumberListener.h"
     48#include "JoyStickQuantityListener.h"
    4949
    5050namespace orxonox
     
    5555        Manages the key bindings.
    5656    */
    57     class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler,
    58                                   public JoyStickDeviceNumberListener
     57    class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener
    5958    {
    6059    public:
     
    6968
    7069    protected: // functions
    71         void updateInput(float dt);
    72         void updateKey(float dt) { }
    73         void updateMouse(float dt);
    74         void updateJoyStick(float dt, unsigned int joyStick);
     70        void allDevicesUpdated(float dt);
     71        void mouseUpdated(float dt);
     72        void joyStickUpdated(unsigned int joyStick, float dt);
    7573        // internal
    7674        void tickHalfAxis(HalfAxis& halfAxis);
    7775
    7876        void buttonThresholdChanged();
    79         // from JoyStickDeviceNumberListener interface
    80         virtual void JoyStickDeviceNumberChanged(unsigned int value);
     77        // from JoyStickQuantityListener interface
     78        virtual void JoyStickQuantityChanged(unsigned int value);
    8179        void initialiseJoyStickBindings();
    8280        void compilePointerLists();
    8381
    84         void keyPressed (const KeyEvent& evt);
    85         void keyReleased(const KeyEvent& evt);
    86         void keyHeld    (const KeyEvent& evt);
    87 
    88         void mouseButtonPressed (MouseButtonCode::ByEnum id);
    89         void mouseButtonReleased(MouseButtonCode::ByEnum id);
    90         void mouseButtonHeld    (MouseButtonCode::ByEnum id);
    91         void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    92         void mouseScrolled      (int abs, int rel);
    93 
    94         void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
    95         void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
    96         void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
    97         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
     82        void buttonPressed (const KeyEvent& evt);
     83        void buttonReleased(const KeyEvent& evt);
     84        void buttonHeld    (const KeyEvent& evt);
     85
     86        void buttonPressed (MouseButtonCode::ByEnum button);
     87        void buttonReleased(MouseButtonCode::ByEnum button);
     88        void buttonHeld    (MouseButtonCode::ByEnum button);
     89        void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
     90        void mouseScrolled (int abs, int rel);
     91
     92        void buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button);
     93        void buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button);
     94        void buttonHeld    (unsigned int device, JoyStickButtonCode::ByEnum button);
     95        void axisMoved     (unsigned int device, unsigned int axis, float value);
    9896
    9997    protected: // variables
     
    172170    };
    173171
    174     inline void KeyBinder::keyPressed (const KeyEvent& evt)
    175     { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnPress); }
    176 
    177     inline void KeyBinder::keyReleased(const KeyEvent& evt)
    178     { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnRelease); }
    179 
    180     inline void KeyBinder::keyHeld    (const KeyEvent& evt)
    181     { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnHold); }
    182 
    183 
    184     inline void KeyBinder::mouseButtonPressed (MouseButtonCode::ByEnum id)
    185     { mouseButtons_[id].execute(KeybindMode::OnPress); }
    186 
    187     inline void KeyBinder::mouseButtonReleased(MouseButtonCode::ByEnum id)
    188     { mouseButtons_[id].execute(KeybindMode::OnRelease); }
    189 
    190     inline void KeyBinder::mouseButtonHeld    (MouseButtonCode::ByEnum id)
    191     { mouseButtons_[id].execute(KeybindMode::OnHold); }
    192 
    193 
    194     inline void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
    195     { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnPress); }
    196 
    197     inline void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
    198     { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnRelease); }
    199 
    200     inline void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
    201     { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); }
    202 
    203     inline void KeyBinder::updateInput(float dt)
     172    inline void KeyBinder::buttonPressed (const KeyEvent& evt)
     173    { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); }
     174
     175    inline void KeyBinder::buttonReleased(const KeyEvent& evt)
     176    { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnRelease); }
     177
     178    inline void KeyBinder::buttonHeld    (const KeyEvent& evt)
     179    { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnHold); }
     180
     181
     182    inline void KeyBinder::buttonPressed (MouseButtonCode::ByEnum button)
     183    { mouseButtons_[button].execute(KeybindMode::OnPress); }
     184
     185    inline void KeyBinder::buttonReleased(MouseButtonCode::ByEnum button)
     186    { mouseButtons_[button].execute(KeybindMode::OnRelease); }
     187
     188    inline void KeyBinder::buttonHeld    (MouseButtonCode::ByEnum button)
     189    { mouseButtons_[button].execute(KeybindMode::OnHold); }
     190
     191
     192    inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button)
     193    { joyStickButtons_[device][button].execute(KeybindMode::OnPress); }
     194
     195    inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button)
     196    { joyStickButtons_[device][button].execute(KeybindMode::OnRelease); }
     197
     198    inline void KeyBinder::buttonHeld    (unsigned int device, JoyStickButtonCode::ByEnum button)
     199    { joyStickButtons_[device][button].execute(KeybindMode::OnHold); }
     200
     201    inline void KeyBinder::allDevicesUpdated(float dt)
    204202    {
    205203        // execute all buffered bindings (additional parameter)
  • code/branches/core4/src/core/input/KeyDetector.cc

    r3196 r3274  
    7373    }
    7474
    75     void KeyDetector::JoyStickDeviceNumberChanged(unsigned int value)
     75    void KeyDetector::JoyStickQuantityChanged(unsigned int value)
    7676    {
    77         KeyBinder::JoyStickDeviceNumberChanged(value);
     77        KeyBinder::JoyStickQuantityChanged(value);
    7878        setCallbackCommand(callbackCommand_);
    7979    }
  • code/branches/core4/src/core/input/KeyDetector.h

    r3196 r3274  
    3636#define _KeyDetector_H__
    3737
    38 #include "core/CorePrereqs.h"
     38#include "InputPrereqs.h"
    3939
    4040#include <string>
     
    4949        ~KeyDetector();
    5050        void setCallbackCommand(const std::string& command);
    51         void JoyStickDeviceNumberChanged(unsigned int value);
     51        void JoyStickQuantityChanged(unsigned int value);
    5252
    5353    private:
  • code/branches/core4/src/orxonox/gamestates/GSGraphics.cc

    r3270 r3274  
    3838#include <OgreRenderWindow.h>
    3939
     40#include "util/Convert.h"
    4041#include "core/ConfigValueIncludes.h"
    4142#include "core/Clock.h"
     43#include "core/CommandExecutor.h"
    4244#include "core/ConsoleCommand.h"
    4345#include "core/Core.h"
     
    4749#include "core/input/InputManager.h"
    4850#include "core/input/KeyBinder.h"
    49 #include "core/input/SimpleInputState.h"
     51#include "core/input/InputState.h"
    5052#include "core/Loader.h"
    5153#include "core/XMLFile.h"
     
    125127
    126128        // load master key bindings
    127         masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
     129        masterInputState_ = InputManager::getInstance().createInputState("master", true);
    128130        masterKeyBinder_ = new KeyBinder();
    129131        masterKeyBinder_->loadBindings("masterKeybindings.ini");
     
    244246    {
    245247        // OIS needs this under linux even if we only use relative input measurement.
    246         if (this->inputManager_)
    247             this->inputManager_->setWindowExtents(newWidth, newHeight);
     248        // HACK:
     249        CommandExecutor::execute("setWindowExtents_s " + multi_cast<std::string>(newWidth) + " " + multi_cast<std::string>(newHeight));
    248250    }
    249251
  • code/branches/core4/src/orxonox/gamestates/GSGraphics.h

    r3243 r3274  
    7575
    7676        KeyBinder*            masterKeyBinder_;     //!< Key binder for master key bindings
    77         SimpleInputState*     masterInputState_;    //!< Special input state for master input
     77        InputState*           masterInputState_;    //!< Special input state for master input
    7878        XMLFile*              debugOverlay_;
    7979        ConsoleCommand*       ccToggleGUI_;         //!< Console command to toggle GUI
  • code/branches/core4/src/orxonox/gamestates/GSLevel.cc

    r3249 r3274  
    3131
    3232#include "core/input/InputManager.h"
    33 #include "core/input/SimpleInputState.h"
     33#include "core/input/InputState.h"
    3434#include "core/input/KeyBinder.h"
    3535#include "core/Clock.h"
     
    9090        if (GameMode::showsGraphics())
    9191        {
    92             gameInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game");
     92            gameInputState_ = InputManager::getInstance().createInputState("game");
    9393            keyBinder_ = new KeyBinder();
    9494            keyBinder_->loadBindings("keybindings.ini");
    9595            gameInputState_->setHandler(keyBinder_);
    9696
    97             guiMouseOnlyInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("guiMouseOnly");
     97            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
    9898            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
    9999
    100             guiKeysOnlyInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("guiKeysOnly");
     100            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
    101101            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
    102102
  • code/branches/core4/src/orxonox/gamestates/GSLevel.h

    r3245 r3274  
    6363
    6464        KeyBinder*            keyBinder_;               //!< tool that loads and manages the input bindings
    65         SimpleInputState*     gameInputState_;          //!< input state for normal ingame playing
    66         SimpleInputState*     guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
    67         SimpleInputState*     guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
     65        InputState*           gameInputState_;          //!< input state for normal ingame playing
     66        InputState*           guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
     67        InputState*           guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
    6868        Radar*                radar_;                   //!< represents the Radar (not the HUD part)
    6969        CameraManager*        cameraManager_;           //!< camera manager for this level
  • code/branches/core4/src/orxonox/gamestates/GSMainMenu.cc

    r3245 r3274  
    3232
    3333#include "core/input/InputManager.h"
    34 #include "core/input/SimpleInputState.h"
     34#include "core/input/InputState.h"
    3535#include "core/Game.h"
    3636#include "core/Clock.h"
     
    5757    void GSMainMenu::activate()
    5858    {
    59         inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("mainMenu");
     59        inputState_ = InputManager::getInstance().createInputState("mainMenu");
    6060        inputState_->setHandler(GUIManager::getInstancePtr());
    61         inputState_->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
     61        inputState_->setJoyStickHandler(&InputHandler::EMPTY);
    6262
    6363        // create an empty Scene
  • code/branches/core4/src/orxonox/gamestates/GSMainMenu.h

    r3243 r3274  
    5353
    5454    private:
    55         SimpleInputState* inputState_;
     55        InputState*      inputState_;
    5656        Scene*            scene_;
    5757        Ogre::Camera*     camera_;
  • code/branches/core4/src/orxonox/gui/GUIManager.cc

    r3261 r3274  
    366366    void GUIManager::keyPressed(const KeyEvent& evt)
    367367    {
    368         guiSystem_->injectKeyDown(evt.key); guiSystem_->injectChar(evt.text);
     368        guiSystem_->injectKeyDown(evt.getKeyCode());
     369        guiSystem_->injectChar(evt.getText());
    369370    }
    370371    void GUIManager::keyReleased(const KeyEvent& evt)
    371372    {
    372         guiSystem_->injectKeyUp(evt.key);
     373        guiSystem_->injectKeyUp(evt.getKeyCode());
    373374    }
    374375
     
    382383        It is for CEGUI to process the event.
    383384    */
    384     void GUIManager::mouseButtonPressed(MouseButtonCode::ByEnum id)
     385    void GUIManager::buttonPressed(MouseButtonCode::ByEnum id)
    385386    {
    386387        try
     
    404405        It is for CEGUI to process the event.
    405406    */
    406     void GUIManager::mouseButtonReleased(MouseButtonCode::ByEnum id)
     407    void GUIManager::buttonReleased(MouseButtonCode::ByEnum id)
    407408    {
    408409        try
  • code/branches/core4/src/orxonox/gui/GUIManager.h

    r3261 r3274  
    4444
    4545#include "util/OgreForwardRefs.h"
    46 #include "core/input/InputInterfaces.h"
     46#include "core/input/InputHandler.h"
    4747
    4848// tolua_begin
     
    6262    class _OrxonoxExport GUIManager
    6363// tolua_end
    64         : public KeyHandler, public MouseHandler
     64        : public InputHandler
    6565// tolua_begin
    6666    {
     
    106106        void keyPressed (const KeyEvent& evt);
    107107        void keyReleased(const KeyEvent& evt);
    108         void keyHeld    (const KeyEvent& evt) { }
    109108
    110109        // mouseHandler functions
    111         void mouseButtonPressed (MouseButtonCode::ByEnum id);
    112         void mouseButtonReleased(MouseButtonCode::ByEnum id);
    113         void mouseButtonHeld    (MouseButtonCode::ByEnum id) { }
    114         void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    115         void mouseScrolled      (int abs, int rel);
    116 
    117         void updateInput(float dt)  { }
    118         void updateKey  (float dt)  { }
    119         void updateMouse(float dt)  { }
     110        void buttonPressed (MouseButtonCode::ByEnum id);
     111        void buttonReleased(MouseButtonCode::ByEnum id);
     112        void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
     113        void mouseScrolled (int abs, int rel);
    120114
    121115        Ogre::RenderWindow*         renderWindow_;      //!< Ogre's render window to give CEGUI access to it
  • code/branches/core4/src/orxonox/overlays/console/InGameConsole.cc

    r3265 r3274  
    4949#include "core/ConsoleCommand.h"
    5050#include "core/input/InputManager.h"
    51 #include "core/input/SimpleInputState.h"
     51#include "core/input/InputState.h"
    5252#include "core/input/InputBuffer.h"
    5353
     
    158158            if (bHidesAllInput_)
    159159            {
    160                 inputState_->setMouseHandler(&InputManager::EMPTY_HANDLER);
    161                 inputState_->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
     160                inputState_->setMouseHandler(&InputHandler::EMPTY);
     161                inputState_->setJoyStickHandler(&InputHandler::EMPTY);
    162162            }
    163163            else
     
    175175    {
    176176        // create the corresponding input state
    177         inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", false, false, InputStatePriority::Console);
     177        inputState_ = InputManager::getInstance().createInputState("console", false, false, InputStatePriority::Console);
    178178        inputState_->setKeyHandler(Shell::getInstance().getInputBuffer());
    179179        bHidesAllInputChanged();
  • code/branches/core4/src/orxonox/overlays/console/InGameConsole.h

    r3196 r3274  
    101101
    102102        // input related
    103         SimpleInputState* inputState_;
     103        InputState* inputState_;
    104104
    105105        // config values
Note: See TracChangeset for help on using the changeset viewer.