X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInput%2FFGEventInput.cxx;h=8bf9f304e53bb2be03e22c04bbc1182008b3e78b;hb=d0a2fbba990c07608b813fa026126fe7ce52c552;hp=6ac1dd4af642b67c80877defd75664de973d45ca;hpb=a1a610f7d5458004b8fc6fd3ff88bcec660a26f4;p=flightgear.git diff --git a/src/Input/FGEventInput.cxx b/src/Input/FGEventInput.cxx index 6ac1dd4af..8bf9f304e 100644 --- a/src/Input/FGEventInput.cxx +++ b/src/Input/FGEventInput.cxx @@ -24,11 +24,14 @@ # include #endif +#include #include "FGEventInput.hxx" #include
#include #include +using simgear::PropertyList; + FGEventSetting::FGEventSetting( SGPropertyNode_ptr base ) : value(0.0) { @@ -64,7 +67,7 @@ bool FGEventSetting::Test() static inline bool StartsWith( string & s, const char * cp ) { - return s.compare( 0, strlen(cp), cp ) == 0; + return s.find( cp ) == 0; } FGInputEvent * FGInputEvent::NewObject( FGInputDevice * device, SGPropertyNode_ptr node ) @@ -74,10 +77,10 @@ FGInputEvent * FGInputEvent::NewObject( FGInputDevice * device, SGPropertyNode_p return new FGButtonEvent( device, node ); if( StartsWith( name, "rel-" ) ) - return new FGAxisEvent( device, node ); + return new FGRelAxisEvent( device, node ); if( StartsWith( name, "abs-" ) ) - return new FGAxisEvent( device, node ); + return new FGAbsAxisEvent( device, node ); return new FGInputEvent( device, node ); } @@ -93,8 +96,8 @@ FGInputEvent::FGInputEvent( FGInputDevice * aDevice, SGPropertyNode_ptr node ) : read_bindings( node, bindings, KEYMOD_NONE, device->GetNasalModule() ); - vector settingNodes = node->getChildren("setting"); - for( vector::iterator it = settingNodes.begin(); it != settingNodes.end(); it++ ) + PropertyList settingNodes = node->getChildren("setting"); + for( PropertyList::iterator it = settingNodes.begin(); it != settingNodes.end(); it++ ) settings.push_back( new FGEventSetting( *it ) ); } @@ -121,18 +124,25 @@ void FGInputEvent::fire( FGEventData & eventData ) if( lastDt >= intervalSec ) { for( binding_list_t::iterator it = bindings[eventData.modifiers].begin(); it != bindings[eventData.modifiers].end(); it++ ) - (*it)->fire( eventData.value, 1.0 ); + fire( *it, eventData ); lastDt -= intervalSec; } } +void FGInputEvent::fire( SGBinding * binding, FGEventData & eventData ) +{ + binding->fire(); +} + + + FGAxisEvent::FGAxisEvent( FGInputDevice * device, SGPropertyNode_ptr node ) : FGInputEvent( device, node ) { tolerance = node->getDoubleValue("tolerance", 0.002); - minRange = node->getDoubleValue("min-range", -1024.0); - maxRange = node->getDoubleValue("max-range", 1024.0); + minRange = node->getDoubleValue("min-range", 0.0 ); + maxRange = node->getDoubleValue("max-range", 0.0 ); center = node->getDoubleValue("center", 0.0); deadband = node->getDoubleValue("dead-band", 0.0); lowThreshold = node->getDoubleValue("low-threshold", -0.9); @@ -145,7 +155,36 @@ void FGAxisEvent::fire( FGEventData & eventData ) if (fabs( eventData.value - lastValue) < tolerance) return; lastValue = eventData.value; - FGInputEvent::fire( eventData ); + + // We need a copy of the FGEventData struct to set the new value and to avoid side effects + FGEventData ed = eventData; + + if( fabs(ed.value) < deadband ) + ed.value = 0.0; + + if( minRange != maxRange ) + ed.value = 2.0*(eventData.value-minRange)/(maxRange-minRange)-1.0; + + FGInputEvent::fire( ed ); +} + +void FGAbsAxisEvent::fire( SGBinding * binding, FGEventData & eventData ) +{ + // sets the "setting" node + binding->fire( eventData.value ); +} + +FGRelAxisEvent::FGRelAxisEvent( FGInputDevice * device, SGPropertyNode_ptr node ) : + FGAxisEvent( device, node ) +{ + // relative axes can't use tolerance + tolerance = 0.0; +} + +void FGRelAxisEvent::fire( SGBinding * binding, FGEventData & eventData ) +{ + // sets the "offset" node + binding->fire( eventData.value, 1.0 ); } FGButtonEvent::FGButtonEvent( FGInputDevice * device, SGPropertyNode_ptr node ) : @@ -185,8 +224,8 @@ FGInputDevice::~FGInputDevice() if( nasal ) { SGPropertyNode_ptr nasalClose = nasal->getNode("close"); if (nasalClose) { - const char *s = nasalClose->getStringValue(); - nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s, strlen(s), deviceNode ); + const string s = nasalClose->getStringValue(); + nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s.c_str(), s.length(), deviceNode ); } } nas->deleteModule(nasalModule.c_str()); @@ -199,8 +238,8 @@ void FGInputDevice::Configure( SGPropertyNode_ptr aDeviceNode ) nasalModule = string("__event:") + GetName(); - vector eventNodes = deviceNode->getChildren( "event" ); - for( vector::iterator it = eventNodes.begin(); it != eventNodes.end(); it++ ) + PropertyList eventNodes = deviceNode->getChildren( "event" ); + for( PropertyList::iterator it = eventNodes.begin(); it != eventNodes.end(); it++ ) AddHandledEvent( FGInputEvent::NewObject( this, *it ) ); debugEvents = deviceNode->getBoolValue("debug-events", debugEvents ); @@ -215,10 +254,10 @@ void FGInputDevice::Configure( SGPropertyNode_ptr aDeviceNode ) if (nasal) { SGPropertyNode_ptr open = nasal->getNode("open"); if (open) { - const char *s = open->getStringValue(); + const string s = open->getStringValue(); FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal"); if (nas) - nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s, strlen(s), deviceNode ); + nas->createModule(nasalModule.c_str(), nasalModule.c_str(), s.c_str(), s.length(), deviceNode ); } }