Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/InputHandler.h @ 1341

Last change on this file since 1341 was 1340, checked in by rgrieder, 17 years ago
  • 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 size: 7.6 KB
RevLine 
[971]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1323]3 *                    > www.orxonox.net <
[971]4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
[973]28
[971]29/**
30 @file
[1022]31 @brief Different definitions of input processing.
[971]32 */
[973]33
34#ifndef _InputHandler_H__
35#define _InputHandler_H__
36
[1062]37#include "CorePrereqs.h"
38
[1022]39#include <string>
[1340]40#include <vector>
[1293]41
[1219]42#include "ois/OIS.h"
[1323]43#include "util/Math.h"
[1219]44#include "OrxonoxClass.h"
45#include "CommandExecutor.h"
[1293]46#include "InputInterfaces.h"
[973]47
48namespace orxonox
49{
[1340]50  class _CoreExport BaseCommand
[1219]51  {
[1340]52  public:
53    virtual ~BaseCommand() { }
54    virtual bool execute(float abs = 1.0f, float rel = 1.0f) = 0;
[1323]55  };
[1219]56
[1340]57  class _CoreExport BufferedParamCommand
[1219]58  {
[1340]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  };
[1323]67
[1340]68  class _CoreExport SimpleCommand : public BaseCommand
69  {
70  public:
71    bool execute(float abs = 1.0f, float rel = 1.0f);
72
73    CommandEvaluation evaluation_;
[1219]74  };
75
[1340]76  class _CoreExport ParamCommand : public BaseCommand
[1323]77  {
[1340]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_;
[1323]85  };
86
[1340]87  class _CoreExport Button
[1323]88  {
[1340]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_;
[1323]108  };
109
[1340]110
111  class _CoreExport HalfAxis : public Button
[1323]112  {
[1340]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_;
[1323]130  };
131
132
[1219]133  /**
[1340]134    @brief Handles mouse, keyboard and joy stick input while in the actual game mode.
[1219]135           Manages the key bindings.
136  */
137  class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
138  {
139  public:
140    KeyBinder ();
141    ~KeyBinder();
[1323]142
[1340]143    void loadBindings();
[1323]144    void clearBindings(bool bInit = false);
[1022]145
[1323]146    void setConfigValues();
147
[1219]148  private: // functions
[1340]149    void readTrigger(Button& button);
[1219]150
[1340]151    //static void clearBundle(KeyBindingBundle& bundle, bool bInit);
152    //static void redimensionBinding(KeyBinding& binding);
153
[1323]154    void tick(float dt);
[1219]155
[1340]156    void keyPressed (const KeyEvent& evt);
157    void keyReleased(const KeyEvent& evt);
158    void keyHeld    (const KeyEvent& evt);
[1022]159
[1340]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);
[1022]165
[1340]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);
[1022]170
[1219]171  private: // variables
172    //! denotes the number of different keys there are in OIS.
[1323]173    static const unsigned int nKeys_s = 0xEE;
174    //! Actual key bindings as bundle for Press, Hold and Release
[1340]175    Button keys_ [nKeys_s];
[1022]176
[1219]177    //! denotes the number of different mouse buttons there are in OIS.
[1323]178    static const unsigned int nMouseButtons_s = 8;
179    //! Actual key bindings as bundle for Press, Hold and Release
[1340]180    Button mouseButtons_ [nMouseButtons_s];
[1219]181
182    //! denotes the number of different joy stick buttons there are in OIS.
[1323]183    static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons
184    //! Actual key bindings as bundle for Press, Hold and Release
[1340]185    Button joyStickButtons_ [nJoyStickButtons_s];
[1219]186
[1323]187    //! denotes the number of half axes (every axis twice) there can be.
188    static const unsigned int nHalfAxes_s = 56;
189    /**
190    * Array with all the half axes for mouse and joy sticks.
[1340]191    * Keep in mind that the positions are fixed and that the first entry is the
[1323]192    * positive one and the second is negative.
193    * Sequence is as follows:
194    *  0 -  3: Mouse x and y
195    *  4 -  7: Mouse scroll wheels 1 and 2 (2 not yet supported)
196    *  8 - 23: joy stick (slider) axes 1 to 8
197    * 24 - 55: joy stick axes 1 - 16
198    */
199    HalfAxis halfAxes_[nHalfAxes_s];
200
201    /**
202    * Commands that have additional parameters (axes) are executed at the end of
203    * the tick() so that all values can be buffered for single execution.
204    */
[1340]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_;
[973]211  };
212
213
214  /**
[1022]215    @brief Captures mouse and keyboard input and distributes it to the
216    GUI.
[973]217  */
[1219]218  //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
219  //{
220  //public:
221  //  GUIInputHandler ();
222  //  ~GUIInputHandler();
[973]223
[1219]224  //private:
225  //  // input events
[1293]226    //bool keyPressed   (const OIS::KeyEvent   &arg);
227    //bool keyReleased  (const OIS::KeyEvent   &arg);
228    //bool keyHeld      (const OIS::KeyEvent   &arg);
[973]229
[1293]230  //  bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButton id);
231    //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButton id);
232    //bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButton id);
[1219]233  //  bool mouseMoved   (const OIS::MouseEvent &arg);
234
[1323]235    //bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
236    //bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
237    //bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
238    //bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
239    //bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
240    //bool povMoved      (const OIS::JoyStickEvent &arg, int id);
[1219]241  //};
242
[973]243}
244
245#endif /* _InputHandler_H__ */
Note: See TracBrowser for help on using the repository browser.