Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 19, 2008, 10:50:09 AM (16 years ago)
Author:
rgrieder
Message:

Basically, almost everything about the input management is written, but I wasn't yet able to test things.

File:
1 edited

Legend:

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

    r1293 r1323  
    267267    activeJoyStickHandlers_.resize(joySticksSize_);
    268268    joyStickButtonsDown_.resize(joySticksSize_);
     269    povStates_.resize(joySticksSize_);
     270    sliderStates_.resize(joySticksSize_);
    269271    return success;
    270272  }
     
    348350    }
    349351    CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
     352  }
     353
     354  void InputManager::_updateTickables()
     355  {
     356    // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
     357    std::set<InputTickable*> tempSet;
     358    for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
     359      tempSet.insert(activeKeyHandlers_[iHandler]);
     360    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
     361      tempSet.insert(activeMouseHandlers_[iHandler]);
     362    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
     363      for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     364        tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]);
     365
     366    // copy the content of the set back to the actual vector
     367    activeHandlers_.clear();
     368    for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++)
     369      activeHandlers_.push_back(*itHandler);
    350370  }
    351371
     
    389409
    390410        case IS_GUI:
    391           // FIXME: do stuff
     411          // TODO: do stuff
    392412          break;
    393413
     
    426446    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    427447      for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    428         activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]);
     448        activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    429449
    430450    // call all the handlers for the held joy stick button events
     
    432452      for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    433453        for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    434           activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(
    435               JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]);
     454          activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     455
     456
     457    // call the ticks
     458    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
     459      activeHandlers_[iHandler]->tick(dt);
    436460  }
    437461
     
    508532    {
    509533      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    510         activeMouseHandlers_[i]->mouseMoved(e.state);
     534        activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs),
     535            IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height));
    511536    }
    512537
     
    515540    {
    516541      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    517         activeMouseHandlers_[i]->mouseScrolled(e.state);
     542        activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    518543    }
    519544
     
    536561
    537562    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    538       activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id);
     563      activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id);
    539564
    540565    return true;
     
    559584
    560585    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    561       activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id);
     586      activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id);
    562587
    563588    return true;
     
    584609
    585610    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    586       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button);
     611      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button);
    587612
    588613    return true;
     
    609634
    610635    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    611       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button);
     636      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button);
    612637
    613638    return true;
     
    616641  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    617642  {
     643    //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl;
    618644    // use the device to identify which one called the method
    619645    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     
    622648      iJoyStick++;
    623649
     650    // keep in mind that the first 8 axes are reserved for the sliders
    624651    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    625       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis);
     652      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
    626653
    627654    return true;
     
    630657  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    631658  {
     659    //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;
    632660    // use the device to identify which one called the method
    633661    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     
    636664      iJoyStick++;
    637665
    638     for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    639       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id);
     666    if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX)
     667    {
     668      // slider X axis changed
     669      sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX;
     670      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     671        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX);
     672    }
     673    else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY)
     674    {
     675      // slider Y axis changed
     676      sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY;
     677      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     678        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
     679    }
    640680
    641681    return true;
     
    650690      iJoyStick++;
    651691
    652     for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    653       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id);
    654 
    655     return true;
    656   }
    657 
    658   bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
     692    // translate the POV into 8 simple buttons
     693    int lastState = povStates_[iJoyStick][id];
     694    if (lastState & OIS::Pov::North)
     695      buttonReleased(arg, 32 + id * 4 + 0);
     696    if (lastState & OIS::Pov::South)
     697      buttonReleased(arg, 32 + id * 4 + 1);
     698    if (lastState & OIS::Pov::East)
     699      buttonReleased(arg, 32 + id * 4 + 2);
     700    if (lastState & OIS::Pov::West)
     701      buttonReleased(arg, 32 + id * 4 + 3);
     702   
     703    povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction;
     704    int currentState = povStates_[iJoyStick][id];
     705    if (currentState & OIS::Pov::North)
     706      buttonPressed(arg, 32 + id * 4 + 0);
     707    if (currentState & OIS::Pov::South)
     708      buttonPressed(arg, 32 + id * 4 + 1);
     709    if (currentState & OIS::Pov::East)
     710      buttonPressed(arg, 32 + id * 4 + 2);
     711    if (currentState & OIS::Pov::West)
     712      buttonPressed(arg, 32 + id * 4 + 3);
     713
     714    return true;
     715  }
     716
     717  /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
    659718  {
    660719    // use the device to identify which one called the method
     
    668727
    669728    return true;
    670   }
     729  }*/
    671730
    672731
     
    735794  }
    736795
    737   const MouseState InputManager::getMouseState()
     796  /*const MouseState InputManager::getMouseState()
    738797  {
    739798    if (_getSingleton().mouse_)
     
    741800    else
    742801      return MouseState();
    743   }
    744 
    745   const JoyStickState InputManager::getJoyStickState(unsigned int ID)
     802  }*/
     803
     804  /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)
    746805  {
    747806    if (ID < _getSingleton().joySticksSize_)
     
    749808    else
    750809      return JoyStickState();
    751   }
     810  }*/
    752811
    753812
     
    882941      if ((*it) == (*mapIt).second)
    883942      {
    884         _getSingleton().stateRequest_ = IS_CUSTOM;
    885943        return true;
    886944      }
     
    888946    _getSingleton().activeKeyHandlers_.push_back((*mapIt).second);
    889947    _getSingleton().stateRequest_ = IS_CUSTOM;
     948    _getSingleton()._updateTickables();
    890949    return true;
    891950  }
     
    910969        _getSingleton().activeKeyHandlers_.erase(it);
    911970        _getSingleton().stateRequest_ = IS_CUSTOM;
     971        _getSingleton()._updateTickables();
    912972        return true;
    913973      }
    914974    }
    915     _getSingleton().stateRequest_ = IS_CUSTOM;
    916975    return true;
    917976  }
     
    10101069      if ((*it) == (*mapIt).second)
    10111070      {
    1012         _getSingleton().stateRequest_ = IS_CUSTOM;
    10131071        return true;
    10141072      }
     
    10161074    _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);
    10171075    _getSingleton().stateRequest_ = IS_CUSTOM;
     1076    _getSingleton()._updateTickables();
    10181077    return true;
    10191078  }
     
    10381097        _getSingleton().activeMouseHandlers_.erase(it);
    10391098        _getSingleton().stateRequest_ = IS_CUSTOM;
     1099        _getSingleton()._updateTickables();
    10401100        return true;
    10411101      }
    10421102    }
    1043     _getSingleton().stateRequest_ = IS_CUSTOM;
    10441103    return true;
    10451104  }
     
    11471206      if ((*it) == (*handlerIt).second)
    11481207      {
    1149         _getSingleton().stateRequest_ = IS_CUSTOM;
    11501208        return true;
    11511209      }
     
    11531211    _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);
    11541212    _getSingleton().stateRequest_ = IS_CUSTOM;
     1213    _getSingleton()._updateTickables();
    11551214    return true;
    11561215  }
     
    11801239        _getSingleton().activeJoyStickHandlers_[ID].erase(it);
    11811240        _getSingleton().stateRequest_ = IS_CUSTOM;
     1241        _getSingleton()._updateTickables();
    11821242        return true;
    11831243      }
Note: See TracChangeset for help on using the changeset viewer.