Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 12, 2009, 4:12:04 PM (15 years ago)
Author:
rgrieder
Message:

Added a few more generic parts to the input library:

  • Created Mouse and Keyboard to join JoyStick and provided them with a templated base class (InputDeviceTemplated) that does most of the work (reduces quite some redundancy)
  • Created InputPrereqs.h from InputInterfaces.h and destroyed the latter
  • Exported InputHandler to its own file and replaced KeyHandler, MouseHandler and JoyStickHandler with the single InputHandler.
  • Deleted the SimpleInputState: There is only one class now which fulfills all our needs.

In general there is now less code and the code itself has more 'pluses'. However I haven't really thrown away any feature at all.

File:
1 edited

Legend:

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

    r3272 r3274  
    5050#include "core/ConsoleCommand.h"
    5151#include "core/CommandLine.h"
     52#include "core/Functor.h"
    5253
    5354#include "InputBuffer.h"
    5455#include "KeyDetector.h"
     56#include "InputHandler.h"
    5557#include "InputState.h"
    56 #include "SimpleInputState.h"
    57 #include "JoyStickDeviceNumberListener.h"
     58#include "JoyStickQuantityListener.h"
    5859#include "JoyStick.h"
     60#include "Mouse.h"
     61#include "Keyboard.h"
    5962
    6063// HACK (include this as last, X11 seems to define some macros...)
     
    7376    SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard");
    7477
    75     EmptyHandler InputManager::EMPTY_HANDLER;
     78    InputHandler InputHandler::EMPTY;
    7679    InputManager* InputManager::singletonRef_s = 0;
    77 
    78     using namespace InputDevice;
    7980
    8081    /**
     
    109110    InputManager::InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight)
    110111        : inputSystem_(0)
    111         , keyboard_(0)
    112         , mouse_(0)
    113         , devicesNum_(0)
     112        , devices_(2)
    114113        , windowHnd_(0)
    115114        , internalState_(Uninitialised)
     
    117116        , keyDetector_(0)
    118117        , calibratorCallbackBuffer_(0)
    119         , keyboardModifiers_(0)
    120118    {
    121119        RegisterRootObject(InputManager);
     
    182180#endif
    183181
     182            // TODO: clean this up
    184183            try
    185184            {
     
    199198            }
    200199
     200            // TODO: Remove the two parameters
    201201            _initialiseMouse(windowWidth, windowHeight);
    202202
     
    220220
    221221            // Lowest priority empty InputState
    222             stateEmpty_ = createInputState<SimpleInputState>("empty", false, false, InputStatePriority::Empty);
    223             stateEmpty_->setHandler(&EMPTY_HANDLER);
     222            stateEmpty_ = createInputState("empty", false, false, InputStatePriority::Empty);
     223            stateEmpty_->setHandler(&InputHandler::EMPTY);
    224224            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
    225225
    226226            // KeyDetector to evaluate a pressed key's name
    227             SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector);
     227            InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector);
     228            FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers);
     229            bufferFunctor->setObject(this);
     230            detector->setLeaveFunctor(bufferFunctor);
    228231            keyDetector_ = new KeyDetector();
    229232            detector->setHandler(keyDetector_);
    230233
    231234            // Joy stick calibration helper callback
    232             SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator);
    233             calibrator->setHandler(&EMPTY_HANDLER);
     235            InputState* calibrator = createInputState("calibrator", false, false, InputStatePriority::Calibrator);
     236            calibrator->setHandler(&InputHandler::EMPTY);
    234237            calibratorCallbackBuffer_ = new InputBuffer();
    235             calibratorCallbackBuffer_->registerListener(this, &InputManager::_completeCalibration, '\r', true);
     238            calibratorCallbackBuffer_->registerListener(this, &InputManager::_stopCalibration, '\r', true);
    236239            calibrator->setKeyHandler(calibratorCallbackBuffer_);
    237240
     
    246249    }
    247250
    248     /**
    249     @brief
    250         Creates a keyboard and sets the event handler.
    251     @return
    252         False if keyboard stays uninitialised, true otherwise.
    253     */
    254251    void InputManager::_initialiseKeyboard()
    255252    {
    256         if (keyboard_ != 0)
    257         {
    258             CCOUT(2) << "Warning: Keyboard already initialised, skipping." << std::endl;
    259             return;
    260         }
     253        assert(devices_[InputDeviceEnumerator::Keyboard] == 0);
    261254        if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)
    262         {
    263             keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true);
    264             // register our listener in OIS.
    265             keyboard_->setEventCallback(this);
    266             // note: OIS will not detect keys that have already been down when the keyboard was created.
    267             CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
    268         }
     255            devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard);
    269256        else
    270         {
    271257            ThrowException(InitialisationFailed, "InputManager: No keyboard found, cannot proceed!");
    272         }
    273     }
    274 
    275     /**
    276     @brief
    277         Creates a mouse and sets the event handler.
    278     @return
    279         False if mouse stays uninitialised, true otherwise.
    280     */
     258    }
     259
    281260    void InputManager::_initialiseMouse(unsigned int windowWidth, unsigned int windowHeight)
    282261    {
    283         if (mouse_ != 0)
    284         {
    285             CCOUT(2) << "Warning: Mouse already initialised, skipping." << std::endl;
    286             return;
    287         }
    288         try
    289         {
    290             if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
    291             {
    292                 mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
    293                 // register our listener in OIS.
    294                 mouse_->setEventCallback(this);
    295                 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl;
    296 
    297                 // Set mouse region
    298                 setWindowExtents(windowWidth, windowHeight);
    299             }
    300             else
    301             {
    302                 CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
    303             }
    304         }
    305         catch (OIS::Exception ex)
    306         {
    307             CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n"
    308                 << "OIS error message: \"" << ex.eText << "\"\n Proceeding without mouse support." << std::endl;
    309             mouse_ = 0;
    310         }
     262        assert(devices_[InputDeviceEnumerator::Mouse] == 0);
     263        if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
     264        {
     265            try
     266            {
     267                devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, windowWidth, windowHeight);
     268            }
     269            catch (const OIS::Exception& ex)
     270            {
     271                CCOUT(2) << "Warning: Failed to create Mouse:" << ex.eText << std::endl
     272                         << "Proceeding without mouse support." << std::endl;
     273            }
     274        }
     275        else
     276            CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
    311277    }
    312278
     
    319285    void InputManager::_initialiseJoySticks()
    320286    {
    321         if (!this->joySticks_.empty())
    322         {
    323             CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl;
    324             return;
    325         }
    326 
    327         devicesNum_ = 2 + inputSystem_->getNumberOfDevices(OIS::OISJoyStick);
    328         // state management
    329         activeStatesTriggered_.resize(devicesNum_);
     287        assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
    330288
    331289        for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++)
     
    333291            try
    334292            {
    335                 joySticks_.push_back(new JoyStick(activeStatesTriggered_[2 + i], i));
     293                devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i));
    336294            }
    337295            catch (std::exception ex)
     
    342300
    343301        // inform all JoyStick Device Number Listeners
    344         for (ObjectList<JoyStickDeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it)
    345             it->JoyStickDeviceNumberChanged(joySticks_.size());
     302        for (ObjectList<JoyStickQuantityListener>::iterator it = ObjectList<JoyStickQuantityListener>::begin(); it; ++it)
     303            it->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick);
    346304    }
    347305
    348306    void InputManager::_startCalibration()
    349307    {
    350         BOOST_FOREACH(JoyStick* stick, joySticks_)
    351             stick->startCalibration();
     308        BOOST_FOREACH(InputDevice* device, devices_)
     309            device->startCalibration();
    352310
    353311        getInstance().internalState_ |= Calibrating;
     
    355313    }
    356314
    357     void InputManager::_completeCalibration()
    358     {
    359         BOOST_FOREACH(JoyStick* stick, joySticks_)
    360             stick->stopCalibration();
     315    void InputManager::_stopCalibration()
     316    {
     317        BOOST_FOREACH(InputDevice* device, devices_)
     318            device->stopCalibration();
    361319
    362320        // restore old input state
    363321        requestLeaveState("calibrator");
    364322        internalState_ &= ~Calibrating;
     323        // Clear buffers to prevent button hold events
     324        this->clearBuffers();
    365325    }
    366326
     
    374334        Destroys all the created input devices and states.
    375335    */
     336    // TODO: export this to be used with reload()
    376337    InputManager::~InputManager()
    377338    {
     
    379340        {
    380341            CCOUT(3) << "Destroying ..." << std::endl;
    381 
    382             // kick all active states 'nicely'
    383             for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
    384                 rit != activeStates_.rend(); ++rit)
    385             {
    386                 (*rit).second->onLeave();
    387             }
    388342
    389343            // Destroy calibrator helper handler and state
     
    401355
    402356            // destroy the devices
    403             _destroyKeyboard();
    404             _destroyMouse();
    405             _destroyJoySticks();
     357            BOOST_FOREACH(InputDevice*& device, devices_)
     358            {
     359                std::string className = device->getClassName();
     360                try
     361                {
     362                    if (device)
     363                        delete device;
     364                    device = 0;
     365                    CCOUT(4) << className << " destroyed." << std::endl;
     366                }
     367                catch (...)
     368                {
     369                    CCOUT(1) << className << " destruction failed! Potential resource leak!" << std::endl;
     370                }
     371            }
     372            devices_.resize(InputDeviceEnumerator::FirstJoyStick);
    406373
    407374            try
     
    416383
    417384        singletonRef_s = 0;
    418     }
    419 
    420     /**
    421     @brief
    422         Destroys the keyboard and sets it to 0.
    423     */
    424     void InputManager::_destroyKeyboard()
    425     {
    426         assert(inputSystem_);
    427         try
    428         {
    429             if (keyboard_)
    430                 inputSystem_->destroyInputObject(keyboard_);
    431             keyboard_ = 0;
    432             CCOUT(4) << "Keyboard destroyed." << std::endl;
    433         }
    434         catch (...)
    435         {
    436             CCOUT(1) << "Keyboard destruction failed! Potential resource leak!" << std::endl;
    437         }
    438     }
    439 
    440     /**
    441     @brief
    442         Destroys the mouse and sets it to 0.
    443     */
    444     void InputManager::_destroyMouse()
    445     {
    446         assert(inputSystem_);
    447         try
    448         {
    449             if (mouse_)
    450                 inputSystem_->destroyInputObject(mouse_);
    451             mouse_ = 0;
    452             CCOUT(4) << "Mouse destroyed." << std::endl;
    453         }
    454         catch (...)
    455         {
    456             CCOUT(1) << "Mouse destruction failed! Potential resource leak!" << std::endl;
    457         }
    458     }
    459 
    460     /**
    461     @brief
    462         Destroys all the joy sticks and resizes the lists to 0.
    463     */
    464     void InputManager::_destroyJoySticks()
    465     {
    466         assert(inputSystem_);
    467         while (!joySticks_.empty())
    468         {
    469             try
    470             {
    471                 delete joySticks_.back();
    472             }
    473             catch (...)
    474             {
    475                 CCOUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl;
    476             }
    477             joySticks_.pop_back();
    478             devicesNum_ = 2;
    479         }
    480         CCOUT(4) << "Joy sticks destroyed." << std::endl;
    481385    }
    482386
     
    539443
    540444            // Save mouse clipping size
    541             int mouseWidth  = mouse_->getMouseState().width;
    542             int mouseHeight = mouse_->getMouseState().height;
     445            int mouseWidth  = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingWidth();
     446            int mouseHeight = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingHeight();
    543447
    544448            internalState_ &= ~OISReady;
    545449
    546450            // destroy the devices
    547             _destroyKeyboard();
    548             _destroyMouse();
    549             _destroyJoySticks();
     451            // destroy the devices
     452            BOOST_FOREACH(InputDevice*& device, devices_)
     453            {
     454                try
     455                {
     456                    if (device)
     457                        delete device;
     458                    device = 0;
     459                    CCOUT(4) << device->getClassName() << " destroyed." << std::endl;
     460                }
     461                catch (...)
     462                {
     463                    CCOUT(1) << device->getClassName() << " destruction failed! Potential resource leak!" << std::endl;
     464                }
     465            }
     466            devices_.resize(InputDeviceEnumerator::FirstJoyStick);
    550467
    551468            OIS::InputManager::destroyInputSystem(inputSystem_);
     
    592509                it != stateLeaveRequests_.end(); ++it)
    593510            {
    594                 (*it)->onLeave();
     511                (*it)->left();
    595512                // just to be sure that the state actually is registered
    596513                assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     
    631548                activeStates_[(*it)->getPriority()] = (*it);
    632549                _updateActiveStates();
    633                 (*it)->onEnter();
     550                (*it)->entered();
    634551            }
    635552            stateEnterRequests_.clear();
     
    647564        }
    648565
    649         // check whether a state has changed its EMPTY_HANDLER situation
     566        // check whether a state has changed its EMPTY situation
    650567        bool bUpdateRequired = false;
    651568        for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
    652569        {
    653             if (it->second->handlersChanged())
    654             {
    655                 it->second->resetHandlersChanged();
     570            if (it->second->hasExpired())
     571            {
     572                it->second->resetExpiration();
    656573                bUpdateRequired = true;
    657574            }
     
    664581
    665582        // Capture all the input. This calls the event handlers in InputManager.
    666         if (keyboard_)
    667             keyboard_->capture();
    668         if (mouse_)
    669             mouse_->capture();
    670         BOOST_FOREACH(JoyStick* stick, joySticks_)
    671             stick->capture();
     583        BOOST_FOREACH(InputDevice* device, devices_)
     584            device->update(time);
    672585
    673586        if (!(internalState_ & Calibrating))
    674587        {
    675             // call all the handlers for the held key events
    676             for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    677             {
    678                 KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_);
    679 
    680                 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
    681                     activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt);
    682             }
    683 
    684             // call all the handlers for the held mouse button events
    685             for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    686             {
    687                 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    688                     activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    689             }
    690 
    691             // update the handlers for each active handler
    692             for (unsigned int i = 0; i < devicesNum_; ++i)
    693             {
    694                 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
    695                     activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i);
    696             }
    697 
    698             // update the handler with a general tick afterwards
     588            // update the states with a general tick afterwards
    699589            for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
    700                 activeStatesTicked_[i]->updateInput(time.getDeltaTime());
     590                activeStatesTicked_[i]->update(time.getDeltaTime());
    701591        }
    702592
     
    711601    void InputManager::_updateActiveStates()
    712602    {
    713         for (unsigned int i = 0; i < devicesNum_; ++i)
    714         {
     603        // temporary resize
     604        for (unsigned int i = 0; i < devices_.size(); ++i)
     605        {
     606            std::vector<InputState*>& states = devices_[i]->getStateListRef();
    715607            bool occupied = false;
    716             activeStatesTriggered_[i].clear();
    717             for (std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
     608            states.clear();
     609            for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
    718610            {
    719611                if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_))
    720612                {
    721                     activeStatesTriggered_[i].push_back(rit->second);
     613                    states.push_back(rit->second);
    722614                    if (!rit->second->bTransparent_)
    723615                        occupied = true;
     
    729621        // Using a std::set to avoid duplicates
    730622        std::set<InputState*> tempSet;
    731         for (unsigned int i = 0; i < devicesNum_; ++i)
    732             for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
    733                 tempSet.insert(activeStatesTriggered_[i][iState]);
     623        for (unsigned int i = 0; i < devices_.size(); ++i)
     624            for (unsigned int iState = 0; iState < devices_[i]->getStateListRef().size(); ++iState)
     625                tempSet.insert(devices_[i]->getStateListRef()[iState]);
    734626
    735627        // copy the content of the std::set back to the actual vector
     
    737629        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
    738630            activeStatesTicked_.push_back(*it);
    739 
    740         this->mouseButtonsDown_.clear();
    741631    }
    742632
     
    747637    void InputManager::clearBuffers()
    748638    {
    749         keysDown_.clear();
    750         keyboardModifiers_ = 0;
    751         mouseButtonsDown_.clear();
    752         BOOST_FOREACH(JoyStick* stick, joySticks_)
    753             stick->clearBuffer();
    754     }
    755 
    756 
    757     // ############################################################
    758     // #####                    OIS events                    #####
    759     // ##########                                        ##########
    760     // ############################################################
    761 
    762     // ###### Key Events ######
    763 
    764     /**
    765     @brief
    766         Event handler for the keyPressed Event.
    767     @param e
    768         Event information
    769     */
    770     bool InputManager::keyPressed(const OIS::KeyEvent &e)
    771     {
    772         // check whether the key already is in the list (can happen when focus was lost)
    773         unsigned int iKey = 0;
    774         while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::ByEnum)e.key)
    775             iKey++;
    776         if (iKey == keysDown_.size())
    777             keysDown_.push_back(Key(e));
    778         else
    779         {
    780             // This happens when XAutoRepeat is set under linux. The KeyPressed event gets then sent
    781             // continuously.
    782             return true;
    783         }
    784 
    785         // update modifiers
    786         if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
    787             keyboardModifiers_ |= KeyboardModifier::Alt;   // alt key
    788         if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
    789             keyboardModifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
    790         if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
    791             keyboardModifiers_ |= KeyboardModifier::Shift; // shift key
    792 
    793         KeyEvent kEvt(e, keyboardModifiers_);
    794         for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
    795             activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt);
    796 
    797         return true;
    798     }
    799 
    800     /**
    801     @brief
    802         Event handler for the keyReleased Event.
    803     @param e
    804         Event information
    805     */
    806     bool InputManager::keyReleased(const OIS::KeyEvent &e)
    807     {
    808         // remove the key from the keysDown_ list
    809         for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    810         {
    811             if (keysDown_[iKey].key == (KeyCode::ByEnum)e.key)
    812             {
    813                 keysDown_.erase(keysDown_.begin() + iKey);
    814                 break;
    815             }
    816         }
    817 
    818         // update modifiers
    819         if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
    820             keyboardModifiers_ &= ~KeyboardModifier::Alt;   // alt key
    821         if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
    822             keyboardModifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
    823         if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
    824             keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key
    825 
    826         KeyEvent kEvt(e, keyboardModifiers_);
    827         for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
    828             activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt);
    829 
    830         return true;
    831     }
    832 
    833 
    834     // ###### Mouse Events ######
    835 
    836     /**
    837     @brief
    838         Event handler for the mouseMoved Event.
    839     @param e
    840         Event information
    841     */
    842     bool InputManager::mouseMoved(const OIS::MouseEvent &e)
    843     {
    844         // check for actual moved event
    845         if (e.state.X.rel != 0 || e.state.Y.rel != 0)
    846         {
    847             IntVector2 abs(e.state.X.abs, e.state.Y.abs);
    848             IntVector2 rel(e.state.X.rel, e.state.Y.rel);
    849             IntVector2 clippingSize(e.state.width, e.state.height);
    850             for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    851                 activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize);
    852         }
    853 
    854         // check for mouse scrolled event
    855         if (e.state.Z.rel != 0)
    856         {
    857             for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    858                 activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    859         }
    860 
    861         return true;
    862     }
    863 
    864     /**
    865     @brief
    866         Event handler for the mousePressed Event.
    867     @param e
    868         Event information
    869     @param id
    870         The ID of the mouse button
    871     */
    872     bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    873     {
    874         // check whether the button already is in the list (can happen when focus was lost)
    875         unsigned int iButton = 0;
    876         while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButtonCode::ByEnum)id)
    877             iButton++;
    878         if (iButton == mouseButtonsDown_.size())
    879             mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id);
    880 
    881         for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    882             activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    883 
    884         return true;
    885     }
    886 
    887     /**
    888     @brief
    889         Event handler for the mouseReleased Event.
    890     @param e
    891         Event information
    892     @param id
    893         The ID of the mouse button
    894     */
    895     bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    896     {
    897         // remove the button from the keysDown_ list
    898         for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    899         {
    900             if (mouseButtonsDown_[iButton] == (MouseButtonCode::ByEnum)id)
    901             {
    902                 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton);
    903                 break;
    904             }
    905         }
    906 
    907         for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
    908             activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    909 
    910         return true;
     639        BOOST_FOREACH(InputDevice* device, devices_)
     640            device->clearBuffers();
    911641    }
    912642
     
    923653        Returns true if ID is ok (unique), false otherwise.
    924654    */
    925     bool InputManager::checkJoyStickID(const std::string& idString)
    926     {
    927         BOOST_FOREACH(JoyStick* stick, joySticks_)
    928         {
    929             if (stick->getIDString() == idString)
     655    bool InputManager::checkJoyStickID(const std::string& idString) const
     656    {
     657        for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i)
     658            if (static_cast<JoyStick*>(devices_[i])->getIDString() == idString)
    930659                return false;
    931         }
    932660        return true;
    933661    }
     
    938666    // ##########                                        ##########
    939667    // ############################################################
    940 
    941     /**
    942     @brief
    943         Adjusts the mouse window metrics.
    944         This method has to be called every time the size of the window changes.
    945     @param width
    946         The new width of the render window
    947     @param^height
    948         The new height of the render window
    949     */
    950     void InputManager::setWindowExtents(const int width, const int height)
    951     {
    952         if (mouse_)
    953         {
    954             // Set mouse region (if window resizes, we should alter this to reflect as well)
    955             mouse_->getMouseState().width  = width;
    956             mouse_->getMouseState().height = height;
    957         }
    958     }
    959668
    960669    /**
     
    970679
    971680    // ###### InputStates ######
     681
     682    /**
     683    @brief
     684        Creates a new InputState by type, name and priority.
     685       
     686        You will have to use this method because the
     687        c'tors and d'tors are private.
     688    @remarks
     689        The InputManager will take care of the state completely. That also
     690        means it gets deleted when the InputManager is destroyed!
     691    @param name
     692        Name of the InputState when referenced as string
     693    @param priority
     694        Priority matters when multiple states are active. You can specify any
     695        number, but 1 - 99 is preferred (99 means high).
     696    */
     697    InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
     698    {
     699        InputState* state = new InputState;
     700        if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))
     701            return state;
     702        else
     703        {
     704            delete state;
     705            return 0;
     706        }
     707    }
    972708
    973709    /**
     
    1008744            }
    1009745            inputStatesByName_[name] = state;
    1010             state->JoyStickDeviceNumberChanged(numberOfJoySticks());
     746            state->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick);
    1011747            state->setName(name);
    1012748            state->bAlwaysGetsInput_ = bAlwaysGetsInput;
Note: See TracChangeset for help on using the changeset viewer.