Index: code/trunk/src/core/InputHandler.h
===================================================================
--- code/trunk/src/core/InputHandler.h	(revision 1293)
+++ code/trunk/src/core/InputHandler.h	(revision 1349)
@@ -38,6 +38,8 @@
 
 #include <string>
+#include <vector>
 
 #include "ois/OIS.h"
+#include "util/Math.h"
 #include "OrxonoxClass.h"
 #include "CommandExecutor.h"
@@ -46,24 +48,91 @@
 namespace orxonox
 {
-  namespace KeybindSetting
-  {
-    enum KeybindSetting
-    {
-      None,
-      OnPress,
-      OnRelease,
-      Continuous,
-    };
-  }
-
-  struct _CoreExport KeyBinding
-  {
-    std::string commandStr;
-    CommandEvaluation evaluation;
-  };
- 
+  class _CoreExport BaseCommand
+  {
+  public:
+    virtual ~BaseCommand() { }
+    virtual bool execute(float abs = 1.0f, float rel = 1.0f) = 0;
+  };
+
+  class _CoreExport BufferedParamCommand
+  {
+  public:
+    BufferedParamCommand() : value_(0.0f), nValuesAdded_(0), paramIndex_(-1) { }
+    bool execute();
+
+    float value_;
+    unsigned int nValuesAdded_;
+    int paramIndex_;
+    CommandEvaluation evaluation_;
+  };
+
+  class _CoreExport SimpleCommand : public BaseCommand
+  {
+  public:
+    bool execute(float abs = 1.0f, float rel = 1.0f);
+
+    CommandEvaluation evaluation_;
+  };
+
+  class _CoreExport ParamCommand : public BaseCommand
+  {
+  public:
+    ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { }
+    bool execute(float abs = 1.0f, float rel = 1.0f);
+
+    bool bRelative_;
+    float paramModifier_;
+    BufferedParamCommand* paramCommand_;
+  };
+
+  class _CoreExport Button
+  {
+  public:
+    Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); }
+    virtual ~Button() { clear(); }
+    virtual void clear();
+    virtual bool addParamCommand(ParamCommand* command) { return false; }
+    void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer);
+    bool execute(KeybindMode::Enum mode, float abs = 1.0f, float rel = 1.0f);
+
+    //! The configured string value
+    std::string bindingString_;
+    //! Name of the trigger as strings
+    std::string name_;
+    //! Basic commands for OnPress, OnHold and OnRelease
+    BaseCommand** commands_[3];
+    //! Number of basic commands
+    unsigned int nCommands_[3];
+    //! Says how much it takes for an analog axis to trigger a button
+    //! Note: This variable is here to have only one parse() function.
+    float buttonThreshold_;
+  };
+
+
+  class _CoreExport HalfAxis : public Button
+  {
+  public:
+    HalfAxis() : relVal_(0.0f), absVal_(0.0f), paramCommands_(0), nParamCommands_(0),
+                 wasDown_(false), hasChanged_(false) { }
+    using Button::execute;
+    bool execute();
+    //bool execute(KeybindMode::Enum mode) { return Button::execute(mode); }
+    bool addParamCommand(ParamCommand* command);
+    void clear();
+
+    // axis related
+    float relVal_;
+    float absVal_;
+    ParamCommand** paramCommands_;
+    unsigned int nParamCommands_;
+
+    // button related
+    bool wasDown_;
+    bool hasChanged_;
+  };
+
 
   /**
-    @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
+    @brief Handles mouse, keyboard and joy stick input while in the actual game mode.
            Manages the key bindings.
   */
@@ -74,70 +143,85 @@
     ~KeyBinder();
 
-    bool loadBindings();
-    void clearBindings();
+    void loadBindings();
+    void clearBindings(bool bInit = false);
 
     void setConfigValues();
 
   private: // functions
