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 moved

Legend:

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

    r1412 r1413  
    3232 */
    3333
    34 #include "InputHandler.h"
     34#include "KeyBinder.h"
    3535#include <fstream>
    3636#include "util/Convert.h"
     
    472472    clearBindings();
    473473
    474     /*std::ifstream infile;
     474    std::ifstream infile;
    475475    infile.open("keybindings.ini");
    476476    if (!infile.is_open())
    477477    {
    478       ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings_def.ini");
    479       setConfigValues();
    480     }
    481     infile.close();*/
     478      ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, keybindingsDefault_);
     479      ConfigFileManager::getSingleton()->save(CFT_Keybindings, "keybindings.ini");
     480    }
     481    infile.close();
    482482    ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini");
     483
     484    // parse key bindings
    483485    setConfigValues();
    484486
     
    496498    SetConfigValue(derivePeriod_, 0.1f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier.");
    497499    SetConfigValue(mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived.");
    498     SetConfigValue(keybindingsDefault_, "keybindings_def.ini").description("Default ini file for the keybindings.");
     500    SetConfigValue(keybindingsDefault_, "def_keybindings.ini").description("Default ini file for the keybindings.");
    499501
    500502    float oldThresh = buttonThreshold_;
     
    542544    @brief Overwrites all bindings with ""
    543545  */
    544   void KeyBinder::clearBindings(bool bInit)
     546  void KeyBinder::clearBindings()
    545547  {
    546548    for (unsigned int i = 0; i < nKeys_s; i++)
     
    561563  }
    562564
    563   void KeyBinder::tick(float dt)
     565  void KeyBinder::tickInput(float dt, const HandlerState& state)
    564566  {
    565567    // we have to process all the analog input since there is e.g. no 'mouseDoesntMove' event.
    566     for (unsigned int i = 0; i < nHalfAxes_s; i++)
     568    unsigned int iBegin = 8;
     569    unsigned int iEnd   = 8;
     570    if (state.joyStick)
     571      iEnd = nHalfAxes_s;
     572    if (state.mouse)
     573      iBegin = 0;
     574    for (unsigned int i = iBegin; i < iEnd; i++)
    567575    {
    568576      if (halfAxes_[i].hasChanged_)
     
    596604    }
    597605
    598     if (bDeriveMouseInput_)
     606    if (bDeriveMouseInput_ && state.mouse)
    599607    {
    600608      if (deriveTime_ > derivePeriod_)
    601609      {
    602         deriveTime_ = 0.0f;
    603610        //CCOUT(3) << "mouse abs: ";
    604611        for (int i = 0; i < 2; i++)
     
    606613          if (mouseRelative_[i] > 0)
    607614          {
    608             halfAxes_[2*i + 0].absVal_ =  mouseRelative_[i] / derivePeriod_ / 5000 * mouseSensitivityDerived_;
     615            halfAxes_[2*i + 0].absVal_ =  mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    609616            halfAxes_[2*i + 1].absVal_ = 0.0f;
    610617          }
     
    612619          {
    613620            halfAxes_[2*i + 0].absVal_ = 0.0f;
    614             halfAxes_[2*i + 1].absVal_ = -mouseRelative_[i] / derivePeriod_ / 5000 * mouseSensitivityDerived_;
     621            halfAxes_[2*i + 1].absVal_ = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    615622          }
    616623          else
     
    622629          mouseRelative_[i] = 0;
    623630        }
     631        deriveTime_ = 0.0f;
    624632        //COUT(3) << std::endl;
    625633      }
     
    633641
    634642    // always reset the relative movement of the mouse
    635     for (unsigned int i = 0; i < 8; i++)
    636       halfAxes_[i].relVal_ = 0.0f;
     643    if (state.mouse)
     644      for (unsigned int i = 0; i < 8; i++)
     645        halfAxes_[i].relVal_ = 0.0f;
    637646  }
    638647
     
    784793
    785794  // ###############################
    786   // ###     GUIInputHandler     ###
     795  // #####     KeyDetector     #####
    787796  // ###############################
    788797
    789   ///**
    790   //  @brief standard constructor
    791   //*/
    792   //GUIInputHandler::GUIInputHandler()
    793   //{
    794   //}
    795 
    796   ///**
    797   //  @brief Destructor
    798   //*/
    799   //GUIInputHandler::~GUIInputHandler()
    800   //{
    801   //}
    802 
    803   ///**
    804   //  @brief Event handler for the keyPressed Event.
    805   //  @param e Event information
    806   //*/
    807   //bool GUIInputHandler::keyPressed(const OIS::KeyEvent &e)
    808   //{
    809     ////CEGUI::System::getSingleton().injectKeyDown( arg.key );
    810     ////CEGUI::System::getSingleton().injectChar( arg.text );
    811   //  return true;
    812   //}
    813 
    814   ///**
    815   //  @brief Event handler for the keyReleased Event.
    816   //  @param e Event information
    817   //*/
    818   //bool GUIInputHandler::keyReleased(const OIS::KeyEvent &e)
    819   //{
    820     ////CEGUI::System::getSingleton().injectKeyUp( arg.key );
    821   //  return true;
    822   //}
    823 
    824   ///**
    825   //  @brief Event handler for the mouseMoved Event.
    826   //  @param e Event information
    827   //*/
    828   //bool GUIInputHandler::mouseMoved(const OIS::MouseEvent &e)
    829   //{
    830     ////CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
    831   //  return true;
    832   //}
    833 
    834   ///**
    835   //  @brief Event handler for the mousePressed Event.
    836   //  @param e Event information
    837   //  @param id The ID of the mouse button
    838   //*/
    839   //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButton id)
    840   //{
    841     ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
    842   //  return true;
    843   //}
    844 
    845   ///**
    846   //  @brief Event handler for the mouseReleased Event.
    847   //  @param e Event information
    848   //  @param id The ID of the mouse button
    849   //*/
    850   //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButton id)
    851   //{
    852     ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
    853   //  return true;
    854   //}
    855 
     798  /**
     799    @brief Constructor
     800  */
     801  KeyDetector::KeyDetector()
     802  {
     803    RegisterObject(KeyDetector);
     804  }
     805
     806  /**
     807    @brief Destructor
     808  */
     809  KeyDetector::~KeyDetector()
     810  {
     811  }
     812
     813  /**
     814    @brief Loads the key and button bindings.
     815    @return True if loading succeeded.
     816  */
     817  void KeyDetector::loadBindings()
     818  {
     819    clearBindings();
     820    setConfigValues();
     821  }
     822
     823  /**
     824    @brief Loader for the key bindings, managed by config values.
     825  */
     826  void KeyDetector::setConfigValues()
     827  {
     828    // keys
     829    for (unsigned int i = 0; i < nKeys_s; i++)
     830      readTrigger(keys_[i]);
     831    // mouse buttons
     832    for (unsigned int i = 0; i < nMouseButtons_s; i++)
     833      readTrigger(mouseButtons_[i]);
     834    // joy stick buttons
     835    for (unsigned int i = 0; i < nJoyStickButtons_s; i++)
     836      readTrigger(joyStickButtons_[i]);
     837    // half axes
     838    for (unsigned int i = 0; i < nHalfAxes_s; i++)
     839      readTrigger(halfAxes_[i]);
     840  }
     841
     842  void KeyDetector::readTrigger(Button& button)
     843  {
     844    // binding has changed
     845    button.parse(paramCommandBuffer_);
     846    SimpleCommand* cmd = new SimpleCommand();
     847    cmd->evaluation_ = CommandExecutor::evaluate("storeKeyStroke " + button.name_);
     848    button.commands_[KeybindMode::OnPress] = new BaseCommand*[1];
     849    button.commands_[KeybindMode::OnPress][0] = cmd;
     850    button.nCommands_[KeybindMode::OnPress] = 1;
     851  }
    856852}
Note: See TracChangeset for help on using the changeset viewer.