[Orxonox-commit 781] r3306 - branches/core4/src/core/input
rgrieder at orxonox.net
rgrieder at orxonox.net
Sun Jul 19 01:13:43 CEST 2009
Author: rgrieder
Date: 2009-07-19 01:13:43 +0200 (Sun, 19 Jul 2009)
New Revision: 3306
Modified:
branches/core4/src/core/input/JoyStick.cc
branches/core4/src/core/input/JoyStick.h
branches/core4/src/core/input/KeyBinder.cc
branches/core4/src/core/input/KeyBinder.h
branches/core4/src/core/input/KeyDetector.cc
branches/core4/src/core/input/KeyDetector.h
Log:
Keybindings should now map to the correct joy stick by device name (like "WingMan Action Pad" or so).
Modified: branches/core4/src/core/input/JoyStick.cc
===================================================================
--- branches/core4/src/core/input/JoyStick.cc 2009-07-18 16:24:38 UTC (rev 3305)
+++ branches/core4/src/core/input/JoyStick.cc 2009-07-18 23:13:43 UTC (rev 3306)
@@ -42,7 +42,7 @@
//! Helper function that loads the config value vector of one coefficient
void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue);
- std::vector<std::string> JoyStick::idStrings_s;
+ std::vector<std::string> JoyStick::deviceNames_s;
JoyStick::JoyStick(unsigned int id, OIS::InputManager* oisInputManager)
: super(id, oisInputManager)
@@ -52,34 +52,38 @@
// Initialise POV and Slider states
this->clearBuffersImpl();
- idString_ = "JoyStick_";
- std::string name = oisDevice_->vendor();
- replaceCharacters(name, ' ', '_');
- idString_ += name + "_";
- idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button)) + "_";
- idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)) + "_";
- idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider)) + "_";
- idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
- //idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
+ // Generate unique name
+ if (oisDevice_->vendor().empty())
+ deviceName_ = "Unknown_";
+ else
+ {
+ std::string name = oisDevice_->vendor();
+ replaceCharacters(name, ' ', '_');
+ deviceName_ = name + "_";
+ }
+ deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button)) + "_";
+ deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis)) + "_";
+ deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider)) + "_";
+ deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
+ //deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
-
- BOOST_FOREACH(std::string& idString, idStrings_s)
+ BOOST_FOREACH(std::string& idString, deviceNames_s)
{
- if (idString_ == idString)
+ if (deviceName_ == idString)
{
// Make the ID unique for this execution time.
- idString_ += "_" + multi_cast<std::string>(this->getDeviceID());
+ deviceName_ += "_" + multi_cast<std::string>(this->getDeviceName());
break;
}
}
- COUT(4) << "Created OIS joy stick with ID " << idString_ << std::endl;
+ COUT(4) << "Created OIS joy stick with ID " << deviceName_ << std::endl;
// Load calibration
size_t axes = sliderAxes_s + static_cast<size_t>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis));
- loadCalibration(configMinValues_, idString_, "MinValue", axes, -32768);
- loadCalibration(configMaxValues_, idString_, "MaxValue", axes, 32768);
- loadCalibration(configZeroValues_, idString_, "ZeroValue", axes, 0);
+ loadCalibration(configMinValues_, deviceName_, "MinValue", axes, -32768);
+ loadCalibration(configMaxValues_, deviceName_, "MaxValue", axes, 32768);
+ loadCalibration(configZeroValues_, deviceName_, "ZeroValue", axes, 0);
this->evaluateCalibration();
}
@@ -147,17 +151,17 @@
if (configMinValues_[i] == INT_MAX)
configMinValues_[i] = -32768;
ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
- idString_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
+ deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
// Maximum values
if (configMaxValues_[i] == INT_MIN)
configMaxValues_[i] = 32767;
ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
- idString_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
+ deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
// Middle values
ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
- idString_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
+ deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
}
this->evaluateCalibration();
Modified: branches/core4/src/core/input/JoyStick.h
===================================================================
--- branches/core4/src/core/input/JoyStick.h 2009-07-18 16:24:38 UTC (rev 3305)
+++ branches/core4/src/core/input/JoyStick.h 2009-07-18 23:13:43 UTC (rev 3306)
@@ -70,8 +70,8 @@
~JoyStick() { }
void setConfigValues();
- //! Returns the ID string generated from the number of knobs and the device name
- const std::string& getIDString() const { return this->idString_; }
+ //! Returns the name generated from the number of knobs and the device name
+ const std::string& getDeviceName() const { return this->deviceName_; }
private:
void calibrationStarted();
@@ -105,7 +105,7 @@
//! Returns the class name as string
static std::string getClassNameImpl() { return "JoyStick"; }
- std::string idString_; //!< ID string generated by the number of knobs and the device name
+ std::string deviceName_; //!< Name generated by the number of knobs and the device name
int povStates_[4]; //!< Internal states for the POVs
int sliderStates_[4][2]; //!< Internal states for the Sliders (each slider has X and Y!)
@@ -121,8 +121,8 @@
// ConfigValues
std::string calibrationFilename_; //!< Joy stick calibration ini filename
- //! Contains a list of all ID strings to avoid duplicates
- static std::vector<std::string> idStrings_s;
+ //! Contains a list of all names to avoid duplicates
+ static std::vector<std::string> deviceNames_s;
//!< Maximum number of slider axes
static const unsigned int sliderAxes_s = 8;
Modified: branches/core4/src/core/input/KeyBinder.cc
===================================================================
--- branches/core4/src/core/input/KeyBinder.cc 2009-07-18 16:24:38 UTC (rev 3305)
+++ branches/core4/src/core/input/KeyBinder.cc 2009-07-18 23:13:43 UTC (rev 3306)
@@ -39,6 +39,7 @@
#include "core/CoreIncludes.h"
#include "core/ConfigFileManager.h"
#include "InputCommands.h"
+#include "JoyStick.h"
namespace orxonox
{
@@ -47,8 +48,7 @@
Constructor that does as little as necessary.
*/
KeyBinder::KeyBinder()
- : numberOfJoySticks_(0)
- , deriveTime_(0.0f)
+ : deriveTime_(0.0f)
{
mouseRelative_[0] = 0;
mouseRelative_[1] = 0;
@@ -81,14 +81,14 @@
nameSuffix = MouseButtonCode::ByString[i];
else
nameSuffix = mouseWheelNames[i - MouseButtonCode::numberOfButtons];
- mouseButtons_[i].name_ = std::string("Mouse") + nameSuffix;
+ mouseButtons_[i].name_ = nameSuffix;
mouseButtons_[i].paramCommandBuffer_ = ¶mCommandBuffer_;
mouseButtons_[i].groupName_ = "MouseButtons";
}
// mouse axes
for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
{
- mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i / 2];
+ mouseAxes_[i].name_ = MouseAxisCode::ByString[i / 2];
if (i & 1)
mouseAxes_[i].name_ += "Pos";
else
@@ -101,12 +101,8 @@
this->configFile_ = ConfigFileType::NoType;
// initialise joy sticks separatly to allow for reloading
- numberOfJoySticks_ = this->getJoyStickList().size();
- initialiseJoyStickBindings();
+ this->JoyStickQuantityChanged(this->getJoyStickList());
- // collect all Buttons and HalfAxes
- compilePointerLists();
-
// set them here to use allHalfAxes_
setConfigValues();
}
@@ -155,8 +151,8 @@
void KeyBinder::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
{
- unsigned int oldValue = numberOfJoySticks_;
- numberOfJoySticks_ = joyStickList.size();
+ unsigned int oldValue = joySticks_.size();
+ joySticks_ = joyStickList;
// initialise joy stick bindings
initialiseJoyStickBindings();
@@ -167,7 +163,7 @@
// load the bindings if required
if (configFile_ != ConfigFileType::NoType)
{
- for (unsigned int iDev = oldValue; iDev < numberOfJoySticks_; ++iDev)
+ for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev)
{
for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
joyStickButtons_[iDev][i].readConfigValue(this->configFile_);
@@ -182,30 +178,30 @@
void KeyBinder::initialiseJoyStickBindings()
{
- this->joyStickAxes_.resize(numberOfJoySticks_);
- this->joyStickButtons_.resize(numberOfJoySticks_);
+ this->joyStickAxes_.resize(joySticks_.size());
+ this->joyStickButtons_.resize(joySticks_.size());
// reinitialise all joy stick binings (doesn't overwrite the old ones)
- for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)
+ for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++)
{
- std::string deviceNumber = multi_cast<std::string>(iDev);
+ std::string deviceName = joySticks_[iDev]->getDeviceName();
// joy stick buttons
for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
{
- joyStickButtons_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickButtonCode::ByString[i];
+ joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i];
joyStickButtons_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_;
- joyStickButtons_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Buttons";
+ joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName;
}
// joy stick axes
for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
{
- joyStickAxes_[iDev][i].name_ = std::string("JoyStick") + deviceNumber + JoyStickAxisCode::ByString[i >> 1];
+ joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2];
if (i & 1)
joyStickAxes_[iDev][i].name_ += "Pos";
else
joyStickAxes_[iDev][i].name_ += "Neg";
joyStickAxes_[iDev][i].paramCommandBuffer_ = ¶mCommandBuffer_;
- joyStickAxes_[iDev][i].groupName_ = std::string("JoyStick") + deviceNumber + "Axes";
+ joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName;
}
}
}
@@ -218,21 +214,21 @@
// Note: Don't include the dummy keys which don't actually exist in OIS but have a number
for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
if (!keys_[i].name_.empty())
- allButtons_[keys_[i].name_] = keys_ + i;
+ allButtons_[keys_[i].groupName_ + "." + keys_[i].name_] = keys_ + i;
for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
- allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i;
+ allButtons_[mouseButtons_[i].groupName_ + "." + mouseButtons_[i].name_] = mouseButtons_ + i;
for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
{
- allButtons_[mouseAxes_[i].name_] = mouseAxes_ + i;
+ allButtons_[mouseAxes_[i].groupName_ + "." + mouseAxes_[i].name_] = mouseAxes_ + i;
allHalfAxes_.push_back(mouseAxes_ + i);
}
- for (unsigned int iDev = 0; iDev < numberOfJoySticks_; iDev++)
+ for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++)
{
for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
- allButtons_[joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
+ allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
{
- allButtons_[joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
+ allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
allHalfAxes_.push_back(&(joyStickAxes_[iDev][i]));
}
}
@@ -302,7 +298,7 @@
void KeyBinder::resetJoyStickAxes()
{
- for (unsigned int iDev = 0; iDev < numberOfJoySticks_; ++iDev)
+ for (unsigned int iDev = 0; iDev < joySticks_.size(); ++iDev)
{
for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
{
Modified: branches/core4/src/core/input/KeyBinder.h
===================================================================
--- branches/core4/src/core/input/KeyBinder.h 2009-07-18 16:24:38 UTC (rev 3305)
+++ branches/core4/src/core/input/KeyBinder.h 2009-07-18 23:13:43 UTC (rev 3306)
@@ -96,7 +96,7 @@
protected: // variables
//! Currently active joy sticks
- unsigned int numberOfJoySticks_;
+ std::vector<JoyStick*> joySticks_;
//! Actual key bindings for keys on the keyboard
Button keys_ [KeyCode::numberOfKeys];
Modified: branches/core4/src/core/input/KeyDetector.cc
===================================================================
--- branches/core4/src/core/input/KeyDetector.cc 2009-07-18 16:24:38 UTC (rev 3305)
+++ branches/core4/src/core/input/KeyDetector.cc 2009-07-18 23:13:43 UTC (rev 3306)
@@ -26,12 +26,6 @@
*
*/
-/**
- at file
- at brief
- Implementation of the different input handlers.
-*/
-
#include "KeyDetector.h"
#include "util/Debug.h"
@@ -67,7 +61,7 @@
clearBindings();
for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
{
- it->second->bindingString_ = callbackCommand_ + it->second->name_;
+ it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;
it->second->parse();
}
}
Modified: branches/core4/src/core/input/KeyDetector.h
===================================================================
--- branches/core4/src/core/input/KeyDetector.h 2009-07-18 16:24:38 UTC (rev 3305)
+++ branches/core4/src/core/input/KeyDetector.h 2009-07-18 23:13:43 UTC (rev 3306)
@@ -26,12 +26,6 @@
*
*/
-/**
- at file
- at brief
- Different definitions of input processing.
-*/
-
#ifndef _KeyDetector_H__
#define _KeyDetector_H__
More information about the Orxonox-commit
mailing list