Index: code/trunk/src/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/core/input/KeyBinder.h	(revision 1755)
+++ code/trunk/src/core/input/KeyBinder.h	(revision 1887)
@@ -39,9 +39,9 @@
 
 #include <vector>
-
-#include "core/OrxonoxClass.h"
 #include "InputInterfaces.h"
 #include "Button.h"
 #include "HalfAxis.h"
+#include "InputCommands.h"
+#include "JoyStickDeviceNumberListener.h"
 
 namespace orxonox
@@ -52,5 +52,6 @@
         Manages the key bindings.
     */
-    class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
+    class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler,
+                                  public JoyStickDeviceNumberListener
     {
     public:
@@ -58,6 +59,7 @@
         virtual ~KeyBinder();
 
-        void loadBindings();
+        void loadBindings(const std::string& filename);
         void clearBindings();
+        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
         void setConfigValues();
         void resetJoyStickAxes();
@@ -65,11 +67,15 @@
     protected: // functions
         void tickInput(float dt);
-        //void tickInput(float dt, int device);
         void tickKey(float dt) { }
         void tickMouse(float dt);
         void tickJoyStick(float dt, unsigned int joyStick);
-        void tickDevices(unsigned int begin, unsigned int end);
-
-        virtual void readTrigger(Button& button);
+        // internal
+        void tickDevices(HalfAxis* begin, HalfAxis* end);
+
+        void buttonThresholdChanged();
+        // from JoyStickDeviceNumberListener interface
+        virtual void JoyStickDeviceNumberChanged(unsigned int value);
+        void initialiseJoyStickBindings();
+        void compilePointerLists();
 
         void keyPressed (const KeyEvent& evt);
@@ -77,44 +83,49 @@
         void keyHeld    (const KeyEvent& evt);
 
-        void mouseButtonPressed (MouseButton::Enum id);
-        void mouseButtonReleased(MouseButton::Enum id);
-        void mouseButtonHeld    (MouseButton::Enum id);
+        void mouseButtonPressed (MouseButtonCode::ByEnum id);
+        void mouseButtonReleased(MouseButtonCode::ByEnum id);
+        void mouseButtonHeld    (MouseButtonCode::ByEnum id);
         void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
         void mouseScrolled      (int abs, int rel);
 
-        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
-        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
-        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
+        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
+        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
+        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
         void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
 
     protected: // variables
-        //! denotes the number of different keys there are in OIS.
-        static const unsigned int nKeys_s = 0xEE;
-        //! Actual key bindings as bundle for Press, Hold and Release
-        Button keys_ [nKeys_s];
-
-        //! denotes the number of different mouse buttons there are in OIS.
-        static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels
-        //! Actual key bindings as bundle for Press, Hold and Release
-        Button mouseButtons_ [nMouseButtons_s];
-
-        //! denotes the number of different joy stick buttons there are in OIS.
-        static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons
-        //! Actual key bindings as bundle for Press, Hold and Release
-        Button joyStickButtons_ [nJoyStickButtons_s];
-
-        //! denotes the number of half axes (every axis twice) there can be.
-        static const unsigned int nHalfAxes_s = 56;
-        /**
-        * Array with all the half axes for mouse and joy sticks.
-        * Keep in mind that the positions are fixed and that the first entry is the
-        * positive one and the second is negative.
-        * Sequence is as follows:
-        *  0 -  3: Mouse x and y
-        *  4 -  7: empty
-        *  8 - 23: joy stick slider axes 1 to 8
-        * 24 - 55: joy stick axes 1 - 16
-        */
-        HalfAxis halfAxes_[nHalfAxes_s];
+        //! Currently active joy sticks
+        unsigned int numberOfJoySticks_;
+
+        //! Actual key bindings for keys on the keyboard
+        Button keys_            [KeyCode::numberOfKeys];
+        //! Number of mouse buttons in KeyBinder (+4)
+        static const int numberOfMouseButtons_ = MouseButtonCode::numberOfButtons + 4;
+        //! Actual key bindings for mouse buttons including the wheel(s)
+        Button mouseButtons_    [numberOfMouseButtons_];
+        //! Actual key bindings for mouse axes
+        HalfAxis mouseAxes_     [MouseAxisCode::numberOfAxes * 2];
+
+        //! Helper class to use something like std:vector<Button[64]>
+        struct JoyStickButtonVector
+        {
+            Button& operator[](unsigned int index) { return buttons[index]; }
+            Button buttons[JoyStickButtonCode::numberOfButtons];
+        };
+        //! Actual key bindings for joy stick buttons
+        std::vector<JoyStickButtonVector> joyStickButtons_;
+        //! Helper class to use something like std:vector<HalfAxis[48]>
+        struct JoyStickAxisVector
+        {
+            HalfAxis& operator[](unsigned int index) { return halfAxes[index]; }
+            HalfAxis halfAxes[JoyStickAxisCode::numberOfAxes * 2];
+        };
+        //! Actual key bindings for joy stick axes (and sliders)
+        std::vector<JoyStickAxisVector> joyStickAxes_;
+
+        //! Pointer map with all Buttons, including half axes
+        std::map<std::string, Button*> allButtons_;
+        //! Pointer list with all half axes
+        std::vector<HalfAxis*> allHalfAxes_;
 
         /**
@@ -131,7 +142,11 @@
         float deriveTime_;
 
-
+        //! Config file used. "" in case of KeyDetector. Also indicates whether we've already loaded.
+        std::string configFile_;
+
+    private:
         //##### ConfigValues #####
-
+        //! Filename of default keybindings.
+        std::string defaultKeybindings_;
         //! Threshold for analog triggers until which the state is 0.
         float analogThreshold_;
@@ -146,7 +161,56 @@
         //! mouse sensitivity if mouse input is derived
         float mouseSensitivityDerived_;
-        //! Whether or not to clip abslute mouse values to 1024
-        bool bClipMouse_;
+        //! Equals one step of the mousewheel
+        float mouseWheelStepSize_;
+
+        //##### Constant config variables #####
+        // Use some value at about 1000. This can be configured with mouseSensitivity_ anyway.
+        static const int mouseClippingSize_ = 1024;
     };
+
+    inline void KeyBinder::keyPressed (const KeyEvent& evt)
+    { keys_[evt.key].execute(KeybindMode::OnPress); }
+
+    inline void KeyBinder::keyReleased(const KeyEvent& evt)
+    { keys_[evt.key].execute(KeybindMode::OnRelease); }
+
+    inline void KeyBinder::keyHeld    (const KeyEvent& evt)
+    { keys_[evt.key].execute(KeybindMode::OnHold); }
+
+
+    inline void KeyBinder::mouseButtonPressed (MouseButtonCode::ByEnum id)
+    { mouseButtons_[id].execute(KeybindMode::OnPress); }
+
+    inline void KeyBinder::mouseButtonReleased(MouseButtonCode::ByEnum id)
+    { mouseButtons_[id].execute(KeybindMode::OnRelease); }
+
+    inline void KeyBinder::mouseButtonHeld    (MouseButtonCode::ByEnum id)
+    { mouseButtons_[id].execute(KeybindMode::OnHold); }
+
+
+    inline void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
+    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnPress); }
+
+    inline void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
+    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnRelease); }
+
+    inline void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
+    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); }
+
+    inline void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
+    {
+        tickDevices(&joyStickAxes_[joyStick][0], &joyStickAxes_[joyStick][JoyStickAxisCode::numberOfAxes * 2]);
+    }
+
+    inline void KeyBinder::tickInput(float dt)
+    {
+        // execute all buffered bindings (additional parameter)
+        for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
+            paramCommandBuffer_[i]->execute();
+
+        // always reset the relative movement of the mouse
+        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
+            mouseAxes_[i].relVal_ = 0.0f;
+    }
 }
 
