- 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 ()
|
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)
|
FGBinding::FGBinding (const SGPropertyNode * node)
|
||||||
: _command(0), _arg(0)
|
: _command(0),
|
||||||
|
_arg(new SGPropertyNode),
|
||||||
|
_setting(0),
|
||||||
|
_command_state(0)
|
||||||
{
|
{
|
||||||
read(node);
|
read(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
FGBinding::~FGBinding ()
|
FGBinding::~FGBinding ()
|
||||||
{
|
{
|
||||||
// no op
|
delete _arg; // Delete the saved arguments
|
||||||
|
delete _command_state; // Delete the saved command state
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -116,33 +133,32 @@ FGBinding::read (const SGPropertyNode * node)
|
||||||
_arg = 0;
|
_arg = 0;
|
||||||
return;
|
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
|
void
|
||||||
FGBinding::fire () const
|
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
|
void
|
||||||
FGBinding::fire (double setting) const
|
FGBinding::fire (double setting) const
|
||||||
{
|
{
|
||||||
SGPropertyNode arg;
|
// A value is automatically added to
|
||||||
if (_arg != 0)
|
// the args
|
||||||
copyProperties(_arg, &arg);
|
if (_setting == 0) // save the setting node for efficiency
|
||||||
arg.setDoubleValue("setting", setting);
|
_setting = _arg->getChild("setting", 0, true);
|
||||||
_fire(&arg);
|
_setting->setDoubleValue(setting);
|
||||||
}
|
fire();
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue