From 53103ac15e42e1c94436fa205066bbd95f66c75a Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Sun, 19 Mar 2017 19:34:54 +0100 Subject: [PATCH 1/8] YASim: update CLI usage message. --- src/FDM/YASim/yasim-test.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/FDM/YASim/yasim-test.cpp b/src/FDM/YASim/yasim-test.cpp index 71c4ac8ef..5b2b8e2f5 100644 --- a/src/FDM/YASim/yasim-test.cpp +++ b/src/FDM/YASim/yasim-test.cpp @@ -174,12 +174,15 @@ void yasim_drag(Airplane* a, const float aoa, const float alt, int cfg = CONFIG_ int usage() { - fprintf(stderr, "Usage: yasim [-g [-a alt] [-s kts] [-approach | -cruise] ]\n"); - fprintf(stderr, " yasim [-d [-a alt] [-approach | -cruise] ]\n"); - fprintf(stderr, " yasim [-m]\n"); - fprintf(stderr, " -g print lift/drag table: aoa, lift, drag, lift/drag \n"); - fprintf(stderr, " -d print drag over TAS: kts, drag\n"); - fprintf(stderr, " -m print mass distribution table: id, x, y, z, mass \n"); + fprintf(stderr, "Usage: \n"); + fprintf(stderr, " yasim [-g [-a meters] [-s kts] [-approach | -cruise] ]\n"); + fprintf(stderr, " yasim [-d [-a meters] [-approach | -cruise] ]\n"); + fprintf(stderr, " yasim [-m]\n"); + fprintf(stderr, " -g print lift/drag table: aoa, lift, drag, lift/drag \n"); + fprintf(stderr, " -d print drag over TAS: kts, drag\n"); + fprintf(stderr, " -a set altitude in meters!\n"); + fprintf(stderr, " -s set speed in knots\n"); + fprintf(stderr, " -m print mass distribution table: id, x, y, z, mass \n"); return 1; } From f7359d969910ad71abb38638905e75aa49970a58 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Tue, 21 Mar 2017 22:46:33 +0100 Subject: [PATCH 2/8] YASim: add bug warning messages. --- src/FDM/YASim/FGFDM.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index 40bf6efa2..d981eb516 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -832,7 +832,12 @@ Wing* FGFDM::parseWing(XMLAttributes* a, const char* type, Version * version) w->setSweep(attrf(a, "sweep", 0) * DEG2RAD); w->setTaper(attrf(a, "taper", 1)); w->setDihedral(attrf(a, "dihedral", defDihed) * DEG2RAD); - w->setCamber(attrf(a, "camber", 0)); + + float camber = attrf(a, "camber", 0); + if (!version->isVersionOrNewer(Version::YASIM_VERSION_2017_2) && (camber == 0)) { + SG_LOG(SG_FLIGHT, SG_DEV_WARN, "YASIM warning: versions before 2017.2 are buggy for wings with camber=0"); + } + w->setCamber(camber); // These come in with positive indicating positive AoA, but the // internals expect a rotation about the left-pointing Y axis, so From 50110b0cd6f9aebb34e1e9c7077a3ab7e6837430 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Tue, 21 Mar 2017 22:47:07 +0100 Subject: [PATCH 3/8] YASIM: minor change to allow RigidBody addMass and setMass to trigger aggregation correctly. (not a problem up to now, just to be safe in future) --- src/FDM/YASim/RigidBody.cpp | 3 +-- src/FDM/YASim/RigidBody.hpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/FDM/YASim/RigidBody.cpp b/src/FDM/YASim/RigidBody.cpp index e1fb94b70..495098525 100644 --- a/src/FDM/YASim/RigidBody.cpp +++ b/src/FDM/YASim/RigidBody.cpp @@ -55,13 +55,12 @@ void RigidBody::setMass(int handle, float mass) void RigidBody::setMass(int handle, float mass, const float* pos, bool isStatic) { - _masses[handle].m = mass; _masses[handle].isStatic = isStatic; Math::set3(pos, _masses[handle].p); + setMass(handle, mass); if (_bodyN != 0) { SGPropertyNode_ptr n = _bodyN->getChild("mass", handle, true); n->getNode("isStatic", true)->setValue(isStatic); - n->getNode("mass", true)->setFloatValue(mass); n->getNode("pos-x", true)->setFloatValue(pos[0]); n->getNode("pos-y", true)->setFloatValue(pos[1]); n->getNode("pos-z", true)->setFloatValue(pos[2]); diff --git a/src/FDM/YASim/RigidBody.hpp b/src/FDM/YASim/RigidBody.hpp index d7ca39939..4b982e070 100644 --- a/src/FDM/YASim/RigidBody.hpp +++ b/src/FDM/YASim/RigidBody.hpp @@ -82,7 +82,7 @@ public: void setBodySpin(const float* rotation) { Math::set3(rotation, _spin); } // Returns the center of gravity of the masses, in the body - // coordinate system. + // coordinate system. valid only after recalc() void getCG(float* cgOut) { Math::set3(_cg, cgOut); } // Returns the acceleration of the body's c.g. relative to the From 7db8ed17c4b97f376745f6dd3dd6472ba446ccf5 Mon Sep 17 00:00:00 2001 From: Alessandro Menti Date: Sun, 26 Mar 2017 12:10:15 +0200 Subject: [PATCH 4/8] Test suite: add GPerfTools and system SQLite linking fixes If GPerfTools and/or the SYSTEM_SQLITE options are enabled, the test suite fails to build (GPerfTools is not linked explicitly in CMakeLists.txt, but becomes required by SimGear, so the linker failes with an "undefined reference" error; the SQLite library the test suite links against is always hardcoded to the FG-provided one). This patch adds the GPerfTools library to the target link libraries (if the profiler is enabled) and links to the system SQLite library whenever SYSTEM_SQLITE is enabled. --- tests/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 24f385908..af4842a31 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -90,6 +90,10 @@ set_target_properties (fgtestlib COMPILE_DEFINITIONS "FG_TESTLIB" ) +if(FG_HAVE_GPERFTOOLS) + include_directories(${GooglePerfTools_INCLUDE_DIR}) + target_link_libraries(fgtestlib ${GooglePerfTools_LIBRARIES}) +endif() target_link_libraries(fgtestlib SimGearCore ${PLATFORM_LIBS}) add_executable(fgtest fgTestDriver.cxx) @@ -97,9 +101,9 @@ target_link_libraries(fgtest fgtestlib) # repeat this section for each unit-test executable add_executable(testnavs test_navaids2.cxx) -target_link_libraries(testnavs fgtestlib fgsqlite3) +target_link_libraries(testnavs fgtestlib ${SQLITE3_LIBRARY}) add_test(testnavs ${EXECUTABLE_OUTPUT_PATH}/testnavs) add_executable(testflightplan test_flightplan.cxx) -target_link_libraries(testflightplan fgtestlib fgsqlite3) +target_link_libraries(testflightplan fgtestlib ${SQLITE3_LIBRARY}) add_test(testflightplan ${EXECUTABLE_OUTPUT_PATH}/testflightplan) From 09fe744de0f99eecf317d7dbc8866fa9dccca55f Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 26 Mar 2017 12:15:29 +0100 Subject: [PATCH 5/8] Test helper CMake macro. Also build the test code first, so tests can reside in source tree as well as the test tree. Finally, build local Sqlite with -fpic to give consistent linkage when using either built-in or system sqlite. --- 3rdparty/sqlite3/CMakeLists.txt | 2 +- CMakeLists.txt | 5 +++-- tests/CMakeLists.txt | 16 ++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/3rdparty/sqlite3/CMakeLists.txt b/3rdparty/sqlite3/CMakeLists.txt index cf1036fb4..8ddae70e3 100644 --- a/3rdparty/sqlite3/CMakeLists.txt +++ b/3rdparty/sqlite3/CMakeLists.txt @@ -2,4 +2,4 @@ add_definitions(-DSQLITE_OMIT_LOAD_EXTENSION) add_definitions(-DNDEBUG) add_library(fgsqlite3 sqlite3.c) -set_target_properties(fgsqlite3 PROPERTIES COMPILE_FLAGS "-fno-fast-math") +set_target_properties(fgsqlite3 PROPERTIES COMPILE_FLAGS "-fpic -fno-fast-math") diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d7e2ac37..b83550e22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -509,8 +509,6 @@ configure_file ( add_subdirectory(3rdparty) add_subdirectory(utils) -add_subdirectory(src) -add_subdirectory(man) if(ENABLE_TESTS) # enable CTest / make test target @@ -528,6 +526,9 @@ else() message(STATUS "Tests: DISABLED") endif(ENABLE_TESTS) +add_subdirectory(src) +add_subdirectory(man) + #----------------------------------------------------------------------------- ### uninstall target #----------------------------------------------------------------------------- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index af4842a31..3033669d5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -94,16 +94,16 @@ if(FG_HAVE_GPERFTOOLS) include_directories(${GooglePerfTools_INCLUDE_DIR}) target_link_libraries(fgtestlib ${GooglePerfTools_LIBRARIES}) endif() -target_link_libraries(fgtestlib SimGearCore ${PLATFORM_LIBS}) +target_link_libraries(fgtestlib SimGearCore ${PLATFORM_LIBS} ${SQLITE3_LIBRARY}) add_executable(fgtest fgTestDriver.cxx) target_link_libraries(fgtest fgtestlib) -# repeat this section for each unit-test executable -add_executable(testnavs test_navaids2.cxx) -target_link_libraries(testnavs fgtestlib ${SQLITE3_LIBRARY}) -add_test(testnavs ${EXECUTABLE_OUTPUT_PATH}/testnavs) +macro(flightgear_test name sources) + add_executable(${name} ${sources}) + target_link_libraries(${name} fgtestlib) + add_test(${name} ${EXECUTABLE_OUTPUT_PATH}/${name}) +endmacro() -add_executable(testflightplan test_flightplan.cxx) -target_link_libraries(testflightplan fgtestlib ${SQLITE3_LIBRARY}) -add_test(testflightplan ${EXECUTABLE_OUTPUT_PATH}/testflightplan) +flightgear_test(test_navs test_navaids2.cxx) +flightgear_test(test_flightplan test_flightplan.cxx) From feb5d599d03cd5a5191cd6b88845490ab80431f5 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sun, 26 Mar 2017 21:49:26 +0100 Subject: [PATCH 6/8] Replace "tile-manager" with "scenery" --- src/Main/fg_scene_commands.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main/fg_scene_commands.cxx b/src/Main/fg_scene_commands.cxx index 1342ccf1b..7e1ed2ddf 100644 --- a/src/Main/fg_scene_commands.cxx +++ b/src/Main/fg_scene_commands.cxx @@ -231,7 +231,7 @@ do_tile_cache_reload (const SGPropertyNode * arg) master_freeze->setBoolValue(true); } - globals->get_subsystem("tile-manager")->reinit(); + globals->get_subsystem("scenery")->reinit(); if ( !freeze ) { master_freeze->setBoolValue(false); From 58a7f2c5c2573e8589a5d5a49b134a9f0b604f65 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 27 Mar 2017 15:37:54 +0100 Subject: [PATCH 7/8] Unit-test for initPosition. Only basic, but can be expanded incrementally now --- src/Include/config_cmake.h.in | 1 + src/Main/CMakeLists.txt | 4 + src/Main/options.cxx | 12 ++- src/Main/options.hxx | 7 ++ src/Main/positioninit.cxx | 138 +++++++++++++++++----------------- tests/CMakeLists.txt | 4 +- tests/unitTestHelpers.cxx | 15 +++- tests/unitTestHelpers.hxx | 2 + 8 files changed, 113 insertions(+), 70 deletions(-) diff --git a/src/Include/config_cmake.h.in b/src/Include/config_cmake.h.in index cd5b9fb91..aa3254a4b 100644 --- a/src/Include/config_cmake.h.in +++ b/src/Include/config_cmake.h.in @@ -34,6 +34,7 @@ #define PKGLIBDIR "@FG_DATA_DIR@" #define FGSRCDIR "@PROJECT_SOURCE_DIR@" +#define FGBUILDDIR "@PROJECT_BINARY_DIR@" #define WEB_BROWSER "@WEB_BROWSER@" // Ensure FG_HAVE_xxx always have a value diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt index 640c1ce7a..a8c47a7df 100644 --- a/src/Main/CMakeLists.txt +++ b/src/Main/CMakeLists.txt @@ -184,3 +184,7 @@ if(ENABLE_METAR) install(TARGETS metar RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() + +if (ENABLE_TESTS) + flightgear_test(posinit test_posinit.cxx) +endif() diff --git a/src/Main/options.cxx b/src/Main/options.cxx index b18855661..d1e2fd45d 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -95,7 +95,7 @@ using namespace flightgear; #define NEW_DEFAULT_MODEL_HZ 120 -static flightgear::Options* shared_instance = NULL; +static flightgear::Options* shared_instance = nullptr; static double atof( const string& str ) @@ -1979,6 +1979,14 @@ Options* Options::sharedInstance() return shared_instance; } +void Options::reset() +{ + if (shared_instance != nullptr) { + delete shared_instance; + shared_instance = nullptr; + } +} + Options::Options() : p(new OptionsPrivate()) { @@ -2034,7 +2042,9 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath) } if (!p->shouldLoadDefaultConfig) { +#if !defined(FG_TESTLIB) setupRoot(argc, argv); +#endif return; } diff --git a/src/Main/options.hxx b/src/Main/options.hxx index 6fd9954ef..4ce9fe067 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -67,6 +67,13 @@ private: public: static Options* sharedInstance(); + /** + * Delete the entire options object. Use with a degree of care, no code + * should ever be caching the Options pointer but this has not actually been + * checked across the whole code :) + */ + static void reset(); + ~Options(); /** diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index 0ccb46a10..8e552a4a5 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -46,7 +46,7 @@ using std::string; namespace flightgear { - + /// to avoid blocking when metar-fetch is enabled, but the network is /// unresponsive, we need a timeout value. This value is reset on initPosition, /// and tracked through each call to finalizePosition. @@ -54,7 +54,7 @@ static SGTimeStamp global_finalizeTime; static bool global_callbackRegistered = false; static void finalizePosition(); - + // Set current tower position lon/lat given an airport id static bool fgSetTowerPosFromAirportID( const string& id) { const FGAirport *a = fgFindAirportID( id); @@ -67,11 +67,11 @@ static bool fgSetTowerPosFromAirportID( const string& id) { } else { return false; } - + } class FGTowerLocationListener : public SGPropertyChangeListener { - + void valueChanged(SGPropertyNode* node) { string id(node->getStringValue()); if (fgGetBool("/sim/tower/auto-position",true)) @@ -104,12 +104,12 @@ class FGClosestTowerLocationListener : public SGPropertyChangeListener }; void initTowerLocationListener() { - + SGPropertyChangeListener* tll = new FGTowerLocationListener(); globals->addListenerToCleanup(tll); fgGetNode("/sim/tower/airport-id", true) ->addChangeListener( tll, true ); - + FGClosestTowerLocationListener* ntcl = new FGClosestTowerLocationListener(); globals->addListenerToCleanup(ntcl); fgGetNode("/sim/airport/closest-airport-id", true) @@ -144,7 +144,7 @@ static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double if (aTargetHeading == HUGE_VAL) { aTargetHeading = aHeading; } - + if ( fabs( fgGetDouble("/sim/presets/offset-distance-nm") ) > SG_EPSILON ) { double offsetDistance = fgGetDouble("/sim/presets/offset-distance-nm"); offsetDistance *= SG_NM_TO_METER; @@ -153,13 +153,13 @@ static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double offsetAzimuth = fgGetDouble("/sim/presets/offset-azimuth-deg"); aHeading = aTargetHeading; } - + SGGeod offset; double az2; // dummy SGGeodesy::direct(startPos, offsetAzimuth + 180, offsetDistance, offset, az2); startPos = offset; } - + setInitialPosition(startPos, aHeading); } @@ -176,7 +176,7 @@ boost::tuple runwayStartPos(FGRunwayRef runway) FGGroundNetwork* groundNet = runway->airport()->groundNetwork(); // add a margin, try to keep the entire aeroplane comfortable off the - // runway. + // runway. double margin = startOffset + (runway->widthM() * 1.5); FGTaxiNodeRef taxiNode = groundNet ? groundNet->findNearestNodeOffRunway(pos, runway, margin) : 0; if (taxiNode) { @@ -196,12 +196,12 @@ boost::tuple runwayStartPos(FGRunwayRef runway) static bool setPosFromAirportIDandHdg( const string& id, double tgt_hdg ) { if ( id.empty() ) return false; - + // set initial position from runway and heading SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position from airport code " << id << " heading " << tgt_hdg ); - + const FGAirport* apt = fgFindAirportID(id); if (!apt) return false; @@ -231,7 +231,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par SGPath acData; if ( id.empty() ) return false; - + const FGAirport* apt = fgFindAirportID(id); if (!apt) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport " << id ); @@ -247,11 +247,11 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par setInitialPosition(apt->geod(), 0.0); return true; } - + ParkingAssignment pka; double radius = fgGetDouble("/sim/dimensions/radius-m"); if ((parkpos == "AVAILABLE") && (radius > 0)) { - + try { acData = globals->get_fg_home(); acData.append("aircraft-data"); @@ -265,7 +265,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par } catch (const sg_exception &) { SG_LOG(SG_GENERAL, SG_INFO, "Could not load aircraft aircrat type and operator information from: " << acData << ". Using defaults"); - + // cout << path.str() << endl; } if (fltType.empty() || fltType == "NONE") { @@ -278,8 +278,8 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par "Aircraft operator information not found in: " << acData << ". Using default value"); acOperator = fgGetString("/sim/aircraft-operator" ); } - - + + pka = dcs->getAvailableParking(radius, fltType, acType, acOperator); if (pka.isValid()) { // why is the following line necessary? @@ -291,7 +291,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par return false; } } else { - + pka = dcs->getParkingByName(parkpos); if (!pka.isValid()) { SG_LOG( SG_GENERAL, SG_ALERT, @@ -303,9 +303,9 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par fgGetString("/sim/presets/parkpos"); fgSetString("/sim/presets/parkpos", pka.parking()->getName()); // The problem is, this line doesn't work because the ParkingAssignment's refcounting mechanism: - // The parking will be released after this function returns. - // As a temporary measure, I'll try to reserve the parking via the atc_manager, which should work, because it uses the same - // mechanism as the AI traffic code. + // The parking will be released after this function returns. + // As a temporary measure, I'll try to reserve the parking via the atc_manager, which should work, because it uses the same + // mechanism as the AI traffic code. dcs->setParkingAvailable(pka.parking(), false); fgApplyStartOffset(pka.parking()->geod(), pka.parking()->getHeading()); return true; @@ -316,12 +316,12 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy, bool rwy_req ) { if ( id.empty() ) return false; - + // set initial position from airport and runway number SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for " << id << ":" << rwy ); - + const FGAirport* apt = fgFindAirportID(id); if (!apt) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport:" << id); @@ -361,7 +361,7 @@ static void fgSetDistOrAltFromGlideSlope() { * SG_DEGREES_TO_RADIANS ; double od = fgGetDouble("/sim/presets/offset-distance-nm"); double alt = fgGetDouble("/sim/presets/altitude-ft"); - + double apt_elev = 0.0; if ( ! apt_id.empty() ) { apt_elev = fgGetAirportElev( apt_id ); @@ -371,7 +371,7 @@ static void fgSetDistOrAltFromGlideSlope() { } else { apt_elev = 0.0; } - + if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) { // set altitude from glideslope and offset-distance od *= SG_NM_TO_METER * SG_METER_TO_FEET; @@ -448,20 +448,22 @@ static bool fgSetPosFromNAV( const string& id, // Set current_options lon/lat given an aircraft carrier id static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) { - + // set initial position from runway and heading SGGeod geodPos; double heading; SGVec3d uvw; + +#ifndef FG_TESTLIB if (FGAIManager::getStartPosition(carrier, posid, geodPos, heading, uvw)) { double lon = geodPos.getLongitudeDeg(); double lat = geodPos.getLatitudeDeg(); double alt = geodPos.getElevationFt(); - + SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for " << carrier << " at lat = " << lat << ", lon = " << lon << ", alt = " << alt << ", heading = " << heading); - + fgSetDouble("/sim/presets/longitude-deg", lon); fgSetDouble("/sim/presets/latitude-deg", lat); fgSetDouble("/sim/presets/altitude-ft", alt); @@ -470,7 +472,7 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) { fgSetDouble("/position/latitude-deg", lat); fgSetDouble("/position/altitude-ft", alt); fgSetDouble("/orientation/heading-deg", heading); - + fgSetString("/sim/presets/speed-set", "UVW"); fgSetDouble("/velocities/uBody-fps", uvw(0)); fgSetDouble("/velocities/vBody-fps", uvw(1)); @@ -478,11 +480,13 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) { fgSetDouble("/sim/presets/uBody-fps", uvw(0)); fgSetDouble("/sim/presets/vBody-fps", uvw(1)); fgSetDouble("/sim/presets/wBody-fps", uvw(2)); - + fgSetBool("/sim/presets/onground", true); - + return true; - } else { + } else +#endif + { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate aircraft carrier = " << carrier ); return false; @@ -504,7 +508,7 @@ static bool fgSetPosFromFix( const string& id, PositionedID guid ) SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id ); return false; } - + fgApplyStartOffset(fix->geod(), fgGetDouble("/sim/presets/heading-deg")); return true; } @@ -517,22 +521,22 @@ bool initPosition() globals->get_event_mgr()->addTask("finalizePosition", &finalizePosition, 0.1); global_callbackRegistered = true; } - + double gs = fgGetDouble("/sim/presets/glideslope-deg") * SG_DEGREES_TO_RADIANS ; double od = fgGetDouble("/sim/presets/offset-distance-nm"); double alt = fgGetDouble("/sim/presets/altitude-ft"); - + bool set_pos = false; - + // If glideslope is specified, then calculate offset-distance or // altitude relative to glide slope if either of those was not // specified. if ( fabs( gs ) > 0.01 ) { fgSetDistOrAltFromGlideSlope(); } - - + + // If we have an explicit, in-range lon/lat, don't change it, just use it. // If not, check for an airport-id and use that. // If not, default to the middle of the KSFO field. @@ -546,7 +550,7 @@ bool initPosition() { set_pos = true; } - + string apt = fgGetString("/sim/presets/airport-id"); const bool apt_req = fgGetBool("/sim/presets/airport-requested"); string rwy_no = fgGetString("/sim/presets/runway"); @@ -564,21 +568,21 @@ bool initPosition() SGPropertyNode *hdg_preset = fgGetNode("/sim/presets/heading-deg", true); double hdg = hdg_preset->getDoubleValue(); - + // save some start parameters, so that we can later say what the // user really requested. TODO generalize that and move it to options.cxx static bool start_options_saved = false; if (!start_options_saved) { start_options_saved = true; SGPropertyNode *opt = fgGetNode("/sim/startup/options", true); - + opt->setDoubleValue("latitude-deg", lat_deg); opt->setDoubleValue("longitude-deg", lon_deg); opt->setDoubleValue("heading-deg", hdg); opt->setStringValue("airport", apt.c_str()); opt->setStringValue("runway", rwy_no.c_str()); } - + if (hdg > 9990.0) hdg = fgGetDouble("/environment/config/boundary/entry/wind-from-heading-deg", 270); @@ -602,7 +606,7 @@ bool initPosition() set_pos = true; } } - + if ( !set_pos && !apt.empty() && !rwy_no.empty() ) { // An airport + runway is requested if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) { @@ -613,7 +617,7 @@ bool initPosition() set_pos = true; } } - + if ( !set_pos && !apt.empty() ) { // An airport is requested (find runway closest to hdg) if ( setPosFromAirportIDandHdg( apt, hdg ) ) { @@ -624,38 +628,38 @@ bool initPosition() set_pos = true; } } - + if (hdg_preset->getDoubleValue() > 9990.0) hdg_preset->setDoubleValue(hdg); - + if ( !set_pos && !vor.empty() ) { // a VOR is requested if ( fgSetPosFromNAV( vor, vor_freq, FGPositioned::VOR, navaidId ) ) { set_pos = true; } } - + if ( !set_pos && !ndb.empty() ) { // an NDB is requested if ( fgSetPosFromNAV( ndb, ndb_freq, FGPositioned::NDB, navaidId ) ) { set_pos = true; } } - + if ( !set_pos && !carrier.empty() ) { // an aircraft carrier is requested if ( fgSetPosFromCarrier( carrier, parkpos ) ) { set_pos = true; } } - + if ( !set_pos && !fix.empty() ) { // a Fix is requested if ( fgSetPosFromFix( fix, navaidId ) ) { set_pos = true; } } - + if ( !set_pos ) { // No lon/lat specified, no airport specified, use the default airport // TODO: don't hardcode this. Really. @@ -665,37 +669,37 @@ bool initPosition() fgSetDouble("/sim/presets/longitude-deg", airportGeod.getLongitudeDeg()); fgSetDouble("/sim/presets/latitude-deg", airportGeod.getLatitudeDeg()); } else { - // So, the default airport is unknown? We are in serious trouble. + // So, the default airport is unknown? We are in serious trouble. // Let's hope KSFO still exists somehow fgSetDouble("/sim/presets/longitude-deg", -122.374843); fgSetDouble("/sim/presets/latitude-deg", 37.619002); SG_LOG(SG_GENERAL, SG_ALERT, "Sorry, the default airport seems to be unknown."); } } - + fgSetDouble( "/position/longitude-deg", fgGetDouble("/sim/presets/longitude-deg") ); fgSetDouble( "/position/latitude-deg", fgGetDouble("/sim/presets/latitude-deg") ); fgSetDouble( "/orientation/heading-deg", hdg_preset->getDoubleValue()); - + // determine if this should be an on-ground or in-air start if ((fabs(gs) > 0.01 || fabs(od) > 0.1 || alt > 0.1) && carrier.empty()) { fgSetBool("/sim/presets/onground", false); } else { fgSetBool("/sim/presets/onground", true); } - + fgSetBool("/sim/position-finalized", false); // Initialize the longitude, latitude and altitude to the initial position fgSetDouble("/position/altitude-ft", fgGetDouble("/sim/presets/altitude-ft")); fgSetDouble("/position/longitude-deg", fgGetDouble("/sim/presets/longitude-deg")); fgSetDouble("/position/latitude-deg", fgGetDouble("/sim/presets/latitude-deg")); - + return true; } - + bool finalizeMetar() { double hdg = fgGetDouble( "/environment/metar/base-wind-dir-deg", 9999.0 ); @@ -711,14 +715,14 @@ bool finalizeMetar() !rwy_req && onground && parkpos.empty(); - + if (needMetar) { // timeout so we don't spin forever if the network is down if (global_finalizeTime.elapsedMSec() > fgGetInt("/sim/startup/metar-fetch-timeout-msec", 6000)) { SG_LOG(SG_GENERAL, SG_WARN, "finalizePosition: timed out waiting for METAR fetch"); return true; } - + if (fgGetBool( "/environment/metar/failure" )) { SG_LOG(SG_ENVIRONMENT, SG_INFO, "metar download failed, not waiting"); return true; @@ -727,32 +731,32 @@ bool finalizeMetar() if (!fgGetBool( "/environment/metar/valid" )) { return false; } - + SG_LOG(SG_ENVIRONMENT, SG_INFO, "Using METAR for runway selection: '" << fgGetString("/environment/metar/data") << "'" ); setPosFromAirportIDandHdg( apt, hdg ); // fall through to return true } // of need-metar case - + return true; } - + void finalizePosition() { // first call to finalize after an initPosition call if (global_finalizeTime.get_usec() == 0) { global_finalizeTime = SGTimeStamp::now(); } - + bool done = true; - + /* Scenarios require Nasal, so FGAIManager loads the scenarios, * including its models such as a/c carriers, in its 'postinit', * which is the very last thing we do. * flightgear::initPosition is called very early in main.cxx/fgIdleFunction, * one of the first things we do, long before scenarios/carriers are * loaded. => When requested "initial preset position" relates to a - * carrier, recalculate the 'initial' position here + * carrier, recalculate the 'initial' position here */ std::string carrier = fgGetString("/sim/presets/carrier"); std::string parkpos = fgGetString("/sim/presets/parkpos"); @@ -772,12 +776,12 @@ void finalizePosition() } else { done = finalizeMetar(); } - + fgSetBool("/sim/position-finalized", done); if (done) { globals->get_event_mgr()->removeTask("finalizePosition"); global_callbackRegistered = false; } } - + } // of namespace flightgear diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3033669d5..c60458815 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,7 @@ set(sources Main/globals.cxx Main/locale.cxx Main/util.cxx + Main/positioninit.cxx Aircraft/controls.cxx Aircraft/FlightHistory.cxx Aircraft/flightrecorder.cxx @@ -91,7 +92,7 @@ set_target_properties (fgtestlib ) if(FG_HAVE_GPERFTOOLS) - include_directories(${GooglePerfTools_INCLUDE_DIR}) + target_include_directories(fgtestlib PRIVATE ${GooglePerfTools_INCLUDE_DIR}) target_link_libraries(fgtestlib ${GooglePerfTools_LIBRARIES}) endif() target_link_libraries(fgtestlib SimGearCore ${PLATFORM_LIBS} ${SQLITE3_LIBRARY}) @@ -101,6 +102,7 @@ target_link_libraries(fgtest fgtestlib) macro(flightgear_test name sources) add_executable(${name} ${sources}) + target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/tests) target_link_libraries(${name} fgtestlib) add_test(${name} ${EXECUTABLE_OUTPUT_PATH}/${name}) endmacro() diff --git a/tests/unitTestHelpers.cxx b/tests/unitTestHelpers.cxx index c23fb6770..c44731e08 100644 --- a/tests/unitTestHelpers.cxx +++ b/tests/unitTestHelpers.cxx @@ -4,6 +4,8 @@ #include "unitTestHelpers.hxx" #include
+#include
+ #include #include