Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2008, 9:07:08 PM (17 years ago)
Author:
rgrieder
Message:
  • merged input branch back to trunk
File:
1 edited

Legend:

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

    r1293 r1349  
    9898      windowHndStr << (unsigned int)windowHnd;
    9999      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    100 
     100      //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
     101      //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
    101102//#if defined OIS_LINUX_PLATFORM
    102103//      paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
     
    126127
    127128      // Set mouse/joystick region
    128       setWindowExtents(windowWidth, windowHeight);
     129      if (mouse_)
     130      {
     131        //// hack the mouse position
     132        //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2;
     133        //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2;
     134        setWindowExtents(windowWidth, windowHeight);
     135      }
    129136
    130137      state_ = IS_NONE;
     
    267274    activeJoyStickHandlers_.resize(joySticksSize_);
    268275    joyStickButtonsDown_.resize(joySticksSize_);
     276    povStates_.resize(joySticksSize_);
     277    sliderStates_.resize(joySticksSize_);
    269278    return success;
    270279  }
     
    350359  }
    351360
     361  void InputManager::_updateTickables()
     362  {
     363    // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
     364    std::set<InputTickable*> tempSet;
     365    for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
     366      tempSet.insert(activeKeyHandlers_[iHandler]);
     367    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
     368      tempSet.insert(activeMouseHandlers_[iHandler]);
     369    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
     370      for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     371        tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]);
     372
     373    // copy the content of the set back to the actual vector
     374    activeHandlers_.clear();
     375    for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++)
     376      activeHandlers_.push_back(*itHandler);
     377  }
     378
    352379
    353380  // #################################
     
    380407          // normal play mode
    381408          // note: we assume that the handlers exist since otherwise, something's wrong anyway.
    382           activeKeyHandlers_.push_back(keyHandlers_["keybinder"]);
    383           activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    384           if (getMouseHandler("SpaceShip"))
    385             activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
    386           for (unsigned int i = 0; i < joySticksSize_; i++)
    387             activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
     409          enableKeyHandler("keybinder");
     410          enableMouseHandler("keybinder");
     411          enableMouseHandler("SpaceShip");
     412          enableJoyStickHandler("keybinder", 0);
    388413          break;
    389414
    390415        case IS_GUI:
    391           // FIXME: do stuff
     416          // TODO: do stuff
    392417          break;
    393418
    394419        case IS_CONSOLE:
    395           activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    396           if (getMouseHandler("SpaceShip"))
    397             activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
    398           for (unsigned int i = 0; i < joySticksSize_; i++)
    399             activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
    400 
    401           activeKeyHandlers_.push_back(keyHandlers_["buffer"]);
     420          enableMouseHandler("keybinder");
     421          enableMouseHandler("SpaceShip");
     422          enableJoyStickHandler("keybinder", 0);
     423          enableKeyHandler("buffer");
    402424          break;
    403425
     
    426448    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    427449      for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    428         activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]);
     450        activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    429451
    430452    // call all the handlers for the held joy stick button events
     
    432454      for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    433455        for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    434           activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(
    435               JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]);
     456          activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     457
     458
     459    // call the ticks
     460    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
     461      activeHandlers_[iHandler]->tick(dt);
    436462  }
    437463
     
    508534    {
    509535      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    510         activeMouseHandlers_[i]->mouseMoved(e.state);
     536        activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs),
     537            IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height));
    511538    }
    512539
     
    515542    {
    516543      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    517         activeMouseHandlers_[i]->mouseScrolled(e.state);
     544        activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    518545    }
    519546
     
    536563
    537564    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    538       activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id);
     565      activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id);
    539566
    540567    return true;
     
    559586
    560587    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    561       activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id);
     588      activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id);
    562589
    563590    return true;
     
    584611
    585612    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    586       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button);
     613      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button);
    587614
    588615    return true;
     
    609636
    610637    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    611       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button);
     638      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button);
    612639
    613640    return true;
     
    616643  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    617644  {
     645    //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl;
    618646    // use the device to identify which one called the method
    619647    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     
    622650      iJoyStick++;
    623651
     652    // keep in mind that the first 8 axes are reserved for the sliders
    624653    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    625       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis);
     654      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
    626655
    627656    return true;
     
    630659  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    631660  {
     661    //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;
    632662    // use the device to identify which one called the method
    633663    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     
    636666      iJoyStick++;
    637667
    638     for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    639       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id);
     668    if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX)
     669    {
     670      // slider X axis changed
     671      sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX;
     672      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     673        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX);
     674    }
     675    else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY)
     676    {
     677      // slider Y axis changed
     678      sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY;
     679      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     680        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
     681    }
    640682
    641683    return true;
     
    650692      iJoyStick++;
    651693
    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)
     694    // translate the POV into 8 simple buttons
     695    int lastState = povStates_[iJoyStick][id];
     696    if (lastState & OIS::Pov::North)
     697      buttonReleased(arg, 32 + id * 4 + 0);
     698    if (lastState & OIS::Pov::South)
     699      buttonReleased(arg, 32 + id * 4 + 1);
     700    if (lastState & OIS::Pov::East)
     701      buttonReleased(arg, 32 + id * 4 + 2);
     702    if (lastState & OIS::Pov::West)
     703      buttonReleased(arg, 32 + id * 4 + 3);
     704   
     705    povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction;
     706    int currentState = povStates_[iJoyStick][id];
     707    if (currentState & OIS::Pov::North)
     708      buttonPressed(arg, 32 + id * 4 + 0);
     709    if (currentState & OIS::Pov::South)
     710      buttonPressed(arg, 32 + id * 4 + 1);
     711    if (currentState & OIS::Pov::East)
     712      buttonPressed(arg, 32 + id * 4 + 2);
     713    if (currentState & OIS::Pov::West)
     714      buttonPressed(arg, 32 + id * 4 + 3);
     715
     716    return true;
     717  }
     718
     719  /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
    659720  {
    660721    // use the device to identify which one called the method
     
    668729
    669730    return true;
    670   }
     731  }*/
    671732
    672733
     
    735796  }
    736797
    737   const MouseState InputManager::getMouseState()
     798  /*const MouseState InputManager::getMouseState()
    738799  {
    739800    if (_getSingleton().mouse_)
     
    741802    else
    742803      return MouseState();
    743   }
    744 
    745   const JoyStickState InputManager::getJoyStickState(unsigned int ID)
     804  }*/
     805
     806  /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)
    746807  {
    747808    if (ID < _getSingleton().joySticksSize_)
     
    749810    else
    750811      return JoyStickState();
    751   }
     812  }*/
    752813
    753814
     
    882943      if ((*it) == (*mapIt).second)
    883944      {
    884         _getSingleton().stateRequest_ = IS_CUSTOM;
    885945        return true;
    886946      }
     
    888948    _getSingleton().activeKeyHandlers_.push_back((*mapIt).second);
    889949    _getSingleton().stateRequest_ = IS_CUSTOM;
     950    _getSingleton()._updateTickables();
    890951    return true;
    891952  }
     
    910971        _getSingleton().activeKeyHandlers_.erase(it);
    911972        _getSingleton().stateRequest_ = IS_CUSTOM;
     973        _getSingleton()._updateTickables();
    912974        return true;
    913975      }
    914976    }
    915     _getSingleton().stateRequest_ = IS_CUSTOM;
    916977    return true;
    917978  }
     
    10101071      if ((*it) == (*mapIt).second)
    10111072      {
    1012         _getSingleton().stateRequest_ = IS_CUSTOM;
    10131073        return true;
    10141074      }
     
    10161076    _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);
    10171077    _getSingleton().stateRequest_ = IS_CUSTOM;
     1078    _getSingleton()._updateTickables();
    10181079    return true;
    10191080  }
     
    10381099        _getSingleton().activeMouseHandlers_.erase(it);
    10391100        _getSingleton().stateRequest_ = IS_CUSTOM;
     1101        _getSingleton()._updateTickables();
    10401102        return true;
    10411103      }
    10421104    }
    1043     _getSingleton().stateRequest_ = IS_CUSTOM;
    10441105    return true;
    10451106  }
     
    11471208      if ((*it) == (*handlerIt).second)
    11481209      {
    1149         _getSingleton().stateRequest_ = IS_CUSTOM;
    11501210        return true;
    11511211      }
     
    11531213    _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);
    11541214    _getSingleton().stateRequest_ = IS_CUSTOM;
     1215    _getSingleton()._updateTickables();
    11551216    return true;
    11561217  }
     
    11801241        _getSingleton().activeJoyStickHandlers_[ID].erase(it);
    11811242        _getSingleton().stateRequest_ = IS_CUSTOM;
     1243        _getSingleton()._updateTickables();
    11821244        return true;
    11831245      }
Note: See TracChangeset for help on using the changeset viewer.