Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1193


Ignore:
Timestamp:
Apr 27, 2008, 1:50:28 PM (17 years ago)
Author:
rgrieder
Message:
  • OIS initialise should be complete, but need to use cmake to determine version number..
  • merged trunk back
Location:
code/branches/input
Files:
5 deleted
7 edited
1 copied
2 moved

Legend:

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

    r1089 r1193  
    264264///  CCOUT: Prints output with std::cout and adds the classname   ///
    265265/////////////////////////////////////////////////////////////////////
     266#define CCOUTORX_NONE    CCOUT0
     267#define CCOUTORX_ERROR   CCOUT1
     268#define CCOUTORX_WARNING CCOUT2
     269#define CCOUTORX_INFO    CCOUT3
     270#define CCOUTORX_DEBUG   CCOUT4
     271#define CCOUTORX_vDEBUG  CCOUT5
    266272
    267273#define CCOUT_EXEC(x) \
  • code/branches/input/src/core/InputBuffer.h

    r1066 r1193  
    3535#include <list>
    3636
    37 #ifdef WIN32
    3837#include <OIS/OISKeyboard.h>
    39 #else
    40 #include <OISKeyboard.h>
    41 #endif
    4238
    4339namespace orxonox
  • code/branches/input/src/core/InputManager.cc

    r1182 r1193  
    2828
    2929/**
    30  @file
    31  @brief Implementation of a little Input handler that distributes everything
    32         coming from OIS.
     30  @file
     31  @brief Implementation of the InputManager that captures all the input from OIS
     32         and redirects it to listeners if necessary.
    3333 */
    3434
     
    4242namespace orxonox
    4343{
    44   /**
    45     @brief Constructor only resets the pointer values to 0.
     44  // ###############################
     45  // ###    Internal Methods     ###
     46  // ###############################
     47
     48  /**
     49    @brief Constructor only sets member fields to initial zero values
     50           and registers the class in the class hierarchy.
    4651  */
    4752  InputManager::InputManager() :
     
    4954      state_(IS_UNINIT), stateRequest_(IS_UNINIT)
    5055  {
     56    // overwrite every key binding with ""
     57    _clearBindings();
     58    _setNumberOfJoysticks(0);
     59
    5160    RegisterObject(InputManager);
    5261  }
     
    6372
    6473  /**
    65     @brief Destructor only called at the end of the program
     74    @brief Destructor only called at the end of the program, after main.
    6675  */
    6776  InputManager::~InputManager()
     
    7180
    7281  /**
    73     @brief Creates the OIS::InputMananger, the keyboard and the mouse and
    74            assigns the key bindings.
     82    @brief Creates the OIS::InputMananger, the keyboard, the mouse and
     83           the joysticks and assigns the key bindings.
    7584    @param windowHnd The window handle of the render window
    7685    @param windowWidth The width of the render window
    7786    @param windowHeight The height of the render window
    7887  */
    79   bool InputManager::_initialise(size_t windowHnd, int windowWidth, int windowHeight)
    80   {
    81     if (!inputSystem_)
    82     {
    83       // Setup basic variables
     88  bool InputManager::_initialise(size_t windowHnd, int windowWidth, int windowHeight,
     89        bool createKeyboard, bool createMouse, bool createJoySticks)
     90  {
     91    if (state_ == IS_UNINIT)
     92    {
     93      CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl;
     94
    8495      OIS::ParamList paramList;
    8596      std::ostringstream windowHndStr;
     
    95106      try
    96107      {
    97         // Create inputsystem
    98108        inputSystem_ = OIS::InputManager::createInputSystem(paramList);
    99         COUT(ORX_DEBUG) << "*** InputManager: Created OIS input system" << std::endl;
    100 
    101         // create a keyboard. If none are available the exception is caught.
    102         keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
    103         COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl;
    104 
    105         //TODO: check for already pressed keys
    106 
    107         // create a mouse. If none are available the exception is caught.
    108         mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
    109         COUT(ORX_DEBUG) << "*** InputManager: Created OIS keyboard" << std::endl;
    110 
    111         // Set mouse region
    112         setWindowExtents(windowWidth, windowHeight);
    113 
    114         this->state_ = IS_NONE;
     109        CCOUT(ORX_DEBUG) << "Created OIS input system" << std::endl;
    115110      }
    116111      catch (OIS::Exception ex)
    117112      {
    118         // something went wrong with the initialisation
    119         COUT(ORX_ERROR) << "Error: Failed creating an input system/keyboard/mouse. Message: \"" << ex.eText << "\"" << std::endl;
     113        CCOUT(ORX_ERROR) << "Error: Failed creating an OIS input system."
     114            << "OIS message: \"" << ex.eText << "\"" << std::endl;
    120115        inputSystem_ = 0;
    121116        return false;
    122117      }
    123     }
    124 
    125     keyboard_->setEventCallback(this);
    126     mouse_->setEventCallback(this);
    127 
     118
     119      if (createKeyboard)
     120        _initialiseKeyboard();
     121
     122      if (createMouse)
     123        _initialiseMouse();
     124
     125      if (createJoySticks)
     126        _initialiseJoySticks();
     127
     128      // Set mouse/joystick region
     129      setWindowExtents(windowWidth, windowHeight);
     130
     131      this->state_ = IS_NONE;
     132      CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl;
     133    }
     134    else
     135    {
     136      CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;
     137    }
     138
     139    // InputManager holds the input buffer --> create one and add it.
    128140    addKeyListener(new InputBuffer(), "buffer");
    129141
    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     }
     142    // Read all the key bindings and assign them
     143    if (!_loadBindings())
     144      return false;
     145
     146    CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
     147    return true;
     148  }
     149
     150  /**
     151    @brief Creates a keyboard and sets the event handler.
     152  */
     153  void InputManager::_initialiseKeyboard()
     154  {
     155    try
     156    {
     157#if (OIS_VERSION >> 8) == 0x0100
     158    if (inputSystem_->numKeyboards() > 0)
     159#elif (OIS_VERSION >> 8) == 0x0102
     160    if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)
     161#endif
     162      {
     163        keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true);
     164        // register our listener in OIS.
     165        keyboard_->setEventCallback(this);
     166        // note: OIS will not detect keys that have already been down when the keyboard was created.
     167        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
     168      }
     169      else
     170        CCOUT(ORX_WARNING) << "Warning: No keyboard found!" << std::endl;
     171    }
     172    catch (OIS::Exception ex)
     173    {
     174      CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS keyboard\n"
     175          << "OIS error message: \"" << ex.eText << "\"" << std::endl;
     176      keyboard_ = 0;
     177    }
     178  }
     179
     180  /**
     181    @brief Creates a mouse and sets the event handler.
     182  */
     183  void InputManager::_initialiseMouse()
     184  {
     185    try
     186    {
     187#if (OIS_VERSION >> 8) == 0x0100
     188    if (inputSystem_->numMice() > 0)
     189#elif (OIS_VERSION >> 8) == 0x0102
     190    if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
     191#endif
     192      {
     193        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
     194        // register our listener in OIS.
     195        mouse_->setEventCallback(this);
     196        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
     197      }
     198      else
     199        CCOUT(ORX_WARNING) << "Warning: No mouse found!" << std::endl;
     200    }
     201    catch (OIS::Exception ex)
     202    {
     203      CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n"
     204          << "OIS error message: \"" << ex.eText << "\"" << std::endl;
     205      mouse_ = 0;
     206    }
     207  }
     208
     209  /**
     210    @brief Creates all joy sticks and sets the event handler.
     211  */
     212  void InputManager::_initialiseJoySticks()
     213  {
     214#if (OIS_VERSION >> 8) == 0x0100
     215    if (inputSystem_->numJoySticks() > 0)
     216    {
     217      _setNumberOfJoysticks(inputSystem_->numJoySticks());
     218#elif (OIS_VERSION >> 8) == 0x0102
     219    if (inputSystem_->getNumberOfDevices(OIS::OISJoyStick) > 0)
     220    {
     221      _setNumberOfJoysticks(inputSystem_->getNumberOfDevices(OIS::OISJoyStick));
     222#endif
     223      for (std::vector<OIS::JoyStick*>::iterator it = joySticks_.begin(); it != joySticks_.end(); it++)
     224      {
     225        try
     226        {
     227          *it = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject(OIS::OISJoyStick, true));
     228          // register our listener in OIS.
     229          (*it)->setEventCallback(this);
     230          CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << (*it)->getID() << std::endl;
     231        }
     232        catch (OIS::Exception ex)
     233        {
     234          CCOUT(ORX_WARNING) << "Warning: Failed to create OIS joy stick with ID" << (*it)->getID() << "\n"
     235              << "OIS error message: \"" << ex.eText << "\"" << std::endl;
     236          (*it) = 0;
     237        }
     238      }
     239    }
     240    else
     241      CCOUT(ORX_WARNING) << "Warning: Joy stick support requested, but no joy stick was found" << std::endl;
     242  }
     243
     244  /**
     245    @brief Resizes all lists related to joy sticks and sets joy stick bindings to "".
     246    @param size Number of joy sticks available.
     247  */
     248  void InputManager::_setNumberOfJoysticks(int size)
     249  {
     250    this->bindingsJoyStickButtonHold_   .resize(size);
     251    this->bindingsJoyStickButtonPress_  .resize(size);
     252    this->bindingsJoyStickButtonRelease_.resize(size);
     253    this->bJoyStickButtonBindingsActive_.resize(size);
     254    this->joyStickButtonsDown_          .resize(size);
     255    this->joySticks_                    .resize(size);
     256    for (int j = 0; j < size; j++)
     257    {
     258      bindingsJoyStickButtonPress_  [j].resize(numberOfJoyStickButtons_s);
     259      bindingsJoyStickButtonRelease_[j].resize(numberOfJoyStickButtons_s);
     260      bindingsJoyStickButtonHold_   [j].resize(numberOfJoyStickButtons_s);
     261      for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     262      {
     263        this->bindingsJoyStickButtonPress_  [j][i] = "";
     264        this->bindingsJoyStickButtonRelease_[j][i] = "";
     265        this->bindingsJoyStickButtonHold_   [j][i] = "";
     266      }
     267    }
     268  }
     269
     270  /**
     271    @brief Loads the key and button bindings.
     272  */
     273  bool InputManager::_loadBindings()
     274  {
     275    CCOUT(ORX_DEBUG) << "Loading key bindings..." << std::endl;
     276
     277    // clear all the bindings at first.
     278    _clearBindings();
     279
     280    // TODO: Insert the code to load the bindings from file.
    145281    this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "activateConsole";
    146282    this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
    147283    this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt";
    148   }
    149 
    150   /**
    151     @brief Destroys all the created input devices and handlers.
     284
     285    CCOUT(ORX_DEBUG) << "Loading key bindings done." << std::endl;
     286    return true;
     287  }
     288
     289  /**
     290    @brief Overwrites all bindings with ""
     291  */
     292  void InputManager::_clearBindings()
     293  {
     294    for (int i = 0; i < numberOfKeys_s; i++)
     295    {
     296      this->bindingsKeyPress_  [i] = "";
     297      this->bindingsKeyRelease_[i] = "";
     298      this->bindingsKeyHold_   [i] = "";
     299    }
     300    for (int i = 0; i < numberOfMouseButtons_s; i++)
     301    {
     302      this->bindingsMouseButtonPress_  [i] = "";
     303      this->bindingsMouseButtonRelease_[i] = "";
     304      this->bindingsMouseButtonHold_   [i] = "";
     305    }
     306    for (unsigned int j = 0; j < joySticks_.size(); j++)
     307    {
     308      for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     309      {
     310        this->bindingsJoyStickButtonPress_  [j][i] = "";
     311        this->bindingsJoyStickButtonRelease_[j][i] = "";
     312        this->bindingsJoyStickButtonHold_   [j][i] = "";
     313      }
     314    }
     315  }
     316
     317  /**
     318    @brief Destroys all the created input devices and sets the InputManager to construction state.
    152319  */
    153320  void InputManager::_destroy()
    154321  {
    155     COUT(ORX_DEBUG) << "*** InputManager: Destroying ..." << std::endl;
    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     }
    174 
    175     COUT(ORX_DEBUG) << "*** InputManager: Destroying done." << std::endl;
    176   }
     322    CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
     323
     324    if (state_ != IS_UNINIT)
     325    {
     326      this->listenersKeyActive_.clear();
     327      this->listenersMouseActive_.clear();
     328      this->listenersJoySticksActive_.clear();
     329      this->listenersKey_.clear();
     330      this->listenersMouse_.clear();
     331      this->listenersJoySticks_.clear();
     332
     333      this->keysDown_.clear();
     334      this->mouseButtonsDown_.clear();
     335
     336      _clearBindings();
     337
     338      if (keyboard_)
     339        inputSystem_->destroyInputObject(keyboard_);
     340      keyboard_ = 0;
     341
     342      if (mouse_)
     343        inputSystem_->destroyInputObject(mouse_);
     344      mouse_ = 0;
     345
     346      if (joySticks_.size() > 0)
     347      {
     348        for (unsigned int i = 0; i < joySticks_.size(); i++)
     349        {
     350          if (joySticks_[i] != 0)
     351            inputSystem_->destroyInputObject(joySticks_[i]);
     352        }
     353        _setNumberOfJoysticks(0);
     354      }
     355
     356      if (inputSystem_)
     357        OIS::InputManager::destroyInputSystem(inputSystem_);
     358      inputSystem_ = 0;
     359
     360      if (listenersKey_.find("buffer") != listenersKey_.end())
     361        delete listenersKey_["buffer"];
     362
     363      this->state_ = IS_UNINIT;
     364    }
     365    else
     366      CCOUT(ORX_WARNING) << "Warning: Cannot be destroyed, since not initialised." << std::endl;
     367
     368    CCOUT(ORX_DEBUG) << "Destroying done." << std::endl;
     369  }
     370
     371
     372  // ###############################
     373  // ###  Public Member Methods  ###
     374  // ###############################
    177375
    178376  /**
     
    188386    if (state_ != stateRequest_)
    189387    {
    190       if (stateRequest_ != IS_CUSTOM)
    191         _setDefaultState();
    192 
    193388      switch (stateRequest_)
    194389      {
    195390      case IS_NORMAL:
     391        this->listenersKeyActive_.clear();
     392        this->listenersMouseActive_.clear();
     393        this->listenersJoySticksActive_.clear();
     394        this->bKeyBindingsActive_            = true;
     395        this->bMouseButtonBindingsActive_    = true;
     396        //this->bJoySticksButtonBindingsActive_ = true;
    196397        break;
     398
    197399      case IS_GUI:
    198         //FIXME: do stuff
     400        // FIXME: do stuff
    199401        break;
     402
    200403      case IS_CONSOLE:
    201         if (this->keyListeners_.find("buffer") != this->keyListeners_.end())
    202           this->activeKeyListeners_.push_back(this->keyListeners_["buffer"]);
    203         this->bDefaultKeyInput = false;
     404        this->listenersKeyActive_.clear();
     405        this->listenersMouseActive_.clear();
     406        //this->listenersJoyStickActive_.clear();
     407        this->bKeyBindingsActive_            = false;
     408        this->bMouseButtonBindingsActive_    = true;
     409        //this->bJoyStickButtonBindingsActive_ = true;
     410        if (listenersKey_.find("buffer") != listenersKey_.end())
     411          listenersKeyActive_.push_back(listenersKey_["buffer"]);
     412        else
     413        {
     414          // someone fiddled with the InputBuffer
     415          CCOUT(2) << "Error: Cannot redirect input to console, InputBuffer instance missing." << std::endl;
     416          this->bKeyBindingsActive_ = true;
     417        }
    204418        break;
     419
     420      case IS_NONE:
     421        this->listenersKeyActive_.clear();
     422        this->listenersMouseActive_.clear();
     423        //this->listenersJoyStickActive_.clear();
     424        this->bKeyBindingsActive_            = false;
     425        this->bMouseButtonBindingsActive_    = false;
     426        //this->bJoyStickButtonBindingsActive_ = false;
     427        break;
     428
    205429      case IS_CUSTOM:
    206430        // don't do anything
     
    210434    }
    211435
    212     // capture all the input. That calls the event handlers.
     436    // Capture all the input. This calls the event handlers in InputManager.
    213437    if (mouse_)
    214438      mouse_->capture();
     
    217441  }
    218442
    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   }
     443  /*void InputManager::_setDefaultState()
     444  {
     445    this->listenersKeyActive_.clear();
     446    this->listenersMouseActive_.clear();
     447    this->listenersJoyStickActive_.clear();
     448    this->bKeyBindingsActive_            = true;
     449    this->bMouseButtonBindingsActive_    = true;
     450    this->bJoyStickButtonBindingsActive_ = true;
     451  }*/
    228452
    229453
     
    236460    this->keysDown_.push_back(e.key);
    237461
    238     if (this->bDefaultKeyInput)
     462    if (this->bKeyBindingsActive_)
    239463    {
    240464      // find the appropriate key binding
     
    248472    else
    249473    {
    250       for (std::list<OIS::KeyListener*>::const_iterator it = activeKeyListeners_.begin(); it != activeKeyListeners_.end(); it++)
     474      for (std::list<OIS::KeyListener*>::const_iterator it = listenersKeyActive_.begin(); it != listenersKeyActive_.end(); it++)
    251475        (*it)->keyPressed(e);
    252476    }
     
    270494    }
    271495
    272     if (this->bDefaultKeyInput)
     496    if (this->bKeyBindingsActive_)
    273497    {
    274498      // find the appropriate key binding
     
    282506    else
    283507    {
    284       for (std::list<OIS::KeyListener*>::const_iterator it = activeKeyListeners_.begin(); it != activeKeyListeners_.end(); it++)
     508      for (std::list<OIS::KeyListener*>::const_iterator it = listenersKeyActive_.begin(); it != listenersKeyActive_.end(); it++)
    285509        (*it)->keyReleased(e);
    286510    }
     
    343567
    344568
     569  // ################################
     570  // ### Static Interface Methods ###
     571  // ################################
    345572
    346573  /**
     
    352579  void InputManager::setWindowExtents(int width, int height)
    353580  {
    354     // Set mouse region (if window resizes, we should alter this to reflect as well)
    355     const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState();
    356     mouseState.width  = width;
    357     mouseState.height = height;
     581    if (_getSingleton().mouse_)
     582    {
     583      // Set mouse region (if window resizes, we should alter this to reflect as well)
     584      const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState();
     585      mouseState.width  = width;
     586      mouseState.height = height;
     587    }
    358588  }
    359589
     
    382612  }
    383613
    384   bool InputManager::initialise(size_t windowHnd, int windowWidth, int windowHeight)
    385   {
    386     return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight);
     614  bool InputManager::initialise(size_t windowHnd, int windowWidth, int windowHeight,
     615    bool createKeyboard, bool createMouse, bool createJoySticks)
     616  {
     617    return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight,
     618          createKeyboard, createMouse, createJoySticks);
    387619  }
    388620
    389621  bool InputManager::addKeyListener(OIS::KeyListener *listener, const std::string& name)
    390622  {
    391     if (_getSingleton().keyListeners_.find(name) == _getSingleton().keyListeners_.end())
    392     {
    393       _getSingleton().keyListeners_[name] = listener;
     623    if (_getSingleton().listenersKey_.find(name) == _getSingleton().listenersKey_.end())
     624    {
     625      _getSingleton().listenersKey_[name] = listener;
    394626      return true;
    395627    }
     
    400632  bool InputManager::removeKeyListener(const std::string &name)
    401633  {
    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);
     634    std::map<std::string, OIS::KeyListener*>::iterator it = _getSingleton().listenersKey_.find(name);
     635    if (it != _getSingleton().listenersKey_.end())
     636    {
     637      _getSingleton().listenersKey_.erase(it);
    406638      return true;
    407639    }
     
    412644  OIS::KeyListener* InputManager::getKeyListener(const std::string& name)
    413645  {
    414     std::map<std::string, OIS::KeyListener*>::iterator it = _getSingleton().keyListeners_.find(name);
    415     if (it != _getSingleton().keyListeners_.end())
     646    std::map<std::string, OIS::KeyListener*>::iterator it = _getSingleton().listenersKey_.find(name);
     647    if (it != _getSingleton().listenersKey_.end())
    416648    {
    417649      return (*it).second;
  • code/branches/input/src/core/InputManager.h

    r1182 r1193  
    5656          public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener
    5757  {
    58   public:
     58  public: // enumerations
    5959    /**
    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.
     60      @brief Designates the way input is handled and redirected.
    6461    */
    6562    enum InputState
    6663    {
    67       IS_UNINIT,
    68       IS_NONE,
    69       IS_NORMAL,
    70       IS_GUI,
    71       IS_CONSOLE,
    72       IS_CUSTOM
     64      IS_UNINIT,  //!< InputManager has not yet been initialised.
     65      IS_NONE,    //!< Input is discarded.
     66      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
     67      IS_GUI,     //!< All OIS input events are passed to CEGUI.
     68      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
     69      IS_CUSTOM   //!< Any possible configuration.
    7370    };
    7471
    75   public:
    76     void tick(float dt);
    77 
    78     static bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
     72  public: // functions
     73    // METHODS OF THE STATIC INTERFACE
     74
     75    static bool initialise(size_t windowHnd, int windowWidth, int windowHeight,
     76          bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
    7977    static void destroy();
    8078
    8179    static void setWindowExtents(int width, int height);
     80
    8281    static void setInputState(const InputState state);
    8382    static InputState getInputState();
     83    static void setKeyBindingState           (bool bActive);
     84    static void setMouseButtonBindingState   (bool bActive);
     85    static void setJoyStickButtonBindingState(bool bActive);
    8486
    8587    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);
     88    static bool removeKeyListener  (const std::string& name);
     89    static bool enableKeyListener  (const std::string& name);
     90    static bool disableKeyListener (const std::string& name);
     91    static bool isKeyListenerActive(const std::string& name);
    9092    static OIS::KeyListener* getKeyListener(const std::string& name);
    91     static bool isKeyListenerActive(const std::string& name);
    9293
    9394    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);
     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 bool isMouseListenerActive(const std::string& name);
    9899    static OIS::MouseListener* getMouseListener(const std::string& name);
    99     static bool isMouseListenerActive(const std::string& name);
    100100
    101101    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);
     102    static bool removeJoyStickListener  (const std::string& name);
     103    static bool enableJoyStickListener  (const std::string& name);
     104    static bool disableJoyStickListener (const std::string& name);
     105    static bool isJoyStickListenerActive(const std::string& name);
    106106    static OIS::JoyStickListener* getJoyStickListener(const std::string& name);
    107     static bool isJoyStickListenerActive(const std::string& name);
    108107
    109108    // Temporary solutions. Will be removed soon!
     
    111110    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
    112111
    113   private:
     112  private: // functions
    114113    // don't mess with a Singleton
    115114    InputManager ();
     
    117116    ~InputManager();
    118117
    119     bool _initialise(size_t windowHnd, int windowWidth, int windowHeight);
     118    // Intenal methods
     119    bool _initialise(size_t, int, int, bool, bool, bool);
     120    void _initialiseKeyboard();
     121    void _initialiseMouse();
     122    void _initialiseJoySticks();
    120123    void _destroy();
    121     void _setDefaultState();
    122     void _loadBindings();
     124    //void _setDefaultState();
     125    bool _loadBindings();
     126    void _clearBindings();
     127    void _setNumberOfJoysticks(int size);
     128
     129    void tick(float dt);
    123130
    124131    // input events
     
    137144    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
    138145
    139   private:
     146  private: // variables
    140147    OIS::InputManager* inputSystem_;    //!< OIS input manager
    141148    OIS::Keyboard*     keyboard_;       //!< OIS mouse
    142149    OIS::Mouse*        mouse_;          //!< OIS keyboard
     150    std::vector<OIS::JoyStick*> joySticks_;       //!< OIS joy sticks
    143151
    144152    InputState state_;
    145153    InputState stateRequest_;
    146154
    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_;
     155    bool bKeyBindingsActive_;
     156    bool bMouseButtonBindingsActive_;
     157    std::vector<bool> bJoyStickButtonBindingsActive_;
     158
     159    std::map<std::string, OIS::KeyListener*>      listenersKey_;
     160    std::map<std::string, OIS::MouseListener*>    listenersMouse_;
     161    std::map<std::string, OIS::JoyStickListener*> listenersJoySticks_;
     162
     163    std::list<OIS::KeyListener*>      listenersKeyActive_;
     164    std::list<OIS::MouseListener*>    listenersMouseActive_;
     165    std::list<OIS::JoyStickListener*> listenersJoySticksActive_;
     166
     167    std::list<OIS::KeyCode>         keysDown_;
     168    std::list<OIS::MouseButtonID>   mouseButtonsDown_;
     169    std::vector< std::list<int> >   joyStickButtonsDown_;
    159170
    160171
    161172    /** 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. */
     173        256 should be ok since the highest number in the OIS enum is 237. */
    163174    static const int numberOfKeys_s = 256;
    164175    //! Array of input events for every pressed key
     
    170181
    171182    /** 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. */
     183        16 should be ok since the highest number in the OIS enum is 7. */
    173184    static const int numberOfMouseButtons_s = 16;
    174185    //! Array of input events for every pressed mouse button
     
    182193        32 should be ok. */
    183194    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];
     195    std::vector< std::vector< std::string > > bindingsJoyStickButtonPress_;
     196    std::vector< std::vector< std::string > > bindingsJoyStickButtonRelease_;
     197    std::vector< std::vector< std::string > > bindingsJoyStickButtonHold_;
    190198
    191199  };
  • code/branches/input/visual_studio/core_properties.vsprops

    r1084 r1193  
    1212        <Tool
    1313                Name="VCLinkerTool"
    14                 AdditionalDependencies="OgreMain$(CSS).lib OIS$(CS).lib lua51$(CS).lib"
     14                AdditionalDependencies="OgreMain$(CSS).lib ois-1.2.0$(CS).lib lua-5.1$(CS).lib"
    1515        />
    1616</VisualStudioPropertySheet>
  • code/branches/input/visual_studio/orxonox_properties.vsprops

    r1084 r1193  
    1414        <Tool
    1515                Name="VCLinkerTool"
    16                 AdditionalDependencies="OgreMain$(CSS).lib OIS$(CS).lib"
     16                AdditionalDependencies="OgreMain$(CSS).lib ois-1.2.0$(CS).lib"
    1717                OutputFile="$(OutDir)$(ProjectName)$(CS).exe"
    1818                IgnoreDefaultLibraryNames=""
  • code/branches/input/visual_studio/orxonox_vc8.sln

    r1064 r1193  
    5757        EndProjectSection
    5858EndProject
    59 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tolua++", "vc8\tolua++.vcproj", "{35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}"
     59Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tolua", "vc8\tolua.vcproj", "{35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}"
    6060        ProjectSection(WebsiteProperties) = preProject
    6161                Debug.AspNetCompiler.Debug = "True"
     
    102102                {2240ECD7-2F48-4431-8E1B-25466A384CCC}.static_libs_release|Win32.ActiveCfg = Release|Win32
    103103                {F101C2F0-1CB9-4A57-827B-6C399A99B28F}.Debug|Win32.ActiveCfg = Debug|Win32
     104                {F101C2F0-1CB9-4A57-827B-6C399A99B28F}.Debug|Win32.Build.0 = Debug|Win32
    104105                {F101C2F0-1CB9-4A57-827B-6C399A99B28F}.Release|Win32.ActiveCfg = Release|Win32
     106                {F101C2F0-1CB9-4A57-827B-6C399A99B28F}.Release|Win32.Build.0 = Release|Win32
    105107                {F101C2F0-1CB9-4A57-827B-6C399A99B28F}.static_libs_debug|Win32.ActiveCfg = Debug|Win32
    106108                {F101C2F0-1CB9-4A57-827B-6C399A99B28F}.static_libs_debug|Win32.Build.0 = Debug|Win32
     
    108110                {F101C2F0-1CB9-4A57-827B-6C399A99B28F}.static_libs_release|Win32.Build.0 = Release|Win32
    109111                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.Debug|Win32.ActiveCfg = Debug|Win32
     112                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.Debug|Win32.Build.0 = Debug|Win32
    110113                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.Release|Win32.ActiveCfg = Release|Win32
     114                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.Release|Win32.Build.0 = Release|Win32
    111115                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.static_libs_debug|Win32.ActiveCfg = Debug|Win32
    112116                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.static_libs_debug|Win32.Build.0 = Debug|Win32
  • code/branches/input/visual_studio/tolua_properties.vsprops

    r1158 r1193  
    33        ProjectType="Visual C++"
    44        Version="8.00"
    5         Name="tolua++_properties"
     5        Name="tolua_properties"
    66        InheritedPropertySheets=".\directory_properties.vsprops"
    77        >
     8        <Tool
     9                Name="VCCLCompilerTool"
     10                DisableSpecificWarnings="4996"
     11        />
    812</VisualStudioPropertySheet>
  • code/branches/input/visual_studio/vc8/tolua.vcproj

    r1158 r1193  
    33        ProjectType="Visual C++"
    44        Version="8.00"
    5         Name="tolua++"
     5        Name="tolua"
    66        ProjectGUID="{35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}"
    77        RootNamespace="FICN"
     
    1919                        Name="Debug|Win32"
    2020                        ConfigurationType="4"
    21                         InheritedPropertySheets="$(SolutionDir)base_properties_debug.vsprops;..\tolua++_properties.vsprops"
     21                        InheritedPropertySheets="$(SolutionDir)base_properties_debug.vsprops;..\tolua_properties.vsprops"
    2222                        CharacterSet="1"
    2323                        >
     
    7171                        Name="Release|Win32"
    7272                        ConfigurationType="4"
    73                         InheritedPropertySheets="$(SolutionDir)base_properties_release.vsprops;..\tolua++_properties.vsprops"
     73                        InheritedPropertySheets="$(SolutionDir)base_properties_release.vsprops;..\tolua_properties.vsprops"
    7474                        CharacterSet="1"
    7575                        WholeProgramOptimization="1"
Note: See TracChangeset for help on using the changeset viewer.