Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 29, 2008, 11:13:11 PM (16 years ago)
Author:
rgrieder
Message:
  • InputManager fully functional (most parts tested), if there wasn't that selfish SpaceShip who claims all the mouse input…
  • InputHandler still loads hard coded key bindings, but works fine otherwise
  • I've tried to give full multiple joy stick support. Couldn't yet test that however. And more than one Joystick still doesn't make sense as long as we don't have split view ;)
File:
1 edited

Legend:

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

    r1182 r1203  
    3838
    3939#include <string>
    40 #include <list>
    41 #include <OIS/OIS.h>
    42 
    43 #include "InputEvent.h"
     40#include "ois/OIS.h"
    4441
    4542namespace orxonox
     
    5653  }
    5754
    58   class _CoreExport BaseInputHandler
    59       : public OIS::KeyListener, public OIS::MouseListener
    60   {
    61     virtual void tick(float dt) = 0;
    62   };
    63    
    6455  /**
    65     @brief Captures mouse and keyboard input while in the actual game mode.
    66     Manages the key bindings.
     56    @brief Interface class used for key input listeners.
    6757  */
    68   class _CoreExport InputHandlerGame : public BaseInputHandler
     58  class _CoreExport KeyHandler : public OIS::KeyListener
    6959  {
    7060  public:
    71     InputHandlerGame ();
    72     ~InputHandlerGame();
     61    virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;
     62  };
     63
     64  /**
     65    @brief Interface class used for mouse input listeners.
     66  */
     67  class _CoreExport MouseHandler : public OIS::MouseListener
     68  {
     69  public:
     70    virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;
     71  };
     72
     73  /**
     74    @brief Interface class used for joy stick input listeners.
     75  */
     76  class _CoreExport JoyStickHandler : public OIS::JoyStickListener
     77  {
     78  public:
     79    virtual bool buttonHeld(const OIS::JoyStickEvent &arg, int button) = 0;
     80  };
     81 
     82
     83  /**
     84    @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
     85           Manages the key bindings.
     86  */
     87  class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler
     88  {
     89  public:
     90    KeyBinder ();
     91    ~KeyBinder();
    7392
    7493    bool loadBindings();
     94    void clearBindings();
    7595
    76   private:
    77     // input events
    78                 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    79                 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    80     bool mouseMoved   (const OIS::MouseEvent &arg);
     96  private: // functions
    8197                bool keyPressed   (const OIS::KeyEvent   &arg);
    8298                bool keyReleased  (const OIS::KeyEvent   &arg);
     99                bool keyHeld      (const OIS::KeyEvent   &arg);
    83100
    84     void tick(float dt);
     101    bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     102                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     103                bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     104    bool mouseMoved   (const OIS::MouseEvent &arg);
    85105
    86     // temporary hack
    87     void callListeners(InputEvent &evt);
     106                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
     107                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     108                bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
     109                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
     110                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
     111                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
    88112
    89     //! Stores all the keys that are down
    90     std::list<OIS::KeyCode> keysDown_;
    91 
     113  private: // variables
    92114    /** denotes the maximum number of different keys there are in OIS.
    93         256 should be ok since the highest number in the enum is 237. */
     115        256 should be ok since the highest number in the OIS enum is 237. */
    94116    static const int numberOfKeys_s = 256;
    95117    //! Array of input events for every pressed key
    96     std::string bindingsKeyPress_[numberOfKeys_s];
     118    std::string bindingsKeyPress_  [numberOfKeys_s];
    97119    //! Array of input events for every released key
    98120    std::string bindingsKeyRelease_[numberOfKeys_s];
    99     //! Array of input events for every holding key
    100     std::string bindingsKeyHold_[numberOfKeys_s];
     121    //!Array of input events for every held key
     122    std::string bindingsKeyHold_   [numberOfKeys_s];
    101123
    102124    /** denotes the maximum number of different buttons there are in OIS.
    103         16 should be ok since the highest number in the enum is 7. */
    104     static const int numberOfButtons_s = 16;
    105     //! Array of input events for every pressed key
    106     std::string bindingsButtonPressed_[numberOfButtons_s];
    107     //! Array of input events for every released key
    108     std::string bindingsButtonReleased_[numberOfButtons_s];
     125        16 should be ok since the highest number in the OIS enum is 7. */
     126    static const int numberOfMouseButtons_s = 16;
     127    //! Array of input events for every pressed mouse button
     128    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
     129    //! Array of input events for every released mouse button
     130    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
     131    //! Array of input events for every held mouse button
     132    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
     133
     134    /** denotes the maximum number of different buttons there are in OIS.
     135        32 should be ok. */
     136    static const int numberOfJoyStickButtons_s = 32;
     137    //! Array of input events for every pressed joy stick button
     138    std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
     139    //! Array of input events for every released joy stick button
     140    std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
     141    //! Array of input events for every held joy stick button
     142    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
    109143
    110144  };
     
    115149    GUI.
    116150  */
    117   class _CoreExport InputHandlerGUI : public BaseInputHandler
    118   {
    119   public:
    120     InputHandlerGUI ();
    121     ~InputHandlerGUI();
     151  //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
     152  //{
     153  //public:
     154  //  GUIInputHandler ();
     155  //  ~GUIInputHandler();
    122156
    123     void tick(float dt);
     157  //private:
     158  //  // input events
     159                //bool keyPressed   (const OIS::KeyEvent   &arg);
     160                //bool keyReleased  (const OIS::KeyEvent   &arg);
     161                //bool keyHeld      (const OIS::KeyEvent   &arg);
    124162
    125   private:
    126     // input events
    127                 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    128                 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    129     bool mouseMoved   (const OIS::MouseEvent &arg);
    130                 bool keyPressed   (const OIS::KeyEvent   &arg);
    131                 bool keyReleased  (const OIS::KeyEvent   &arg);
    132   };
     163  //  bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     164                //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     165                //bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     166  //  bool mouseMoved   (const OIS::MouseEvent &arg);
     167
     168                //bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
     169                //bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     170                //bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
     171                //bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
     172                //bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
     173                //bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     174  //};
    133175
    134176}
Note: See TracChangeset for help on using the changeset viewer.