Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2008, 12:23:29 AM (16 years ago)
Author:
rgrieder
Message:
  • tried a more object oriented approach for the KeyBinder
  • things work as far as I can tell
  • tested slomo command on joy stick slider: I was able to steer the time factor with the slider.
  • more infos to come..
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/core/InputHandler.h

    r1323 r1340  
    3838
    3939#include <string>
     40#include <vector>
    4041
    4142#include "ois/OIS.h"
     
    4748namespace orxonox
    4849{
    49   struct _CoreExport AxisCommand
    50   {
    51     std::string commandStr;
    52     CommandEvaluation evaluation;
    53     bool bRelative;
    54     float value;
    55     unsigned int nValuesAdded;
    56   };
    57 
    58   struct _CoreExport SimpleCommand
    59   {
    60     // for simple binding; direct
    61     std::string commandStr;
    62     CommandEvaluation evaluation;
    63 
    64     // axis binding; buffered
    65     AxisCommand* axisCommand;
    66     float axisModifier;
    67   };
    68 
    69   struct _CoreExport KeyBinding
    70   {
    71     void clear() { commands = 0; nCommands = 0; }
    72     SimpleCommand* commands;
    73     unsigned int nCommands;
    74   };
    75 
    76   struct _CoreExport KeyBindingBundle
    77   {
    78     KeyBinding OnPress;
    79     KeyBinding OnRelease;
    80     KeyBinding OnHold;
    81   };
    82 
    83   struct _CoreExport HalfAxis
    84   {
    85     float rel;
    86     float abs;
    87     float threshold;
    88     bool wasDown;
    89     bool hasChanged;
     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    float value_;
     63    unsigned int nValuesAdded_;
     64    int paramIndex_;
     65    CommandEvaluation evaluation_;
     66  };
     67
     68  class _CoreExport SimpleCommand : public BaseCommand
     69  {
     70  public:
     71    bool execute(float abs = 1.0f, float rel = 1.0f);
     72
     73    CommandEvaluation evaluation_;
     74  };
     75
     76  class _CoreExport ParamCommand : public BaseCommand
     77  {
     78  public:
     79    ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { }
     80    bool execute(float abs = 1.0f, float rel = 1.0f);
     81
     82    bool bRelative_;
     83    float paramModifier_;
     84    BufferedParamCommand* paramCommand_;
     85  };
     86
     87  class _CoreExport Button
     88  {
     89  public:
     90    Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); }
     91    virtual ~Button() { clear(); }
     92    virtual void clear();
     93    virtual bool addParamCommand(ParamCommand* command) { return false; }
     94    void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer);
     95    bool execute(KeybindMode::Enum mode);
     96
     97    //! The configured string value
     98    std::string bindingString_;
     99    //! Name of the trigger as strings
     100    std::string name_;
     101    //! Basic commands for OnPress, OnHold and OnRelease
     102    BaseCommand** commands_[3];
     103    //! Number of basic commands
     104    unsigned int nCommands_[3];
     105    //! Says how much it takes for an analog axis to trigger a button
     106    //! Note: This variable is here to have only one parse() function.
     107    float buttonThreshold_;
     108  };
     109
     110
     111  class _CoreExport HalfAxis : public Button
     112  {
     113  public:
     114    HalfAxis() : relVal_(0.0f), absVal_(0.0f), paramCommands_(0), nParamCommands_(0),
     115                 wasDown_(false), hasChanged_(false) { }
     116    bool execute();
     117    bool execute(KeybindMode::Enum mode) { return Button::execute(mode); }
     118    bool addParamCommand(ParamCommand* command);
     119    void clear();
     120
     121    // axis related
     122    float relVal_;
     123    float absVal_;
     124    ParamCommand** paramCommands_;
     125    unsigned int nParamCommands_;
     126
     127    // button related
     128    bool wasDown_;
     129    bool hasChanged_;
    90130  };
    91131
    92132
    93133  /**
    94     @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
     134    @brief Handles mouse, keyboard and joy stick input while in the actual game mode.
    95135           Manages the key bindings.
    96136  */
     
    101141    ~KeyBinder();
    102142
    103     bool loadBindings();
     143    void loadBindings();
    104144    void clearBindings(bool bInit = false);
    105145
     
    107147
    108148  private: // functions
    109     bool readBindings(std::string* names, std::string* bindingStrings, KeyBindingBundle* bindings, unsigned int size);
    110     bool executeBinding(KeyBinding& binding, float axisRel, float axisAbs);
    111     void clearBundle(KeyBindingBundle& bundle, bool bInit);
     149    void readTrigger(Button& button);
     150
     151    //static void clearBundle(KeyBindingBundle& bundle, bool bInit);
     152    //static void redimensionBinding(KeyBinding& binding);
    112153
    113154    void tick(float dt);
    114155
    115     bool keyPressed (const KeyEvent& evt);
    116     bool keyReleased(const KeyEvent& evt);
    117     bool keyHeld    (const KeyEvent& evt);
    118 
    119     bool mouseButtonPressed (MouseButton::Enum id);
    120     bool mouseButtonReleased(MouseButton::Enum id);
    121     bool mouseButtonHeld    (MouseButton::Enum id);
    122     bool mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    123     bool mouseScrolled      (int abs, int rel);
    124 
    125     bool joyStickButtonPressed (int joyStickID, int button);
    126     bool joyStickButtonReleased(int joyStickID, int button);
    127     bool joyStickButtonHeld    (int joyStickID, int button);
    128     bool joyStickAxisMoved     (int joyStickID, int axis, int value)  ;
     156    void keyPressed (const KeyEvent& evt);
     157    void keyReleased(const KeyEvent& evt);
     158    void keyHeld    (const KeyEvent& evt);
     159
     160    void mouseButtonPressed (MouseButton::Enum id);
     161    void mouseButtonReleased(MouseButton::Enum id);
     162    void mouseButtonHeld    (MouseButton::Enum id);
     163    void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
     164    void mouseScrolled      (int abs, int rel);
     165
     166    void joyStickButtonPressed (int joyStickID, int button);
     167    void joyStickButtonReleased(int joyStickID, int button);
     168    void joyStickButtonHeld    (int joyStickID, int button);
     169    void joyStickAxisMoved     (int joyStickID, int axis, int value);
    129170
    130171  private: // variables
     
    132173    static const unsigned int nKeys_s = 0xEE;
    133174    //! Actual key bindings as bundle for Press, Hold and Release
    134     KeyBindingBundle bindingsKeys_ [nKeys_s];
    135     //! Names of the keys as strings
    136     std::string namesKeys_         [nKeys_s];
    137     //! The configured string values
    138     std::string bindingStringsKeys_[nKeys_s];
     175    Button keys_ [nKeys_s];
    139176
    140177    //! denotes the number of different mouse buttons there are in OIS.
    141178    static const unsigned int nMouseButtons_s = 8;
    142179    //! Actual key bindings as bundle for Press, Hold and Release
    143     KeyBindingBundle bindingsMouseButtons_ [nMouseButtons_s];
    144     //! Names of the mouse buttons as strings
    145     std::string namesMouseButtons_         [nMouseButtons_s];
    146     //! The configured string values
    147     std::string bindingStringsMouseButtons_[nMouseButtons_s];
     180    Button mouseButtons_ [nMouseButtons_s];
    148181
    149182    //! denotes the number of different joy stick buttons there are in OIS.
    150183    static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons
    151184    //! Actual key bindings as bundle for Press, Hold and Release
    152     KeyBindingBundle bindingsJoyStickButtons_ [nJoyStickButtons_s];
    153     //! Names of the joy stick buttons as strings
    154     std::string namesJoyStickButtons_         [nJoyStickButtons_s];
    155     //! The configured string values
    156     std::string bindingStringsJoyStickButtons_[nJoyStickButtons_s];
     185    Button joyStickButtons_ [nJoyStickButtons_s];
    157186
    158187    //! denotes the number of half axes (every axis twice) there can be.
     
    160189    /**
    161190    * Array with all the half axes for mouse and joy sticks.
    162     * Bear in mind that the positions are fixed and that the first entry is the
     191    * Keep in mind that the positions are fixed and that the first entry is the
    163192    * positive one and the second is negative.
    164193    * Sequence is as follows:
     
    169198    */
    170199    HalfAxis halfAxes_[nHalfAxes_s];
    171     //! Actual key bindings as bundle for Press, Hold and Release
    172     KeyBindingBundle bindingsHalfAxes_ [nHalfAxes_s];
    173     //! Names of the half axes
    174     std::string namesHalfAxes_         [nHalfAxes_s];
    175     //! The configured string values
    176     std::string bindingStringsHalfAxes_[nHalfAxes_s];
    177200
    178201    /**
     
    180203    * the tick() so that all values can be buffered for single execution.
    181204    */
    182     std::vector<AxisCommand*> axisCommands_;
     205    std::vector<BufferedParamCommand*> paramCommandBuffer_;
     206
     207    //! Threshold for analog triggers until which the state is 0.
     208    float analogThreshold_;
     209    //! Threshold for analog triggers until which the button is not pressed.
     210    float buttonThreshold_;
    183211  };
    184212
Note: See TracChangeset for help on using the changeset viewer.