Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1182


Ignore:
Timestamp:
Apr 24, 2008, 9:40:23 PM (16 years ago)
Author:
rgrieder
Message:
  • InputManager works so far, but has to be largely extended
Location:
code/branches/input
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/core/InputBuffer.cc

    r1066 r1182  
    4040        //this->bActivated_ = false;
    4141        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"().:,;_-+*/=!?<>[|]";
    42         this->keyboard_ = InputManager::getSingleton().getKeyboard();
     42        this->keyboard_ = InputManager::getKeyboard();
    4343        this->buffer_ = "";
    4444
  • code/branches/input/src/core/InputHandler.cc

    r1066 r1182  
    3838#include "InputEvent.h"
    3939#include "InputManager.h"
     40#include "core/CommandExecutor.h"
    4041
    4142namespace orxonox
     
    6869    {
    6970      // simply write the key number (i) in the string
    70       this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i);
    71       this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i);
    72     }
     71      this->bindingsKeyPress_[i] = "";
     72      this->bindingsKeyRelease_[i] = "";
     73    }
     74    this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD);
     75    this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
     76    this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt";
    7377    return true;
    7478  }
     
    8084  bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
    8185  {
    82     if (e.key == OIS::KC_ESCAPE)
    83     {
    84       InputEvent e = {1, true, 0, 0, 0};
    85       InputHandlerGame::callListeners(e);
    86     }
    87     else if (e.key == OIS::KC_NUMPADENTER)
    88     {
    89       InputManager::getSingleton().setInputMode(IM_KEYBOARD);
    90     }
    91     else
     86    this->keysDown_.push_back(e.key);
     87    // find the appropriate key binding
     88    std::string cmdStr = bindingsKeyPress_[int(e.key)];
     89    if (cmdStr != "")
     90    {
     91      CommandExecutor::execute(cmdStr);
     92      COUT(3) << "Executing command: " << cmdStr << std::endl;
     93    }
     94    return true;
     95  }
     96
     97  /**
     98    @brief Event handler for the keyReleased Event.
     99    @param e Event information
     100  */
     101  bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
     102  {
     103    // remove the key from the keysDown_ list
     104    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
     105    {
     106      if (*it == e.key)
     107      {
     108        keysDown_.erase(it);
     109        break;
     110      }
     111    }
     112
     113    // find the appropriate key binding
     114    std::string cmdStr = bindingsKeyRelease_[int(e.key)];
     115    if (cmdStr != "")
     116    {
     117      CommandExecutor::execute(cmdStr);
     118      COUT(3) << "Executing command: " << cmdStr << std::endl;
     119    }
     120    return true;
     121  }
     122
     123  /**
     124    @brief Event handler for the mouseMoved Event.
     125    @param e Event information
     126  */
     127  bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
     128  {
     129    return true;
     130  }
     131
     132  /**
     133    @brief Event handler for the mousePressed Event.
     134    @param e Event information
     135    @param id The ID of the mouse button
     136  */
     137  bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     138  {
     139    return true;
     140  }
     141
     142  /**
     143    @brief Event handler for the mouseReleased Event.
     144    @param e Event information
     145    @param id The ID of the mouse button
     146  */
     147  bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     148  {
     149    return true;
     150  }
     151
     152  /**
     153    @brief Tick method to do additional calculations.
     154    @param dt Delta time.
     155  */
     156  void InputHandlerGame::tick(float dt)
     157  {
     158    // iterate through all the pressed keys
     159    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
    92160    {
    93161      // find the appropriate key binding
    94       std::string cmdStr = bindingsKeyPressed_[int(e.key)];
    95       //COUT(3) << cmdStr << " pressed" << std::endl;
    96     }
    97     return true;
    98   }
    99 
    100   /**
    101     @brief Event handler for the keyReleased Event.
    102     @param e Event information
    103   */
    104   bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
    105   {
    106     // find the appropriate key binding
    107     std::string cmdStr = bindingsKeyReleased_[int(e.key)];
    108     //COUT(3) << cmdStr << " released" << std::endl;
    109     return true;
    110   }
    111 
    112   /**
    113     @brief Event handler for the mouseMoved Event.
    114     @param e Event information
    115   */
    116   bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
    117   {
    118     return true;
    119   }
    120 
    121   /**
    122     @brief Event handler for the mousePressed Event.
    123     @param e Event information
    124     @param id The ID of the mouse button
    125   */
    126   bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    127   {
    128     return true;
    129   }
    130 
    131   /**
    132     @brief Event handler for the mouseReleased Event.
    133     @param e Event information
    134     @param id The ID of the mouse button
    135   */
    136   bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    137   {
    138     return true;
     162      std::string cmdStr = bindingsKeyHold_[*it];
     163      if (cmdStr != "")
     164      {
     165        CommandExecutor::execute(cmdStr);
     166        COUT(3) << "Executing command: " << cmdStr << std::endl;
     167      }
     168    }
    139169  }
    140170
     
    226256  }
    227257
     258  /**
     259    @brief Tick method to do additional calculations.
     260    @param dt Delta time.
     261  */
     262  void InputHandlerGUI::tick(float dt)
     263  {
     264   
     265  }
     266
    228267}
  • code/branches/input/src/core/InputHandler.h

    r1062 r1182  
    3838
    3939#include <string>
     40#include <list>
    4041#include <OIS/OIS.h>
    4142
     
    4445namespace orxonox
    4546{
     47  namespace KeybindSetting
     48  {
     49    enum KeybindSetting
     50    {
     51      None,
     52      OnPress,
     53      OnRelease,
     54      Continuous,
     55    };
     56  }
     57
     58  class _CoreExport BaseInputHandler
     59      : public OIS::KeyListener, public OIS::MouseListener
     60  {
     61    virtual void tick(float dt) = 0;
     62  };
     63   
    4664  /**
    4765    @brief Captures mouse and keyboard input while in the actual game mode.
    4866    Manages the key bindings.
    4967  */
    50   class _CoreExport InputHandlerGame
    51         : public OIS::KeyListener, public OIS::MouseListener
     68  class _CoreExport InputHandlerGame : public BaseInputHandler
    5269  {
    5370  public:
     
    6582                bool keyReleased  (const OIS::KeyEvent   &arg);
    6683
     84    void tick(float dt);
     85
    6786    // temporary hack
    6887    void callListeners(InputEvent &evt);
     88
     89    //! Stores all the keys that are down
     90    std::list<OIS::KeyCode> keysDown_;
    6991
    7092    /** denotes the maximum number of different keys there are in OIS.
     
    7294    static const int numberOfKeys_s = 256;
    7395    //! Array of input events for every pressed key
    74     std::string bindingsKeyPressed_[numberOfKeys_s];
     96    std::string bindingsKeyPress_[numberOfKeys_s];
    7597    //! Array of input events for every released key
    76     std::string bindingsKeyReleased_[numberOfKeys_s];
     98    std::string bindingsKeyRelease_[numberOfKeys_s];
     99    //! Array of input events for every holding key
     100    std::string bindingsKeyHold_[numberOfKeys_s];
    77101
    78102    /** denotes the maximum number of different buttons there are in OIS.
     
    91115    GUI.
    92116  */
    93   class _CoreExport InputHandlerGUI
    94         : public OIS::KeyListener, public OIS::MouseListener
     117  class _CoreExport InputHandlerGUI : public BaseInputHandler
    95118  {
    96119  public:
    97120    InputHandlerGUI ();
    98121    ~InputHandlerGUI();
     122
     123    void tick(float dt);
    99124
    100125  private:
  • code/branches/input/src/core/InputManager.cc

    r1089 r1182  
    3636#include "CoreIncludes.h"
    3737#include "Debug.h"
    38 #include "InputEventListener.h"
    39 #include "InputHandler.h"
    4038#include "InputBuffer.h"
    4139#include "ConsoleCommand.h"
     40#include "util/Convert.h"
    4241
    4342namespace orxonox
    4443{
    45   ConsoleCommand(InputManager, setInputMode, AccessLevel::Admin, true).setDefaultValue(0, IM_INGAME);
    46 
    4744  /**
    4845    @brief Constructor only resets the pointer values to 0.
     
    5047  InputManager::InputManager() :
    5148      inputSystem_(0), keyboard_(0), mouse_(0),
    52       currentMode_(IM_UNINIT), setMode_(IM_UNINIT),
    53       handlerGUI_(0), handlerBuffer_(0), handlerGame_(0)
     49      state_(IS_UNINIT), stateRequest_(IS_UNINIT)
    5450  {
    5551    RegisterObject(InputManager);
    56   }
    57 
    58   /**
    59     @brief Destructor only called at the end of the program
    60   */
    61   InputManager::~InputManager()
    62   {
    63     this->destroy();
    6452  }
    6553
     
    6856    @return A reference to the only instance of the InputManager
    6957  */
    70   InputManager& InputManager::getSingleton()
     58  InputManager& InputManager::_getSingleton()
    7159  {
    7260    static InputManager theOnlyInstance;
    7361    return theOnlyInstance;
     62  }
     63
     64  /**
     65    @brief Destructor only called at the end of the program
     66  */
     67  InputManager::~InputManager()
     68  {
     69    this->_destroy();
    7470  }
    7571
     
    8177    @param windowHeight The height of the render window
    8278  */
    83   bool InputManager::initialise(size_t windowHnd, int windowWidth, int windowHeight)
    84   {
    85     if (!this->inputSystem_)
     79  bool InputManager::_initialise(size_t windowHnd, int windowWidth, int windowHeight)
     80  {
     81    if (!inputSystem_)
    8682    {
    8783      // Setup basic variables
     
    9389      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    9490
    95 #if defined OIS_LINUX_PLATFORM
    96       paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    97 #endif
     91//#if defined OIS_LINUX_PLATFORM
     92//      paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
     93//#endif
    9894
    9995      try
     
    107103        COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl;
    108104
     105        //TODO: check for already pressed keys
     106
    109107        // create a mouse. If none are available the exception is caught.
    110108        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
     
    112110
    113111        // Set mouse region
    114         this->setWindowExtents(windowWidth, windowHeight);
     112        setWindowExtents(windowWidth, windowHeight);
     113
     114        this->state_ = IS_NONE;
    115115      }
    116116      catch (OIS::Exception ex)
     
    118118        // something went wrong with the initialisation
    119119        COUT(ORX_ERROR) << "Error: Failed creating an input system/keyboard/mouse. Message: \"" << ex.eText << "\"" << std::endl;
    120         this->inputSystem_ = 0;
     120        inputSystem_ = 0;
    121121        return false;
    122122      }
    123123    }
    124124
    125     // create the handlers
    126     this->handlerGUI_ = new InputHandlerGUI();
    127     this->handlerGame_ = new InputHandlerGame();
    128     //this->handlerBuffer_ = new InputBuffer();
    129     this->handlerGame_->loadBindings();
    130 
    131     /*COUT(ORX_DEBUG) << "*** InputManager: Loading key bindings..." << std::endl;
    132     // load the key bindings
    133     InputEvent empty = {0, false, 0, 0, 0};
    134     for (int i = 0; i < this->numberOfKeys_; i++)
    135       this->bindingsKeyPressed_[i] = empty;
    136 
    137     //assign 'abort' to the escape key
    138     this->bindingsKeyPressed_[(int)OIS::KC_ESCAPE].id = 1;
    139     COUT(ORX_DEBUG) << "*** InputManager: Loading done." << std::endl;*/
    140 
    141     return true;
     125    keyboard_->setEventCallback(this);
     126    mouse_->setEventCallback(this);
     127
     128    addKeyListener(new InputBuffer(), "buffer");
     129
     130    _loadBindings();
     131
     132    COUT(ORX_DEBUG) << "*** InputManager: Loading done." << std::endl;
     133
     134    return true;
     135  }
     136
     137  void InputManager::_loadBindings()
     138  {
     139    for (int i = 0; i < numberOfKeys_s; i++)
     140    {
     141      // simply write the key number (i) in the string
     142      this->bindingsKeyPress_[i] = "";
     143      this->bindingsKeyRelease_[i] = "";
     144    }
     145    this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "activateConsole";
     146    this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
     147    this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt";
    142148  }
    143149
     
    145151    @brief Destroys all the created input devices and handlers.
    146152  */
    147   void InputManager::destroy()
     153  void InputManager::_destroy()
    148154  {
    149155    COUT(ORX_DEBUG) << "*** InputManager: Destroying ..." << std::endl;
    150     if (this->mouse_)
    151       this->inputSystem_->destroyInputObject(mouse_);
    152     if (this->keyboard_)
    153       this->inputSystem_->destroyInputObject(keyboard_);
    154     if (this->inputSystem_)
    155       OIS::InputManager::destroyInputSystem(this->inputSystem_);
    156 
    157     this->mouse_         = 0;
    158     this->keyboard_      = 0;
    159     this->inputSystem_   = 0;
    160 
    161     if (this->handlerBuffer_)
    162       delete this->handlerBuffer_;
    163     if (this->handlerGame_)
    164       delete this->handlerGame_;
    165     if (this->handlerGUI_)
    166       delete this->handlerGUI_;
    167 
    168     this->handlerBuffer_ = 0;
    169     this->handlerGame_   = 0;
    170     this->handlerGUI_    = 0;
     156    if (mouse_)
     157      inputSystem_->destroyInputObject(mouse_);
     158    if (keyboard_)
     159      inputSystem_->destroyInputObject(keyboard_);
     160    if (inputSystem_)
     161      OIS::InputManager::destroyInputSystem(inputSystem_);
     162
     163    mouse_         = 0;
     164    keyboard_      = 0;
     165    inputSystem_   = 0;
     166
     167    OIS::KeyListener* buffer = keyListeners_["buffer"];
     168    if (buffer)
     169    {
     170      this->removeKeyListener("buffer");
     171      delete buffer;
     172      buffer = 0;
     173    }
    171174
    172175    COUT(ORX_DEBUG) << "*** InputManager: Destroying done." << std::endl;
     
    179182  void InputManager::tick(float dt)
    180183  {
     184    if (state_ == IS_UNINIT)
     185      return;
     186
    181187    // reset the game if it has changed
    182     if (this->currentMode_ != this->setMode_)
    183     {
    184       switch (this->setMode_)
    185       {
    186       case IM_GUI:
    187         this->mouse_->setEventCallback(this->handlerGUI_);
    188         this->keyboard_->setEventCallback(this->handlerGUI_);
     188    if (state_ != stateRequest_)
     189    {
     190      if (stateRequest_ != IS_CUSTOM)
     191        _setDefaultState();
     192
     193      switch (stateRequest_)
     194      {
     195      case IS_NORMAL:
    189196        break;
    190       case IM_INGAME:
    191         this->mouse_->setEventCallback(this->handlerGame_);
    192         this->keyboard_->setEventCallback(this->handlerGame_);
     197      case IS_GUI:
     198        //FIXME: do stuff
    193199        break;
    194       case IM_KEYBOARD:
    195         this->mouse_->setEventCallback(this->handlerGame_);
    196         this->keyboard_->setEventCallback(this->handlerBuffer_);
     200      case IS_CONSOLE:
     201        if (this->keyListeners_.find("buffer") != this->keyListeners_.end())
     202          this->activeKeyListeners_.push_back(this->keyListeners_["buffer"]);
     203        this->bDefaultKeyInput = false;
    197204        break;
    198       case IM_UNINIT:
    199         this->mouse_->setEventCallback(0);
    200         this->keyboard_->setEventCallback(0);
     205      case IS_CUSTOM:
     206        // don't do anything
    201207        break;
    202208      }
    203       this->currentMode_ = this->setMode_;
     209      state_ = stateRequest_;
    204210    }
    205211
     
    207213    if (mouse_)
    208214      mouse_->capture();
    209 
    210215    if (keyboard_)
    211216      keyboard_->capture();
    212217  }
     218
     219  void InputManager::_setDefaultState()
     220  {
     221    this->activeJoyStickListeners_.clear();
     222    this->activeKeyListeners_.clear();
     223    this->activeMouseListeners_.clear();
     224    this->bDefaultKeyInput      = true;
     225    this->bDefaultMouseInput    = true;
     226    this->bDefaultJoyStickInput = true;
     227  }
     228
     229
     230  /**
     231    @brief Event handler for the keyPressed Event.
     232    @param e Event information
     233  */
     234  bool InputManager::keyPressed(const OIS::KeyEvent &e)
     235  {
     236    this->keysDown_.push_back(e.key);
     237
     238    if (this->bDefaultKeyInput)
     239    {
     240      // find the appropriate key binding
     241      std::string cmdStr = bindingsKeyPress_[int(e.key)];
     242      if (cmdStr != "")
     243      {
     244        CommandExecutor::execute(cmdStr);
     245        COUT(3) << "Executing command: " << cmdStr << std::endl;
     246      }
     247    }
     248    else
     249    {
     250      for (std::list<OIS::KeyListener*>::const_iterator it = activeKeyListeners_.begin(); it != activeKeyListeners_.end(); it++)
     251        (*it)->keyPressed(e);
     252    }
     253    return true;
     254  }
     255
     256  /**
     257    @brief Event handler for the keyReleased Event.
     258    @param e Event information
     259  */
     260  bool InputManager::keyReleased(const OIS::KeyEvent &e)
     261  {
     262    // remove the key from the keysDown_ list
     263    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
     264    {
     265      if (*it == e.key)
     266      {
     267        keysDown_.erase(it);
     268        break;
     269      }
     270    }
     271
     272    if (this->bDefaultKeyInput)
     273    {
     274      // find the appropriate key binding
     275      std::string cmdStr = bindingsKeyRelease_[int(e.key)];
     276      if (cmdStr != "")
     277      {
     278        CommandExecutor::execute(cmdStr);
     279        COUT(3) << "Executing command: " << cmdStr << std::endl;
     280      }
     281    }
     282    else
     283    {
     284      for (std::list<OIS::KeyListener*>::const_iterator it = activeKeyListeners_.begin(); it != activeKeyListeners_.end(); it++)
     285        (*it)->keyReleased(e);
     286    }
     287    return true;
     288  }
     289
     290  /**
     291    @brief Event handler for the mouseMoved Event.
     292    @param e Event information
     293  */
     294  bool InputManager::mouseMoved(const OIS::MouseEvent &e)
     295  {
     296    return true;
     297  }
     298
     299  /**
     300    @brief Event handler for the mousePressed Event.
     301    @param e Event information
     302    @param id The ID of the mouse button
     303  */
     304  bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     305  {
     306    return true;
     307  }
     308
     309  /**
     310    @brief Event handler for the mouseReleased Event.
     311    @param e Event information
     312    @param id The ID of the mouse button
     313  */
     314  bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     315  {
     316    return true;
     317  }
     318
     319  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     320  {
     321    return true;
     322  }
     323
     324  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
     325  {
     326    return true;
     327  }
     328
     329  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
     330  {
     331    return true;
     332  }
     333
     334  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
     335  {
     336    return true;
     337  }
     338
     339  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
     340  {
     341    return true;
     342  }
     343
     344
    213345
    214346  /**
     
    221353  {
    222354    // Set mouse region (if window resizes, we should alter this to reflect as well)
    223     const OIS::MouseState &mouseState = mouse_->getMouseState();
     355    const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState();
    224356    mouseState.width  = width;
    225357    mouseState.height = height;
     
    231363    @remark Only has an affect if the mode actually changes
    232364  */
    233   void InputManager::setInputMode(int mode)
    234   {
    235     if (mode > 0 && mode < 4)
    236       getSingleton().setMode_ = (InputMode)mode;
     365  void InputManager::setInputState(const InputState state)
     366  {
     367    _getSingleton().stateRequest_ = state;
    237368  }
    238369
     
    241372    @return The current input mode.
    242373  */
    243   InputMode InputManager::getInputMode()
    244   {
    245     return this->currentMode_;
    246   }
    247 
    248   void InputManager::feedInputBuffer(InputBuffer* buffer)
    249   {
    250     this->handlerBuffer_ = buffer;
    251   }
    252 
     374  InputManager::InputState InputManager::getInputState()
     375  {
     376    return _getSingleton().state_;
     377  }
     378
     379  void InputManager::destroy()
     380  {
     381    _getSingleton()._destroy();
     382  }
     383
     384  bool InputManager::initialise(size_t windowHnd, int windowWidth, int windowHeight)
     385  {
     386    return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight);
     387  }
     388
     389  bool InputManager::addKeyListener(OIS::KeyListener *listener, const std::string& name)
     390  {
     391    if (_getSingleton().keyListeners_.find(name) == _getSingleton().keyListeners_.end())
     392    {
     393      _getSingleton().keyListeners_[name] = listener;
     394      return true;
     395    }
     396    else
     397      return false;
     398  }
     399
     400  bool InputManager::removeKeyListener(const std::string &name)
     401  {
     402    std::map<std::string, OIS::KeyListener*>::iterator it = _getSingleton().keyListeners_.find(name);
     403    if (it != _getSingleton().keyListeners_.end())
     404    {
     405      _getSingleton().keyListeners_.erase(it);
     406      return true;
     407    }
     408    else
     409      return false;
     410  }
     411
     412  OIS::KeyListener* InputManager::getKeyListener(const std::string& name)
     413  {
     414    std::map<std::string, OIS::KeyListener*>::iterator it = _getSingleton().keyListeners_.find(name);
     415    if (it != _getSingleton().keyListeners_.end())
     416    {
     417      return (*it).second;
     418    }
     419    else
     420      return 0;
     421  }
    253422
    254423}
  • code/branches/input/src/core/InputManager.h

    r1084 r1182  
    3838#include "CorePrereqs.h"
    3939
     40#include <map>
     41#include <list>
    4042#include <OIS/OIS.h>
    4143
     
    4648{
    4749  /**
    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
    54   {
    55     IM_GUI      = 0,
    56     IM_KEYBOARD = 1,
    57     IM_INGAME   = 2,
    58     IM_UNINIT   = 3,
    59   };
    60 
    61   /**
    6250    @brief Captures and distributes mouse and keyboard input.
    6351    It resolves the key bindings to InputEvents which can be heard by
     
    6553  */
    6654  class _CoreExport InputManager
    67         : public Tickable
     55        : public Tickable,
     56          public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener
    6857  {
    6958  public:
    70     bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
    71     void destroy();
     59    /**
     60      @brief Designates the way input is handled currently.
     61      IM_GUI:    All the OIS input events are passed to CEGUI
     62      IM_BUFFER: Only keyboard input is captured and passed to the InputBuffer
     63      IM_NORMAL: Normal game mode. Key bindings and mouse are active.
     64    */
     65    enum InputState
     66    {
     67      IS_UNINIT,
     68      IS_NONE,
     69      IS_NORMAL,
     70      IS_GUI,
     71      IS_CONSOLE,
     72      IS_CUSTOM
     73    };
     74
     75  public:
    7276    void tick(float dt);
    73     void setWindowExtents(int width, int height);
    74     InputMode getInputMode();
    7577
    76     // temporary hack
    77     void feedInputBuffer(InputBuffer* buffer);
     78    static bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
     79    static void destroy();
     80
     81    static void setWindowExtents(int width, int height);
     82    static void setInputState(const InputState state);
     83    static InputState getInputState();
     84
     85    static bool addKeyListener(OIS::KeyListener* listener, const std::string& name);
     86    //static bool removeKeyListener(OIS::KeyListener* listener);
     87    static bool removeKeyListener(const std::string& name);
     88    static bool enableKeyListener(const std::string& name);
     89    static bool disableKeyListener(const std::string& name);
     90    static OIS::KeyListener* getKeyListener(const std::string& name);
     91    static bool isKeyListenerActive(const std::string& name);
     92
     93    static bool addMouseListener(OIS::MouseListener* listener, const std::string& name);
     94    //static bool removeMouseListener(OIS::MouseListener* listener);
     95    static bool removeMouseListener(const std::string& name);
     96    static bool enableMouseListener(const std::string& name);
     97    static bool disableMouseListener(const std::string& name);
     98    static OIS::MouseListener* getMouseListener(const std::string& name);
     99    static bool isMouseListenerActive(const std::string& name);
     100
     101    static bool addJoyStickListener(OIS::JoyStickListener* listener, const std::string& name);
     102    //static bool removeJoyStickListener(OIS::JoyStickListener* listener);
     103    static bool removeJoyStickListener(const std::string& name);
     104    static bool enableJoyStickListener(const std::string& name);
     105    static bool disableJoyStickListener(const std::string& name);
     106    static OIS::JoyStickListener* getJoyStickListener(const std::string& name);
     107    static bool isJoyStickListenerActive(const std::string& name);
    78108
    79109    // Temporary solutions. Will be removed soon!
    80     OIS::Mouse    *getMouse()    { return this->mouse_   ; }
    81     OIS::Keyboard *getKeyboard() { return this->keyboard_; }
    82 
    83     static InputManager& getSingleton();
    84     static InputManager* getSingletonPtr() { return &getSingleton(); }
    85     static void setInputMode(int mode);
     110    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
     111    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
    86112
    87113  private:
     
    91117    ~InputManager();
    92118
    93     OIS::InputManager *inputSystem_;    //!< OIS input manager
    94     OIS::Keyboard     *keyboard_;       //!< OIS mouse
    95     OIS::Mouse        *mouse_;          //!< OIS keyboard
     119    bool _initialise(size_t windowHnd, int windowWidth, int windowHeight);
     120    void _destroy();
     121    void _setDefaultState();
     122    void _loadBindings();
    96123
    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
     124    // input events
     125                bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
     126                bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
     127    bool mouseMoved    (const OIS::MouseEvent    &arg);
     128                bool keyPressed    (const OIS::KeyEvent      &arg);
     129                bool keyReleased   (const OIS::KeyEvent      &arg);
     130                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
     131                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     132                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
     133                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
     134                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
    103135
    104     //! Pointer to the instance of the singleton
    105     //static InputManager *singletonRef_s;
     136    static InputManager& _getSingleton();
     137    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
     138
     139  private:
     140    OIS::InputManager* inputSystem_;    //!< OIS input manager
     141    OIS::Keyboard*     keyboard_;       //!< OIS mouse
     142    OIS::Mouse*        mouse_;          //!< OIS keyboard
     143
     144    InputState state_;
     145    InputState stateRequest_;
     146
     147    std::list<OIS::KeyCode> keysDown_;
     148
     149    bool bDefaultKeyInput;
     150    bool bDefaultMouseInput;
     151    bool bDefaultJoyStickInput;
     152
     153    std::map<std::string, OIS::KeyListener*>      keyListeners_;
     154    std::list<OIS::KeyListener*>                  activeKeyListeners_;
     155    std::map<std::string, OIS::MouseListener*>    mouseListeners_;
     156    std::list<OIS::MouseListener*>                activeMouseListeners_;
     157    std::map<std::string, OIS::JoyStickListener*> joystickListeners_;
     158    std::list<OIS::JoyStickListener*>             activeJoyStickListeners_;
     159
     160
     161    /** denotes the maximum number of different keys there are in OIS.
     162        256 should be ok since the highest number in the enum is 237. */
     163    static const int numberOfKeys_s = 256;
     164    //! Array of input events for every pressed key
     165    std::string bindingsKeyPress_  [numberOfKeys_s];
     166    //! Array of input events for every released key
     167    std::string bindingsKeyRelease_[numberOfKeys_s];
     168    //! Array of input events for every held key
     169    std::string bindingsKeyHold_   [numberOfKeys_s];
     170
     171    /** denotes the maximum number of different buttons there are in OIS.
     172        16 should be ok since the highest number in the enum is 7. */
     173    static const int numberOfMouseButtons_s = 16;
     174    //! Array of input events for every pressed mouse button
     175    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
     176    //! Array of input events for every released mouse button
     177    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
     178    //! Array of input events for every held mouse button
     179    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
     180
     181    /** denotes the maximum number of different buttons there are in OIS.
     182        32 should be ok. */
     183    static const int numberOfJoyStickButtons_s = 32;
     184    //! Array of input events for every pressed joystick button
     185    std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
     186    //! Array of input events for every released joystick button
     187    std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
     188    //! Array of input events for every held joystick button
     189    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
     190
    106191  };
    107192}
  • code/branches/input/src/orxonox/Orxonox.cc

    r1156 r1182  
    8484namespace orxonox
    8585{
    86   ConsoleCommand(Orxonox, exit, AccessLevel::None, true);
    87   ConsoleCommand(Orxonox, slomo, AccessLevel::Offline, true).setDefaultValue(0, 1.0);
    88   ConsoleCommand(Orxonox, setTimeFactor, AccessLevel::Offline, false).setDefaultValue(0, 1.0);
    89 
     86  ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None);
     87  ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0);
     88  ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0);
     89  ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None);
    9090  class Testconsole : public InputBufferListener
    9191  {
     
    118118      void exit() const
    119119      {
    120         CommandExecutor::execute("setInputMode 2");
     120        InputManager::setInputState(InputManager::IS_NORMAL);
    121121      }
    122122
     
    177177      delete this->orxonoxHUD_;
    178178    Loader::close();
    179     InputManager::getSingleton().destroy();
     179    InputManager::destroy();
    180180    if (this->auMan_)
    181181      delete this->auMan_;
     
    392392  void Orxonox::setupInputSystem()
    393393  {
    394     inputHandler_ = &InputManager::getSingleton();
    395     if (!inputHandler_->initialise(ogre_->getWindowHandle(),
     394    if (!InputManager::initialise(ogre_->getWindowHandle(),
    396395          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
    397396      abortImmediateForce();
    398     inputHandler_->setInputMode(IM_INGAME);
     397    InputManager::setInputState(InputManager::IS_NORMAL);
    399398  }
    400399
     
    415414  void Orxonox::startRenderLoop()
    416415  {
    417     InputBuffer* ib = new InputBuffer();
    418     InputManager::getSingleton().feedInputBuffer(ib);
    419     Testconsole* console = new Testconsole(ib);
    420     ib->registerListener(console, &Testconsole::listen, true);
    421     ib->registerListener(console, &Testconsole::execute, '\r', false);
    422     ib->registerListener(console, &Testconsole::execute, '\n', false);
    423     ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);
    424     ib->registerListener(console, &Testconsole::clear, '§', true);
    425     ib->registerListener(console, &Testconsole::removeLast, '\b', true);
    426     ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
     416    InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyListener("buffer"));
     417    console_ = new Testconsole(ib);
     418    ib->registerListener(console_, &Testconsole::listen, true);
     419    ib->registerListener(console_, &Testconsole::execute, '\r', false);
     420    ib->registerListener(console_, &Testconsole::execute, '\n', false);
     421    ib->registerListener(console_, &Testconsole::hintandcomplete, '\t', true);
     422    ib->registerListener(console_, &Testconsole::clear, '§', true);
     423    ib->registerListener(console_, &Testconsole::removeLast, '\b', true);
     424    ib->registerListener(console_, &Testconsole::exit, (char)0x1B, true);
    427425
    428426    // first check whether ogre root object has been created
     
    442440      eventTimes[i].clear();
    443441    // fill the fps time list with zeros
    444     for (int i = 0; i < 20; i++)
     442    for (int i = 0; i < 50; i++)
    445443      eventTimes[3].push_back(0);
    446444
     
    468466      // show the current time in the HUD
    469467      orxonoxHUD_->setTime((int)now, 0);
     468      orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber());
    470469      if (eventTimes[3].back() - eventTimes[3].front() != 0)
    471         orxonoxHUD_->setRocket1((int)(20000.0f/(eventTimes[3].back() - eventTimes[3].front())));
     470        orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front())));
    472471
    473472      // Iterate through all Tickables and call their tick(dt) function
     
    533532  }
    534533
    535   /**
    536     @brief Test method for the InputHandler.
    537     But: Is actually responsible for catching an exit event..
    538   */
    539   void Orxonox::eventOccured(InputEvent &evt)
    540   {
    541     if (evt.id == 1)
    542       this->abortRequest();
     534  void Orxonox::activateConsole()
     535  {
     536    InputManager::setInputState(InputManager::IS_CONSOLE);
    543537  }
    544538}
  • code/branches/input/src/orxonox/Orxonox.h

    r1089 r1182  
    4949namespace orxonox {
    5050
     51  class Testconsole;
     52
    5153  enum gameMode{
    5254    SERVER,
     
    5658
    5759  //! Orxonox singleton class
    58   class _OrxonoxExport Orxonox : public InputEventListener
     60  class _OrxonoxExport Orxonox
    5961  {
    6062    public:
     
    7274      static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; }
    7375      static inline void exit() { Orxonox::getSingleton()->abortRequest(); }
     76      static inline void activateConsole();
    7477
    7578   private:
     
    9598      float calculateEventTime(unsigned long, std::deque<unsigned long>&);
    9699
    97       void eventOccured(InputEvent &evt);
    98 
    99100    private:
    100101      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
     
    102103      audio::AudioManager*  auMan_;         //!< audio manager
    103104      InputManager*         inputHandler_;  //!< Handles input with key bindings
     105      Testconsole*          console_;
    104106      Ogre::Timer*          timer_;         //!< Main loop timer
    105107      // TODO: make this a config-value by creating a config class for orxonox
  • code/branches/input/src/orxonox/objects/SpaceShip.cc

    r1064 r1182  
    428428    void SpaceShip::tick(float dt)
    429429    {
    430       if (InputManager::getSingleton().getMouse()->getEventCallback() != this)
    431         {
    432             if (InputManager::getSingleton().getMouse())
     430      if (InputManager::getMouse()->getEventCallback() != this)
     431        {
     432            if (InputManager::getMouse())
    433433            {
    434                 InputManager::getSingleton().getMouse()->setEventCallback(this);
     434                InputManager::getMouse()->setEventCallback(this);
    435435                this->setMouseEventCallback_ = true;
    436436            }
     
    457457        }
    458458
    459         OIS::Keyboard* mKeyboard = InputManager::getSingleton().getKeyboard();
     459        OIS::Keyboard* mKeyboard = InputManager::getKeyboard();
    460460        //FIXME: variable never used
    461461        //OIS::Mouse* mMouse = InputManager::getSingleton().getMouse();
  • code/branches/input/visual_studio/vc8/core.vcproj

    r1153 r1182  
    203203                                RelativePath="..\..\src\core\InputHandler.cc"
    204204                                >
     205                                <FileConfiguration
     206                                        Name="Debug|Win32"
     207                                        ExcludedFromBuild="true"
     208                                        >
     209                                        <Tool
     210                                                Name="VCCLCompilerTool"
     211                                        />
     212                                </FileConfiguration>
     213                                <FileConfiguration
     214                                        Name="Release|Win32"
     215                                        ExcludedFromBuild="true"
     216                                        >
     217                                        <Tool
     218                                                Name="VCCLCompilerTool"
     219                                        />
     220                                </FileConfiguration>
    205221                        </File>
    206222                        <File
  • code/branches/input/visual_studio/vc8/orxonox.vcproj

    r1153 r1182  
    398398                                                />
    399399                                        </FileConfiguration>
     400                                        <FileConfiguration
     401                                                Name="Release|Win32"
     402                                                >
     403                                                <Tool
     404                                                        Name="VCCLCompilerTool"
     405                                                        UsePrecompiledHeader="0"
     406                                                />
     407                                        </FileConfiguration>
    400408                                </File>
    401409                        </Filter>
Note: See TracChangeset for help on using the changeset viewer.