-
-    bool executeSimpleBinding(KeyBinding &binding);
-
-    bool keyPressed (const KeyEvent& evt);
-    bool keyReleased(const KeyEvent& evt);
-    bool keyHeld    (const KeyEvent& evt);
-
-    bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id);
-    bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id);
-    bool mouseButtonHeld    (const MouseState& state, MouseButton::Enum id);
-    bool mouseMoved         (const MouseState& state);
-    bool mouseScrolled      (const MouseState& state);
-
-    bool joyStickButtonPressed (const JoyStickState& state, int button);
-    bool joyStickButtonReleased(const JoyStickState& state, int button);
-    bool joyStickButtonHeld    (const JoyStickState& state, int button);
-    bool joyStickAxisMoved     (const JoyStickState& state, int axis)  ;
-    bool joyStickSliderMoved   (const JoyStickState& state, int index) ;
-    bool joyStickPovMoved      (const JoyStickState& state, int index) ;
-    bool joyStickVector3Moved  (const JoyStickState& state, int index) ;
+    void readTrigger(Button& button);
+
+    //static void clearBundle(KeyBindingBundle& bundle, bool bInit);
+    //static void redimensionBinding(KeyBinding& binding);
+
+    void tick(float dt);
+
+    void keyPressed (const KeyEvent& evt);
+    void keyReleased(const KeyEvent& evt);
+    void keyHeld    (const KeyEvent& evt);
+
+    void mouseButtonPressed (MouseButton::Enum id);
+    void mouseButtonReleased(MouseButton::Enum id);
+    void mouseButtonHeld    (MouseButton::Enum id);
+    void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
+    void mouseScrolled      (int abs, int rel);
+
+    void joyStickButtonPressed (int joyStickID, int button);
+    void joyStickButtonReleased(int joyStickID, int button);
+    void joyStickButtonHeld    (int joyStickID, int button);
+    void joyStickAxisMoved     (int joyStickID, int axis, int value);
 
   private: // variables
-
     //! denotes the number of different keys there are in OIS.
-    static const int numberOfKeys_s = 0xEE;
-    //! Array of input events for every pressed key
-    KeyBinding bindingsKeyPress_  [numberOfKeys_s];
-    //! Array of input events for every released key
-    KeyBinding bindingsKeyRelease_[numberOfKeys_s];
-    //! Array of input events for every held key
-    KeyBinding bindingsKeyHold_   [numberOfKeys_s];
-    //! Names of the keys as strings
-    std::string keyNames_[numberOfKeys_s];
+    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 int numberOfMouseButtons_s = 8;
-    //! Array of input events for every pressed mouse button
-    KeyBinding bindingsMouseButtonPress_  [numberOfMouseButtons_s];
-    //! Array of input events for every released mouse button
-    KeyBinding bindingsMouseButtonRelease_[numberOfMouseButtons_s];
-    //! Array of input events for every held mouse button
-    KeyBinding bindingsMouseButtonHold_   [numberOfMouseButtons_s];
-    //! Key binding for mouse moved event
-    KeyBinding bindingMouseMoved_;
-    //! Key binding for mouse scrolled event
-    KeyBinding bindingMouseScrolled_;
-    //! Names of the mouse buttons as strings
-    std::string mouseButtonNames_[numberOfMouseButtons_s];
+    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 int numberOfJoyStickButtons_s = 32;
-    //! Array of input events for every pressed joy stick button
-    KeyBinding bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
-    //! Array of input events for every released joy stick button
-    KeyBinding bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
-    //! Array of input events for every held joy stick button
-    KeyBinding bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
-    //! Names of the joy stick buttons as strings
-    std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
-
+    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];
+
+    /**
+    * Commands that have additional parameters (axes) are executed at the end of
+    * the tick() so that all values can be buffered for single execution.
+    */
+    std::vector<BufferedParamCommand*> paramCommandBuffer_;
+
+    //! Keeps track of the absolute mouse value (incl. scroll wheel)
+    int mousePosition_[3];
+    //! Used to derive mouse input if requested
+    int mouseRelative_[2];
+    float deriveTime_;
+
+    //##### ConfigValues #####
+    //! Threshold for analog triggers until which the state is 0.
+    float analogThreshold_;
+    //! Threshold for analog triggers until which the button is not pressed.
+    float buttonThreshold_;
+    //! Derive mouse input for absolute values?
+    bool bDeriveMouseInput_;
+    //! Accuracy of the mouse input deriver. The higher the more precise, but laggier.
+    float derivePeriod_;
+    //! mouse sensitivity
+    float mouseSensitivity_;
   };
 
