- modified FGBinding to keep a local copy of the argument property
node, and to modify that directly for scaling events: that will make handling joystick axes much more efficient - modified FGBinding to work with the new command state, so that commands can save their state (i.e. compiled arguments) from the last pass - removed FGBinding::_fire implementation - implemented FGBinding copy constructor
This commit is contained in:
parent
9ff7217961
commit
ce45dbefe0
1 changed files with 36 additions and 20 deletions
|
@ -85,19 +85,36 @@ SG_USING_STD(vector);
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FGBinding::FGBinding ()
|
||||
: _command(0), _arg(0)
|
||||
: _command(0),
|
||||
_arg(new SGPropertyNode),
|
||||
_setting(0),
|
||||
_command_state(0)
|
||||
{
|
||||
}
|
||||
|
||||
FGBinding::FGBinding (const FGBinding &binding)
|
||||
: _command_name(binding._command_name),
|
||||
_command(binding._command),
|
||||
_arg(new SGPropertyNode),
|
||||
_setting(0),
|
||||
_command_state(0)
|
||||
{
|
||||
copyProperties(binding._arg, _arg);
|
||||
}
|
||||
|
||||
FGBinding::FGBinding (const SGPropertyNode * node)
|
||||
: _command(0), _arg(0)
|
||||
: _command(0),
|
||||
_arg(new SGPropertyNode),
|
||||
_setting(0),
|
||||
_command_state(0)
|
||||
{
|
||||
read(node);
|
||||
}
|
||||
|
||||
FGBinding::~FGBinding ()
|
||||
{
|
||||
// no op
|
||||
delete _arg; // Delete the saved arguments
|
||||
delete _command_state; // Delete the saved command state
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -116,33 +133,32 @@ FGBinding::read (const SGPropertyNode * node)
|
|||
_arg = 0;
|
||||
return;
|
||||
}
|
||||
_arg = node; // FIXME: don't use whole node!!!
|
||||
|
||||
delete _arg;
|
||||
_arg = new SGPropertyNode;
|
||||
_setting = 0;
|
||||
copyProperties(node, _arg); // FIXME: don't use whole node!!!
|
||||
}
|
||||
|
||||
void
|
||||
FGBinding::fire () const
|
||||
{
|
||||
_fire(_arg);
|
||||
if (_command == 0) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
|
||||
} else if (!(*_command)(_arg, &_command_state)) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command " << _command_name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FGBinding::fire (double setting) const
|
||||
{
|
||||
SGPropertyNode arg;
|
||||
if (_arg != 0)
|
||||
copyProperties(_arg, &arg);
|
||||
arg.setDoubleValue("setting", setting);
|
||||
_fire(&arg);
|
||||
}
|
||||
|
||||
void
|
||||
FGBinding::_fire(const SGPropertyNode * arg) const
|
||||
{
|
||||
if (_command == 0) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
|
||||
} else if (!(*_command)(arg)) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command " << _command_name);
|
||||
}
|
||||
// A value is automatically added to
|
||||
// the args
|
||||
if (_setting == 0) // save the setting node for efficiency
|
||||
_setting = _arg->getChild("setting", 0, true);
|
||||
_setting->setDoubleValue(setting);
|
||||
fire();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue