Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2008, 8:12:20 PM (16 years ago)
Author:
rgrieder
Message:
  • renamed InputHandler to KeyBinder
  • added feature to detect a key in input part
  • added def_keybindings.ini and removed keybindings.ini
File:
1 edited

Legend:

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

    r1398 r1413  
    3737#include "Debug.h"
    3838#include "InputBuffer.h"
    39 #include "InputHandler.h"
     39#include "KeyBinder.h"
    4040
    4141namespace orxonox
     
    5252  InputManager::InputManager() :
    5353      inputSystem_(0), keyboard_(0), mouse_(0),
     54      keyBinder_(0), buffer_(0),
    5455      joySticksSize_(0),
    5556      state_(IS_UNINIT), stateRequest_(IS_UNINIT),
     
    144145
    145146    // InputManager holds the input buffer --> create one and add it.
    146     addKeyHandler(new InputBuffer(), "buffer");
    147 
    148     KeyBinder* binder = new KeyBinder();
    149     binder->loadBindings();
    150     addKeyHandler(binder, "keybinder");
    151     addMouseHandler(binder, "keybinder");
    152     addJoyStickHandler(binder, "keybinder");
    153 
    154     // Read all the key bindings and assign them
    155     //if (!_loadBindings())
    156     //  return false;
     147    buffer_ = new InputBuffer();
     148    addKeyHandler(buffer_, "buffer");
     149
     150    keyBinder_ = new KeyBinder();
     151    keyBinder_->loadBindings();
     152    addKeyHandler(keyBinder_, "keybinder");
     153    addMouseHandler(keyBinder_, "keybinder");
     154    addJoyStickHandler(keyBinder_, "keybinder");
     155
     156    keyDetector_ = new KeyDetector();
     157    keyDetector_->loadBindings();
     158    addKeyHandler(keyDetector_, "keydetector");
     159    addMouseHandler(keyDetector_, "keydetector");
     160    addJoyStickHandler(keyDetector_, "keydetector");
    157161
    158162    CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
     
    288292      CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
    289293
    290       if (keyHandlers_.find("buffer") != keyHandlers_.end())
    291         delete keyHandlers_["buffer"];
    292 
    293       if (keyHandlers_.find("keybinder") != keyHandlers_.end())
    294         delete keyHandlers_["keybinder"];
     294      if (buffer_)
     295        delete buffer_;
     296
     297      if (keyBinder_)
     298        delete keyBinder_;
     299
     300      if (keyDetector_)
     301        delete keyDetector_;
    295302
    296303      keyHandlers_.clear();
     
    361368  void InputManager::_updateTickables()
    362369  {
    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;
     370    // we can use a map to have a list of unique pointers (an object can implement all 3 handlers)
     371    std::map<InputTickable*, HandlerState> tempSet;
    365372    for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
    366       tempSet.insert(activeKeyHandlers_[iHandler]);
     373      tempSet[activeKeyHandlers_[iHandler]].joyStick = true;
    367374    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    368       tempSet.insert(activeMouseHandlers_[iHandler]);
     375      tempSet[activeMouseHandlers_[iHandler]].mouse = true;
    369376    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
    370377      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
     378        tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true;
     379
     380    // copy the content of the map back to the actual vector
    374381    activeHandlers_.clear();
    375     for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++)
    376       activeHandlers_.push_back(*itHandler);
     382    for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin();
     383        itHandler != tempSet.end(); itHandler++)
     384      activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second));
    377385  }
    378386
     
    422430          break;
    423431
     432        case IS_DETECTION:
     433          if (mouse_)
     434            mouse_->capture();
     435          if (keyboard_)
     436            keyboard_->capture();
     437          for (unsigned  int i = 0; i < joySticksSize_; i++)
     438            joySticks_[i]->capture();
     439
     440          lastStroke_ = "";
     441          enableKeyHandler("keydetector");
     442          enableMouseHandler("keydetector");
     443          enableJoyStickHandler("keydetector", 0);
     444          break;
     445
    424446        default:
    425447          break;
     
    455477
    456478
    457     // call the ticks
     479    // call the ticks for the handlers (need to be treated specially)
    458480    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
    459       activeHandlers_[iHandler]->tick(dt);
     481      activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second);
     482
     483    /*for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
     484      activeKeyHandlers_[iHandler]->tickKey(dt);
     485    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
     486      activeMouseHandlers_[iHandler]->tickMouse(dt);
     487    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
     488      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     489        activeJoyStickHandlers_[iJoyStick][iHandler]->tickJoyStick(dt);*/
    460490  }
    461491
     
    781811  }
    782812
    783   bool InputManager::isKeyDown(KeyCode::Enum key)
     813  /*bool InputManager::isKeyDown(KeyCode::Enum key)
    784814  {
    785815    if (_getSingleton().keyboard_)
     
    787817    else
    788818      return false;
    789   }
    790 
    791   bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
     819  }*/
     820
     821  /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
    792822  {
    793823    if (_getSingleton().keyboard_)
     
    795825    else
    796826      return false;
    797   }
     827  }*/
    798828
    799829  /*const MouseState InputManager::getMouseState()
     
    812842      return JoyStickState();
    813843  }*/
    814 
    815844
    816845  void InputManager::destroy()
     
    871900  }
    872901
     902  void InputManager::storeKeyStroke(const std::string& name)
     903  {
     904    if (_getSingleton().lastStroke_ == "")
     905      _getSingleton().lastStroke_ = name;
     906  }
     907
     908  const std::string& InputManager::getLastKeyStroke()
     909  {
     910    return _getSingleton().lastStroke_;
     911  }
     912
    873913
    874914  // ###### KeyHandler ######
Note: See TracChangeset for help on using the changeset viewer.