Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2008, 9:07:08 PM (16 years ago)
Author:
rgrieder
Message:
  • merged input branch back to trunk
File:
1 edited

Legend:

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

    r1293 r1349  
    3838
    3939#include <string>
     40#include <vector>
    4041
    4142#include "ois/OIS.h"
     43#include "util/Math.h"
    4244#include "OrxonoxClass.h"
    4345#include "CommandExecutor.h"
     
    4648namespace orxonox
    4749{
    48   namespace KeybindSetting
    49   {
    50     enum KeybindSetting
    51     {
    52       None,
    53       OnPress,
    54       OnRelease,
    55       Continuous,
    56     };
    57   }
    58 
    59   struct _CoreExport KeyBinding
    60   {
    61     std::string commandStr;
    62     CommandEvaluation evaluation;
    63   };
    64  
     50  class _CoreExport BaseCommand
     51  {
     52  public:
     53    virtual ~BaseCommand() { }
     54    virtual bool execute(float abs = 1.0f, float rel = 1.0f) = 0;
     55  };
     56
     57  class _CoreExport BufferedParamCommand
     58  {
     59  public:
     60    BufferedParamCommand() : value_(0.0f), nValuesAdded_(0), paramIndex_(-1) { }
     61    bool execute();
     62
     63    float value_;
     64    unsigned int nValuesAdded_;
     65    int paramIndex_;
     66    CommandEvaluation evaluation_;
     67  };
     68
     69  class _CoreExport SimpleCommand : public BaseCommand
     70  {
     71  public:
     72    bool execute(float abs = 1.0f, float rel = 1.0f);
     73
     74    CommandEvaluation evaluation_;
     75  };
     76
     77  class _CoreExport ParamCommand : public BaseCommand
     78  {
     79  public:
     80    ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { }
     81    bool execute(float abs = 1.0f, float rel = 1.0f);
     82
     83    bool bRelative_;
     84    float paramModifier_;
     85    BufferedParamCommand* paramCommand_;
     86  };
     87
     88  class _CoreExport Button
     89  {
     90  public:
     91    Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); }
     92    virtual ~Button() { clear(); }
     93    virtual void clear();
     94    virtual bool addParamCommand(ParamCommand* command) { return false; }
     95    void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer);
     96    bool execute(KeybindMode::Enum mode, float abs = 1.0f, float rel = 1.0f);
     97
     98    //! The configured string value
     99    std::string bindingString_;
     100    //! Name of the trigger as strings
     101    std::string name_;
     102    //! Basic commands for OnPress, OnHold and OnRelease
     103    BaseCommand** commands_[3];
     104    //! Number of basic commands
     105    unsigned int nCommands_[3];
     106    //! Says how much it takes for an analog axis to trigger a button
     107    //! Note: This variable is here to have only one parse() function.
     108    float buttonThreshold_;
     109  };
     110
     111
     112  class _CoreExport HalfAxis : public Button
     113  {
     114  public:
     115    HalfAxis() : relVal_(0.0f), absVal_(0.0f), paramCommands_(0), nParamCommands_(0),
     116                 wasDown_(false), hasChanged_(false) { }
     117    using Button::execute;
     118    bool execute();
     119    //bool execute(KeybindMode::Enum mode) { return Button::execute(mode); }
     120    bool addParamCommand(ParamCommand* command);
     121    void clear();
     122
     123    // axis related
     124    float relVal_;
     125    float absVal_;
     126    ParamCommand** paramCommands_;
     127    unsigned int nParamCommands_;
     128
     129    // button related
     130    bool wasDown_;
     131    bool hasChanged_;
     132  };
     133
    65134
    66135  /**
    67     @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
     136    @brief Handles mouse, keyboard and joy stick input while in the actual game mode.
    68137           Manages the key bindings.
    69138  */
     
    74143    ~KeyBinder();
    75144
    76     bool loadBindings();
    77     void clearBindings();
     145    void loadBindings();
     146    void clearBindings(bool bInit = false);
    78147
    79148    void setConfigValues();
    80149
    81150  private: // functions
    82 
    83     bool executeSimpleBinding(KeyBinding &binding);
    84 
    85     bool keyPressed (const KeyEvent& evt);
    86     bool keyReleased(const KeyEvent& evt);
    87     bool keyHeld    (const KeyEvent& evt);
    88 
    89     bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id);
    90     bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id);
    91     bool mouseButtonHeld    (const MouseState& state, MouseButton::Enum id);
    92     bool mouseMoved         (const MouseState& state);
    93     bool mouseScrolled      (const MouseState& state);
    94 
    95     bool joyStickButtonPressed (const JoyStickState& state, int button);
    96     bool joyStickButtonReleased(const JoyStickState& state, int button);
    97     bool joyStickButtonHeld    (const JoyStickState& state, int button);
    98     bool joyStickAxisMoved     (const JoyStickState& state, int axis)  ;
    99     bool joyStickSliderMoved   (const JoyStickState& state, int index) ;
    100     bool joyStickPovMoved      (const JoyStickState& state, int index) ;
    101     bool joyStickVector3Moved  (const JoyStickState& state, int index) ;
     151    void readTrigger(Button& button);
     152
     153    //static void clearBundle(KeyBindingBundle& bundle, bool bInit);
     154    //static void redimensionBinding(KeyBinding& binding);
     155
     156    void tick(float dt);
     157
     158    void keyPressed (const KeyEvent& evt);
     159    void keyReleased(const KeyEvent& evt);
     160    void keyHeld    (const KeyEvent& evt);
     161
     162    void mouseButtonPressed (MouseButton::Enum id);
     163    void mouseButtonReleased(MouseButton::Enum id);
     164    void mouseButtonHeld    (MouseButton::Enum id);
     165    void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
     166    void mouseScrolled      (int abs, int rel);
     167
     168    void joyStickButtonPressed (int joyStickID, int button);
     169    void joyStickButtonReleased(int joyStickID, int button);
     170    void joyStickButtonHeld    (int joyStickID, int button);
     171    void joyStickAxisMoved     (int joyStickID, int axis, int value);
    102172
    103173  private: // variables
    104 
    105174    //! denotes the number of different keys there are in OIS.
    106     static const int numberOfKeys_s = 0xEE;
    107     //! Array of input events for every pressed key
    108     KeyBinding bindingsKeyPress_  [numberOfKeys_s];
    109     //! Array of input events for every released key
    110     KeyBinding bindingsKeyRelease_[numberOfKeys_s];
    111     //! Array of input events for every held key
    112     KeyBinding bindingsKeyHold_   [numberOfKeys_s];
    113     //! Names of the keys as strings
    114     std::string keyNames_[numberOfKeys_s];
     175    static const unsigned int nKeys_s = 0xEE;
     176    //! Actual key bindings as bundle for Press, Hold and Release
     177    Button keys_ [nKeys_s];
    115178
    116179    //! denotes the number of different mouse buttons there are in OIS.
    117     static const int numberOfMouseButtons_s = 8;
    118     //! Array of input events for every pressed mouse button
    119     KeyBinding bindingsMouseButtonPress_  [numberOfMouseButtons_s];
    120     //! Array of input events for every released mouse button
    121     KeyBinding bindingsMouseButtonRelease_[numberOfMouseButtons_s];
    122     //! Array of input events for every held mouse button
    123     KeyBinding bindingsMouseButtonHold_   [numberOfMouseButtons_s];
    124     //! Key binding for mouse moved event
    125     KeyBinding bindingMouseMoved_;
    126     //! Key binding for mouse scrolled event
    127     KeyBinding bindingMouseScrolled_;
    128     //! Names of the mouse buttons as strings
    129     std::string mouseButtonNames_[numberOfMouseButtons_s];
     180    static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels
     181    //! Actual key bindings as bundle for Press, Hold and Release
     182    Button mouseButtons_ [nMouseButtons_s];
    130183
    131184    //! denotes the number of different joy stick buttons there are in OIS.
    132     static const int numberOfJoyStickButtons_s = 32;
    133     //! Array of input events for every pressed joy stick button
    134     KeyBinding bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
    135     //! Array of input events for every released joy stick button
    136     KeyBinding bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
    137     //! Array of input events for every held joy stick button
    138     KeyBinding bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
    139     //! Names of the joy stick buttons as strings
    140     std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
    141 
     185    static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons
     186    //! Actual key bindings as bundle for Press, Hold and Release
     187    Button joyStickButtons_ [nJoyStickButtons_s];
     188
     189    //! denotes the number of half axes (every axis twice) there can be.
     190    static const unsigned int nHalfAxes_s = 56;
     191    /**
     192    * Array with all the half axes for mouse and joy sticks.
     193    * Keep in mind that the positions are fixed and that the first entry is the
     194    * positive one and the second is negative.
     195    * Sequence is as follows:
     196    *  0 -  3: Mouse x and y
     197    *  4 -  7: empty
     198    *  8 - 23: joy stick (slider) axes 1 to 8
     199    * 24 - 55: joy stick axes 1 - 16
     200    */
     201    HalfAxis halfAxes_[nHalfAxes_s];
     202
     203    /**
     204    * Commands that have additional parameters (axes) are executed at the end of
     205    * the tick() so that all values can be buffered for single execution.
     206    */
     207    std::vector<BufferedParamCommand*> paramCommandBuffer_;
     208
     209    //! Keeps track of the absolute mouse value (incl. scroll wheel)
     210    int mousePosition_[3];
     211    //! Used to derive mouse input if requested
     212    int mouseRelative_[2];
     213    float deriveTime_;
     214
     215    //##### ConfigValues #####
     216    //! Threshold for analog triggers until which the state is 0.
     217    float analogThreshold_;
     218    //! Threshold for analog triggers until which the button is not pressed.
     219    float buttonThreshold_;
     220    //! Derive mouse input for absolute values?
     221    bool bDeriveMouseInput_;
     222    //! Accuracy of the mouse input deriver. The higher the more precise, but laggier.
     223    float derivePeriod_;
     224    //! mouse sensitivity
     225    float mouseSensitivity_;
    142226  };
    143227
Note: See TracChangeset for help on using the changeset viewer.