From 831f81d97cd1a3383b866ca4e7ee5b7577466ef5 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sat, 3 Dec 2011 14:40:48 +0100 Subject: [PATCH 1/8] Properly construct a string from another string and an integer, use a relative path for sound construction, allow enable/disable aimodel sounds using /sim/sound/aimodels/enabled --- src/AIModel/AIBase.cxx | 13 ++++++++++--- src/Sound/fg_fx.cxx | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index d2e2fe25d..95d023296 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -147,7 +147,10 @@ FGAIBase::~FGAIBase() { if (_refID != 0 && _refID != 1) { SGSoundMgr *smgr = globals->get_soundmgr(); - smgr->remove("aifx:"+_refID); + stringstream name; + name << "aifx:"; + name << _refID; + smgr->remove(name.str()); } delete fp; @@ -221,7 +224,8 @@ void FGAIBase::update(double dt) { _fx->set_orientation( orient ); SGVec3d velocity; - velocity = SGVec3d( speed_north_deg_sec, speed_east_deg_sec, pitch*speed ); + velocity = SGVec3d( speed_north_deg_sec, speed_east_deg_sec, + pitch*speed ); _fx->set_velocity( velocity ); } else if (_aimodel) @@ -234,7 +238,10 @@ void FGAIBase::update(double dt) { // initialize the sound configuration SGSoundMgr *smgr = globals->get_soundmgr(); - _fx = new FGFX(smgr, "aifx:"+_refID, props); + stringstream name; + name << "aifx:"; + name << _refID; + _fx = new FGFX(smgr, name.str(), props); _fx->init(); } } diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index c8c6b49f3..2df20387d 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -40,11 +40,19 @@ #include FGFX::FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props ) : - _props( props ), - _enabled( fgGetNode("/sim/sound/effects/enabled", true) ), - _volume( fgGetNode("/sim/sound/effects/volume", true) ) + _props( props ) { - if (!props) _props = globals->get_props(); + if (!props) { + _props = globals->get_props(); + _enabled = fgGetNode("/sim/sound/effects/enabled", true); + _volume = fgGetNode("/sim/sound/effects/volume", true); + } else { + _enabled = _props->getNode("/sim/sound/aimodels/enabled", true); + _enabled->setBoolValue(fgGetBool("/sim/sound/effects/enabled")); + _volume = _props->getNode("/sim/sound/aimodels/volume", true); + _volume->setFloatValue(fgGetFloat("/sim/sound/effects/volume")); +_volume->setFloatValue(0.1f); + } _avionics_enabled = _props->getNode("sim/sound/avionics/enabled", true); _avionics_volume = _props->getNode("sim/sound/avionics/volume", true); @@ -102,9 +110,9 @@ FGFX::init() SGXmlSound *sound = new SGXmlSound(); try { - sound->init(globals->get_props(), node->getChild(i), this, +// sound->init(globals->get_props(), node->getChild(i), this, + sound->init(_props, node->getChild(i), this, _avionics, path.dir()); - _sound.push_back(sound); } catch ( sg_exception &e ) { SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage()); From 61e60484c8918a019d0b30e884c07cca79513fb1 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sat, 3 Dec 2011 15:29:04 +0100 Subject: [PATCH 2/8] make the sound of the base model work again. this also gives an indication where things start to go wrong. --- src/Sound/fg_fx.cxx | 15 ++++++++------- src/Sound/fg_fx.hxx | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 2df20387d..390609567 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -43,10 +43,12 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props ) : _props( props ) { if (!props) { + _is_aimodel = false; _props = globals->get_props(); _enabled = fgGetNode("/sim/sound/effects/enabled", true); _volume = fgGetNode("/sim/sound/effects/volume", true); } else { + _is_aimodel = true; _enabled = _props->getNode("/sim/sound/aimodels/enabled", true); _enabled->setBoolValue(fgGetBool("/sim/sound/effects/enabled")); _volume = _props->getNode("/sim/sound/aimodels/volume", true); @@ -105,18 +107,17 @@ FGFX::init() } node = root.getNode("fx"); - if(node) { + if(node && !_is_aimodel) { for (int i = 0; i < node->nChildren(); ++i) { - SGXmlSound *sound = new SGXmlSound(); + SGXmlSound *soundfx = new SGXmlSound(); try { -// sound->init(globals->get_props(), node->getChild(i), this, - sound->init(_props, node->getChild(i), this, - _avionics, path.dir()); - _sound.push_back(sound); + soundfx->init( _props, node->getChild(i), this, _avionics, + path.dir() ); + _sound.push_back( soundfx ); } catch ( sg_exception &e ) { SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage()); - delete sound; + delete soundfx; } } } diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index a46d8583c..3803f5bc6 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -58,6 +58,7 @@ public: private: + bool _is_aimodel; SGSharedPtr _avionics; std::vector _sound; From ded106fe31a47eee387fdf37bb7be39c03c1b97c Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Sat, 3 Dec 2011 22:59:20 +0100 Subject: [PATCH 3/8] event input for Linux: substitude dbus+hal by udev --- src/Input/FGLinuxEventInput.cxx | 100 ++++++++------------------------ src/Input/FGLinuxEventInput.hxx | 4 -- 2 files changed, 23 insertions(+), 81 deletions(-) diff --git a/src/Input/FGLinuxEventInput.cxx b/src/Input/FGLinuxEventInput.cxx index e41f6e195..a5e825b10 100644 --- a/src/Input/FGLinuxEventInput.cxx +++ b/src/Input/FGLinuxEventInput.cxx @@ -25,15 +25,11 @@ #include #include #include -#include -#include -#include -#include #include "FGLinuxEventInput.hxx" +#include #include #include -#include #include #include @@ -445,92 +441,42 @@ void FGLinuxInputDevice::SetDevname( std::string name ) this->devname = name; } -FGLinuxEventInput::FGLinuxEventInput() : - halcontext(NULL) +FGLinuxEventInput::FGLinuxEventInput() { } FGLinuxEventInput::~FGLinuxEventInput() { - if( halcontext != NULL ) { - libhal_ctx_shutdown( halcontext, NULL); - libhal_ctx_free( halcontext ); - halcontext = NULL; - } } -#if 0 -//TODO: enable hotplug support -static void DeviceAddedCallback (LibHalContext *ctx, const char *udi) -{ - FGLinuxEventInput * linuxEventInput = (FGLinuxEventInput*)libhal_ctx_get_user_data (ctx); - linuxEventInput->AddHalDevice( udi ); -} - -static void DeviceRemovedCallback (LibHalContext *ctx, const char *udi) -{ -} -#endif - void FGLinuxEventInput::postinit() { FGEventInput::postinit(); - DBusConnection * connection; - DBusError dbus_error; + struct udev * udev = udev_new(); - dbus_error_init(&dbus_error); - connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error); - if (dbus_error_is_set(&dbus_error)) { - SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to system bus " << dbus_error.message); - dbus_error_free (&dbus_error); - return; + struct udev_enumerate *enumerate = udev_enumerate_new(udev); + udev_enumerate_add_match_subsystem(enumerate, "input"); + udev_enumerate_scan_devices(enumerate); + struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate); + struct udev_list_entry *dev_list_entry; + + udev_list_entry_foreach(dev_list_entry, devices) { + const char * path = udev_list_entry_get_name(dev_list_entry); + struct udev_device *dev = udev_device_new_from_syspath(udev, path); + const char * node = udev_device_get_devnode(dev); + + dev = udev_device_get_parent( dev ); + const char * name = udev_device_get_sysattr_value(dev,"name"); + + SG_LOG(SG_INPUT,SG_ALERT, "name=" << (name?name:"") << ", node=" << (node?node:"")); + if( name && node ) + AddDevice( new FGLinuxInputDevice(name, node) ); + + udev_device_unref(dev); } - halcontext = libhal_ctx_new(); - - libhal_ctx_set_dbus_connection (halcontext, connection ); - dbus_error_init (&dbus_error); - - if( libhal_ctx_init( halcontext, &dbus_error )) { - - int num_devices = 0; - char ** devices = libhal_find_device_by_capability(halcontext, "input", &num_devices, NULL); - - for ( int i = 0; i < num_devices; i++) - AddHalDevice( devices[i] ); - - libhal_free_string_array (devices); - -//TODO: enable hotplug support -// libhal_ctx_set_user_data( halcontext, this ); -// libhal_ctx_set_device_added( halcontext, DeviceAddedCallback ); -// libhal_ctx_set_device_removed( halcontext, DeviceRemovedCallback ); - } else { - if(dbus_error_is_set (&dbus_error) ) { - SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to hald: " << dbus_error.message); - dbus_error_free (&dbus_error); - } else { - SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to hald." ); - } - - libhal_ctx_free (halcontext); - halcontext = NULL; - } -} - -void FGLinuxEventInput::AddHalDevice( const char * udi ) -{ - char * device = libhal_device_get_property_string( halcontext, udi, "input.device", NULL); - char * product = libhal_device_get_property_string( halcontext, udi, "input.product", NULL); - - if( product != NULL && device != NULL ) - AddDevice( new FGLinuxInputDevice(product, device) ); - else - SG_LOG( SG_INPUT, SG_ALERT, "Can't get device or product property of " << udi ); - - if( device != NULL ) libhal_free_string( device ); - if( product != NULL ) libhal_free_string( product ); + udev_unref(udev); } diff --git a/src/Input/FGLinuxEventInput.hxx b/src/Input/FGLinuxEventInput.hxx index f3bfa044f..5fcd81e24 100644 --- a/src/Input/FGLinuxEventInput.hxx +++ b/src/Input/FGLinuxEventInput.hxx @@ -25,7 +25,6 @@ #include "FGEventInput.hxx" #include -#include struct FGLinuxEventData : public FGEventData { FGLinuxEventData( struct input_event & event, double dt, int modifiers ) : @@ -71,10 +70,7 @@ public: virtual void update (double dt); virtual void postinit(); - void AddHalDevice( const char * udi ); protected: - LibHalContext *halcontext; - }; #endif From 9933a7cb4ab5594eb89b70cd736ae248bfca7fb0 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sun, 4 Dec 2011 14:37:25 +0100 Subject: [PATCH 4/8] cmake: add support for Torsten's UDev EventInput (Hopefully meeting Torsten's quality expectations) --- CMakeLists.txt | 25 ++++++++----- CMakeModules/FindDBus.cmake | 72 ------------------------------------- CMakeModules/FindUDev.cmake | 53 +++++++++++++++++++++++++++ src/Input/CMakeLists.txt | 33 ++++++++--------- src/Main/CMakeLists.txt | 11 +++--- 5 files changed, 92 insertions(+), 102 deletions(-) delete mode 100644 CMakeModules/FindDBus.cmake create mode 100644 CMakeModules/FindUDev.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ffea91c25..6e356fbec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,8 +80,11 @@ IF(APPLE) list(APPEND PLATFORM_LIBS ${COCOA_LIBRARY} ${CORESERVICES_LIBRARY}) elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") - # disabled while DBus / HAL / udev issues are decided - #set(EVENT_INPUT_DEFAULT 1) + find_package(UDev) + + if(UDEV_FOUND) + set(EVENT_INPUT_DEFAULT 1) + endif(UDEV_FOUND) endif() find_package(Git) @@ -160,19 +163,23 @@ endif (MSVC AND MSVC_3RDPARTY_ROOT) if(EVENT_INPUT) message(STATUS "checking event-based Input") - + IF(APPLE) elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") - find_package(DBus) - if(NOT DBUS_FOUND) - message(WARNING "DBus not found, event input will be disabled") - set(EVENT_INPUT 0) - endif() - + if(NOT UDEV_FOUND) + message(WARNING "UDev not found, event input is disabled!") + set(EVENT_INPUT 0) + else() + set(EVENT_INPUT_LIBRARIES ${UDEV_LIBRARIES}) + endif() + else() message(WARNING "event input is not supported on this platform yet") endif() + + # Keep PLIB INPUT enabled as long as EventInput does not replace current joystick configurations. + set(ENABLE_PLIB_JOYSTICK 1) else(EVENT_INPUT) set(ENABLE_PLIB_JOYSTICK 1) endif(EVENT_INPUT) diff --git a/CMakeModules/FindDBus.cmake b/CMakeModules/FindDBus.cmake deleted file mode 100644 index f227cc297..000000000 --- a/CMakeModules/FindDBus.cmake +++ /dev/null @@ -1,72 +0,0 @@ -# - Try to find the low-level D-Bus library -# Once done this will define -# -# DBUS_FOUND - system has D-Bus -# DBUS_INCLUDE_DIR - the D-Bus include directory -# DBUS_ARCH_INCLUDE_DIR - the D-Bus architecture-specific include directory -# DBUS_LIBRARIES - the libraries needed to use D-Bus - -# Copyright (c) 2008, Kevin Kofler, -# modeled after FindLibArt.cmake: -# Copyright (c) 2006, Alexander Neundorf, -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) - - # in cache already - SET(DBUS_FOUND TRUE) - -else (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) - - IF (NOT WIN32) - FIND_PACKAGE(PkgConfig) - IF (PKG_CONFIG_FOUND) - # use pkg-config to get the directories and then use these values - # in the FIND_PATH() and FIND_LIBRARY() calls - pkg_check_modules(_DBUS_PC QUIET dbus-1) - ENDIF (PKG_CONFIG_FOUND) - ENDIF (NOT WIN32) - - FIND_PATH(DBUS_INCLUDE_DIR dbus/dbus.h - ${_DBUS_PC_INCLUDE_DIRS} - /usr/include - /usr/include/dbus-1.0 - /usr/local/include - ) - - FIND_PATH(DBUS_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h - ${_DBUS_PC_INCLUDE_DIRS} - /usr/lib${LIB_SUFFIX}/include - /usr/lib${LIB_SUFFIX}/dbus-1.0/include - /usr/lib64/include - /usr/lib64/dbus-1.0/include - /usr/lib/include - /usr/lib/dbus-1.0/include - ) - - FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 dbus - PATHS - ${_DBUS_PC_LIBDIR} - ) - - - if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) - set(DBUS_FOUND TRUE) - endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) - - - if (DBUS_FOUND) - if (NOT DBus_FIND_QUIETLY) - message(STATUS "Found D-Bus: ${DBUS_LIBRARIES}") - endif (NOT DBus_FIND_QUIETLY) - else (DBUS_FOUND) - if (DBus_FIND_REQUIRED) - message(FATAL_ERROR "Could NOT find D-Bus") - endif (DBus_FIND_REQUIRED) - endif (DBUS_FOUND) - - MARK_AS_ADVANCED(DBUS_INCLUDE_DIR DBUS_ARCH_INCLUDE_DIR DBUS_LIBRARIES) - -endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) diff --git a/CMakeModules/FindUDev.cmake b/CMakeModules/FindUDev.cmake new file mode 100644 index 000000000..dc363bafc --- /dev/null +++ b/CMakeModules/FindUDev.cmake @@ -0,0 +1,53 @@ +# Configure libudev environment +# +# UDEV_FOUND - system has a libudev +# UDEV_INCLUDE_DIR - where to find header files +# UDEV_LIBRARIES - the libraries to link against udev +# UDEV_STABLE - it's true when is the version greater or equals to 143 - version when the libudev was stabilized in its API +# +# copyright (c) 2011 Petr Vanek +# Redistribution and use of this file is allowed according to the terms of the BSD license. +# + +FIND_PATH( + UDEV_INCLUDE_DIR + libudev.h + /usr/include + /usr/local/include + ${UDEV_PATH_INCLUDES} +) + +FIND_LIBRARY( + UDEV_LIBRARIES + NAMES udev libudev + PATHS + /usr/${CMAKE_INSTALL_LIBDIR} + /usr/local/${CMAKE_INSTALL_LIBDIR} + ${UDEV_PATH_LIB} +) + +IF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR) + SET(UDEV_FOUND "YES") + execute_process(COMMAND pkg-config --atleast-version=143 libudev RESULT_VARIABLE UDEV_STABLE) + # retvale is 0 of the condition is "true" so we need to negate the value... + if (UDEV_STABLE) + set(UDEV_STABLE 0) + else (UDEV_STABLE) + set(UDEV_STABLE 1) + endif (UDEV_STABLE) + message(STATUS "libudev stable: ${UDEV_STABLE}") +ENDIF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR) + +IF (UDEV_FOUND) + MESSAGE(STATUS "Found UDev: ${UDEV_LIBRARIES}") + MESSAGE(STATUS " include: ${UDEV_INCLUDE_DIR}") +ELSE (UDEV_FOUND) + MESSAGE(STATUS "UDev not found.") + MESSAGE(STATUS "UDev: You can specify includes: -DUDEV_PATH_INCLUDES=/opt/udev/include") + MESSAGE(STATUS " currently found includes: ${UDEV_INCLUDE_DIR}") + MESSAGE(STATUS "UDev: You can specify libs: -DUDEV_PATH_LIB=/opt/udev/lib") + MESSAGE(STATUS " currently found libs: ${UDEV_LIBRARIES}") + IF (UDev_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find UDev library") + ENDIF (UDev_FIND_REQUIRED) +ENDIF (UDEV_FOUND) diff --git a/src/Input/CMakeLists.txt b/src/Input/CMakeLists.txt index b38ffc8cb..a0031c2cb 100644 --- a/src/Input/CMakeLists.txt +++ b/src/Input/CMakeLists.txt @@ -4,7 +4,7 @@ IF(APPLE) set(EVENT_INPUT_SOURCES FGMacOSXEventInput.cxx) set(EVENT_INPUT_HEADERS FGMacOSXEventInput.hxx) elseif(MSVC) - message(STATUS "EventInput not implemented for Windows yet") + message(STATUS "EventInput not implemented for Windows yet") else() set(EVENT_INPUT_SOURCES FGLinuxEventInput.cxx) set(EVENT_INPUT_HEADERS FGLinuxEventInput.hxx) @@ -21,36 +21,37 @@ set(SOURCES FGMouseInput.cxx input.cxx ) - + set(HEADERS FGButton.hxx - FGCommonInput.hxx - FGDeviceConfigurationMap.hxx - FGEventInput.hxx - FGJoystickInput.hxx - FGKeyboardInput.hxx - FGMouseInput.hxx - input.hxx + FGCommonInput.hxx + FGDeviceConfigurationMap.hxx + FGEventInput.hxx + FGJoystickInput.hxx + FGKeyboardInput.hxx + FGMouseInput.hxx + input.hxx ) - + if(EVENT_INPUT) list(APPEND SOURCES ${EVENT_INPUT_SOURCES}) list(APPEND SOURCES ${EVENT_INPUT_HEADERS}) - include_directories(${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR}) + include_directories(${UDEV_INCLUDE_DIR}) + add_definitions(-DWITH_EVENTINPUT) endif() - + set(FGJS_SOURCES fgjs.cxx jsinput.cxx jssuper.cxx ) - + add_executable(fgjs ${FGJS_SOURCES}) target_link_libraries(fgjs - ${SIMGEAR_CORE_LIBRARIES} - ${PLIB_LIBRARIES} - ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) + ${SIMGEAR_CORE_LIBRARIES} + ${PLIB_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) add_executable(js_demo js_demo.cxx) diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt index 827e09f80..6a4df8c89 100644 --- a/src/Main/CMakeLists.txt +++ b/src/Main/CMakeLists.txt @@ -61,12 +61,12 @@ get_property(FG_LIBS GLOBAL PROPERTY FG_LIBS) #message(STATUS "SG libs ${SIMGEAR_LIBRARIES}") if(RTI_FOUND) - find_sg_component(hla SIMGEAR_LIBRARIES) - find_sg_component(rti13 SIMGEAR_LIBRARIES) - find_sg_component(rti SIMGEAR_LIBRARIES) - set(HLA_LIBRARIES ${RTI_LIBRARIES}) + find_sg_component(hla SIMGEAR_LIBRARIES) + find_sg_component(rti13 SIMGEAR_LIBRARIES) + find_sg_component(rti SIMGEAR_LIBRARIES) + set(HLA_LIBRARIES ${RTI_LIBRARIES}) else() - set(HLA_LIBRARIES "") + set(HLA_LIBRARIES "") endif() target_link_libraries(fgfs @@ -77,6 +77,7 @@ target_link_libraries(fgfs ${PLIB_LIBRARIES} ${JPEG_LIBRARY} ${HLA_LIBRARIES} + ${EVENT_INPUT_LIBRARIES} ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ${SIMGEAR_SCENE_LIBRARY_DEPENDENCIES} ${PLATFORM_LIBS} From 07aa70dce9a6a429a88cd8d9e77f4a228b35b24f Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sun, 4 Dec 2011 17:18:02 +0100 Subject: [PATCH 5/8] sound: fix sound-buffer-in-use issue FGFX objects must be dereferenced early enough, and sound manager must be removed late enough - otherwise openal complains about resources being still in use when tryin to remove buffers. Also: do not create FGFX objects for AI/MP aircraft, when AI sound is disabled. --- src/AIModel/AIBase.cxx | 4 +++- src/Main/globals.cxx | 4 +++- src/Model/acmodel.cxx | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 95d023296..230837621 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -228,7 +228,7 @@ void FGAIBase::update(double dt) { pitch*speed ); _fx->set_velocity( velocity ); } - else if (_aimodel) + else if ((_aimodel)&&(fgGetBool("/sim/sound/aimodels/enabled",false))) { string fxpath = _aimodel->get_sound_path(); if (fxpath != "") @@ -492,6 +492,8 @@ void FGAIBase::unbind() { props->setBoolValue("/sim/controls/radar/", true); + // drop reference to sound effects now + _fx = 0; } double FGAIBase::UpdateRadar(FGAIManager* manager) { diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 00dd943dc..4eb26f21f 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -171,7 +171,8 @@ FGGlobals::~FGGlobals() ai->unbind(); delete ai; } - + SGSubsystem* sound = subsystem_mgr->remove("sound"); + subsystem_mgr->shutdown(); subsystem_mgr->unbind(); delete subsystem_mgr; @@ -205,6 +206,7 @@ FGGlobals::~FGGlobals() delete tacanlist; delete carrierlist; delete channellist; + delete sound; } diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index 3c9faaf23..3b0658b0a 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -91,6 +91,9 @@ FGAircraftModel::reinit() void FGAircraftModel::deinit() { + // drop reference + _fx = 0; + if (!_aircraft) { return; } From fcfb905ef17f22ced92daabc47fcb812d06a8a0b Mon Sep 17 00:00:00 2001 From: Durk Talsma Date: Sun, 4 Dec 2011 17:31:02 +0100 Subject: [PATCH 6/8] Make sure not to disable the entire ATC system when handling special cases. --- src/ATC/atc_mgr.cxx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index 33d90a9a4..0fbec1313 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -100,7 +100,7 @@ void FGATCManager::init() { FGAirport *apt = FGAirport::findByIdent(airport); - if (apt && onGround && !runway.empty()) { + if (apt && onGround) {// && !runway.empty()) { FGAirportDynamics* dcs = apt->getDynamics(); int park_index = dcs->getNrOfParkings() - 1; //cerr << "found information: " << runway << " " << airport << ": parking = " << parking << endl; @@ -111,16 +111,21 @@ void FGATCManager::init() { "Failed to find parking position " << parking << " at airport " << airport << " at " << SG_ORIGIN); } + // No valid parking location, so either at the runway or at a random location. if (parking.empty() || (park_index < 0)) { - controller = apt->getDynamics()->getTowerController(); - int stationFreq = apt->getDynamics()->getTowerFrequency(2); - //cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl; - fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0)); - leg = 3; - string fltType = "ga"; - fp->setRunway(runway); - fp->createTakeOff(&ai_ac, false, apt, 0, fltType); - ai_ac.setTakeOffStatus(2); + if (!runway.empty()) { + controller = apt->getDynamics()->getTowerController(); + int stationFreq = apt->getDynamics()->getTowerFrequency(2); + //cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl; + fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0)); + leg = 3; + string fltType = "ga"; + fp->setRunway(runway); + fp->createTakeOff(&ai_ac, false, apt, 0, fltType); + ai_ac.setTakeOffStatus(2); + } else { + // We're on the ground somewhere. Handle this case later. + } } else { controller = apt->getDynamics()->getStartupController(); int stationFreq = apt->getDynamics()->getGroundFrequency(1); From 6b1391e404b11e0d9a5bfcd11c1307e2e9531616 Mon Sep 17 00:00:00 2001 From: Vivian Meazza Date: Mon, 21 Nov 2011 09:09:12 +0000 Subject: [PATCH 7/8] Make parameter "roll-factor" settable in scenario files Signed-off-by: Vivian Meazza --- src/AIModel/AIShip.cxx | 5 +++++ src/AIModel/AIShip.hxx | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index b7ce2ef34..c6cfa7a05 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -101,6 +101,7 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) { setFixedTurnRadius(scFileNode->getDoubleValue("fixed-turn-radius-ft", 500)); setSpeedConstant(scFileNode->getDoubleValue("speed-constant", 0.5)); setSMPath(scFileNode->getStringValue("submodel-path", "")); + setRollFactor(scFileNode->getDoubleValue("roll-factor", 1)); if (!flightplan.empty()) { SG_LOG(SG_AI, SG_ALERT, "getting flightplan: " << _name ); @@ -560,6 +561,10 @@ void FGAIShip::setFixedTurnRadius(double ftr) { _fixed_turn_radius = ftr; } +void FGAIShip::setRollFactor(double rf) { + _roll_factor = rf * -0.0083335; +} + void FGAIShip::setInitialTunnel(bool t) { _initial_tunnel = t; setTunnel(_initial_tunnel); diff --git a/src/AIModel/AIShip.hxx b/src/AIModel/AIShip.hxx index 591aa6166..f82a14f8d 100644 --- a/src/AIModel/AIShip.hxx +++ b/src/AIModel/AIShip.hxx @@ -61,11 +61,14 @@ public: void setRudderConstant(double rc); void setSpeedConstant(double sc); void setFixedTurnRadius(double ft); + void setRollFactor(double rf); + void setTunnel(bool t); void setInitialTunnel(bool t); void setWPNames(); void setWPPos(); + double sign(double x); bool _hdg_lock; From f720f7645629822903707904bef073c94858514c Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 4 Dec 2011 22:08:56 +0200 Subject: [PATCH 8/8] Hopefully fix windows compilation error --- src/Radio/itm.cpp | 4 ++-- src/Radio/radio.cxx | 8 ++++---- src/Radio/radio.hxx | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Radio/itm.cpp b/src/Radio/itm.cpp index 5fe6abc8e..1b970d067 100644 --- a/src/Radio/itm.cpp +++ b/src/Radio/itm.cpp @@ -39,8 +39,8 @@ #include #include -const float THIRD = (1.0/3.0); -const float f_0 = 47.7; // 47.7 MHz from [Alg 1.1], to convert frequency into wavenumber and vica versa +const double THIRD = (1.0/3.0); +const double f_0 = 47.7; // 47.7 MHz from [Alg 1.1], to convert frequency into wavenumber and vica versa using namespace std; diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index be8dc1ef3..4c80a9fe5 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -375,14 +375,14 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate, pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum); if( _root_node->getBoolValue( "use-clutter-attenuation", false ) ) - clutterLoss(frq_mhz, distance_m, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss); + clutterLoss(frq_mhz, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss); } else { point_to_point(itm_elev, transmitter_height, receiver_height, eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate, pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum); if( _root_node->getBoolValue( "use-clutter-attenuation", false ) ) - clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss); + clutterLoss(frq_mhz, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss); } double pol_loss = 0.0; @@ -415,11 +415,11 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i * We are only worried about clutter loss, terrain influence * on the first Fresnel zone is calculated in the ITM functions ***/ -void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque materials, +void FGRadioTransmission::clutterLoss(double freq, double itm_elev[], deque materials, double transmitter_height, double receiver_height, int p_mode, double horizons[], double &clutter_loss) { - distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points + double distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone int mat = 0; diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index 7b07d927e..ef0b19e7f 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -56,7 +56,7 @@ private: double polarization_loss(); double ITM_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air); double LOS_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air); - void clutterLoss(double freq, double distance_m, double itm_elev[], std::deque materials, + void clutterLoss(double freq, double itm_elev[], std::deque materials, double transmitter_height, double receiver_height, int p_mode, double horizons[], double &clutter_loss); void get_material_properties(string mat_name, double &height, double &density);