[Orxonox-commit 1710] r6428 - code/trunk/src/libraries/core/input
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Dec 28 23:10:37 CET 2009
Author: rgrieder
Date: 2009-12-28 23:10:37 +0100 (Mon, 28 Dec 2009)
New Revision: 6428
Modified:
code/trunk/src/libraries/core/input/Button.cc
code/trunk/src/libraries/core/input/Button.h
code/trunk/src/libraries/core/input/KeyBinder.cc
code/trunk/src/libraries/core/input/KeyBinder.h
code/trunk/src/libraries/core/input/KeyDetector.cc
Log:
Changed config value handling in the KeyBinder. Doesn't change the interface though.
Modified: code/trunk/src/libraries/core/input/Button.cc
===================================================================
--- code/trunk/src/libraries/core/input/Button.cc 2009-12-28 19:35:54 UTC (rev 6427)
+++ code/trunk/src/libraries/core/input/Button.cc 2009-12-28 22:10:37 UTC (rev 6428)
@@ -41,7 +41,6 @@
#include "core/ConsoleCommand.h"
#include "core/CommandEvaluation.h"
#include "core/CommandExecutor.h"
-#include "core/ConfigValueContainer.h"
namespace orxonox
{
@@ -51,8 +50,7 @@
correctly the first time. It is then set to false first and changed later in Button::parse().
*/
Button::Button()
- : configContainer_(0)
- , bButtonThresholdUser_(false)
+ : bButtonThresholdUser_(false)
, paramCommandBuffer_(0)
{
nCommands_[0]=0;
@@ -63,9 +61,6 @@
Button::~Button()
{
this->clear();
-
- if (this->configContainer_)
- delete this->configContainer_;
}
void Button::clear()
@@ -82,23 +77,30 @@
nCommands_[j] = 0;
}
}
+ this->bindingString_.clear();
}
- void Button::readConfigValue(ConfigFileType configFile)
+ void Button::readBinding(ConfigFileType type)
{
- // create/get ConfigValueContainer
- if (!configContainer_)
- {
- configContainer_ = new ConfigValueContainer(configFile, 0, groupName_, name_, "", name_);
- configContainer_->callback(this, &Button::parse);
- }
- configContainer_->getValue(&bindingString_, this);
+ const std::string& binding = ConfigFileManager::getInstance().getValue(type, groupName_, name_, "", true);
+ this->parse(binding);
}
- void Button::parse()
+ void Button::setBinding(ConfigFileType type, const std::string& binding, bool bTemporary)
{
+ if (!bTemporary)
+ ConfigFileManager::getInstance().setValue(type, groupName_, name_, binding, true);
+ this->parse(binding);
+ }
+
+ void Button::parse(const std::string& binding)
+ {
+ if (binding == this->bindingString_)
+ return;
+
// delete all commands
clear();
+ this->bindingString_ = binding;
if (isEmpty(bindingString_))
return;
Modified: code/trunk/src/libraries/core/input/Button.h
===================================================================
--- code/trunk/src/libraries/core/input/Button.h 2009-12-28 19:35:54 UTC (rev 6427)
+++ code/trunk/src/libraries/core/input/Button.h 2009-12-28 22:10:37 UTC (rev 6428)
@@ -51,12 +51,11 @@
virtual ~Button();
virtual void clear();
virtual bool addParamCommand(ParamCommand* command) { return false; }
- void parse();
- void readConfigValue(ConfigFileType configFile);
+ void parse(const std::string& binding);
+ void readBinding(ConfigFileType type);
+ void setBinding(ConfigFileType type, const std::string& binding, bool bTemporary);
bool execute(KeybindMode::Value mode, float abs = 1.0f, float rel = 1.0f);
- //! Container to allow for better configValue support
- ConfigValueContainer* configContainer_;
//! The configured string value
std::string bindingString_;
//! Name of the trigger as strings
Modified: code/trunk/src/libraries/core/input/KeyBinder.cc
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.cc 2009-12-28 19:35:54 UTC (rev 6427)
+++ code/trunk/src/libraries/core/input/KeyBinder.cc 2009-12-28 22:10:37 UTC (rev 6428)
@@ -56,7 +56,7 @@
RegisterRootObject(KeyBinder);
- // intialise all buttons and half axes to avoid creating everything with 'new'
+ // initialise all buttons and half axes to avoid creating everything with 'new'
// keys
for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
{
@@ -167,9 +167,9 @@
for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev)
{
for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
- (*joyStickButtons_[iDev])[i].readConfigValue(this->configFile_);
+ (*joyStickButtons_[iDev])[i].readBinding(this->configFile_);
for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
- (*joyStickAxes_[iDev])[i].readConfigValue(this->configFile_);
+ (*joyStickAxes_[iDev])[i].readBinding(this->configFile_);
}
}
@@ -256,7 +256,7 @@
// Parse bindings and create the ConfigValueContainers if necessary
for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
{
- it->second->readConfigValue(this->configFile_);
+ it->second->readBinding(this->configFile_);
addButtonToCommand(it->second->bindingString_, it->second);
}
@@ -269,11 +269,7 @@
if (it != allButtons_.end())
{
addButtonToCommand(binding, it->second);
- if (bTemporary)
- it->second->configContainer_->tset(binding);
- else
- it->second->configContainer_->set(binding);
- it->second->configContainer_->getValue(&(it->second->bindingString_), it->second);
+ it->second->setBinding(this->configFile_, binding, bTemporary);
return true;
}
else
Modified: code/trunk/src/libraries/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.h 2009-12-28 19:35:54 UTC (rev 6427)
+++ code/trunk/src/libraries/core/input/KeyBinder.h 2009-12-28 22:10:37 UTC (rev 6428)
@@ -37,6 +37,7 @@
#include <map>
#include <boost/shared_ptr.hpp>
+#include "core/ConfigFileManager.h"
#include "InputHandler.h"
#include "Button.h"
#include "HalfAxis.h"
Modified: code/trunk/src/libraries/core/input/KeyDetector.cc
===================================================================
--- code/trunk/src/libraries/core/input/KeyDetector.cc 2009-12-28 19:35:54 UTC (rev 6427)
+++ code/trunk/src/libraries/core/input/KeyDetector.cc 2009-12-28 22:10:37 UTC (rev 6428)
@@ -63,12 +63,8 @@
void KeyDetector::assignCommands()
{
// Assign every button/axis the same command, but with its name as argument
- clearBindings();
for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
- {
- it->second->bindingString_ = callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_;
- it->second->parse();
- }
+ it->second->parse(callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_);
}
void KeyDetector::callback(const std::string& name)
More information about the Orxonox-commit
mailing list