Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 2, 2008, 10:44:57 PM (17 years ago)
Author:
rgrieder
Message:

merged input branch back to trunk. Not yet tested on tardis

File:
1 edited

Legend:

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

    r1084 r1219  
    3838#include "CorePrereqs.h"
    3939
    40 #include <OIS/OIS.h>
     40#include <map>
     41#include <list>
    4142
     43#include "ois/OIS.h"
    4244#include "Tickable.h"
    43 #include "InputEvent.h"
    4445
    4546namespace orxonox
    4647{
    47   /**
    48     @brief Designates the way input is handled currently.
    49     IM_GUI:      All the OIS input events are passed to CEGUI
    50     IM_KEYBOARD: Only keyboard input is captured and passed to the InputBuffer
    51     IM_INGAME:   Normal game mode. Key bindings and mouse are active.
    52   */
    53   enum InputMode
     48  class Mouse : public OIS::Mouse
    5449  {
    55     IM_GUI      = 0,
    56     IM_KEYBOARD = 1,
    57     IM_INGAME   = 2,
    58     IM_UNINIT   = 3,
    5950  };
    6051
    6152  /**
    6253    @brief Captures and distributes mouse and keyboard input.
    63     It resolves the key bindings to InputEvents which can be heard by
    64     implementing the InputEventListener interface.
    6554  */
    6655  class _CoreExport InputManager
    67         : public Tickable
     56        : public Tickable,
     57          public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
    6858  {
    69   public:
    70     bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
    71     void destroy();
    72     void tick(float dt);
    73     void setWindowExtents(int width, int height);
    74     InputMode getInputMode();
     59  public: // enumerations
     60    /**
     61      @brief Designates the way input is handled and redirected.
     62    */
     63    enum InputState
     64    {
     65      IS_UNINIT,  //!< InputManager has not yet been initialised.
     66      IS_NONE,    //!< Input is discarded.
     67      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
     68      IS_GUI,     //!< All OIS input events are passed to CEGUI.
     69      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
     70      IS_CUSTOM   //!< Any possible configuration.
     71    };
    7572
    76     // temporary hack
    77     void feedInputBuffer(InputBuffer* buffer);
     73  public: // static functions
     74    static bool initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
     75          const bool createKeyboard = true, const bool createMouse = true, const bool createJoySticks = false);
     76    static bool initialiseKeyboard();
     77    static bool initialiseMouse();
     78    static bool initialiseJoySticks();
     79    static int  numberOfKeyboards();
     80    static int  numberOfMice();
     81    static int  numberOfJoySticks();
     82
     83    static void destroy();
     84    static void destroyKeyboard();
     85    static void destroyMouse();
     86    static void destroyJoySticks();
     87
     88    static void setWindowExtents(const int width, const int height);
     89
     90    static void setInputState(const InputState state);
     91    static InputState getInputState();
     92
     93    static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
     94    static bool removeKeyHandler              (const std::string& name);
     95    static KeyHandler* getKeyHandler          (const std::string& name);
     96    static bool enableKeyHandler              (const std::string& name);
     97    static bool disableKeyHandler             (const std::string& name);
     98    static bool isKeyHandlerActive            (const std::string& name);
     99
     100    static bool addMouseHandler               (MouseHandler* handler, const std::string& name);
     101    static bool removeMouseHandler            (const std::string& name);
     102    static MouseHandler* getMouseHandler      (const std::string& name);
     103    static bool enableMouseHandler            (const std::string& name);
     104    static bool disableMouseHandler           (const std::string& name);
     105    static bool isMouseHandlerActive          (const std::string& name);
     106
     107    static bool addJoyStickHandler            (JoyStickHandler* handler, const std::string& name);
     108    static bool removeJoyStickHandler         (const std::string& name);
     109    static JoyStickHandler* getJoyStickHandler(const std::string& name);
     110    static bool enableJoyStickHandler         (const std::string& name, const int id);
     111    static bool disableJoyStickHandler        (const std::string& name, const int id);
     112    static bool isJoyStickHandlerActive       (const std::string& name, const int id);
    78113
    79114    // Temporary solutions. Will be removed soon!
    80     OIS::Mouse    *getMouse()    { return this->mouse_   ; }
    81     OIS::Keyboard *getKeyboard() { return this->keyboard_; }
     115    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
     116    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
    82117
    83     static InputManager& getSingleton();
    84     static InputManager* getSingletonPtr() { return &getSingleton(); }
    85     static void setInputMode(int mode);
    86 
    87   private:
     118  private: // functions
    88119    // don't mess with a Singleton
    89120    InputManager ();
     
    91122    ~InputManager();
    92123
    93     OIS::InputManager *inputSystem_;    //!< OIS input manager
    94     OIS::Keyboard     *keyboard_;       //!< OIS mouse
    95     OIS::Mouse        *mouse_;          //!< OIS keyboard
     124    // Intenal methods
     125    bool _initialise(const size_t, const int, const int, const bool, const bool, const bool);
     126    bool _initialiseKeyboard();
     127    bool _initialiseMouse();
     128    bool _initialiseJoySticks();
    96129
    97     InputMode          currentMode_;    //!< Input mode currently used
    98     InputMode          setMode_;        //!< Input mode that has been set lately
    99     InputHandlerGUI   *handlerGUI_;     //!< Handles the input if in GUI mode
    100     // FIXME: insert the InputBuffer once merged with core2
    101     InputBuffer       *handlerBuffer_;  //!< Handles the input if in Buffer mode
    102     InputHandlerGame  *handlerGame_;    //!< Handles the input if in Game mode
     130    void _destroy();
     131    void _destroyKeyboard();
     132    void _destroyMouse();
     133    void _destroyJoySticks();
    103134
    104     //! Pointer to the instance of the singleton
    105     //static InputManager *singletonRef_s;
     135    //void _setNumberOfJoysticks(int size);
     136
     137    void tick(float dt);
     138
     139    // input events
     140                bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
     141                bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
     142    bool mouseMoved    (const OIS::MouseEvent    &arg);
     143                bool keyPressed    (const OIS::KeyEvent      &arg);
     144                bool keyReleased   (const OIS::KeyEvent      &arg);
     145                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
     146                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     147                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
     148                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
     149                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     150                bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
     151
     152    static InputManager& _getSingleton();
     153    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
     154
     155  private: // variables
     156    OIS::InputManager*                          inputSystem_; //!< OIS input manager
     157    OIS::Keyboard*                              keyboard_;    //!< OIS mouse
     158    OIS::Mouse*                                 mouse_;       //!< OIS keyboard
     159    std::vector<OIS::JoyStick*>                 joySticks_;   //!< OIS joy sticks
     160
     161    InputState state_;
     162    InputState stateRequest_;
     163
     164    std::map<std::string, KeyHandler*>          keyHandlers_;
     165    std::map<std::string, MouseHandler*>        mouseHandlers_;
     166    std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
     167
     168    std::vector<KeyHandler*>                    activeKeyHandlers_;
     169    std::vector<MouseHandler*>                  activeMouseHandlers_;
     170    std::map< OIS::JoyStick*, std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
     171
     172    std::list<OIS::KeyCode>                     keysDown_;
     173    std::list<OIS::MouseButtonID>               mouseButtonsDown_;
     174    std::map< OIS::JoyStick*, std::list<int> >  joyStickButtonsDown_;
     175
    106176  };
    107177}
Note: See TracChangeset for help on using the changeset viewer.